Skip to content

Commit

Permalink
Properly process 'slaves' argument (#2292)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cavaler authored Aug 13, 2024
1 parent bdbbe9f commit 3e60a20
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
1 change: 0 additions & 1 deletion examples/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def get_commandline(server=False, description=None, extras=None, cmdline=None):
help="set number of slaves, default is 0 (any)",
default=0,
type=int,
nargs="+",
)
parser.add_argument(
"--context",
Expand Down
25 changes: 7 additions & 18 deletions examples/server_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def setup_server(description=None, context=None, cmdline=None):
# full address range::
datablock = lambda : ModbusSequentialDataBlock.create() # pylint: disable=unnecessary-lambda-assignment,unnecessary-lambda

if args.slaves:
if args.slaves > 1:
# The server then makes use of a server context that allows the server
# to respond with different slave contexts for different slave ids.
# By default it will return the same context for every slave id supplied
Expand All @@ -101,27 +101,16 @@ def setup_server(description=None, context=None, cmdline=None):
# that a request to address(0-7) will map to the address (0-7).
# The default is False which is based on section 4.4 of the
# specification, so address(0-7) will map to (1-8)::
context = {
0x01: ModbusSlaveContext(
di=datablock(),
co=datablock(),
hr=datablock(),
ir=datablock(),
),
0x02: ModbusSlaveContext(
di=datablock(),
co=datablock(),
hr=datablock(),
ir=datablock(),
),
0x03: ModbusSlaveContext(
context = {}

for slave in range(args.slaves):
context[slave] = ModbusSlaveContext(
di=datablock(),
co=datablock(),
hr=datablock(),
ir=datablock(),
zero_mode=True,
),
}
)

single = False
else:
context = ModbusSlaveContext(
Expand Down

0 comments on commit 3e60a20

Please sign in to comment.