Table of Contents
stty
stty
gives control over the terminal settings.
To view the running settings, use:
stty -a
Custimization
Defining Control Sequences
The syntax is:
stty <Signal> <Sequence>
Signal
is one of the predefined ones, seestty(1)
.Sequence
maybe anything possible, but a good choice is defining an Escape Sequence (starting with^
).
Example:
stty stop ^Y
NB: Regular sequences are interpreted case sensitive, escape sequences are not!
The ''^S''-Problem
You typed C-s? Terminal hangs? In fact, you sent a stop
signal.
Do not even try, typing reset
does not help.
The output of stty -a
gives some insight:
% stty -a speed 38400 baud; rows 51; columns 89; line = 54; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0; -parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts -ignbrk brkint ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany imaxbel -iutf8 opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke
The values for stop
and start
are relevant here:
start = ^Q; stop = ^S;
Therefore, typing C-q should bring things back to normal.
Serial Terminal Baud Rate
stty
can set the terminal's baud rate and it receives feedback whether the
value was accepted. This may be used to find out what max baud rate a serial
port supports. A simple script could loop over:
# stty -F /dev/ttyX <value>
checking the return value. With regular serial ports, max speed is typically 115200baud. USB-serial-adapters may do more, relevant with some OBD2-adapters for car diagnostics.
Standard baud values are found in /usr/include/asm-generic/termbits.h and
/usr/include/asm-generic/termbits-common.h as defines with name B<value>
:
#define B0 0x00000000 /* hang up */ #define B50 0x00000001 #define B75 0x00000002 #define B110 0x00000003 #define B134 0x00000004 #define B150 0x00000005 #define B200 0x00000006 #define B300 0x00000007 #define B600 0x00000008 #define B1200 0x00000009 #define B1800 0x0000000a #define B2400 0x0000000b #define B4800 0x0000000c #define B9600 0x0000000d #define B19200 0x0000000e #define B38400 0x0000000f #define B57600 0x00001001 #define B115200 0x00001002 #define B230400 0x00001003 #define B460800 0x00001004 #define B500000 0x00001005 #define B576000 0x00001006 #define B921600 0x00001007 #define B1000000 0x00001008 #define B1152000 0x00001009 #define B1500000 0x0000100a #define B2000000 0x0000100b #define B2500000 0x0000100c #define B3000000 0x0000100d #define B3500000 0x0000100e #define B4000000 0x0000100f