delays, latency and timeout

36 views
Skip to first unread message

Alessandro Manicone

unread,
Jan 10, 2018, 5:58:14 AM1/10/18
to libmodbus
Hi,
I'm using libmodbus on a custom board with the following characteristics:
- ARM9 processor, 400MHz 256MB RAM
- Linux version: Linux imx28evk 2.6.35.3-maintain+gb3912bb #2 PREEMPT Mon Mar 20 09:11:16 GMT 2017 armv5tejl GNU/Linux
- libmodbus (3.1.4) dynamically linked to a Qt application

I've been noticing so far a delay in each single modbus operation. I measure the time using Linux clock, and the time between each call appears to be up to 60 ms, and sometimes 80.
The application gets blocked for such long time, that's sounds me very odd.
If I set the timeout to 10ms the functions exit with timeout error or invalid data.
A timeout which seems good for an error free communication is 100ms at the moment.
The code doesn't do anything than write 2 registers in an infinite loop, I get the Linux time before and after the write call and subtract the millisecs.

I know libmodbus is quite popular and I also used it in the past without these timing issues.
I can confirm that it's not related to the slave because the same slave reply quicker with other applications. I simulated a slave on my PC and I gets the same timing, and libmodbus is successfully used on a PC application and communicates with the slave without any problem, so the issue is definitely on the board side.

I'd like to know if there are known timing issues related to specific architectures, hardware, Qt environment, and so on.
Has anyone got any idea?

Thank you very much,
Alessandro

Patrick Boettcher

unread,
Jan 10, 2018, 6:33:12 AM1/10/18
to Alessandro Manicone, libm...@googlegroups.com
On Wed, 10 Jan 2018 02:58:14 -0800 (PST)
Alessandro Manicone <alessandr...@gmail.com> wrote:
> The code doesn't do anything than write 2 registers in an infinite
> loop, I get the Linux time before and after the write call and
> subtract the millisecs.

If you are measuring 10 writes does the timing evolve linearly? Do
you see the same when doing reads?

> I can confirm that it's not related to the slave because the same
> slave reply quicker with other applications. I simulated a slave on
> my PC and I gets the same timing, and libmodbus is successfully used
> on a PC application and communicates with the slave without any
> problem, so the issue is definitely on the board side.

Is the board communication done with TCP or RTU? If it is TCP, how is
the Ethernet-port connected to the system? Via USB?

> I'd like to know if there are known timing issues related to specific
> architectures, hardware, Qt environment, and so on.
> Has anyone got any idea?

From what I saw, libmodbus is using the lowest C system level functions
such as connect (for tcp), open, read(2) and write(2). The problem most
likely does not come from libmodbus.

regards,
--
Patrick.



Alessandro Manicone

unread,
Jan 10, 2018, 7:19:03 AM1/10/18
to Patrick Boettcher, libm...@googlegroups.com
HI All,
A quick update:

A standard C application like this

while(1)
    {
        clock_gettime(CLOCK_MONOTONIC, &spec);
        modbus_write_register(mb, 7218, 1000);
        clock_gettime(CLOCK_MONOTONIC, &spec);
    }

gives me 5ms as elapsed time. So the 2
1-Qt core introduce some latency 
2-The Qt application I used before has got a MASSIVE bug somewhere.

Replying to Patrick:

- The time is not linear and I see the same for readings.
- The board is using modbus TCP, there's no USB in the middle
Reply all
Reply to author
Forward
0 new messages