@@ -53,8 +53,7 @@ def __init__(
5353 self .trace_packet = trace_packet or self .dummy_trace_packet
5454 self .trace_pdu = trace_pdu or self .dummy_trace_pdu
5555 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
5857 if sync_client :
5958 self .sync_client = sync_client
6059 self ._sync_lock = RLock ()
@@ -109,12 +108,12 @@ def sync_execute(self, no_response_expected: bool, request: ModbusPDU) -> Modbus
109108 return self .sync_get_response ()
110109 except asyncio .exceptions .TimeoutError :
111110 count_retries += 1
112- if self .count_no_responses >= self . accept_no_response_limit :
111+ if self .count_until_disconnect < 0 :
113112 self .connection_lost (asyncio .TimeoutError ("Server not responding" ))
114113 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."
116115 )
117- self .count_no_responses + = 1
116+ self .count_until_disconnect - = 1
118117 txt = f"No response received after { self .retries } retries, continue with next request"
119118 Log .error (txt )
120119 raise ModbusIOException (txt )
@@ -141,16 +140,16 @@ async def execute(self, no_response_expected: bool, request: ModbusPDU) -> Modbu
141140 response = await asyncio .wait_for (
142141 self .response_future , timeout = self .comm_params .timeout_connect
143142 )
144- self .count_no_responses = 0
143+ self .count_until_disconnect = self . max_until_disconnect
145144 return response
146145 except asyncio .exceptions .TimeoutError :
147146 count_retries += 1
148- if self .count_no_responses >= self . accept_no_response_limit :
147+ if self .count_until_disconnect < 0 :
149148 self .connection_lost (asyncio .TimeoutError ("Server not responding" ))
150149 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."
152151 )
153- self .count_no_responses + = 1
152+ self .count_until_disconnect - = 1
154153 txt = f"No response received after { self .retries } retries, continue with next request"
155154 Log .error (txt )
156155 raise ModbusIOException (txt )
@@ -175,7 +174,7 @@ def callback_new_connection(self):
175174
176175 def callback_connected (self ) -> None :
177176 """Call when connection is succcesfull."""
178- self .count_no_responses = 0
177+ self .count_until_disconnect = self . max_until_disconnect
179178 self .next_tid = 0
180179 self .trace_connect (True )
181180
0 commit comments