0

Currently Im working on a program which will simultaneously take in measurement data from a laser displacement sensor through the serial port and will chart the data live. I have never worked this extensively with I/O in c#, and even less with handling large data sets in the chart control.

Right now Im using a background worker to continuously read data from the serial port and move it into an array, and after each number is read from the port the background worker reports there is a new number available through progress reports. From the reports handeler, I plot this new point on the chart and recalculate the mean, mode, standard deviation, upper and lower control limits, etc. A few other graphs and view ports are updated with the new data as well. This should be able to be done on a continuous basis.

(for those of you who are wondering, Im putting all this info down simply because random suggestions from this site have been a big help in the past)

Now here is my question:

I would like to save the data captured to a text file, but cannot interrupt data capture or plotting to do so. Am i better off to write the data sampled immediately to a text file and only copy the most recent 500 points into an array? I could then start a new text file every 10 minutes or so to keep the size limited, then add a time and a date of data capture for later reference. Is there a way to bind a chart to something like a queue, then each time I add a value to the queue it discards the oldest point? I need a way to dispose of points in the chart series that are older then 500 samples old since it seems to slow down the chart control as more and more points are added.

This is my first shot at multi-threading, so do your best to not jump down my throat if ive done something terribly wrong.

Thanks in advance for all of your suggestions! Any guidance would be appreciated.

Pencho Ilchev
  • 3,132
  • 16
  • 19
user1003131
  • 499
  • 6
  • 20

1 Answers1

0

For your queueing problem, take a look at this thread about a limited-size queue.

For your logging stuff, could you write a second handler, running on a low-priority thread, that logs things rather than graphing them?

Community
  • 1
  • 1
SirPentor
  • 1,914
  • 12
  • 24