From: Tormod V. <lis...@gm...> - 2018-05-05 09:31:47
|
Hi Mike, The numbers you get from the configuration are indexes to the string descriptors. You can use get_string() to retrieve the strings from the device. If nowhere else, it is documented in the usb/util.py source code. Note that the configuration indexes are cached by the operating system, and usually readable without OS privileges, however retrieving the string descriptors involves the device and requires OS permissions to the device. Regards, Tormod On Sat, May 5, 2018 at 5:03 AM, Soultanian, Mike wrote: > Hi, > > We have a problem at work where my coworkers are manually (visually) parsing > through the output of "usb-devices" to find information (bus, vendor, > prodid, manufacturer, serialnumber, etc) and then using that information to > fix problematic devices using that information. I'd like to write a python > script to accomplish what my coworkers have been doing by hand, but instead > of parsing through the output of "usb-device" (which I could do, but it's > tedious), I'd rather get that information from pyusb if it can provide what > I'm looking for. I've been searching google and scouring through the > documentation, but I'm confused and I'm stuck. I tried the code below but > it's just displaying numbers instead of text: > > import usb.core > > # find USB devices > dev = usb.core.find(find_all=True) > > for cfg in dev: > print('Serial Number=' + str(cfg.iSerialNumber)) > print('VendorID=' + hex(cfg.idVendor)) > print('Manufacturer=' + str(cfg.Manufacturer)) > print('Product=' + hex(cfg.iProduct) + "\n") > > and it outputs this: > > Serial Number=3 > VendorID=0x424 > Manufacturer=1 > Product=2 > > Serial Number=3 > VendorID=0x403 > Manufacturer=1 > Product=2 > > ... > > Obviously that's not what I'm looking for. I'm really hoping to get more > information similar to the output from usb-devices: > > T: Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=480 MxCh= 8 > D: Ver= 2.00 Cls=09(hub ) Sub=00 Prot=01 MxPS=64 #Cfgs= 1 > P: Vendor=1d6b ProdID=0002 Rev=04.04 > S: Manufacturer=Linux 4.4.0-116-generic xhci-hcd > S: Product=xHCI Host Controller > S: SerialNumber=0000:00:15.0 > C: #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=0mA > I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub > > T: Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=480 MxCh= 7 > D: Ver= 2.00 Cls=09(hub ) Sub=00 Prot=02 MxPS=64 #Cfgs= 1 > P: Vendor=0424 ProdID=2517 Rev=00.00 > S: Manufacturer=cambrionix > S: Product=U16S > C: #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=2mA > I: If#= 0 Alt= 1 #EPs= 1 Cls=09(hub ) Sub=00 Prot=02 Driver=hub > > ... > > > Any help would be much appreciated! > > Thanks, > > Mike |