Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more testing for WriteRegisters. #2280

Merged
merged 1 commit into from
Aug 1, 2024
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
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