Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to you specify DAQmxRegisterEveryNSamplesEvent in C++ ?

Hello,

 

Can you tell me what the syntax is for using DAQmxRegisterEveryNSampleEvents in C++?

 

I have tried to specify the following:

 

DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(

/*TaskHandle taskHandle*/ m_hTaskHandle,

/*int32 everyNsamplesEventType*/ DAQmx_Val_Acquired_Into_Buffer,

/*uInt32 nSamples*/ NI_DAQmx_SAMPLE_SIZE,

/*uInt32 options*/ 0,

/*DAQmxEveryNSamplesEventCallbackPtr callbackFunction*/ &NIDAQmx::OnEveryNSamplesCallback,

/*void *callbackData*/ NULL));

 

but I am getting the following build error:

 

error C2664: 'DAQmxRegisterEveryNSamplesEvent' : cannot convert parameter 5 from 'int32 (__cdecl NIDAQmx::* )(TaskHandle,int32,uInt32,void *)' to 'DAQmxEveryNSamplesEventCallbackPtr'1>         

There is no context in which this conversion is possible

 

I also tried using a type cast and that did not resolve the error.

 

Thank you.

0 Kudos
Message 1 of 3
(3,558 Views)

Hello,

 

It looks like you are using a pointer to a function when the function is expecting a function. If you remove the & from the 6th line, it may fix the issue.

 

Also, what environment are you developing in using C++?

 

Regards,

 

Jason D

Applications Engineer

National Instruments

0 Kudos
Message 2 of 3
(3,533 Views)

Hi brianbat,

 

The C++ FAQ Lite has a couple of entries about this:

[33.1] Is the type of "pointer-to-member-function" different from "pointer-to-function"?
[33.2] How do I pass a pointer-to-member-function to a signal handler, X event callback, system call...

 

Note that the "void *callbackData" parameter is useful for passing the "this" pointer. Here's a completely untested example:

 

class MyClass

{

   ...

 

   int32 everyNSamplesCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples);

   void registerEveryNSamples();

 

   ...

};

 

 

int32 MyClass::everyNSamplesCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples)

{

   ... do whatever ...

}

 

static int32 CVICALLBACK everyNSamplesWrapper(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData)

{

   MyClass* obj = static_cast<MyClass*>(callbackData);

   return obj->everyNSamplesCallback(taskHandle, everyNsamplesEventType, nSamples);

}

 

void MyClass::registerEveryNSamples()

{

   DAQmxErrChk(DAQmxRegisterEveryNSamplesEvent(

      m_hTaskHandle, DAQmx_Val_Acquired_Into_Buffer, NI_DAQmx_SAMPLE_SIZE, /* options */ 0,

      &everyNSamplesWrapper, /* callbackData */ this));

   ...

}

 

Brad

 

---
Brad Keryan
NI R&D
0 Kudos
Message 3 of 3
(3,506 Views)