LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading instrument data through a serial connection as it is transmitted

I am trying to read an instrument through a serial connection. The instrument automatically transmits data every half second. When I use a serial port read every half second, it works for a while, but eventually the timing gets off (I think) and the program begins reading only half the the transmitted data. Is there a way to read the data as it is transmitted, detecting the line feeds so that I always get a complete transmission/the right amount of bytes? In other words, I have tried to read all the bytes at the serial port every half second so that I get a full line of transmitted data (it varies), but the timing gets off. I would like to read the bytes at the serial port until it reads a line feed so that I don't have to mess with the timing.
0 Kudos
Message 1 of 10
(3,602 Views)

As long as the data has a LF at the end, something like the code below should work. The VISA Configure Serial Port has a enable termination input and the default termination character is a LF. That means that the VISA Read will automatically terminate whenever it sees this character. You can specify some large number of bytes to read and it will just read the actual number of bytes up to the termination character. If there is not so much data that it takes more than 500 msecs to read, the Wait Until Next ms Multiple should keep up with the instrument. If you are doing a lot of processing in the read loop, you might want to move it out so that the read does not fall behind.

Message Edited by Dennis Knutson on 01-11-2007 11:15 AM

Message 2 of 10
(3,598 Views)
What is the " " outside of th while loop connected to the concatenate string bock?
0 Kudos
Message 3 of 10
(3,585 Views)
It's an empty string constant. Look on your string palette.
0 Kudos
Message 4 of 10
(3,582 Views)
Thank you for your reply. I have tried your suggestion and have gotten some things to work. I am working with Labview 4.1 and don't have Visa Serial Init. Will Visa Serial Open work? Also, what are the up and down arrows/triangles at the entrances and exits of the while loop? Thanks again,
 
Spencer
0 Kudos
Message 5 of 10
(3,571 Views)
That's an extremely old version of LabVIEW and if I remember correctly, VISA itself was pretty new at the time. I don't remember what VISA Serial Open even did. If it initializes the com port and enables the termination character, then it might work. Do you know what version of VISA you are using?
 
Those little 'triangles' are a shift register. I would point you to the learning LabVIEW resource page but I don't know how much that would help with version 4.1.
0 Kudos
Message 6 of 10
(3,563 Views)
Thank you so much. I pieced my program together from a few different examples, but the shift registers were the last piece I needed to get it working.
0 Kudos
Message 7 of 10
(3,541 Views)
I have another question that involves this same program. The program is reading my instrument continuously, as the instrument transmits the data. I record the millisecond timer value each time a full line of data is sent (a line feed is read), and the time difference is usually 256 ms, but sometimes 192 ms or other multiples of 16 ms. I would like to be able to record the data (write it to file with a time stamp) at 2 Hz, 1 Hz, or slower. If I just record every fourth data line, I get approximately 1 Hz, but not quite. I have tried to put another wait until next ms multiple outside the first loop to just record the current data line at the specified frequency, but it messes up the first loop. How can I get the timing to work right?
0 Kudos
Message 8 of 10
(3,501 Views)
In your original post you said that the instrument was sending at 2 Hz, but now you seem to be receiving at almost 4 Hz. The instrument should be driving the timing. How accurate is its timing?

Is there something in the instrument which causes it to run on 16 ms increments?

Lynn
0 Kudos
Message 9 of 10
(3,493 Views)

The documentation on the instrument says that is transmits every half second, but I found out after I got my program working that it is actually close to 4 Hz; I even checked to make sure that I'm getting a unique reading every quarter second. I don't know why it is only in multiples of 16 ms and I can't change the frequency that the instrument automatically transmits data. I posted a jpg of that part of the program, is there something there that is messing stuff up?

Spencer

0 Kudos
Message 10 of 10
(3,487 Views)