How To Check and Use Serial Ports Under Linux

How do I check and configure serial ports under Linux for various purposes such as modem, connecting null modems or connect a dumb terminal?

Linux offers various tools and commands to access serial ports. Linux uses ttySx for a serial port device name. For example, COM1 (DOS/Windows name) is ttyS0, COM2 is ttyS1, and so on. USB based serial ports might use a name such as ttySUSB0. All these devices are located under /dev/ directory.

Display Detected System’s Serial Support Under Linux

Simple run the dmesg command:
$ dmesg | grep tty

[   37.531286] serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[   37.531841] 00:0b: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[   37.532138] 0000:04:00.3: ttyS1 at I/O 0x1020 (irq = 18) is a 16550A

A note about USB based serial ports

USB to RS232 adapter cable connects from the USB port of a computer to a device. Such serial to USB adapter connects to devices for configuration or programming under Linux. Here is what the dmesg command displays when you enter USB adapter:
$ dmesg
## use grep command/egrep command to filter out USB devices ##
$ dmesg | grep -i serial
$ dmesg | grep -i FTDI

Listing and using USB serial ports on Linux

List and Check Serial Ports Under Linux

Here is how it looks when I attached USB device:
$ sudo dmesg | more

Use the setserial command to check and use serial ports

The setserial is a program designed to set and/or report the configuration information associated with a serial port. This information includes what I/O port and IRQ a particular serial port is using, and whether or not the break key should be interpreted as the Secure Attention Key, and so on.

Debian/Ubuntu Linux install setserial using the apt-get command/apt command

$ sudo apt install setserial

Reading package lists… Done Building dependency tree Reading state information… Done The following NEW packages will be installed: setserial 0 upgraded, 1 newly installed, 0 to remove and 14 not upgraded. Need to get 35.9 kB of archives. After this operation, 120 kB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 setserial amd64 2.17-52 [35.9 kB] Fetched 35.9 kB in 1s (25.7 kB/s) Preconfiguring packages … Selecting previously unselected package setserial. (Reading database … 292992 files and directories currently installed.) Preparing to unpack …/setserial_2.17-52_amd64.deb … Unpacking setserial (2.17-52) … Setting up setserial (2.17-52) … removing the old setserial entry in the rcn.d directories Update complete. update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults Stopping setserial (via systemctl): setserial.service. Created symlink /etc/systemd/system/multi-user.target.wants/setserial.service → /lib/systemd/system/setserial.ser vice. Created symlink /etc/systemd/system/multi-user.target.wants/etc-setserial.service → /lib/systemd/system/etc-setse rial.service. Processing triggers for man-db (2.9.1-1) … Processing triggers for systemd (245.4-4ubuntu3.2) …

CentOS/RHEL/Oracle Linux install setserial using the yum command

$ sudo yum install setserial
Fedora Linux user try the dnf command:
$ sudo dnf install setserial

Using setserial to list serial ports and devices

Now we installed required package. Open the termial and then type the following setserial command:
$ setserial -g /dev/ttyS[0123]
If you get an error/warning that reads as “Permission denied,” try running the command as the root user. For example, I am running it using the sudo command/su command:
$ sudo setserial -g /dev/ttyS[0123]

/dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4
/dev/ttyS1, UART: 16550A, Port: 0x1020, IRQ: 18
/dev/ttyS2, UART: unknown, Port: 0x03e8, IRQ: 4
/dev/ttyS3, UART: unknown, Port: 0x02e8, IRQ: 3

The setserial with -g option help to find out what physical serial ports your Linux box has.

Listing or displaying USB serial ports on Linux

Try:
$ sudo setserial -g /dev/ttyUSB[01]

/dev/ttyUSB0, UART: unknown, Port: 0x0000, IRQ: 0

Linux serial console programs

Once serial ports identified you can configure Linux box and use serial ports using various utilities:

  1. minicom– The best friendly serial communication program for controlling modems and connecting to dump devices
  2. wvidial or other GUI dial up networking program – a PPP dialer with built-in intelligence.
  3. Screen Command: Set Baud Rate [ Terminal Communication ]
  4. getty / agetty – agetty opens a tty port, prompts for a login name and invokes the /bin/login command.
  5. grub / lilo configuration – To configure serial port as the system console

Cocnlusion

You learned how to list or check serial ports including USB based adptor on Linux.

Reference: https://www.cyberciti.biz/faq/find-out-linux-serial-ports-with-setserial/

CATEGORIES:

Software Livre

Tags:

Comments are closed