Modbus RTU Meter Integration

Introduction

Mostly I use M-Bus (Meter-Bus) for interfacing with metering devices but some of the meters I have acquired use Modbus rather than Meter-Bus as the interfacing protocol.

The term “Modbus” refers to a range of interfacing standards and protocols, which can lead to some confusion – in addition to the similarity of the term Modbus to M-Bus.

Modbus is a client-server application-layer protocol and can run on top of different physical network technologies. Very often this is RS-485 but it could also be RS-232 or RS-422 and some devices use TCP/IP to encapsulate Modbus data frames, with Ethernet as the transport layer for TCP/IP.

When using Modbus over a serial line, there are two alternative ways of encoding the data:

  • Modbus RTU, which uses a compact binary representation of data fields
  • Modbus ASCII, which encodes the data as ASCII characters

Generally speaking, the term “Modbus” is used as shorthand for Modbus RTU over RS-485.

Reading data from a device like an electricity meter which uses Modbus RTU over RS-485 requires:

  • A computer which can act as the ‘client’ to initiate a Modbus query transaction – something like a Raspberry Pi
  • Some hardware to help this computer communicate using RS-485 – something like a USB-to-RS-485 adaptor
  • Cabling to connect this adaptor to the ‘server’ (i.e. the electricity meter)
  • Software which can send and receive the Modbus protocol

RS-485 Cabling

In normal (half-duplex) RS-485 there are two wires which carry the signal. Often these are labelled ‘A’ and ‘B’ but sometimes different notation is used:

  • D- is a synonym for A
  • D+ is a synonym for B

Modbus Software

For handling the Modbus protocol within Python code, the PyModbus library is typically the best option.

CC BY-SA 4.0 Modbus RTU Meter Integration by Marsh Flatts Farm Self Build Diary is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.