0

I need to construct a message to send to a serial device that is 1024 ASCII characters. If I construct this message in a regular string data type will this work? I assume the data will be wrong because strings are formatted in Unicode. How could I go about doing something like this?

2
  • Could you show the code that send data to the serial device? Commented Mar 19, 2013 at 13:13
  • If the characters are ASCII and you have not changed the encoding of the serial port you can just write the string. Commented Mar 19, 2013 at 15:26

1 Answer 1

1

First of all, strings are not designed to handle binary data so you should not use it when you need access to row binary data.

Most suitable candidate for this is byte array. It will ensure that the data is store exactly you want it.

For writing to serial port, you should use binary streams. It will take a binary array and can put on any writable device.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.