LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Check PID/VID of a USB Pen/Thumb Drive

Hi, I would like to read the PID and VID of the USB Pen Drive without using the NI VISA development wizard. This is because, when the pen drive plug in, the windows will automatic detect the windows inf file and install the driver for the pen drive. Is there any way to read and detect the PID/VID of the pen drive such as query the windows registry or call API of the Windows Device Manager?
 
Please kindly help! Thanks a lot!
0 Kudos
Message 1 of 15
(16,853 Views)
Search for USB Viewer (USBVIEW.EXE), which is am example program with C source included in the Windows DDK.  I believe you can download the compiled EXE somewhere on the NET, though Microsoft seems like not distributing it alone at their web sites.
Message 2 of 15
(16,842 Views)
An alternative way is to check the registry entry. Go for,
HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Enum \ USB
 
You will find your USB device with VID/PID name, immediately under the USB branch.
0 Kudos
Message 3 of 15
(16,840 Views)

Hi,

Thanks for the information. I tried to read the PID/VID from the regedit, ENUM but the problem is, the regedit can't tell is the usb pen driver already plug in or not as the registry already there all the time. I wish i can find the API (something like Device Manager) or the registry that can tell the the USB alreayd plug in or not. Please kindly help and advise.

 

0 Kudos
Message 4 of 15
(16,829 Views)
Hi,
 
I manage to download the USBVIEW.exe. However, if I want to read the content of the program automatically. If there any way to access the exe program item (such as Refresh F5, read the output content etc)?
 
If there any dll or API that can call directly? Please kindly help.Thanks
 
0 Kudos
Message 5 of 15
(16,825 Views)

Unfortunately there is no easy-drive API functions, which can acuire USB device information so easily. Instead, you must use Configuration Manager API, which is declared and implemented in SETUPAPI.H/DLL.  Probably it will be very hard to call them from LabVIEW.  Then you must use

SetupDiGetClassDevs() - retrieve HDEVINFO handle from the GUID, which is associated with your device or hosted device driver.

SetupDiEnumDeviceInterface() - enumerate active USB devices from the above-acquired HDEVINFO resulting SP_INTERFACE_DEVICE_DATA

SetupDiGetInterfaceDeviceDetail() - acquire detail info from SP_INTERFACE_DEVICE_DATA resulting SP_DEVINFO_DATA

SetupDiGetDeviceInstanceId() - acquire the "device path name" from SP_DEVINFO_DATA, resulting a NULL-terminated string, which will include the USB VID/PID values in hex-format, such as including "USB\VID_xxxx&PID_xxxx\..." string. 

You can loop above API calls for each enumeration, until the destinate VID and PID are found.

0 Kudos
Message 6 of 15
(16,823 Views)
What are the PID and VID attributes??  What operating system are you using??
0 Kudos
Message 7 of 15
(16,813 Views)

Rebecca,

What is your true object for the device?
1) Are you just trying to acquire the device VID and PID values programatically? or,
2) Are you trying to control the device through the device-driver, which is already provided for the device without using NI-VISA USB RAW layer? or,
3) Any others?

0 Kudos
Message 8 of 15
(16,807 Views)

Hi,

I am using WinXP.

I am actually need to develop a test program for a USB device, eg: Pen drive. My application is actually test the USB functionality of the device. So when I plug the USB drive, the program need to detect the USB device and read the PID/VID of the product.

1. I want to read the PID/VID programmatically, I also want to detect whether the USB is plugged to the PC. I also want to do a write/read file to the Pen drive.

2. I know I can detect a NI VISA driver to read the device. However, if it's a USB pen drive, the windows will automatically load the Windows driver for the USB, the PC will bypass the NI driver. So, I can't use the NI Visa driver wizard.

I will look into API methods that have suggested. at the same time, we don't have other methods that suit my application, right? Thanks a lot.

0 Kudos
Message 9 of 15
(16,803 Views)
This thread discusses the problem too. You can run devcon from the sysexec function.
0 Kudos
Message 10 of 15
(16,750 Views)