@@ -52,20 +52,13 @@ class ModbusBaseClient(ModbusClientMixin, ModbusProtocol):
5252 class _params :
5353 """Parameter class."""
5454
55- host : str = None
56- port : str | int = None
57- timeout : float = None
5855 retries : int = None
5956 retry_on_empty : bool = None
6057 close_comm_on_error : bool = None
6158 strict : bool = None
6259 broadcast_enable : bool = None
6360 reconnect_delay : int = None
6461
65- baudrate : int = None
66- bytesize : int = None
67- parity : str = None
68- stopbits : int = None
6962 handle_local_echo : bool = None
7063
7164 source_address : tuple [str , int ] = None
@@ -89,28 +82,30 @@ def __init__( # pylint: disable=too-many-arguments
8982 """Initialize a client instance."""
9083 ModbusClientMixin .__init__ (self )
9184 self .use_sync = kwargs .get ("use_sync" , False )
85+ setup_params = CommParams (
86+ comm_type = kwargs .get ("CommType" ),
87+ comm_name = "comm" ,
88+ reconnect_delay = reconnect_delay ,
89+ reconnect_delay_max = reconnect_delay_max ,
90+ timeout_connect = timeout ,
91+ host = kwargs .get ("host" , None ),
92+ port = kwargs .get ("port" , None ),
93+ sslctx = kwargs .get ("sslctx" , None ),
94+ baudrate = kwargs .get ("baudrate" , None ),
95+ bytesize = kwargs .get ("bytesize" , None ),
96+ parity = kwargs .get ("parity" , None ),
97+ stopbits = kwargs .get ("stopbits" , None ),
98+ )
9299 if not self .use_sync :
93100 ModbusProtocol .__init__ (
94101 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- ),
102+ setup_params ,
109103 False ,
110104 )
105+ else :
106+ self .comm_params = setup_params
111107 self .framer = framer
112108 self .params = self ._params ()
113- self .params .timeout = float (timeout )
114109 self .params .retries = int (retries )
115110 self .params .retry_on_empty = bool (retry_on_empty )
116111 self .params .close_comm_on_error = bool (close_comm_on_error )
@@ -199,7 +194,9 @@ async def async_execute(self, request=None):
199194 resp = b"Broadcast write sent - no response expected"
200195 else :
201196 try :
202- resp = await asyncio .wait_for (req , timeout = self .params .timeout )
197+ resp = await asyncio .wait_for (
198+ req , timeout = self .comm_params .timeout_connect
199+ )
203200 except asyncio .exceptions .TimeoutError :
204201 self .close (reconnect = True )
205202 raise
@@ -315,4 +312,6 @@ def __str__(self):
315312
316313 :returns: The string representation
317314 """
318- return f"{ self .__class__ .__name__ } { self .params .host } :{ self .params .port } "
315+ return (
316+ f"{ self .__class__ .__name__ } { self .comm_params .host } :{ self .comm_params .port } "
317+ )
0 commit comments