Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

I am new to Linux as a developer (but not new to C++) and I have tried to research (without success) if it is possible to change the size of this buffer, or indeed if my assumptions are even true. In my application timing is critical and I need to be alerted whenever there is a new byte on the read buffer. Is this possible, without delving into kernel code?

like image 235
mathematician1975 Avatar asked May 30 '12 11:05

mathematician1975


People also ask

What is serial port buffer size?

The buffer size, in bytes. The default value is 4096; the maximum value is that of a positive int, or 2147483647.

What is serial input buffer?

The input buffer is computer memory allocated by the serial port object to store data that is to be read from the device. When reading data from your device, the data flow follows these two steps: The data read from the device is stored in the input buffer.

How big is the Arduino serial buffer?

The serial receive buffer can hold 64 bytes. The data you send from your computer, to your Arduino, will end up in the serial receive buffer.


2 Answers

You can try to play with the VMIN and VTIME values of the c_cc member of the termios struct. Some info here, especially in the section 3.2.

like image 169
Sbirro Avatar answered Oct 04 '22 18:10

Sbirro


You want to use the serial IOCTL TIOCSSERIAL which allows changing both receive buffer depth and send buffer depth (among other things). The maximums depend on your hardware, but if a 16550A is in play, the max buffer depth is 14.

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

The original link went bad: http://www.groupsrv.com/linux/about57282.html The new one will have to do until I write another or find a better example.

like image 44
JimR Avatar answered Oct 04 '22 19:10

JimR