简体   繁体   English

确定USB设备文件路径

[英]Determine USB device file Path

How can i get USB device file path correctly in Linux.如何在 Linux 中正确获取 USB 设备文件路径。 I used command: find / -iname "usb" and got the result as below:我使用命令: find / -iname "usb" 并得到如下结果:

/dev/bus/usb
/sys/bus/usb
/sys/bus/usb/drivers/usb
/sys/kernel/debug/usb

Under /dev/bus/usb i see:在 /dev/bus/usb 下我看到:

001  002  003  004  005  006

But I think they aren't files as i need.但我认为它们不是我需要的文件。

Under /sys/bus/usb/devices/:在 /sys/bus/usb/devices/ 下:

sh-3.2# ls /sys/bus/usb/devices/
1-0:1.0  1-1:1.0  3-0:1.0  5-0:1.0  usb1     usb3     usb5
1-1      2-0:1.0  4-0:1.0  6-0:1.0  usb2     usb4     usb6

And Under /sys/bus/scsi/devices/ when i pluged an USB i see:在 /sys/bus/scsi/devices/ 下,当我插入 USB 时,我看到:

2:0:0:0      host0        host2        target2:0:0

And when i removed USB i see:当我移除 USB 时,我看到:

sh-3.2# ls
host0

So which device file is used for USB?那么USB使用的是哪个设备文件呢? How can i indentify it?我怎样才能识别它? I need to make a C program with USB device file...我需要用USB设备文件制作一个C程序...

Further more, could you explain to me the number 1-1:1.0?更进一步,你能向我解释1-1:1.0这个数字吗? What does it mean?这是什么意思?

Thank you.谢谢你。

So which device file is used for USB?那么USB使用的是哪个设备文件呢? How can i indentify it?我怎样才能识别它?

What you see behind /sys/ is mainly configuration/information about devices.您在/sys/后面看到的主要是有关设备的配置/信息。 /dev/bus/usb is what you are looking for. /dev/bus/usb就是你要找的。 I think that the following article can help you我认为下面的文章可以帮助你

http://www.linuxjournal.com/article/7466?page=0,0 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 ) (在他们谈论/proc/bus/usb ,今天我们有/dev/bus/usb

Further more, could you explain to me the number 1-1:1.0?更进一步,你能向我解释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. X 是连接 USB 系统的主板的 USB 总线。
  • Y is the port in use on the bus system Y 是总线系统上使用的端口

So the USB device identified with the string 3-3 is the device connected on the port 3 of the bus 3.所以用字符串3-3标识的 USB 设备就是连接在总线 3 的端口 3 上的设备。

If you connect an USB hub, you are extending the connection capability of a single USB port.如果您连接 USB 集线器,您就是在扩展单个 USB 端口的连接能力。 The Linux kernel identify this situation by appending the Z field. Linux 内核通过附加 Z 字段来识别这种情况。

  • Z is the port is use on an hub Z 是在集线器上使用的端口

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.因此,以字符串1-2.5标识的USB设备是连接在总线1端口2上的集线器端口5上的设备。

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. USB 规范允许您级联连接多个 USB 集线器,因此 Linux 内核继续附加不同集线器上使用的端口。 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.所以,用字符串1-2.1.1标识的USB设备就是连接在集线器的端口1上的设备,连接在集线器的端口1上,连接到总线1的端口2。

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 :然后,模式的最后两个字段(冒号后)标识 USB 设备的内部部分:

  • A is the configuration number of the device A是设备的配置号
  • B is the interface number of a configuration B是配置的接口号

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.因此,字符串4-1:1.1表示:接口 1,在配置 1 上连接到总线 4 的端口 1。

You can retrieve these information with the command lsusb .您可以使用命令lsusb检索这些信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM