LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

buffer allocation in DAQmx for multiple channel acquisition - which routines want total samples, and which want samples per channel?

I am attempting to acquire data from two channels using an E-series board, and am running into a question regarding buffer allocation and terminology.

 

I started out by defining a task "DAQ_Acq_Task" in MAX: two channels, N samples per acquisition, 1000 samples, 50 kHz, non-interleaved. External triggering from PIO0. Works fine from the MAX test panel. Triggering is at 30 Hz, so every 33 ms it should acquire 1000 samples.

 

In the software, then I 

- call "DAQmxLoadTask ("DAQ_Acq_Task", @handle) to load the task

- call "DAQmxGetBufferAttribute (handle, DAQmx_Buf_Input_BufSize, &BufferSize)" to get the number of samples (which should be 1000 in this case - but I might change it, so I check every time)

- call malloc to allocate buffers of type float64 size (BufferSize * 2) to copy the data into

and finally

- DAQmxErrChk(DAQmxRegisterEveryNSamplesEvent (handle, DAQmx_Val_Acquired_Into_Buffer, BufferSize, DAQmx_Val_SynchronousEventCallbacks, CB_DataRdy, NULL) to register a callback service routine to handle the data. 

 

The service routine is defined as

int32 CVICALLBACK CB_DataRdy (TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData);

 

and in turn calls

DAQmxReadAnalogF64 (taskHandle, DAQmx_Val_Auto, 0, DAQmx_Val_GroupByChannel, DataBuffer, BufferSize, &samplesRead, 0));

 

to read the samples into the locally allocated buffers. "DataBuffer" above is defined as buffer_size * 2 (or, in this case, 2000 samples) of float64 - 1000 for each channel.

 

The confusion seems to be that some places use samples per channel, and some use total samples. The question is: which is which? In my software, when CB_DataRdy() gets called, much to my surprise nSamples = 1000 and I get 500 samples of each channel copied into DataBuffer, instead of 1000. If I define N samples in MAX as 2000, then I get 1000 samples per channel. (I have a saw-tooth going into channel 0 and a steady voltage going into channel 1, so I can tell where one channel stops and the other starts). 

0 Kudos
Message 1 of 5
(3,029 Views)

Oh, of course I call

DAQmxStartTask (handle) to start the task after loading it. 

0 Kudos
Message 2 of 5
(3,027 Views)

Hi pblase!

It looks to me like the issue you are having is determining when nSamples means total number of samples acquired versus number of samples per channel, is this right?  You also mention that when you run the task in the test panel that everything works right.  Do you mean that when you set your number of samples to 1000 with two channels that each of the channels takes 1000 samples?

 

I'm just trying to make sure I understand the issue.  In short, the task in test panels acquired 1000 samples per channel, but when you run the task as you've described above the task samples a total of 1000 samples, is this right?  Let us know so we can make sure we are talking about the same thing.  Thanks!

0 Kudos
Message 3 of 5
(3,014 Views)

Yes, that's it. When I looked at the data, I saw 500 samples from channel 0, and 500 from channel 1 instead of 1000 from each.

 

I think that I've figured it out: All of the DAQmx calls want samples per channel, except for the "BufferSize" parameter in DAQmxReadAnalogF64 which wants the total buffer size - samples/channel * channels (2 * samples/channel, in this case).

 

0 Kudos
Message 4 of 5
(3,008 Views)

Hi pblase!

You are absolutely right.  DAQmx commands are written such that the number of samples to read/write is always per channel, where the buffer size is the total buffer.  If you think about it, it sort of makes sense since you are only creating a single buffer, and writing from all channels into that buffer.  If you do have other questions feel free to post!

0 Kudos
Message 5 of 5
(3,002 Views)