@mbs38 you realize that you have 5ms polling period?
I think that might be too low…My understanding of low level serial communication is a bit limited but here goes. modbus.org: MODBUS over Serial Line - Specification and Implementation guide (p.13 remark) says that inter-frame delay of 1.75ms is recommended with baud rates > 19200. See also this compact answer in stackoverflow on the timings.
Since you have 10 slaves configured, each will product single modbus request-response message (frame) pair, i.e. we should expect poll to take over 1.75ms102 = 35ms. This is with the assumption that there is no delays between bits of the message (the spec recommends 750us=0.75ms for the inter-character time-out). Let’s say each request has 8 bits + RTU frame of 3 bits = 11 bits. With max inter-character delays, that would total to 0.75ms*10 = 7.5ms per message. Since each poll means 20 messages, that amounts to max 150ms of inter-character delays. Summing this up with inter-frame delays we get 185ms (150+35).
So using this logic, poll period of around 35ms is as low as you should go, but with some cases 185ms could be considered the minimum limit (max. inter-character delays).
I might be completely off here (specs are specs – real world is something different, and not sure if I read it correctly), and to be honest have no details how the serial communication has been implemented in the java library openhab uses. I think it uses OS specific bits so this might depend on platform.
- Would the errors disappear if you set poll period to something more conservative, such as 500ms? I do understand that there might be use cases for high poll periods, but at least we can rule out what causes these issues… If that works, perhaps you could try to lower it from there
- You could also try increasing the baud rate (e.g. 115200 which is the maximum the binding supports), if possible with your setup.
Thanks for testing these out…
EDIT: Noticed that the jamod library that is used (actually openhab has its own forked version) for the modbus binding, has this disclaimer under Serial Modbus Implementations section:
The RTU implementation does only support the Master side. It is working by the best effort principle, which means it might not work in a reliable way in a low-lantency real-time context.
The requirement of 5ms poll period might be on the edge I believe
EDIT2: if you check your debug logs closely,
$ grep Sent /tmp/YEHZZbNg.txt
00:59:11.548 [DEBUG] [i.modbus.io.ModbusRTUTransport:77 ] - Sent: 03 02 00 00 00 01 b8 28
00:59:11.571 [DEBUG] [i.modbus.io.ModbusRTUTransport:77 ] - Sent: 0a 01 00 00 00 18 3d 7b
00:59:11.601 [DEBUG] [i.modbus.io.ModbusRTUTransport:77 ] - Sent: 10 02 00 00 00 01 ba 8b
00:59:11.621 [DEBUG] [i.modbus.io.ModbusRTUTransport:77 ] - Sent: 08 01 00 00 00 18 3c 99
you can see that true poll periods are 23ms, 30ms, and 20ms. Perhaps this gives some realistic poll period to try, say 50ms?
EDIT3: In any case, I think even with long polling period, at every poll, many modbus requests are written simultaneously without waiting in-between. I will make a version with configurable inter-request wait period that might help with these issues. In fact, I saw similar approach taken in another modbus library (modbus4j).