繁体   English   中英

Flutter_Blue来自写入的读取响应

[英]Flutter_Blue Read response from write

我没有销售代表来为Flutter_Blue创建标签。 但这会在Android Studio中使用Flutter_Blue。

我正在尝试将命令发送到由公司创建设备的设备,并且正在开发和Android / IOS应用程序,该应用程序连接到设备并发送命令并读取设备返回的内容。

我已经移植了示例代码以查找设备,然后将其写入。 我有以下代码。

    _writeCharacteristic(BluetoothCharacteristic c) async {

await device.writeCharacteristic(c, [0x076, 0x0d, 0x0a],
    type: CharacteristicWriteType.withResponse);


setState(() {});
}

这会将av和crlf发送到设备。 如何阅读设备响应?

让我知道是否还有更多我需要正确完成此问题。

我想通了,见下文

我可能是错的,但我发现了可以找到我所寻找的响应的地方。

我添加了这个

String x = "";
        d.forEach((f) => x+=String.fromCharCode(f));

_setNotification(BluetoothCharacteristic c) async {
    if (c.isNotifying) {
      await device.setNotifyValue(c, false);
      // Cancel subscription
      valueChangedSubscriptions[c.uuid]?.cancel();
      valueChangedSubscriptions.remove(c.uuid);
    } else {
      await device.setNotifyValue(c, true);
      // ignore: cancel_subscriptions
      final sub = device.onValueChanged(c).listen((d) {
        String x = "";
        d.forEach((f) => x+=String.fromCharCode(f));
        Response = x;
        setState(() {

          print('onValueChanged $x');
        });
      });
      // Add to map
      valueChangedSubscriptions[c.uuid] = sub;
    }
    setState(() {});
  }

和输出

    onValueChanged DT8610CI-7125

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM