Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

NI USB-6009 Locks up after 4 to 6 reads

Win XP, CVI 7.1
 
I have a NI USB-6009 DAQ that I am trying to use to make a very simple voltage measurement with one differential channel every time a command button is pressed. My app works fine until between 4 to 6 reads (presses of the CMD buttom) then seems to lock up inside the DAQmxBaseReadAnalogF64 function. Any idea what is going on?
 
Here is my trial code:
 
int CVICALLBACK READ (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 switch (event)
  {
  case EVENT_COMMIT:
   Status = DAQmxBaseCreateTask ("TASK1OUTPUT", &task1Handle);
 
   Status = DAQmxBaseCreateAIVoltageChan (task1Handle, "Dev1/ai0", "Output", DAQmx_Val_Diff, -10.0, 10.0,
              DAQmx_Val_Volts, NULL);
 
   Status = DAQmxBaseStartTask (task1Handle);
 
   Status = DAQmxBaseReadAnalogF64 (task1Handle, 1, 5, DAQmx_Val_GroupByChannel, &task1data, 1,
           &pointsRead, NULL);
 
   SetCtrlVal (panelHandle, PANEL_CUR_VAL, task1data);
 
   Status = DAQmxBaseClearTask (task1Handle);
 
   if(Status){
   printf("Status error is: %i", Status);
   }
 
   break;
  }
 return 0;
}
 
Thanks,
Jim
 
 
0 Kudos
Message 1 of 5
(3,491 Views)
Jealclr,

The first thing I'd do is print out the status after each function call, just to make sure that you're not trying to read if the task creation failed (which is probably what's going on). Then I'd add code to abort the operation if the status is bad (Always clear the task though). Depending on the rate at which you press the button, and other heuristics, it is possible that even though you cleared the task, the task name would stick around in memory. I've seen this behavior in measurement studio and I "fixed" it by passing a random task name every time. Note that the fact that the name stays in memory doesn't mean that the task wasn't cleared, or that the driver is using up your resources, it's just a matter of name caching to improve the performance on the rest of the system. Most of the time the only way to guarantee that the cache will be cleared is to close the application.
My real suggestion is that you create the task and the channel and clear the task only once, outside the callback, storing the task handle globally, and then you start the the task, read and stop the task in the handle. This will improve your performance and the responsiveness of your application, since it won't be tied down in the callback doing configuration. Doing it this way also creates only one instance of the class.

I hope this is helpful. Please post any more status information if it doesn't solve the issue.

Greetings

Daniel Domene
Portable DAQ R&D
0 Kudos
Message 2 of 5
(3,478 Views)
 

Hi All-

Daniel's suggestions should be quite helpful- you need to make absolutely sure that you are only accessing the resource from a single call at a time and that you are monitoring error conditions because the commands will not execute if an error has been throw previously.  Creating and destroying the task globally rather than with each iteration of the loop will also provide much greater efficiency in terms of operation.

Finally, you may be interested to know that the USB-6008 is now fully supported by NI-DAQmx 7.5.  This driver is considerably more powerful and offers many advantages over the NI-DAQmx Base driver in terms of speed and flexibility.  Instructions for configuring your USB-6008 for use with NI-DAQmx can be found here

Hopefully this helps-

Tom W
National Instruments
0 Kudos
Message 3 of 5
(3,465 Views)

Thanks for the info. Since this was just a quick trial I was simply stepping through and monitoring the Status variable, which was always good. What the problem ended up being was that I never closed the task. Once I added the close task function all was fine. The CVI documentation was weak and I missed seeing the Closetask function in the sample code.

I will properly rewrite this so that it is clean per your suggestions.

One thing I can say is that the Base driver leaves a lot to be desired for a NI product. I was expecting to purchase this DAQ, install the driver, and use function panels, but there is no "base" .fp to be found. I may give the mx7.5 driver a try.

Thanks all!

Jim 

 
0 Kudos
Message 4 of 5
(3,442 Views)
Hi Jim-
 
Yes, please give NI-DAQmx 7.5 a try.  It will be fully supported by CVI with function panels and many examples.  I'm glad to hear you got your app up and running for the timebeing and good luck with the rest of your development-
Tom W
National Instruments
0 Kudos
Message 5 of 5
(3,434 Views)