【问题标题】:how to detect a buffer over run on serial port in linux using c++如何使用c ++检测Linux中串行端口上运行的缓冲区
【发布时间】:2010-07-01 05:04:45
【问题描述】:

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

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

【问题讨论】:

    标签: linux serial-port


    【解决方案1】:

    根据内核源代码,您应该使用 TIOCGICOUNT ioctl。第三个 ioctl 参数应该是指向以下结构的指针,在 <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];
    };
    

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

    【讨论】:

    • 嘿,谢谢你,但我们的系统似乎没有更新“overrun”和“buf_overrun”字段。知道为什么吗?
    【解决方案2】:

    黑暗神庙,

    您的串行驱动程序应该更新 icount.frame/overrun 错误。

    serial_core.h 中的struct uart_port 有成员struct uart_icount,应根据收到的中断在平台串行设备驱动程序中更新。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多