Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 10 additions & 8 deletions umodbus/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def execute(self, slave_id, route_map):
for address in range(self.starting_address,
self.starting_address + self.quantity):
endpoint = route_map.match(slave_id, self.function_code,
address)
address, self.starting_address)
values.append(endpoint(slave_id=slave_id, address=address,
function_code=self.function_code))

Expand Down Expand Up @@ -575,7 +575,7 @@ def execute(self, slave_id, route_map):
for address in range(self.starting_address,
self.starting_address + self.quantity):
endpoint = route_map.match(slave_id, self.function_code,
address)
address, self.starting_address)
values.append(endpoint(slave_id=slave_id, address=address,
function_code=self.function_code))

Expand Down Expand Up @@ -755,7 +755,7 @@ def execute(self, slave_id, route_map):
for address in range(self.starting_address,
self.starting_address + self.quantity):
endpoint = route_map.match(slave_id, self.function_code,
address)
address, self.starting_address)
values.append(endpoint(slave_id=slave_id, address=address,
function_code=self.function_code))

Expand Down Expand Up @@ -933,7 +933,7 @@ def execute(self, slave_id, route_map):
for address in range(self.starting_address,
self.starting_address + self.quantity):
endpoint = route_map.match(slave_id, self.function_code,
address)
address, self.starting_address)
values.append(endpoint(slave_id=slave_id, address=address,
function_code=self.function_code))

Expand Down Expand Up @@ -1093,7 +1093,8 @@ def execute(self, slave_id, route_map):
:param slave_id: Slave id.
:param eindpoint: Instance of modbus.route.Map.
"""
endpoint = route_map.match(slave_id, self.function_code, self.address)
starting_address = self.address
endpoint = route_map.match(slave_id, self.function_code, self.address, starting_address)
try:
endpoint(slave_id=slave_id, address=self.address, value=self.value,
function_code=self.function_code)
Expand Down Expand Up @@ -1237,7 +1238,8 @@ def execute(self, slave_id, route_map):
:param slave_id: Slave id.
:param eindpoint: Instance of modbus.route.Map.
"""
endpoint = route_map.match(slave_id, self.function_code, self.address)
starting_address = self.address
endpoint = route_map.match(slave_id, self.function_code, self.address, starting_address)
try:
endpoint(slave_id=slave_id, address=self.address, value=self.value,
function_code=self.function_code)
Expand Down Expand Up @@ -1453,7 +1455,7 @@ def execute(self, slave_id, route_map):
"""
for index, value in enumerate(self.values):
address = self.starting_address + index
endpoint = route_map.match(slave_id, self.function_code, address)
endpoint = route_map.match(slave_id, self.function_code, address, self.starting_address)

try:
endpoint(slave_id=slave_id, address=address, value=value,
Expand Down Expand Up @@ -1605,7 +1607,7 @@ def execute(self, slave_id, route_map):
"""
for index, value in enumerate(self.values):
address = self.starting_address + index
endpoint = route_map.match(slave_id, self.function_code, address)
endpoint = route_map.match(slave_id, self.function_code, address, self.starting_address)

try:
endpoint(slave_id=slave_id, address=address, value=value,
Expand Down
16 changes: 9 additions & 7 deletions umodbus/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@ class Map:
def __init__(self):
self._rules = []

def add_rule(self, endpoint, slave_ids, function_codes, addresses):
def add_rule(self, endpoint, slave_ids, function_codes, addresses, starting_address=None):
self._rules.append(DataRule(endpoint, slave_ids, function_codes,
addresses))
addresses, starting_address))

def match(self, slave_id, function_code, address):
def match(self, slave_id, function_code, address, starting_address):
for rule in self._rules:
if rule.match(slave_id, function_code, address):
if rule.match(slave_id, function_code, address, starting_address):
return rule.endpoint


class DataRule:
def __init__(self, endpoint, slave_ids, function_codes, addresses):
def __init__(self, endpoint, slave_ids, function_codes, addresses, starting_address):
self.endpoint = endpoint
self.slave_ids = slave_ids
self.function_codes = function_codes
self.addresses = addresses
self.starting_address = starting_address

def match(self, slave_id, function_code, address):
if slave_id in self.slave_ids and\
def match(self, slave_id, function_code, address, starting_address):
if slave_id in self.slave_ids and \
function_code in self.function_codes and \
(True if self.starting_address is None else starting_address == self.starting_address) and \
address in self.addresses:
return True

Expand Down
4 changes: 2 additions & 2 deletions umodbus/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
pack_exception_pdu, recv_exactly)


def route(self, slave_ids=None, function_codes=None, addresses=None):
def route(self, slave_ids=None, function_codes=None, addresses=None, starting_address=None):
""" A decorator that is used to register an endpoint for a given
rule::

Expand All @@ -24,7 +24,7 @@ def read_single_bit_values(slave_id, address):
:param addresses: A list or set with addresses.
"""
def inner(f):
self.route_map.add_rule(f, slave_ids, function_codes, addresses)
self.route_map.add_rule(f, slave_ids, function_codes, addresses, starting_address)
return f

return inner
Expand Down