Skip to content

Commit

Permalink
Add more testing for WriteRegisters. (#2280)
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen authored Aug 1, 2024
1 parent a239fc3 commit 388ab66
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions examples/client_async_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ async def async_handle_holding_registers(client):
assert not rr.isError() # test that call was OK
assert rr.registers == [10] * 8

await client.write_registers(1, [10], slave=SLAVE)
rr = await client.read_holding_registers(1, 1, slave=SLAVE)
assert not rr.isError() # test that call was OK
assert rr.registers == [10]

_logger.info("### write read holding registers")
arguments = {
"read_address": 1,
Expand Down
4 changes: 2 additions & 2 deletions pymodbus/client/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,11 @@ def write_coils(
)

def write_registers(
self, address: int, values: list[int] | int, slave: int = 1, skip_encode: bool = False) -> T:
self, address: int, values: list[int], slave: int = 1, skip_encode: bool = False) -> T:
"""Write registers (code 0x10).
:param address: Start address to write to
:param values: List of values to write, or a single value to write
:param values: List of values to write
:param slave: (optional) Modbus slave ID
:param skip_encode: (optional) do not encode values
:raises ModbusException:
Expand Down
4 changes: 4 additions & 0 deletions test/sub_function_codes/test_register_write_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ async def test_write_multiple_register_request(self):
result = await request.execute(context)
assert result.function_code == request.function_code

request = WriteMultipleRegistersRequest(0x00, [0x00])
result = await request.execute(context)
assert result.function_code == request.function_code

# -----------------------------------------------------------------------#
# Mask Write Register Request
# -----------------------------------------------------------------------#
Expand Down

0 comments on commit 388ab66

Please sign in to comment.