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
2 changes: 1 addition & 1 deletion pymodbus/simulator/simruntime.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async def get_reg_block(self, block_id: str, func_code: int, address: int, count
"""Handle holding registers and input registers."""
start_address, register_count, registers, _ = self.block[block_id]
offset = address - start_address
if register_count <= offset < 0 or offset + count > register_count:
if offset < 0 or offset + count > register_count:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be the wrong fix, it would be more logical to test that address >= start_address.

This should also be done in set_values

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to merge this without any further changes?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the PR solved the problem which is enough.

return ExcCodes.ILLEGAL_ADDRESS
if (result := await self.__check_block(func_code, block_id, address, count, offset, values)):
return result
Expand Down
8 changes: 8 additions & 0 deletions test/simulator/test_simruntime.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ async def test_simruntime_getValues(self):
rt = SimRuntime(sd)
result = await rt.async_getValues(0x03, 10, 1)
assert result == [15]
result = await rt.async_getValues(0x03, 8, 1)
assert isinstance(result, ExcCodes)
result = await rt.async_getValues(0x03, 9, 1)
assert isinstance(result, ExcCodes)
result = await rt.async_getValues(0x03, 11, 1)
assert isinstance(result, ExcCodes)
result = await rt.async_getValues(0x03, 12, 1)
assert isinstance(result, ExcCodes)
result = await rt.async_getValues(0x03, 15, 1)
assert isinstance(result, ExcCodes)

Expand Down
Loading