使用最新版本的Android设备(Oneplus 7 Pro)导致的错误,我可以在此处安装。我确定具有该ID的服务位于我的设备中,因为它是在flutter_blue被调用之前发现的。
我不知道那是怎么回事。部分代码在这里具有含义:
var startVibrating = [0x00, 0xC0, 0x45, 0x22, 0x01, 0x1E, 0x00, 0x00, 0xC3];
BluetoothService btVibrations;
BluetoothCharacteristic vibChar;
//here iam getting interested service "starting vibrations" in my device.
void listServices() async {
List<BluetoothService> services = await widget.device.discoverServices();
services.forEach((service) async {
if (service.uuid.toString() == "daebb240-b041-11e4-9e45-0002a5d5c51b") {
btVibrations = service;
var characteristics = service.characteristics;
for (BluetoothCharacteristic c in characteristics) {
try {
if (c.uuid.toString() == "e16c6e20-b041-11e4-a4c3-0002a5d5c51b") {
//c.write(startVibrating, withoutResponse: true);
vibChar = c;
print("UUID val added FIRST: \n\n\n");
print(c.uuid);
}
} on Exception {
print("error");
}
}
}
});
}
void _startVibrating() async {
// print(await widget.device.canSendWriteWithoutResponse);
try {
widget.device.connect();
} on Exception {}
print("device: " + vibChar.deviceId.id);
vibChar.write(startVibrating, withoutResponse: true);
await vibChar.write(startVibrating, withoutResponse: true);
//await vibChar.read();
}
... blah blah blah rest of long code...
onPressed: _startVibrating,
... /blah blah blah ...
我尝试在没有“响应”的情况下尝试这样做(如您所见),以确保已连接设备。我确定变量btVibrations和vibChar不为空。
我的想法是可能由于flutter_blue仍在寻找服务而引起的(我有其他错误),但是我找不到解决该问题的方法。