SerialPort encoding - how do I get 8 bit ASCII?

前端 未结 3 1815
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-23 16:34

I\'m having a problem with a program that communicates over a serial port. One of the characters it must send and receive is the degree symbol, ASCII 0xBF. It\'s been working fi

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-23 17:29

    Your problem is that ASCIIEncoding is a 7 bit encoding. You're looking for something that supports Extended ASCII.

    The following will get you Codepage 1252.

    System.Text.Encoding.GetEncoding(1252);
    

    This will get you ISO 8859-1.

    System.Text.Encoding.GetEncoding(28591);
    

    Both of these are considered Extended ASCII and both contain symbols (mostly with the same byte representation) typically associated with this set, such as © , ¥ , and º . See the referenced links for more information about which characters are included in each encoding.

提交回复
热议问题