The stty utility sets or reports on terminal characteristics for the device that is its standard input. If no options or operands are specified, it reports the settings of a subset of characteristics as well as additional ones if they differ from their default values. Otherwise it modifies the terminal state according to the specified arguments.
[root@rh9 root]# stty -a < /dev/ttyS0
speed 9600 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <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
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
If you are troubleshooting two devices (one working and one not) then compare the characteristics of both devices with your process running on them. Then modify your application to set the correct characteristics for the device.
If you application does not have the ability to enable/disable terminal characteristics then you can perform this manually by opening the device with a process and then using the stty command to set the characteristics. Note: if the devices closes then the host system will set the characteristics to default setting.
example, we use the cat command to keep the port open indefinitely then use stty
[root@rh9 root]# (cat > /dev/null) < /dev/ttyS0 &
[root@rh9 root]# stty raw cs7 < /dev/ttyS0
See your man pages on stty for further details on your Unix operating system.
Some important characteristics:
Enable (disable) parity generation and detection.
Select odd (even) parity.
cs5 cs6 cs7 cs8
Select character size, if possible.
Set terminal baud rate to the number given, if possible. If the baud rate is set to zero, modem control is no longer asserted.
Assume a line without (with) modem control.
Enable (disable) RTS/CTS flow control.
Enable (disable) START/STOP output control. Output from the system is stopped when the system receives STOP and started when the system receives START, or if ixany is set, any character restarts output.
Request that the system send (not send) START/STOP characters when the input queue is nearly empty/full.
Allow any character (allow only START) to restart output.
Echo back (do not echo back) every character typed.
Enable (disable) canonical input (ERASE and KILL processing).
raw (-raw or cooked)
Enable raw input and output (no ERASE, KILL, INTERRUPT, QUIT, EOT, or output post-processing). raw is equivalent to the settings: cs8 -parenb -isig -icanon -xcase -opost -inpck min 1 time 1
TTY in canonical mode
In canonical mode, characters are read from the device and processed before being returned. This processing translates kill and erase characters. Characters are not returned until a new line (NL), end of file (EOF), or end of line (EOL) is read, which means that characters are returned a line at a time. Canonical mode is usually associated with terminals.
TTY in raw mode
In raw mode, characters are read and returned as is; that is, without being processed. Reading from a TTY device in raw mode is faster than reading from a TTY device in canonical mode. In the interest of efficiency, raw mode should be used when characters do not need to be canonically processed.