I am transmitting data from the Bean to an iOS app using serial communication.
My Bean code is:
void loop() {
int value = getValue();
Serial.write(value);
Bean.sleep(1000);
}
My iOS code is:
func bean(_ bean: PTDBean!, serialDataReceived serData: Data!) {
print (serData)
}
Looking at the output from the above print statement, it shows that only one byte was received, while I would expect to receive two bytes since I transmitted an Int. Even if I convert the output value to a Long, I only receive 1 byte.
However, if I change the Bean code to Serial.print(value), then everything works fine. I can convert that received value to a String and I see the values that I was expecting.
Once this problem is corrected, my next question is how to convert the received binary data into an int value in Swift 3. I have tried a number of ways, but it's not clear how to do this.