Linux 如何在 gnu 屏幕中切换 CR/LF?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7812142/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to toggle CR/LF in gnu screen?
提问by Patrick
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...
我正在使用 screen 从串行控制台读取文本。问题是输出似乎只有换行符\n但没有回车符\r,所以显示看起来像这样......
Line1
Line2
Line3
I wonder if there is any patch to fix this issue?
我想知道有没有补丁可以解决这个问题?
采纳答案by Frédéric Hamidi
回答by tacos
onlcr
is for translating outgoingnewlines to carriage returns.
onlcr
是用于转换øutgoing ÑEW升分级表到Çarriage řeturns。
stty -F /dev/ttyS0 inlcr
will translate incomingnewlines 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.
stty -F /dev/ttyS0 inlcr
将传入的换行符转换为回车。您可以在启动 screen 后从另一个终端运行它,以避免在启动时重置该屏幕。然而不幸的是,这只会改变问题。然后你只会得到回报而没有换行符。
What is needed is an option to appenda return to an incoming newline so that the terminal receives \n\r
, which is what the serial device shouldhave output in the first place. There seems to be an onlret
option to do this for outgoing data, but no inlret
option as we would seem to need in this case.
需要的是一个选项,将返回附加到传入的换行符,以便终端接收\n\r
,这是串行设备首先应该输出的内容。似乎有一个onlret
选项可以为传出数据执行此操作,但没有inlret
我们在这种情况下似乎需要的选项。
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!?
我有完全相同的问题(尽管使用 picocom)并且我一直在谷歌上搜索并试图找到标准修复程序好几天,但似乎没有人有一个。有许多串行设备只能输出\n
而根本无法输出\r\n
,我拒绝相信它们都只属于两个 linux 用户。是什么赋予了!?
回答by Peter E.
If you use the miniterm.pyprogram 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.
如果您使用pyserial 附带的miniterm.py程序,它会将换行符解释为 crlf。它不是功能最齐全的终端仿真器,但对于与简单的串行设备进行交互,它可以完成工作。
Usage syntax (on OSX):
使用语法(在 OSX 上):
miniterm.py /dev/tty.usbserial-XXXXXX 115200
Replace XXXXXX with whatever the device comes up on your system as.
将 XXXXXX 替换为系统上出现的任何设备。
回答by jejdacz
In my case worked: stty -F /dev/ttyACM0 -icrnl
在我的情况下工作: 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
.
因为串行被隐式设置为将 CR 转换为 NL。此命令将其重新设置。注意前面的减号icrnl
。