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

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

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

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

        <tfoot id='x4N7z'></tfoot>
      1. C# 串行端口速度

        C# serialPort speed(C# 串行端口速度)

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

                <legend id='yTa7m'><style id='yTa7m'><dir id='yTa7m'><q id='yTa7m'></q></dir></style></legend>
                  <tbody id='yTa7m'></tbody>
                <tfoot id='yTa7m'></tfoot>
                • <small id='yTa7m'></small><noframes id='yTa7m'>

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

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

                  问题描述

                  我正在为某种基于串行通信的协议开发一些监控工具.

                  I am developing some monitoring tool for some kind of protocol based on serial communication.

                  串行波特率=187,5kb我使用 System.IO.Ports.SerialPort 类.

                  Serial BaudRate=187,5kb I use System.IO.Ports.SerialPort class.

                  此协议有 4 种帧.它们有 1Byte、3Bytes、6Bytes、10-255Bytes.我可以与他们合作,但我收到他们来得太晚,无法回复.

                  This protocol has 4 kinds of frames. They have 1Byte,3Bytes,6Bytes, 10-255Bytes. I can work with them but I receive them too late to respond.

                  一开始我收到的第一个包装是在 ex 之后.96ms(为时已晚),它包含大约 1000B.这意味着 20-50 帧(太多,太晚了).后来它的工作更稳定,3-10Bytes 但仍然为时已晚,因为它包含 1-2 帧.当然 1 帧还可以,但是 2 就太晚了.

                  For the beginning I receive first packed after ex. 96ms (too late), and it contains about 1000B. This means 20-50 frames (too much, too late). Later its work more stable, 3-10Bytes but it is still too late because it contains 1-2 frames. Of Course 1 frame is OK, but 2 is too late.

                  你能指出我怎样才能更可靠地处理它吗?我知道这是可能的.

                  Can you point me how can I deal with it more reliable? I know it is possible.

                  修订1:

                  我直接尝试了:

                  private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
                  {
                         if (!serialPort1.IsOpen) return;
                         this.BeginInvoke(new EventHandler(this.DataReceived));
                  }
                  

                  和后台工作者:并且......新的胎面(阅读)和......总是一样的.太晚了,太慢了.是不是必须回到 WinApi 并导入一些 kernel32.dll 函数?

                  And Backgroud worker: And ... new Tread(Read) and... always the same. Too late, too slow. Do I have to go back to WinApi and import some kernel32.dll functions?

                  修订版 2:这是Treading方式中代码使用的一部分:

                  Revision 2: this is the part of code use in the Treading way:

                  int c = serialPort1.BytesToRead;
                  byte[] b = new byte[c];
                  serialPort1.Read(b, 0, c);
                  

                  我猜这是在 SerialPort 类中使用流的一些问题.或者一些同步问题.

                  I guess it is some problem with stream use inside SerialPort class. Or some synchronization problem.

                  修订版 3:我不会同时使用两个!!我只是尝试了不同的方法.

                  Revision 3: I do not use both at once!! I just tried different ways.

                  问候马立克

                  推荐答案

                  也许你应该看看这个 首先,因为这个错误与 DataReceived 事件有关,它有时不会触发,并且在 Framework 3.0/3.5 中仍未修复.另外,您应该阅读一些 这里关于这张海报,当他在 VS2008/NET 3.5 下使用它时遇到问题时向微软报告了这个问题......我不能说这是否属实......但值得记住的是...微软在 .NET 版本 2 中引入的 .NET 版本确实存在一定的困难.

                  Maybe you should read this first, as this bug has to do with DataReceived Event which does not fire at times, and it is still not fixed in Framework 3.0/3.5. Also, you should read something here about this poster who reported the problem to Microsoft when he had issues using it, under VS2008/NET 3.5...I cannot say if that is true or not...but is something worth keeping in mind about...and Microsoft did have a certain amount of difficulty with the .NET version which was introduced into .NET version 2.

                  当时,我正在使用 .NET 1.1,我遇到了使用 VB6 的 ActiveX 控件附带的版本的建议,根据 来源s在互联网上,它是最好的串行通讯控件!!!

                  At the time, I was using .NET 1.1, I came across suggestions to use the version that came with VB6's ActiveX control, which according to sources on the internet, that it was the best serial comms control!!!

                  您可能会更好地调查使用第三方代码来处理串行通信,通常是在托管世界之外编写的那些,即使用大量 p/invoke 的非托管.

                  You might be better to investigate using a third party code to handle the serial communications, usually, the ones written outside of the managed world, i.e. unmanaged using lots of p/invokes.

                  我尝试使用 MSDN 文章 这里,我确实觉得这很令人反感,因为没有办法异步执行它,而且这是一种可怕的编码体验..

                  I have tried using John Hind's version found in the MSDN article here, which I did find very off-putting as there was no way to do it asynchronously, plus it was a horrible coding experience..

                  我最终使用了由 Franson 提供的一个,它比 Hind 的代码产生了更好的结果.

                  I did end up using one supplied by Franson which produced better results than Hind's code.

                  希望这会有所帮助,最好的祝福,汤姆.

                  Hope this helps, Best regards, Tom.

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

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

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

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

                            <tbody id='pqDaU'></tbody>
                          • <bdo id='pqDaU'></bdo><ul id='pqDaU'></ul>