开发者

Plot data from the serial port

开发者 https://www.devze.com 2023-02-23 04:25 出处:网络
I got a serial port in .NET at 9600 baudrate. The incoming dat开发者_Go百科a is numeric, it\'s the time between 2 pulses of a motor encoder, it\'s the RPM of the motor actualy.

I got a serial port in .NET at 9600 baudrate. The incoming dat开发者_Go百科a is numeric, it's the time between 2 pulses of a motor encoder, it's the RPM of the motor actualy.

How do I plot the data in real time?


A simple plotter is fairly easy to do. You can spend hours looking for a just right library or program or just write your own in equivalent time.

Here is how I have done it in the past

  • Allocate a circular buffer - about 2-4K data points should be sufficient
  • take your serial data store it in the serial buffer
  • get a drawable area
  • map the height of the drawable area to the maximum - minimum value you wish to display
  • map the width of the drawable area to the number of points you wish to display
  • start a thread which takes in the serial data, parses it and puts it in the circular buffer,
  • start another thread which checks for new data in buffer periodically, plots the data in the circular buffer on a back buffer and then updates the drawable area displayed with the backbuffer.

I had a similar issue some time back. I looked for a simple, light program that would do it do out of the box. I finally gave in and coded my own program using Win32 calls. A .NET implementation would be simpler.

http://www.fast-product-development.com/real-time-serial-data-plot.html


There is an example on the arduino playground that does that, you should check it.

Or as a general purpose and more flexibility you could use Firmata, it gives you the ability control you arduino remotely from your computer (digital_write, digital_read, analog_write, analog_read...), plus there is FirmataVB, it's a .NET component class library that contains methods to send and receive messages using the Firmata V 2.0 protocol, so you don't need to get your hands dirty, just load firmata on your arduino , use the library, and you're done

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号