LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

convert data from serial port to real time plot

Well, this is way too many posts in a row, but I took the last 2 minutes and just put together the chart plotting one as well, so hopefully you can learn more from it.  Basically, the attached VI reads line by line from the attached file, and plots point by point to the waveform chart.  You will have to replace the File I/O stuff here with your Serial I/O VIs, and you'll probably want to replace the FOR loop with a While loop if your sensor outputs continuously.
 
I hope this helps and have a great weekend!
 
Best Regards,
 
JLS
Best,
JLS
Sixclear
Download All
0 Kudos
Message 11 of 34
(2,204 Views)

Hi,

I have deleted the file i/o parts of your generously donated vi and have converted the for loop to while loop. At least I am learning something Smiley Wink. I have a problem trying to wire the serial terminal I am using with your graphing vi.If I can send the data to the chart then 95% of work is done. The 5% would involve exporting the plot data to a csv file when I am finished with a measurement.

Regards,

Frank

 

 

 

0 Kudos
Message 12 of 34
(2,189 Views)
Hello,
 
I don't have the serial VIs so things are broken when I open the VI you attached, but I did see the part of code that I attached included there.  Basically what I think you have to do is almost exactly replace my file I/O stuff with your serial I/O stuff.  In the case where I posted the VI that reads line by line... the reading from file was to simulate the reading from the serial port... if you can read the number of bytes you expect for one line exactly, then it should parse your data correctly.  Another option is to read until you find a \n (linefeed) character since I think all your lines end with that... then you'll read just a single line using that method on each iteration.  This will allow you to plot your data point-by-point as it comes in, IF that's what you want to do.
 
From the looks of it, you won't be able to just drop your previous code in...
 
Also, is there a reason you're not using the VISA api to access your serial port?  It is a very simple API and will be similar to the file I/O api, where you can basically replace File open, read, and close with VISA open, read, and close.  The only other thing you'll have to do just after the open (outside of any loops usually) is to use the VISA Configure Serial Port VI to make sure your serial communication properties such as baud rate etc match those of the device you're communicating with.
 
I hope this helps you get a better understanding of the application!
 
Thank you and best of luck on the next iteration!
 
JLS
Best,
JLS
Sixclear
0 Kudos
Message 13 of 34
(2,170 Views)

Hey,

Been trying to get this thing done and have looked at other serial port vi examples but the one I found from this website is the one that behacves most like the hyperterminal program. http://sthmac.magnet.fsu.edu/labview/vi_library.html

The spec of the sensor I am using and the way it cmmunicates through the serial cable is talked about in this file:

http://www.sparkfun.com/datasheets/Acceler...SerAccel-v5.pdf

Other serial read vis even in the labview examples do not seem to read continiously or have other issues which prevent me from graphing the output of the sensor. To be honest, my labview experience is beginner level and i excited at all the possibilities of the program but I need to try and get this thing done soon as the volunteer group i am helping needs it.

I have a serial program that gets the data from the sensor. I have the graphing part of the vi which you so generously gave me. I am including the full libray of the serial terminal. The newbie forgot you needed the extra files for it to work!. So I would like it to take the output of the response box and graph it versus time.  I would the graph to refresh it self after x number of seconds (30-60secs). I could tell the rower the last peak of accelleration data was good, repeat it a couple of times. So having previous data on the graph would be useful. The rate of data from the sensor could vary from 15-50 points per sec.

Another suggestion made by a labview coder was to use the serial terminal vi above but add the extract numvers.vi (a sample string vi in the labview program) as a SubVI to parse the data.

Add the chart vi to the loop if the serial terminal vi and feed the string from the latest output of the sensor in the String Server read into the Extract Numbers.vi subvi, take the output array from Extract Numbers.vi and put it into an Array to Cluster conversion node and then into the Chart. I have trying that as well but wiring errors are making me go nuts :-0

Hope you can help again. Life would be easy if I did not need to graph the output of the sensor while the rower takes a stroke but its the only way the person can learn to react to the feedback from the accelerometer sensor.

Frank

 

 

Download All
0 Kudos
Message 14 of 34
(2,156 Views)
Hello,
 
I looked at your screenshot, and I think there is a misunderstanding.  I am not sure what you were attempting in the top part of your original code, but the code that I last posted was meant to give you the tools necessary to entirely re-write your program.  I have replaced the for loop with a while loop, and replaced the file i/o code with VISA operations.  You should be able to use that API to access your serial port to read the data coming from your sensor.  I would literally try running the attached code here and just see what happens. If the data is formatted as you originally indicated, the attached VI might just get you started.  You will need to put the name of the com port you are accessing on your machine in the VISA resource name control, and also check that the baud rate, number of data bits, parity, and stop bits match those used by your device - if the defaults used by the VISA configure serial port vi doesn't match nose, you should create constants from those terminals and enter the correct values to match your device (see the block diagram for organized comments).  You can leave the other terminals unwired, because I think your device is ending all it's transmissions with a linefeed character, and the read operation will actually use the fact that termination is enabled (by default in the visa config VI) to terminate - that's why there is a 100 wired to the read VI... it will actually exit on each iteration after the termination character is received.
 
My suggestion is to use that model for your data acquisition from the serial port.  If you need to use a different model because we have miscommunicated something, then hopefully you can use code and the comments to learn about the necessary functions so that you can begin implementing more precisely what you need.  If you feel that you are having trouble understanding wiring and the errors you are receiving while building a block diagram, you may benefit from going through some LabVIEW tutorials on the web, or taking a formal training class.  For a tutorial, check out the the following to start: LabVIEW Introduction Course - Six Hours
 
I hope this helps!
 
Best Regards,
 
JLS
Best,
JLS
Sixclear
0 Kudos
Message 15 of 34
(2,149 Views)

Thank you for the link to the course and I look forward to using it 🙂 Your serial reader with the appropriate settings reads the data from my sensor. But the line feed termination does not seem to work and it reads the whole line of data one time and then the next time it reads only part of the data.  X=0.2 Y=0.01 Z=0.322 is shown when it reads the data properly but then it reads only X=0.3 while rest of the line is missing. I found that the termination character used was the $ sign. ax0 was for line feed and I tried to ax24 ($) as the termination character but that did not seem to solve the problem.

If the vi could be set to start at # and terminate at $ would that solve the inaccurate of the data from the sensor? The sensor can also output the data in raw format rather than numbers. X=0x01A2 Y=0x0255 Z=0x0340

Maybe this might be easier to deal with it than the other format? Thanks again for all your help and suggestions.

Frank.

 

0 Kudos
Message 16 of 34
(2,122 Views)

oopps forgot this piece of information about the data output of the sensor.

 

Byte     Description

0          Start Char- #

1          Data output designator- @

2          Sample No High Byte

3          Sample No Low Byte

4          X Hi Byte

5          X Lo Byte

6          Y Hi byte

7          Y Lo byte

8          Z Hi byte

9          Z Lo byte

10        End Char- $

 

0 Kudos
Message 17 of 34
(2,123 Views)
Hello,
 
Well, if you know that you receive exactly 11 bytes each time, then you can just read exactly that many bytes from your serial port, and disable termination using the corresponding input on the VISA configuration VI.  That is, if you know that each line is EACTLY the same number of bytes, you can just read that many bytes instead of relying on the detection of a termination character.  If your line size varies, you will want to use a termination character.  To be honest, since I don't have the device here to actually see the data being returned, I can't give you all the specific details about how you need to program.  You are going to have to understand how to program in LabVIEW, how your sensor returns the data, and then simply program accordingly.  In case this is a point of confusion, let me explain in more detail how the VISA read operation will take place:
 
The VISA read VI you see on your block diagram will exit on a given iteration and return data to you IF any of the following occur:
 
1. you receive the number of bytes you specify in the input
2. you receive a termination character AND you have termination enabled
3. you receive an error, such as a timeout error which can occur if neither 1 nor 2 occurs before the timeout period set.
 
Thus, the last code I posted for your was trying to specify MORE bytes that necessary to read a single line, in order let condition 2 cause the read function to stop on each iteration.  However, as I noted above, if you know WITH CERTAINTY that each "line of data" has exactly the same number of characters, then you can simply read EXACTLY that many characters on each iteration of the loop.  If you do this, you'll want to set the VISA Configure Serial Port VI's "termination" input to FALSE so that it doesn't terminate prematurely on the termination character.  IF you need to set the termination character to a different value, all you have to do is wire that value to the termination character input and leave the termination input unwired (or wire TRUE to it - that's the default if you don't wire it).  Keep in mind that if you wire the value for specifying a termination character, you need to wire the integer which defines that character's ASCII value.  More specifically, you also need to make sure you are representing that integer in the right way.  By that I mean, hex 63 is NOT the same as decimal 63.  For a table of ASCII characters, as well as basic serial concepts, click here.
 
As a final note, if you are having problems communicating with your serial port using VISA, you should post those questions to the instrument control forum.  This question started about how to plot data you already acquired, but I think you are now having trouble with serial communication and how to actually get the data from your serial port.
 
I hope this helps!  Sometimes it helps to just acquire a bunch of data from your serial port, look at it in a string indicator, and then design your code to handle whatever you see as the pattern coming from your device.
 
Best Regards,
 
JLS
Best,
JLS
Sixclear
Message 18 of 34
(2,106 Views)

This does not make sense even if the protocol is fixed length.

Since the ascII values of "#", "@", and "$" can be contained in the data field of this packet there is no way to distinguish the envelope from the data.

Ben

 

Message Edited by Ben on 03-29-2006 11:18 AM

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 19 of 34
(2,104 Views)
Hi Ben,
 
Thanks for the input. The specification of the sensor allows three forms of output.
 
Calculated Gravity values
X=0.2 Y=0.01 Z=0.322
 
Raw format
X=0x01A2 Y=0x0255 Z=0x0340
 
Binary Format
#---------$
 
I have looked at the binary format of the sensor through hyperterminal and might show you what it looks like. Page 3-4 of the attached pdf file shows how the sensor sends data to the computer through the serial port. Maybe you can deciper how it is sending data to the computer, if you feel it does not make sense.
 
Frank
0 Kudos
Message 20 of 34
(2,099 Views)