@@ -234,7 +234,7 @@ class ReconnectingAsyncioModbusTcpClient(object):
234234 #: Maximum delay in milli seconds before reconnect is attempted.
235235 DELAY_MAX_MS = 1000 * 60 * 5
236236
237- def __init__ (self , protocol_class = None , loop = None ):
237+ def __init__ (self , protocol_class = None , loop = None , ** kwargs ):
238238 """
239239 Initialize ReconnectingAsyncioModbusTcpClient
240240 :param protocol_class: Protocol used to talk to modbus device.
@@ -251,6 +251,7 @@ def __init__(self, protocol_class=None, loop=None):
251251 self .connected = False
252252 #: Reconnect delay in milli seconds.
253253 self .delay_ms = self .DELAY_MIN_MS
254+ self ._proto_args = kwargs
254255
255256 def reset_delay (self ):
256257 """
@@ -291,7 +292,7 @@ def _create_protocol(self):
291292 """
292293 Factory function to create initialized protocol instance.
293294 """
294- protocol = self .protocol_class ()
295+ protocol = self .protocol_class (** self . _proto_args )
295296 protocol .factory = self
296297 return protocol
297298
@@ -350,7 +351,7 @@ def _reconnect(self):
350351class AsyncioModbusTcpClient (object ):
351352 """Client to connect to modbus device over TCP/IP."""
352353
353- def __init__ (self , host = None , port = 502 , protocol_class = None , loop = None ):
354+ def __init__ (self , host = None , port = 502 , protocol_class = None , loop = None , ** kwargs ):
354355 """
355356 Initializes Asyncio Modbus Tcp Client
356357 :param host: Host IP address
@@ -369,6 +370,7 @@ def __init__(self, host=None, port=502, protocol_class=None, loop=None):
369370 self .port = port
370371
371372 self .connected = False
373+ self ._proto_args = kwargs
372374
373375 def stop (self ):
374376 """
@@ -384,7 +386,7 @@ def _create_protocol(self):
384386 """
385387 Factory function to create initialized protocol instance.
386388 """
387- protocol = self .protocol_class ()
389+ protocol = self .protocol_class (** self . _proto_args )
388390 protocol .factory = self
389391 return protocol
390392
@@ -439,14 +441,14 @@ class ReconnectingAsyncioModbusTlsClient(ReconnectingAsyncioModbusTcpClient):
439441 """
440442 Client to connect to modbus device repeatedly over TLS."
441443 """
442- def __init__ (self , protocol_class = None , loop = None , framer = None ):
444+ def __init__ (self , protocol_class = None , loop = None , framer = None , ** kwargs ):
443445 """
444446 Initialize ReconnectingAsyncioModbusTcpClient
445447 :param protocol_class: Protocol used to talk to modbus device.
446448 :param loop: Event loop to use
447449 """
448450 self .framer = framer
449- ReconnectingAsyncioModbusTcpClient .__init__ (self , protocol_class , loop )
451+ ReconnectingAsyncioModbusTcpClient .__init__ (self , protocol_class , loop , ** kwargs )
450452
451453 @asyncio .coroutine
452454 def start (self , host , port = 802 , sslctx = None , server_hostname = None ):
@@ -490,7 +492,7 @@ def _create_protocol(self):
490492 """
491493 Factory function to create initialized protocol instance.
492494 """
493- protocol = self .protocol_class (framer = self .framer )
495+ protocol = self .protocol_class (framer = self .framer , ** self . _proto_args )
494496 protocol .transaction = FifoTransactionManager (self )
495497 protocol .factory = self
496498 return protocol
@@ -506,7 +508,7 @@ class ReconnectingAsyncioModbusUdpClient(object):
506508 #: Maximum delay in milli seconds before reconnect is attempted.
507509 DELAY_MAX_MS = 1000 * 60 * 5
508510
509- def __init__ (self , protocol_class = None , loop = None ):
511+ def __init__ (self , protocol_class = None , loop = None , ** kwargs ):
510512 """
511513 Initializes ReconnectingAsyncioModbusUdpClient
512514 :param protocol_class: Protocol used to talk to modbus device.
@@ -523,6 +525,7 @@ def __init__(self, protocol_class=None, loop=None):
523525 self .port = 0
524526
525527 self .connected = False
528+ self ._proto_args = kwargs
526529 self .reset_delay ()
527530
528531 def reset_delay (self ):
@@ -572,7 +575,7 @@ def _create_protocol(self, host=None, port=0):
572575 """
573576 Factory function to create initialized protocol instance.
574577 """
575- protocol = self .protocol_class ()
578+ protocol = self .protocol_class (** self . _proto_args )
576579 protocol .host = host
577580 protocol .port = port
578581 protocol .factory = self
@@ -637,7 +640,7 @@ class AsyncioModbusUdpClient(object):
637640 Client to connect to modbus device over UDP.
638641 """
639642
640- def __init__ (self , host = None , port = 502 , protocol_class = None , loop = None ):
643+ def __init__ (self , host = None , port = 502 , protocol_class = None , loop = None , ** kwargs ):
641644 """
642645 Initializes Asyncio Modbus UDP Client
643646 :param host: Host IP address
@@ -656,6 +659,7 @@ def __init__(self, host=None, port=502, protocol_class=None, loop=None):
656659 self .port = port
657660
658661 self .connected = False
662+ self ._proto_args = kwargs
659663
660664 def stop (self ):
661665 """
@@ -674,7 +678,7 @@ def _create_protocol(self, host=None, port=0):
674678 """
675679 Factory function to create initialized protocol instance.
676680 """
677- protocol = self .protocol_class ()
681+ protocol = self .protocol_class (** self . _proto_args )
678682 protocol .host = host
679683 protocol .port = port
680684 protocol .factory = self
@@ -842,7 +846,7 @@ def init_tcp_client(proto_cls, loop, host, port, **kwargs):
842846 :return:
843847 """
844848 client = ReconnectingAsyncioModbusTcpClient (protocol_class = proto_cls ,
845- loop = loop )
849+ loop = loop , ** kwargs )
846850 yield from client .start (host , port )
847851 return client
848852
@@ -863,7 +867,8 @@ def init_tls_client(proto_cls, loop, host, port, sslctx=None,
863867 :return:
864868 """
865869 client = ReconnectingAsyncioModbusTlsClient (protocol_class = proto_cls ,
866- loop = loop , framer = framer )
870+ loop = loop , framer = framer ,
871+ ** kwargs )
867872 yield from client .start (host , port , sslctx , server_hostname )
868873 return client
869874
@@ -880,6 +885,6 @@ def init_udp_client(proto_cls, loop, host, port, **kwargs):
880885 :return:
881886 """
882887 client = ReconnectingAsyncioModbusUdpClient (protocol_class = proto_cls ,
883- loop = loop )
888+ loop = loop , ** kwargs )
884889 yield from client .start (host , port )
885890 return client
0 commit comments