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

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

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

      <legend id='WlHQi'><style id='WlHQi'><dir id='WlHQi'><q id='WlHQi'></q></dir></style></legend>

      1. 附加字符串时的C#SerialPort DataReceived问题

        C# SerialPort DataReceived problem when when attached strings(附加字符串时的C#SerialPort DataReceived问题)

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

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

                <legend id='shSpW'><style id='shSpW'><dir id='shSpW'><q id='shSpW'></q></dir></style></legend>
                  <bdo id='shSpW'></bdo><ul id='shSpW'></ul>
                    <tbody id='shSpW'></tbody>

                  本文介绍了附加字符串时的C#SerialPort DataReceived问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 DataReceived 方法正在触发从 RS232 设备发送数据.使用以下代码可以顺利运行

                  I have a DataReceived method being trigger a data is send from a RS232 device. Things run smoothly with the following code

                  byte[] data = new Byte[serialPort.BytesToRead];
                  serialPort.Read(data, 0, data.Length);
                  string read = System.Text.Encoding.ASCII.GetString(data);
                  

                  但如果我在数据后添加一个字符串

                  but if I add a string after a data

                  string read = System.Text.Encoding.ASCII.GetString(data) + "asdf 
                  ";
                  

                  数据仍然被接收,但偶尔会显示不正确.例如.如果我连接到秤并且应该读取10.45kg asdf",它将在我的计算机上显示为10. asdf45kg".这里有什么问题?

                  The data is still received but occasionally would be displayed incorrectly. E.g. if I'm connecting to a scale and should be reading "10.45kg asdf" it would show on my computer as "10. asdf45kg". What is the problem here?

                  推荐答案

                  DataReceived方法会在串口感觉触发的时候触发,不一定是收到完整的字符串装置.请参阅 此 SO 答案详细讨论.如果您有一个已知的终止符,您可以通过设置 SerialPort 的 NewLine 属性,然后使用 ReadLine() 来解决此问题.

                  The DataReceived method will be triggered when the serial port feels like triggering it, which is NOT necessarily when you receive a full string from the device. See this SO answer for a great discussion of the details. If you have a known terminator character, you can work around this problem by setting the NewLine property of the SerialPort, and then using ReadLine().

                  这篇关于附加字符串时的C#SerialPort DataReceived问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                  Parameter count mismatch with Invoke?(参数计数与调用不匹配?)
                  How to store delegates in a List(如何将代表存储在列表中)
                  How delegates work (in the background)?(代表如何工作(在后台)?)
                  C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)
                  Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)
                • <i id='kFAow'><tr id='kFAow'><dt id='kFAow'><q id='kFAow'><span id='kFAow'><b id='kFAow'><form id='kFAow'><ins id='kFAow'></ins><ul id='kFAow'></ul><sub id='kFAow'></sub></form><legend id='kFAow'></legend><bdo id='kFAow'><pre id='kFAow'><center id='kFAow'></center></pre></bdo></b><th id='kFAow'></th></span></q></dt></tr></i><div id='kFAow'><tfoot id='kFAow'></tfoot><dl id='kFAow'><fieldset id='kFAow'></fieldset></dl></div>

                    <tbody id='kFAow'></tbody>
                    <bdo id='kFAow'></bdo><ul id='kFAow'></ul>
                  • <legend id='kFAow'><style id='kFAow'><dir id='kFAow'><q id='kFAow'></q></dir></style></legend>

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

                  • <tfoot id='kFAow'></tfoot>