Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

NI9402: WriteDigitalLines within a for loop().Some or all of the samples to write could not be written to the buffer yet.

 

I am writting two different signals with NI9402, one for the clock and the other for the data.
I have created two channels, one for the data and another for the clock.
My goal is to test the DAQmxWriteDigitalLines function within a loop with different payload each time. From (0 to 4000 bytes).
In each iterations I calculate the size of the payload and send the signal out. The Clock 101010.. would go by line0 and the payload (111...) will go by line1.
There is a simplified version of the code:

 

DAQmxErrChk (DAQmxCreateDOChan(taskData,"cDAQ1Mod1/port0/line0","dataOutClock",DAQmx_Val_ChanPerLine));
DAQmxErrChk (DAQmxCreateDOChan(taskData,"cDAQ1Mod1/port0/line1","dataOutData",DAQmx_Val_ChanPerLine));
DAQmxErrChk (DAQmxCfgSampClkTiming(taskData,NULL,2000000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,DAQmx_Val_ContSamps)); 

 

for(i=0;i<4000;i++){

ClockAndData=(i)*2; // *2 because of the clock
free(data);
free(infoVect);
infoVect=malloc(i); //the useful payload of this iteration
data=malloc(ClockAndData);

printf("Clock : ");fflush(stdout);
for(k=0;k<ClockAndData/2;k++){
data[k]=k%2;
printf("%d",data[k]); }

 

printf("Info Vect : ");fflush(stdout); //I set the 'i' bits of payload to 1
for(k=0;k<i;k++){
data[ClockAndData/2+k]=1; // the firsts ClockAndData/2 bits are for the channel 1 (clock)
}
DAQmxErrChk (DAQmxWriteDigitalLines(taskData,ClockAndData/2,1,30.0,DAQmx_Val_GroupByChannel,data,NULL,NULL)); 

}

If I start by a small 'i' in the loop, after the firsts iterations of the loop I get the error listed below. On the other hand if I start with a high value of 'i', let's say 200, The NI9402 succesfully write all the sample with the variable payload.


DAQmx Error: Some or all of the samples to write could not be written to the buffer yet. More space will free up as samples currently in the buffer are generated.

To wait for more space to become available, use a longer write timeout. To make the space available sooner, increase the sample rate.
Property: DAQmx_Write_RelativeTo
Corresponding Value: DAQmx_Val_CurrWritePos
Property: DAQmx_Write_Offset
Corresponding Value: 0

Task Name: taskData

Status Code: -200292

 

Does anybody know how could I fix this ? I have tried to put sleep() before each write, but I still get the same error.. could it be a problem of the clock DAQmxErrChk (DAQmxCfgSampClkTiming(taskData,NULL,2000000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,DAQmx_Val_ContSamps));  ? 

 

Thank you very much

0 Kudos
Message 1 of 2
(5,189 Views)

Hi Coquivhdl,

 

There is some good information posted by John_P1 on this post here that I believe you will find helpful. The link in his post leads to a longer forum about a similar issue that could help answer your question about error -200292. 

Robert R. | Applications Engineer | National Instruments
0 Kudos
Message 2 of 2
(5,160 Views)