LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

one while loop vs many while loops

Hello,
I have a data acquisition application that collects data from many different devices. I have developed subVIs to collect one data point from each of the different devices. I would like for these VIs to continuously collect data and write it to a data file. Would it be better to:
a) place all the subVIs in one while loop, or
b) run each subVI in it's own while loop
Thanks
0 Kudos
Message 1 of 6
(3,894 Views)

It depends on timing.  If you place all subvi's in one loop, and have data dependency between the subvi's (like Error Out of one going to Error In of another), they will execute one at a time.  The next data collection won't happen until all subvi's have executed once.  You could put them all in one loop and not connect wires from one to the other, and then they will all execute in parallel.  But one subvi that is faster than another would collect its data and would have to wait until the slowest vi is done before the next loop iteration tells it to collect again.  If you put each subvi in its own loop, they would each run in parallel, and the fastest one would not have to wait for the slowest one to finish.

So it depends on timing.  Whichever method you choose, be sure to put a delay in each loop (even 1mS) to give the CPU time to process other functions.

- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 6
(3,884 Views)

Thanks Tbob

In that case, since there are no dependencies btwn the subVIs, I will place them all in one big while loop so that I can wire the output of each subVI to a "write data to file" subVI that will run at the while loop rate.

This brings me to another question:

Will LabVIEW allow me to call the same subVI multiple (to access different instruments) inside of the while loop? In other words, if the data collection is happening in parallel, will I be able to use multiple instances of the same subVI simultaneously?

Thanks again.

0 Kudos
Message 3 of 6
(3,879 Views)
You would have to make the subvi Reentrant.  Then each time it is called, it will create a new memory space for that instance, and you can have several instances run at the same time.  Click on File - VI Properties - select Execution in Category drop down menu, and check Reentrant execution.  I don't use reentrant vi's but I believe there are some gotcha's about them.  Maybe someone else can chime in and speak of reentrant vi's.
- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 6
(3,864 Views)

"Will LabVIEW allow me to call ...multiple instances of the same subVI simultaneously?"

Depends....

Is the subVI re-entrant?*

Are all of the VI's called by the subVI re-entrant?

Does the subVI show its Front Panel?**

If using VISA are you up to date on driver verions?***

If you clear all of the above you are on your way. Smiley Happy

Have fun,

Ben

*A re-entrant VI will allow simultaneous execution by creating unique data spaces for each instance of the subVI.

**Prior to LV8, LV would allow the viewing of one intsance of a re-entrant VI and that required double-clicking on the instance you wanted to view. Smiley Surprised

***In GPIB applications that used multiple devices would occationally force LV to execute as single threaded. Smiley MadSmiley Tongue Has been fixed since about LV8.

Message Edited by Ben on 01-09-2007 06:27 PM

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 5 of 6
(3,862 Views)

Thanks guys,

I will make the particular subVI reentrant and see how it goes.

0 Kudos
Message 6 of 6
(3,856 Views)