Skip to main content

Flex Modbus Reader

Project description

Flex Modbus Reader

Easily connect, debug and test any device that supports Modbus TCP!

Features:

  • Splitting a request by chunks with configurable chunck size value. (Modbus TCP protocol supports maximum of 260 bytes per request, but it also depends on the device's manufactorer.)
  • Auto-skip no needed registers in a bytes stream.
  • Supports index auth-shifting. (By default, registers are addressed starting at zero, but therefore devices that specify 1-16 are addressed as 0-15.)

Installation Guide

Prerequisites

  • python version 3.9 or later

Installation:

pip install flex-modbus-reader

Integrate your modbus device

Examples:

You can find an example of integrating Modbus energy meter in flexmodbusreader/examples module.

Writing your own ModbusDevice class:

Steps:

  • Check the manufacturer documentation to find registers you need to read.
  • Create the registers map
  • Use this map to get the data from the device
from pymodbus.constants import Endian

from flexmodbusreader.device import ModbusDevice, Register
from flexmodbusreader.reader import ModbusDeviceDataReader


device = ModbusDevice(
    model="Energy Meter",
    registers_map=[
        Register("value_1", 3000, 2, ModbusTcpClient.DATATYPE.FLOAT32),
        Register("value_2", 3002, 2, ModbusTcpClient.DATATYPE.FLOAT32),
        Register("value_3", 3004, 2, ModbusTcpClient.DATATYPE.FLOAT32),
        Register("value_4", 3200, 2, ModbusTcpClient.DATATYPE.FLOAT32),
        Register("value_5", 3202, 2, ModbusTcpClient.DATATYPE.INT32),
        Register("value_6", 3204, 2, ModbusTcpClient.DATATYPE.FLOAT32),
        Register("value_7", 3250, 2, ModbusTcpClient.DATATYPE.UINT64),
        Register("value_8", 3252, 2, ModbusTcpClient.DATATYPE.FLOAT32),
        Register("value_9", 3340, 2, ModbusTcpClient.DATATYPE.FLOAT32),
    ],
    unit=10, # Modbus Slave ID
    index_shift=-1 # the value by which to shift the indices
)

client = ModbusTcpClient("192.168.0.1", port=5030, timeout=1)
reader = ModbusDeviceDataReader(
    client=client, # ModbusTcpClient
    byteorder=Endian.BIG, # byte endianess. Needed for decoding
    wordorder=Endian.BIG, # word endianess. Needed for decoding
    message_size=100, # Maximum size of register to read per one request
    device=device, # ModbusDevice instance
)

data = reader.read_registers() # returns a dict with decoded values 

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flex_modbus_reader-0.0.1.tar.gz (6.1 kB view details)

Uploaded Source

File details

Details for the file flex_modbus_reader-0.0.1.tar.gz.

File metadata

  • Download URL: flex_modbus_reader-0.0.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.8

File hashes

Hashes for flex_modbus_reader-0.0.1.tar.gz
Algorithm Hash digest
SHA256 32e8a951058696c8ea1ab936179c55fdffb4b58e885301b82695ce99b87ed3e7
MD5 e7ca1fe40164e921cf29a942dda6e994
BLAKE2b-256 d78aef84e784c5a4c8e59bec99aba01b2bb722455a9925f950cf073ef0ba4a31

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page