Use Modbus with your Arduino.
Using TCP or RS485 shields, like the MKR 485 Shield. This library depends on the ArduinoRS485 library.
This library is based on libmodbus, modifications were made to the lower level RS485 and TCP layers to use Arduino Serial/RS485 and Client API’s. Then an Arduino friendly API was added on top.
For more information about this library please visit us at https://www.arduino.cc/en/ArduinoModbus/ArduinoModbus
This library is RTU only implementation of Modbus with a tweak to transmission initiation functions to make sure that proper delays, based on current port speed, are applied between the moment, when DE/~RE pin of RS485-to-UART module is set to DE=HIGH/~RE=HIGH (write mode), and the moment, when actual write to UART Serial port takes place.
When initiating transmission, the original ArduinoModbus library (which is designed for a specific Arduino shield) applies hardcoded 50us delay regardless of port speed, which resulted in garbled communication over RS485 in a setup with generic RS485-to-UART module based on MAX485 chip. This is "mysteriously" in line with the strict Modbus standard requirement to maintain at least 3.5 delay between frames (with an exception of fixed delay of 1750us for port speeds of 19200 and higher).
Based on extended study it was discovered, that a delay equivalent of time interval required to transmit 3-3.5 chars at the current port speed is enough avoid transmission errors in majority of tests.
Tested with Arduino Uno slave, MAX485 based RS485-to-UART adapter and a Modbus master device running original libmodbus library.
Copyright (c) 2018 Arduino SA. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA