Skip to content

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.

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 <[email protected]>
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
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.

2 participants