Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions API_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +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
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