Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Error - when stopping a task-200018

Hello all,

 

I have a simple C application where I write to an analog value to a current output card (cDAQ 9265) on a USB rack (cDAQ-9178) every 1ms.

I wrote a C code which works ok until the time I stop the output task. When I stop I get the error -20018 

Spoiler
DAC conversion attempted before data to be converted was available.

Decrease the output frequency to increase the period between DAC conversions, or reduce the size of your output buffer in order to write data more often. If you are using an external clock, check your signal for the presence of noise or glitches.

I don't know how to solve it... someone has an idea?

 

My code:

//create variables
float64 buffer[32];
int32 bytesPerSamp=4;
int32 SampPerChan=1;

// Create task
DAQmxCreateTask("",&taskHandle);

// add channels to task
DAQmxCreateAOCurrentChan  (taskHandle, "cDAQ3Mod2/ao0" , "" , 0 , 0.02,  DAQmx_Val_CurrentUnits2_Amps ,  "");
DAQmxCreateAOCurrentChan  (taskHandle, "cDAQ3Mod2/ao1" , "" , 0 , 0.02,  DAQmx_Val_CurrentUnits2_Amps ,  "");

//Clock
DAQmxCfgSampClkTiming(taskHandle,"",100000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,1000000);

//This line avoids the error of starting task with nothing to output
DAQmxWriteAnalogF64(taskHandle,2,false,0,DAQmx_Val_GroupByScanNumber,buffer,&bytesPerSamp,NULL);

DAQmxSetWriteRelativeTo(taskHandle,	DAQmx_Val_FirstSample);

// Loop every 1 ms
while (something...)
{
.. do something
buffer[0]=k1;	// value to go to channel 0	
buffer[1]=k2;	// value to go to channel 1    

DAQmxWriteAnalogF64(taskHandle, 2, false,0,DAQmx_Val_GroupByScanNumber, buffer, &bytesPerSamp,0);
}

// end - Here I get the error:
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);


 

Thanks for any tip!

0 Kudos
Message 1 of 4
(4,012 Views)

Hi aranteg,

 

Where do you start your task in the program? DAQmxStartTask(taskHandle) is missing here.

 

you should find a good C-example in "C:\Users\Public\Documents\National Instruments\CVI\samples\DAQmx\Analog Out\Generate Current\Gen 0-20mA Current"

 

Best Regards.

0 Kudos
Message 2 of 4
(3,970 Views)

Hello, the "Start task" is really missin on the snippet that I coopied here!
The "start task" is after:

DAQmxSetWriteRelativeTo(taskHandle, DAQmx_Val_FirstSample);

 
And before the while loop.

 

The problem using the example that you indicated is that the time for execution of this code example is arround 2ms and I need it to be under 1ms.

 

Thanks for your answer!

0 Kudos
Message 3 of 4
(3,966 Views)

Hello,

I'm back to this problem...

 

Does anybody have any Idea that could help?

 

thanks.

0 Kudos
Message 4 of 4
(3,837 Views)