在 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 是否返回有效值,并且它们确实返回了,但是无论出于何种原因,它们都没有添加到列表中。

有人可以帮我找出问题的解决方案吗?

解决方法

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

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

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