05-10-2012 04:05 PM
I am outputting digital outputs continuously using DAQmxCfgSampClkTiming and the DAQmx_Val_ContSamps parameter. This works, it cycles repeatedly through a single buffer I supply. But when I call DAQmxStopTask, the task is stopped immediately, in the middle of the buffer. I would like to have the system only stop when it is at the end of the buffer. Is there any way to accomplish this?
Alternatively, is there any way to know exactly where it was in the buffer when it stopped?
I am using a NI6353 board and the NI-DAQmx C API.
Thanks for your help. If there is a better forum for posting this question, please let me know. I could not find a software forum for the NI_DAQmx C API.
05-11-2012 12:54 PM
There is. I would start with DAQmx_Read_AvailSampPerChan &DAQmx_Read_CurrReadPos. More information at the NI-DAQmx C Reference Help.
05-13-2012 08:44 AM
I am writing (outputting) digital values, not reading. So I think you mean DAQmxGetWriteCurrWritePos().
That looked good, but doesn't seem to work. If I call DAQmxGetWriteCurrWritePos after calling DAQmxStopTask, it always returns a value equal to the buffer size. If I call it before I call DAQmxStopTask, I get various values, but they are all larger than the buffer size. I would expect the value to range from 0 to the buffer size.
Is there an examle that does this, or can you provide any more guidance?
05-14-2012 12:37 PM
The same options are available for writing operations, take a look at the picture. I could not find the examples but this options should give you a starting point.
06-26-2012 11:39 AM
I'm not aware of a way to force a continuous task to end at a specific point (such as the end) in the output buffer at a precise hardware-timed level. Here's the kind of thing I'd try to do as a workaround:
1. When you're ready to stop after the completion of this particular cycle through the buffer, make 2 consecutive write calls which each write 1/2 buffer of data. The data should simply be the last desired digital state duplicated for 1/2 buffer size.
2. If you only originally wrote your pattern once to the buffer before starting to regenerate, the new write should circle back to the beginning of the buffer to start overwriting the old pattern. However, DAQmx should manage the timing & negotiations for you so that this new data won't overwrite the old data until it's "safe."
3. By the time you return from writing both 1/2 buffers, the task will necessarily be outputting that final digital state. You should be able to stop the task at any time.
4. Even if you can't react and stop right away, the task should happily regenerate the same final digital state forever until you stop the task.