The Question:I plugged in a device (i.e. GSM modem) through a serial port (a.k.a. RS-232), and I need to see with which file in /dev/ filesystem this device was tied up, to be able to communicate with it. Unfortunately there is no newly created file in /dev/ nor can be seen anything in dmesg output. So this seems to be a hard question.Background:I had never worked with a serial device, so yesterday, when there appeared a need, I tried to Google it but couldn't find anything helpful. I spent a few hours in seek, and I want to share a found answer as it could be helpful for someone.
How to find which serial port is in use?
devices;tty;serial port
A Solution:The problem is that this serial port is non-PlugNPlay, so the kernel does not know which device was plugged in. After reading a HowTo tutorial I got the working idea. In the /dev/ directory of a unix like OS there are files named as ttySn where the ending n is a number. Most of these files are dumb i.e. doesn't correspond to an existing device. But some of those refer to a real port. To find which it is, issue a command:$dmesg | grep ttyS[    0.872181] 00:06: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A[    0.892626] 00:07: ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A[    0.915797] 0000:01:01.0: ttyS4 at I/O 0x9800 (irq = 19) is a ST16650V2[    0.936942] 0000:01:01.1: ttyS5 at I/O 0x9c00 (irq = 18) is a ST16650V2Above is an example output of my PC. You can see the initialization of a few serial ports which are:ttyS0, ttyS1, ttyS4, ttyS5. One of those serial ports is going to have a positive voltage when a device is plugged in so by comparing the content of the file /proc/tty/driver/serial in two different situations as: With the device plugged in Without the device plugged in we can easily find the ttyS related to our device.To do so do the following:$ sudo cat /proc/tty/driver/serial> /tmp/1(un)plug a device$ sudo cat /proc/tty/driver/serial> /tmp/2Next check the difference between two files. Below is output of my PC:$ diff /tmp/1 /tmp/22c2< 0: uart:16550A port:000003F8 irq:4 tx:6 rx:0---> 0: uart:16550A port:000003F8 irq:4 tx:6 rx:0 CTS|DSRThe uart number of our device is 16550A. By looking up this number in dmesg output, we can find our device's corresponding ttyS which here it is ttyS0:[    0.872181] 00:06: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550ASo, our device is /dev/ttyS0, that's it. mission accomplished!