Multifunction DAQ

Showing results for 
Search instead for 
Did you mean: 

Write Analog value timeout (NiDAQmx using C++)

Go to solution

I tried to write to analog output channel with an external trigger source - PFI0.  The write operation times out even after I write values 0 and 1 to the digital channel- Dev1/PFI0 within the timeout period. The error message obtained is given below

Wait Until Done did not indicate that the task was done within the specified timeout.
Increase the timeout, check the program, and make sure connections for external timing and triggering are in place.
Task Name: _unnamedTask<17>
Status Code: -200560


The code that I used for the write operation is given below. The write operation succeeds when I set the source terminal of the Sample Clock as internal source of the device in the API DAQmxCfgSampClkTiming.   


What could be the issue with the following code?

double dValues[2]{ 2, 2 };

int32 nError = DAQmxCreateTask("", &oTask);

nError = DAQmxCreateAOVoltageChan(oTask, "Dev1/AO1", "", -3.25, 3.25, DAQmx_Val_Volts, nullptr);

nError = DAQmxCfgSampClkTiming(oTask, "PFI0", 50.0, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 2);

nError = DAQmxCfgDigEdgeStartTrig(oTask, "PFI0", DAQmx_Val_Rising);

nError = DAQmxWriteAnalogF64(oTask, 2, 1, 60, DAQmx_Val_GroupByChannel, dValues, nullptr, nullptr);

nError = DAQmxWaitUntilTaskDone(oTask, 60);


0 Kudos
Message 1 of 2
Accepted by topic author kiran_t

I find it unusual to specify PFI0 as both a trigger signal *and* a sample clock signal.  


In DAQmx, a trigger is a very different thing than a sample clock.  I've seen a lot of confusion on the forums over the years when posters use the terms differently than DAQmx defines them.


I would expect to see a line of code where you call a function to *start* the task after writing data and before waiting for the task to be done.  (I don't know the text API, but in LabVIEW the write function includes an optional argument for "autostart".  You may or may not be getting that autostart behavior, but I'd recommend you do an explicit start and make sure.)


Otherwise, I think you'd need to pulse PFI0 3 times for your task not to timeout.  The first pulse will be seen as the trigger.  But it very likely won't be seen as a sample clock, because the task wouldn't have been ready to receive one until after it was armed by its trigger.  So the 2nd pulse would be seen as the 1st sample clock and the 3rd pulse would be the 2nd sample clock.  That should end your 2-sample finite output task, and the wait function should return without timing out.



-Kevin P

Message 2 of 2