Skip to content

Add control to ModbusPDU, used by diag/mei/other messages. - #3114

Merged
janiversen merged 1 commit into
pymodbus-dev:devfrom
tarfouss3:pdu-control
Dec 5, 2026
Merged

janiversen merged 1 commit into
pymodbus-dev:devfrom
tarfouss3:pdu-control

Conversation

@tarfouss3

@tarfouss3 tarfouss3 commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

First part of #3104, only the PDU side, like you asked.

  • ModbusPDU gets a control class attribute. The default is the shared ModbusControlBlock(), so nothing changes yet.
  • the diag, mei and other messages use self.control in datastore_update() instead of the module level _MCB. The three _MCB globals in diag_message.py, mei_message.py and other_message.py are gone.

No behaviour change and no new tests. ModbusPDU.control is ModbusControlBlock() is still true today. The point is that the request handler can later set pdu.control to its own block per connection and the PDUs don't have to know about it.

I left framer/ascii.py alone since it isn't PDU. That and the request handler part come after #3068 is in.

check_ci.sh is clean here (codespell, ruff, pylint, zuban, pytest at 100% coverage).

ModbusPDU gets a control class attribute that defaults to the shared
ModbusControlBlock. The diag, mei and other messages use self.control in
datastore_update() instead of a module level _MCB.

No behaviour change. This lets the request handler set its own control
block on a PDU later (pymodbus-dev#3104).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@DanShinde

Copy link
Copy Markdown
Contributor

Pulled it and ran test/pdu and test/server, 825 passed. Since ModbusControlBlock is a singleton this really is a no-op for now, agreed.

One thing to keep in mind for the next part. ChangeAsciiInputDelimiterRequest now writes self.control.Delimiter, but framer/ascii.py still reads the module level _MCB.Delimiter for its end marker. Today that's the same object, but once the handler gives each connection its own control block, a delimiter change from a client won't reach the framer anymore. So the framer probably needs the same control block passed in.

@janiversen

Copy link
Copy Markdown
Collaborator

Yes passing the control block to framer is one of the challenges with this change. But framer is not part of the API, so it is easier to allow an extra parameter.

@janiversen janiversen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks.

As you wrote this is a no-op for now, but please be aware once the "control=ModbusControlBlock()" changes to "control=None", it will cause problems.

Once #3068 is merged, there should be a check if self.control is None for diag/Mei messages.

@janiversen
janiversen merged commit 3b731a7 into pymodbus-dev:dev Dec 5, 2026
16 checks passed
@janiversen

Copy link
Copy Markdown
Collaborator

Just noted, that you defines control as a class variable (slipped through the review), that will NOT work, since there are no guarantee that multiple devices cannot have parallel requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants