04-18-2012 01:19 PM
I would like to repeatedly make n Analog readings in a program, however, I am unable to accomplish this without creating a new task each time... perhaps I'm doing something wrong.
Here is my pseudo-code:
DAQmxErrChk(DAQmxCreateTask("", &taskHandleAI));
DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandleAI, ...));
DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandleAI,...));
Loop start
DAQmxErrChk(DAQmxStartTask(*taskHandleAI));
DAQmxErrChk(DAQmxWaitUntilTaskDone(*taskHandleAI, 0.001));
DAQmxErrChk(DAQmxReadAnalogF64(*taskHandleAI, ...));
DAQmxErrChk(DAQmxStopTask(*taskHandleAI));
parse_data_and_do_something();
Loop end
The very first read seems to work fine, however, all subsequent reads gets the following error message:
DAQmx Error: Measurements: Task specified is invalid or does not exist.
Status Code: -200088
Does anyone have a clue what is happening?
04-18-2012 03:19 PM
Hello,
Without actually seeing your block diagram it is hard to see what might be the problem. But from just looking at your pseudo-code I would move the StartTask, WaituntilTaskDone, and StopTask outside of the loop. Just have the ReadTask inside the loop.
Hope this helps, Good-Luck.
Steven
04-18-2012 04:05 PM
Sorry, I'm implementing this in C so I don't have block diagrams...
I tried moving start/wait/stop outside of the loop, the exact same error occurs.
I actually don't understand why you would do that though...
Let's say the loop only iterates 2 cycles, if we unroll the code I have, we get:
DAQmxErrChk(DAQmxCreateTask("", &taskHandleAI));
DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandleAI, ...));
DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandleAI,...));
//first loop
DAQmxErrChk(DAQmxStartTask(*taskHandleAI));
DAQmxErrChk(DAQmxWaitUntilTaskDone(*taskHandleAI, 0.001));
DAQmxErrChk(DAQmxReadAnalogF64(*taskHandleAI, ...));
DAQmxErrChk(DAQmxStopTask(*taskHandleAI));
parse_data_and_do_something();
//second loop
DAQmxErrChk(DAQmxStartTask(*taskHandleAI));
DAQmxErrChk(DAQmxWaitUntilTaskDone(*taskHandleAI, 0.001));
DAQmxErrChk(DAQmxReadAnalogF64(*taskHandleAI, ...));
DAQmxErrChk(DAQmxStopTask(*taskHandleAI));
parse_data_and_do_something();
Your suggestion seems to imply the following:
DAQmxErrChk(DAQmxCreateTask("", &taskHandleAI));
DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandleAI, ...));
DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandleAI,...));
DAQmxErrChk(DAQmxStartTask(*taskHandleAI));
DAQmxErrChk(DAQmxWaitUntilTaskDone(*taskHandleAI, 0.001));
//first loop
DAQmxErrChk(DAQmxReadAnalogF64(*taskHandleAI, ...));
parse_data_and_do_something();
//secondloop
DAQmxErrChk(DAQmxReadAnalogF64(*taskHandleAI, ...));
parse_data_and_do_something();
DAQmxErrChk(DAQmxStopTask(*taskHandleAI));
What triggers the read to start in this case?
04-18-2012 05:26 PM
The DAQmxErrChk(DAQmxReadAnalogF64(*taskHandleAI, ...)); initiates a read. What did you think did?
Noticed the wait until task is done function. That does not belong anywhere. Have you looked at the C examples (i.e. Cont Acq-Int Clk)