Linux serial port reading - can I change the size of the input buffer?

I am writing an application on Ubuntu Linux in C ++ to read data from a serial port. It works successfully with my code calling select() and then ioctl(fd,FIONREAD,&bytes_avail) to find out how many bytes are available until the data is finally received using read() .

My question is this: every time select returns with data, the number of bytes available is reported as 8. I assume that this is the size of the buffer that is set somewhere, and this choice returns a notification to the user when this buffer is full.

I am new to Linux as a developer (but not new to C ++), and I tried to investigate (without success) if you can resize this buffer or really if my assumptions are correct. In my application, time is critical, and I need to get warnings when there is a new byte in the read buffer. Is this possible without delving into the kernel code?

+6
source share
2 answers

You want to use the serial IOCTL TIOCSSERIAL , which allows you to change the depth of the receive buffer and the depth of the send buffer (among other things). The maximum values ​​depend on your hardware, but if the 16550A is in the game, the maximum buffer depth is 14.

You can find code that does something similar to what you want to do here

The original link has deteriorated: http://www.groupsrv.com/linux/about57282.html A new one will have to be done until I write another or find a better example.

+2
source

You can try playing with the VMIN and VTIME values ​​of the c_cc member of the termios structure. Some information here , especially in section 3.2.

-1
source

Source: https://habr.com/ru/post/917000/


All Articles