Repository navigation
Add control to ModbusPDU, used by diag/mei/other messages. - #3114
Conversation
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>
|
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. |
|
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
left a comment
There was a problem hiding this comment.
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.
|
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. |
First part of #3104, only the PDU side, like you asked.
ModbusPDUgets acontrolclass attribute. The default is the sharedModbusControlBlock(), so nothing changes yet.self.controlindatastore_update()instead of the module level_MCB. The three_MCBglobals indiag_message.py,mei_message.pyandother_message.pyare 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 setpdu.controlto its own block per connection and the PDUs don't have to know about it.I left
framer/ascii.pyalone 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).