react-native-ble-plx错误监视器CharacteristicForDevice

问题描述

我需要帮助解决此问题,我使用react-native-ble-plx连接accu-chex。要检查一些人的葡萄糖酸盐,我已经阅读了一些文档,但无助于解决此问题,并且仍然无法监视CharacteristicForDevice

我已经在两个版本中进行了测试:

"react-native": "0.63.3","react-native-ble-plx": "^2.0.1"

"react-native": "0.59.5","react-native-ble-plx": "^1.1.1",

但是我有这样的错误

error

这是我在app.js文件中的代码

    /**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow strict-local
 */

import React,{
    Component
} from 'react';
import {
    SafeAreaView,StyleSheet,BackHandler,View,Text,StatusBar,Button,} from 'react-native';

import { BleManager } from 'react-native-ble-plx';
import base64 from 'react-native-base64'

export default class App extends Component {
    constructor(props) {
        super(props)
        this.manager = new BleManager()
        this.state = {
            isLoading: true,info: "",values: {}
        };
        this.prefixUUID = "cAHXIQABAAE="
        this.suffixUUID = "00001808-0000-1000-8000-00805f9b34fb"
        this.sensors = {
            0: "Temperature",1: "Accelerometer",2: "Humidity",3: "Magnetometer",4: "Barometer",5: "gyroscope"
        }

        this.scanAndConnect = this.scanAndConnect.bind(this)
    };

    componentDidMount() {
        this.manager = new BleManager()
        BackHandler.addEventListener('hardwareBackPress',this.handleBackButton);
        this.scanAndConnect()
    };

    componentwillUnmount() {
        BackHandler.removeEventListener('hardwareBackPress',this.handleBackButton);
    };

    serviceUUID(num) {
        return this.prefixUUID + num + "0" + this.suffixUUID
    }

    notifyUUID(num) {
        return this.prefixUUID + num + "1" + this.suffixUUID
    }

    writeUUID(num) {
        return this.prefixUUID + num + "2" + this.suffixUUID
    }

    info(message) {
        this.setState({ info: message })
    }

    updateValue(key,value) {
        this.setState({ values: { ...this.state.values,[key]: value } })
    }

    scanAndConnect() {
        this.manager.startDeviceScan(null,null,(error,device) => {
                this.info("Scanning...")
                console.log(device)

                if (error) {
                    this.error(error.message)
                    return
                }

                if (device.name === 'meter+00629446') {
                    this.info("Connecting to TI Sensor")
                    this.manager.stopDeviceScan()
                    this.manager.connectToDevice(device.id)
                        .then((device) => {
                            this.info("discovering services and characteristics")
                            return this.manager.discoverAllServicesAndcharacteristicsForDevice(device.id)
                        })
                        .then((device) => {
                            console.log(`connected ${device.id} ${device.name} mtu:${device.mtu}`);
                            device.cancelConnection()
                            this.info("Setting notifications")
                            return this.setupNotifications(device)
                        })
                        .then(() => {
                            this.info("Listening...")
                        },(error) => {
                            console.log(device)
                            this.error(error.message)
                        })
                }
            });
    }

    setupNotifications(device) {
        this.manager.monitorCharacteristicForDevice(device.id,'00001808-0000-1000-8000-00805f9b34fb','00002A18-0000-1000-8000-00805f9b34fb',characteristic) => {
            console.log("characteristic",characteristic)
            if (error) {
                this.error(error.message)
                return
            }
            // this.updateValue(characteristic.uuid,characteristic.value)
        })

        this.manager.writeCharacteristicWithResponseForDevice(device.id,'00002A52-0000-1000-8000-00805f9b34fb',base64.decode('0401'),see) => {
            if (error) {
                this.error(error.message)
                return
            }
            console.log(see.uuid,see)
        })
    }

    render() {
        return (
            <SafeAreaView style={{ flex: 1,backgroundColor: 'white' }}>
                <View style={{ padding: 10 }}>
                    <Text>{this.state.info}</Text>
                    {Object.keys(this.sensors).map((key) => {
                        return <Text key={key}>
                            {this.sensors[key] + ": " + (this.state.values[this.notifyUUID(key)] || "-")}
                        </Text>
                    })}
                    
                </View>
            </SafeAreaView>
        );
    }
}

我已经阅读了一些文档来解决此问题,但仍然无法正常工作。请帮忙... 谢谢:)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...