React native 使用Polidea/react本机ble plx从ble设备获取所有服务和特性时出错
您好,我正在尝试使用Polidea/react本机ble plx库连接蓝牙设备 首先,我进行了扫描,效果良好:React native 使用Polidea/react本机ble plx从ble设备获取所有服务和特性时出错,react-native,bluetooth-lowenergy,android-bluetooth,react-native-ble-plx,React Native,Bluetooth Lowenergy,Android Bluetooth,React Native Ble Plx,您好,我正在尝试使用Polidea/react本机ble plx库连接蓝牙设备 首先,我进行了扫描,效果良好: scanAndConnect() { console.log('scanAndConnect'); this.manager.startDeviceScan(null, null, (error, device) => { //console.log('Scanning...' + error); if (error) { // Handle error (scanning wi
scanAndConnect() {
console.log('scanAndConnect');
this.manager.startDeviceScan(null, null, (error, device) => {
//console.log('Scanning...' + error);
if (error) {
// Handle error (scanning will be stopped automatically)
console.log('Scanning ERROR');
return;
}
if ((device.id=== '54:6C:0E:A0:7B:6D')
{
console.log('device found: ' + device.name + '(' + device.id + ')');
this.manager.stopDeviceScan();
}
}
第二步,我尝试连接。而且它也有效
device.connect().then((dev) => {
console.log("try to connect")
}).then((dev) => {
console.log("success to connect")
}).catch((error) => {
console.log("connect error:" + error)
throw error
});
所以,现在我想让所有的服务和角色扮演者从设备上读取一些信息,但这个功能对我来说不起作用
我正在使用这种方法
设备。发现服务和特征()
我总是收到一个错误
有时我会收到以下错误消息:
1) 警告可能未处理的承诺拒绝(id:0):
BLERROR:设备54:6C:0E:A0:7B:6D未连接
我不理解第一个,因为我已经连接了设备
var status = this.manager.isDeviceConnected(device.id).then((status)=>console.log('status1: '+status))
上面的行在调用connect方法之前返回false,之后返回true
但当我尝试获取服务和特征时,我得到的信息是设备未连接