Serial ports are interfaces used to communicate with the serial devices connected to the system. Serial devices, such as mice, keyboards, and modems, communicate with the system by transmitting one bit at a time. The system establishes communication with the serial device using the serial port name. On Windows, COM1 or COM2 names are given to serial ports. While on Linux, the system ttyS0, ttyS1, and ttyUSB names are used.
By default, the serial devices automatically establish a connection to the system. However, as a system administrator or developer, it is important to know the serial port names. They are used in troubleshooting the system and applications.
Compared to Windows, finding serial port names on Linux is relatively challenging.
In this instructional guide, I will go through various approaches to displaying serial ports on Linux.
How to List Serial Ports on Linux
There are different approaches to listing the serial ports on Linux.
Through /sys/class Directory
On Linux, /sys/class directory contains information about devices connected to the system. These devices include block devices, serial devices, network devices, USB devices, and PCI devices. A device class signifies a specific type of device connected to the system, and it is used to efficiently manage those devices. To list the contents of the /sys/class directory, utilize the ls command with the -l flag.
ls -l /sys/class/tty/*/device/driver
This will list all the serial ports also including the virtual and pseudo devices. But, we are only interested in the available serial ports, which in my case is ttyAMA0. Let’s remove the /platform/drivers/serial8250 from the list using the grep filtration.
ls -l /sys/class/tty/*/device/driver/ | grep -v /platform/drivers/serial8250
The -v is used to invert the match, basically removing the match.
Now, it shows the ports that are available for serial communication.
To make things simple, a permanent alias can be created for the command given above, by placing it in the bashrc file.
alias getports='ls -l /sys/class/tty/*/device/driver/ | grep -v /platform/drivers/serial8250'
Through dmesg Command
To display the ports, the simplest approach is to use the dmesg command. The dmesg command is used to print the kernel ring buffer messages about hardware connected to the system, and the error encountered by the kernel during the operation of the system. Execute the dmesg command and grep for tty with sudo privileges.
sudo dmesg | grep tty
The output shows the serial port ttyAMA0.
Through Cutecom App
Another method to list the serial ports is to use GUI-based applications. To install the Cutecom application on Linux, use the following commands.
Ubuntu, LinuxMint, and other Debian-based distributions.
sudo apt install cutecom
For Fedora.
sudo dnf install cutecom
Cutecom cannot directly be installed on Red Hat Enterprise Linux. To install Cutecom on RHEL, first, we need to enable the EPEL release, which is short for Extra Packages for Enterprise Linux.
sudo yum install epel-release
Now, install it using.
sudo yum install cutecom
Now, launch the application.
Click on the drop-down menu beside Device to see a list of available serial ports. If you have attached multiple devices, then it will list the assigned ports of all the connected devices.
Conclusion
To list the serial ports on Linux is not a straightforward task. They can be viewed by listing the /sys/class directory. This directory contains information about serial ports. However, not all serial ports represent actual physical hardware. There are many virtual and pseudo devices. In this guide, I discussed how to list the serial ports using approaches such as listing the /sys/class directory, using the dmesg command, and installing the GUI-based application Cutecom.
More...
Categories
Collapse
Article Tags
Collapse
There are no tags yet.
Latest Articles
Collapse
-
by Kasimba
by George Whittaker
Introduction
Ubuntu stands out as one of the most popular Linux distributions among web developers due to its stability, extensive community support, and robust package management. This article dives into creating a dedicated web development environment in Ubuntu, guiding you from the initial system setup to deploying and maintaining your websites.
Setting Up Ubuntu for
...-
Channel: Articles
Yesterday, 05:40 PM -
-
by Kasimba
by George Whittaker
Introduction
The world of scientific computing has consistently leaned on robust, flexible operating systems to handle the demanding nature of research tasks. Linux, with its roots deeply embedded in the realms of free and open-source software, stands out as a powerhouse for computational tasks, especially in disciplines that require extensive data processing and modeling, such as neuroscience....-
Channel: Articles
09-26-2024, 03:50 PM -
-
by Kasimba
by George Whittaker
Data visualization is not just an art form but a crucial tool in the modern data analyst's arsenal, offering a compelling way to present, explore, and understand large datasets. In the context of Ubuntu, one of the most popular Linux distributions, leveraging the power of data visualization tools can transform complex data into insightful, understandable visual narratives. This guide delves deep into...-
Channel: Articles
09-20-2024, 12:33 AM -
-
by Kasimba
by Amit Ronen
The Growing Demand for Specialized Linux Solutions
As the Linux market is set to soar to nearly USD 100 billion by 2032,1 businesses are facing mounting challenges in managing increasingly complex workloads spanning from the cloud to the edge. Traditional Linux distributions are not built to meet the specific demands of these modern use cases, creating an urgent need for a more specialized, enterprise-grade...-
Channel: Articles
09-18-2024, 04:11 PM -
-
by Kasimba
by german.suarez
Introduction
As our reliance on technology grows, so does the need for robust security measures that protect systems from unauthorized access and malicious attacks. One critical area of focus is the system's boot process, a vulnerable phase where malware, rootkits, and other threats can potentially infiltrate and compromise the entire operating system. This is where Secure Boot, a feature of...-
Channel: Articles
09-16-2024, 07:51 PM -
-
by KasimbaAWS transfers OpenSearch to the Linux Foundation to support a vendor-neutral community for search, analytics, observability, and vector database software. Read more at linuxfoundation.org
The post Linux Foundation Announces OpenSearch Software Foundation to Foster Open Collaboration in Search and Analytics appeared first on Linux.com.
More...-
Channel: Articles
09-16-2024, 01:11 PM -