根据udev的信息判断设备物理路径

udev会生成by-path路径,根据这个就可以判断

dev目录下

[toybrick@localhost dev]$ find | grep platform-fe3c0000
./disk/by-path/platform-fe3c0000.usb-usb-0:1.2:1.0-scsi-0:0:0:0-part1
./disk/by-path/platform-fe3c0000.usb-usb-0:1.2:1.0-scsi-0:0:0:0
./input/by-path/platform-fe3c0000.usb-usb-0:1.1:1.0-event-mouse
./input/by-path/platform-fe3c0000.usb-usb-0:1.3:1.0-event-kbd
[toybrick@localhost dev]$ find | grep platform-fe380000
./serial/by-path/platform-fe380000.usb-usb-0:1.3:1.0-port0
./serial/by-path/platform-fe380000.usb-usb-0:1.2:1.0-port0
./serial/by-path/platform-fe380000.usb-usb-0:1.1:1.0-port0

https://stackoverflow.com/questions/33140787/determine-usb-device-file-path

14

So which device file is used for USB? How can i indentify it?

What you see behind /sys/ is mainly configuration/information about devices. /dev/bus/usb is what you are looking for. I think that the following article can help you

http://www.linuxjournal.com/article/7466?page=0,0

Is quite old, but still it can help you. (In the article they speak about /proc/bus/usb, today we have /dev/bus/usb)

Further more, could you explain to me the number 1-1:1.0? What does it mean?

The generic form is

X-Y.Z:A.B

Each field identify the connection point of your device. The first two field are mandatory:

  • X is the USB bus of your motherboard where is connected the USB system.
  • Y is the port in use on the bus system

So the USB device identified with the string 3-3 is the device connected on the port 3 of the bus 3.

If you connect an USB hub, you are extending the connection capability of a single USB port. The Linux kernel identify this situation by appending the Z field.

  • Z is the port is use on an hub

So, the USB device identified with the string 1-2.5 is the device connected on the port 5 of the hub connected on the port 2 of the bus 1.

USB specification allow you to connect in cascade more then one USB hub, so the Linux kernel continue to append the port in use on the different hubs. So, the USB device identified with the string 1-2.1.1 is the device connected on the port 1 of the hub connected on the port 1 of the hub connected to the port 2 of the bus 1.

A fast way to retrieve these information is to read the kernel messages (if you can).

$ dmesg | grep usb
[... snip ...]
[ 2.047950] usb 4-1: new full-speed USB device number 2 using ohci_hcd
[ 2.202628] usb 4-1: New USB device found, idVendor=046d, idProduct=c318
[ 2.202638] usb 4-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 2.202643] usb 4-1: Product: Logitech Illuminated Keyboard
[ 2.202648] usb 4-1: Manufacturer: Logitech
[... snip ...]

Then, the last two fields of the pattern (after colon) identify an internal section of an USB device :

  • A is the configuration number of the device
  • B is the interface number of a configuration

So, the string 4-1:1.1 means: the interface 1, on configuration 1 that is connected on the port 1 of the bus 4.

You can retrieve these information with the command lsusb.

通过libusb操纵led

https://www.linuxjournal.com/article/7466?page=0,0

原文地址:https://www.cnblogs.com/cute/p/11325250.html