Upgrade pymodbus 2.5.2 to 3.x (Python 3.12+ compatibility)#3340
Closed
Xerolux wants to merge 1 commit intoopenWB:masterfrom
Closed
Upgrade pymodbus 2.5.2 to 3.x (Python 3.12+ compatibility)#3340Xerolux wants to merge 1 commit intoopenWB:masterfrom
Xerolux wants to merge 1 commit intoopenWB:masterfrom
Conversation
Migrate from pymodbus 2.5.2 to pymodbus >=3.13.0 to support Python 3.12+ (pymodbus 2.x is incompatible). Changes: - requirements.txt: pymodbus==2.5.2 -> pymodbus>=3.13.0 - New: packages/modules/common/pymodbus_compat.py Provides Endian, BinaryPayloadBuilder, BinaryPayloadDecoder (removed from pymodbus 3.x) - Import updates: pymodbus.client.sync -> pymodbus.client pymodbus.transaction -> pymodbus.framer (FramerType enum) pymodbus.constants.Endian -> local compat module pymodbus.payload.* -> local compat module - API changes: unit= -> device_id= (keyword-only in 3.x) ModbusSocketFramer/ModbusRtuFramer -> FramerType.SOCKET/RTU ModbusSerialClient(method='rtu',port=X) -> ModbusSerialClient(port=X,framer=FramerType.RTU) ModbusTcpClient(host,port,framer) -> ModbusTcpClient(host,port=port,framer=framer) read_holding_registers(addr,count,...) -> read_holding_registers(addr,count=count,...) response.getRegister(i) -> response.registers[i] - Updated test mocks in conftest.py for new module paths Tested on Debian Trixie (Python 3.13.5) with openWB2 service running.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pymodbus_compat.py) for removed classes:Endian,BinaryPayloadBuilder,BinaryPayloadDecoderChanges
API Migration (pymodbus 3.x breaking changes)
from pymodbus.client.sync import ModbusTcpClientfrom pymodbus.client import ModbusTcpClientfrom pymodbus.transaction import ModbusSocketFramerfrom pymodbus.framer import FramerTypefrom pymodbus.constants import Endianfrom modules.common.pymodbus_compat import Endianfrom pymodbus.payload import BinaryPayloadBuilderfrom modules.common.pymodbus_compat import BinaryPayloadBuilderunit=<id>device_id=<id>(keyword-only)ModbusSerialClient(method="rtu", port=X)ModbusSerialClient(port, framer=FramerType.RTU)ModbusTcpClient(host, port, framer)ModbusTcpClient(host, port=port, framer=framer)(keyword-only)read_holding_registers(addr, count, unit=x)read_holding_registers(addr, count=count, device_id=x)response.getRegister(i)response.registers[i]New file
packages/modules/common/pymodbus_compat.py- struct-based reimplementation ofEndian,BinaryPayloadBuilder, andBinaryPayloadDecoder(removed from pymodbus 3.x)163 files changed
requirements.txt:pymodbus==2.5.2->pymodbus>=3.13.0packages/modules/common/modbus.py- constructor fixes, keyword-only argsunit=->device_id=conftest.pyupdated for new module pathsTesting
Tested on Debian Trixie 13.4 with Python 3.13.5:
openwb2.servicestarts successfully withpymodbus 3.13.0atreboot.shpip-installs pymodbus 3.13.0 correctly (no rollback)Why
pymodbus 2.5.2 is incompatible with Python 3.12+. As distributions ship newer Python versions (e.g., Debian Trixie ships Python 3.13), openWB cannot run without this migration.