
[英]reading data through bluetooth using flutter_bluetooth_serial package
[英]Problems reading Bluetooth Device data and returning it into code in Flutter/Dart
以下是我用来从蓝牙设备读取数据的功能代码
Future listServices() async {
List<BluetoothService>? services = await primBms?.device.discoverServices();
List values = [];
services?.forEach((service) async {
if (service.uuid.toString() == primBmsUuids[0]) {
for (BluetoothCharacteristic c in service.characteristics) {
List<int> value = await c.read();
int val = int.parse(String.fromCharCode(value[0]) + String.fromCharCode(value[1]));
print(value);
print(val);
values.add(val);
}
}
});
return values;
}
我正在解析读取数据包中的字符代码,但是使用此函数返回一个空列表。 我使用了一个打印函数来确认 value 和 val 是否返回有效值并且它们确实返回了,但是无论出于何种原因这些都没有添加到列表中。
有人可以帮助我找出解决问题的方法吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.