LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

stopping programs (multiple loops)

i have a statemachine that includes some while loops in given states.  these states sit there 'looping' untill defined conditions are met, like a certain time is reached, and then execute some more code, before changing to next appropriate state. what i want to be able to do is stop the program execution (from front panel button), regardless of it's current state, i.e not having to wait for loop to finish before stop button is picked up on and program actually stops. this delayed stop is the only one i've managed to get to work, and even then i end up introducing some error messages depending on how i do it. any pointers much appreciated.

cheers in advance.


Message 1 of 13
(6,559 Views)
You can change the mechanical action of your stop button to a switch action and place a local variable of it in all of your inner while loops as an additional stopping condition. That way, when you click it, the local will be read and the loop will stop. You will have to reset the button to F when the program is finished.

___________________
Try to take over the world!
0 Kudos
Message 2 of 13
(6,548 Views)

hi there

in LabVIEW 7.1 you could replace each while lopp with a "Timed Loop". You can give each timed loop a name and then stop each loop with the "Abort timed Loop.vi".

But: the timing behaviour of your app will probably change because a Timed Loop will take at least 1 ms for one turn.

Another solution would be to pack your state machine in a vi and load that vi dynamically. then you could call the "Abort VI" method to kill the vi.

best regards
chris
Best regards
chris

CL(A)Dly bending G-Force with LabVIEW

famous last words: "oh my god, it is full of stars!"
0 Kudos
Message 3 of 13
(6,543 Views)
You could also place your state code inside the timeout case of event structures, one in each loop. Set each event timeout to your desired loop timing. Add a stop button (latch when released) in a stop case of one of the loops. Now add a stop event to all other event structures, all triggered by the same button. (No local variables needed 😉
.
See attached simple example (LabVIEW 7.1)

Message Edited by altenbach on 08-09-2005 08:22 AM


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
Message 4 of 13
(6,534 Views)
yeah, i tried the road of locals etc, but didn't get anywhere really for some reason they kept messing up my daq config. sure i was probably doing it wrong? anyway i went down the event structure road, cos this is new to me and i didn't understand how to use them, but now i have a better idea, and that's what it's all about isn't it? anyway code now stops as i'd like, thanks again guys for all the help/pointersSmiley Happy.
0 Kudos
Message 5 of 13
(6,514 Views)

@Altenbach

 

Sorry for referring to your reply 6 years ago lol. Power of database.

 

If I understand what you have proposed here, Having code placed in timeout case of an event structure inside a while loop and setting timeout to say 100 ms is equivalent to having a while loop with 100ms iteration time with the same code? I am trying to understand how that works?

 

Effectively, is the structure polling every 100ms for an event to occur vis'-a-vis' STOP, if not, the code executes?

 

THanks!

I may not be perfect, but I'm all I got!
0 Kudos
Message 6 of 13
(5,379 Views)

Basically what is happening is that each 'while loop' keeps each 'event structure' running until a True condition is passed to the While Loop condition element. After the 'Timeout period' (200ms or 500ms), the timeout case will execute. During the wait period of 200ms or 500ms, any other event can occur and the Event Structure will jump to that event. In the example provided, the only other event is the pressing of the Stop button. When the Stop button is pressed, the value is passed out to the stop condition of the While Loop and the Event structure no longer runs.

So the event structure is not polling every 200ms or 500ms for a Stop button event, it is ever ready for a Stop button event. The 200ms or 500ms timeout causes the 'Timeout' event to occur so every 200ms or 500ms the waveforms update (in the provided example ).

To better understand, try running the exmple with the Highlight on with larger timeout period.and press the Stop button at any time.

0 Kudos
Message 7 of 13
(5,377 Views)

@VeeJay wrote:

Effectively, is the structure polling every 100ms for an event to occur vis'-a-vis' STOP, if not, the code executes?


This old example is somewhat unusual because both event structures have a timeout event to do something at regular intervals. This is often not needed. You can have an event structure with all real events and it will just be sitting there unless one of the events is triggered.

 

Typically only zero or one of all event structures has a timeout event. An event loop without a timeout will do nothing at all unless an associated event is triggered. There is no polling.

 

For example you could have a small event loop that only reacts when a cursor is moved in order to synchronize the cursor of another graph. An example can be found here. There could be a small event loop that monitors key presses. All these indepdendent event loops need to stop when the stop button in your main interactive loop is pressed. All they need is a stop event, they don't even need the terminal (or local variable) of the stop button.


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 8 of 13
(5,367 Views)

From what I understand the loops are being terminated when some condition you programmed becomes "True", but you want to have the ablility to stop before. Just wire your condition and you stop to an "OR" then to the loop termination. Also set the mechanical action on the stop button to 'Latch'. Remeber to click it again once the program stops to return the button to its standard "F" state. If the Stop button determined the value for all the other stop variables it should work.

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

@Adrian S. wrote:

From what I understand the loops are being terminated when some condition you programmed becomes "True", but you want to have the ablility to stop before. Just wire your condition and you stop to an "OR" then to the loop termination.


We are talking about loops with an event structure here. Each event can output any desired boolean to the conditional terminal. The tunnel is set to use default if unwired, so all events that don't specifically stop the loop with keep it running.

 

Of course in each event case you can use any boolean operations you want to come to the final stop decision but that's not the topic of this discussion. Here we are talking about stopping multiple parallel loops. It is probably not a good idea to selectively stop only some loops and there should be only one condition to stop all at once.


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