Specifying Number of Samples When Continuously Acquiring NI-DAQmx for LabVIEW NXG

Updated Sep 5, 2018

Reported In

Software

  • LabVIEW NXG
  • DAQExpress

Driver

  • NI-DAQmx

Other


 

Issue Details

Why do I have to specify a number of samples to read when continuously acquiring data using NI-DAQmx with support for LabVIEW NXG?
 

Solution

When performing an acquisition with DAQmx, data is first transferred from the DAQ Device into the memory (RAM) of your computer. There is a a preallocated buffer on your computer's RAM, called the DAQmx PC Buffer, which is reserved as a holding place for unread data. 

Note: The transfer speed between the DAQ device and the DAQmx PC Buffer on the host computer's RAM depends on the bus being used to communicate with the DAQ Device (PCI, USB, PXI, etc.).

Data can then be read from the DAQmx PC Buffer and into an array or waveform inside of your DAQmx application by executing the DAQmx Read function.
Figure 1:  Diagram of Dataflow in DAQmx

The size of the array/waveform, as well as the size of the DAQmx PC Buffer, are implicitly determined by the configuration of the DAQmx task, as outlined below.

When you configure the DAQmx Timing VI for your task in LabVIEW, the Samples per Channel value has a different effect depending on whether the Sample Mode is set to Continuous Samples or Finite Samples
 
  • For Finite Samples, the Samples per Channel value determines the number of samples to acquire before the task completes. 
  • For Continuous Samples, the Samples per Channel value is used to determine the size of the DAQmx PC Buffer if the default buffer size is not sufficient.  However, in most cases, the default buffer size is used and this value is ignored. See DAQmx Buffer Size Allocation for Finite or Continuous Acquisitions for more information about how buffer size is determined for continuous acquisitions. 

Conversely, DAQmx Read VI has an input called Number of Samples per Channel. The Number of Samples per Channel value determines the size, in samples, of each array or waveform of data that is read from the buffer into your application when DAQmx Read is executed. 

 
It should be noted that DAQmx Read will wait until all of the requested samples have been acquired and stored in the DAQmx PC Buffer before providing the data to the application.

Consequently, if the sampling rate is not fast enough to create an array or waveform of this size in the time allotted by the timeout, the VI will throw a timeout error. To prevent this, increase the timeout parameter (the default value is 10 seconds), or reduce Number of Samples per Channel.

Additionally, note that in the interactive Measurement Panels, as well as in DAQExpress, this parameter is renamed Samples to Read, as shown below:

 
Note: The default value for Number of Samples per Channel is -1, which causes DAQmx Read to read all data that is available in the buffer immediately. If no data is available in the buffer when Number of Samples per Channel is set to -1, DAQmx Read will return an empty array rather than wait for samples to be acquired.
 

WAS THIS ARTICLE HELPFUL?

Not Helpful