LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to update contiuous output (DAQmxWrite) with minimal latency

Hello,

 

I have the following problem which I'm trying to solve with the DAQmx C API (actually with a thin Python layer on top):

 

I am writing a continuous stream with the analog output of a USB-6259 DAQ, for example a series of square pulses. At some point I want to change the output, e.g. to have a different amplitude. The time when this happens is not known beforehand, so I chose continuous sampling, set the regeneration mode to DAQmx_Val_DoNotAllowRegen and am refilling the buffer using the Every N Samples callback method.

 

The buffer (8191 samples) is being filled nearly immediately by repeated calls to the callback function so that writing different data into the buffer would only have an effect at T=8191/framerate later, about 0.8s for a sampling rate of 10kHz. Since this latency is much too high for my purpose, I tried to overwrite the buffer starting from a short time in the future, once my program is ordered to change the output ASAP:

 

self.SetWriteRelativeTo(daq.DAQmx_Val_FirstSample)  # relative to 1st sample
self.SetWriteOffset(offset)                         # offset is calculated to be between
                                                    # GetWriteTotalSampPerChanGenerated(...) and GetWriteCurrWritePos(...)
self.WriteAnalogF64(...)

Unfortunately the last line produces errors unless offset is smaller than the latest write position:

 

PyDAQmx.DAQmxFunctions.DAQError: Attempted to write samples that have already been generated or have already been sent to the device for generation.

Increasing the buffer size or writing the data more frequently might correct the problem.
Property: DAQmx_Write_RelativeTo
Corresponding Value: DAQmx_Val_FirstSample
Property: DAQmx_Write_Offset
Corresponding Value: 2400

Task Name: _unnamedTask<0>

Status Code: -200289
 in function DAQmxWriteAnalogF64

So I basically have two questions:

  1. Is this the right way to achieve near-real time output generation anyway?
  2. What can be done about the "overwrite error"?
0 Kudos
Message 1 of 2
(2,684 Views)

Additional info:

I even tried the example VI from Data Transfer Request Condition for Continuous Analog Output using NI-DAQmx, but the delay (between switching output waveform and actual chage of the output) was always on the order of 8000 samples (4-5 seconds for a sample rate of 2000 S/s), no matter which mode I chose.  Could this be an inherent issue with the DAQ (connected via USB, NI USB-6259 BNC) and would a PCI or PCIe device have significantly less latency?

0 Kudos
Message 2 of 2
(2,562 Views)