如何找出哪个 USB-RS232 设备在哪个 tty 上? [英] How to find out which USB-RS232 device is on which tty?

查看:12
本文介绍了如何找出哪个 USB-RS232 设备在哪个 tty 上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个基于相同 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".

我可以假设总线 004 设备 001"始终是USB 根集线器",因此 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

当然,linked devices/...节点包含很多信息

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.

不是很方便,但它'工作'

这篇关于如何找出哪个 USB-RS232 设备在哪个 tty 上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆