The goal is to connect to an embedded
device using serial
interface.
So far, I've used:
stty -F /dev/ttyS2 115200 cs8 ixoff
socat readline,history=/etc/socat.history /dev/ttyS2,raw,echo=0
And it works excellent, but then I discovered that there are some options during system boot
that require you to press a single key without pressing enter
, and readline
fails there. So my idea was to bind the ttyS2
to cons0
, but then I discovered multiple problems, such as inability to quit (ctr+c
, ctr+q
ctr+]
and even esc
doesn't work), backspace
and delete
do not work, letters are typed twice, etc. So after some trial and error, I came up with this:
socat /dev/cons0,raw,echo=0,crnl /dev/ttyS2,raw,echo=0,escape=0x03,crnl
raw
on both sides allows a singlekey press
to trigger aboot option
echo=0
on both sides preventskey press
doublingcrnl
on both sides prevententer
key press
doublingescape=0x03
allows me toquit
the thing by pressingctr+c
The problem is, when I quit, my cons0
is all f****d up, as if it somehow preserved the raw,echo=0,crnl
settings. I know this problem is probably too specific for my scenario, but I just need a simple way to send keystrokes to serial as I would with putty
(which is not available on my platform). I am using socat
because it is extremely lightweight, does not require any aditional libraries, and because the shown commands are a part of the greater script that uses expect
.
Any ideas and suggestions are greatly appreciated.
As Austin Phillips says, you can use
stty sane
to recover......but what is even better is that you can (probably) append it to your socat command as
socat xxxxx ; stty sane
and have the recovery be automatic when you quit with ctrl-c.Thanks, that worked for me! I just want to point out that the script should not rely on "static" console identification, because when
expect
spawns the script, it is going to have a completely differenttty
, therefor:edit:
nonblock
also solved the "enter" problem