write_characteristic_error,writecharacteristic失败,null,null
我正在尝试开发一个带有颤动的应用程序,该应用程序应该能够通过包装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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论