question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Read common descriptors from sysfs, when available

See original GitHub issue

Running Debian Linux 11 with Python 3.10 and libusb1. I am trying to connect to an LG UltraFine monitor via USB-C.

It works via lsusb (running as my user):

$ lsusb -D /dev/bus/usb/003/010
Device: ID 043e:9a39 LG Electronics USA, Inc. LG Monitor Controls
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass          239 Miscellaneous Device
  bDeviceSubClass         2 
  bDeviceProtocol         1 Interface Association
  bMaxPacketSize0        64
  idVendor           0x043e LG Electronics USA, Inc.
  idProduct          0x9a39 
  bcdDevice            4.11
  iManufacturer           1 LG Electronics Inc.
  iProduct                3 LG Monitor Controls
  iSerial                 4 107NTYTAD986
  bNumConfigurations      1

but not via pyusb:

$ python -c 'import usb.core; d = usb.core.find(idVendor=0x043e, idProduct=0x9a39); print(d)'
DEVICE ID 043e:9a39 on Bus 003 Address 010 =================
 bLength                :   0x12 (18 bytes)
 bDescriptorType        :    0x1 Device
 bcdUSB                 :  0x200 USB 2.0
 bDeviceClass           :   0xef Miscellaneous
 bDeviceSubClass        :    0x2
 bDeviceProtocol        :    0x1
 bMaxPacketSize0        :   0x40 (64 bytes)
 idVendor               : 0x043e
 idProduct              : 0x9a39
 bcdDevice              :  0x411 Device 4.11
 iManufacturer          :    0x1 Error Accessing String
 iProduct               :    0x3 Error Accessing String
 iSerialNumber          :    0x4 Error Accessing String
 bNumConfigurations     :    0x1
$ ls -lah /dev/bus/usb/003/010
crw-rw-r-- 1 root root 189, 265 Sep 28 07:48 /dev/bus/usb/003/010

The device file is world readable.

The strange thing is that pyusb and also lsusb try to open the device with write permissions. I wonder why those are necessary to list something.

I can also do

$ cat /sys/bus/usb/devices/3-6.3/manufacturer
LG Electronics Inc.

or

$ cat /sys/bus/usb/devices/3-6.3/product 
LG Monitor Controls
$ ll /sys/bus/usb/devices/3-6.3/product 
-r--r--r-- 1 root root 4096 Sep 28 07:48 /sys/bus/usb/devices/3-6.3/product

I would expect pyusb to be able to show the vendor and manufacturer similar to lsusb without having write permissions (which are not necessary).

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ronny-rentnercommented, Oct 9, 2022

Thanks for the direction, will do it like this.

0reactions
jonasmalacofilhocommented, Oct 6, 2022

Can we reopen the ticket for this?

Done, but I also renamed for accuracy.

PS: I would probably not replace any existing logic but just whenever there is “Error Accessing String” do an extra step and try to find the string through /sys/bus/usb Sounds pretty straight forward to me.

Actually, it should probably go in the Device.manufacturer and similar properties, not in Device.__str__ (which may then be reworked to use the new feature).

PyUSB is not a lsusb clone: sure, this feature will improve Device.__str__, but it’s also necessary (and, arguably, more important) to make the data available for callers using PyUSB for something more than print(dev).

And the preference order should probably be: locally cached value > (on Linux:) sysfs value > GET_DESCRIPTOR transfer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rules on how to access information in sysfs
In general, failures to read or write sysfs device attributes shall propagate errors wherever possible. Common errors include, but are not limited to:....
Read more >
sysfs(5) - Linux manual page - man7.org
The files under sysfs provide information about devices, kernel modules, filesystems, and other kernel components. The sysfs filesystem is commonly mounted ...
Read more >
Sysfs in Linux Kernel- Linux Device Driver Tutorial Part 11
Sysfs is the commonly used method to export system information from the kernel space to the user space for specific devices.
Read more >
Documentation/filesystems/sysfs.txt - kernel/common
linkages between them to userspace. sysfs is tied inherently to the kobject infrastructure. Please read. Documentation/kobject.txt for ...
Read more >
Linux Kernel Documentation / ABI / testing / sysfs-devices-soc
What: /sys/devices/socX/family Date: January 2012 contact: Lee Jones <lee.jones@linaro.org> Description: Read-only attribute common to all SoCs.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found