Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to detect USB power off condition?

Hi,

 

I'm using a USB-6229 with NI-DAQmx 9.5.0f2 under Windows 7 for analog data collection. An AI Voltage Channel is created, and samples gathered continuously via a registered event (DAQmxRegisterEveryNSamplesEvent).

 

I would like to know if there is any way reliably to detect loss of power (possibly because a naughty user has switched it off) to the USB device while it is in the middle of data collection.

 

What happens at the moment is that an error dialog is displayed before my code can even detect the fact that data is no longer coming in - usually. I say 'usually' because sometimes the code does execute, but the error is still displayed. My trap code includes calls to stop and clear all tasks. Currently it relies on detecting the fact that expected data isn't arriving on time. DAQmxReadBinaryI16 (in the callback) doesn't return an error, making me think that the callback itself stops being called when power goes off. If my trap code doesn't execute, the program terminates abnormally, like there is some bad memory access.

 

The error dialog says:

 

"NIDAQ: NI Platform Services: A USB transfer failed due to a transaction error reported by the USB host controller.  This may be due to a fault in the system's USB host controller, a USB cable, or a USB device."

 

I'm not so bothered about recovering after the error; the important thing is that the user is given appropriate instructions on how to deal with the condition by my software. So I really need to trap this condition myself, rather than some other part of the system taking over error handling.

 

When I power off the USB device when collecting analog data in the test panel of Measurement & Automation Explorer, it intercepts the error and displays it as "Error -50808 occurred at Test Panel". Moreover, when I power off and on again in the Explorer, the Self-Test button disables and re-enables. So it looks like NI software can do what I am wanting to do.

 

Is there API support in NI-DAQmx for this kind of power state awareness?

 

Thanks,

Francis Burton

 

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

Hi Francis,

 

I don' think you can check to see if the power line in the USB connector is on but it should be possible to check whether a device is connected to the system. Take a look at this example and see if it gets you moving in the right direction:

 

Programmatically Finding Device Name of DAQ Device in System

 

Good luck.

 

Chris

National Instruments - Tech Support
0 Kudos
Message 2 of 3
(3,998 Views)

Thanks for your suggestion, Chris. Checking for which devices are present after a data stream interruption has been detected seems to be the sensible way to go.

0 Kudos
Message 3 of 3
(3,952 Views)