Next Previous Contents

9. Serial Port Devices /dev/ttyS4, (or /dev/ttys/4) etc.

9.1 Serial Port Names: ttyS4, etc

Once upon a time the names of the serial ports were simple. Except for some multiport serial cards they were named /dev/ttyS0, /dev/ttyS1, etc. Then around the year 2000 came the USB bus with names like /dev/ttyUSB0 and /dev/ttyACM1 (for the ACM modem on the USB bus).

9.2 The PCI Bus

Since DOS provided for 4 serial ports on the old ISA bus: COM1-COM4, ttyS0-ttyS3 most serial ports on the newer PCI bus used higher numbers such as ttyS4 or ttyS14 (prior to kernel 2.6.13). But since most PCs only came with one or two serial ports, ttyS0 and possibly ttyS1 (for the second port) the PCI bus now may use ttyS2 (kernel 2.6.15 on). All this permits one to have both ISA serial ports and PCI serial ports on the same PC with no name conflicts. 0-1 (or 0-3) are reserved for the old ISA bus (or the newer LPC bus) and 2-upward (or 4-upward or 14-upward) are used for PCI. It's not required to be this way but it often is. On-board serial ports on motherboards which have both PCI and ISA slots are likely to still be ISA ports. Even for all-PCI-slot motherboards, the serial ports are often not PCI. Instead, they are either ISA, on an internal ISA bus or on a LPC bus which is intended for slow legacy I/O devices: serial/parallel ports and floppy drives.

9.3 Serial Port Device Names & Numbers

Devices in Linux have major and minor numbers. The serial port ttySx (x=0,1,2, etc.) is major number 4. You can see this (and the minor numbers too) by typing: "ls -l ttyS*" in the /dev directory. To find the device names for various devices, see the "devices" file in the kernel documentation.

There formerly was a "cua" name for each serial port and it behaved just a little differently. For example, ttyS2 would correspond to cua2. It was mainly used for modems. The cua major number was 5 and minor numbers started at 64. You may still have the cua devices in your /dev directory but they are now deprecated. For details see Modem-HOWTO, section: cua Device Obsolete.

For creating the old devices in the device directory see: the Serial-HOWTO: "Creating Devices In the /dev directory".

9.4 More on Serial Port Names

Dos/Windows use the COM name while the messages from the serial driver use ttyS00, ttyS01, etc. Older serial drivers (2001 ?) used just tty00, tty01, etc.

The tables below shows some examples of serial device names. The IO addresses are the default addresses for the old ISA bus (not for the newer PCI and USB buses).

dos     common                  IO       USB-BUS ( ACM => acm modem )
name     name     major minor address || common name      common name
COM1   /dev/ttyS0  4,  64;   3F8      || /dev/ttyUSB0  |  /dev/ttyACM0
COM2   /dev/ttyS1  4,  65;   2F8      || /dev/ttyUSB1  |  /dev/ttyACM1
COM3   /dev/ttyS2  4,  66;   3E8      || /dev/ttyUSB2  |  /dev/ttyACM2
COM4   /dev/ttyS3  4,  67;   2E8      || /dev/ttyUSB3  |  /dev/ttyACM3
 -     /dev/ttyS4  4,  68;   various

9.5 USB (Universal Serial Bus) Serial Ports

For more info see the usb subdirectory in the kernel documentation directory for files: usb-serial, acm, etc.

9.6 Link ttySN to /dev/modem

On some installations, two extra devices will be created, /dev/modem for your modem and /dev/mouse for a mouse. Both of these are symbolic links to the appropriate device in /dev.

Historical note: Formerly (in the 1990s) the use of /dev/modem (as a link to the modem's serial port) was discouraged since lock files might not realize that it was really say /dev/ttyS2. The newer lock file system doesn't fall into this trap so it's now OK to use such links.

9.7 Devfs (The Improved but Obsolete Device File System)

Kernel 2.4 introduced the now obsolete optional "device file system" (devfs) with a whole new set of names for everything. But in 2003-4, it was claimed that devfs had unsolvable problems and starting with kernel 2.6.12 it was replaced with "udev" (kernels prior to 2.6.12 also could use udev but with some problems). Although udev doesn't provide all the functionality of devfs, it does handle hot plugging. Also, the use of udev isn't required to run Linux so some people don't use it. But many distributions install it by default.

Devfs was a good idea and was claimed to be more efficient than udev. But unfortunately, the author of devfs didn't maintain it for long and it allegedly became not too well maintained. So for better or worse we now have udev instead although the debate of devfs vs. udev still continues. For a detailed description of devfs see: http://www.atnf.csiro.au/~rgooch/linux/docs/devfs.html Also see the kernel documentation tree: filesystems/devfs.

The names of devices for the devfs can be used in udev, but usually are not and may not be simple to activate. Here's the devfs names for serial devices: ttyS1 becomes tts/1, ttyUSB1 becomes /usb/tts/1, and ttyACM1 is /usb/acm/1. Note that the number 1 above is just an example. It could be replaced by 0, 2, 3, 4, etc. Some more examples of udev names: ttyS2 becomes tts/2 (Serial port), tty3 becomes vc/3 (Virtual Console), ptyp1 becomes pty/m1 (PTY master), ttyp2 becomes pty/s2 (PTY slave). "tts" looks like a directory which contains devices "files": 0, 1, 2, etc. All of these new names should still be in the /dev directory although optionally one may put them elsewhere.

For devfs device names in the /dev directory are created automatically by the corresponding driver. Thus, if serial support comes from a module and that module isn't loaded yet, there will not be any serial devices in the /dev directory. This can be confusing: you physically have serial ports but don't see them in the /dev directory. However, if a device name is told to a communication program and the serial module isn't loaded, the kernel is supposed to try to find a driver for it and create a name for it in the /dev directory.

This works OK if it finds a driver. But suppose there is no driver found for it. For example, if you try to use "setserial" to configure a port that the driver failed to detect, it claims there is no such port. How does one create a devfs port in this case?

For multiport devices for example, /dev/ttyF9 becomes /dev/ttf/9, or in a later version /dev/tts/F9. Substitute for F (or f) whatever letter(s) your multiport board uses for this purpose. A multiport driver is supposed to create a devfs name similar to the above and put it into the /dev directory

9.8 cua Device Obsolete

Each ttyS device has a corresponding cua device. But the cua device is deprecated so it's best to use ttyS (unless cua is required). There is a difference between cua and ttyS but a savvy programmer can make a ttyS port behave just like a cua port so there is no real need for the cua anymore. Except that some older programs may need to use the cua.

What's the difference? The main difference between cua and ttyS has to do with what happens in a C-program when an ordinary "open" command tries to open the port. If a cua port has been set to check modem control signals, the port can be opened even if the CD modem control signal says not to. Astute programming (by adding additional lines to the program) can force a ttyS port to behave this way also. But a cua port can be more easily programmed to open for dialing out on a modem even when the modem fails to raise CD (since no one has called into it and there's no carrier). That's why cua was once used for dial-out and ttyS used for dial-in.

Starting with Linux kernel 2.2, a warning message is put in the kernel log when one uses cua. This is an omen that cua is defunct and should be avoided if possible.


Next Previous Contents