如何使用 c++ 检测 Linux 中串口上的缓冲区溢出

发布于 2024-09-08 06:34:18 字数 491 浏览 7 评论 0原文

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

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

快乐很简单 2024-09-15 06:34:18

根据内核源代码,您应该使用 TIOCGICOUNT ioctl。第三个 ioctl 参数应该是指向以下结构的指针,在 中定义:

/*
 * 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];
};

但是我不知道是否每个驱动程序都检测到所有条件。

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.

懵少女 2024-09-15 06:34:18

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文