Reputation: 573
I'm no expert of Linux or serial programming, and my understanding of Linux serial port communication is: the system links certain /dev/ttyS* file to a certain physical serial port, then the system or other procedures can talk with any device that is attached to that serial port via the /dev/ttyS* file. And the /dev/ttyS* file would be assigned/linked to the serial port no matter there's any device attached.
If I'm correct about this, then is there any way, in C, that I can get all such /dev/ttyS* files which are linked to physical serial ports?
Have already searched all over Google and SO, nothing really helpful found, plz halp!
PS, I can find such files by using:
dmesg | grep ttyS
but I need a more precise way to get these info, things like libudev can do this ??
Upvotes: 0
Views: 2440
Reputation:
I'm not absolutely sure what is being asked here, but the way /dev/ttyS* are mapped has not changed in ages and the first serial port, sometimes called with DOS name COM1, is still accessible as /dev/ttyS0
, second being /dev/ttyS1
and so on.
From kernel documentation, namely from file Documentation/devices.txt
you can still find some useful information:
4 char TTY devices
0 = /dev/tty0 Current virtual console
1 = /dev/tty1 First virtual console
...
63 = /dev/tty63 63rd virtual console
64 = /dev/ttyS0 First UART serial port
...
255 = /dev/ttyS191 192nd UART serial port
UART serial ports refer to 8250/16450/16550 series devices.
If your question how to find all serial ports on your system, see /dev/serial
which should have (unless you're using a kernel really ancient) entries by-id and by-uuid.
Upvotes: 1