Acquisition modes
Buffer handling
(c) Spectrum GmbH
77
Step 6: roll over the end of buffer
Now nearly the complete buffer is filled. Please keep in mind that our cur-
rent user position is still at the end of the data part that we got in step 4.
Therefore the data to process now is split in two parts. Part 1 is at the end
of the buffer while part 2 is starting with address 0.
Step 7: set the rest of the buffer available
Feel free to process the complete data or just the part 1 until the end of
the buffer as we do in this example. If you decide to process complete
buffer please keep in mind the roll over at the end of the buffer.
This buffer handling can now continue endless as long as we manage to
set the data available for the card fast enough.
Buffer handling example for transfer from card to PC
char* pcData = new char[lBufferSizeInBytes];
// we now define the transfer buffer with the minimum notify size of on page = 4 kByte
spcm_dwDefTransfer_i64 (hDrv, SPCM_BUF_DATA, SPCM_DIR_CARDTOPC , 4096, (void*) pcData, 0, lBufferSizeInBytes);
// we start the DMA transfer
dwError = spcm_dwSetParam_i32 (hDrv, SPC_M2CMD, M2CMD_DATA_STARTDMA);
do
{
if (!dwError)
{
// we wait for the next data to be available. Afte this call we get at least 4k of data to proceed
dwError = spcm_dwSetParam_i32 (hDrv, SPC_M2CMD, M2CMD_DATA_WAITDMA);
// if there was no error we can proceed and read out the available bytes that are free again
spcm_dwGetParam_i32 (hDrv, SPC_DATA_AVAIL_USER_LEN, &lAvailBytes);
spcm_dwGetParam_i32 (hDrv, SPC_DATA_AVAIL_USER_POS, &lBytePos);
printf (“We now have %d new bytes available\n”, lAvailBytes);
printf (“The available data starts at position %d\n”, lBytesPos);
// we take care not to go across the end of the buffer
if ((lB lAvailBytes) >= lBufferSizeInBytes)
lAvailBytes = lBufferSizeInBytes - lBytePos;
// our do function gets a pointer to the start of the available data section and the length
vDoSomething (&pcData[lBytesPos], lAvailBytes);
// the buffer section is now immediately set available for the card
spcm_dwSetParam_i32 (hDrv, SPC_DATA_AVAIL_CARD_LEN, lAvailBytes);
}
}
while (!dwError); // we loop forever if no error occurs