This library allows your Arduino board to communicate via Modbus protocol. The Modbus is a protocol used in industrial automation and also can be used in other areas, such as home automation.
The Modbus generally uses serial RS-485 as physical layer (then called Modbus Serial) and TCP/IP via Ethernet or WiFi (Modbus TCP and Modbus TCP Security).
Modbus standard defines only two types of data: bit value and 16-bit value. All other datatypes should be sent as multiple 16-bit values.
The library is designed to execute calls async way. That is readHreg()
function just sends read request to Modbus server device and exits. Responce is processed (as suun as it's arrive) by task()
. task()
is also async and exits if data hasn't arrive yet.
It's timeout error. Suggestions below are applicable to persistent errors or frequently errors. Rare timeout errors may be normal in some considerations.
Typically is indicates some kind of wiring or hardware problems.
- Check wiring.
- Check that baudrate settings are identical for client and server.
- Try to reduce it to 9600bps.
- Try to use different power source for Arduino device.
- Try to replace RS-485 tranceiver.
- If using Modbus simulator software on PC check the result with alternative software.
It maybe network problems. Use standard procedures as ping
and firewall settings checks for diagnostics.
Some ideas to implement full functional brodge may be taken from this code. Very limited implementation is available in example.
(c)2021 Alexander Emelianov
The code in this repo is licensed under the BSD New License. See LICENSE.txt for more info.