LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

convert data from serial port to real time plot

Hi Frank,

No problem about any confusion!  There is something nice about your binary format - that is each "packet" is precisely 11 bytes.  Thus, once you have "synchronized" you can just read 11 bytes at a time, and you know you'll have a single packet of data, which you can pull apart and manipulate.  So the problem becomes getting to the point where you can just read 11 bytes at a time, pull apart that data, and plot it - we'll address this after an important point:

Something which may have been overlooked to this point but can be helpful to keep in mind as a concept, is that your serial port has a buffer which your data is stored in, and all data is transmitted and therefore received one byte at a time.  Therefore, when you read, you are actually reading from this buffer - this is a good thing because you don't have to be constantly reading from the port!  Instead, as your program will do, you can read a portion of the data (say 11 bytes ;), then process those 11 bytes, then read 11 more bytes, then process those 11 bytes, etc... and comtinue that cycle for all your data points, and you don't miss any data because each time you read from the buffer you are reading from where you last "left off" (you can think of it as a queue structure where data comes in on the serial port at one end, and you read it in the order it was received from the other end).

Now to the issue of synchronization.  The idea is that, once we know exactly where the START of a packet is, we know that we can continue to read subsequent packets easily (just 11 byes each).  Now, this would seem to be easy because we would hope we could just look for the # character.  The fundamental problem is that, IF your sensor is always transmitting, and THEN you start your program, your program will open the serial port and just start receiving whatever data is coming in, and this could be RIGHT IN THE MIDDLE of one of your data packets!  For example, suppose you receive, say, the low byte of your X data first AND it happens to have the same ascii representation as the # character.  In this case, we would incorrectly start reading 11 byte chuncks thinking they were packets, but we would really be reading 11 byte chuncks which start in the middle of one packet and end in the middle of another. 

One simple solution comes to mind; here's the outline:

0. Make sure you start your program BEFORE you start your sensor sending data to the serial port.

1. Architect your program as:

a). First wait for the arrival of a first byte of data (bascially your program waits for you to turn on or plug in your sensor).  Use the technique I used in the last program I posted with VISA functions to wait for the first byte (the first serial character) to arrive.

b). When you receive the first character (the VISA event VIs will proceed) then enter a loop which reads 11 bytes, parses, converts, and graphs the data... the loop continues until your data stops coming, after which time you could return to the WAITING for a character stage.

If you have the ability to start your program before your sensor starts transmitting anything, AND you sensor ONLY tranmits packets in that binary form, then the technique above should work and require a fairly small amount of code to implement.  And best of all, most of the techniques are shown in the examples that are attached in this thread!

Best Regards and looking forward to your success!

Thank you,

JLS

Best,
JLS
Sixclear
Message 31 of 34
(987 Views)

Hello guys,

 

am a newbie to labview and currently working on my student final project, but I have encountered a problem extracting both the voltage and current values from hexadecimal string read at VISA read buffer. Also I want to discard the header string each time so I can only process only the voltage and current hexadecimal string. My string of data read is as attached. AA55 0023 0034 AA55 0045 0132 AA55 ..... Where AA55 is header I want to discard. The next 2 bytes after the header represent the voltage, while the next 2 bytes represent the current. After 6 bytes, the header(AA55) appears again. 

 

So far I read the data at VISA read as in VI attached, and I would appreciate all the help in successfully extracting only the voltage and current values each time the header(AA55) is read at raw data. I have read various forums regading this topic but none seems to click yet. Thank you once again!

 

The VI am working on is attached and some failed attempts in print screens.

Download All
0 Kudos
Message 32 of 34
(510 Views)

I'd recommend starting a new message thread with your question rather than posting to the end of a very long, 9 year old message thread.

 

But to get you started, if you know how many bytes you are trying to read, I would recommend reading that many bytes reather than using the Bytes At Port method which is very likely going to leave you with short messages.

0 Kudos
Message 33 of 34
(500 Views)

Thanks RavenFan for the reply,

 

I have followed your advice and started a new thread instead. Apologies, first time using ni forum. Yes, I want to read in total 6 bytes per complete data frame but always exlude the header characters AA55. I just can not get my head around how to read only the 6 bytes, as my data from the instrument has no termination character expect the repeative sequence AA55 in the the values I want to extract and plot. 

 

Gavin.

0 Kudos
Message 34 of 34
(488 Views)