如何在 gnu 屏幕中切换 CR/LF?
我正在使用屏幕从串行控制台读取文本。问题是输出似乎只有换行符 \n 而没有回车符 \r,所以显示看起来像这样......
Line1
Line2
Line3
我想知道是否有任何补丁可以解决这个问题?
I'm using screen to read the text from a serial console. The problem is the output seems to only have newline \n but not carriage return \r, so the display looks like this...
Line1
Line2
Line3
I wonder if there is any patch to fix this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
onlcr
用于翻译outgoing newlines 到 carriage rreturns。stty -F /dev/ttyS0 inlcr
会将传入的换行符转换为回车符。您可以在启动屏幕后从另一个终端运行它,以避免屏幕在启动时可能进行的任何重置。然而不幸的是,这只会改变问题。然后你将只得到返回值而没有换行符。需要的是一个选项来附加传入的换行符,以便终端接收
\n\r
,这就是串行设备应该 首先有输出。似乎有一个 onlret 选项可以对传出数据执行此操作,但没有在本例中我们似乎需要的 inlret 选项。我遇到了完全相同的问题(尽管使用 picocom),并且我已经连续几天在谷歌上断断续续地搜索,试图找到标准的解决方案,但似乎没有人有解决办法。有许多串行设备仅输出
\n
并且根本无法输出\r\n
我拒绝相信所有这些设备仅属于两个linux用户。什么给!?onlcr
is for translating outgoing newlines to carriage returns.stty -F /dev/ttyS0 inlcr
will translate incoming newlines to carriage returns. You can run that from another terminal after starting screen to avoid any resetting that screen may do on startup. Unfortunately however, this will only change the problem. You'll then get only returns and no newlines.What is needed is an option to append a return to an incoming newline so that the terminal receives
\n\r
, which is what the serial device should have output in the first place. There seems to be anonlret
option to do this for outgoing data, but noinlret
option as we would seem to need in this case.I have the exact same problem (using picocom though) and I've been googling off and on for days trying to find the standard fix, but no one seems to have one. There are a number of serial devices out there which only output
\n
and simply can't be made to output\r\n
and I refuse to believe that all of them belong to only two linux users. What gives!?如果您使用 pyserial 附带的 miniterm.py 程序,它会将换行符解释为 crlf。它不是功能最齐全的终端仿真器,但对于与简单的串行设备交互,它可以完成工作。
使用语法(在 OSX 上):
将 XXXXXX 替换为系统上出现的任何设备。
If you use the miniterm.py program that comes with pyserial it will interpret newlines as crlf. It is not the most fully-featured terminal emulator but for interacting with simple serial devices it gets the job done.
Usage syntax (on OSX):
Replace XXXXXX with whatever the device comes up on your system as.
尝试
stty onlcr
。手册页表示它将在输出时将换行符转换为回车符/换行符对,这似乎成为你所需要的。
Try
stty onlcr
.The man page says it will translate newlines to carriage return / newline pairs on output, which seems to be what you need.
在我的例子中有效: stty -F /dev/ttyACM0 -icrnl
因为序列被隐式设置为将 CR 转换为 NL。该命令将其设置回来。请注意
icrnl
前面的减号字符。In my case worked:
stty -F /dev/ttyACM0 -icrnl
Because the serial was implicitly set to translate CR to NL. This command set it back. Notice the minus character preceding
icrnl
.