I cannot figure out how to use NIDAQmx (calling from Visual C++) for a 6534 app I am developing. I want to output a short (5 msec) buffer continuously for some period of time (seconds or minutes), then change the output buffer contents on the fly without a glitch. I have read the NI manuals (especially the sections on Buffering and Glitching), looked at the example code, and looked at many entries in Developer Zone. They all say I can do this but I have yet to figure out the exact NIDAQmx calls to load the second buffer while the first one is running.
I can successfully output the first buffer, stop the task, load the second buffer, and restart the task, but of course that is not
seamless and is unacceptable for the app I am writing.
Here is the relevant sample code I have now (less error checking):
const int iSize = 500;
iStatus = DAQmxCreateTask("Pattern", &mhPattern);
iStatus = DAQmxCreateDOChan(mhPattern, "EPStimPattern/port0", "Pattern", DAQmx_Val_ChanForAllLines);
iStatus = DAQmxSetDOUseOnlyOnBrdMem(mhPattern, "Pattern", false);
iStatus = DAQmxCfgSampClkTiming(mhPattern, 0, 1e5, DAQmx_Val_Rising, DAQmx_Val_ContSamps, iSize);
int32 n, iWritten;
for (n=0; n<200; n++) pwStimPatternA[n] = 0;
for ( ; n<300; n++) pwStimPatternA[n] = 1;
for ( ; n<iSize; n++) pwStimPatternA[n] = 0;
for (n=0; n<100; n++) pwStimPatternB[n] = 0;
for ( ; n<400; n++) pwStimPatternB[n] = 1;
for ( ; n<iSize; n++) pwStimPatternB[n] = 0;
iStatus = DAQmxWriteDigitalU16(mhPattern, iSize, false, 0., DAQmx_Val_GroupByChannel, pwStimPatternA, &iWritten, 0); iStatus = DAQmxStartTask(mhPattern);
Sleep(20); // sample run time shortened for viewing on oscilloscope
// if I do another WriteDigitalU16 here I get a 200015 error
// the manual seems to say that if I disable regeneration, then rewriting the buffer in system memory will output the new
// buffer next time, but this also does not work. The first buffer continues to be generated for another 30 msec.
CopyMemory(pwStimPatternA, pwStimPatternB, (iSize * sizeof(uInt16)));
iStatus = DAQmxStopTask(mhPattern);
iStatus = DAQmxClearTask(mhPattern);
Any help here would be much appreciated.
Thanks for posting to the NI Discussion Forums. I understand that you are trying to perform a continuous digital generation using a 6534, and would like to update the output pattern on-the-fly (I assume based on pressing a button in the software). The 200151 code is a warning that will be returned when you write new samples to the buffer and regeneration is enabled. Thus, disabling regeneration and constantly performing a write (ie - streaming from memory) is the best option at the rate you are outputting. However, you are correct that you will experience a small delay (usually a few cycles) as the old data which was placed in the buffer is flushed out and the new data begins to update. Due to the nature of this device, there is no way around this; the output is not glitching, but it will not be an immediate update. The type of functionality you are looking for would best be obtained by using one of the 654x devices, which allows the use of scripting. With these devices, you can load multiple waveforms into memory and run one waveform until you send a script trigger to begin immediately updating the next waveform. More information about scripting with HSDIO devices can be found here. Hope this helps,