如何使用c ++检测Linux中串行端口上运行的缓冲区 [英] how to detect a buffer over run on serial port in linux using c++

查看:23
本文介绍了如何使用c ++检测Linux中串行端口上运行的缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大问题.目前我正在通过以下钩子访问串口:

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 )

问题是在我阅读之前,我需要检测是否有任何缓冲区溢出.在串行端口级别和内部 tty 翻转缓冲区.

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.

我们尝试了 cat/proc/tty/driver/serial 但它似乎没有列出溢出(见下面的输出)

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

推荐答案

根据内核源码,你应该使用TIOCGICOUNT ioctl.第三个 ioctl 参数应该是指向以下结构的指针,在 <linux/serial.h> 中定义:

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> :

/*
 * Serial input interrupt line counters -- external structure
 * Four lines can interrupt: CTS, DSR, RI, DCD
 */
struct serial_icounter_struct {
        int cts, dsr, rng, dcd;
        int rx, tx;
        int frame, overrun, parity, brk;
        int buf_overrun;
        int reserved[9];
};

我不知道是否每个驱动程序都检测到所有情况.

I don't know if every driver detect all conditions however.

这篇关于如何使用c ++检测Linux中串行端口上运行的缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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