LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmxStartTask does not start data acquisition

I recently received my USB-6008 device and I am trying to get repeatable results from it.  The task does not always seem to be started when I use a simple program (very similar to ContAcq-IntClk-AnlgStart example program) to read from a single analog input channel.  About 50% of the time I do not get any errors but the read function never gets any samples returned.    Code snippet:
 
stat = DAQmxCreateTask ("MyTask", &mytask);
 stat = DAQmxCreateAIVoltageChan (mytask, "Dev1/ai0", "Ch1", DAQmx_Val_Cfg_Default, -5.0, 5.0, DAQmx_Val_Volts, "");
  stat = DAQmxCfgSampClkTiming (mytask, "OnboardClock", 100, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 100);
loop while reading
stat = DAQmxReadAnalogF64 (mytask, DAQmx_Val_Auto, 0, DAQmx_Val_GroupByScanNumber, data, arraysize, &count, 0);
 
 
stat = DAQmxStopTask( mytask );
stat = DAQmxClearTask( mytask );

 
0 Kudos
Message 1 of 4
(3,355 Views)
Hi Mande!

    Your code seems good, but I don't see DAQmxStartTask() function.

    I can also suggest you to:
      a)  Use Finite samples instead of Continue samples reading in DAQmxCfgSampClkTiming (mytask, "OnboardClock", 100, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 100);
           to read a fixed number of points, once.
      b)  Use
DAQmxWaitUntilTaskDone() to wait for task to finish, before using data. 

I hope it helps, and please, let me know if you can fix your problem!

Bye.

graziano

0 Kudos
Message 2 of 4
(3,340 Views)
Hello Mande,

I would suggest allowing a timeout period (10s or so) in your DAQmxReadAnalogF64 call.  It seems likely that the data is accumulating in the device buffer before being transmitted across the USB connection to the DAQ driver's memory.  If you try to read the samples before they are available in the driver's memory, and you do not specify a timeout, DAQmxReadAnalogF64 will return without reading any samples.

I hope this helps.

Mert A.
National Instruments
0 Kudos
Message 3 of 4
(3,339 Views)

Thank you for the feedback.

I am sorry, I did miss showing the start task function, it is in there just before looping while reading.

stat = DAQmxStartTask( mytask );
 

My application supports probably 20 different NI cards, this being selected by the end user.  The intent is that data is constantly being collected in the background while there is an entire script being run in the foreground.  I cannot wait for data to be returned, I simply check if there is any data available, I check this between 10 to 100 times a second and provide the current input data to the foreground script.

I modified the sample program to not use triggers and it behaves the same way.  About half of the time there is never any data available to the read function.  I stop it and start again and there may or may not be data available.

 

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