Skip to content
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

A datastore for each slave. #2050

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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