我正在使用Flutter Blue库来构建一个应用程序以连接到IoT设备。我能够获得连接并发现可以工作的服务。
我想发送一个最初用Java(NRF库)编写的命令。
public boolean setSourceSettings() {
byte[] packetStream = new byte[20];
for (int i = 0; i < 20; i++) {
packetStream[i] = (byte) 0;
}
packetStream[0] = (byte) 22;
packetStream[1] = (byte) 2;
packetStream[2] = (byte) 0;
packetStream[3] = (byte) 0;
packetStream[4] = (byte) 0;
packetStream[5] = (byte) 14;
packetStream[6] = (byte) 2;
packetStream[7] = (byte) 0;
packetStream[8] = (byte) 0;
packetStream[9] = (byte) 5;
packetStream[10] = (byte) 35;
packetStream[11] = (byte) 10;
mP3ConnectionServices.WriteToP3(packetStream);
return true;
}
以上代码的dart等效项是什么?我尝试了各种组合,但dart只是拒绝发送“字节”。此mP3ConnectionServices是设备参考,并且写入p3命令正在写入串行BLE的Rx。
我相信你正在寻找Uint8List。这等效于你发布的Java代码:
bool setSourceSettings() {
final packetStream = Uint8List.fromList([22, 2, 0, 0, 0, 14, 2, 0, 0, 5, 35, 10]);
mP3ConnectionServices.WriteToP3(packetStream);
return true;
}