【问题标题】:GNU Screen terminal line settingsGNU Screen 终端线设置
【发布时间】:2017-04-24 08:28:38
【问题描述】:

我想使用 GNU screen 来监控这样的串行 USB 端口:

$ screen /dev/ttyUSB0 115200

但我需要调整一些终端线路设置。我做了几次尝试,但似乎都没有奏效。例如,要为换行符发送 NL+CR,而不仅仅是 NL,终端行设置为 onlcr。

尝试 1 - 无需任何特殊设置:

$ screen /dev/ttyUSB0 115200
# only sends NL

尝试 2 - 通过屏幕:

$ screen /dev/ttyUSB0 115200,onlcr
# still only sends NL

尝试 3 - 通过 ssty:

$ stty -F /dev/ttyUSB0 onlcr
$ screen /dev/ttyUSB0 115200
# still only sends NL

尝试 4 - 通过两者:

$ stty -F /dev/ttyUSB0 onlcr
$ screen /dev/ttyUSB0 115200,onlcr
# still only sends NL

尝试 5 - 以其他顺序:

$ screen /dev/ttyUSB0 115200,onlcr
# then ctrl+a, ctrl+z to pause the screen session
$ stty -F /dev/ttyUSB0 onlcr
stty: /dev/ttyUSB0: Device or resource busy

在所有情况下,如果我运行 stty 来检查终端线路设置,我会得到:

在运行屏幕之前 - 注意 -onlcr 存在:

$ stty -F /dev/ttyUSB0 
speed 115200 baud; line = 0;
kill = ^H; min = 100; time = 2;
-icrnl -imaxbel
-opost -onlcr
-isig -icanon -echo

更改 stty 设置 - 注意 -onlcr 已消失:

$ stty -F /dev/ttyUSB0 onlcr
$ stty -F /dev/ttyUSB0 
speed 115200 baud; line = 0;
kill = ^H; min = 100; time = 2;
-icrnl -imaxbel
-opost 
-isig -icanon -echo

运行屏幕后 - 注意 -onlcr 又回来了:

$ stty -F /dev/ttyUSB0 
speed 115200 baud; line = 0;
kill = ^H; min = 100; time = 2;
-icrnl -imaxbel
-opost -onlcr
-isig -icanon -echo

就好像 screen 忽略了任何 stty 设置并将它们重置为它自己的默认值。这在我测试过的两台机器上都是一样的; Debain 8.7 和 macOS Sierra 10.12.4

我看过其他人面临类似问题的帖子,但没有一个给出明确的答案。许多人最终推荐了一个替代屏幕的替代品,比如 minicom,但现在我很感兴趣。

stty 设置,比如 onlcr,可以和 screen 一起使用吗?

【问题讨论】:

    标签: gnu-screen stty


    【解决方案1】:

    我刚刚经历了大致相同的过程,只是发现屏幕无论如何都会破坏 stty 设置。这里的一条评论建议更改屏幕源代码: How to toggle CR/LF in gnu screen?

    最后,我很高兴找到了一个更简单的哑终端程序,它允许在命令行上传递 stty 样式的参数: https://github.com/npat-efault/picocom

    它还会在启动时漂亮地打印串行端口设置,以便您轻松检查它们。

    软件包存在于 Debian 衍生发行版 (sudo apt-get install picocom) 中,对于其他发行版来说,编译似乎很简单。一个依赖项是 linenoise 库,可以禁用。

    【讨论】:

      【解决方案2】:

      我处理这个问题的方法是在没有任何特殊终端选项的情况下启动 screen 运行,在您的情况下使用:screen /dev/ttyUSB0 115200,然后让它运行,然后切换到另一个终端窗口并执行 stty 命令那里。

      如果你停止screen,我认为它会以某种方式锁定设备(或者因为你没有使用sudo)。在另一个窗口中,您可以输入sudo stty -F /dev/ttyUSB0 onlcr,这将改变screen 会话的行为。问题是screen 忽略了传递给它的设置,只是以自己的方式配置 tty。您可以键入sudo stty -F /dev/ttyUSB0 -a 以在屏幕运行时从另一个窗口列出设置,然后根据需要更改它们。 (请注意,在 Mac 上,-F 应为小写。)

      如果您只有一个终端窗口,那么这是有问题的,因为将 screen 放在后台并让它运行只会在 shell 和 screen 进程之间混合输入和输出流。

      【讨论】:

        【解决方案3】:

        如果您打开了两个终端窗口,您可以做的另一件事是在没有任何工作时进行低级后备黑客攻击:在一个终端类型 cat /dev/ttyUSB0。然后在另一个设置中使用sudo stty 设置您想要的终端选项。然后,您可以从同一终端通过echo "Some text" > /dev/ttyUSB0 发送命令。您可以通过sedtr 传递cat 命令的输出。例如cat /dev/ttyUSB0 | tr '\r' '\n' 会将收到的任何回车转换为换行符。

        【讨论】:

          猜你喜欢
          • 2011-08-20
          • 1970-01-01
          • 1970-01-01
          • 2011-01-13
          • 2012-08-03
          • 1970-01-01
          • 1970-01-01
          • 2015-12-20
          • 1970-01-01
          相关资源
          最近更新 更多