Serial Networking Devices  «Prev  Next»

Lesson 3Administering serial ports
ObjectiveConfigure and use Serial Ports

Administering Serial Ports

Administering, configuring, and using serial ports in Red Hat Enterprise Linux (RHEL) 9.2 involves several steps. Here are the general steps you need to follow:
  1. Identifying the Serial Port: The first step is identifying the serial port you wish to configure. Serial ports in Linux are represented as files in the /dev directory. They're typically named /dev/ttyS0, /dev/ttyS1, etc., with ttyS0 usually being the COM1 in DOS/Windows terms.
    To list available serial ports, you can use the command:
    # dmesg | grep tty
  2. Configuring the Serial Port: Once you've identified the serial port, you can configure it using the setserial command. This command allows you to set and report the configuration information associated with a serial port. For instance, you can use setserial to define the port's baud rate, parity, data bits, and stop bits.
    An example usage is as follows:
    # setserial /dev/ttyS0 baud_base 9600 spd_normal

    In this example, /dev/ttyS0 is the serial port, the baud_base is set to 9600 (standard baud rate), and spd_normal sets the port speed to the speed of the baud_base. The setserial command must be executed with root privileges, and changes made with setserial are not persistent across reboots. To make them persistent, you'll have to add the appropriate setserial command to a startup script, such as
  3. Using the Serial Port:
    To use the serial port, you can use a terminal emulator such as minicom, screen, or picocom.
    For example, to use minicom with /dev/ttyS0, you would use the command:
    # minicom -D /dev/ttyS0

    To use screen with /dev/ttyS0 at 9600 baud, you would use the command:
    # screen /dev/ttyS0 9600
  4. Checking Serial Port Communication:
    To check if data is being sent or received on a particular serial port, you can use the cat command to monitor the port:
    # cat /dev/ttyS0

    In another terminal, you can send data to the port:
    # echo "Test message" > /dev/ttyS0

    You should see the "Test message" output in the terminal where you ran the cat command. Remember that working with serial ports directly can affect your system. Always ensure that you have the appropriate system privileges and that you're certain about the changes you're making.
  5. Troubleshooting: If the serial port is not functioning as expected, ensure the port is not being used by another process. Use the fuser command to check for processes using the serial port:
    # fuser /dev/ttyS0

    These are the basics of administering, configuring, and using serial ports in RHEL 9.2. Depending on your specific use case and hardware, you may need to use additional commands and options. Always refer to the man pages (man setserial, man minicom, man screen, etc.) and the official Red Hat documentation for more detailed information.
Serial ports provide the interface between serial devices and the computer's I/O subsystem. On the Intel x86 architecture, there are usually two built-in serial ports. These normally correspond to /dev/ttyS0 and /dev/ttyS1, which are COM1 and COM2 under DOS and Windows. During system boot, Linux initializes these and two other ports: /dev/ttyS2 and /dev/ttyS3.
The setserial command provides a method for configuring and examining the characteristics for a vast range of serial devices, including modems, mice, and serial terminals. The setserial command enables you to set data speed, the I/O port address, flow control, and other variables for each initialized serial port. It also enables you to define additional serial ports and to query the settings of existing ports.

For example, setserial /dev/ttyS0 produces something similar to the following output:

Set Serial Administration
Set Serial Administration
  1. Device being queried or set
  2. Universal Asynchronous Receiver Transmitter converts signal voltage to computer voltage and converts asynchronous input to synchronous output.
  3. The logical address for the serial port
  4. The interrupt channel given exclusively to this serial port
Serial Ports: No serial ports are assigned by default. You can assign any of the serial ports ($_com1 to $_com4) to a device such as a modem (/dev/modem), a mouse (/dev/mouse), or a terminal line (/dev/tty0).
Set serial linux command
In the next lesson, the roles serial modems play in the Linux OS will be defined.