LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stopping an event structure inside a while loop.

Solved!
Go to solution
I am relatively new to LabView, and especially the event structure. I have been looking at previous posts regarding the event structure and people having trouble stopping it. In my VI, I have two event cases in addition to the timeout. I am using this VI for stepper motor control. I have 2 buttons (for each case), one for movement to the left, the other to the right. It runs like it is supposed to, but when I try to stop it I have to press both buttons before it stops. As if the loop has to execute everything inside before stopping.

In my VI, how can I make the execution stop when I press the stop button? I tried many setups of the stop button and boolean logic (which I believe was correct) but am now stuck.

Thank you very much ,

Alek
0 Kudos
Message 1 of 12
(5,342 Views)

You simply need to create an event for the stop button.  I've modified your code to include the Stop button.

Also, there is no need for the Local Variables.  You can use shift registers.  The code includes that modification also.

RayR

0 Kudos
Message 2 of 12
(5,340 Views)
You can also delete all the sequences, they serve no purpose. 😉
 
Dataflow fully determines proper execution order where it matters.
0 Kudos
Message 3 of 12
(5,338 Views)
Of all people, how could I have not removed that!!  LOL!! 😄
 
Must be signs of old age!!
 
Thanks Altenbach!  🙂
 
Here is the improved version.  No Sequence Structures...  It is best not to use them..  They're not needed with this code.
 
RayR
 
0 Kudos
Message 4 of 12
(5,336 Views)
OK, here's my simplified version. All you need is two event cases.
  • Note that (with a tiny difference), the "left" and "right" cases are identical, so they can be handled in one event, reusing most of the shared code.
  • We don't need a timeout event

Just some extra tweaks... 😄



Message Edited by altenbach on 06-23-2008 05:09 PM
Download All
0 Kudos
Message 5 of 12
(5,332 Views)

LOL!!  Yes.. I agree Christian..  🙂

I try not to modify the original code too much..  😉 

RayR

 

0 Kudos
Message 6 of 12
(5,322 Views)
There is actually one (possibly important) functional difference. The shift register code does not update the FP control.
 
If the "known position" can change during execution of the program, we need a value change event, feeding the "new val" into the shift register. In this case, we need a local variable in the left-right case to update the control.
 
It is difficult to tell without having the full specs, but maybe it should be made into an indicator and the shift register initialized with a constant.
 
 
Alternatively, we could keep the control and add an indicator inside the loop.


Message Edited by altenbach on 06-23-2008 06:08 PM
0 Kudos
Message 7 of 12
(5,316 Views)
Here's a version that more closely matches the original version with all the local variables.
 
I am not sure if it is really the right way to do things.
 
 
Message 8 of 12
(5,314 Views)

Agreed that we'd need the full specs to suggest the appropriate solution.

I would recommend having the "known position" as an indicator. 

RayR

Message 9 of 12
(5,303 Views)
Thank you guys. This 2MOD2 version is what I need. I may have to add another axis(up/down) and will need another variable to keep track of that movement. I will try to do this with shift registers and a variable. I still can not entirely understand why was it not stopping - why does it stop now and not before? This will be usefult to me in the future. Thanks,

Alek
Message 10 of 12
(5,278 Views)