简体   繁体   中英

Callbacks: Difference between DAQmxRegisterDoneEvent() and DAQmxEveryNSamplesEvent

Trying to figure out how callback wrappers are called specifically. Our code deals with a slowTask and an onTask . During a slowTask , I deal with the following two lines (specific to this question):

DAQmxCfgSampClkTiming(slowTask, "OnboardClock", GUI_RATE,
      DAQmx_Val_Rising, DAQmx_Val_ContSamps, 1);
DAQmxRegisterEveryNSamplesEvent(slowTask, DAQmx_Val_Acquired_Into_Buffer, 1,
      0, EveryNCallbackWrapper, this);

I understand that here, everytime the buffer fills up with one sample, EveryNCallbackWrapper will be called.

For an onTask , I have a hardtime understanding how the callback gets called. I consulted the NI documentation but couldn't quite get it.

DAQmxCfgSampClkTiming(onTask, "OnboardClock", ON_RATE, DAQmx_Val_Rising,
     DAQmx_Val_FiniteSamps, 100);
DAQmxRegisterDoneEvent(onTask, 0, DoneCallbackWrapper, this);

This one boggles my mind a bit more. I believe that whenever onTask is triggered (with a hardware trigger), the DAQ starts taking and digitizing analog measurements at ON_RATE samples/second and once 100 samples are taken/read into the DAQs buffer, the DoneCallbackWrapper() is called. Depending on how long this hardware trigger stays high, this wrapper will be called every time the DAQ reads 100 samples (while trigger is high) OR will the callback be called only once after 100 samples were read?

The callback is called only once after 100 samples were read

Because slowTask uses DAQmx_Val_ContSamps , the program asks for an infinite (aka continuous) acquisition where data is streamed to the host. Using the EveryNSamples callback allows the program to access and process the newest data that was sent by the device.

Because onTask uses DAQmx_Val_FiniteSamps , the program asks for a single acquisition of 100 samples. Using the Done event allows the program to access and process the complete and full acquisition.

In your comment update, the program uses

DAQmxCfgDigEdgeStartTrig(onTask, "/PXI2Slot4/PXI_Trig0", DAQmx_Val_Rising));

to configure a digital edge start trigger for onTask . When that trigger line has a rising edge, the onTask acquisition begins, captures 100 samples, stops, and invokes the callback.

If the program needs to acquire 100 samples for onTask for every rising edge on /PXI2Slot4/PXI_Trig0 , you can use the retriggerable property on the NI 63xx series devices that allows the same task to re-run for each trigger event .

More details are in the X Series User Manual :

The AI Start Trigger is also configurable as retriggerable. The timing engine generates the sample and convert clocks for the configured acquisition in response to each pulse on an AI Start Trigger signal.

The timing engine ignores the AI Start Trigger signal while the clock generation is in progress. After the clock generation is finished, the counter waits for another Start Trigger to begin another clock generation. Figure 4-22 shows a retriggerable analog input with three AI channels and four samples per trigger

可触发的模拟输入信号的图示

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM