Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx API event to detect USB device hot plugged in

Solved!
Go to solution

Using the DAQmx API calls, is there a way to request notification to detect when a USB device has been plugged in to the PC?

 

I found  information on registering callbacks for Done, Signal and EveryNSamplesEvent (e.g. DAQmxRegisterDoneEvent, DAQmxRegisterSignalEvent and DAQmxRegisterEveryNSamplesEvent) but nothing like "DAQmxRegisterDevicePluginDetectedEvent".

 

The ends of these threads:

http://forums.ni.com/ni/board/message?board.id=250&message.id=28298&requireLogin=False

http://forums.ni.com/ni/board/message?board.id=170&message.id=245864&query.id=69454#M245864

 

make it look as though I'm going to have to poll for all devices with:

DAQmxGetSysDevNames(char *data, uInt32 bufferSize);

 

but I'm hoping that there is something more automated available.

 

All ideas and points appreciated. 

 

Thanks. 

 

Sherryl Radbil
Data Acquisition Engineer
The MathWorks
0 Kudos
Message 1 of 13
(7,811 Views)

Hey,

 

DAQmx does not provide such an event.

You can try to get the event which is produced by the operating system if you plug in a USB device.

 

Christian

0 Kudos
Message 2 of 13
(7,796 Views)

Hello again,

 

I'm working on Windows and have a program that uses the standard Windows WM_DEVICECHANGE message and others as described in the MSDN Device Management Reference http://msdn.microsoft.com/en-us/library/aa363239(VS.85).aspx

 

When I plug in a single device it is detected. This is expected and is good.

When I plug in a cDAQ-9172 CompactDAQ chassis it is detected. Also expected and good.

 

But when I plug individual modules into the cDAQ chassis there is no Windows operating system event generated so the new module is not detected. This is the problem.

 

In Measurement and Automation Explorer the module appears in the chassis instantaneously.

 

Please let me know what the mechanism is that I need to use to detect CompactDAQ module plug in and unplug.

 

Thanks,

Sherryl Radbil
Data Acquisition Engineer
The MathWorks
0 Kudos
Message 3 of 13
(7,453 Views)

The cDAQ modules are all hot swappable so the behavior of seeing the modules in MAX when placing them in the chassis is expected.  After looking into the Device Management Events on the Microsoft website, that only will work if you plug in a device directly to the computer such as usb.  The devices that are added to the cDAQ chassis will not trigger a windows event unless you recycle the power on the chassis or unplug/plug the chassis.  The advice of polling what devices are in the cDAQ chassis in your program would be the best way to know the current status of the chassis.   

 

Is there a specific reason that you need a windows event generated when modules are added or removed? 

Regards,
Jordan F
National Instruments
0 Kudos
Message 4 of 13
(7,428 Views)

Hi Jordan,

Thanks for the answer.

 

So are you saying that  MAX is constantly polling the chassis to instantaneously detect the CompactDAQ module plug in?

 

I was hoping for a DAQmx event that arrives when a CompactDAQ module is plugged in or unplugged from the chassis

For instance, something similar to DAQmxRegisterSignalEvent that would allow me to register a callback for CompactDAQ module insertion/removal events.

I don't necessarily need a Windows event.

 

Our application can detect USB devices plugged in using the Windows events and now we need to ensure that it detects CompactDAQ modules as well. I prefer not to poll so other suggestions are welcome.

 

All the best,

 

Sherryl Radbil
Data Acquisition Engineer
The MathWorks
0 Kudos
Message 5 of 13
(7,424 Views)

Hi Sherryl,

 

The only way currently to see what devices are in your chassis is to poll the device names (ex. DAQmx Device Property Node->Chassis.ModuleDeviceNames).  There is no event triggered because the individual modules are not detected by Windows, the chassis is what controls all the communication (hence why you can receive an event when the chassis is added).  I am unsure how exactly the modules are detected by MAX so I can look into this futher for you. 

 

I know that polling is undesired but it will not take up too much CPU usage if you only poll the chassis every half second or second.  Again, this is the only way to have your program detect the available devices.       

Regards,
Jordan F
National Instruments
0 Kudos
Message 6 of 13
(7,376 Views)