NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Member
Rebecca Tee
Posts: 14
0 Kudos

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!
Active Participant
Makoto
Posts: 524

Re: Check PID/VID of a USB Pen/Thumb Drive

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.
Active Participant
Makoto
Posts: 524
0 Kudos

Re: Check PID/VID of a USB Pen/Thumb Drive

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.
Member
Rebecca Tee
Posts: 14
0 Kudos

Re: Check PID/VID of a USB Pen/Thumb Drive

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.

 

Member
Rebecca Tee
Posts: 14
0 Kudos

Re: Check PID/VID of a USB Pen/Thumb Drive

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
 
Active Participant
Makoto
Posts: 524
0 Kudos

Re: Check PID/VID of a USB Pen/Thumb Drive

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.

Active Participant
unclebump
Posts: 1,828
0 Kudos

Re: Check PID/VID of a USB Pen/Thumb Drive

What are the PID and VID attributes??  What operating system are you using??
Active Participant
Makoto
Posts: 524
0 Kudos

Re: Check PID/VID of a USB Pen/Thumb Drive

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?

Member
Rebecca Tee
Posts: 14
0 Kudos

Re: Check PID/VID of a USB Pen/Thumb Drive

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.

Active Participant
Posts: 252
0 Kudos

Re: Check PID/VID of a USB Pen/Thumb Drive

This thread discusses the problem too. You can run devcon from the sysexec function.
By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page