如何在换行符到达之前读取 tty 设备上的终端输入? [英] How can I read the terminal input on a tty device before a newline arrives?

查看:70
本文介绍了如何在换行符到达之前读取 tty 设备上的终端输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 open()、tcget/setattr()、read() 使用嵌入式 linux (angstrom) 读取串行设备.我可以很好地读写数据.但是,我正在阅读的设备会显示一个不以换行符结尾的提示.这意味着我无法阅读提示,直到我导致设备发送一些其他输出,最后有一个换行符.基本上,我知道提示字符串(COM3>")位于 tty 缓冲区中,等待设备发送换行符.read() 在换行符到达之前不会访问COM3>"提示字符串.有什么办法可以改变强制read()在换行符到来之前获取缓冲区中的数据吗?

I am reading a serial device using embedded linux (angstrom) using open(), tcget/setattr(), read(). I can read and write data just fine. However, the device I am reading displays a prompt that is not terminated with a newline. This means I can't read the prompt until after I cause the device to send some other output that has a newline at the end. Basically, I know the prompt string ("COM3>") is sitting in the tty buffer waiting for the device to send a newline. read() won't access the "COM3>" prompt string until the newline arrives. Is there any way to change the force read() to get the data in the buffer before the newline arrives?

谢谢

推荐答案

在规范模式下,默认情况下,输入是行缓冲的.

In canonical mode, which is the default, input is line-buffered.

您可能想要的是使用 cfmakeraw() 将终端设置为原始"模式,这将(除其他外)禁用规范模式.

What you probably want is to set the terminal into "raw" mode with cfmakeraw(), which will (among other things) disable canonical mode.

有关详细信息,请参阅 tcsetattr() 手册页.

See the tcsetattr() man page for more information.

这篇关于如何在换行符到达之前读取 tty 设备上的终端输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆