Modbus Crawler

Simple Python Modbus Crawler that reads registers of a Modbus server/slave based on a register secification in a data frame/csv/...

View the Project on GitHub AIT-RDP/rdp-modbus-crawler

Modbus Crawler

Generic Modbus crawler that reads and writes registers according to device and register spec.

Author: Christian Seitl, christian.seitl@ait.ac.at

Registers are specified either in a pandas data frame or a csv-file. The columns are:

Example:

Register_start Register_end Register_type Data_type Name Unit Scaling
100 100 i INT16 I_L1 A 0.01
110 111 i SINGLE f Hz 1
200 205 i SINGLE U_L1 V 1
x x i SINGLE U_L2 V 1
x x i SINGLE U_L3 V 1

API

register_spec_df = pd.read_csv("register_spec.csv")

modbus_device = ModbusTcpDevice("localhost", 502, byteorder=Endian.BIG, wordorder=Endian.BIG, auto_connect=True,
                                registers_spec_df=register_spec_df, register_specs_file_name=None)

modbus_device.connect()
registers = modbus_device.read_registers_as_dict()
modbus_device.disconnect()

Functions in ModbusTcpDevice:

def connect(self):
    """Connects to the Modbus device."""


def disconnect(self):
    """Disconnects from the Modbus device."""


@property
def connected(self) -> bool:
    """Returns True if connected to the Modbus device."""


def read_registers_as_dict(self) -> dict[str, float]:
    """Reads all registers and returns them as dictionary."""


def read_registers(self) -> list[ModbusRegister]:
    """Reads all registers with mode `r` or `rw` and returns them as list of ModbusRegister objects."""


def read_register(self, register: str | int) -> ModbusRegister:
    """Reads a single register with mode `r` or `rw` and returns it as ModbusRegister object."""


def write_register(self, register: str | int, value):
    """Writes a single register."""