@@ -53,8 +53,7 @@ def __init__(
53
53
self .trace_packet = trace_packet or self .dummy_trace_packet
54
54
self .trace_pdu = trace_pdu or self .dummy_trace_pdu
55
55
self .trace_connect = trace_connect or self .dummy_trace_connect
56
- self .accept_no_response_limit = retries + 3
57
- self .count_no_responses = 0
56
+ self .max_until_disconnect = self .count_until_disconnect = retries + 3
58
57
if sync_client :
59
58
self .sync_client = sync_client
60
59
self ._sync_lock = RLock ()
@@ -109,12 +108,12 @@ def sync_execute(self, no_response_expected: bool, request: ModbusPDU) -> Modbus
109
108
return self .sync_get_response ()
110
109
except asyncio .exceptions .TimeoutError :
111
110
count_retries += 1
112
- if self .count_no_responses >= self . accept_no_response_limit :
111
+ if self .count_until_disconnect < 0 :
113
112
self .connection_lost (asyncio .TimeoutError ("Server not responding" ))
114
113
raise ModbusIOException (
115
- f "ERROR: No response received of the last { self . accept_no_response_limit } request , CLOSING CONNECTION."
114
+ "ERROR: No response received of the last requests (default: retries+3) , CLOSING CONNECTION."
116
115
)
117
- self .count_no_responses + = 1
116
+ self .count_until_disconnect - = 1
118
117
txt = f"No response received after { self .retries } retries, continue with next request"
119
118
Log .error (txt )
120
119
raise ModbusIOException (txt )
@@ -141,16 +140,16 @@ async def execute(self, no_response_expected: bool, request: ModbusPDU) -> Modbu
141
140
response = await asyncio .wait_for (
142
141
self .response_future , timeout = self .comm_params .timeout_connect
143
142
)
144
- self .count_no_responses = 0
143
+ self .count_until_disconnect = self . max_until_disconnect
145
144
return response
146
145
except asyncio .exceptions .TimeoutError :
147
146
count_retries += 1
148
- if self .count_no_responses >= self . accept_no_response_limit :
147
+ if self .count_until_disconnect < 0 :
149
148
self .connection_lost (asyncio .TimeoutError ("Server not responding" ))
150
149
raise ModbusIOException (
151
- f "ERROR: No response received of the last { self . accept_no_response_limit } request , CLOSING CONNECTION."
150
+ "ERROR: No response received of the last requests (default: retries+3) , CLOSING CONNECTION."
152
151
)
153
- self .count_no_responses + = 1
152
+ self .count_until_disconnect - = 1
154
153
txt = f"No response received after { self .retries } retries, continue with next request"
155
154
Log .error (txt )
156
155
raise ModbusIOException (txt )
@@ -175,7 +174,7 @@ def callback_new_connection(self):
175
174
176
175
def callback_connected (self ) -> None :
177
176
"""Call when connection is succcesfull."""
178
- self .count_no_responses = 0
177
+ self .count_until_disconnect = self . max_until_disconnect
179
178
self .next_tid = 0
180
179
self .trace_connect (True )
181
180
0 commit comments