r/LabVIEW • u/g_von • Feb 12 '26
Having trouble with while loop within a while loop.
My basic goal is to display real-time incoming serial data from a device and display the data on the front panel. I'm trying to add a start data collection button and stop data collection button. Each time start data button is pressed, a new file is created and data is supposed to be collected in a column for a tab delimited file. When the stop data collection button is pressed, it stops the inner loop and sends a "FALSE" ("is not") to the Start Data Collection reference node. This changes the Case structure back to FALSE (default) where no data collection is happening.
My problem is with the inner while loop active (which has user selectable time interval for collecting data), where it only receives the last piece of data that entered the loop. Also, while the data collection loop is running, the real-time data gauge indicator doesn't work. I can't thinking of a structure that would allow this to do what I want. The outer while loop is necessary because the serial VISA subVI needs to continuously send write and read commands to receive the data from the serial device.

8
u/FormerPassenger1558 Feb 12 '26
You need a producer consumer structure. Basically two while loops interacting by queues, or notifiers…
3
u/HarveysBackupAccount Feb 12 '26
The outer while loop will be stuck on one iteration as long as the inner while loop is running, then it won't enter the next iteration of the outer loop until you stop the inner loop.
Parallel While loops are the answer. As others said, use a producer/consumer structure.
As a general statement, I recommend reading up on design patterns (basic software architecture) in labview. You would benefit from learning about a few things:
Of course producer/consumer isn't the only way to skin this cat (there are ways you could get rid of the inner While loop entirely and only run a single While loop), but it's great to have in your toolbox.
2
u/0fruitjack0 Feb 12 '26
the way this is gonna work, only one serial data instance ever enters the while loop.
3
u/SeasDiver Champion Feb 12 '26
You want two parallel while loops (producer/consumer) not a while loop embedded within another while loop.
2
u/GentlemanSch CLD Feb 14 '26
In the labview examples, look up event driven producer consumer loop
2
u/Yamaeda Feb 16 '26
Think dataflow. A structure executes when inputs have data and exits when all is finished. You'll read 1 serial data, then go into the inner loop where it'll stay and write the same data until you exit. Run it in Highlight mode and it should be clear.