11-29-2016 09:15 PM - edited 11-29-2016 09:37 PM
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; }
11-30-2016 05:04 PM
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?
11-30-2016 09:12 PM
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
12-01-2016 02:34 AM
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.
12-01-2016 04:28 AM
Okay thank you, its just for my knowledge
12-01-2016 09:46 PM - edited 12-01-2016 09:48 PM
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; }
12-05-2016 03:00 AM
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)