LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to collect periodic data over RS232?

I'm using Labview 6i to collect data from a device over RS232.  The device manual says that it delivers data digitally by sending 10 bytes every 100ms.  I'm using VISA Write to send an initialization string, and then I step in to a loop containing VISA Read set to read data synchronously, set to read 10 bytes of data.  I have tried a number of things to get this to work:

Adding a wait to the loop and varying the wait time
Increasing the bytes read from 10 to 15 and filtering out the specific 10-byte set I want to read
Taking out the wait completely and letting the loop run untimed, limited by the VISA Read node

The problem I encounter is that often the VISA Read node returns a set of data that is "shifted".  In hex, my 10-byte set should look like this:

FFFE 0106 04 FF FF FF 45 D4

Where the FFFE 0106 04 acts as a header.  Often the 10 byte set I retrieve contains some bytes from one set, and some bytes from the next set; so, the header might lie in the center or at the end of the 10-byte set rather than at the beginning (in which case there is some data lost at the leading and trailing ends)

One thing I have tried is throwing out "bad" sets, but then I am losing data and not getting the full 10 data points per second that the device is capable of.

When reading data like this, where a set of bytes is sent periodically, how can you ensure that every set is properly read?


0 Kudos
Message 1 of 4
(3,040 Views)

To deal with streaming data in I like the following:

Initialize.

Loop

wait some nominal amount.

Read serial and append to a shift register string initialized to an empty string.

Pass the string through your string parser before returning to the shift register. 

EndLoop

Close Visa.

 

Works very well for me.  I usually dont use a loop but convert the whole thing to an action engine with modes initialize,read, and close then I can easily drop it into a state machine architecture (the loop wait is gone) with nice results.

Paul

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
Message 2 of 4
(3,032 Views)
Ah, yeah, I like the state machine solution, and using shift registers.  That should do it for me.

Thanks!
0 Kudos
Message 3 of 4
(3,023 Views)
When working with a device that is essentially streaming data back to the computer you have to take on the responsibility of  parsing the response and breaking it up into individual messages. One good thing in your favor is that you have a well defined header that you can search for in the datastream. The nice thing about the shift register approach is that you can parse as many or as few packest as you want. Moreover at the leasurely rate the device is passing data LV should be able to more than keep up with the flow.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 4 of 4
(3,012 Views)