Showing results for 
Search instead for 
Did you mean: 

queue or local variable to pass between loops

I have a question about... best practices I guess... I've been making data aquisition VIs with data logging, and I usually make two while loops, one loop collects all my data and displays plots of the data (this loop executes faster), and my other loop I just use to write my data out to a file every second (this is my slpwer loop) ok, here's my question... I've been basically using a local variable to pass all my data from my fast loop to my slower loop.  But when I look through LabVIEW material I don't see it done this way much (or at all) I usually see people using something called queue's to pass the data from one loop to another.  Do I need to switch to queues?


If the only problem is race conditions, I don't mind, because I'm logging my data only once per second, and my data acquisition loop is fast so if I get the data from the previous iteration and not right away when I call it, I don't mind (my data isn't changing that fast anyway)



0 Kudos
Message 1 of 7

"Slow", "I don't care" lend me to believe you can get away with using locals to transfer the data, but it is not a "best practive" becuase when you bump up the speed and care about loosing data, that mechanism will start to fail.


The queue is the prefered approach.



Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 2 of 7

its like what you need in your car.. CRDI (QUEUE) or normal injection (locals)




Guru (CLA)
0 Kudos
Message 3 of 7

Local Variable may seems to be easy to setup, but if you get into a habit of using it, it will hunt you.  Queue seems a bit involve to setup at time (relatively), but it is the definitely the preferred way.




Kudos and Accepted as Solution are welcome!
0 Kudos
Message 4 of 7

First is there really a necessity to use 2 while loops. If you can manage to do it in the same loop then it is the best.


Cause there is nothing better then transferring the data through a wire. After all we use labVIEW............ :smileywink:

Message Edited by muks on 03-05-2010 03:13 PM
0 Kudos
Message 5 of 7




i recently started to use the "action engine" (thanks to Ben for the great nugget !). So give it a try !

(if you have a version previous to 9, unfortunately there is a strange bug to the AE, when using waveforms in cluster, otherwise it is great ! it is my most used tool after the state machine !)


Message 6 of 7

An easy way to get started using the queue in your architecture is to start with a Producer/Consumer temaplate as well as running some of the queue examples.


In LabVIEW go to File >> New...

In the dialog box expand VI >> From Template >> Frameworks >> Designe Patterns and select Producer/Consumer Design Pattern (Data)


This will set you up to fill in your code in the slow (consumer) and fast (producer) loop.

Also, take a look at the Queue in the Example Finder.

National Instruments
0 Kudos
Message 7 of 7