LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Restarting a while loop

Highlighted
while my program is running, I need to restart a while loop from a boolean control, or some other control. But once I stop the loop I cannot restart it. Can anyone help?
0 Kudos
Message 1 of 10
(11,637 Views)
Highlighted
Try putting the loop you need to restart inside a case structure, and put that inside another while loop. When the inner loop stops, keep the outer loop running with your boolean control on the case structure preventing the inner loop from running.

When you want to restart the inner loop, toggle the boolean to switch to the case with the inner loop and it will start running again until you stop it and control will return to the outer loop again.

Use a shift register on the outer loop to pass the boolean value for the case structure.

Ed


Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
Message 2 of 10
(11,637 Views)
Highlighted

Thanks Ed Dickens, It also helped me.

0 Kudos
Message 3 of 10
(8,768 Views)
Highlighted

Instead of having loops inside loops, you can do everything with a single loop and a proper state machine architecture. Instead of stopping the loop, you simply go to the idle state while staying inside the loop.

 

Don't overcomplicate things.


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
Message 4 of 10
(7,829 Views)
Highlighted

Hi Folks,

 

does it make sense to make a while in case in while structure if the inner loop is a timed loop?

aiming to free up some ressource? 

 

best regards

Sergio

0 Kudos
Message 5 of 10
(7,264 Views)
Highlighted
Why would that "free up resources"?

LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 6 of 10
(7,221 Views)
Highlighted

Because a Timed Loop is (normally & in my case) way faster than a simple while. So LabView would have more time to do some other things than running a time critical loop with idle state, or am i wrong?

0 Kudos
Message 7 of 10
(7,182 Views)
Highlighted

A time loop is more precise, but that has nothing to do with efficiency. Typically the loop timing is determined by a wait statement or by the timed loop configuration. Only if the loop contains more code than an be executed in the allocated time, the loop timing will depend on the exection time of the code inside the loop. Since this is highly dependent on the computer hardware, it should typically be avoided.


@LeonardoD wrote:

Because a Timed Loop is (normally & in my case) way faster than a simple while.


What you are describing makes absolutely no sense.

 

Can you attach an example of the two types of loops, what they are doing in your code, and how you are measuring the "speed" (whatever that means).


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 8 of 10
(7,174 Views)
Highlighted

I am using a while loop to gather data from a spectrum analyzer and I would like for it to go quiet after getting the last sample. However simply stopping the loop leaves me with a dead loop that I can't restart. Using your state machine example sounds good but as I have only recently started using Lab View I am a little flummoxed on how to proceed. Would I place a SM inside the main while loop and then route signals through it? Can you point me to some suggested study material that may help?

AF6ND On the Air
0 Kudos
Message 9 of 10
(2,335 Views)
Highlighted

Look at the design templates that ship with LabVIEW. There are also example programs.


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 10 of 10
(2,334 Views)