Page 1 of 1

How to increase the serial recieve buffer size in C linux

Posted: Thu Sep 06, 2018 1:01 pm
by zoalsay
Hi All,
I am attaching a sensor( recognized as: /dev/ttyUSB0) that continuously send data to raspberry pi 3 B.
I want to increase the UART (serial) USB receive input buffer to be able to store data more than the current (4095); is there anyway to do this in C under Linux?
I used to do it in C under windows using:
Status = SetupComm(hComm, 51200000,4096);
Is there any equivalent to this command in Linux?
Best Regards,

Re: How to increase the serial recieve buffer size in C linux

Posted: Thu Sep 06, 2018 1:25 pm
by joan
Do you know what the size defaults to on Linux? I always assumed it was a 16k bytes buffer but that may just be a faulty memory.

Re: How to increase the serial recieve buffer size in C linux

Posted: Thu Sep 06, 2018 1:29 pm
by jamesh
Not found one. Which is odd! Seems to, on the whole, default to PAGE_SIZE which is 4096.

A better way of dealing with this is to have your own buffer, and transfer data from the serial buffer to that using another thread. That way you can have whatever buffer size you need and can leave the serial driver to do it's job.

Re: How to increase the serial recieve buffer size in C linux

Posted: Thu Sep 06, 2018 1:40 pm
by zoalsay
joan wrote:
Thu Sep 06, 2018 1:25 pm
Do you know what the size defaults to on Linux? I always assumed it was a 16k bytes buffer but that may just be a faulty memory.
I am checking the available bytes in buffer using:
ioctl(hCom, FIONREAD, &avaialble_bytes);
It never exceeds 4095, I understood it is 4095 bytes.

Re: How to increase the serial recieve buffer size in C linux

Posted: Thu Sep 06, 2018 1:43 pm
by zoalsay
jamesh wrote:
Thu Sep 06, 2018 1:29 pm
Not found one. Which is odd! Seems to, on the whole, default to PAGE_SIZE which is 4096.

A better way of dealing with this is to have your own buffer, and transfer data from the serial buffer to that using another thread. That way you can have whatever buffer size you need and can leave the serial driver to do it's job.
Is there anyway change the driver default setting in Linux?

Re: How to increase the serial recieve buffer size in C linux

Posted: Thu Sep 06, 2018 2:03 pm
by jamesh
zoalsay wrote:
Thu Sep 06, 2018 1:43 pm
jamesh wrote:
Thu Sep 06, 2018 1:29 pm
Not found one. Which is odd! Seems to, on the whole, default to PAGE_SIZE which is 4096.

A better way of dealing with this is to have your own buffer, and transfer data from the serial buffer to that using another thread. That way you can have whatever buffer size you need and can leave the serial driver to do it's job.
Is there anyway change the driver default setting in Linux?
As I said, not that I have found. You could perhaps rebuild the kernel with a larger buffer size. Not sure which particular uart drivers we use though.