Skip to content

Commit b582f6b

Browse files
authored
ExceptionResponse for no_response_expected. (#2801)
1 parent 5be871e commit b582f6b

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

API_changes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ API changes
22
===========
33
Versions (X.Y.Z) where Z > 0 e.g. 3.0.1 do NOT have API changes!
44

5+
API changes 3.12.0
6+
------------------
7+
- when using no_response_expected=, the call returns None
8+
59
API changes 3.11.0
610
------------------
711
- Revert wrong byte handling in v3.10.0

examples/client_async_calls.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,7 @@ async def async_execute_diagnostic_requests(client):
267267
rr = await client.diag_getclear_modbus_response(device_id=DEVICE_ID)
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)
270-
assert rr.isError() # test that call was OK, error indicate no response
271-
270+
assert not rr
272271

273272
# ------------------------
274273
# Run the calls in groups.

pymodbus/transaction/transaction.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pymodbus.exceptions import ConnectionException, ModbusIOException
99
from pymodbus.framer import FramerAscii, FramerBase, FramerRTU
1010
from pymodbus.logging import Log
11-
from pymodbus.pdu import ExceptionResponse, ModbusPDU
11+
from pymodbus.pdu import ModbusPDU
1212
from pymodbus.transport import CommParams, ModbusProtocol
1313

1414

@@ -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 None # type: ignore[return-value]
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 None # type: ignore[return-value]
174174
try:
175175
response = await asyncio.wait_for(
176176
self.response_future, timeout=self.comm_params.timeout_connect

test/transaction/test_transaction.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,7 @@ async def test_client_protocol_execute_outside(self, use_clc, no_resp):
314314
transact.data_received(data)
315315
if no_resp:
316316
result = await resp
317-
assert result.isError()
318-
assert isinstance(result, ExceptionResponse)
317+
assert not result
319318
else:
320319
with pytest.raises(ModbusIOException):
321320
await resp
@@ -599,7 +598,7 @@ def test_sync_client_protocol_execute_outside(self, use_clc, no_resp):
599598
transact.sync_client.send = mock.Mock()
600599
result = transact.sync_execute(no_resp, request)
601600
if no_resp:
602-
assert result.isError()
601+
assert not result
603602
else:
604603
assert not result.isError()
605604
assert isinstance(response, ReadCoilsResponse)

0 commit comments

Comments
 (0)