Managing Serial Ports on Ubuntu: Information, Tools, and Permissions
Checking Serial Port Information
1. Determining Port Usage
Serial port device are located in the /dev directory. To check if a specific port is present and accessible, use the ls command.
ls -l /dev/ttyUSB0
Explanation:
ls -l: Lists directory contents with detailed information. Usinglsorll(if aliased) also works.ttyUSB0: The device name for the serial port. Names typically start withtty, such asttyS0for onboard serial orttyACM0for some USB CDC devices. The number (e.g., 0) is the port identifier and should be adjusted as needed.
Result:
- If the port exists and is accessible, the command outputs the device file details.
- If the port does not exist or is not found, the output will be:
ls: cannot access '/dev/ttyUSB0': No such file or directory.
2. Viewing Device Details
To see kernel messages related to a specific serial device, use dmesg with grep.
dmesg | grep ttyUSB0
Serial Port Communication Tools
1. Minicom
Minicom is a powerful, text-based terminal program for serial communication.
Installation:
sudo apt install minicom
2. CuteCom
CuteCom provides a graphical user interface (GUI) for serial communication, similar to many Windows tools. It allows selection of port, baud rate, data bits, stop bits, etc., with separate windows for receiving and sending data.
Installation and Launch:
# Install the package
sudo apt install cutecom
# Run the application (requires root for port access by default)
sudo cutecom
3. COMTool
COMTool is a cross-platform serial communicatino tool developed in Python 3 by Neucrack Neutree. It is available for Linux, Windows, and macOS.
Note: Python 3 must be installed on the system to run it. Installation and usage instructions for each platform are available on its GitHub repository.
Managing Serial Port Permissions
By default, regular users lack read/write permissions for serial ports in Linux. Temporary permissions can be granted using chmod:
sudo chmod 666 /dev/ttyUSB0
However, for applications that need to run automatiaclly on startup, permanent permission rules are more practical.
1. Create a Udev Rule File
Open or create a rules file in /etc/udev/rules.d/. The filename can be customized but must end with .rules.
sudo nano /etc/udev/rules.d/70-usb-serial.rules
2. Add Rule Content
Add the following line to the file. This rule matches all devices with names like ttyUSB* (adjust ttyUSB* to ttyS* or other patterns as needed). The MODE sets permissions to 0666 (read/write for all). The SYMLINK+ directive creates a persistent symbolic link (e.g., vibot_base) to the device; this part is optoinal and can be omitted.
KERNEL=="ttyUSB*", MODE="0666", SYMLINK+="vibot_base"
3. Apply Changes
Reboot the system or trigger udev to reload the rules:
sudo udevadm control --reload-rules
sudo udevadm trigger
After applying the rules, the device permissions should be set correctly, and if a SYMLINK was specified, the symbolic link (e.g., /dev/vibot_base) will be available.