The heart of serial communications is "Universal Asynchronous Receiver Transmitter", or UART for short. The UART is responsible for controlling the computer's RS-232 port.
The standard UARTs for DOS and Windows machines are the National 8250, 16450, and 16550 UART. Newer UARTs are the StarTech 16650 and the Texas Instruments 16750.
8250 : Works well (to 9600/19200) on DOS machines. 16450 : Works well on DOS and some Windows machines to 38400. 16550 : Features 16-byte FIFO buffers. The "standard". 16650 : Features 32-byte FIFO buffers. Pin compatible with 16550. 16750 : Features 64-byte FIFO buffers.
The purpose of the UART is:
(1) To convert bytes from the CPU (Central Processing Unit), into a serial format by adding the necessary start, stop, and parity bits to each byte before transmission, and to then transmit each bit at the correct baud rate.
The first bit is always the start bit, followed by 5 to 8 data bits, (optionally) followed by the parity bit, followed by the stop bit or bits.
(2) To convert the incoming stream (at a specified baud rate) of serial bits into bytes by removing the start, stop, and parity bit before being made available to the CPU.
The UART is capable of operating in one of two modes, 'polled' and 'interrupt driven'. The serial communications functions in the BIOS use the polled method. In this approach, the CPU is typically in a loop asking the UART over and over again if it has a byte ready. If its does, the polling code returns the byte. But, if the next byte comes in before the polling code is executing again, then that byte is lost.
In the interrupt driven approach, when a byte is received by the UART, an 'Interrupt Service Routine' (ISR) is executed immediately, suspending temporarily whatever is currently executing. The ISR then moves the byte to a buffer so that the application program can later read it.
The 16550 can be programmed so that an (RX) interrupt is not triggered until 4 (or 8 or 14) bytes have been received, while the 16650 can be triggered at up to 30 bytes, and the 16750 can be triggered at up to 56 bytes. This can significantly reduce the CPU processing time, since 14 (or 30 or 56) bytes can be moved at once.
Transmitted bytes are queued up awaiting transmission. When a byte is moved from the UART transmitter holding register to the UART transmitter shift register, an interrupt is generated and the next byte is taken from the library transmitter buffer by the ISR and written to the UART holding register.
Up to 16 bytes can be written at once to the transmitter FIFO buffer while processing one transmitter interrupt if an 16550 UART is used, while the 16650 can write up to 32 bytes at once, and the 16750 can write up to 64 bytes.
A modem is used to extend the distance over which you may communicate. Without a modem, your RS-232 cable is limited to a maximum of approximately 50 feet. But with a modem, you can communicate literally around the world.
Two modems can communicate over a telephone line only if they are both using the same signaling frequencies and modulation, which are determined by the the modem standards used. Modem standards can be divided into three sets: (1) speed, (2) data compression used, and (3) error control.
The Bell standards (103 & 212A) are those of AT&T. The CCITT (The International Consultative Committee for Telephone and Telegraph) standards are designated as 'V. '.
Speed Bell 103 : 300 baud. Bell 212A : 1200 baud. V.21 : 300 baud. V.22bis : 1200 & 2400 baud. V.32 : 4800 & 9600 baud. V.32bis : 4800, 7200, 9600, 12000, and 14400 baud. V.34 : V.32bis plus 16800, 19200, 21600, 24000, 26400, and 28800 baud. V.34bis : V.34 plus 31200 and 33600 baud. USR X2 : US Robotics 56KB standard (33.6 KB uploads). K56flex : Rockwells 56KB standard (33.6 KB uploads). V.90 : 56KB standard. Data Compression MNP 5 : Microcom Networking Protocol (proprietary). V.42bis : International data compression standard. Error Control MNP 2,3,4 : Three level error correction (public domain). V.42 : International error correction standard.
With modems using data compression, the modem to modem connection will run at various speeds depending on the quality of the line. The computer to modem connection will be at a fixed baud rate. Therefore, a protocol (flow control) is necessary to synchronize the data flow between a modem and the computer to which it is connected. Refer to your modem manual for information on flow control protocols supported.
Two flow control protocols are used by most all modems which require flow control. Software flow control is called 'XON/XOFF' (other software flow control character pairs are defined but operate the same as XON/XOFF) and hardware flow control is called 'RTS/CTS'. Most modems which require flow control enable hardware flow control by default.
In XON/XOFF (software) flow control, the computer suspends transmitting data if it receives a XOFF character (13 hex) from the modem, and continues transmitting when it receives a XON character (11 hex). Similiarly, the computer can signal the modem not to send any more data by transmitting a XOFF to it, and can tell the modem to continue transmission be sending a XON.
In RTS/CTS (hardware) flow control, the RTS line is used by the computer to signal the modem , while the CTS line is used by the modem to signal the computer. The RTS line is set OFF by the computer to tell the modem to suspend transmission, and set to ON to tell the modem to continue transmission. The CTS line is set to OFF by the modem to tell the computer to stop transmitting, and set to ON to tell the computer to continue transmitting.
Given the choice, always choose hardware flow control over software flow control so that all data transmission is transparent. If hardware flow control is not the default (which it almost always is), you should modify your modem initialization string to turn hardware flow control on.
If an application uses a modem (as opposed to using a null modem cable), then it should always send an initialization string to the modem. Communication programs such as PROCOMM and TELIX always send such a string automatically as soon as they start up.
The particular initialization string depends on the make of your modem. For most modems, the following string (followed by a carriage return) should work:
AT E1 S7=60 S11=60 V1 X1 Q0 S0=0
Recall that the modem must be in command mode in order to send AT commands. To force command mode, send the character string "+-+" (without the quotes), preceeded by 1 second of silence, and followed by one second of silence.
Refer to your Modem User's Guide for a full discussion of these commands. A brief description is as follows:
AT Modem attention command. E1 Modem will echo what you send to it. S7=60 Wait 60 seconds for carrier and/or dial tone. S11=60 Use 60 milliseconds for tone dialing duration & spacing. V1 Display result code as words (not numbers). X1 Use the extended result message (CONNECT XXXX) set. Q0 Modem displays result codes. S0=0 Do not answer RING.If the application will answer incoming calls, set the S0 register to the ring on which to automatically answer.
Most modems can be set to the 'factory default' by transmitting
To be sure, the modem is the most common serial device. But there are many other serial devices such as digitizing tablets, scanners, digital cameras, numerical control machines, card readers, panel displays, etc.
Some serial devices (such as modems) use hardware (RTS/CTS) flow control, but DTR/DSR flow control and software (XON/XOFF) flow control are also common.
If you are writing a program to communicate with a serial device, keep in mind the following:
(1) Always set DTR and RTS. Many serial devices "play dead" if DTR is not set.
(2) You may need to add a small time delay (0.25 sec) between transmitted characters. This can be reduced or eliminated once everything is working.
(3) Make sure that your receive buffer is sufficently large. You want to avoid buffer overflow.
More details on UARTs, including RS232 signals and UART register definitions, can be obtained from
UART data sheets can be obtained from:
16550 National 16650 Exar 16750 Texas Instruments
WSC4C WIN C/C++ Windows Standard Comm Library for C/C++ WSC4D WIN Delphi Windows Standard Comm Library for Delphi WSC4VB WIN Visual Basic Windows Standard Comm Library for VB WSC4PB WIN Power Basic Windows Standard Comm Library for Power Basic WSC4FP WIN FoxPro Windows Standard Comm Library for FoxPro WSC4DB WIN FoxPro Windows Standard Comm Library for dBase WSC4XB WIN FoxPro Windows Standard Comm Library for Xbase PCL4C DOS C/C++ Personal Comm Library for C/C++ PCL4P DOS Pascal Personal Comm Library for Pascal PCL4VB DOS Visual Basic Personal Comm Library for Visual Basic PCL4PB DOS Power Basic Personal Comm Library for Power Basic.
Our libraries have also been sucessfully used from Excel, Access, FoxPro, Clarion, PowerBuilder, dBase, Fortran, and Cobol.
All products can be found at Products Page