Skip to content

Commit

Permalink
remove zero_mode parameter. (#2354)
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen committed Oct 26, 2024
1 parent a1016e4 commit 8e2535f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 25 deletions.
1 change: 1 addition & 0 deletions API_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Versions (X.Y.Z) where Z > 0 e.g. 3.0.1 do NOT have API changes!

API changes 3.8.0
-----------------
- ModbusSlaveContext, remove zero_mode parameter.


API changes 3.7.0
Expand Down
3 changes: 2 additions & 1 deletion doc/source/roadmap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ The following bullet points are what the maintainers focus on:
- 3.7.X, bug fix release, hopefully with:
- Not planned
- 3.8.0, with:
- on dev:
- skip_encode, zero_mode parameters removed
- Simplify PDU classes
- Simplify transaction manager (central control point)
- Remove ModbusControlBlock
- new transaction handling
- transaction 100% coverage
- skip_encode, zero_mode parameters removed
- 4.0.0, with:
- client async with sync/async API
- Only one datastore, but with different API`s
Expand Down
5 changes: 0 additions & 5 deletions examples/server_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ def setup_server(description=None, context=None, cmdline=None):
# (broadcast mode).
# However, this can be overloaded by setting the single flag to False and
# then supplying a dictionary of slave id to context mapping::
#
# The slave context can also be initialized in zero_mode which means
# 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 = {}

for slave in range(args.slaves):
Expand Down
23 changes: 4 additions & 19 deletions pymodbus/datastore/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,32 +79,20 @@ class ModbusSlaveContext(ModbusBaseSlaveContext):
:param co: coils initializer ModbusDataBlock
:param hr: holding register initializer ModbusDataBlock
:param ir: input registers initializer ModbusDataBlock
:param zero_mode: Not add one to address
When True, a request for address zero to n will map to
datastore address zero to n.
When False, a request for address zero to n will map to
datastore address one to n+1, based on section 4.4 of
specification.
Default is False.
"""

def __init__(self, *_args,
di=ModbusSequentialDataBlock.create(),
co=ModbusSequentialDataBlock.create(),
ir=ModbusSequentialDataBlock.create(),
hr=ModbusSequentialDataBlock.create(),
zero_mode=False):
):
"""Initialize the datastores."""
self.store = {}
self.store["d"] = di
self.store["c"] = co
self.store["i"] = ir
self.store["h"] = hr
self.zero_mode = zero_mode

def __str__(self):
"""Return a string representation of the context.
Expand All @@ -126,8 +114,7 @@ def validate(self, fc_as_hex, address, count=1):
:param count: The number of values to test
:returns: True if the request in within range, False otherwise
"""
if not self.zero_mode:
address += 1
address += 1
Log.debug("validate: fc-[{}] address-{}: count-{}", fc_as_hex, address, count)
return self.store[self.decode(fc_as_hex)].validate(address, count)

Expand All @@ -139,8 +126,7 @@ def getValues(self, fc_as_hex, address, count=1):
:param count: The number of values to retrieve
:returns: The requested values from a:a+c
"""
if not self.zero_mode:
address += 1
address += 1
Log.debug("getValues: fc-[{}] address-{}: count-{}", fc_as_hex, address, count)
return self.store[self.decode(fc_as_hex)].getValues(address, count)

Expand All @@ -151,8 +137,7 @@ def setValues(self, fc_as_hex, address, values):
:param address: The starting address
:param values: The new values to be set
"""
if not self.zero_mode:
address += 1
address += 1
Log.debug("setValues[{}] address-{}: count-{}", fc_as_hex, address, len(values))
self.store[self.decode(fc_as_hex)].setValues(address, values)

Expand Down

0 comments on commit 8e2535f

Please sign in to comment.