From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

How to continuously collect data using VISA class for a serial instrument and read it all out to a text file?

Hello,

 

I'm new to LabView but I have a device that measures position through a serial port and I'd like to continously aquire data for some set amount of time and store that data to a file. I can communicate with the device through the basic serial read and write however I cannot get the program to continuously send a command out to the device and store the response to a file. I have attached what I've done so far.

 

As I said I'm very new to LabView VIs so any help would be appreciated!

 

 

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

You have several problems, but all are easily fixed.

 

1. You while loop only iterates once then ends, because you have a True wired to the termination terminal. Repalce that True constant with a control on the front panel, probably the Stop button from the Boolean controls palette.

2. You should not be using both termination character enabled and Bytes at Port in the same program. Unfortunately the basic serial example is set up that way without commenting on why it should not be routinely done.  If your device sends messages whic end with a termination character, you can simply eliminate the Bytes at Port property node and set the byte count input to a constant value larger than the largest message expected. The VISA Read will wait until the termination character appears and then return all the bytes read.  If your device does not send a termination character, then things become more complicated. In any case you MUST know what protocol is used by the device.

3. To accumulate all the data from multiple reads place a shift register on the while loop. Where you have the Concatenate Strings in the Read case, add an input so that the prior string from the shift register has the new data appended. Note that this will eventually run out of memory if the string gets too large.

4. I notice that you have wired True constants to the case structures. If you will never be using the False cases, simply remove the case structures.

 

Lynn

 

Cumulative string.png

0 Kudos
Message 2 of 3
(4,979 Views)

Thank you so much this has been very helpful! My program works correctly now!

 

 

0 Kudos
Message 3 of 3
(4,897 Views)