How to read the VID PID of the USB webcam

Just starting out? Need help? Post your questions and find answers here.
AAT
Enthusiast
Enthusiast
Posts: 256
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

How to read the VID PID of the USB webcam

Post by AAT »

Hi.
Does anyone know how to read the VID and PID of webcam connected to a computer via USB?
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: How to read the VID PID of the USB webcam

Post by infratec »

lsusb :mrgreen:

But I can not see what kind of OS you are running.
User avatar
blueb
Addict
Addict
Posts: 1044
Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico

Re: How to read the VID PID of the USB webcam

Post by blueb »

Perhaps getting the hardware information might shine some light on what you need.

From:https://www.voti.nl/docs/usb-pid.html
"The PC uses the VID/PID combination to find the drivers (if any) that are to be used for the USB device."
search for: GetHardwareList_Func.pbi By Thunder93

http://www.purebasic.fr/english/viewtop ... =5&t=65328

Results I obtained:
-----------------------
Item: 325
Device Name: Logitech Webcam 905
Class: Image
Class Description: Imaging devices
Class GUID: {4BDD1D6-810F-11D0-BEC7-08002BE2092F}
Class Image Index: 63
CM_Status: 25190410
CM_Problem: 0

Device Status flags...:
DN_DRIVER_LOADED
DN_STARTED
DN_DISABLEABLE
DN_REMOVABLE
DN_NT_ENUMERATOR
DN_NT_DRIVER
-----------------------------
Hopefully you get some information that you need. :)
- It was too lonely at the top.

System : PB 6.10 LTS (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
AAT
Enthusiast
Enthusiast
Posts: 256
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Re: How to read the VID PID of the USB webcam

Post by AAT »

Thanks, guys!

infratec, my OS is Windows XP and 7. lsusb works fine and this is exactly what I need. But I would like to get the same result on PureBasic.

blueb, i can't get setupapi_h.pbi and cfg_h.pbi from http://www.purebasic.fr/english/viewtop ... =5&t=65230 :
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable"
AAT
Enthusiast
Enthusiast
Posts: 256
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Re: How to read the VID PID of the USB webcam

Post by AAT »

The answer is

Code: Select all

#MAX_CLASS_NAME_LEN = 32
#MAX_DEV_NAME_LEN   = 512

#SPDRP_HARDWAREID   = 1
#SPDRP_CLASS        = 7

Structure SP_DEVINFO_DATA Align #PB_Structure_AlignC
  cbSize.l
  ClassGuid.GUID
  DevInst.l
  *Reserved
EndStructure

Global hDevInfo.l, DeviceInfoData.SP_DEVINFO_DATA, setupapi.l, Ncam.l = 0, funcExt.s, MemberIndex.l = 0, CM_Status.l = 0, CM_Problem.l = 0
Global DevName.s = Space(#MAX_DEV_NAME_LEN), DevClass.s = Space(#MAX_CLASS_NAME_LEN)
  
CompilerIf #PB_Compiler_Unicode 
  funcExt = "W" 
CompilerElse 
  funcExt = "A" 
CompilerEndIf

Prototype.l CM_Get_DevNode_Status(pulStatus.l,pulProblemNumber.l,dnDevInst,ulFlags.l)
Prototype.l SetupDiGetClassDevs(*ClassGuid,Enumerator,hwndParent,Flags.l)
Prototype.l SetupDiEnumDeviceInfo(DeviceInfoSet,MemberIndex.l,DeviceInfoData)
Prototype.l SetupDiGetDeviceRegistryProperty(DeviceInfoSet,DeviceInfoData,Property.l,PropertyRegDataType.l,PropertyBuffer,PropertyBufferSize.l,RequiredSize.l)

setupapi = OpenLibrary(#PB_Any, "setupapi.dll")
If setupapi
  CM_Get_DevNode_Status.CM_Get_DevNode_Status = GetFunction(setupapi, "CM_Get_DevNode_Status")
  SetupDiGetClassDevs.SetupDiGetClassDevs = GetFunction(setupapi, "SetupDiGetClassDevs"+funcExt)
  SetupDiEnumDeviceInfo.SetupDiEnumDeviceInfo = GetFunction(setupapi, "SetupDiEnumDeviceInfo")
  SetupDiGetDeviceRegistryProperty.SetupDiGetDeviceRegistryProperty = GetFunction(setupapi, "SetupDiGetDeviceRegistryProperty"+funcExt)
Else
  MessageRequester("Error", "Can't open library setupapi.dll")
  End  
EndIf  
*pGUID = ?GUID_USB_DEVICE
hDevInfo = SetupDiGetClassDevs(*pGUID, #Null, #Null, #DIGCF_PRESENT | #DIGCF_ALLCLASSES) 
If hDevInfo = #INVALID_HANDLE_VALUE    
  MessageRequester("Error", "Inavlid handle value")
  End
EndIf      
DeviceInfoData\cbSize = SizeOf(SP_DEVINFO_DATA)
While SetupDiEnumDeviceInfo(hDevInfo, MemberIndex, @DeviceInfoData)                  
  CM_Get_DevNode_Status(@CM_Status, @CM_Problem, DeviceInfoData\DevInst, 0)    
  SetupDiGetDeviceRegistryProperty(hDevInfo, @DeviceInfoData, #SPDRP_CLASS, #Null, @DevClass, #MAX_CLASS_NAME_LEN, #Null)              
; only connected webcams (ImageClass USB devices)  
  If CM_Status <> 0 And DevClass = "Image"   
    SetupDiGetDeviceRegistryProperty(hDevInfo, @DeviceInfoData, #SPDRP_HARDWAREID, #Null, @DevName, #MAX_DEV_NAME_LEN, #Null)    
    Ncam + 1
    Debug "Class: "+DevClass+",  CM_Status: "+ Str(CM_Status)+",  CM_Problem: "+ Str(CM_Problem)  
    Debug "Device Name: "+DevName +#CRLF$ 
  EndIf    
  MemberIndex + 1 : CM_Status = 0 : CM_Problem = 0  
Wend 
Debug (Str(Ncam) + " webcam(s) found")
  
DataSection
  GUID_USB_DEVICE:
    Data.l $6BDD1FC6
    Data.w $810F, $11D0
    Data.b $BE, $C7, $08, $00, $2B, $E2, $09, $2F  
EndDataSection  
Many thanks to Thunder93 for the start point: Device Manager!

P.S. Windows XP 32 bit, my result:

Code: Select all

Class: Image,  CM_Status: 25190410,  CM_Problem: 0
Device Name: USB\Vid_05a3&Pid_9310&Rev_0000&MI_00

Class: Image,  CM_Status: 25190410,  CM_Problem: 0
Device Name: USB\Vid_0c45&Pid_62b3&Rev_0100&MI_00

2 webcam(s) found
Post Reply