LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to loop AI Voltage readings without creating a new task (NI-DAQmx)?

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));

 

do_something();

 

Loop end

 

The first read seems to work fine, however, all subsequet 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
(2,273 Views)
First, you listed to the wrong board. LabVIEW is not a text language. Second, have you simply tried moving the start and stop task to outside the loop?
0 Kudos
Message 2 of 4
(2,269 Views)

Sorry... is it possible to move a post, or should I simply start another one?

 

Also. I don't fully understand what you mean by moving start & stop outside of the loop... the 'do_something()' part parses the reading results that was just read...

 

are you saying I should not run StartTask/StopTask for each iteration of the loop? 

0 Kudos
Message 3 of 4
(2,258 Views)
That is exactly what I am saying.
0 Kudos
Message 4 of 4
(2,254 Views)