dimm kit: modbus client context manager - #3848
Open
LKuemmel wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the dimm kit IO module to use the Modbus TCP client as a context manager, ensuring Modbus connections are opened/closed in a controlled scope during reads/writes.
Changes:
- Wrap Modbus read operations in
with client:to leverage__enter__/__exit__lifecycle handling. - Wrap Modbus write operations (including initializer output setup) in
with client:for consistent connection handling. - Add small inter-call delays (
time.sleep(0.1)) around IO operations (notably during initializer output writes).
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
62
to
66
| def write(analog_output: Optional[Dict[str, int]], digital_output: Optional[Dict[str, bool]]) -> None: | ||
| for i, value in digital_output.items(): | ||
| client.write_single_coil(DigitalOutputMapping[i].value, 1 if value is True else 0, | ||
| with client: | ||
| for i, value in digital_output.items(): | ||
| client.write_single_coil(DigitalOutputMapping[i].value, 1 if value is True else 0, | ||
| unit=config.configuration.modbus_id) |
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.
Ticket #66006528
ersetzt https://github.com/openWB/core/tree/feature_dimm_kit_base_release für den PR