如何图形流数据在C# [英] How to graph streaming data in C#

查看:200
本文介绍了如何图形流数据在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要绘制流式数据(9600波特),这是来自串行端口的2-4字节数据包。数据包需要在绘制之前进行处理。目前,我在每个完整的数据包上产生一个事件,这导致了绘图形式的响应问题。

I need to graph streaming data (9600 baud), which is coming in 2-4 byte packets from a serial port. The packets need to be processed before graphing. Currently, I am raising an event on each complete packet, which is causing responsiveness issues on the graphing form.

这是此问题的最佳解决方案:

Which is the best solution to this issue:


  • 以定时间隔(即500毫秒)缓冲数据并提升缓冲数据

  • 构建缓冲区并进行实例化轮询时缓冲数据/空缓冲区的对象轮询

  • 其他(?)

推荐答案

我肯定会限制更新率。对于这样的应用程序,每300ms通常就足够了。

I would definitely limit the update rate. For such applications, one each 300ms usually is enough.

基于这一点,一个好的实现将是工作线程读取串口并将其添加到缓冲区。 UI线程可以使用定时器来查询数据并更新显示。

Based on that, a good implementation would be a worker thread that reads the serial port and adds it to a buffer. The UI thread can use a timer to query the data and update the display.

使用单独的线程,工作线程可以以更高的优先级运行,从而负载尖峰可能延迟显示更新,但没有数据丢失。

Using separate threads, the worker thread can run at higher priority, so that load spikes may delay display updates, but no data is lost.

一个额外的技巧是不使用固定的计时器,但更新完成后重新启动计时器。因此,如果更新需要大量时间,例如由于系统负载过高,您的更新速度变慢,有效地减少了负载。

One additional trick is not to use a fixed timer, but restart the timer after the update is complete. Thus, if the update takes significant time e.g. due to high system load, your updates slow down, effectively reducing load.

这篇关于如何图形流数据在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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