Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmxStopTask hangs for NIDAQ6009

Our NIDAQ 6009 hangs indefinitly on DAQmxStopTask after several minutes of reading data. When hanging, DAQmxStopTask only returns if the device is disconnected. Run time until hang is fairly random, but gets shorter as the sample rate is increased. At a very high sample rate like 10000, a hang usually occurs after about 20 seconds. For a sample rate of between 1000 and 5000, time until hang varies randomly between around 5 and 60 minutes. Hanging happens sooner when using 2 DAQs (with one task for each DAQ), but is still a problem when only using 1 DAQ.

 

The problem can be aleviated by using a low sampling rate, but we don't have a lot of confidence in this as a robust solution due to the probabilistic nature of the hangs.

Note that we are calling Start and Stop for every read. No error codes have been returned. We have tested with 9.1 and 9.5.1 drivers.

 

Here's our code:

 

// Init

const double SAMPLE_RATE = 5000;
const int SAMPLES_PER_CHANNEL = 100;
const int DATA_BUFFER_SIZE = 400;
const double MIN_VOLTAGE = 0.0;
const double MAX_VOLTAGE = 10.0;
int taskHandle = 0;

DAQmxErrChk (DAQmxCreateTask("",&m_taskHandle));

DAQmxCreateAIVoltageChan(taskHandle, "Dev1/ai0", "ai0", DAQmx_Val_RSE, MIN_VOLTAGE, MAX_VOLTAGE, DAQmx_Val_Volts, NULL);
DAQmxCreateAIVoltageChan(taskHandle, "Dev1/ai1", "ai1", DAQmx_Val_RSE, MIN_VOLTAGE, MAX_VOLTAGE, DAQmx_Val_Volts, NULL);
DAQmxCreateAIVoltageChan(taskHandle, "Dev1/ai2", "ai2", DAQmx_Val_RSE, MIN_VOLTAGE, MAX_VOLTAGE, DAQmx_Val_Volts, NULL);
DAQmxCreateAIVoltageChan(taskHandle, "Dev1/ai3", "ai3", DAQmx_Val_RSE, MIN_VOLTAGE, MAX_VOLTAGE, DAQmx_Val_Volts, NULL);
DAQmxCfgSampClkTiming(taskHandle, "", SAMPLE_RATE, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, SAMPLES_PER_CHANNEL);


// .....
// For each update

DAQmxStartTask(taskHandle);
int32 read;

DAQmxReadAnalogF64(taskHandle, SAMPLES_PER_CHANNEL, 10.0, DAQmx_Val_GroupByChannel, m_data, DATA_BUFFER_SIZE, &read, NULL);
DAQmxStopTask(taskHandle);


0 Kudos
Message 1 of 6
(3,549 Views)

MReid,

 

This seems interesting.  What I'd suggest first is to add DAQmxClearTask(TaskHandle) after the stop task to see if the program is hanging because the task can't be cleared.  I'd also suggest adding some error handling exceptions as in this sample in case an unhandled error message may be causing an issue:

 

// Stop and clear task

Error:

       if( DAQmxFailed(error) )

              DAQmxGetExtendedErrorInfo(errBuff,2048);

       if( taskHandle!=0 )  {

              DAQmxStopTask(taskHandle);

              DAQmxClearTask(taskHandle);

       }

       if( DAQmxFailed(error) )

              printf("DAQmx Error: %s\n",errBuff);

              return 0;

 

Which is expanded upon in this article: http://www.ni.com/white-paper/5409/en

National Instruments
0 Kudos
Message 2 of 6
(3,534 Views)

We actually have error checking on all functions. I didn't show error checking there for readibility. I'm not seeing any errors detected.

 

I tried creating and clearing the task for every read, but I still get a hang in DAQmxStopTask. Are you suggesting to call DAQmxClearTask from a different thread while DAQmxStopTask is blocking indefinitly?

0 Kudos
Message 3 of 6
(3,522 Views)

Turns out the problem was caused by a multi-port USB adapter. If we run the devices straight to the PC's ports it works.

0 Kudos
Message 4 of 6
(3,515 Views)

MRied,

 

I have heard of similar problems with the USB-6009 going through a hub in the past.  Depending on your system, upgrading the drivers may possibly alleviate this issue.  At any rate, glad to hear it's working curently.

 

Regards,

National Instruments
0 Kudos
Message 5 of 6
(3,503 Views)

Different brand hubs work differently too. 

 

Used to use cheap D-link hubs in all our equipment.  Switched them over to Startech hubs (which convienently have a 7-24V DC terminal block power input) and the test errors went down significantly.  Those Startech hubs are certainly worth the money.

0 Kudos
Message 6 of 6
(3,498 Views)