12-04-2013 02:00 AM
Hi all,
I am using 6711 card and trying to output some samples to analog channel. In the mid way, I will stop the task, redirect the buffer pointer, set the trigger mode and restart the task again. I try the following code
void output(void)
{
double data[1000];
for (int i=0; i<200; i++) data[i]=8.5;
for (int i=200; i<700; i++) data[i]=4.2;
for (int i=700; i<800; i++) data[i]=3;
for (int i=800; i<1000; i++) data[i]=0.0;
DAQmxCfgSampClkTiming(AO_task, NULL, 100000, DAQmx_Val_Falling, DAQmx_Val_FiniteSamps,1000);
DAQmxWriteAnalogF64(AO_task, 1000, 0, 10, DAQmx_Val_GroupByChannel, data, NULL, NULL);
DAQmxStartTask(AO_task);
Sleep(1);
DAQmxStopTask(AO_task);
// other calculation (not related to DAQ)
DAQmxCfgDigEdgeStartTrig(AO_task, "/Dev1/PFI0", DAQmx_Val_Rising);
DAQmxSetWriteAttribute(AO_task, DAQmx_Write_RelativeTo, DAQmx_Val_FirstSample);
DAQmxSetWriteAttribute(AO_task, DAQmx_Write_Offset, 700);
DAQmxStartTask(AO_task);
// other calculation (not related to DAQ)
DAQmxWaitUntilTaskDone(AO_task, 10);
DAQmxStopTask(AO_task);
}
The task AO_task created somewhere else. Above function will be called several times. But I find that it is running without any problem for the first time. But if I call it again, the following error comes out
"The generation is not yet started, and not enough space is available in the buffer.
Configure a larger buffer, or start the generation before writing more data than will fit in the buffer.
Property: DAQmx_Write_RelativeTo
Corresponding Value: DAQmx_Val_FirstSample
Property: DAQmx_Write_Offset
Corresponding Value:700
Property: DAQmx_Buf_Output_BufSize
Corresponding Value: 1000
Task Name: AO_task
Status Code:-200293"
I wonder what error is that, why can't I reset the pointer of the buffer. Thanks.
12-05-2013 02:27 PM
Since you are rewriting the data array each time you call the output function, I would recommend using a DAQmxClearTask function before your last DAQmxStopTask function to clear out the buffer since you are rewriting it anyways.
Please let me know if this helps.
12-05-2013 04:40 PM
@Holly-S wrote:
Since you are rewriting the data array each time you call the output function, I would recommend using a DAQmxClearTask function before your last DAQmxStopTask function to clear out the buffer since you are rewriting it anyways.
Please let me know if this helps.
Thanks for your reply. But if I use DAQmxClearTask to clear the task, I have to create the task again each time I write to the buffer again, right? Since the same task are used many different places in the code, some place are writing single sample and some are writing multiple data, so I would like to create the task once and use everywhere until the application closed. So besides clearing the task, any other function could use to clean the buffer? Thanks.