C#.NET串行DataReceived事件检索响应高速率数据太慢 [英] C# .Net Serial DataReceived Event response too slow for high-rate data

查看:1296
本文介绍了C#.NET串行DataReceived事件检索响应高速率数据太慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了SerialDataReceivedEventHandler,具有形式VS2008基础的计划表示。我的串行端口设置如下:



115200,8N1



DTR和RTS启用



ReceivedBytesThreshold = 1



我有我与通过蓝牙,USB转串口接口的设备。超级终端在任何数据速率接收数据就好了。该数据在22字节长包定时发送。该器件具有在该数据发送可调整利率。在低数据速率,10-20Hz,下面的代码的伟大工程,没有任何问题。然而,当我过去增加25Hz的数据速率,但开始在一个呼叫收到多张包。我的意思是,应该有一个事件触发每一个进入的数据包。凭借更高的产出率,我已经测试过的缓冲区大小(BytesToRead命令)立刻当事件被调用,并有多个数据包缓冲区中,然后。我认为,事件触发缓慢通过它到达代码的时间,更是否解决砸中缓冲区。一个测试我做的是看事件有多少时间是每秒触发。在10Hz的,我得到10事件触发,真棒。在100Hz,我得到的东西像40事件触发,也不好。我对数据速率的目标是100HZ是可以接受的,200Hz的首选,而300Hz的最佳。这应该工作,因为即使在300Hz以下,也就是只有52800bps,小于设定波特率115200的一半。 ?什么我俯瞰

 公共Form1中()
{
的InitializeComponent();
serialPort1.DataReceived + =新SerialDataReceivedEventHandler(serialPort1_DataReceived);
}


私人无效serialPort1_DataReceived(对象发件人,SerialDataReceivedEventArgs E)
{
this.Invoke(新的EventHandler(Display_Results));
}


私人无效Display_Results(对象S,EventArgs五)
{
serialPort1.Read(IMU,0,serial_Port1.BytesToRead);
}


解决方案

你尝试以调整时间等待时间上的USB串口转换器?我有同样的问题与FTDI USB转串口转换器。我用示波器看到我的IN和OUT数据从设备快到了,我看得出来,电脑总是反应慢。缺省情况下,设备上的时间延迟设置为16毫秒。我改成了2毫秒,它使一个很大的区别。转到您的USB串口转换器在设备管理器,并在高级设置中,等待时间更改为2毫秒。它应该工作。试试吧。


I have set up a SerialDataReceivedEventHandler, with a forms based program in VS2008 express. My serial port is set up as follows:

115200, 8N1

Dtr and Rts enabled

ReceivedBytesThreshold = 1

I have a device I am interfacing with over a BlueTooth, USB to Serial. Hyper terminal receives the data just fine at any data rate. The data is sent regularly in 22 byte long packets. This device has an adjustable rate at which data is sent. At low data rates, 10-20Hz, the code below works great, no problems. However, when I increase the data rate past 25Hz, there starts to recieve mulitple packets on one call. What I mean by this is that there should be a event trigger for every incoming packet. With higher output rates, I have tested the buffer size (BytesToRead command) immediatly when the event is called and there are multiple packets in the buffer then. I think that the event fires slowly and by the time it reaches the code, more packes have hit the buffer. One test I do is see how many time the event is trigger per second. At 10Hz, I get 10 event triggers, awesome. At 100Hz, I get something like 40 event triggers, not good. My goal for data rate is 100HZ is acceptable, 200Hz preferred, and 300Hz optimum. This should work because even at 300Hz, that is only 52800bps, less than half of the set 115200 baud rate. Anything I am over looking?

    public Form1()
    {
        InitializeComponent();
        serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);            
    }


    private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
    {
        this.Invoke(new EventHandler(Display_Results));
    }


    private void Display_Results(object s, EventArgs e)
    {
        serialPort1.Read(IMU, 0, serial_Port1.BytesToRead);
    }

解决方案

Did you try to ajust time latency on the USB serial converter? I had the same problem with a FTDI USB to serial converter. I use an oscilloscope to see my IN and OUT data coming from the device and I could see that the computer was always slow to respond. By default, time latency on the device is set to 16 ms. I changed it to 2 ms and it makes a big difference. Go to your USB Serial Converter in the Device Manager and in the advanced settings, change Latency time to 2 ms. It should works. Try it.

这篇关于C#.NET串行DataReceived事件检索响应高速率数据太慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆