LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

QUIT App button behaves strangely.

I have a QUIT button on the main panel that works but sometimes when pressed it indicates a press and turns green while the application is shutting down, however, most of the time when it is pressed by the mouse it does not show any indication of being pressed and does not change color yet the application shut down fine.

 

Here are the code snippets:

 

Sint32 CVICALLBACK TimerCallBack (Sint32 panel, Sint32 control, Sint32 event,void *callbackData, Sint32 eventData1, Sint32 eventData2) { Sint32 result = 0; switch (event) { case EVENT_TIMER_TICK: ProcessData (); if(ccu_TaskControlObject.ccuFsmSignal==PROCESS_STATEMACHINE) { UpdateStateManager (); } ProcessSystemEvents (); if (global_quit == TRUE) { CallCtrlCallback(panel, PANEL_MAIN_QUITBUTTON, EVENT_COMMIT, 999, 999,0); } break;/* end case EVENT_TIMER_TICK: */ }/* end switch (event) */ return (result); }/* end Sint32 CVICALLBACK TimerCallBack () */ Sint32 CVICALLBACK PanelMainCallBack (Sint32 panel, Sint32 event, void *callbackData, Sint32 eventData1, Sint32 eventData2) { switch (event) { case EVENT_CLOSE: global_quit = TRUE; break; }/* end switch (event) */ return (0); }/* end Sint32 CVICALLBACK PanelMainCallBack () */ Sint32 CVICALLBACK GlobalQuitCallBack (Sint32 panel, Sint32 control, Sint32 event, void *callbackData, Sint32 eventData1, Sint32 eventData2) { switch (event) { case EVENT_COMMIT: global_quit = TRUE; break; } return (0); }/* end Sint32 CVICALLBACK GlobalQuitCallBack () */ Sint32 CVICALLBACK QuitCallBack (Sint32 panel, Sint32 control, Sint32 event, void *callbackData, Sint32 eventData1, Sint32 eventData2) { Sint32 eventData3 = 0; Sint32 eventData4 = 0; Sint32 returnValue; switch (event) { case EVENT_COMMIT: SuspendTimerCallbacks (); DisplayStatus ("Wait While Application Quits..."); SetCtrlVal (panel, control, 1); HidePanel (panelHandleSc); HidePanel (panelHandleFileTransfer); if (sim4_enabled) { sim4_end(); sim4_enabled = FALSE; } /* Turn off CCU Power */ SetCtrlVal (panel, PANEL_MAIN_POWER, 0); CallCtrlCallback (panel, PANEL_MAIN_POWER, EVENT_COMMIT, eventData3, eventData4, &returnValue); if (IsExcelFileOpen()) { /* Excel replace all <> with ABORT. */ SetFullTestPassed (FALSE); ExcelFileSaveTime (); ExcelFileSave (); } CloseDAQDev1 (); CloseDAQDev2 (); CloseCommPorts (); CloseDataFiles (); QuitUserInterface(0); break; case EVENT_LEFT_CLICK_UP: SetCtrlVal (panel, control, 0); break; }/* end switch (event) */ return (0); }/* end Sint32 CVICALLBACK QuitCallBack () */

 

0 Kudos
Message 1 of 9
(4,102 Views)

Which callback is tied to the Quit button?

 

What is your timer interval?

 

How long do ProcessData() and UpdateStateManager() take? 

 

Do you have any other long callbacks that may be running?

 

If you program is executing a callback, the screen won't be updated (including button pushes) until the callback exits or you call ProcessSystemEvents() and/or ProcessDrawEvents().

 

Have you put a breakpoint on the first statement inside your callback function to see how long it takes to get there? 

 

Do you have a close control specified in your panel properties?  If you do, why do you need to call PanelMainCallBack just to set global_quit True?

0 Kudos
Message 2 of 9
(4,094 Views)
This is the callBack associated with "Quit" button:

QuitCallBack

 

The timer interval is set to 0.1 seconds.

All of the timer code executes within the timer timeout.

 

There are other callbacks that press buttons but are very short and rarely happen.

 

 

The Close Control is set to None. I will try setting it to the GlobalQuitCallBack().

 

There was a problem when trying to close the application with the X in the upper right that would hang the app and I was able to get around that by modifying the PanelMainCallBack by removing the QuitUserInterface (0) call and replacing it with the global_quit = TRUE so that the timer code would finish and initiate the shut down.

 

Now the X and the "Quit" button work the same. 

 

I will check the timing with a break point.

0 Kudos
Message 3 of 9
(4,075 Views)

Do you want a different behavior when you press Quit vs. when you close the an X?  I can't think of a reason right now why you would not want them to act the same. 

 

If you have a Quit button, I'd suggest that you set that as your Close Control in the panel properties.  Then you don't have to catch EVENT_CLOSE on your own.

 

 

0 Kudos
Message 4 of 9
(4,070 Views)

Yes, I want the same behavior for both and they do act the same.

I set the Close Control to the 'Global Quit' that sets a flag which the timer code checks and then calls the 'Quit' callBack so that all code in the timer is finished before quitting.

This seems to work fine.

 

I put a break point in the 'Quit' CallBack and it instantly stops there. Unfortunatly I cannot physically see the 'Quit' button in debug mode but in release mode it is still only sometimes turning green and sometimes not even though I force it ON in the 'Quit' code.

0 Kudos
Message 5 of 9
(4,066 Views)

Here are a couple of other things you can try:

In QuitCallBack, call ProcessDrawEvents() after you set the control value TRUE.

For debugging purposes, put a Delay statement of a secodn or 2 at the start of QuitCallBack and also at the end of it.  This will give you a little more time to see what the button is doing without having a breakpoint.

0 Kudos
Message 6 of 9
(4,061 Views)

Here are the results:

 

SetCtrlVal (panel, control, 1);
Delay(5);
Causes the button to display a faint green dotted line around the outer edge of the button while the rest of it stays grey (no change) for the 5 second delay.

 

Then: 

DisplayStatus ("Done");
QuitUserInterface(
0);
break;

I do not see the 'Done' message as it finishes too fast but I do see the button body turn all green for a fraction of a second.

 

It appears that the QuitUserInterface(0) changes the button body color?

 

What is strange is that on occasion the button body turns green as soon as it is pressed which is what I would expect.

0 Kudos
Message 7 of 9
(4,047 Views)
Did you try calling ProcessDrawEvents() after you set the control TRUE?
0 Kudos
Message 8 of 9
(4,044 Views)

Hi Al.

 

I just added ProcessDrawEvents()  and that did the trick!

I guess since the app is closing down it probably skips process events and once in a while it does catch them which would explain why it ocasionally worked?

 

Thanks for your help.

0 Kudos
Message 9 of 9
(4,040 Views)