How To Check and Use Serial Ports Under Linux

h‮/:sptt‬/www.lautturi.com
How To Check and Use Serial Ports Under Linux

To check and use serial ports under Linux, you can follow these steps:

  1. Use the ls /dev/tty* command to list all the available serial ports on the system. The /dev/tty* directory contains device nodes for all the serial ports on the system, and the ls command will list the names of these device nodes.

For example:

$ ls /dev/tty*
/dev/tty   /dev/tty0  /dev/tty1  /dev/tty2  /dev/tty3  /dev/tty4  /dev/tty5  /dev/tty6  /dev/tty7  /dev/tty8  /dev/tty9
/dev/ttyS0 /dev/ttyS1 /dev/ttyS2 /dev/ttyS3 /dev/ttyS4 /dev/ttyS5 /dev/ttyS6 /dev/ttyS7 /dev/ttyS8 /dev/ttyS9

The names of the serial ports typically start with /dev/ttyS for traditional hardware serial ports, or /dev/ttyUSB for USB-to-serial adapters.

  1. Use the stty command to configure the serial port. The stty command is used to set or display the terminal I/O options for the terminal device connected to the serial port. You can use the stty command to set the baud rate, parity, flow control, and other options for the serial port.

For example, to set the baud rate of the /dev/ttyS0 serial port to 115200 baud, you can use the following command:

$ stty -F /dev/ttyS0 115200
Created Time:2017-10-28 21:38:50  Author:lautturi