Skip to content

Commit c03741c

Browse files
committed
ExceptionResponse for no_response_expected.
1 parent 5cc128d commit c03741c

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

examples/client_async_calls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ async def async_execute_diagnostic_requests(client):
268268
assert not rr.isError() # test that call was OK
269269
rr = await client.diag_force_listen_only(device_id=DEVICE_ID, no_response_expected=True)
270270
assert rr.isError() # test that call was OK, error indicate no response
271-
271+
assert not rr.dev_id
272+
assert rr.exception_code == -1
272273

273274
# ------------------------
274275
# Run the calls in groups.

pymodbus/transaction/transaction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def sync_execute(self, no_response_expected: bool, request: ModbusPDU) -> Modbus
127127
while count_retries <= self.retries:
128128
self.pdu_send(request)
129129
if no_response_expected:
130-
return ExceptionResponse(0xff)
130+
return ExceptionResponse(request.function_code, device_id=0, exception_code=-1)
131131
try:
132132
response = self.sync_get_response(request.dev_id, request.transaction_id)
133133
if response.dev_id != request.dev_id:
@@ -170,7 +170,7 @@ async def execute(self, no_response_expected: bool, request: ModbusPDU) -> Modbu
170170
self.response_future = asyncio.Future()
171171
self.pdu_send(request)
172172
if no_response_expected:
173-
return ExceptionResponse(0xff)
173+
return ExceptionResponse(request.function_code, device_id=0, exception_code=-1)
174174
try:
175175
response = await asyncio.wait_for(
176176
self.response_future, timeout=self.comm_params.timeout_connect

0 commit comments

Comments
 (0)