From 0a0e8d259ececf2f0894875f3e4e0868528afcd0 Mon Sep 17 00:00:00 2001 From: corollaries <5928576+corollaries@users.noreply.github.com> Date: Sat, 27 May 2023 15:37:36 +0200 Subject: [PATCH 1/2] Allow reading/writing address 0 in the simulator --- pymodbus/datastore/simulator.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pymodbus/datastore/simulator.py b/pymodbus/datastore/simulator.py index 7fa762401..4cf5aa1fe 100755 --- a/pymodbus/datastore/simulator.py +++ b/pymodbus/datastore/simulator.py @@ -554,8 +554,9 @@ def validate(self, func_code, address, count=1): # Bit count, correct to register count count = int((count + WORD_SIZE - 1) / WORD_SIZE) address = int(address / 16) + real_address = self.fc_offset[func_code] + address - if real_address <= 0 or real_address > self.register_count: + if real_address < 0 or real_address > self.register_count: return False fx_write = func_code in self._write_func_code From 2b1ffa579cdee7aac512a0d78cccb3db3573ce37 Mon Sep 17 00:00:00 2001 From: corollaries <5928576+corollaries@users.noreply.github.com> Date: Sat, 27 May 2023 16:00:26 +0200 Subject: [PATCH 2/2] Fix whitespace --- pymodbus/datastore/simulator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymodbus/datastore/simulator.py b/pymodbus/datastore/simulator.py index 4cf5aa1fe..cd9cade56 100755 --- a/pymodbus/datastore/simulator.py +++ b/pymodbus/datastore/simulator.py @@ -554,7 +554,7 @@ def validate(self, func_code, address, count=1): # Bit count, correct to register count count = int((count + WORD_SIZE - 1) / WORD_SIZE) address = int(address / 16) - + real_address = self.fc_offset[func_code] + address if real_address < 0 or real_address > self.register_count: return False