Skip to content

Commit

Permalink
fix length check of "discrete inputs" in DataBank
Browse files Browse the repository at this point in the history
  • Loading branch information
sourceperl committed Jul 5, 2024
1 parent 8cf25cd commit ef2c457
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions pyModbusTCP/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit ef2c457

Please sign in to comment.