how to detect a buffer over run on serial port in linux using c++

元气小坏坏 提交于 2019-12-18 17:57:33

问题


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

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/3155213/how-to-detect-a-buffer-over-run-on-serial-port-in-linux-using-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!