06-02-2011 03:11 PM
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.
06-03-2011 05:44 AM
Hi Ben,
I would suggest implementing the wait function you mentioned. Do you mind if we have a look at the code so far?
06-03-2011 02:50 PM
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
06-13-2011 04:02 AM
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++.
06-13-2011 12:05 PM
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,