09-14-2021 11:04 AM
Hi all,
I'm looking to fire user events when and NI usb daq device is connected/disconnected.
I've been able to cobble together a working VI based on previous posts (see snippets and code below)
and some example code from https://forums.ni.com/t5/LabVIEW/How-to-catch-USB-device-plug-unplug-events/td-p/1461976?profile.lan...
using windows message queue functions. (Windows messaging functions from NI are located here)
The issue is the WM_DEVICECHANGE msg detects that a USB device has been inserted/unplugged, but the return value (DBT_DEVNODES_CHANGED) yields no extra information about the device in question. This also doesn't give any indication of whether the device is ready to use. As such, querying DAQmx system immediately afterwards doesn't detect the device. One way around this is to simply insert a delay before querying DAQmx system to see if the device list has changed. This works but seems clunky, and if possible i'd like to better understand how to implement something more robust.
From further reading, it seems as though I should register for device notifications, but I can't quite get my head around the exact process for doing this.
Any ideas would be greatly appreciated