LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help implementing an Emergency Stop (interrupt) Button

I need a little help getting this interrupt button to work properly. During my testing sequence I need to be able to monitor the user interface and see if the user has hit the "Emergency Stop" button. This should halt all testing and return the user to the main menu.

I currently am using a flag that gets set if the user interface returns a event from that button. This is the code:

statusbyte = GetUserEvent (0, &PanelID, &buttonevent);
if (buttonevent == 5)
Fail = 1;

This is inefficient and very cumbersome trying to pass that flag around and to see if it's set or not. Can anyone please help me in devising an easier way of doing this task --- or is there one? Also, is there a routine I could call t
hat would halt program execution and just return to the Main Panel?

Thanks in advance!!!
0 Kudos
Message 1 of 6
(3,830 Views)
The basic concept is the one you are using.
I personally prefer to set a callback function for the emergency button into which to set the 'fail' flag, and use ProcessSystemEvents () throughout the testing function.
I found this easier 'cause in my testing routine I have a lot of pauses (turn on a relay and wait for it to switch, start a motor engine and wait for it to rotate at the right speed...): I implemented these pauses in while loops with the code to test alarm conditions (daq errors, fuses broken, air pressure fault, carter opened...) and a ProcessSystemEvents inside, so every emergency condition stops my routine.

Hope this elps
Roberto


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 6
(3,830 Views)
Thanks Roberto - the only problem that I have running ProcessSystemEvents() throughout my test algorithm is that PSE() causes a rather lengthy pause in program execution. That is, a rather lengthy pause when every millisecond counts. I have under one minute to complete a seven phase test algorithm, so calling PSE() drastically hurts my program timing and performance.

So the only other way is to use the method that I'm using (that you know of) and pass that fail flag all around? Btw, I have the method implemented right now that you use. Another problem with that method is that if I call a new thread, which I do during each phase of testing, the program will not process that fail flag until I return from the new thread. -- that is because the fail flag
is local to the first.

Thanks again tho!
0 Kudos
Message 3 of 6
(3,830 Views)
Another quick idea would be to look at multithreading. I think you could spawn another thread that would contain your testing sequence. Then you would just need to create a global flag variable. Within the callback function for the stop button, you would "activate" the flag, and just have a check for the flag in the spawned thread. If you don't have experience with multithreading, you can check out our readme file on it for CVI, and that is usually located on your machine at:

C:\Program Files\National Instruments\MeasurementStudio\CVI\bin
and the file is MultiThreadingOverview.pdf

We also have some web links that might be good:

http://zone.ni.com/devzone/conceptd.nsf/2d17d611efb58b22862567a9006ffe76/785199275fc420218625686900732df3?OpenDocument

http://zone.
ni.com/devzone/learningcenter.nsf/03f7c60f17aad210862567a90054a26c/8829ce1ce5a4a9718625693800549f58?OpenDocument
0 Kudos
Message 4 of 6
(3,830 Views)
Hi,

You could use multiThreading, so if your Emergency button is in thread 2 you will stop thread 1 or do something else. Its a suggestion...I don't know how fast you testing must go. Give it a try. I'm using such thing in mine. I have 3 threads

Good luck,
0 Kudos
Message 5 of 6
(3,830 Views)
Hi,

You could use multiThreading, so if your Emergency button is in thread 2 you will stop thread 1 or do something else. Its a suggestion...I don't know how fast you testing must go. Give it a try. I'm using such thing in mine. I have 3 threads

Good luck,
0 Kudos
Message 6 of 6
(3,830 Views)