From ef2c457cc0cadc1f8c987cbd7be4c2a2e3c33839 Mon Sep 17 00:00:00 2001 From: sourceperl <3809271+sourceperl@users.noreply.github.com> Date: Fri, 5 Jul 2024 15:48:17 +0200 Subject: [PATCH] fix length check of "discrete inputs" in DataBank --- CHANGES | 2 ++ pyModbusTCP/server.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 252f584..c4a00e2 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ Revision history for pyModbusTCP 0.2.x xxxx-xx-xx + + - fix ModbusServer: wrong check of discrete inputs length in DataBank (thanks to OTnetproj). - updated compatibility test (python versions): remove 3.7, add 3.12. 0.2.1 2023-11-21 diff --git a/pyModbusTCP/server.py b/pyModbusTCP/server.py index 421d0e1..396ab86 100644 --- a/pyModbusTCP/server.py +++ b/pyModbusTCP/server.py @@ -171,7 +171,7 @@ def get_discrete_inputs(self, address, number=1, srv_info=None): """ # secure extract of data from list used by server thread with self._d_inputs_lock: - if (address >= 0) and (address + number <= len(self._coils)): + if (address >= 0) and (address + number <= len(self._d_inputs)): return self._d_inputs[address: number + address] else: return None @@ -191,7 +191,7 @@ def set_discrete_inputs(self, address, bit_list): bit_list = [bool(b) for b in bit_list] # ensure atomic update of internal data with self._d_inputs_lock: - if (address >= 0) and (address + len(bit_list) <= len(self._coils)): + if (address >= 0) and (address + len(bit_list) <= len(self._d_inputs)): for offset, b_value in enumerate(bit_list): self._d_inputs[address + offset] = b_value else: