Solution
This error occurs when DAQmx Read attempts to return data after the DAQ device has stopped acquiring data.
One common occurrence of this error is when DAQmx Read is used inside of a while loop while the task is configured for finite acquisition. When the
Sample Mode property of DAQmx Timing is set to
Finite Samples, the DAQ device will acquire data for a number of samples, at which point it will stop acquiring data and throw error -200278 if DAQmx Read is called again.
Note: If you do not explicitly configure the
Sample Mode property for DAQmx Timing, the default value is
Finite Samples. If you desire
Continuous Samples, remember to explicitly configure this property appropriately.
There are several potential solutions below to resolve Error -200278 in your DAQmx application outlined below:
Solution 1: Remove the While LoopIf you are performing a finite acquisition, most likely a while loop is unnecessary, as you are only acquiring a single array of samples across a finite period. In this case, the easiest solution is to just remove the while loop, as in the example code below:
Solution 2: Configure DAQmx to Acquire ContinuouslyIf a while loop is needed, another solution is to configure the task to acquire
Continuous Samples instead of
Finite Samples. When this option is selected, the DAQ device will continue acquiring data until the task is explicitly stopped.
Solution 3: Restart Acquisition in a While LoopIf you do need to use
Finite Samples and you need to use a while loop, the task will need to be restarted to continue acquiring data after the first read is complete. This can be accomplished by starting and stopping the task inside of the loop as in the example code below:
Note: In order to improve performance, you should manually move the DAQmx task to the Commit State before entering the while loop, as is shown in the example above. You can read more about the Commit State and other DAQmx Task States at NI-DAQmx Help: Task State Model .
Solution 4: Use Is Task Done? in While Loop
In some cases, you may be interested in acquiring a subset of the complete finite acquisition before the acquisition is complete. In this case, you can manually specify a number of samples that is lower than the total number of samples being acquired.
In the example below, the DAQmx Read property Status»Available Samples Per Channel is used to determine how many samples are currently in the DAQmx buffer and make a read request for the number of samples available in the buffer at that moment.
After DAQmx Read is called, the DAQmx Is Task Done? function is used to identify whether the finite acquisition is complete.