Skip to content

Commit

Permalink
A datastore for each slave. (#2050)
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen authored Feb 22, 2024
1 parent 974d626 commit 179f599
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions examples/server_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ def setup_server(description=None, context=None, cmdline=None):
# This is because many devices exhibit this kind of behavior (but not all)
if args.store == "sequential":
# Continuing, use a sequential block without gaps.
datablock = ModbusSequentialDataBlock(0x00, [17] * 100)
datablock = lambda : ModbusSequentialDataBlock(0x00, [17] * 100) # pylint: disable=unnecessary-lambda-assignment
elif args.store == "sparse":
# Continuing, or use a sparse DataBlock which can have gaps
datablock = ModbusSparseDataBlock({0x00: 0, 0x05: 1})
datablock = lambda : ModbusSparseDataBlock({0x00: 0, 0x05: 1}) # pylint: disable=unnecessary-lambda-assignment
elif args.store == "factory":
# Alternately, use the factory methods to initialize the DataBlocks
# or simply do not pass them to have them initialized to 0x00 on the
# full address range::
datablock = ModbusSequentialDataBlock.create()
datablock = lambda : ModbusSequentialDataBlock.create() # pylint: disable=unnecessary-lambda-assignment,unnecessary-lambda

if args.slaves:
# The server then makes use of a server context that allows the server
Expand All @@ -94,29 +94,29 @@ def setup_server(description=None, context=None, cmdline=None):
# specification, so address(0-7) will map to (1-8)::
context = {
0x01: ModbusSlaveContext(
di=datablock,
co=datablock,
hr=datablock,
ir=datablock,
di=datablock(),
co=datablock(),
hr=datablock(),
ir=datablock(),
),
0x02: ModbusSlaveContext(
di=datablock,
co=datablock,
hr=datablock,
ir=datablock,
di=datablock(),
co=datablock(),
hr=datablock(),
ir=datablock(),
),
0x03: ModbusSlaveContext(
di=datablock,
co=datablock,
hr=datablock,
ir=datablock,
di=datablock(),
co=datablock(),
hr=datablock(),
ir=datablock(),
zero_mode=True,
),
}
single = False
else:
context = ModbusSlaveContext(
di=datablock, co=datablock, hr=datablock, ir=datablock
di=datablock(), co=datablock(), hr=datablock(), ir=datablock()
)
single = True

Expand Down

0 comments on commit 179f599

Please sign in to comment.