Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF realtime chart application architecture

Tags:

c#

wpf

charts

prism

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

like image 908
user2799180 Avatar asked Oct 18 '13 15:10

user2799180


3 Answers

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#.

like image 118
philologon Avatar answered Oct 19 '22 16:10

philologon


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.

like image 2
MrZoidberg Avatar answered Oct 19 '22 15:10

MrZoidberg


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

like image 1
Dr. Andrew Burnett-Thompson Avatar answered Oct 19 '22 16:10

Dr. Andrew Burnett-Thompson