@@ -234,7 +234,7 @@ class ReconnectingAsyncioModbusTcpClient(object):
234
234
#: Maximum delay in milli seconds before reconnect is attempted.
235
235
DELAY_MAX_MS = 1000 * 60 * 5
236
236
237
- def __init__ (self , protocol_class = None , loop = None ):
237
+ def __init__ (self , protocol_class = None , loop = None , ** kwargs ):
238
238
"""
239
239
Initialize ReconnectingAsyncioModbusTcpClient
240
240
:param protocol_class: Protocol used to talk to modbus device.
@@ -251,6 +251,7 @@ def __init__(self, protocol_class=None, loop=None):
251
251
self .connected = False
252
252
#: Reconnect delay in milli seconds.
253
253
self .delay_ms = self .DELAY_MIN_MS
254
+ self ._proto_args = kwargs
254
255
255
256
def reset_delay (self ):
256
257
"""
@@ -291,7 +292,7 @@ def _create_protocol(self):
291
292
"""
292
293
Factory function to create initialized protocol instance.
293
294
"""
294
- protocol = self .protocol_class ()
295
+ protocol = self .protocol_class (** self . _proto_args )
295
296
protocol .factory = self
296
297
return protocol
297
298
@@ -350,7 +351,7 @@ def _reconnect(self):
350
351
class AsyncioModbusTcpClient (object ):
351
352
"""Client to connect to modbus device over TCP/IP."""
352
353
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 ):
354
355
"""
355
356
Initializes Asyncio Modbus Tcp Client
356
357
:param host: Host IP address
@@ -369,6 +370,7 @@ def __init__(self, host=None, port=502, protocol_class=None, loop=None):
369
370
self .port = port
370
371
371
372
self .connected = False
373
+ self ._proto_args = kwargs
372
374
373
375
def stop (self ):
374
376
"""
@@ -384,7 +386,7 @@ def _create_protocol(self):
384
386
"""
385
387
Factory function to create initialized protocol instance.
386
388
"""
387
- protocol = self .protocol_class ()
389
+ protocol = self .protocol_class (** self . _proto_args )
388
390
protocol .factory = self
389
391
return protocol
390
392
@@ -439,14 +441,14 @@ class ReconnectingAsyncioModbusTlsClient(ReconnectingAsyncioModbusTcpClient):
439
441
"""
440
442
Client to connect to modbus device repeatedly over TLS."
441
443
"""
442
- def __init__ (self , protocol_class = None , loop = None , framer = None ):
444
+ def __init__ (self , protocol_class = None , loop = None , framer = None , ** kwargs ):
443
445
"""
444
446
Initialize ReconnectingAsyncioModbusTcpClient
445
447
:param protocol_class: Protocol used to talk to modbus device.
446
448
:param loop: Event loop to use
447
449
"""
448
450
self .framer = framer
449
- ReconnectingAsyncioModbusTcpClient .__init__ (self , protocol_class , loop )
451
+ ReconnectingAsyncioModbusTcpClient .__init__ (self , protocol_class , loop , ** kwargs )
450
452
451
453
@asyncio .coroutine
452
454
def start (self , host , port = 802 , sslctx = None , server_hostname = None ):
@@ -490,7 +492,7 @@ def _create_protocol(self):
490
492
"""
491
493
Factory function to create initialized protocol instance.
492
494
"""
493
- protocol = self .protocol_class (framer = self .framer )
495
+ protocol = self .protocol_class (framer = self .framer , ** self . _proto_args )
494
496
protocol .transaction = FifoTransactionManager (self )
495
497
protocol .factory = self
496
498
return protocol
@@ -506,7 +508,7 @@ class ReconnectingAsyncioModbusUdpClient(object):
506
508
#: Maximum delay in milli seconds before reconnect is attempted.
507
509
DELAY_MAX_MS = 1000 * 60 * 5
508
510
509
- def __init__ (self , protocol_class = None , loop = None ):
511
+ def __init__ (self , protocol_class = None , loop = None , ** kwargs ):
510
512
"""
511
513
Initializes ReconnectingAsyncioModbusUdpClient
512
514
:param protocol_class: Protocol used to talk to modbus device.
@@ -523,6 +525,7 @@ def __init__(self, protocol_class=None, loop=None):
523
525
self .port = 0
524
526
525
527
self .connected = False
528
+ self ._proto_args = kwargs
526
529
self .reset_delay ()
527
530
528
531
def reset_delay (self ):
@@ -572,7 +575,7 @@ def _create_protocol(self, host=None, port=0):
572
575
"""
573
576
Factory function to create initialized protocol instance.
574
577
"""
575
- protocol = self .protocol_class ()
578
+ protocol = self .protocol_class (** self . _proto_args )
576
579
protocol .host = host
577
580
protocol .port = port
578
581
protocol .factory = self
@@ -637,7 +640,7 @@ class AsyncioModbusUdpClient(object):
637
640
Client to connect to modbus device over UDP.
638
641
"""
639
642
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 ):
641
644
"""
642
645
Initializes Asyncio Modbus UDP Client
643
646
:param host: Host IP address
@@ -656,6 +659,7 @@ def __init__(self, host=None, port=502, protocol_class=None, loop=None):
656
659
self .port = port
657
660
658
661
self .connected = False
662
+ self ._proto_args = kwargs
659
663
660
664
def stop (self ):
661
665
"""
@@ -674,7 +678,7 @@ def _create_protocol(self, host=None, port=0):
674
678
"""
675
679
Factory function to create initialized protocol instance.
676
680
"""
677
- protocol = self .protocol_class ()
681
+ protocol = self .protocol_class (** self . _proto_args )
678
682
protocol .host = host
679
683
protocol .port = port
680
684
protocol .factory = self
@@ -842,7 +846,7 @@ def init_tcp_client(proto_cls, loop, host, port, **kwargs):
842
846
:return:
843
847
"""
844
848
client = ReconnectingAsyncioModbusTcpClient (protocol_class = proto_cls ,
845
- loop = loop )
849
+ loop = loop , ** kwargs )
846
850
yield from client .start (host , port )
847
851
return client
848
852
@@ -863,7 +867,8 @@ def init_tls_client(proto_cls, loop, host, port, sslctx=None,
863
867
:return:
864
868
"""
865
869
client = ReconnectingAsyncioModbusTlsClient (protocol_class = proto_cls ,
866
- loop = loop , framer = framer )
870
+ loop = loop , framer = framer ,
871
+ ** kwargs )
867
872
yield from client .start (host , port , sslctx , server_hostname )
868
873
return client
869
874
@@ -880,6 +885,6 @@ def init_udp_client(proto_cls, loop, host, port, **kwargs):
880
885
:return:
881
886
"""
882
887
client = ReconnectingAsyncioModbusUdpClient (protocol_class = proto_cls ,
883
- loop = loop )
888
+ loop = loop , ** kwargs )
884
889
yield from client .start (host , port )
885
890
return client
0 commit comments