问题描述
我有两个基于相同USB-RS232芯片的不同USB设备.当我将它们插入USB时,它们将安装到/dev/ttyUSB0 ... 3
I have two different USB devices based on the same USB-RS232 chips.When I plug those in the USB they are mounted to /dev/ttyUSB0...3
我的问题是,如何在脚本中找出哪个在tty上?
My problem is how, inside a script, I can find out which one is on what tty?
使用lsusb可以区分它们:
Using lsusb I can differentiate them:
$> lsusb | grep 0403:f850
Bus 004 Device 002: ID 0403:f850 Future Technology Devices International, Ltd
$> lsusb | grep 0403:6001
Bus 004 Device 003: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC
使用dmesg,我可以知道它们的安装位置:
And using dmesg I can tell where they were mounted:
$> dmesg | grep 'FTDI USB Serial Device converter now attached'
[36051.393350] usb 4-2: FTDI USB Serial Device converter now attached to ttyUSB1
[36061.823513] usb 4-1: FTDI USB Serial Device converter now attached to ttyUSB0
但是"usb 4-1"似乎与"Bus 004 Device 002"相对应.
But "usb 4-1" does not seem to correspond to "Bus 004 Device 002".
我是否可以假设"Bus 004 Device 001"始终是"USB root hub",因此dmesg从1开始计数,从lsusb从2开始计数?
Can I assume that "Bus 004 Device 001" will always be an "USB root hub" and thus dmesg will count from 1 onwards and lsusb from 2 onwards?
或者您对如何将设备ID与安装点相关联(在脚本中)是否有其他建议?
Or do you have another suggestion on how to correlate device ID to mount point (inside a script)?
我正在使用Ubuntu 10.04 LTS.
I'm using Ubuntu 10.04 LTS.
推荐答案
使用sysfs查找更多信息:
Find more info using sysfs:
$ ls /sys/bus/usb-serial/devices/ -ltrah
lrwxrwxrwx 1 root root 0 2012-02-07 22:17 ttyUSB0 -> ../../../devices/pci0000:00/0000:00:0f.4/usb2/2-2/2-2:1.0/ttyUSB0
$ ls -ltrad /sys//devices/pci0000:00/0000:00:0f.4/usb2/2-2/2-2:1.0/ttyUSB0
drwxr-xr-x 4 root root 0 2012-02-07 22:17 /sys//devices/pci0000:00/0000:00:0f.4/usb2/2-2/2-2:1.0/ttyUSB0
$ ls -ltrad /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 0 2012-02-01 00:17 /dev/ttyUSB0
当然,链接的设备/...节点包含很多信息
Of course, the linked devices/... node contains a lot of information
如果卸下/插入设备,则设备号会不断增加. lsusb -t
可用于将设备号与usb总线/端口相关联.
The device number keeps growing if devices are removed/inserted. lsusb -t
can be used to correlate the device numbers with usb bus/port.
然后,"lsusb -d devID"可以确定哪个设备在哪个端口上.最后,"ls/sys/bus/usb-serial/devices/-ltrah"将(按总线/端口)列出安装位置.
Then, 'lsusb -d devID' can determine what device is on which port.Finally 'ls /sys/bus/usb-serial/devices/ -ltrah' will list (by bus/port) where it was mounted.
不是很方便,但是它正常工作'
这篇关于如何找出哪个tty上的USB-RS232设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!