libusb icon indicating copy to clipboard operation
libusb copied to clipboard

Added libusb_get_device_string() which works with a closed device

Open mliberty1 opened this issue 7 months ago • 12 comments

This new API call provides access to device strings, normally accessed using USB string descriptors, without opening the device. The common use case is to filter on serial number for selecting one of multiple connected devices.

The commit adds the new API function, documentation, and support for the following platforms:

  • Windows WinUSB
  • Linux
  • macOS

All platforms support manufacturer, product, and serial number strings.

The example/listdevs.c now has a "--verbose" command line argument that prints these strings.

Known issues:

  • On one Ubuntu Linux machine, reading the /sys/bus/usb/ files to get the strings takes a variable amount of time on one device, an xHCI root hub. While the read can be fast, it can also take seconds. Using "cat" at the command line has the exact same behavior.

References:

  • https://github.com/libusb/libusb/issues/866
  • https://github.com/libusb/libusb/pull/875
  • https://github.com/libusb/libusb/pull/1258
  • https://github.com/hjmallon/libusb/commit/d0f9fd4852dfceaa4f8f55700ed9b74c4e5406dd

Thank you to the prior work that made this much quicker:

  • @mcuee
  • @sonatique
  • @hjmallon

I apologize anyone that I missed. This feature has been in the works for a long time with multiple starts and stops.

And thank you to @Youw for providing quick, detailed feedback!

mliberty1 avatar Jul 09 '24 21:07 mliberty1