我正在尝试通过蓝牙从iOS设备上的Arduino板读取数据。特别是,我使用的是Coin蓝牙原型板。
虽然我能够从Arduino接收iOS设备上的数据,但我无法理解iOS设备上看到的数据顺序。在Arduino上,我正在做一些简单的事情......只是反复发送三个连续的字节:
void loop()
{
mySerial.write((byte)1);
mySerial.write((byte)2);
mySerial.write((byte)3);
}
在iOS上,我能够将数据读入NSData对象,当以十六进制打印出结果时,我的内容如下所示:
0c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 03 00 00 00 00 00 00 00 00 00 00 00 00 00年左右
02 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 02 03 00 00 00 00 00 00 00 00 00 00 00 00 00
01 02 03 00 00 00 00 00 00 00 00 00 00 00 00 00 01 02 01 01 00 00 00 00 00 00 00 00 00 00 00年左右
03 02 03 01 00 00 00 00 00 00 00 00 00 00 00 00 01 02 01 01 04 00 00 00 00 00 00 00 00 00 00 00
02 02 03 01 04 00 00 00 00 00 00 00 00 00 00 00 03 01 02 03 04 00 00 00 00 00 00 00 00 00 00 00
01 01 02 03 04 00 00 00 00 00 00 00 00 00 00 00 03 01 02 03 04 00 00 00 00 00 00 00 00 00 00 00
01 01 02 03 04 00 00 00 00 00 00 00 00 00 00 00 02 01 01 04 00 00 00 00 00 00 00 00 00 00 00
01 03 01 02 04 00 00 00 00 00 00 00 00 00 00 00 03 01 02 03 04 00 00 00 09 00 00 00 00 00 00 00
01 01 02 03 04 00 00 00 09 00 00 00 00 00 00 00 03 01 02 03 04 00 00 00 0a 00 00 00 00 00 00 00
03 01 02 03 04 00 00 00 0a 00 00 00 00 00 00 00 02 03 01 02 04 00 00 00 0b 00 00 00 00 00 00 00
01 03 01 02 04 00 00 00 0b 00 00 00 00 00 00 00 01 02 01 01 04 00 00 00 0c 00 00 00 00 00 00 00
虽然很清楚正在读取正确的数据,但我无法确定的是如何正确地在电路板和iOS设备之间构建数据。在上面,似乎并不总是以正确的顺序接收数据(例如,可以找到03 02 03的序列),并且也出现奇怪的值(0c和04?)。我似乎无法理解为什么会发生这种情况,或者如何确保从设备中按顺序读取iOS设备上的数据。有人可以提供任何有关数据为何如此表现的见解,或者可用于确保正确数据框架的一般Arduino串行数据写入规则吗?
编辑:
在iOS方面,我通过委托功能
从CoreBluetooth获取数据- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
我正在检查的NSData *来自characteristic.value。