LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Callback function

How this Callback function working ,is it using pointer or function pointer? 

 

int CVICALLBACK LatchStatus (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{
		switch (event)
		{
		case EVENT_COMMIT:
			SetCtrlVal(); 
		        break;
		}
	return 0;
}

 

0 Kudos
Message 1 of 7
(4,056 Views)

Can you elaborate a bit more on your question? The callback paradigm makes that the associated function is called whenever an event is raised on a control or panel. Where are you wondering a pointer should be?



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 2 of 7
(4,016 Views)

 The callback paradigm makes that the associated function is called whenever an event is raised on a control or panel

I agree  to your words,I Googled what is funtion pointer and where its using I got a answer

"callback function is a functionthat is called through a function pointer. If you pass the pointer (address) of a function as an argument to another, when that pointer is used to call the function it points to it is said that a call back is made."

how this related into our Labwindows CVI

0 Kudos
Message 3 of 7
(4,011 Views)

The callback concept refers to functions passed as an argument to other functions: there is no such framework in the code you have posted.

I suppose, though, this is the concept that informs the run-time engine framework: the callbacks associated to controls and panels are passed (as a pointer?) to the OS which is in charge of handling machine and user events and call the associated function. Nevertheless, all this mechanism is hided to you: you must not worry about it neither you can alter it in any way.



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

Okay thank you, its just for my knowledge

0 Kudos
Message 5 of 7
(3,984 Views)

In this code using both callbackfuntion and funtion pointer ,actually what its how its differ from normal funtion

int CVIFUNC RegisterTCPServer(unsigned portNumber, tcpFuncPtr pUserCallback, void *callbackData);
void main()
{
if(RegisterTCPServer (iServerPortID, fnServerTCPCallback, NULL) < 0) MessagePopup("TCP Server", "Server registration failed!") else
do something } /*---------------------------------------------------------------------------*/ /* TCP callback function for the server. */ /*---------------------------------------------------------------------------*/ static int CVICALLBACK fnServerTCPCallback (unsigned int handle, int xType, int errCode, void *cbData) { static int i = 0; if (xType == TCP_CONNECT) else if (xType == TCP_DISCONNECT) else if (xType == TCP_DATAREADY) return 0; }
0 Kudos
Message 6 of 7
(3,976 Views)

This is the exact case of a function pointer: passing a function as an argument to a function. This can be used to tailor the behaviour of a function.

This mechanism may be a little more clear if looking at qsort function: it accepts a comparison function that you may declare and code yourself if standard ShortCompare, IntCompare... and so on cannot be used. As an example, I have used qsort to sort an array of elements defined as a structure, writing my own comparison function to sort on one structure field.

As you can see, qsort is a general tool that can be tailored by passing your own sorting algorithm coded in a function.

Another example and a brief discussion of this technique can be found here.

 

 

(Note: ShortCompare and similar functions are defined in the Programmer's Toolbox and you may look at both the definition and the actual code since the source of this library is distributed)



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 7 of 7
(3,951 Views)