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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading data using OPC connection

I've got a VI that opens an OPC connection and reads in a 1-D array of 560 measurements. Another connection reads in a scan number.

I have both connections in a while loop checking for updates every 100 milliseconds.

What I want to do is read in the array and save it to the first column in a spreadsheet. Then, when the scan number goes up, I want to read in the next array of measurements and append it to the second column of my spreadsheet. (I guess I could use the 'Write to Spreadsheet' example)

I foresee a problem because the scan number and the 1-D array of measurements change at the exact same time. If I try to append the 1-D array to the txt file once the scan number changes, I will already be looking at new data.

Eventually, when the scan number resets to zero, I'll want to save the file and start the process over, while LabVIEW analyzes the spreadsheet I just created.

It doesn't seem hard at all, I'm just trying to get the timing right. The fact that it's a continuous process has me a little confused. Any suggestions?

Thanks in advance!
0 Kudos
Message 1 of 2
(2,139 Views)
It sounds as if you’ve got a basic algorithm worked out for writing the data to the file. However, if you are concerned about the timing, I might suggest using a producer / consumer design pattern. In this scenario, your data can be read from the OPC server in one loop (the producer). This is then sent to another loop (the consumer) through a structure called a queue. With this architecture you can be sure that the data will be written to the file in the correct sequence in the consumer loop despite what value LabVIEW is currently reading in the producer loop. If you are interested in this approach I would suggest taking a look at the producer / consumer (data) design template in the LabVIEW getting started window. I hope this helps!

Mike D.
National Instruments
Applications Engineer
0 Kudos
Message 2 of 2
(2,120 Views)