LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to terminate Vi within a For Loop

Solved!
Go to solution

Hello. I have attached my Vi. I have a question about stopping a For Loop. On the "Test in progress" case I have 2 For Loops. I have a conditional termial that will stop my Vi but only after all the iterations of the For Loop have completed. I need this Vi to stop immediately, when the stop button is pressed. I realize it will probably still need to finish an itereation however, right now it waits until all iterations are done, before stopping. I am trying to do this with the same front panel pushbutton that stops the While loop. I have tried a local variable but it requires I change mechanical action and I would rather not do that, if at all possible. There were a lot of messages pertaining to this topic here on the forum however, I couldn't find one that suited my needs. Thank you for your time.

0 Kudos
Message 1 of 10
(3,609 Views)
Solution
Accepted by topic author ceilingwalker

Your While Loop waits the For Loops to stop, so you can use local variables of your stop button to stop the for loops right away.

 

Cheers,

Jimmy

 

2015-07-30 10_56_51-My Project 15.vi Block Diagram _.png

Message 2 of 10
(3,601 Views)

If you want to avoid the Local Variable, a standard way to do this is with Notifiers. Use the same construction that Jimmy has and then add a parallel while loop with an Event Structure that can throw the notifier when you hit the stop button.

 

Your architecture is a bit odd. You have the makings of a state machine that could be expanded to not use a for loop and be completely interruptible. Also, your flat sequence structure isn't doing anything for you.

Message 3 of 10
(3,585 Views)

@Jimmy.chretien wrote:

Your While Loop waits the For Loops to stop, so you can use local variables of your stop button to stop the for loops right away.

 

Cheers,

Jimmy

 

 


Thank you Sir for the reply. I tried the local variable before, the challenge is that I must then change the mechanical action of the stop switch.

0 Kudos
Message 4 of 10
(3,583 Views)

@Taki1999 wrote:

If you want to avoid the Local Variable, a standard way to do this is with Notifiers. Use the same construction that Jimmy has and then add a parallel while loop with an Event Structure that can throw the notifier when you hit the stop button.

 

Your architecture is a bit odd. You have the makings of a state machine that could be expanded to not use a for loop and be completely interruptible. Also, your flat sequence structure isn't doing anything for you.


You have the makings of a state machine that could be expanded to not use a for loop and be completely interruptible I tried removing the For Loops but couldn't get it to do what I needed.

 

Also, your flat sequence structure isn't doing anything for you  Yes Sir, I removed it yesterday. Sorry, I thought I sent my most current copy. Nothing else has changed other than the flat sequence removal.

 

Thank you

0 Kudos
Message 5 of 10
(3,577 Views)
Solution
Accepted by topic author ceilingwalker

@ceilingwalker wrote:

Thank you Sir for the reply. I tried the local variable before, the challenge is that I must then change the mechanical action of the stop switch.


Changing the action of the Stop button is easy and I do it a lot. It's a really easy way to make a local stop variable for multiple loops. Change the Stop button to "switching" mode and then write a False value to another local variable that runs after all loops have stopped.

 

This is your easiest solution.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


Message 6 of 10
(3,567 Views)

Here's a template for the alternate solution I was proposing. In this case, I illustrate with a while loop instead of a for loop.

NotifierStop.png

Message 7 of 10
(3,557 Views)

The Latch on the boolean button is nice if you use an event structure, but you have none of that here, the easiest is to use Switch instead.

 

I'd go with Taki1999 suggestion but you need to quite redesign your code, if you're not going to develop a long term software and need something for a quick experiment, I'd go with the local variables.

 

Message 8 of 10
(3,542 Views)

You'll still need a way to kill the event loop. You can use a user event for that.

 

Kill event loop2.PNG

Kill For loop and daq loop

Kill daq and for loops.PNG

Event loop:

Event loop4.PNG

Message 9 of 10
(3,509 Views)

@igagne wrote:

You'll still need a way to kill the event loop. You can use a user event for that.

 

 

Kill For loop and daq loop

 

Event loop:

 


Thank you for this. I have been trying to learn how to use events, as it seemed the better way to go for my entire project but I haven't figured out how to use them yet.

0 Kudos
Message 10 of 10
(3,433 Views)