On Fri, 20 Nov 2020 12:08:26 +0100
bservicer <
bser...@fastwebnet.it> wrote:
> Hello,
>
> I am currently developing an equipment based on a Raspberry Pi 4 box
> that must be supervised by a separate controller interfaced in Modbus.
>
> The supervisor is developed by a separate organization which
> initially started by opening and closing the connection on every
> query (say once per second).
> We have faced a problem on such a framework in that every around 1000
> queries (and related open/close activities) we receive a buffer
> overflow error on modbus_receive (). The threshold is not constant in
> time but is always in the range 1005÷1015 queries.
I suggest (based on the number a little less than 1024) that you are
leaking file descriptors (by not closing the connections correctly
somewhere), and so running out of file handles, leading to the
"overflow error".
Each process on Linux has 1024 file descriptors available to it (by
default), one is used each time a file or pseudo-file is opened, and
they are freed and re-used on orderly closure. Three are in use when
your program starts for standard in, standard out and standard error
(although you can close them).
> The buffer passed to the function is already dimensioned to
> MODBUS_TCP_MAX_ADU_LENGTH, and doubling its size does not change this
> behaviour. If the connection is kept open we have no problem in
> maintaining the system active for a long time. Is this an expected
> behavior or can it be fixed someway?
The solution is to make sure that connections are closed (on both
sides) once not in use! But I can't advise on the detail of doing so,
as I have mostly used libmodbus with physical serial ports rather than
TCP (which you imply).
Richard