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

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

        <bdo id='IEYrb'></bdo><ul id='IEYrb'></ul>
      <i id='IEYrb'><tr id='IEYrb'><dt id='IEYrb'><q id='IEYrb'><span id='IEYrb'><b id='IEYrb'><form id='IEYrb'><ins id='IEYrb'></ins><ul id='IEYrb'></ul><sub id='IEYrb'></sub></form><legend id='IEYrb'></legend><bdo id='IEYrb'><pre id='IEYrb'><center id='IEYrb'></center></pre></bdo></b><th id='IEYrb'></th></span></q></dt></tr></i><div id='IEYrb'><tfoot id='IEYrb'></tfoot><dl id='IEYrb'><fieldset id='IEYrb'></fieldset></dl></div>
      <tfoot id='IEYrb'></tfoot>
      1. 如何正确使用 SerialPort.DiscardInBuffer?

        时间:2023-11-10

          <bdo id='V2KFk'></bdo><ul id='V2KFk'></ul>
          <tfoot id='V2KFk'></tfoot>
          <legend id='V2KFk'><style id='V2KFk'><dir id='V2KFk'><q id='V2KFk'></q></dir></style></legend>
        • <small id='V2KFk'></small><noframes id='V2KFk'>

                  <tbody id='V2KFk'></tbody>
                <i id='V2KFk'><tr id='V2KFk'><dt id='V2KFk'><q id='V2KFk'><span id='V2KFk'><b id='V2KFk'><form id='V2KFk'><ins id='V2KFk'></ins><ul id='V2KFk'></ul><sub id='V2KFk'></sub></form><legend id='V2KFk'></legend><bdo id='V2KFk'><pre id='V2KFk'><center id='V2KFk'></center></pre></bdo></b><th id='V2KFk'></th></span></q></dt></tr></i><div id='V2KFk'><tfoot id='V2KFk'></tfoot><dl id='V2KFk'><fieldset id='V2KFk'></fieldset></dl></div>
                  本文介绍了如何正确使用 SerialPort.DiscardInBuffer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我编写了一个应用程序,它以非常快的速度从串行设备中读取数据.然而,串行端口对象在连续运行约 20 分钟后未能触发 DataReceieved 事件.以编程方式断开和重新连接串行允许事件再次工作,但仅再持续 20 分钟.

                  I've written an application which reads from a serial device at a very fast rate. The serial port object however, fails to fire the DataReceieved event after about 20 min of continuous operation. Disconnecting and reconnecting the serial programmatically allows the event to work again but for only another 20 min.

                  我尝试在每个 DataReceived 事件之后使用 DiscardInBuffer,这似乎已经解决了问题.但是这种方法会消耗大量的 cpu 时间,并且会降低应用程序的性能.MSDN 提到丢弃串行驱动程序接收缓冲区中的数据"方法,但没有建议何时使用.

                  I tried using DiscardInBuffer after every DataReceived event and this has appeared to have solved the problem. But the method consumes a lot of cpu time and is degrading the performance of the application. MSDN mentions that the method "Discards data from the serial driver's receive buffer.", but fails to suggest when it should be used.

                  应该何时以及如何使用 DiscardInBuffer,我是否在针对特定问题的正确上下文中使用它?

                  When and how should DiscardInBuffer be used, and am I using it in the correct context for my particular problem ?

                  执行ErrorReceived事件后,返回的事件数据表明事件类型为RXOver".

                  After implementing the ErrorReceived event, the event data returned indicated the event type was an "RXOver".

                  推荐答案

                  经过更多调查,我的问题似乎是一个更根本的问题.由于数据以极快的速度涌入,因此需要连续清除或处理 SerialPort 缓冲区以防止RXOver"错误.我通过在 DataReceived 事件期间读入另一个缓冲区并在另一个单独的线程中处理它来实现这一点.

                  After more investigations, it appears my problem was more a fundamental issue. Since the data was flooding in at a hot pace, the SerialPort buffer needed to be cleared or processed continuously to prevent the "RXOver" error. I achieved this by reading into another buffer during the DataReceived event and processed it in another separate thread.

                  据我了解,DiscardInBuffer 只能选择性地用于清除端口内容以进行初始化,例如在打开端口之前.清除驱动程序缓冲区的过程确实需要一些时间才能完成,因此应该在面向性能的应用程序中明智地使用.

                  From my understanding the DiscardInBuffer should only be used selectively to clear the contents of the ports for initialisation purposes, such as before opening a port. The process of clearing the driver buffer does take some time to complete and therefore should be used wisely in a performance orientated application.

                  这篇关于如何正确使用 SerialPort.DiscardInBuffer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:C# 串行端口速度 下一篇:如何关闭另一个程序使用的串口

                  相关文章

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

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

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

                      <tfoot id='PDOC6'></tfoot>