LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to break a event callback

My problem is: when one event function is running after event_commit on the control, how to break it (in other words, stop running the funtion before it's over)?
 
Thanks very much!
Best regards
Jaman
Developing Test Sepcialist
0 Kudos
Message 1 of 5
(3,450 Views)

The easy answer is: simply insert a return 0 or jump to the return at callback end. Smiley Wink

A more complex answer depends on which is the condition for which to stop the callback and when it arise. Is it a "static" condition (i.r. is already known when the callback starts) or does it arise WHILE the callback is running? In the first case the easy answer is your solution: simply test this condition throughout your callback and exit from it if it's necessary. In the second case it would be better that you give us some informations about how this condition arise and which part of the application is rising it (an external device, a different thread, a timer callback...?)



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 2 of 5
(3,448 Views)
Thank you, Roberto, glad to see you again!
 
I want to use the event of anoter control to stop the running callback, How to go please?
 
Best regards
Jaman
Developing Test Sepcialist
0 Kudos
Message 3 of 5
(3,442 Views)

That's definitely not an easy question: while the program is processing a control callback it is not processing other callbacks until the first callback terminates execution. To process these pending events you must regularly call ProcessSystemEvents() inside your callback so that all pending events are processed.

While this can be done, this function is to be used with particular care, since you cannot in any way limit which event is processed and which not so your application may find itself executing parts of the code which are not intended to be processed in this particular moment. You could limit this possibility for example disabling all controls which are not relevant to your code at callback start end re-enabling them at callback end, or rising a global flag for "callback executing" that is controlled inside all other control callbacks and that stops all these callbacks if the first one is under execution.

Once the environment has been prepared this way, I normally set my stop button as a toggle button, without setting any callback for it: its state will be updated by ProcessSystemEvents() inside the callback so that I can test the control value and decide what to do based on its state. For example:

 while (TRUE) {
  Sleep (50);     // This is your code executing

  ProcessSystemEvents ();
  GetCtrlVal (panelHandle, PANEL_stop, &x);
  if (x) break;
 }
 SetCtrlVal (panelHandle, PANEL_stop, 0);   // Remember to reset stop button state in case of future callback executions

 



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 4 of 5
(3,430 Views)

Dear Roberto,

thank you very much, now my program work well!

Best regards
Jaman
Developing Test Sepcialist
0 Kudos
Message 5 of 5
(3,426 Views)