@@ -37,7 +37,6 @@ class ModbusBaseClient(ModbusClientMixin[Awaitable[ModbusResponse]]):
3737 :param reconnect_delay_max: Maximum delay in seconds.milliseconds before reconnecting.
3838 :param on_connect_callback: Will be called when connected/disconnected (bool parameter)
3939 :param no_resend_on_retry: Do not resend request when retrying due to missing response.
40- :param comm_type: Type of communication (set by interface class)
4140 :param kwargs: Experimental parameters.
4241
4342 .. tip::
@@ -60,30 +59,30 @@ def __init__( # pylint: disable=too-many-arguments
6059 reconnect_delay_max : float = 300 ,
6160 on_connect_callback : Callable [[bool ], None ] | None = None ,
6261 no_resend_on_retry : bool = False ,
63- comm_type : CommType | None = None ,
6462 source_address : tuple [str , int ] | None = None ,
63+
64+ comm_params : CommParams | None = None ,
6565 ** kwargs : Any ,
6666 ) -> None :
6767 """Initialize a client instance."""
6868 ModbusClientMixin .__init__ (self ) # type: ignore[arg-type]
69+ if comm_params :
70+ self .comm_params = comm_params
71+ self .comm_params .comm_name = "comm"
72+ self .comm_params .source_address = source_address
73+ self .comm_params .reconnect_delay = reconnect_delay
74+ self .comm_params .reconnect_delay_max = reconnect_delay_max
75+ self .comm_params .timeout_connect = timeout
76+ self .comm_params .host = kwargs .get ("host" , None )
77+ self .comm_params .port = kwargs .get ("port" , 0 )
78+ self .comm_params .baudrate = kwargs .get ("baudrate" , None )
79+ self .comm_params .bytesize = kwargs .get ("bytesize" , None )
80+ self .comm_params .parity = kwargs .get ("parity" , None )
81+ self .comm_params .stopbits = kwargs .get ("stopbits" , None )
82+ self .comm_params .handle_local_echo = kwargs .get ("handle_local_echo" , False )
6983 self .ctx = ModbusClientProtocol (
7084 framer ,
71- CommParams (
72- comm_type = comm_type ,
73- comm_name = "comm" ,
74- source_address = source_address ,
75- reconnect_delay = reconnect_delay ,
76- reconnect_delay_max = reconnect_delay_max ,
77- timeout_connect = timeout ,
78- host = kwargs .get ("host" , None ),
79- port = kwargs .get ("port" , 0 ),
80- sslctx = kwargs .get ("sslctx" , None ),
81- baudrate = kwargs .get ("baudrate" , None ),
82- bytesize = kwargs .get ("bytesize" , None ),
83- parity = kwargs .get ("parity" , None ),
84- stopbits = kwargs .get ("stopbits" , None ),
85- handle_local_echo = kwargs .get ("handle_local_echo" , False ),
86- ),
85+ self .comm_params ,
8786 on_connect_callback ,
8887 )
8988 self .no_resend_on_retry = no_resend_on_retry
@@ -276,26 +275,28 @@ def __init__( # pylint: disable=too-many-arguments
276275 no_resend_on_retry : bool = False ,
277276 comm_type : CommType | None = None ,
278277 source_address : tuple [str , int ] | None = None ,
278+ comm_params : CommParams | None = None ,
279279 ** kwargs : Any ,
280280 ) -> None :
281281 """Initialize a client instance."""
282282 ModbusClientMixin .__init__ (self ) # type: ignore[arg-type]
283- self .comm_params = CommParams (
284- comm_type = comm_type ,
285- comm_name = "comm" ,
286- source_address = source_address ,
287- reconnect_delay = reconnect_delay ,
288- reconnect_delay_max = reconnect_delay_max ,
289- timeout_connect = timeout ,
290- host = kwargs .get ("host" , None ),
291- port = kwargs .get ("port" , 0 ),
292- sslctx = kwargs .get ("sslctx" , None ),
293- baudrate = kwargs .get ("baudrate" , None ),
294- bytesize = kwargs .get ("bytesize" , None ),
295- parity = kwargs .get ("parity" , None ),
296- stopbits = kwargs .get ("stopbits" , None ),
297- handle_local_echo = kwargs .get ("handle_local_echo" , False ),
298- )
283+ if comm_params :
284+ self .comm_params = comm_params
285+ if comm_type :
286+ self .comm_params .comm_type = comm_type
287+ self .comm_params .comm_name = "comm"
288+ self .comm_params .source_address = source_address
289+ self .comm_params .reconnect_delay = reconnect_delay
290+ self .comm_params .reconnect_delay_max = reconnect_delay_max
291+ self .comm_params .timeout_connect = timeout
292+ self .comm_params .host = kwargs .get ("host" , None )
293+ self .comm_params .port = kwargs .get ("port" , 0 )
294+ self .comm_params .sslctx = kwargs .get ("sslctx" , None )
295+ self .comm_params .baudrate = kwargs .get ("baudrate" , None )
296+ self .comm_params .bytesize = kwargs .get ("bytesize" , None )
297+ self .comm_params .parity = kwargs .get ("parity" , None )
298+ self .comm_params .stopbits = kwargs .get ("stopbits" , None )
299+ self .comm_params .handle_local_echo = kwargs .get ("handle_local_echo" , False )
299300 self .params = self ._params ()
300301 self .params .retries = int (retries )
301302 self .params .retry_on_empty = bool (retry_on_empty )
0 commit comments