LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I generate a LED's callback without clicking on it or pressing anykey ?

hi all,

I want a LED automatically generates its own callback when it's turned on or off by GetCtrlVal() command. Is that possible ? I tried but it seemed to be required an "EVENT" to generate a callback, i tried EVENT_VAL_CHANGED but it didnot work .

Thank U



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

Hi,

I assume you wanted to write SetCtrlVal (not GetCtrlVal).
You can call your callback function with appropriate parameters from anywhere in your code like an ordinary C funtion.
So after you change the position of your switch within your code call the callback function with the event parameter set to EVENT_VAL_CHANGED, and be sure you handle this event in your callback.

Hope this helps,

S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 6
(4,092 Views)
Hi ebalci,

I'm sorry for my mistyping last time, it must be SetCtrlVal() . So sorry.

U said :" You can call your callback function with appropriate parameters from anywhere in your code like an ordinary C funtion."I have never thought about this idea, it's so cool , can U show me more  because I am afraid that i can not pass right parameters for my function .

I also attached my small project to illustrate my question. In my project, I have 3 LEDs and 2 buttons. I want to blink one LED continuously,and from the status changing of this LED to generate a callback ,which in turn , blinks the second LED . The 3rd LED is an indicator only .

Many Thanks.
0 Kudos
Message 3 of 6
(4,078 Views)

Hi ~,

Just replace the line with the one below in your Stop callback function.

TurnOnLed2(panelHandle,PANEL_LED_2,EVENT_VAL_CHANGED,NULL,0,0);

But I still cannot quite understand why you need that. You can simply write

SetCtrlVal(panelHandle,PANEL_LED_2,1);

in the Stop callback.

Anyway, in case you need it, that's the way it works 🙂
Hope this helps,

S. Eren BALCI
IMESTEK
0 Kudos
Message 4 of 6
(4,065 Views)
Hi ebalci,Smiley Very Happy

The reason for my "silly" question is that I just want to know how everything works in CVI. And I have just recently "discoved" another way to call a callback in my code Smiley Very Happy . CVI provides a function CallCtrlCallback to do this stuff.It functions well.

However, returning to the issue of passing parameters to a CtrlCallBack .
For example:

int CVICALLBACK Stop (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)

I am not quite sure why you pass NULL to a pointer *callbackData. According to Help file :

Callback Data

Functions in the User Interface, DDE Support, TCP Support, RS-232, DataSocket, Utility, and ActiveX Libraries provide callbackData, eventCallbackData, and threadFunctionData parameters for user-defined data. These parameters are 4-byte values passed by the library to the callback function.

You can use these parameters as pointers to data objects that you need to access in the callback function. This way, you can avoid declaring the data object as a global variable. In the User Interface Library, for example, this means that conceptually the panel or control that is associated with the callbacks has ownership of the data object.

So I suppose that , in a simple CtrlCallBack like this one , there are no data objects at all ,and  we call pass NULL , is that true?

And passing 0 to  eventData1 and eventData2, we mean that there is no related data of this event, is that true .

How about other conditions, when we dont pass "NULL",0,0 to these parameters ?

Many thanks,Smiley Happy




0 Kudos
Message 5 of 6
(4,038 Views)

Hi ~,

The purpose of the callbackData pointer is as you have written, to pass a parameter to the callback by reference (as a pointer).
That's all. If you need such a data in your callback, you can use it, otherwise it can be safely set to NULL which is a valid pointer that points to nowhere.

eventData1 and eventData2 provide extra information about the event. For example, when you click on a control in the UIR these values become the mouse coordinates at the instant you clicked. panel and control are set to correct values when you operate the control from the UIR during execution but you call the callback "manually" you are free to assign any value.

S. Eren BALCI
IMESTEK
0 Kudos
Message 6 of 6
(4,029 Views)