如何使用c#.net中的计时器功能快速接收串口数据? [英] How to serial port data received quickly with timer funtion in c#.net?

查看:695
本文介绍了如何使用c#.net中的计时器功能快速接收串口数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在开发小型桌面应用程序,(即)从端口读取和接收数据并填充到文本框。直到这个成功运行,没有定时器功能,它将需要至少5分钟来读取和接收。



我的问题是,如何从端口快速读取和接收数据,是它可以用定时器功能吗?



请检查我的代码,我附上它...并且假设数据没有得到,它会显示一些错误信息...... 。



Hi,
I am developing small desktop application , (i.e) Data read and received from port and populate to text box. til this successfully run, without timer function and it will take minimum 5minits to read and received.

My Problem is , how to data read and received from port quickly, is it possible with timer function?

please check my code , i attached it...and also suppose data is not get ,it will show some error message....

private void postDataRecieved(object sender, SerialDataReceivedEventArgs e)
        {

            if (recievedData == null)
            {
                recievedData = new StringBuilder();
            }

            recievedData.Append(devicePort.ReadExisting());
            if (recievedData != null && recievedData.ToString().Contains("</pit>"))
            {
                recievedData.Replace("\0", "");
                char[] x = { '\0', '\n', ' ' };
                this.Invoke(new updatetextboxdelegateCallback(setXMLValues), recievedData.ToString().Substring(1));
                recievedData.Clear();
                recievedData = null;
            }
            if (recievedData != null && recievedData.ToString().Contains("</start>"))
            {
                recievedData.Replace("\0", "");
                char[] x = { '\0', '\n', ' ' };
                this.Invoke(new updatetextboxdelegateCallback(setXMLValues), recievedData.ToString().TrimStart(x));
                recievedData.Clear();
                recievedData = null;
            }
            


        }









先谢谢,





Thanks in Advance,

推荐答案

我没有看到使用计时器的意义。只需处理 DataReceived [ ^ ]事件。
I don't see the point of using a timer. Just handle the DataReceived[^] event.


这篇关于如何使用c#.net中的计时器功能快速接收串口数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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