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?
-
Could you show the code that send data to the serial device?Steve– Steve2013-03-19 13:13:11 +00:00Commented 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.dbasnett– dbasnett2013-03-19 15:26:26 +00:00Commented Mar 19, 2013 at 15:26
Add a comment
|
1 Answer
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.