1313from pymodbus .logging import Log
1414from pymodbus .pdu import ModbusRequest , ModbusResponse
1515from pymodbus .transaction import DictTransactionManager
16- from pymodbus .transport .transport import CommParams , Transport
16+ from pymodbus .transport .transport import CommParams , ModbusProtocol
1717from pymodbus .utilities import ModbusTransactionState
1818
1919
20- class ModbusBaseClient (ModbusClientMixin , Transport ):
20+ class ModbusBaseClient (ModbusClientMixin , ModbusProtocol ):
2121 """**ModbusBaseClient**
2222
2323 **Parameters common to all clients**:
@@ -88,24 +88,26 @@ def __init__( # pylint: disable=too-many-arguments
8888 ) -> None :
8989 """Initialize a client instance."""
9090 ModbusClientMixin .__init__ (self )
91- Transport .__init__ (
92- self ,
93- CommParams (
94- comm_type = kwargs .get ("CommType" ),
95- comm_name = "comm" ,
96- reconnect_delay = reconnect_delay ,
97- reconnect_delay_max = reconnect_delay_max ,
98- timeout_connect = timeout ,
99- host = kwargs .get ("host" , None ),
100- port = kwargs .get ("port" , None ),
101- sslctx = kwargs .get ("sslctx" , None ),
102- baudrate = kwargs .get ("baudrate" , None ),
103- bytesize = kwargs .get ("bytesize" , None ),
104- parity = kwargs .get ("parity" , None ),
105- stopbits = kwargs .get ("stopbits" , None ),
106- ),
107- False ,
108- )
91+ self .use_sync = kwargs .get ("use_sync" , False )
92+ if not self .use_sync :
93+ ModbusProtocol .__init__ (
94+ self ,
95+ CommParams (
96+ comm_type = kwargs .get ("CommType" ),
97+ comm_name = "comm" ,
98+ reconnect_delay = reconnect_delay ,
99+ reconnect_delay_max = reconnect_delay_max ,
100+ timeout_connect = timeout ,
101+ host = kwargs .get ("host" , None ),
102+ port = kwargs .get ("port" , None ),
103+ sslctx = kwargs .get ("sslctx" , None ),
104+ baudrate = kwargs .get ("baudrate" , None ),
105+ bytesize = kwargs .get ("bytesize" , None ),
106+ parity = kwargs .get ("parity" , None ),
107+ stopbits = kwargs .get ("stopbits" , None ),
108+ ),
109+ False ,
110+ )
109111 self .framer = framer
110112 self .params = self ._params ()
111113 self .params .timeout = float (timeout )
@@ -130,7 +132,6 @@ def __init__( # pylint: disable=too-many-arguments
130132 )
131133 self .reconnect_delay = self .params .reconnect_delay
132134 self .reconnect_delay_current = self .params .reconnect_delay
133- self .use_sync = False
134135 self .use_udp = False
135136 self .state = ModbusTransactionState .IDLE
136137 self .last_frame_end : float = 0
@@ -139,6 +140,11 @@ def __init__( # pylint: disable=too-many-arguments
139140 # ----------------------------------------------------------------------- #
140141 # Client external interface
141142 # ----------------------------------------------------------------------- #
143+ @property
144+ def connected (self ):
145+ """Connect internal."""
146+ return True
147+
142148 def register (self , custom_response_class : ModbusResponse ) -> None :
143149 """Register a custom response class with the decoder (call **sync**).
144150
@@ -172,7 +178,7 @@ def execute(self, request: ModbusRequest = None) -> ModbusResponse:
172178 :raises ConnectionException: Check exception text.
173179 """
174180 if self .use_sync :
175- if not self .connect () :
181+ if not self .connected :
176182 raise ConnectionException (f"Failed to connect[{ str (self )} ]" )
177183 return self .transaction .execute (request )
178184 if not self .transport :
0 commit comments