How to know which device is connected in which /dev/ttyUSB port

前提是你 提交于 2019-12-20 19:11:04

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/13914226/how-to-know-which-device-is-connected-in-which-dev-ttyusb-port

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!