iOS BLE UART数据传输问题

iOS BLE UART Data Transmission Problems

我正在使用 Adafruit BLE UART 板将数据传输到 iOS 应用程序进行处理。在 iOS 端,数据由名为 UARTPeripheral. (The link I sent is to the file in some one's GitHub project - I can't find a link to the real thing - but the file is the same. The Arduino side is processing the data with an Adafruit library 的 class 处理。每一方都需要仔细审查的事情(至少我认为)是 Arduino 方面的 print() 函数和 iOS 方面的 - (void)didReceiveData:(NSData*)newData 方法。

这是我尝试发送数据(从 Arduino 端)时突然出现的实际问题:每个数据值之间是 3。就这么简单。假设我使用 ble.print(B00000010) 从电路板发送二进制 2,在 iOS 端我收到 32。假设我使用以下代码从 Arduino 端发送一个整数:

int test = 4132;
ble.print(test);

我最终会 34313332 站在 iOS 一边。我并不是要任何人仔细检查这些库,但如果能说明为什么会发生这样的事情,那就太好了。我知道我可以只使用 "sticking plaster" 方法并摆脱 3s,但我想找到这个问题的根源。

我已经解决了这个问题 - print() 函数将所有值转换为它们的 ASCII 数字,因此所有数字前面都有 3 是有意义的,因为 ASCII 数字在 30 范围内。我需要做的就是用 NSUTF8StringEncoding.

NSData 转换为 NSString