Skip to content
Merged
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
6 changes: 3 additions & 3 deletions pymodbus/simulator/simruntime.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ async def get_bit_block(self, block_id: str, func_code: int, address: int, count
"""Handle coils and discrete input."""
start_address, register_count, registers, _ = self.block[block_id]
offset = (int(address / 16) if self.use_bit_addressing else address) - start_address
reg_count = int(count / 16) + 1
if register_count <= offset < 0 or offset + reg_count > register_count:
bit_offset = address % 16
reg_count = (bit_offset + count + 15) // 16
if offset < 0 or offset + reg_count > register_count:
return ExcCodes.ILLEGAL_ADDRESS
if (result := await self.__check_block(func_code, block_id, address, reg_count, offset, values)):
return result
list_bools = SimUtils.registersToBits(registers[offset:offset+reg_count])
bit_offset = address % 16
if values:
list_bools[bit_offset:bit_offset+count] = values
registers[offset:offset+reg_count] = SimUtils.bitsToRegisters(list_bools)
Expand Down
Loading