LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

emergency button

Hi,

I'm trying to add an "Emergency" command button on my GUI but, it doesn't work because my programm is running. That's impossible to click on my button.

During a loop : If (!DataCaptureComplete(System)); I would like to add the option for the user to stop the programm even if the acquistion is not finished and, reset the acquistion board.

 

Nevertheless, as the programm is running, I can't click on my emergency button. So, the user can't stop the programm. Do you have an idea to do that?

 

I tried to add a second panel which contains my emergency button but, the result was the same. Impossible to click on it.

 

Regards

0 Kudos
Message 1 of 4
(2,806 Views)

The problem is that your application is likely single threaded, so while your loop is running, none of the events triggered in your UI are being processed. You can pause your execution to handle events by calling ProcessSystemEvents( ). I think the help documentation for this function describes the scenario clearly, so I have copied it below.

 

When your program executes in a callback function or in code that does not call RunUserInterface or GetUserEvent, LabWindows/CVI does not process user interface and system events. Functions that are overly time-consuming can "lock out" user interface and system events. To allow LabWindows/CVI to process events, call ProcessSystemEvents. Take care when using ProcessSystemEvents, because it can allow other callback functions to execute before it completes.

 

In your Emergency command button you can set a flag that is read in your data capturing loop to trigger the loop to exit.

 

Additionally, you can run the data capture loop asynchronously in a separate thread. This will allow the UI to remain responsive, but adds complexity since you now need to manage multiple threads.

National Instruments
Message 2 of 4
(2,796 Views)

A little addition that excludes the need for a separate callback and a global flag: if your emergency button is a toggle one, the code could as follows

 

while (TRUE) {
   // Your code here

   ProcessSystemEvents ();
   GetCtrlVal (panelHandle, PANEL_EMERGENCYBUTTON, &stop);
   if (stop) break;
}

// Terminate running activities, clear resources...
if (stop) {
   SetCtrlVal (panelHandle, PANEL_EMERGENCYBUTTON, 0);  // Reset button state
   // Warn the operator
}

 

 



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?
Message 3 of 4
(2,785 Views)

Thank you for your answers! I'm a little bit lost with multithreading but I will work on it.

 

I'm trying to use a simple panel with two buttons. The firt command button starts an infinite loop and, the second one will stop it if I'm clicking on it. For the moment it doesn't work. to be continued...

 

Regards

0 Kudos
Message 4 of 4
(2,764 Views)