write_characteristic_error,writecharacteristic失败,null,null

发布于 2025-02-13 18:04:48 字数 2326 浏览 0 评论 0原文

我正在尝试开发一个带有颤动的应用程序,该应用程序应该能够通过包装Flutter_blue_plus通过蓝牙连接到GPS设备。我目前遇到了这个错误

未经手的异常:platformException(write_characteristis_error,Writecharacteristic失败,null,null)

当我尝试发送字节以获取所需的数据时。我仍然是新手,而且我所看到的,蓝牙连接并不是最简单的实现。

我还从此示例

当我尝试使用write()函数时显示出现。

给我问题的代码块。我在这里可能会缺少什么吗?

List<Widget> _buildServiceTiles(List<BluetoothService> services) {
    return services
        .map(
          (s) => ServiceTile(
            service: s,
            characteristicTiles: s.characteristics
                .map(
                  (c) => CharacteristicTile(
                    characteristic: c,
                    onReadPressed: () async {
                      List data = await c.read();
                      print('DATA: ${data.toString()}');
                      // List<int> value = await c.read();
                      // _parseHr(value); //parse bytes
                      // print(_getRandomBytes());
                    },
                    onWritePressed: () async {
                      await c.write(_getRandomBytes(), withoutResponse: true);
                      // await c.read();
                    },
                    onNotificationPressed: () async {
                      await c.setNotifyValue(!c.isNotifying);
                      await c.read();
                    },
                    descriptorTiles: c.descriptors
                        .map(
                          (d) => DescriptorTile(
                            descriptor: d,
                            onReadPressed: () async {
                              // List<int> value = await c.read();
                              d.read();
                            },
                            onWritePressed: () async {
                              d.write(_getRandomBytes());
                              // print(_sendBytes());
                            },
                          ),
                        )
                        .toList(),
                  ),
                )
                .toList(),
          ),
        )
        .toList();
  }

I'm trying to develop an app with flutter which should be able to connect via bluetooth to a GPS device with the package flutter_blue_plus. I'm currently getting this error

Unhandled Exception: PlatformException(write_characteristic_error, writeCharacteristic failed, null, null)

when I try to send bytes to get the data I need. I'm still new at this and for what I've seen, bluetooth connections is not the most simple thing to implement.

I'm also doing it based from this sample

This error shows up when I try to use the write() function.

The code block that is giving me the problem. Is there anything I might be missing here?

List<Widget> _buildServiceTiles(List<BluetoothService> services) {
    return services
        .map(
          (s) => ServiceTile(
            service: s,
            characteristicTiles: s.characteristics
                .map(
                  (c) => CharacteristicTile(
                    characteristic: c,
                    onReadPressed: () async {
                      List data = await c.read();
                      print('DATA: ${data.toString()}');
                      // List<int> value = await c.read();
                      // _parseHr(value); //parse bytes
                      // print(_getRandomBytes());
                    },
                    onWritePressed: () async {
                      await c.write(_getRandomBytes(), withoutResponse: true);
                      // await c.read();
                    },
                    onNotificationPressed: () async {
                      await c.setNotifyValue(!c.isNotifying);
                      await c.read();
                    },
                    descriptorTiles: c.descriptors
                        .map(
                          (d) => DescriptorTile(
                            descriptor: d,
                            onReadPressed: () async {
                              // List<int> value = await c.read();
                              d.read();
                            },
                            onWritePressed: () async {
                              d.write(_getRandomBytes());
                              // print(_sendBytes());
                            },
                          ),
                        )
                        .toList(),
                  ),
                )
                .toList(),
          ),
        )
        .toList();
  }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文