Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

WM_DEVICECHANGE event does not enable scanning of new hardware with DAQmxGetSysDevNames

My application can identify which NI hardware is currently available using DAQmxGetSysDevNames, it can also detect when NI USB/cDAQ hardware is inserted (http://forums.ni.com/t5/Multifunction-DAQ/DAQmx-API-event-to-detect-USB-device-hot-plugged-in/td-p/7...).

 

However when I run my device detection using DAQmxGetSysDevNames triggered by the WM_DEVICECHANGE event it does not return the USB hardware I have just inserted.  It looks like there has not been time for the DAQmx API to itself identify the hardware has been inserted.

 

I get the following four events from WM_DEVICECHANGE:

 

DBT_DEVNODES_CHANGED: A device has been added to or removed from the system
DBT_DEVICEARRIVAL: A device or piece of media has been inserted and is now available

DBT_DEVICEARRIVAL: A device or piece of media has been inserted and is now available

DBT_DEVNODES_CHANGED: A device has been added to or removed from the system

 

and triggering a scan using DAQmxGetSysDevNames fails each time.

 

Performing a manual scan just after works fine.

 

Does anyone have any suggestions as to how to resolve this?  My initial thought was to fire off a thread that would wait a couple of seconds and then poll for new hardware, but this doesn't seem very robust.

 

Thanks, Ben.

0 Kudos
Message 1 of 5
(5,800 Views)

Hi Ben,

 

I would suggest implementing the wait function you mentioned. Do you mind if we have a look at the code so far?

 

 

Regards

Andrew George @ NI UK
0 Kudos
Message 2 of 5
(5,793 Views)

Thanks for your help Andrew.

 

I've attached a stripped back version of the code I'm using.  It is running in the wxWidgets framework.

 

Example output:

 

NI USB-6251 turned on

20:42:05: Device change detected 0x0007
20:42:05: DBT_DEVNODES_CHANGED: A device has been added to or removed from the system
20:42:05: No NI-DAQmx devices available
20:42:06: Device change detected 0x8000
20:42:06: DBT_DEVICEARRIVAL: A device or piece of media has been inserted and is now available
20:42:06: No NI-DAQmx devices available
20:42:06: Device change detected 0x8000
20:42:06: DBT_DEVICEARRIVAL: A device or piece of media has been inserted and is now available
20:42:06: No NI-DAQmx devices available
20:42:06: Device change detected 0x0007
20:42:06: DBT_DEVNODES_CHANGED: A device has been added to or removed from the system
20:42:06: No NI-DAQmx devices available

NIDAQmx_GetInfo() called using menu item

20:43:42: Decoded Dev1 as a device name

NI USB-6251 turned off

20:44:39: Device change detected 0x0007
20:44:39: DBT_DEVNODES_CHANGED: A device has been added to or removed from the system
20:44:39: Decoded Dev1 as a device name
20:44:42: Device change detected 0x8004
20:44:42: DBT_DEVICEREMOVECOMPLETE: A device or piece of media has been removed
20:44:42: No NI-DAQmx devices available
20:44:42: Device change detected 0x8004
20:44:42: DBT_DEVICEREMOVECOMPLETE: A device or piece of media has been removed
20:44:42: No NI-DAQmx devices available

0 Kudos
Message 3 of 5
(5,785 Views)

Hey Ben,

 

I have found a post from another user that seems to have had similar problems with accessing USB, You must ensure you give a name and value to your device as shown in the this link. It is worth also noting we do not support C++.

Regards

Andrew George @ NI UK
0 Kudos
Message 4 of 5
(5,733 Views)

Hi Ben,

 

There has been some discussion about supporting this natively within DAQmx (be sure to kudo the idea if you like it), but at the moment WM_DEVICECHANGE is the the only event-driven method of detecting new hardware that I am aware of.  Unfortunately, the Windows event is sent before the device is available to the DAQmx driver so if you want to use this event you will still have to wait for the hardware to be recognized by DAQmx.

 

DAQmx does support C++ so I'm not sure what Andrew was referring to in his previous post.

 

 

Best Regards,

John Passiak
0 Kudos
Message 5 of 5
(5,719 Views)