串行通信规范模式非阻塞NL检测 [英] Serial Communication Canonical Mode Non-Blocking NL Detection

查看:38
本文介绍了串行通信规范模式非阻塞NL检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过串行端口从 Linux 嵌入式设备向某些启用串行的固件发送命令.为了便于调试和简单,我们使用以换行符终止的 ascii 人类可读命令.这里使用规范模式是否合适,还是规范模式通常为交互式终端保留?我在网上找到的例子都使用原始模式.

I am sending commands over a serial port from a Linux embedded device to some serial enabled firmware. For easy debugging and simplicity we are using ascii human-readable commands terminated by newlines. Is it appropriate to use canonical mode here, or is canonical mode usually reserved for interactive terminals? The examples I find online all use raw mode.

特别是在规范模式下,我如何在不阻塞的情况下检查整行是否可供阅读.

In particular, in canonical mode, how do I check without blocking if an entire line is available for reading.

推荐答案

这里使用canonical模式是否合适,还是canonical模式通常是为交互终端保留的?

Is it appropriate to use canonical mode here, or is canonical mode usually reserved for interactive terminals?

是的,您可以使用规范模式,但您需要根据您的情况配置 termios 界面.
默认 termios 配置用于交互式终端,因此应禁用回显输入等功能.
由于您的设备不太可能发送退格和删除字符,因此可以忽略此类功能.

Yes, you can use canonical mode, but you will need to configure the termios interface for your situation.
The default termios configuration is for an interactive terminal, so features such as echoing the input should be disabled.
Since your device is unlikely to send the backspace and delete characters, such features can be ignored.

我在网上找到的例子都使用原始模式.

The examples I find online all use raw mode.

似乎有些专家"不知道终端的规范模式存在.
请参阅从 c 中的串行端口读取中断行 .

Seems like there are some "experts" that are not aware that canonical mode for terminals exists.
See the comments to reading from serial port in c breaks up lines .

有关(阻塞)规范模式的示例,请参阅 这个答案(请注意,还有另一个专家评论"告诉 OP 他无法阅读行).

For an example of (blocking) canonical mode, see this answer (note that there's another "expert comment" telling the OP that he cannot read lines).

特别是在规范模式下,我如何在不阻塞的情况下检查整行是否可供阅读.

In particular, in canonical mode, how do I check without blocking if an entire line is available for reading.

您可以使用 select().
手册 页面暗示支持对终端设备进行规范读取:

You could use select().
The man page implies that a canonical read of a terminal device is supported:

将监视 readfds 中列出的文件描述符以查看字符是否可供读取(更准确地说,查看读取是否不会阻塞 ...)

The file descriptors listed in readfds will be watched to see if characters become available for reading (more precisely, to see if a read will not block ...)

当 timeval 结构的两个字段都为零时,则 select() 不会阻塞并立即返回.

When both fields of the timeval structure are zero, then select() will not block and returns immediately.

这篇关于串行通信规范模式非阻塞NL检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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