Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Equivalent of DAQ_DB_HalfReady in NIDAQmx

I'm working to upgrade an existing VC++ application (without Measurement Studio only NIDAQ) that use traditional NIDAQ double buffering realtime acquisition. The target is to add the ability of use the serie M NIDAQ Board that unfotunately not support traditional NIDAQ API :'(
To maintain the thread architecture of the existing application I need something like the old DAQ_DB_HalfReady that inform the acquisition thread when a buffer is complete and ready to be read.
I use the Examples\DAQmx ANSI C\Analog In\Measure Voltage\Cont Acq-Int Clk structure, but is missing a function that tell me when the buffer is complete, I want to polling this and then take the complete buffer when is ready.
I try to use DAQmxRegisterEveryNSamplesEvent but with no success, my application is too mutch busy to respond fast enough to the callback, while register the callback in my acquisition thread using option DAQmx_Val_SynchronousEventCallbacks is not possible because it not processing messages.


I take advantage of this post to ask two question on DAQmxRegisterEveryNSamplesEvent:
- with option DAQmx_Val_SynchronousEventCallbacks what does mean "In order for the callback to occur, you must be processing messages", exist an example?
- how can I unregister a callback? if I register a callback twice at the second time obtain an error that explain me to unregister the previous callback first, but how can i do this? I have not found a function for that.

Many thanks Massimo.
0 Kudos
Message 1 of 4
(4,230 Views)
Massimo,

If I understand your problem correctly, you are saying that you cannot receive events in your main thread because it is too slow and you cannot receive events in your acquisition thread because it is not processing messages.

I think the solution is to turn off the DAQmx_Val_SynchronousEventCallbacks flag by calling DAQmxRegisterEveryNSamplesEvent with '0' for the Options parameter. If you do that, your event callback will be called by a DAQmx thread. You can either process your data in the callback (if it does not take too long) or you can pass the data to one of your other threads.

To answer your other questions:
-In order to use the DAQmx_Val_SynchronousEventCallbacks flag, the thread that registers the event must be processing windows messages. How you do this depends on your application. You can process windows messages by having your own windows message pump or by using MFC or a similar framework to process messages.
-You can unregister a callback by calling DAQmxRegisterEveryNSamplesEvent with '0' or 'NULL' as the callback parameter.

I hope this helps.

-Jeff
Message 2 of 4
(4,218 Views)
Thanks for the idea, I set a flag in the callback that is used in the acquisition thread and seem to function very well.

Massimo.
0 Kudos
Message 3 of 4
(4,203 Views)

Hello,

 

I am very interested in "double-buffering" solution for NI-DAQmx.  Could you please post a code snippet for analog input continous acquisition with callback, that gives information about data being ready for transfer?

 

Your help will be very appreciated.

 

Rasto

0 Kudos
Message 4 of 4
(3,543 Views)