Modbus-Arduino
Modbus library for Arduino
|
Allows your Arduino to communicate via Modbus protocol
The Modbus is a master-slave protocol used in industrial automation and can be used in other areas, such as home automation.
The Modbus generally uses serial RS-232 or RS-485 as physical layer (then called Modbus Serial) and TCP/IP via Ethernet or WiFi (Modbus TCP). But it is also possible to associate the Modbus application protocol on any other physical layer, such as the radio for example (with MobdusRadio for example).
In the current version the library allows the Arduino operate as a slave, supporting Modbus Serial and Modbus over IP. For more information about Modbus see:
A set of examples is available for each of the Modbus-derived classes, for example:
All examples show the use of 0x11 function to report the slave ID.
Notes:
#define USE_HOLDING_REGISTERS_ONLYThus, only the following functions are supported:
You may test the library using the MbPoll software. For example, to turn on the led in the Lamp example, just do:
$ mbpoll -m rtu -b38400 -a10 -t0 /dev/tnt1 1 mbpoll 1.5-2 - ModBus(R) Master Simulator Copyright (c) 2015-2023 Pascal JEAN, https://github.com/epsilonrt/mbpoll This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions; type 'mbpoll -w' for details. Protocol configuration: ModBus RTU Slave configuration...: address = [10] start reference = 1, count = 1 Communication.........: /dev/tnt1, 38400-8E1 t/o 1.00 s, poll rate 1000 ms Data type.............: discrete output (coil) Written 1 references.
There are five classes corresponding to six headers that may be used:
By opting for Modbus Serial, TCP or Radio you must include in your sketch the corresponding header :
#include <ModbusSerial.h>
In this library was decided to use the terms used in Modbus to the methods names, then is important clarify the names of register types:
Register type | Use as | Access | Library methods |
---|---|---|---|
Coil | Digital Output | Read/Write | addCoil(), coil(), setCoil() |
Holding Register | Analog Output | Read/Write | addHreg(), hreg(), setHreg() |
Input Status | Digital Input | Read Only | addIsts(), ists(), setIsts() |
Input Register | Analog Input | Read Only | addIreg(), ireg(), setIreg() |
Notes:
The code in this repo is licensed under the BSD New License. See LICENSE for more info.