How-To Access COM Port (RS-232 client/server)

Alexey Eremenko "Technologov"

$Revision: 05 $

$Date: 2007-01-24 $

Scenario

You have a device, which requires access via COM port; It can be an ancient Terminal Server, or a Cisco Router for example. You are basically converting your Linux PC to a “Terminal Emulator”, or “RS232 client”, if you wish.

Procedure

This How-To uses standard GNU/Linux commands, therefore it is not specific to openSUSE.

Make sure you have screen installed, with:

rpm -q screen

If not, install it. Fortunately it is included on openSUSE CDs and DVD.

The command are very simple: (you must be logged in as root)

# screen /dev/ttyS0

or access any other COM port by changing the last digit (0...7).

To exit screen use: “ctrl+a”, then “ctrl+\”, “y”.

Understanding

The COM Port, which has more professional names such as EIA/TIA-232, RS232 or V.24 is an ancient serial networking and communications technology standard developed in the 1960's. It could be used to connect 2 computers together (DTE-to-DTE), or computer and an external modem (DTE-to-DCE). Some other use cases include connection to UPS (for control), and to mice. Older mice (before 1997) used exclusively this technology. Usually it has 9-pin or 25-pin “D”-like physical interface. Today it is superceded by the Ethernet and USB, but has still accasional use here and there. On modern motherboards, it can be either 9-pin cyan-colored interface (according to PC-Color-99 specification) or lack completely.

Because the standard is extremely successful, old and open, it is supported by *ALL* Operating Systems. (which cannot be said of USB)

Converting your Linux box to RS-232 Server

Besides being a client, Linux has the option of providing a server, that is, a TTY line to other clients connecting to it by way of Serial COM interface.

Primary thing to do, is to edit your /etc/inittab, and uncomment the following line, by removing the first byte:

#S0:12345:respawn:/sbin/agetty -L 9600 ttyS0 vt102

This will allow to connect to your COM port, after the Operating System is up and running, but what if you want to connect to your system earlier?

Another thing to do (optionally) is to modify your /boot/grub/menu.lst so you can connect to your Linux system on the bootloader stage, plus see Linux kernel messages.

Below you see a modified GRUB menu for openSUSE 10.2 system, so similar technology can be applied to other SUSE Linux systems as well.

# Modified by YaST2. Last modification on Fri Dec  8 16:25:38 UTC 2006
default 0
timeout 8
##YaST - generic_mbr
#commented "#gfxmenu", because RS-232 disallows GUI.
#gfxmenu (hd0,0)/boot/message
#
##YaST - activate
serial --unit=0 --speed=9600 --word=8 --parity=no --stop=1
terminal serial console

###Don't change this comment - YaST2 identifier: Original name: linux###
title openSUSE 10.2
root (hd0,0)
kernel /boot/vmlinuz-2.6.18.2-34-default root=/dev/hda1 showopts console=tty0 console=ttyS0,9600n8
initrd /boot/initrd-2.6.18.2-34-default

Let me explain all the modifications:

GRUB-section: You must comment the gfxmenu (graphics menu). RS-232 allows text-only.

#commented "#gfxmenu", because RS-232 disallows GUI.
#gfxmenu (hd0,0)/boot/message

GRUB-section: You must enable serial.

serial --unit=0 --speed=9600 --word=8 --parity=no --stop=1
terminal serial console

Kernel-section: To enable kernel messages on COM port, during boot: add console=tty0 console=ttyS0,9600n8 as your kernel boot parameters, plus remove any vga=0x317 and splash=silent kernel boot parameters. The final result should look like this:

kernel /boot/vmlinuz-2.6.18.2-34-default root=/dev/hda1 showopts console=tty0 console=ttyS0,9600n8
initrd /boot/initrd-2.6.18.2-34-default

For More Information

info screen

Tip: combine this how-to with shared-sessions how-to for excellent effect.

Wikipedia about COM port: http://en.wikipedia.org/wiki/RS232.

A major, feature-full article about Linux as a RS-232 Server: http://www.linux.com/howtos/Remote-Serial-Console-HOWTO/.