Software Flow Control
Software Flow Control
Software flow control is a method of flow control used in computer data links, especially RS-232 serial. It
uses special codes, transmitted in-band, over the primary communications channel. These codes are
generally called XOFF and XON (from "transmit off" and "transmit on", respectively). Thus, "software
flow control" is sometimes called "XON/XOFF flow control". This is in contrast to flow control via
dedicated out-of-band signals — "hardware flow control" — such as RS-232 RTS/CTS.
Representation
For systems using the ASCII character code, XOFF is generally represented using a character or byte with
decimal value 19; XON with value 17.
The ASCII standard does not reserve any control characters for use as XON/XOFF specifically. However,
it does provide four generic "device control" characters (DC1 through DC4). The Teletype Model 33 ASR
adopted two of these, DC3 and DC1, for use as XOFF and XON, respectively. This usage was copied by
others, and is now a de facto standard. The keyboard equivalents of Ctrl + S for XOFF, and Ctrl + Q for
XON, also derive from this usage.
Mechanism
When one end of a data link is unable to accept any more data (or approaching that point), it sends XOFF
to the other end. The other end receives the XOFF code, and suspends transmission. Once the first end is
ready to accept data again, it sends XON, and the other end resumes transmission.
For example, one may imagine a computer sending data to a slow printer. Since the computer is faster at
sending data than the printer can print it, the printer falls behind and approaches a situation where it would
be overwhelmed by the data. The printer reacts to this situation by sending XOFF to the computer, which
temporarily stops sending data. When the printer is again ready to receive more data, it sends XON to the
computer, which starts sending data again.
XOFF/XON can be employed in both directions, for example, two teleprinters connected to each other.
However, software flow control is not without its problems. The most important drawback is that software
flow control is less reliable. Sending XOFF requires at least one character time to transmit, and may be
queued behind already-transmitted data still in buffers. Hardware signals may be asserted almost
instantaneously, and out-of-order.
Finally, since the XOFF/XON codes are sent in-band, they cannot appear in the data being transmitted
without being mistaken for flow control commands. Any data containing the XOFF/XON codes thus must
be encoded in some manner for proper transmission, with corresponding overhead. This is frequently done
with some kind of escape sequence. For printing devices that directly interpret ASCII codes, this is not a
large problem, because the XON and XOFF codes use ASCII "device control" code numbers.
Applications
Software flow control is used extensively by low-speed devices, especially older printers and dumb
terminals, to indicate they are temporarily unable to accept more data. Typically, this is due to a combination
of limited output rate and any buffers being full. Some terminal control packages, such as termcap, employ
"padding" (short delays using millisecond granularity[2]) to allow such equipment sufficient time to perform
the requested actions without the need to assert XOFF.
XOFF/XON are still sometimes used manually by computer operators, to pause and restart output which
otherwise would scroll off the display too quickly.
Terminal emulator software generally implements XOFF/XON support as a basic function. This generally
includes the system console on modern Unix and Linux machines, as well as GUI emulators such as xterm
and the Win32 console.
Robust XON is a technique to restart communication, just in case it was stopped by an accidentally
received XOFF. The receiving unit sends periodic XON characters when it can receive data, and the line is
idle. One common use is by serial printers (like HP LaserJet II) to indicate they are online and ready to
receive data. The XON is sent every 1 to 30 seconds depending on the printer's firmware design.
See also
Ethernet flow control
References
1. Yang, Casper (2009). The Secrets of Flow Control in Serial Communication (https://web.arch
ive.org/web/20220804214055/https://moxa.com.cn/getmedia/2489d383-e47d-4258-94ba-90
75fbeb618f/moxa-the-secrets-of-uart-fifo-tech-note-v1.0.pdf) (PDF). Moxa Tech Note
(1.0 ed.). Moxa Technical Writing Center (published September 30, 2009). Archived from the
original (https://moxa.com.cn/getmedia/2489d383-e47d-4258-94ba-9075fbeb618f/moxa-the-
secrets-of-uart-fifo-tech-note-v1.0.pdf) (PDF) on Aug 4, 2022. Retrieved Aug 4, 2022.
2. "The Termcap Library - Describe Padding" (https://www.gnu.org/software/termutils/manual/te
rmcap-1.3/html_node/termcap_10.html). www.gnu.org.
"HP LaserJet IIP and IIP Plus Printers - Control Panel Keys and Menus" (https://web.archive.
org/web/20060509012616/http://h20000.www2.hp.com/bizsupport/TechSupport/Document.js
p?objectID=bpl06142&locale=en_US). Hewlett-Packard. Archived from the original (http://h2
0000.www2.hp.com/bizsupport/TechSupport/Document.jsp?objectID=bpl06142&locale=en_
US) on May 9, 2006.