gpt4 book ai didi

bluetooth - PlatformException 试图读取 flutter 蓝色上的特性

转载 作者:行者123 更新时间:2023-12-01 17:48:07 24 4
gpt4 key购买 nike

我正在尝试使用插件https://github.com/pauldemarco/flutter_blue从设备读取所有服务的所有特征但它向我抛出了这个错误:

[ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (24425): PlatformException(read_characteristic_error, unknown reason, may occur if readCharacteristic was called before last read finished., null)
E/flutter (24425): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:547:7)
E/flutter (24425): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:279:18)
E/flutter (24425): <asynchronous suspension>
E/flutter (24425): #2 BluetoothDevice.readCharacteristic (file:///C:/Users/Downloads/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_blue-0.3.3/lib/src/bluetooth_device.dart:56:10)
E/flutter (24425): <asynchronous suspension>
E/flutter (24425): #3 _ListTabState._connectToDevice._readCarachteristics (file:///C:/Users/AndroidStudioProjects/my_app/lib/tab_base.dart:125:49)
E/flutter (24425): <asynchronous suspension>
E/flutter (24425): #4 _ListTabState._connectToDevice._showServices (file:///C:/Users/AndroidStudioProjects/my_app/lib/tab_base.dart:157:27)
E/flutter (24425): <asynchronous suspension>
E/flutter (24425): #5 _ListTabState._connectToDevice._connect.<anonymous closure> (file:///C:/Users/AndroidStudioProjects/my_app/lib/tab_base.dart:197:24)
E/flutter (24425): #6 _RootZone.runUnaryGuarded (dart:async/zone.dart:1316:10)
E/flutter (24425): #7 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:330:11)
E/flutter (24425): #8 _DelayedData.perform (dart:async/stream_impl.dart:578:14)
E/flutter (24425): #9 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:694:11)
E/flutter (24425): #10 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:654:7)
E/flutter (24425): #11 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (24425): #12 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)

这是我正在使用的代码:

_readCarachteristics(services) async {
for (BluetoothService service in services){
_characteristics = service.characteristics;
for (BluetoothCharacteristic characteristic in _characteristics) {
final List<int> value = await _device.readCharacteristic(characteristic);
}
}

_services = await device.discoverServices();
_readCarachteristics(_services);

我读到了这个问题:https://github.com/pauldemarco/flutter_blue/issues/57但无法解决它。感谢您的支持。

已更新

似乎信标发送了一些特定的特征,这些特征以特殊的方式组成,破坏了 readCharacteristic 方法。它们应该包含两个未被 readDescriptor 函数读取的 uuid 子类型。

最佳答案

共有三种服务,其中第三个应该用于读取和写入特征。前两个是通用的,第三个是自定义服务,使用它可以工作。试试这个:

_scanResult.device.discoverServices().then((services){
services[2].characteristics[0].read();
});

关于bluetooth - PlatformException 试图读取 flutter 蓝色上的特性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51310233/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com