bash 我如何在超时时读取 tty 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6713668/
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 i can read tty file with timeout?
提问by Denys Rogovchenko
I have tty device in /dev , where I send AT commands. I want to read line by line and stop reading file after timeout.
我在 /dev 中有 tty 设备,我在那里发送 AT 命令。我想逐行读取并在超时后停止读取文件。
采纳答案by Antti
You can use the program sttyto configure the tty device. To see the settings for terminal /dev/ttyS0, try
您可以使用该程序stty来配置 tty 设备。要查看终端 /dev/ttyS0 的设置,请尝试
stty -a -F /dev/ttyS0
stty -a -F /dev/ttyS0
The default settings regarding timeout are min = 1; time = 0, which means that the reading program will read until at least one character has been read and there is no timeout. Using e.g.
超时的默认设置是min = 1; time = 0,这意味着读取程序将读取直到至少读取一个字符并且没有超时。使用例如
stty -F /dev/ttyS0 min 0 time 10
stty -F /dev/ttyS0 min 0 time 10
the reading program (e.g. cat) will finish reading after one second whether anything has been read or not. The unit for the parameter timeis tenths of a second; you can check out man sttyfor more information.
阅读程序(例如cat)将在一秒钟后完成阅读,无论是否已阅读任何内容。参数单位为time十分之一秒;您可以查看man stty更多信息。

