LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to invoke callback function?

I have a basic question with respect to LabWindows/CVI. I will like to know how to invoke a callback function from another function?

My problem is that i change the value in my user interface using the SetCtrlAttribute/SetCtrlValue functions, the value or the attribute is displayed in the interface but it is actually not uploaded to the system. I will like to change the value through another function in the program (not with user interaction) and then do as if the user has done an EVENT_COMMIT, so calling the callback function related to this variable change.

I have tried directly with calling the function: FunctionName(int panel, int control, int event, void *callbackData, int eventData1, int eventData2), but I do not know what information should I give for the void *callbackData, int eventData1, int eventData2 fields.

I will really appreciate some help.

Thank you!

Mari Carmen
0 Kudos
Message 1 of 4
(4,071 Views)

Hello,

you could use the function CallCtrlCallback, which will fire the control's callback function. The panel and ctrl paramters should indicate the control you want to access (e.g. pnlHandle and PNL_SLIDE). The event parameter should be EVENT_COMMIT, and the eventData1 and eventData2 parameters can be 0. If you do not need the return value of the callback function, you can safely pass NULL for the last function parameter.

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

If you look at the help index for the events you want to use/simulate, there is a description of these other parameters. Don't forget, the information passed to the callback (such as eventData1) is provided by the system for your function to use: if you don't use the data there is no need to set it to a particular value in the dummy calls you want to make.

JR

0 Kudos
Message 3 of 4
(4,066 Views)

Another approach (particularly if you are not doing things related to the callback event data) is to break out the functionality that needs to be called both via a callback, and directly, into its own function. Then you can just call that function wherever you like, including from any callback.  For example:

void UpdateInputPanel() {

....

}

int CVICALLBACK InputCtrlCallback (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 switch (event) {
  case EVENT_COMMIT:

           UpdateInputPanel();

           // do anything else needed only in response to callback
   
     break;
 }
 return 0;
}

0 Kudos
Message 4 of 4
(4,029 Views)