Revisitng this topic because it is again causing problems. The code snippet I suggested earlier has a problem: it introduces a random phase shift of the input data relative to the clock that is used to drive a simultaneous output.
Previous code snippet for the error handler:
Case -200279
' Force DAQmx to read the most recent sample in the buffer
DAQmxErrChk (DAQmxSetReadOffset(ByVal AITaskHandle, -1&))
DAQmxErrChk (DAQmxSetReadRelativeTo(ByVal AITaskHandle, DAQmx_Val_MostRecentSamp))
' now read just one value to resynch everything
DAQmxErrChk (DAQmxReadAnalogF64(AITaskHandle, -1, 1#, DAQmx_Val_GroupByChannel, AIData(0), 1&, sampsperchanread, ByVal 0&))
' now reset DAQmx to read from the current position from now on
DAQmxErrChk (DAQmxSetReadOffset(ByVal AITaskHandle, 0&))
DAQmxErrChk (DAQmxSetReadRelativeTo(ByVal AITaskHandle, DAQmx_Val_CurrReadPos))
The comment "resynch everything" is not correct, it just resynchs the AIRead to the latest (random) position.
What I mean by this is that suppose the system is set up with both AO and AI channels, and read/write is controlled by a clock. The AO and AI remain in step forever (they have identically sized buffers). If the 200279 error occurs (for instance in our case if the CPU is too busy or the USB bus is overloaded), then the above code does indeed clear the 200279 error and restarts the AI, but now the AIData() array is out of step with the AOData() array. In other words, a given index into the two arrays gives values that are not taken/written at the same time.
I can fix this by stopping the clocks, restarting both the AI and AO, and then restarting the clocks. They are now resynchronized. Unfortunately, in doing this my sample is destroyed by the sudden stop/start of the AO.
What I need is a simple way to resynchronize the indices that DAQmx is using to read/write from/to the buffers. I must not mess with the AO process, but I need the AI to "catch up" with the AO.
Ideas?
Thanks,
Van