Click here to Skip to main content
15,795,789 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I write Persian characters to serial port but in DataRecieved I get other characters like ?, etc.
How can I write Persian string to serial port and receive it as Persian.
Updated 8-Dec-11 6:12am

1 solution

In the documentation of the Write[^] method is a remark about the encoding used by the function.
By default, SerialPort uses ASCIIEncoding to encode the characters. ASCIIEncoding encodes all characters greater then 127 as (char)63 or '?'. To support additional characters in that range, set Encoding to UTF8Encoding, UTF32Encoding, or UnicodeEncoding.

So the encoding is messing up your bytes, as stated any byte larger than 127 is replaced by char(63) '?'.

Try using a different encoding.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900