对原材料串行连接使用socat [英] Using socat for raw serial connection
问题描述
我们的目标是要连接到使用串口
接口的嵌入
设备。
到目前为止,我用:
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
和它的作品很好,但后来我发现,有系统启动
要求您preSS没有pressing一个键中的一些选项输入
和的readline
失败在那里。所以我的想法是绑定 ttyS2
到 cons0
,但后来我发现了多个问题,如无法退出( CTR + C
, CTR + q
CTR +]
,甚至 ESC
不工作),退格键
和删除
做不行,字母输入两次,等于是经过一番摸索,我想出了这一点:
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
-
原材料
两侧允许单个键preSS
来触发引导选项
-
回声= 0
两侧prevents键preSS
翻番 -
crnl
两侧prevent输入
键preSS
翻番 -
逃脱= 0×03
让我退出
的事情由pressing点击率+ C
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
问题是,当我退出,我的 cons0
是f可**** D盘,就好像它在某种程度上preserved的生,回声= 0,crnl
设置。我知道这个问题可能太具体了我的情况,但我只需要一个简单的方法来发送击键序列,因为我将与腻子
(这是不是用我的平台上)。我使用 socat
,因为它是非常轻量级的,不需要任何aditional的图书馆,而且由于显示的命令是使用较大的脚本的一部分期待
。
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
.
任何意见和建议,都大大AP preciated。
Any ideas and suggestions are greatly appreciated.
推荐答案
奥斯汀菲利普斯说,你可以使用 stty的理智
恢复...
As Austin Phillips says, you can use stty sane
to recover...
...但什么是更好的是,你可以(可能)为 socat XXXXX追加到socat命令; stty的理智
,并有复苏是的自动的当您退出CTRL-C
...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.
这篇关于对原材料串行连接使用socat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!