How to find out which serial port to use on Linux?

I am going to write a program in C that is going to open a connection through the serial port and "listen" to the incoming commands, then it will take some action and report the status.

The connection will be via RS232 (serial port), and I'm trying to figure out how to find out which port to open.

When using windows, if I plug in my USB serial device, I see that the Prolific USB-to-Serial Comm Port (COM4) is displayed in the device manager ... but on the Linux side I don't see any changes in the /sys/class/tty or /dev , I see ttyS0 through ttyS7 all the time (I assume that S stands for serial number based on what I read ).

So how do I know who to connect to?

EDIT
Although I am developing this in the OpenSUSE 12.1 kernel (3.1 kernel), the final program will run on uCLinux on the 2.4Linux kernel board, so I am looking for clean C solutions that will work on older kernels

FYI: the /sys file system, as indicated in the reply to this post , did not exist until the 2.6 kernel and my limitations force me to stick with things available in the 2.4 kernel.

+7
source share
3 answers

The dmesg will show you a kernel message when the module is connected, which will indicate the name of the device.

The /proc file system is similar to the device manager on windows - somewhere there will be a list of tty devices

+3
source

Two things that I used: (a) look for control lines (DTR, DSR, etc.) and (b) open "all" ports and find out which of them seem active. In the latter case, it helps if you can send a message to the serial device and reply to it; this obviously only works if the device responds to the message.

+1
source

Check out /proc/tty/driver/serial - you should see uart like 16550A instead of unknown and rx should be> 0 for existing ports. If you have to guess which port will be used, open all available ports. After that, you need to configure the port for your needs (baud rate, parity, bit, etc.) or try to guess the incoming baud rate, etc.

0
source

All Articles