12-16-2014 02:30 AM
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
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!
12-18-2014 07:24 AM
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.
12-18-2014 07:30 AM
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!
01-09-2015 05:05 AM
Hello,
I'm back to this problem...
Does anybody have any Idea that could help?
thanks.