确定USB设备文件路径 [英] Determine USB device file Path
问题描述
如何在Linux中正确获取USB设备文件路径. 我使用命令:find/-iname"usb"并得到如下结果:
How can i get USB device file path correctly in Linux. I used command: find / -iname "usb" and got the result as below:
/dev/bus/usb
/sys/bus/usb
/sys/bus/usb/drivers/usb
/sys/kernel/debug/usb
在/dev/bus/usb下,我看到:
Under /dev/bus/usb i see:
001 002 003 004 005 006
但是我认为它们不是我需要的文件.
But I think they aren't files as i need.
在/sys/bus/usb/devices/下:
Under /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
在/sys/bus/scsi/devices/下,当我插入USB时,我会看到:
And Under /sys/bus/scsi/devices/ when i pluged an USB i see:
2:0:0:0 host0 host2 target2:0:0
当我卸下USB时,我看到:
And when i removed USB i see:
sh-3.2# ls
host0
那么哪个设备文件用于USB?我该如何识别?我需要用USB设备文件制作一个C程序...
So which device file is used for USB? How can i indentify it? I need to make a C program with USB device file...
再说一遍,您能告诉我1-1:1.0的数字吗?是什么意思?
Further more, could you explain to me the number 1-1:1.0? What does it mean?
谢谢.
推荐答案
那么哪个设备文件用于USB?我该如何识别?
So which device file is used for USB? How can i indentify it?
/sys/
后面的内容主要是有关设备的配置/信息. /dev/bus/usb
是您要寻找的.我认为以下文章可以为您提供帮助
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
已经很老了,但仍然可以为您提供帮助. (在他们谈论/proc/bus/usb
的文章中,今天我们有/dev/bus/usb
)
Is quite old, but still it can help you. (In the article they speak about /proc/bus/usb
, today we have /dev/bus/usb
)
再说一遍,您能告诉我1-1:1.0的数字吗?是什么意思?
Further more, could you explain to me the number 1-1:1.0? What does it mean?
通用形式为
X-Y.Z:A.B
每个字段都标识设备的连接点.前两个字段是必填字段:
Each field identify the connection point of your device. The first two field are mandatory:
- X是主板的USB总线,用于连接USB系统.
- Y是总线系统上正在使用的端口
因此,用字符串3-3
标识的USB设备是连接在总线3的端口3上的设备.
So the USB device identified with the string 3-3
is the device connected on the port 3 of the bus 3.
如果连接USB集线器,则将扩展单个USB端口的连接能力. Linux内核通过附加Z字段来识别这种情况.
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是集线器上正在使用的端口
因此,用字符串1-2.5
标识的USB设备是连接在集线器的端口5上的设备,该集线器的端口连接在总线1的端口2上.
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规范允许您级联连接多个USB集线器,因此Linux内核继续将正在使用的端口附加到不同的集线器上.因此,用字符串1-2.1.1
标识的USB设备是集线器的端口1上连接的设备,集线器的端口1上连接到总线1的端口2的集线器的端口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 ...]
然后,模式的最后两个字段(在冒号之后)标识USB设备的内部部分:
Then, the last two fields of the pattern (after colon) identify an internal section of an USB device :
- A是设备的配置号
- B是配置的接口号
因此,字符串4-1:1.1
表示:配置1上的接口1,该接口1连接在总线4的端口1上.
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.
您可以使用命令lsusb
检索这些信息.
You can retrieve these information with the command lsusb
.
这篇关于确定USB设备文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!