views:

462

answers:

1

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:

  • Buffer data and raise buffered data in event at timed intervals (ie 500 milliseconds)
  • Build buffer and let instantiating object poll for buffered data/empty buffer when polled
  • Other (?)
+5  A: 

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

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.

peterchen
Worked like a charm, thanks!
mikeh