Search code examples
c#serial-portxbee

SerialPort receive ?? chars, encoding is not right


In the documentation for SerialPort.Write in MS, says : By default, SerialPort uses ASCIIEncoding to encode the characters. ASCIIEncoding encodes all characters greater than 127 as (char)63 or '?'. To support additional characters in that range, set Encoding to UTF8Encoding, UTF32Encoding, or UnicodeEncoding.

Can anyone know how i set the Encoding of my serialport to one of that options??


Solution

  • How about using System.IO.Ports.SerialPort.Encoding Property?

    Like this:

    Encoding enc = new UTF8Encoding(true, true);
    YourPort.Encoding = enc;