User manual

Chapter 4 NI-DAQ Double Buffering
© National Instruments Corporation 4-7 NI-DAQ User Manual for PC Compatibles
The double-buffered output operation begins when the output device begins
outputting data from the first half of the circular buffer (Figure 4-4a). After
the device begins retrieving data from the second half of the circular buffer,
NI-DAQ can copy the prepared data from the transfer buffer to the first half
of the circular buffer (Figure 4-4b). Your application can then update the
data in the transfer buffer. After the output device is finished with the
second half of the circular buffer, the device returns to the first half buffer
and begins outputting updated data from the first half. NI-DAQ can
now copy the transfer buffer to the second half of the circular buffer
(Figure 4-4c). The data in the transfer buffer is again available for update
by your application. The process can be repeated endlessly to produce
a continuous stream of output data from your application. Notice that
Figure 4-4d is equivalent to the step in Figure 4-4b and is the start of a
two-step cycle.
Potential Setbacks
Like double-buffered input, double-buffered output has two potential
problems. The first is the possibility of the output device retrieving and
outputting the same data before NI-DAQ has updated the circular buffer
with new data from the transfer buffer. This situation is illustrated by
Figure 4-5.
Notice in Figure 4-5b, NI-DAQ has missed the opportunity to copy data
from the transfer buffer to the first half of the circular buffer while the
output device is retrieving data from the second half. As a result, the
device begins to output the original data in the first half of the circular
buffer before NI-DAQ has updated it with data from the transfer buffer
(Figure 4-5c). To guarantee uncorrupted output data, NI-DAQ is forced
to wait until the device finishes retrieving data from the first half before
copying the data from the transfer buffer. After the device has begun to
output the second half, NI-DAQ copies the data from the transfer buffer
to the first half of the circular buffer (Figure 4-5d).