Next Previous Contents

5. Serial Port Devices /dev/ttySN

5.1 Serial Port Device Names & Numbers

Devices in Linux have major and minor numbers. Each serial port may have 4 possible names, only 2 of which are official and found in the /dev directory: ttyS and cua. The cua name is deprecated and may not be used in the future. See The cua Device. Dos/Windows use the COM name while the setserial program uses tty00, tty01, etc. Don't confuse dev/tty0, dev/tty1, etc. which are used for the console (your PC monitor) but are not serial ports.

       set-                                              IO
dos   serial          major minor         major minor  address
COM1  tty00  /dev/ttyS0  4,  64;  /dev/cua0  5,  64      3F8
COM2  tty01  /dev/ttyS1  4,  65;  /dev/cua1  5,  65      2F8
COM3  tty02  /dev/ttyS2  4,  66;  /dev/cua2  5,  66      3E8
COM4  tty03  /dev/ttyS3  4,  67;  /dev/cua3  5,  67      2E8
Note that all distributions should come with ttyS devices (and cua devices until cua is finally abolished) already made correctly. You can verify this by typing:

linux% ls -l /dev/cua*
linux% ls -l /dev/ttyS*

5.2 Creating Devices In the /dev directory

If you don't have a device, you will have to create it with the mknod command. Example, suppose you needed to create devices for ttyS0:

linux# mknod -m 666 /dev/cua0 c 5 64
linux# mknod -m 666 /dev/ttyS0 c 5 64
You can use the MAKEDEV script, which lives in /dev. See the man page for it. This simplifies the making of devices. For example, if you needed to make the devices for ttyS0 you would type:
linux# cd /dev
linux# ./MAKEDEV ttyS0
This handles the devices creation and should set the correct permissions.

5.3 Link ttySN to /dev/modem ?

On some installations, two extra devices will be created, /dev/modem for your modem and /dev/mouse for your mouse. Both of these are symbolic links to the appropriate device in /dev which you specified during the installation (unless you have a bus mouse, then /dev/mouse will point to the bus mouse device).

There has been some discussion on the merits of /dev/mouse and /dev/modem. The use of these links is discouraged. In particular, if you are planning on using your modem for dialin you may run into problems because the lock files may not work correctly if you use /dev/modem. Use them if you like, but be sure they point to the right device. However, if you change or remove this link, some applications might need reconfiguration.

5.4 The cua Device

Each ttyS device has a corresponding cua device. It is planned to eventually abolish cua 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 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 DCD 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 assert DCD (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 will be put in the kernel log when one uses cua. This is an omen that cua will sometime disappear.


Next Previous Contents