我想使用 GNU 屏幕来监控这样的串行 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一起使用吗?