的SerialPort编码 - 如何获得8位的ASCII? [英] SerialPort encoding - how do I get 8 bit ASCII?

查看:341
本文介绍了的SerialPort编码 - 如何获得8位的ASCII?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,通信通过串行端口出现故障。其中必须发送和接收的字符是度数符号,ASCII码为0xBF。它一直工作正常了多年,现在突然串口对象已开始下降7位,所以我得到的0x3F,而不是为0xBF。

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 fine for years now suddenly the serial port object has started dropping bit 7, so I get 0x3F instead of 0xBF.

我敢肯定,这是一件愚蠢的我已经做了,因为我已经修补了我的code在这方面recenlty - 但我看不出我做了什么,导致了第8位的损耗

I'm sure that this is something silly I've done because I've tinkered with my code in that area recenlty - however I cannot see what I've done that causes loss of the 8th bit.

我的口得到像这样初始化的:

My port gets initialized like this:

    BaudRate              9600  int  
    DataBits              8 int  
    DiscardNull true    bool
    DtrEnable             true  bool
    Encoding    {System.Text.ASCIIEncoding} System.Text.Encoding                  Handshake           None  System.IO.Ports.Handshake
    NewLine           "\n"  string
    Parity            None  System.IO.Ports.Parity
    ParityReplace   63  byte
    PortName              "COM4"    string
    ReadBufferSize  128 int
    ReadTimeout 250 int
    ReceivedBytesThreshold  1   int
    RtsEnable             true  bool
    StopBits              One   System.IO.Ports.StopBits
    WriteBufferSize 64  int
    WriteTimeout    1500    int

任何想法我如何恢复端口为8位操作?

Any ideas how I restore the port to 8-bit operation?

推荐答案

您的问题是,的 ASCIIEncoding 是一个7位编码。你要找的东西,支持扩展ASCII

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

下面将让你 codePAGE 1252

System.Text.Encoding.GetEncoding(1252);

这将让你 ISO 8859-1

System.Text.Encoding.GetEncoding(28591);

这两个被认为是扩展ASCII 并都包含符号(大多是相同的字节重新presentation)通常与这组相关,如© ¥和º 。请参阅参考链接获取更多关于哪些字符包括在每个编码。

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.

这篇关于的SerialPort编码 - 如何获得8位的ASCII?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆