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

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

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

      2. 在C#中清除串口接收缓冲区

        Clear serial port receive buffer in C#(在C#中清除串口接收缓冲区)

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

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

            • <legend id='kNHOx'><style id='kNHOx'><dir id='kNHOx'><q id='kNHOx'></q></dir></style></legend>
                <tfoot id='kNHOx'></tfoot>
                    <tbody id='kNHOx'></tbody>

                  <i id='kNHOx'><tr id='kNHOx'><dt id='kNHOx'><q id='kNHOx'><span id='kNHOx'><b id='kNHOx'><form id='kNHOx'><ins id='kNHOx'></ins><ul id='kNHOx'></ul><sub id='kNHOx'></sub></form><legend id='kNHOx'></legend><bdo id='kNHOx'><pre id='kNHOx'><center id='kNHOx'></center></pre></bdo></b><th id='kNHOx'></th></span></q></dt></tr></i><div id='kNHOx'><tfoot id='kNHOx'></tfoot><dl id='kNHOx'><fieldset id='kNHOx'></fieldset></dl></div>
                  本文介绍了在C#中清除串口接收缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  只想知道如何在 C# 中清除我的串口的接收缓冲区.似乎接收缓冲区中的数据只是不断累积.例如,传入数据的流向是:[Data A]、[Data B]、[Data C].我想要的数据只是[Data C].我正在考虑这样做,当我收到 [Data A] 和 [Data B] 时,我会做一个清除缓冲区.仅当收到 [Data C] 时,我才继续处理.这是在 C# 中实现的方式吗?

                  Just want to know how do we clear the receive buffer of my serial port in C#. Seems like the data in the receive buffer just keep accumulating. For example, the flow of incoming data is: [Data A], [Data B], [Data C]. The data I want is just [Data C]. I'm thinking of doing like, when I receive [Data A] and [Data B], I do a clear buffer. Only when [Data C] is received, I continue process. Is this the way to do it in C#?

                  推荐答案

                  如果你使用的是 System.IO.Ports.SerialPort 那么你可以使用这两种方法:

                  If you are using the System.IO.Ports.SerialPort then you could use the two methods:

                  DiscardInBuffer()DiscardOutBuffer() 刷新缓冲区.

                  如果你是从串口读取数据:

                  If you are reading the data from a serial port:

                  private void comPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
                  {
                      if (!this.Open) return; // We can't receive data if the port has already been closed.  This prevents IO Errors from being half way through receiving data when the port is closed.
                      string line = String.empty;
                      try
                      {
                          line = _SerialPort.ReadLine();
                          line = line.Trim();
                         //process your data if it is "DATA C", otherwise ignore
                      }
                      catch (IOException ex)
                      {
                          //process any errors
                      }
                  }
                  

                  这篇关于在C#中清除串口接收缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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() 和泛型:错误绑定到目标方法)

                      <tbody id='yyc77'></tbody>

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

                          <bdo id='yyc77'></bdo><ul id='yyc77'></ul>

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

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