Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

How to terminate a while loop with a button

Is there a way to terminate a while loop immediately with the push of a button. I'm trying to have my program run a counter that is capable of scanning over a range of voltages. I have it scanning continuously so that I can set up other instruments while the scan is going on. Once I have my other instruments set, however, I'd like to be able to push a button on the front panel of my VI to have the loop terminate or be interrupted and advance the VI to the next sequence in the stacked sequence. Any ideas? Perhaps an event structure? I'm not really sure where to go with this one. Thanks for any help!

- Jon
0 Kudos
Message 1 of 3
(3,066 Views)
John,

sounds a little like not a clear algorithm.
Let me state some assumptions on what you'd like to achieve before giving you an idea.
Using a loop makes sense if you plan to repeat something several times (including maybe zero times). In your case let your counter scan at one voltage. If such a single scan is quick enough so that you can afford finishing it before your program reacts on you pusching the button, than just connect the button with the termination connector of the loop and you'r done. You may save a complete scanning if you put it into a case structure that is just executed when the loop continues.

If, however, your scan takes (much?) longer than the required reaction time, you need some aborting mechanism for that scan as well. This is now completely your turn, as I do not know anything in detail about your setup. Maybe the driver for the counter supports an abort. Or you can split the scanning into much shorter substeps and use a proper means to check for a required abort. This might as well be an putton pressed event. But I'd prefer not to evaluate an UI event in another module. Instead I'd suggest using that event to send a notification or queue element to the other module to request an abort of the counter.

Greetings from Germany!
--
Uwe
0 Kudos
Message 2 of 3
(3,056 Views)
Jon,
 
I dont know if U have tried this option " Place the stop button inside the while loop,which you want to terminate at your wish. You will have the stop button on the front panel, by pressing which you can stop that particular loop, while the other parts of the program run as usual."
 
If I have understood your problem correctly this solutions shud work. Hope this solves your problem.
0 Kudos
Message 3 of 3
(2,995 Views)