5

I have the following scenario in mind:

I want to send (via serial port) some commands to a device. This device does send me back a continuous stream of data (max. 12000 values per second).

To control some settings I need some buttons to send commands to the device to start/stop/change settings before and during data stream. Also I want to have a real time plot of this data. I will filter this data of course. Also at certain timestamps there will be a signal which indicates that I want to cut out a certain window of the received data.

This means I will have two charts. I made already some progress using WPF but now when I interact (zoom/pan) with the lower chart, the upper one freezes noticeable. This is because both have do be refreshed very often!

Work (data receiving/filtering) is done using threads but the update of the plot has to be done within the ui thread.

Any ideas how to solve this issue? Maybe using multiple processes?

enter image description here

user2799180
  • 719
  • 1
  • 11
  • 29

3 Answers3

3

You should use Reactive Extensions. It was built for this kind of thing.

http://msdn.microsoft.com/en-us/data/gg577609.aspx

Requesting a clear, picturesque explanation of Reactive Extensions (RX)?

On this second link, although the topic is javascript, much of what it says is about Reactive Extensions and cross-applies to Rx in C#.

Community
  • 1
  • 1
philologon
  • 2,093
  • 4
  • 19
  • 35
2

I'm making a similar WPF application with real-time waveforms (about 500Hz). I have a background threads that receives real-time data, a separate threads to process them and prepare the data for drawing (I have a buffer with the "size" of the screen where I put the prepared values). In the UI thread I draw the waveforms to the RenderTargetBitmap which is in the end is rendered to the Canvas. This technique allows me have a lot of real-time waveforms on the screen and have zoom and pan working without any problems (about 40-50 fps).

Please let me know if you need some technical details, I can later share them with you.

I think you have some code in the UI thread that is not optimized well or can be moved to the background thread.

Btw, do you use any framework for charts?

Edit

philologon is right, you should use Rx for real-time data, it simplifies code A LOT. I also use them in my project.

MrZoidberg
  • 350
  • 3
  • 15
  • I use oxyplot. The only thing I do within the UI thread is to give values to the plot and update it. As far as I know, this has to be done in the UI thread. Also if I do not update the plots, I get high fps. Do you have an example how you draw your waves? Maybe this already gives me some hint how to do things better. – user2799180 Oct 18 '13 at 15:31
  • Sure, I will share some examples tomorrow. As far as I know (and I did a small investigation in this area) oxyplot is not very good for real-time data. Indeed you have not very much choices. http://dynamicdatadisplay.codeplex.com/ (http://d3future.codeplex.com/) is good, but very outdated. I wouldn't use it in real project, but for the investigations it's very good. You can use [Direct 2D](http://blog.rthand.com/post/2012/01/10/Realtime-graph-for-WPF.aspx). And you always render charts by yourself which is what I do. – MrZoidberg Oct 18 '13 at 15:42
  • I did also some investigation. I found dynamicdatadisplay, but it is really not up to date. I will have a look at Rx and Direct 2D. Though I would be really interested in your RenderTargetBitmap method. I read already about it but never found a good example. This would be really great. The receiving and processing I do also in different threads. Thanks a lot! – user2799180 Oct 18 '13 at 15:54
  • Hey MrZoidberg, would be great if you could share an example about zooming and panning of the image. I figured out how to use the InteropBitmap to render my images. But maybe your example would give me some better idea. I also tried using SharpDX but it is far more complicated. – user2799180 Oct 21 '13 at 06:32
1

Its a commercial product but there is a real-time WPF chart which can handle this use-case and then some. Please take a look at the Tutorial below:

http://www.scichart.com/synchronizing-chartmodifier-mouse-events-across-charts/

enter image description here

There is a live Silverlight demo of this behaviour here:

Sync Multichart Mouse Silverlight Demo

And this chart should be able to handle zooming while inputting values at high speed:

Realtime Performance Demo

Disclosure: I am the owner and tech-lead of SciChart

Dr. Andrew Burnett-Thompson
  • 20,980
  • 8
  • 88
  • 178