1. <tfoot id='uG5qm'></tfoot>
    • <bdo id='uG5qm'></bdo><ul id='uG5qm'></ul>

    <legend id='uG5qm'><style id='uG5qm'><dir id='uG5qm'><q id='uG5qm'></q></dir></style></legend>
    1. <small id='uG5qm'></small><noframes id='uG5qm'>

      <i id='uG5qm'><tr id='uG5qm'><dt id='uG5qm'><q id='uG5qm'><span id='uG5qm'><b id='uG5qm'><form id='uG5qm'><ins id='uG5qm'></ins><ul id='uG5qm'></ul><sub id='uG5qm'></sub></form><legend id='uG5qm'></legend><bdo id='uG5qm'><pre id='uG5qm'><center id='uG5qm'></center></pre></bdo></b><th id='uG5qm'></th></span></q></dt></tr></i><div id='uG5qm'><tfoot id='uG5qm'></tfoot><dl id='uG5qm'><fieldset id='uG5qm'></fieldset></dl></div>

      SerialPort 编码 - 我如何获得 8 位 ASCII?

      时间:2023-11-10

        <small id='EVPGT'></small><noframes id='EVPGT'>

        <i id='EVPGT'><tr id='EVPGT'><dt id='EVPGT'><q id='EVPGT'><span id='EVPGT'><b id='EVPGT'><form id='EVPGT'><ins id='EVPGT'></ins><ul id='EVPGT'></ul><sub id='EVPGT'></sub></form><legend id='EVPGT'></legend><bdo id='EVPGT'><pre id='EVPGT'><center id='EVPGT'></center></pre></bdo></b><th id='EVPGT'></th></span></q></dt></tr></i><div id='EVPGT'><tfoot id='EVPGT'></tfoot><dl id='EVPGT'><fieldset id='EVPGT'></fieldset></dl></div>
            <legend id='EVPGT'><style id='EVPGT'><dir id='EVPGT'><q id='EVPGT'></q></dir></style></legend>

                <tbody id='EVPGT'></tbody>
              <tfoot id='EVPGT'></tfoot>

                <bdo id='EVPGT'></bdo><ul id='EVPGT'></ul>
                本文介绍了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.

                我确信这是我所做的一些愚蠢的事情,因为我最近在该领域修改了我的代码 - 但是我看不出我所做的会导致第 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           "
                "  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.

                以下内容将为您提供代码页1252.

                System.Text.Encoding.GetEncoding(1252);
                

                这将使您获得 ISO 8859-1.

                System.Text.Encoding.GetEncoding(28591);
                

                这两个都被认为是 扩展 ASCII 并且都包含通常与此相关的符号(大多数具有相同的字节表示)设置,例如 ©, ¥, 和 º.有关每种编码中包含哪些字符的详细信息,请参阅参考链接.

                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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:C#串口检查设备是否已连接 下一篇:C# SerialPort#Open() 方法由于端口名称而引发 ArgumentException?

                相关文章

              • <legend id='sJUdX'><style id='sJUdX'><dir id='sJUdX'><q id='sJUdX'></q></dir></style></legend>
              • <small id='sJUdX'></small><noframes id='sJUdX'>

                    <bdo id='sJUdX'></bdo><ul id='sJUdX'></ul>
                  <tfoot id='sJUdX'></tfoot>

                  1. <i id='sJUdX'><tr id='sJUdX'><dt id='sJUdX'><q id='sJUdX'><span id='sJUdX'><b id='sJUdX'><form id='sJUdX'><ins id='sJUdX'></ins><ul id='sJUdX'></ul><sub id='sJUdX'></sub></form><legend id='sJUdX'></legend><bdo id='sJUdX'><pre id='sJUdX'><center id='sJUdX'></center></pre></bdo></b><th id='sJUdX'></th></span></q></dt></tr></i><div id='sJUdX'><tfoot id='sJUdX'></tfoot><dl id='sJUdX'><fieldset id='sJUdX'></fieldset></dl></div>