Appendix E: Modems and Terminals

Appendix E: Modems and Terminals

If you have installed Red Hat Linux on your home PC, you may want to use a modem to dial out to your Internet service provider (ISP) and connect to the Internet. To use a modem, you have to learn how Linux works with the PC's serial ports-the ports through which the modem communicates with the PC. You need also to get cables to connect the modem to the PC, to select the proper serial device to use in Linux, and to set up configuration files that control the communication parameters for the serial port.

Terminals-devices that have a display screen and a keyboard-also connect to the PC through serial ports. In that sense, terminals are similar to modems. Terminals are ideal for simple data-entry tasks and are often used in point-of-sale systems. Linux also supports multiport serial boards that enable you to connect many terminals or modems to your PC running Linux.

This appendix explains how to connect, set up, and use modems and terminals. Much of the information applies to any device connected to the serial port, but some information is specific to modems. This appendix focuses primarily on modems because modems are more popular than dumb terminals connected to a Linux system.

Serial Ports

If you have used communications software, such as Procomm or Crosstalk, under MS-DOS or Windows, you have used your PC's modem and serial port. These communications programs transfer bytes of data from the PC to the modem over the serial port. The serial port is so named because each byte of data is sent serially-one bit at a time. Serial data communication comes with its own set of terminology. To understand how to set up the serial port, you need to understand the terminology.

UART

A chip named the universal asynchronous receiver/transmitter (UART), which is at the heart of all serial communication hardware, takes care of converting each byte to a stream of ones and zeros. That stream of ones and zeros is then sent over the communications medium (for example, the telephone line). At the receiving end, another UART reconstitutes bytes of data from the stream of ones and zeros.

The original IBM PC's motherboard did not include serial communication capabilities. Instead, the serial communication function was provided through a separate serial adapter card (or serial board) called the IBM Asynchronous Communications Adapter. This serial board used National Semiconductor's INS8250 UART chip.

Later, PCs began including the serial communication hardware on the motherboard, but the same 8250 or compatible UART was used for a long time. Still later, an improved version of the 8250-the 16450-was introduced, but the improvements were in the chip's fabrication details, not in its basic capability.

A problem with the 8250 and 16450 UARTs is that they do not have any way to buffer received characters. If the PC cannot keep up with the character stream, some characters may be lost. At high data-transfer rates (more than 9,600 bits per second), the PC may have trouble keeping up with the arrival of characters, especially with operating systems that keep the PC busy (such as Microsoft Windows).

The solution was to add a first in, first out (FIFO) buffer on the UART, enabling the PC to fall behind occasionally, without losing any incoming characters. The newer 16550A UARTs have send and receive buffers, each of which is capable of storing up to 16 characters. The 16550A UART is compatible with the old 8250 and 16450, but it can support higher data-transfer rates because the built-in buffers can store incoming and outgoing characters directly on the UART.

On a historical note, National Semiconductor's original 16550 UART had the FIFO buffers, but the FIFO circuits had some bugs. The 16550A (and later versions of that UART) fixed the problems of the original 16550. By now, however, the 16550 name is often used to refer to any UART with an onboard receive and transmit buffer. You don't have to worry about the distinctions between the 16550 and 16550A, except in the case of the original 16550 UARTs from National Semiconductor; those chips are marked NS16550 (without an A).

Note

Linux supports PC serial ports and serial I/O boards that use a 8250, 16450, 16550, 16550A, or compatible UART. However, you really need a 16550A or better UART to keep up with today's high-speed modems, which can transfer data at rates of up to 56,000 bits per second. Most new Pentium PCs should already have 16550A UARTs. If you are buying a new PC to run Linux, you should check with the vendor and make sure that the serial interface uses 16550A UARTs. Newer UARTs, such as the 16654 and 16750, come with a 64-byte buffer. These UARTs should also work with Linux.

Communications Parameters

In serial communications, the transmission medium (such as the telephone line) is kept at a logical 1 when it is idle (1 is represented by the presence of a signal on the line). In this case, the line is said to be marking. On the other hand, when the line is at a logical 0, it is said to be spacing. Thus, logical 1 and 0 are also referred to as mark and space, respectively.

A sequence of ones and zeros makes up a single 8-bit character. A change in the condition of the line from mark to space indicates the start of a character. That change in line condition is referred to as the Start bit. Following the Start bit is a pattern of bits that represents the character and then a bit known as the Parity bit. Finally, the line reverts to its idling mark condition, which represents the Stop bit and indicates the end of the current character. The number of bits used to represent the character is known as the word length and is usually either seven or eight.

The Parity bit is used to perform rudimentary error detection. When even parity is selected, for example, the Parity bit is set so that the total number of ones in the current word is even (the logic is similar for odd parity). At the receiving end, the parity is recalculated and compared with the received parity bit. If the two disagree, the receiver declares a parity error. One problem of error detection with the parity check is that it can detect only errors that affect a single bit. The bit pattern 0100 0001 0 (the ASCII code for the letter A), for example, transmitted with an 8-bit word length and even parity, may change (due to noise in the telephone line) to 0100 0111 0 (ASCII G); the receiver, however, does not see the error, because the parity is still even. Thus, parity error detection is rarely used nowadays.

In serial communications, the transmitter and the receiver both must have some knowledge of how long each bit lasts; otherwise, they cannot detect the bits correctly. The duration of each bit is determined by data clocks at the receiver and the transmitter. Notice, however, that although the clocks at the receiver and the transmitter must have the same frequency, they do not have to be synchronized. The Start bit signals the receiver that a new character follows; the receiver then begins detecting the bits until it sees the Stop bit.

A particular condition of the line is sometimes used to gain the attention of the receiver. The normal state of the line is mark (1), and the beginning of a character is indicated by a space (0). If the line stays in the space condition for a period of time longer than it would have taken to receive all the bits of a character, a break is assumed to have occurred. When the receiver sees the break condition, it can get ready to receive characters again.

The selection of the clock frequency depends on the baud rate (or simply baud), which refers to the number of times that the line changes state every second. Typically, the serial I/O hardware uses a clock rate of 16 times the baud rate so that the line is sampled often enough to detect reliably.

Baud versus BPS

The data-transfer rate is expressed in terms of bits per second, or bps. In the early days of modems, the data-transfer rate was the same as the baud rate-the rate of change of the line's state-because each line state carried a single bit of information. Nowadays, modems use different technology that can send several bits of information each time the line state changes. In other words, you can get a high bps with a relatively low baud rate. The fastest modems today use a baud rate of 2,400, even though the bits per second can be as high as 56,000.

Thus, baud and bits per second are not the same. Most of us, however, ignore the exact definition of baud rate and simply use baud to mean bits per second. Even though I'll stick to bps when I speak of data-transfer rates, you'll run across Linux settings that use baud rate to mean bps.

Serial-Port IRQs and I/O Addresses

The PC typically has two serial ports, called COM1 and COM2 in MS-DOS parlance. The PC can also support two more serial ports: COM3 and COM4. Because of these port names, the serial ports are often referred to as COM ports.

Like other devices, the serial ports need interrupt request (IRQ) numbers and I/O port addresses. Two IRQs-3 and 4-are shared among the four COM ports. Table E-1 lists the IRQs and I/O port addresses assigned to the four serial ports.

Table E-1: IRQ and I/O Port Addresses Assigned to Serial Ports

Port

IRQ

I/O Address

COM1

4

0x3f8

COM2

3

0x2f8

COM3

4

0x3e8

COM4

3

0x2e8

Serial-Device Names in Linux

Like other devices in Linux, the serial-port devices are represented by device files in the /dev directory. Each serial port has two names: one for incoming connections and one for outgoing connections. Table E-2 lists the device names for incoming and outgoing serial ports, including the major and minor device numbers.

Table E-2: Device Names for Incoming and Outgoing Serial Ports

COM Port

Device Name*

Major Device Number

Minor Device Number

Incoming COM1

/dev/ttyS0

4

64

Incoming COM2

/dev/ttyS1

4

65

Incoming COM3

/dev/ttyS2

4

66

Incoming COM4

/dev/ttyS3

4

67

Outgoing COM1

/dev/cua0

5

64

Outgoing COM2

/dev/cua1

5

65

Outgoing COM3

/dev/cua2

5

66

Outgoing COM4

/dev/cua3

5

67

USB serial port #1

/dev/usb/ttyUSB0

188

0

USB serial port #2

/dev/usb/ttyUSB1

188

1

... 16 serial ports ...

...

188

...

USB serial port #16

/dev/usb/ttyUSB15

188

15

* You should now use the /dev/ttySx devices for both incoming and outgoing serial communications. The /dev/cuax devices only exist to provide backwards compatibility with older programs. The plan is to abolish the /dev/cuax devices in the future.

If you have installed Red Hat Linux from this book's companion CD-ROM, all these devices should already be in your system. If you check the /dev directory, you'll find the /dev/ttyS* and /dev/cua* devices, where * is 0, 1, 2, 3, and so on.

Note

Historically, Linux used the /dev/ttyS* devices for dialing in and the /dev/cua* devices for dialing out. However, the current version of the Linux kernel does not distinguish between /dev/ttyS* and /dev/cua* devices. My recommendation is to use the /dev/ttyS* device names wherever you need to refer to serial devices.