1

This is an issue of implementing a c function in a c++ environment.

National Instruments developed a NIDAQmx.h header file with functions in c. I've been successfully using their functions in a c++ class to control an acquisition device (cDAQ-9174). But one of the functions they provide is callback function that is triggered by an event on the device.

Here's the function in c that I'd like to implement in c++


int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData){
    int32   error=0;
    char    errBuff[2048]={'\0'};

    // Check to see if an error stopped the task.
    DAQmxErrChk (status);

Error:
    if( DAQmxFailed(error) ) {
        DAQmxGetExtendedErrorInfo(errBuff,2048);
        DAQmxClearTask(taskHandle);
        printf("DAQmx Error: %s\n",errBuff);
    }
    return 0;
}

The event handler is registered to the device through the function:

DAQmxRegisterDoneEvent(taskHandle,0,DoneCallback,NULL);

My question is: How do I implement a class member function that is capable of being triggered by this event? I imagine a function cast or some analogous way, but I don't know enough of c and c++ to figure it out.

It would be important to implement this function so that my class knows when an acquisition task is over and release the device for some other instance to use.

A. Vieira
  • 1,103
  • 2
  • 9
  • 23
  • Possible duplicate of [Using a C++ class member function as a C callback function](http://stackoverflow.com/questions/1000663/using-a-c-class-member-function-as-a-c-callback-function) – a3f Jul 19 '16 at 09:38
  • @a3f Maybe it is. But notice this function has a Macro in its type, `CVICALLBACK`, specific to `NIDAQmx.h` header file. I don't know how to include that in the case given in that question you mention. But maybe it's simple. – A. Vieira Jul 19 '16 at 10:13
  • Just define your static member callback as `CVICALLBACK`. – a3f Jul 19 '16 at 10:25
  • Could you formulate an answer? I'm trying to make it static, but I still get errors about it. – A. Vieira Jul 19 '16 at 10:37
  • Edit the answer to reflect your error then. As it stands, your current question is already answered elsewhere on SO. – a3f Jul 19 '16 at 10:41

0 Answers0