如何使用 c++ 检测 Linux 中串口上的缓冲区溢出
我有一个大问题。目前我正在通过以下钩子访问串行端口:
fd = open( "/dev/ttyS1", O_RDWR | O_NOCTTY )
然后我使用以下代码块从中读取内容,
i = select( fd + 1, &rfds, NULL, NULL, &tv )
...
iLen = read( fd, buf, MAX_PACKET_LEN )
问题是在读取之前,我需要检测是否存在任何缓冲区溢出。串行端口级别和内部 tty 翻转缓冲区。
我们尝试了 cat /proc/tty/driver/serial 但它似乎没有列出溢出(请参见下面的输出)
1: uart:16550A port:000002F8 irq:3 tx:70774 rx:862484 fe:44443 pe:270023 brk:30301 RTS|CTS|DTR
I have a big problem. At present I am accessing a serial port via the following hooks:
fd = open( "/dev/ttyS1", O_RDWR | O_NOCTTY )
then I read from it using the following chunk of code
i = select( fd + 1, &rfds, NULL, NULL, &tv )
...
iLen = read( fd, buf, MAX_PACKET_LEN )
the problem is that before I read, I need to detect if there were any buffer overruns. Both at the serial port level and the internal tty flip buffers.
We tried cat /proc/tty/driver/serial
but it doesn't seem to list the overruns (see output below)
1: uart:16550A port:000002F8 irq:3 tx:70774 rx:862484 fe:44443 pe:270023 brk:30301 RTS|CTS|DTR
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据内核源代码,您应该使用 TIOCGICOUNT ioctl。第三个 ioctl 参数应该是指向以下结构的指针,在
中定义:但是我不知道是否每个驱动程序都检测到所有条件。
According to the kernel sources, you should use the TIOCGICOUNT ioctl. The third ioctl argument should be a pointer to the following struct, defined in
<linux/serial.h>
:I don't know if every driver detect all conditions however.
Dark Templer,
您的串行驱动程序应该更新 icount.frame/overrun 错误。
Serial_core.h 中的 struct uart_port 具有成员 struct uart_icount,应根据收到的中断在平台串行设备驱动程序中更新该成员。
Dark Templer,
Your serial driver should update the icount.frame/overrun errors.
struct uart_port in serial_core.h has member struct uart_icount, which should be updated in platform serial device driver as per interrupts received.