Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?

like image 513
Mayur Avatar asked Dec 17 '12 12:12

Mayur


People also ask

Which USB port is ttyUSB0?

ttyUSB means "USB serial port adapter" and the "0" (or "1" or whatever) is the device number. ttyUSB0 is the first one found, ttyUSB1 is the second etc. (Note that if you have two similar devices, then the ports that they are plugged into may affected the order they are detected in, and so the names).

How do I know which USB port is being used Linux?

In linux, lsusb is a tool used to display information about the USB bus in the system and connected to the system. lsusb will display the drivers and internal devices connected to your system, including PID and VID, as well as simple device descriptions.

Where is TTY device in Linux?

To find out which tty's are attached to which processes use the "ps -a" command at the shell prompt (command line). Look at the "tty" column. For the shell process you're in, /dev/tty is the terminal you are now using. Type "tty" at the shell prompt to see what it is (see manual pg.

How do I know my USB developer name?

Go to Control Panel > Device Manager and find your USB device. Double click the device or right click and select Properties. Go to the Details tab and select Hardware ID to view its PID and VID.


1 Answers

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.

like image 64
rodrigo Avatar answered Sep 22 '22 14:09

rodrigo