Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to loop AI Voltage readings without creating a new task everytime?

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?

0 Kudos
Message 1 of 4
(3,324 Views)

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

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

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?  

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

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)

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