使用 socat 进行原始串行连接 [英] Using socat for raw serial connection

查看:31
本文介绍了使用 socat 进行原始串行连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标是使用 serial 接口连接到 embedded 设备.到目前为止,我使用过:

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

而且效果很好,但后来我发现在 system boot 期间有一些选项要求您按一个键而不按 enterreadline 在那里失败.所以我的想法是把ttyS2绑定到cons0,但是后来发现了多个问题,比如无法退出(ctr+c,ctr+q ctr+] 甚至 esc 都不起作用),backspacedelete 不工作,字母输入两次,等等.所以经过一些试验和错误,我想出了这个:

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 允许单个key press 触发启动选项
  • echo=0两侧防止按键加倍
  • crnl两边防止enter key press加倍
  • escape=0x03 允许我通过按 ctr+c
  • 退出这件事

    • raw on both sides allows a single key press to trigger a boot option
    • echo=0 on both sides prevents key press doubling
    • crnl on both sides prevent enter key press doubling
    • escape=0x03 allows me to quit the thing by pressing ctr+c
    • 问题是,当我退出时,我的 cons0 全部搞砸了,好像它以某种方式保留了 raw,echo=0,crnl设置.我知道这个问题对于我的场景来说可能太具体了,但我只需要一种简单的方法来将击键发送到串行,就像使用 putty (这在我的平台上不可用)一样.我使用 socat 是因为它非常轻量级,不需要任何额外的库,而且显示的命令是使用 expect 的更大脚本的一部分.

      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.

      推荐答案

      正如 Austin Phillips 所说,您可以使用 stty sane 来恢复...

      As Austin Phillips says, you can use stty sane to recover...

      ...但更好的是,您可以(可能)将它作为 socat xxxxx 附加到您的 socat 命令中;stty sane 并在您使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆