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 ?
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).
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.
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.
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.
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:
cd /sys/devices
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/...
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:
cd /sys/class/tty/
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With