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
pythonversion 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=1, # 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file flex_modbus_reader-0.0.2.tar.gz.
File metadata
- Download URL: flex_modbus_reader-0.0.2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2459674bfa9942e82fc7cfab9cdef8f643dfe166a7c12d65252ae9b56ebf6c67
|
|
| MD5 |
c7f769ce95f2a3d6676b884be6c92cb4
|
|
| BLAKE2b-256 |
af0ae4fe43d5a208865b317ec2dbaa55316f2a9027f4c2e02595492059a2f4f5
|