Overlapped execution, Foreground-linear transfers, On…… 8-19 – Measurement Computing WaveBook rev.3.0 User Manual
Page 153

WaveBook User’s Manual.
6-24-99
Theory of Operation 8-19
Overlapped Execution
It is often desirable to continue execution of the application program while the acquisition continues
automatically in the background. daqAdcTransferBufData controls this overlapped execution and
configures data transfers to be either:
• foreground transfers, in which the daqAdcTransferBufData command waits for the transfer to
complete before returning to the application program
• background transfers, in which the command returns as soon as possible to the application.
The overlapped operation is controlled by the "foreground" argument to daqAdcTransferBufData.
If true, the argument specifies that wbkBufferTransfer must wait for the transfer to complete; if false, that
daqAdcTransferBufData
must return immediately.
Foreground transfers are simple to use. After daqAdcTransferBufData starts a foreground transfer,
that command waits for the transfer to complete before returning control to the application program. This
allows the application to assume the data is in the buffer and ready to be analyzed or stored.
Background transfers are more complex. After daqAdcTransferBufData starts a background transfer,
it returns control immediately to the application program. The application cannot assume anything about
the contents of the buffer. Instead, it must use the daqAdcTransferGetStat command to retrieve the
state of the buffer and determine if it contains any data to be processed.
Despite the complexity, background transfers are often used because the application can continue execution
during the transfer—such as processing previously acquired data and responding to user input or other
events during the acquisition. This capability can greatly improve the application's efficiency and usability.
The diagram shows how the PC directs its attention during foreground and background transfers:
Foreground-transfer mode
Application program
WaveBook data transfer
wbkBufferTransfer
Transfer
Done
Transfer
Done
Overlapped Execution
Background-transfer mode
Start transfer
Check buffer status
wbkGetBackStat
Pc’s
attention
over
time
The choice of the appropriate combination of foreground, cycle operation, and acquisition mode (as set by
daqAdcSetAcq
) depends on how the application needs to process the received samples. The four
combinations of foreground and cycle (foreground-linear, foreground-circular, background-linear, and
background-circular) are each appropriate for a different approach to data processing. The following
sections describe these approaches and then direct-to-disk transfers.
Foreground-Linear Transfers
Foreground transfers into a linear buffer will transfer data until the buffer is full or until the acquisition
stops. When this occurs, daqAdcTransferBufData returns; and the error code, return count, and
active flag may be examined to decide what action (if any) is necessary. The return count holds the number
of scans that were transferred. This will be the same as the size of the buffer unless the acquisition stopped
before the buffer was filled. The active flag is non-zero if the buffer was not large enough to hold the entire
acquisition and the acquisition is still active. In this case, another daqAdcTransferBufData must be
invoked to transfer the additional samples. If the active flag is zero, the acquisition is complete and the
buffer holds the number of scans indicated by the return count. Because the buffer is linear, the earliest
scan is at the beginning of the buffer and the last scan is toward the end.
Foreground-linear mode may be used with any of the acquisition modes (N-shot, N-shot with re-arm,
pre/post-trigger, and infinite post-trigger) but is most useful in N-shot mode.
In N-shot mode, each acquisition collects exactly N (the post-trigger count) scans. If the buffer is large
enough to hold all the scans, then when daqAdcTransferBufData returns, the entire acquisition will
be ready in the buffer (assuming no error occurred). The scans may then be unpacked (WaveBook/512
only) and analyzed or stored as desired.
In all other acquisition modes, daqAdcTransferBufData will return when the buffer is full, but the
acquisition may not yet be complete. Thus, samples will continue to be acquired, and the application
program may not have much time before it must invoke another daqAdcTransferBufData to continue
the transfer and avoid losing data.