<tfoot id='A1aJ4'></tfoot>
    • <bdo id='A1aJ4'></bdo><ul id='A1aJ4'></ul>

    1. <small id='A1aJ4'></small><noframes id='A1aJ4'>

      <i id='A1aJ4'><tr id='A1aJ4'><dt id='A1aJ4'><q id='A1aJ4'><span id='A1aJ4'><b id='A1aJ4'><form id='A1aJ4'><ins id='A1aJ4'></ins><ul id='A1aJ4'></ul><sub id='A1aJ4'></sub></form><legend id='A1aJ4'></legend><bdo id='A1aJ4'><pre id='A1aJ4'><center id='A1aJ4'></center></pre></bdo></b><th id='A1aJ4'></th></span></q></dt></tr></i><div id='A1aJ4'><tfoot id='A1aJ4'></tfoot><dl id='A1aJ4'><fieldset id='A1aJ4'></fieldset></dl></div>
      <legend id='A1aJ4'><style id='A1aJ4'><dir id='A1aJ4'><q id='A1aJ4'></q></dir></style></legend>
    2. 数据在通过串行端口传输期间损坏

      时间:2023-11-10

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

            • <bdo id='KrSrP'></bdo><ul id='KrSrP'></ul>

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

            • <i id='KrSrP'><tr id='KrSrP'><dt id='KrSrP'><q id='KrSrP'><span id='KrSrP'><b id='KrSrP'><form id='KrSrP'><ins id='KrSrP'></ins><ul id='KrSrP'></ul><sub id='KrSrP'></sub></form><legend id='KrSrP'></legend><bdo id='KrSrP'><pre id='KrSrP'><center id='KrSrP'></center></pre></bdo></b><th id='KrSrP'></th></span></q></dt></tr></i><div id='KrSrP'><tfoot id='KrSrP'></tfoot><dl id='KrSrP'><fieldset id='KrSrP'></fieldset></dl></div>
              • <legend id='KrSrP'><style id='KrSrP'><dir id='KrSrP'><q id='KrSrP'></q></dir></style></legend>
                本文介绍了数据在通过串行端口传输期间损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在开发一个程序来与旧系统进行通信.我为此使用 System.IO.Ports.SerialPort.问题是当我发送更长的消息时,消息会损坏.我使用线路监听器并得到以下结果

                I am developing a program to communicate with an old system. I use System.IO.Ports.SerialPort for this. The problem is when I send a longer message, the message bevome corrupt. I use a line listener and get the following results

                我发送的内容

                aa 01 00 00 12 03 06 18 02 c1 94 02 c1 94 00 00 00 00 00 00 00 00 00 00 00 00 1e fd 
                

                我得到了什么

                c2 aa 01 00 00 12 03 06 18 02 c3 81 c2 94 02 c3 81 c2 94 00 00 00 00 00 00 00 00 00 00 00 00 1e c3 bd
                

                我使用的代码是

                _comPort.Encoding = new UTF8Encoding();
                _comPort.PortName = PortName;  //Com1
                _comPort.BaudRate = BaudRate;  //9600
                _comPort.StopBits = StopBits;  //1
                _comPort.DataBits = DataBits;  //8
                _comPort.Parity   = Parity;    //None
                _comPort.Open();
                
                _comPort.Write(messageStr);
                

                为什么数据会损坏,我该如何解决?

                Why is data corrupted and how do I fix this?

                推荐答案

                我的猜测是 messageStr 是一个字符串,而您看到的是编码问题.您已经明确指定了 UTF-8 编码,所以这就是您得到的 - 但我怀疑这不是您真正想要的.

                My guess is that messageStr is a string, and you're seeing encoding issues. You've explicitly specified the UTF-8 encoding, so that's what you're getting - but I suspect it's not what you really want.

                您已经显示了 二进制 数据,因此我假设您实际上想要发送该二进制数据 - 在这种情况下,您应该使用 Write(byte[], int, int) 过载.

                You've shown binary data, so I assume you actually want to send exactly that binary data - in which case you should use the Write(byte[], int, int) overload.

                如果您真的想要编写文本数据,您可能只需要选择正确的编码 - 但您需要向我们提供更多信息,以便我们帮助您做出正确的选择.

                If you really want to write text data, you probably just need to pick the right encoding - but you'll need to give us more information for us to help you make the right choice.

                这篇关于数据在通过串行端口传输期间损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:在两种不同的形式上使用相同的串口数据接收事件 下一篇:COM 端口无法打开 Unity

                相关文章

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

                  1. <tfoot id='GuMQB'></tfoot>

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