02-13-2006 01:25 PM
02-13-2006 01:44 PM
You cannot break out of a FOR loop short of using the Stop function on the application control palette and that'll stop the VI.
You can, with very minor effort, substitute a WHILE loop for a FOR loop and include an additional means of termination other than just loop count.
Assuming you made that change, your VI will have to be redesigned anyway to move the "start measuring" WHILE loop out of the event structure because as long as it is running within that event state, that event state will never complete and the event structure will never get around to checking to see if the STOP button has been pressed.
The "start measuring" WHILE loop could be run in parallel to the while loop used to check for user events -- you would need to communicate with it somehow. Some people use locals and some use globals but queues or notifiers are the better way.
If you rebuild the VI as a state machine it would also be easy enough to use a timeout in the event structure that allowed the check for user input to quickly finish if nothing had come in from the user and to go on to execute one itteration of the "measuring" process before going back for another quick event check. The you can pass data between the states easily with shift register(s).
BTW, before posting a VI to any forum, it's a good idea to check the hierarchy under that VI to see what those of us who download and open the VI will be missing...
02-13-2006 01:45 PM
02-13-2006 01:58 PM
02-13-2006 02:15 PM
02-13-2006 04:44 PM
@yoyofella wrote:
Thanks for the very informative reply.
The reason I didn't want to use a while loop, is because right now my measurement vi has a for loop within a second for loop (I'm using 2 motors to do a 2D scan, each for loop for each axis). So, I don't know how trivial it would be to rewrite that. However, if I can't figure out a second method, I guess rewriting the loop will be the best option.
Is there a way to tie the stop button with the event structure? for example, if the user hit the stop button, the VI runs the stop motor event prior to shutting down? I just want to implement a software stop to the VI.