Serial port

This is an old revision of this page, as edited by Guy Harris (talk | contribs) at 00:22, 12 October 2006 (Hardware: One RS-232 link suffices.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In computing, a serial port is a serial communication physical interface through which information transfers in or out one bit at a time (contrast parallel port). Throughout most of the history of personal computers, data transfer through serial ports connected the computer to devices such as terminals or modems. Mice, keyboards, and other peripheral devices also connected in this way.

A male DE-9connector used for a serial port on an PC style computer.

While such interfaces as Ethernet, FireWire, and USB all send data as a serial stream, the term "serial port" usually identifies hardware more or less compliant to the RS-232 standard, intended to interface with a modem or with a similar communication device.

Hardware

Some computers, such as the IBM PC, used an integrated circuit called a UART, that converted characters to (and from) asynchronous serial form, and automatically looked after the timing and framing of data. Very low-cost systems, such as some early home computers, would instead use the CPU to send the data through an output pin, using the so-called bit-banging technique.

While the RS-232 standard originally specified a 25-pin D-type connector, many designers of personal computers chose to implement only a subset of the full standard: they traded off compatibility with the standard against the use of less costly and more compact connectors (in particular the DE-9 version used by the original IBM PC-AT). Presence of a D-subminiature connector is neither necessary nor sufficient to indicate use of a serial port.

Many models of Macintosh favored the related RS-422 standard, often using German DIN connectors.

In recent years, advanced electronics has made economical higher-speed serial communications possible, so newer serial communication standards such as USB and FireWire have started to supplant RS-232. These make it possible to connect devices that would not have operated feasibly over slower serial connections, such as storage devices, sound devices, and video devices.

Operating systems usually use a symbolic name to refer to the serial ports of a computer. Unix-like operating systems usually label the serial port devices /dev/tty* where * represents a string identifying the terminal device; the syntax of that string depends on the operating system and the device. The Microsoft MS-DOS and Windows environments refer to serial ports as COM1, COM2, etc.

Settings

Software can control a multitude of software settings for serial connections used for asynchronous start-stop communication, most commonly setting speed, number of data bits per character, parity, and number of stop bits per character. One of the simplifications made in such serial bus standards as Ethernet, FireWire, and USB is that many of those parameters have fixed values so that users can not and need not change the configuration; the speed is either fixed or automatically negotiated.

Speed

Serial ports use two-level (binary) signalling, so the data rate in bits per second is equal to the symbol rate in baud. Common bit rates per second for asynchronous start/stop communication are 300, 1200, 2400, 9600, 19200 baud, etc. These rates are based on multiples of the rates for electromechanical teleprinters. The port speed and device speed must match, though some devices may automatically detect the speed of the serial port. Though the RS-232 standard is formally limited to 20,000 bits per second, serial ports on popular personal computers allow settings up to 115,200 bits per second. Not all bit rates are possible with all serial ports. Some special-purpose protocols such as MIDI for musical instrument control, or OBD diagnostics for automobiles, may use serial data rates other than the above series.

The speed includes bits for framing (stop bits, parity, etc.) and so the effective data rate is lower than the bit transmission rate. For example for 8-N-1 encoding only 80% of the bits are available for data (for every eight bits of data, two more framing bits are sent).

Data Bits

The number of data bits can be 5 (for Baudot Code), 6 (rarely used), 7 (for true ASCII), 8 (for any kind of data, as this matches the size of a byte), or 9 (rarely used). 8 data bits are almost universally used in newer applications. 5 or 7 bits generally only make sense with older equipment such as teleprinters.

Most serial communications designs send the data bits within each byte LSB (Least Significant Bit) first. This standard is also referred to as "little endian". Also possible, but rarely used, is "big endian" or MSB (Most Significant Bit) first serial communications (see Endianness).

Parity

Parity is a method of detecting some errors in transmission. Where parity is used with a serial port, an extra data bit is sent with each data character, arranged so that the number of 1 bits in each character, including the parity bit, is always odd or always even. If a byte is received with the wrong number of 1 bits, then it must have been corrupted. If parity is correct there may have been no errors or an even number of errors. A single parity bit does not allow implementation of error correction on each character, and communication protocols working over serial data links may have higher-level mechanisms such as checksums to ensure data validity and request retransmission of data that has been incorrectly received.

The parity of the serial can be set to none (N), odd (O), even (E), mark (M), or space (S). None means that no parity bit is sent at all. Mark parity means that the parity bit is always set to the mark signal condition (logical 1) and likewise space parity always sends the parity bit in the space signal condition. Aside from uncommon applications that use the 9th (parity) bit for some form of addressing or special signalling, mark or space parity is uncommon, as it adds very little error detection information. Odd parity is more common than even, since it ensures that at least one state transition occurs, which makes it more reliable. The most common parity setting, however, is "none", with error detection handled at higher layers of the protocol.

Stop bits

Stop bits are sent at the end of every byte transmitted in order to allow the receiving signal hardware to resynchronise. Electronic devices usually use one stop bit. Occasionally, and especially if slow electromechanical devices are used, such as teleprinters, one-and-one half or two stop bits are required.

Conventional notation

The D/P/S conventional notation specifies the framing of a serial connection. The most common usage on microcomputers is 8/N/1 (8N1). This specifies 8 data bits, no parity, 1 stop bit.

In this notation, the parity bit is not included in the data bits. 7/E/1 (7E1) means that an even parity bit is added to the seven data bits for a total of eight bits between the start and stop bits. If a receiver of a 7/E/1 stream is expecting an 8/N/1 stream, half the possible bytes will be interpreted as having the high bit set.

Flow control

A serial port may use signals in the interface to pause and resume the transmission of data. For example, a slow printer might need to handshake with the serial port to indicate that data should be paused while the mechanism advances a line. Common hardware handshake signals use the RS-232 RTS/CTS, DTR/DSR signal circuits. See the separate article on transmit flow control.

Another method of flow control may use special characters such as XON/XOFF to control the flow of data. The XON/XOFF characters are sent by the receiver to the sender to control when the sender will send data, that is, these characters go in the opposite direction to the data being sent. The XON character tells the sender that the receiver is ready for more data. The XOFF character tells the sender to stop sending characters until the receiver is ready again. If the control characters are part of the data stream, they must be sent as part of an escape sequence to prevent data from being interpreted as flow control. Since no extra signal circuits are required, XON/XOFF flow control can be done on a 3 wire interface.

Software

A virtual serial port is an emulation of the standard serial port. This port is created by special software products which enable extra serial ports in operation system without additional hardware installation (such as expansion cards, etc.). Unlike the standard physical serial port the virtual one can be assigned any name (COM255, VSP33, etc.). It is possible to create unlimited number of virtual serial ports in your PC. The only limitation is the computer performance, as it may require a substantial amount of resources to emulate 255 serial ports.

Virtual serial port emulates all serial port functionality, including Baud rate, Data bits, Parity bits, Stop bits, etc. Additionally it allows controlling the data flow, emulating all signal lines (DTR/DSR/CTS/RTS/DCD/RI) and customizing pinout (only advanced solutions).

Virtual serial port emulation can be useful in case there is a lack of available physical serial ports or they do not meet the current requirements. For instance, virtual serial ports can help you share data between several applications from one GPS device connected to serial port. Another option is to communicate with any other serial devices via internet or LAN as if they are locally connected to computer (Serial-over-Ethernet technology). You can establish connection between two computers or applications via emulated null-modem link. Most of the available virtual serial port emulators are compatible with Windows 9x, Windows NT, Windows 2000, Windows ME, Windows 2003, Windows XP and some of them run under Windows CE, Windows Mobile and Pocket PC.

See also

  • RS-232 This page contains more of the technical details including pin assignments.
  • Virtual Serial Port Describes the more details about virtual serial port technology.
  • Parallel port
  • Teleprinter describes the history of the devices that the serial port was developed to drive.