LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

stopping a while loop from outside the loop

Is there a way for a front panel control that is not in a loop to pass a value into a while loop? Basically I have a program that will have multiple loops and I would like the ability to stop the program from outside the loops with one singular button that will work on any loop while the loop is still running.

 

A very simple diagram of what I would like to do is attached. I realize that the attached VI will not perform what I would like it to, but it demonstrates what I would like to accomplish.

 

Thanks!

 

Justin

0 Kudos
Message 1 of 13
(9,087 Views)

I wasn't able to look at the example.  Have you tried "or"ing in a control via use of local variables?

 

I'll make an example if that isn't enough.

0 Kudos
Message 2 of 13
(9,084 Views)

Thanks for the suggestion.

 

Local variables will work, as long as the mechanical action of the button is not latching, if there is no other way, I will use this solution, but I was hoping for something that will allow me to keep the latching functionality of the button.

 

Thanks!

 

Justin

0 Kudos
Message 3 of 13
(9,076 Views)

This example uses "latch on release" mechanical latching option.

0 Kudos
Message 4 of 13
(9,070 Views)

please see: Producer-Consumer architecture on these forums.

0 Kudos
Message 5 of 13
(9,069 Views)

You could use a Notifier.  In the following example, I used an event structure to capture the stop button event.  When the stop button is pressed, set the notifier True.  In the Timeout case, set the notifier to False.  The timeout is needed so that the 2nd loop doesn't sit there waiting for a notifier.  It will execute at the same speed as the timeout value.

 

21800i4AD7160C23530C4E  This is a simplified producer-consumer architecture.

- tbob

Inventor of the WORM Global
Message 6 of 13
(9,058 Views)

@Drewski wrote:

This example uses "latch on release" mechanical latching option.


Look again.  The stop button uses Switched When Released.  It even says so on the front panel.  The disadvantage of this is that you have to set the stop button back to false either at the end of the program or at the beginning.

- tbob

Inventor of the WORM Global
0 Kudos
Message 7 of 13
(9,056 Views)

Oh yeah, switch on release.  Yep, there are trade offs to all the possible ways of implementing the desired funtionality.

 

I guess the simple answer to the OP is, "Yes."

0 Kudos
Message 8 of 13
(9,052 Views)

Yes the local variable will work (and I've used it) for stopping a loop from other locations.  It does have the pitfall of not being able to extend to multiple loops if it is a latching boolean.  The reason is pretty obvious if you think like a latching boolean.  "The first time I'm read I'll go back to my default" so the value gets read once and changes state back to the original so it stops one loop and one loop only.

 

A more robust means would be to use queues and for---- sugessted.  Look in the labview examples under queues for some great pointers on how to implement a Producer Consumer loop.  you really are speaking of issueing a "command" to control the state of an independant loop so many synchonizatio methods are good starting points.  Notifiers, Queues, or dynamic events are all possibilities for passing information into a loop (or even other sub-vis)


"Should be" isn't "Is" -Jay
Message 9 of 13
(9,051 Views)

Here's an example of why locals can be bad just due to having to reset the value....sometimes this VI stops...sometimes it doesn't...

 

 Edit: shoudl have used the Code Capture tool instead...

 

 

0 Kudos
Message 10 of 13
(9,030 Views)