2 Feb 1995
Computers and terminals are called Data Terminal Equipment (DTE). Modems are Data Communications Equipment (DCE). The interface between DTE and DCE is the RS- 232 standard. The standard defines a certain set of wires that run between the DTE and DCE. Each wire has a specific use.
One wire is the Ground. The ground is the reference point against which all the signals are measured. One wire carries data from the computer (DTE) to the modem (DCE). Another wire carries data back from the modem to the computer. Wires are always named from the point of view of the DTE end. So the wire carrying data from the computer to the modem is called the Transmit wire (also Transmit Data or TD), and the wire carrying data in the opposite direction is called the Receive wire (Receive Data or RD).
Two additional wires may run from the computer to the modem. Data Terminal Ready DTR is turned on when the computer is ready to communicate (when a communications program is loaded). It is turned off when the program ends, the system reboots, or the computer is turned off. A program will also drop DTR for a few seconds to hang up the phone and return the modem to "AT" command mode. On occasion, a user will want to dial the phone with one program, then transfer data with another. A modern smart modem can be told to ignore changes in DTR. However, the computer then loses a valuable control, and it may be necessary to turn the modem off and on to reset it should something go wrong.
When hardware pacing is selected, the computer can turn off the RTS wire as a signal to tell the modem to stop sending data. Generally the computer is much faster than the modem, and it has lots of memory for buffer space. So actual control of RTS by computer programs is not terribly interesting. However, a smart COM port can take control of RTS for itself. As its internal buffers (in the UART) fill up, it can drop RTS until the operating system of the PC has a chance to read data. This would prevent any loss of data from overruns. It is unusual, however, to find a COM port smart enough to control RTS on its own.
Three signal wires run from the modem to the computer. DSR originally meant that the phone was off hook. Today it means only that the modem is powered up and working, and it is sometimes renamed Modem Ready. The Carrier Detect or DCD wire signals that a valid connection has been made between two compatible modems and data can now be transferred. The CTS wire is a signal that the modem has buffer space to receive more data.
When a modem processes the ATDT command to dial a phone number, and the phone is answered, then the modem runs through a series of tones to identify the type of modem at the other end. If the two modems can agree on a common speed and protocol, then the DCD signal is generated. If DCD does not appear within some time-out period, most communications programs will hang up the phone. Failure to see DCD can mean that 1) you accidentally dialed Joe's Pizza, 2) the computer tried to make a data connection to a Fax machine, 3) that the highest speed of your modem is not fast enough to match the lowest speed that the other modem is configured to accept.
When "Hardware Pacing" is enabled, the modem drops the CTS signal when it is temporarily unable to receive more data, and the computer drops the RTS signal when its buffers are full. CTS and RTS were always part of the RS-232 standard, but they were not always used this way. Ten years ago, the COM port would have to be set to the same speed as the modem. If the modem ran at 2400 baud, then the UART would run at 2400 baud. The computer would have to be able to keep up, and there was no need for hardware pacing.
Then modems added error recovery and data compression. Today, although the RS-232 interface still delivers data one byte at a time, the modems internally buffer data in blocks of 64 character or more. Each block is transmitted, acknowledged, and if necessary it is retransmitted until it is received correctly. Errors and retransmission slow things down. Data compression and the removal of start and stop bits speed things up. So in current use, the UART is set to a higher speed than the modem throughput. A 14400 baud modem might be connected to a UART set to 38800. Since the computer can send data to the modem much faster than the modem can send it over the phone line, at some point the modem buffers may fill up. When this occurs, the modem drops the CTS (Clear to Send) lead. The computer software should then wait until the CTS signal reappears before sending more data. In the somewhat less likely situation that the computer cannot keep up with the modem, it can drop the RTS lead. However, computers are much faster than COM ports so pacing by the computer is much less likely than pacing by the modem.
An external modem will often present
a panel of lights for diagnostic purposes. Each light reflect the state of one of the RS-232 leads
or some internal modem status. The vendors are often creative in renaming or inventing signals.
It may be necessary to read the manual to understand their meaning. In the sample above, IBM
has decided to call Transmit "SD" (Send Data) and Receive becomes "RD". DTR is easy to
spot, but DCD has been abbreviated CD. DSR has probably been renamed MR (Modem
Ready).
The other lights are invented status. OH stands for Off Hook and indicates that the phone line is active. AA means Auto Answer and indicates that the modem will answer the phone for incoming calls. HS is High Speed and means that the modem is set up for some higher speed of communications.
The lights provide a simple diagnostic tool, if the user can learn to read them. For example, if DTR is inactive, then either there is no active communications program or the cable between the computer and modem has come loose.
Real Blinkin Lights is the one clear advantage of an external modem. The state of modem leads, however, is available to any program that requests them. Programs are available for Windows that display a virtual set of modem lights on the screen. The example above comes from the IBM Windsurfer internal adapter card in OS/2.
Most modems have a speaker that allows the user to hear the dial tone, the dialing of the phone, and the initial set of tones. This can be a very simple diagnostic tool, because it is easy to determine if the phone number is invalid, or if the phone is busy, or if it is not answered.
The Transmit and Receive data lines alternate between two voltage levels. When data is being transmitted, one level represents a zero and the other level represents a one. However, the line must have some state when it is idle (when no data is being transmitted). The idle state is called Mark and corresponds to the value of 1 during data transmission. To signal the beginning of a new byte of data, the line is switched to its non-idle state (called Space and corresponding to the data value of zero) for one bit time. This is called the Start Bit.
A universal problem in
communications is to determine when one bit ends and the next one begins. Modern computer
chips can have a very accurate clock signal, but the sender and receiver must agree on the
timing. The start bit is also used for this purpose. Both the COM port and the modem have
internal clocks that operate at least 16 times faster than the communications link. This allows
each to check the voltage on the Transmit or Receive lines sixteen times for every bit. The
transition from Mark (idle) to Space allows the Receiver to synchronize its clock to the
transmitters clock with an accuracy of at least a sixteenth of a bit.
One byte of data follows the start bit. After the eight bits of data, the rules require that the line go back to Mark and remain there for at least one more bit time before a new byte of data can start. This enforced idle time is called the Stop Bit. If there is no more data, or if the next byte is delayed for some reason, then line can remain in the idle state for more than one bit time. Although the start bit and eight data bits are carefully timed, the idle time between characters must be at least one bit long, but it can be extended by any fraction of a bit. The next start bit will cause a new transition from Mark to Space, and that will determined (to within a 16th of a bit time) how the next byte of data will be clocked.
The Start and Stop bits add some overhead to the connection. Each 8 bits of data requires 10 bits worth of elapsed time to transmit. In ancient history this was a problem. However, with modern smart modems that include data compression and error correction, the speed of the modem has very little to do with the speed of the RS-232 interface. The normal convention is to use a fairly high speed between the computer and the modem, then let the modem move the data on as fast as possible. When a modem is moving data at only 14400 bits per second, but the RS-232 interface is transferring data two or three times faster, the overhead caused by the start and stop bits have no effect on performance.
An Intel computer chip performs I/O by loading a 16-bit I/O address into the "D" register. The OUT instruction writes the data in the "A" register to the device with that address. The IN instruction reads from the device and puts the value into the "A" register. Different devices can transfer one, two, or four bytes of data. A COM port device only operates with one-byte I/O operations no matter what type of computer is used.
The COM port occupies eight consecutive one byte I/O addresses. COM1 starts at 03F8 and ends at 03FF. COM2 starts at 02F8 and ends at 02FF. Each of these one byte addresses performs a specific function. A detailed description of COM port programming is outside the scope of this article. The purpose here is to give a "feel" for how things are really done. This description can then help the reader to understand the capabilities and limitations of the COM port as a device. Since all COM ports are the same except for address, this discussion will use COM1 as an example.
The first COM1 address, 03F8, is used to transfer data. Anything written to 03F8 will be sent to the modem. Reading from 03F8 will obtain the next byte of data that the modem has presented. If it were just this simple, then there would be no need for the other addresses. However, the modem operates thousands of times more slowly than the CPU. If the CPU tried to write data at full speed, it would be lost. If the CPU tries to read the next character before it has been received from the modem, the COM port has no choice but to feed back a duplicate of the previous character that it already presented.
So another address, 03FD, provides the "Line Status." When the computer reads from this address, it gets a byte with eight individual status indicators. The lowest bit indicates if there is any data available from the modem waiting to be read. The sixth bit indicates if the COM port can accept another character for transmission.
Some DOS programs loop constantly checking Line Status. In more advanced systems, the COM port is managed through interrupts. Writing to 03F9 enables the interrupts. Then the computer stops normal operation and jumps to the interrupt handler when data arrives or when a previous block of data has been sent to the modem and the computer can present new data for transmission.
One address provides control of the RS-232 signals that the COM port sends to the modem (DTR and RTS). Another reports the status of signals sent from the modem to the computer (DSR, DCD, and CTS). There are also addresses to set the speed, parity, stop bits, and character size. However, the key elements in COM programming are the 03F8 data address, the line status, and the interrupts.
The COM port is not as efficient as the hard disk controller or LAN adapter. On these other devices, data can be processed in larger 512 byte, 1K, or 2K chunks. On other devices an interrupt occurs only when the entire chunk has been read or written. But data is sent to the COM port one byte at a time. Older UARTs may generate interrupts for every character, or at best for every two characters. The "good" 16550A chip handles data in 16-byte chunks.
A simple structure, low cost, easy programming, and flexibility have made the COM port a very useful device. However, the high overhead of support limits the number of COM lines that a system can support, and at high speeds, the device can be expensive to service. This has little effect on the desktop or home computer, but it has a serious impact on servers.
It is tempting to turn the central file and database server into a COM server. Microsoft, for example, makes a point of the fact that Windows NT Advanced Server can support up to 64 lines of dial-in modem communications. This may be true with smarter multiline COM cards on a machine dedicated as a modem server, but modems and database do not mix. The high priority CPU burden of COM device support will disrupt efficient file service.
To take the next step to higher speed requires an adapter with more sophisticated logic. The Waverunner ISDN card, for example, may provide device drivers that emulate the programming interface of a COM port, but in reality it handles data in larger blocks with less overhead and fewer hardware interrupts. Of course it is much easier to do sophisticated things with a $500 card than with a $35 card.
The COM port has survived for so many years because it is simple, inexpensive, moderately fast, and easy to program. There is no protocol. There are no buffer or record boundaries. A program simply feeds bytes into the line at one end, and another program reads them out of the line as they arrive at the other end.
At the same time, the underlying reality has become quite different from the appearance. The modem actually compresses the data into blocks, transmits each block as a unit, and internally handles error recovery and pacing. Traditional settings for parity and stop bits no longer matter. In fact, the speed of the COM port is unrelated to the actual speed of the data transmission.
Modems have become astonishingly smart, and the traditional COM port functions have become less important. Perhaps the best solution would be an internal modem that folds the two functions together. The COM port "knows" when the computer reads data, because the device at address 03F8 (for COM1) receives an IN instruction and transfers the data. If the address on the computer I/O bus can be more directly connected to the modem buffers, then there would be no requirement for an RS-232 interface, or hardware pacing with CTS/RTS leads, and there would be no possibility of data lost due to an overrun.
Comparable function can be achieved, though at a much higher cost, by buying one of the particularly smart COM port cards. For $80 to $100 one can get a card with scads of internal buffer space and internal logic to control the hardware pacing leads. However, it is difficult to justify a COM port for $100 when a complete internal V.32 bis modem card sells for $120 at Price Club.
Return to the Table of Contents
Copyright 1995 PCLT -- The Storm Before the COM -- H. Gilbert