LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

start stop while loop with each start stop of for loop

Hello,

 

I would like to get help with the following programming case:

 

There are two loops : while loop and for loop running in parallel.

I would like to start the while loop with start of each iteration of for loop and then

stop the while loop at completion of each for loop iteration. A vi is attached.

 

Thank you.

0 Kudos
Message 1 of 6
(3,882 Views)

Hi absmisc,

 

to start/stop the while loop you could use notifiers.

And you need to put your while loop into another loop to be able to restart it again and again...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 6
(3,870 Views)

Why even have 2 loops?  Why can't you just put all of your logic in the FOR loop?  What else is happening in your While loop?



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 6
(3,855 Views)

Your FOR loop iteration will complete in nanoseconds, so the while loop will barely able to do a single iteration during that time. This make your question not reasonable.

 

Why don't you take a step back and explain what the program is supposed to do? How do you use it? What should happen and what would you like to see when it runs?

 

The only important thing is what the user sees, now how it is implemented under the hood.

0 Kudos
Message 4 of 6
(3,839 Views)

Here is what the program is supposed to do:

The for loop: runs scans (iterations) from instr 1 while the while loop collects data from instr 2.

Each scan runs for ~ 45 min.

At end of scan, all the data from the while loop gets dumped into a file whose contents are: scan array from instr1, data array of instr2.

Then a new pair of scan (for loop iteration) of instr1 and data from instr 2 (while loop resets) begins.

When trying notifier I could notify the while loop to stop after a scan but could not reset the notifier after scan got completed to restart while loop. (vi attached).

 

Thanks for your inputs.

0 Kudos
Message 5 of 6
(3,812 Views)

You cannot solve your problem by stacking more and more loops! Also, your notifier never makes it inside the loop, so it will be read once before the loop starts and then never again. The upper inner while loop will either stop after one iteration or continue forever, depending on the value of the notifier and outer while loop will depend on the initial error condition in the same way.

Your while loop in the FOR loop can be deleted and nothing would change. Why is it there? And please don't maximize the diagram and front panel to the screen. They can be small enough so you can see both.

 

You really need to start with a few more tutorials about the principles of dataflow. All you probably need is a simple state machine. Keep count of the iterations and switch states as needed for the functionality.

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