LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to canel a FOR LOOP when used in a Producer - Consumer Que format

Hello
 
How do you cancel a FOR LOOP of While Loop structure that has been launched via a QUE Event when using a procer / Consumer format?
 
I was hoping to not have to use a property node or local variable.
 
I'm not sure about this, but once a consumer event has been triggered and there is a long duration for loop that has been initiated is there
any way of getting a canel bool into the event to cancel the for loop?
 
Thanks
Tim C.
1:30 Seconds ARRRGHHH!!!! I want my popcorn NOW! Isn't there anything faster than a microwave!
0 Kudos
Message 1 of 11
(3,588 Views)

For a traditional For loop, I don't know of any way to stop it early.

In LV 8.5, there is now a conditional For Loop.  You can expose a Stop terminal within the For loop with a right click and checking "Conditional Terminal".  Sending a True to that would cause it to stop.



Message Edited by Ravens Fan on 07-16-2008 10:26 PM
0 Kudos
Message 2 of 11
(3,576 Views)
Before 8.5, the solution is to wrap the code inside the loop with a case structure. If the stop condition is true, you execute the empty case and the loop finishes almost immediately.

___________________
Try to take over the world!
0 Kudos
Message 3 of 11
(3,564 Views)

There seems to be a disconnect in what I am asking....

 

I understand how to stop a for loop  BUT once that for loop is in a consumer que event and starts to run how do you send a BOOL into that same consumer Que event once the for loop has started to run.  Once the for loop runs inside an event doesn't it become a blocking event until the for loop completes?

 

Thanks

Tim C. 

1:30 Seconds ARRRGHHH!!!! I want my popcorn NOW! Isn't there anything faster than a microwave!
0 Kudos
Message 4 of 11
(3,542 Views)

Perhaps you can post a screenshot of the code you have so far.  When you say "consumer queue", I'm visualizing the the consumer loop in a producer/consumer architecture.  Or do you have an event structure?  Or are registered for user events?  I'm not sure if any of these would matter for the issue of stopping a For loop early, which is what I thought was the reason for your question.

The easiest way would be to pass the stop command into the loop by way of a local variable.  Notifiers or occurrences would be a more advanced way to pass along information instead of the "not always evil" local variable.

Please post an example of what you have now so we can more clearly see what you want to do.Smiley Wink



Message Edited by Ravens Fan on 07-17-2008 09:25 AM
0 Kudos
Message 5 of 11
(3,533 Views)

You are correct that once a case in a consumer starts executing, the next item will not be consumed until the current one has finished.

Since you want to send the stop command into the same queue, you basically have to run the "for loop" (or whatever) asynchronously, either by launching a dynamic VI call using the Run VI method or by running it in a separate loop. In both cases, you can stop it by using a named notifier.


___________________
Try to take over the world!
0 Kudos
Message 6 of 11
(3,521 Views)
Here is an example
 
Look in the SSS consumer event to see a simple example of what I am trying to accomplish.
 
 
The goal is to stop a for loop early inside a consumer que event without property nodes or local variables....
 
Thanks
Tim C.
 
1:30 Seconds ARRRGHHH!!!! I want my popcorn NOW! Isn't there anything faster than a microwave!
0 Kudos
Message 7 of 11
(3,496 Views)

For a simple one to one relationship, I would just but the button in the For loop and take it out of the Event structure.  Set it to switch when release and manually reset it back to false with a local variable when the case structure completes.  See Attached.

If it gets more complicated then this, then I would start looking at notifications and occurrences tied in with the event structure.

0 Kudos
Message 8 of 11
(3,492 Views)
One flaw in what I posted.  If the loop ends naturally, the wire coming out will be false, not makes it true, and it sets up the local variable to be true.  It could wind up canceling the next iteration when you don't want to.  I was just trying to do it by wiring to help execution order.
 
In reality, there should be no problem with execution order, just eliminate the NOT and the branch from the control inside the loop.  Replace it with a False constant.


Message Edited by Ravens Fan on 07-17-2008 06:30 PM
0 Kudos
Message 9 of 11
(3,487 Views)

The cancel function will get more complicated, as i was planning on using a common cancel button to cancel For Loops in multiple consumer

events.

What are "Que Occurances" (I think that is what you mentioned)?

 

Thanks

Tim C.

1:30 Seconds ARRRGHHH!!!! I want my popcorn NOW! Isn't there anything faster than a microwave!
0 Kudos
Message 10 of 11
(3,475 Views)