a1ien / rusb

A safe Rust wrapper for libusb.
Other
382 stars 78 forks source link

Add Device port_string() function #169

Closed fpagliughi closed 1 year ago

fpagliughi commented 1 year ago

This adds a Device::port_string() function. The string describes the unique physical port to which a USB device is attached. The format of the string is compatible with the one used by Linux in the form: <bus>-<port>.<port>..., like: 4-1.2.

It is simply a string representation of the bus number and port vector. Although it uses the Linux format, it should work on any OS.

The primary use for the port string is to easily, uniquely identify a device on a given host, particularly when multiple, identical, devices are attached to the host and can not be differentiated in any other way. This happens when two of the same devices are attached with the same VID:PID, but do not have serial numbers or other distinguishing identifiers.

On Linux, it is also directly useful to compare to fields in the devpath/syspath and can be used to find the device in the syspath at /sys/bus/usb/devices/<port_string>

fpagliughi commented 1 year ago

I fixed the formatting, squashed, and pushed it, but can't figure out how to re-run the code check. It should be OK now.

a1ien commented 1 year ago

I don't like this changes. This function can be implemented outside of rusb. And actually should if you need.