Skip to content

simulator: Fix context single parameter #2264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

efdx
Copy link
Contributor

@efdx efdx commented Jul 25, 2024

Summary

Fixes an incomplete feature in Commit: d32947517087214d28d71cdcbf3c02355526ab68 Feature/simulator addressing.

The single parameter was used incorrectly when ModbusServerContext was initialized. This caused the simulator to not work correctly when the configuration "device_id" was used. The context would wrap the dict in another, having completely incorrect, resulting in using an invalid object.

Fix it by defining single correctly.

The ModbusServerContext initialization looks like this:

    def __init__(self, slaves=None, single=True):
        """Initialize a new instance of a modbus server context.

        :param slaves: A dictionary of client contexts
        :param single: Set to true to treat this as a single context
        """
        self.single = single
        self._slaves = slaves or {}
        if self.single:
            self._slaves = {0: self._slaves}

So if single == True AND device_id is defined with an address, this will eventuall result in self._slaves being initialized as

self._slaves = {0: {<address>:<context>}}

instead of

self._slaves = {<address>:<context>}

Testing

  1. Ran pytest, no regressions
  2. Ran simulator with device_id defined.

Verified

This commit was signed with the committer’s verified signature.
primeos Michael Weiss
Fixes an incomplete feature in `Commit:
d329475 Feature/simulator addressing`.

The `single` parameter was used incorrectly when ModbusServerContext was
initialized. This caused the simulator to not work correctly when the
configuration "device_id" was used. The context would wrap the dict in
another, having completely incorrect, resulting in using an invalid
object.

Fix it by defining single correctly.

Signed-off-by: Esa Laakso <esa.laakso@fidelix.com>
Copy link
Collaborator

@janiversen janiversen left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@janiversen janiversen merged commit 30e4aa7 into pymodbus-dev:dev Jul 25, 2024
1 check passed
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.

None yet

2 participants