1313from pymodbus .logging import Log
1414from pymodbus .pdu import ModbusPDU
1515from pymodbus .transport import CommParams , CommType
16- from pymodbus .utilities import ModbusTransactionState
1716
1817
1918with contextlib .suppress (ImportError ):
@@ -158,10 +157,6 @@ def run():
158157 Please refer to :ref:`Pymodbus internals` for advanced usage.
159158 """
160159
161- state = ModbusTransactionState .IDLE
162- inter_byte_timeout : float = 0
163- silent_interval : float = 0
164-
165160 def __init__ ( # pylint: disable=too-many-arguments
166161 self ,
167162 port : str ,
@@ -219,6 +214,8 @@ def __init__( # pylint: disable=too-many-arguments
219214 # Set a minimum of 1ms for high baudrates
220215 self ._recv_interval = max (self ._recv_interval , 0.001 )
221216
217+ self .inter_byte_timeout : float = 0
218+ self .silent_interval : float = 0
222219 if baudrate > 19200 :
223220 self .silent_interval = 1.75 / 1000 # ms
224221 else :
@@ -264,14 +261,9 @@ def _in_waiting(self):
264261 """Return waiting bytes."""
265262 return getattr (self .socket , "in_waiting" ) if hasattr (self .socket , "in_waiting" ) else getattr (self .socket , "inWaiting" )()
266263
267- def _send (self , request : bytes ) -> int : # pragma: no cover
268- """Send data on the underlying socket.
269-
270- If receive buffer still holds some data then flush it.
271-
272- Sleep if last send finished less than 3.5 character times ago.
273- """
274- super ()._start_send ()
264+ def send (self , request : bytes , addr : tuple | None = None ) -> int :
265+ """Send data on the underlying socket."""
266+ _ = addr
275267 if not self .socket :
276268 raise ConnectionException (str (self ))
277269 if request :
@@ -283,52 +275,6 @@ def _send(self, request: bytes) -> int: # pragma: no cover
283275 return size
284276 return 0
285277
286- def send (self , request : bytes , addr : tuple | None = None ) -> int : # pragma: no cover
287- """Send data on the underlying socket."""
288- _ = addr
289- start = time .time ()
290- if hasattr (self ,"ctx" ):
291- timeout = start + self .ctx .comm_params .timeout_connect
292- else :
293- timeout = start + self .comm_params .timeout_connect
294- while self .state != ModbusTransactionState .IDLE :
295- if self .state == ModbusTransactionState .TRANSACTION_COMPLETE :
296- timestamp = round (time .time (), 6 )
297- Log .debug (
298- "Changing state to IDLE - Last Frame End - {} Current Time stamp - {}" ,
299- self .last_frame_end ,
300- timestamp ,
301- )
302- if self .last_frame_end :
303- idle_time = self .idle_time ()
304- if round (timestamp - idle_time , 6 ) <= self .silent_interval :
305- Log .debug (
306- "Waiting for 3.5 char before next send - {} ms" ,
307- self .silent_interval * 1000 ,
308- )
309- time .sleep (self .silent_interval )
310- else :
311- # Recovering from last error ??
312- time .sleep (self .silent_interval )
313- self .state = ModbusTransactionState .IDLE
314- elif self .state == ModbusTransactionState .RETRYING :
315- # Simple lets settle down!!!
316- # To check for higher baudrates
317- time .sleep (self .comm_params .timeout_connect )
318- break
319- elif time .time () > timeout :
320- Log .debug (
321- "Spent more time than the read time out, "
322- "resetting the transaction to IDLE"
323- )
324- self .state = ModbusTransactionState .IDLE
325- else :
326- Log .debug ("Sleeping" )
327- time .sleep (self .silent_interval )
328- size = self ._send (request )
329- self .last_frame_end = round (time .time (), 6 )
330- return size
331-
332278 def _wait_for_data (self ) -> int :
333279 """Wait for data."""
334280 size = 0
0 commit comments