如何知道哪个设备连接到了/dev/ttyUSB端口 [英] How to know which device is connected in which /dev/ttyUSB port

查看:1000
本文介绍了如何知道哪个设备连接到了/dev/ttyUSB端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用两个Wavecom 16端口调制解调器.当我将调制解调器连接到系统上时,我能够列出所有/dev/ttyUSB端口名称,但是我也想知道,哪个调制解调器包含端口0到16,哪个调制解调器包含端口17到32? >

调制解调器可能在一天内被连接和移除很多次,所以当调制解调器断开连接并再次连接时,我还想保留日志.

任何想法如何使用c/c ++/php script/node.js做到吗?

解决方案

您可以从sys文件系统中获取此信息.很容易从shell中进行检查,然后执行一个执行相同操作的程序:

  1. cd /sys/devices
  2. 找到第一个端口的目录:find -name "ttyUSB0".它可能会在类似./pci0000:00/0000:00:1d.0/usb2/2-2/2-2.1/2-2.1:1.0/...
  3. 的位置找到它们
  4. pci*部分是USB控制器.有趣的是2-2.1,它是USB设备.在该目录中,有很多文件可以识别您的设备:

    • serial:序列号.可能是您想要的.
    • idVendoridProduct:设备的USB标识符.

第1步和第2步的一个简单替代方法是:

  1. cd /sys/class/tty/
  2. readlink ttyUSBn将为您提供设备目录的完整路径.

作为脚注,请注意sysfs的某些部分被认为是API稳定的,而某些部分则不稳定.有关更多信息,请参见官方sysfs规则.

I am using two Wavecom 16-port modems. When I attach the modems to my system, I am able to list of all the /dev/ttyUSB port names, but also I want to know, which modem is containing ports 0 to 16 and which one is containing ports 17 to 32?

The modems may be attached and removed many times in a single day, so I also want to keep logs when modems get disconnected and connected again.

Any idea how to do so using c/c++/php script/node.js ?

解决方案

You can get this information from the sys filesystem. It is easy to check from the shell, and then do a program that does the same:

  1. cd /sys/devices
  2. Find the directory of the first of your ports: find -name "ttyUSB0". It will probably find them in something like ./pci0000:00/0000:00:1d.0/usb2/2-2/2-2.1/2-2.1:1.0/...
  3. The pci* part is the USB controller. The interesting bit is the 2-2.1 which is the USB device. In that directory there are a lot of files that identify your device:

    • serial: The serial number. Probably what you want.
    • idVendor and idProduct: The USB identifier of the device.

An easy alternatively to steps 1 and 2 is:

  1. cd /sys/class/tty/
  2. readlink ttyUSBn will give you the full path of the device directory.

As a footnote, note that some parts of the sysfs are considered API stable and some parts are not. For more information see the official sysfs rules.

这篇关于如何知道哪个设备连接到了/dev/ttyUSB端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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