To download NI software, including the products shown below, visit ni.com/downloads.
This VI monitors the connection to any USB device, be that a flash memory stick, a keyboard, a web camera,etc.. using Windows Registry
There are no native LabVIEW functions to do this and the VI needed to be able to monitor for ANY USB device, be that a flash memory stick, a keyboard, a web camera.
The information needed is all stored in the Windows Registry so as well as being a useful VI this is also an example of accessing the registry.
The main issue with this is different USB devices are stored in different registry keys. For example all the devices that appear as storage devices are under the usbSTOR key, HCI devices such as the keyboard appear under the usbehci key etc.
The next issue is that if you have never plugged any device of a certain type into your system, the key will simply not exist. This code accounts for both issues. It allows us to add registry keys to search, and will handle any errors generated by keys not being found.
LabVIEW 2012 (or compatible)
Steps to Implement or Execute Code:
Identify the device you wish to monitor for:
1. Plug a USB device into the system.
2. Open Windows Device Manager and locate the USB device.
3. Under the details tab Note down the device instance ID, this varies from device to device but the last part after the last "\" is usually sufficient.
4. Or Open the windows registry (type "regedit" in the run menu).
5. Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services.
6. Locate the device ID in one of the USB registry keys ( device must be connected, might be easier to search for it).
7. Note down the subkey (folder) the device is stored in. By default the VI uses USBSTOR, usbccgp, usbehci, usbaudio.
8. If the device falls under one of these subkeys you are ready to go. If not add the sub key to the paths in the VI.
9. Enter the device ID in the Device ID Control (similar to the default value of the control)
10.Run the VI
Additional Information or References:
**This document has been updated to meet the current required format for the NI Code Exchange. **
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.