-
Notifications
You must be signed in to change notification settings - Fork 1k
2.5.3 #660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2.5.3 #660
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -234,7 +234,7 @@ class ReconnectingAsyncioModbusTcpClient(object): | |
| #: Maximum delay in milli seconds before reconnect is attempted. | ||
| DELAY_MAX_MS = 1000 * 60 * 5 | ||
|
|
||
| def __init__(self, protocol_class=None, loop=None): | ||
| def __init__(self, protocol_class=None, loop=None, **kwargs): | ||
| """ | ||
| Initialize ReconnectingAsyncioModbusTcpClient | ||
| :param protocol_class: Protocol used to talk to modbus device. | ||
|
|
@@ -251,6 +251,7 @@ def __init__(self, protocol_class=None, loop=None): | |
| self.connected = False | ||
| #: Reconnect delay in milli seconds. | ||
| self.delay_ms = self.DELAY_MIN_MS | ||
| self._proto_args = kwargs | ||
|
|
||
| def reset_delay(self): | ||
| """ | ||
|
|
@@ -291,7 +292,7 @@ def _create_protocol(self): | |
| """ | ||
| Factory function to create initialized protocol instance. | ||
| """ | ||
| protocol = self.protocol_class() | ||
| protocol = self.protocol_class(**self._proto_args) | ||
| protocol.factory = self | ||
| return protocol | ||
|
|
||
|
|
@@ -350,7 +351,7 @@ def _reconnect(self): | |
| class AsyncioModbusTcpClient(object): | ||
| """Client to connect to modbus device over TCP/IP.""" | ||
|
|
||
| def __init__(self, host=None, port=502, protocol_class=None, loop=None): | ||
| def __init__(self, host=None, port=502, protocol_class=None, loop=None, **kwargs): | ||
| """ | ||
| Initializes Asyncio Modbus Tcp Client | ||
| :param host: Host IP address | ||
|
|
@@ -369,6 +370,7 @@ def __init__(self, host=None, port=502, protocol_class=None, loop=None): | |
| self.port = port | ||
|
|
||
| self.connected = False | ||
| self._proto_args = kwargs | ||
|
|
||
| def stop(self): | ||
| """ | ||
|
|
@@ -384,7 +386,7 @@ def _create_protocol(self): | |
| """ | ||
| Factory function to create initialized protocol instance. | ||
| """ | ||
| protocol = self.protocol_class() | ||
| protocol = self.protocol_class(**self._proto_args) | ||
| protocol.factory = self | ||
| return protocol | ||
|
|
||
|
|
@@ -439,14 +441,14 @@ class ReconnectingAsyncioModbusTlsClient(ReconnectingAsyncioModbusTcpClient): | |
| """ | ||
| Client to connect to modbus device repeatedly over TLS." | ||
| """ | ||
| def __init__(self, protocol_class=None, loop=None, framer=None): | ||
| def __init__(self, protocol_class=None, loop=None, framer=None, **kwargs): | ||
| """ | ||
| Initialize ReconnectingAsyncioModbusTcpClient | ||
| :param protocol_class: Protocol used to talk to modbus device. | ||
| :param loop: Event loop to use | ||
| """ | ||
| self.framer = framer | ||
| ReconnectingAsyncioModbusTcpClient.__init__(self, protocol_class, loop) | ||
| ReconnectingAsyncioModbusTcpClient.__init__(self, protocol_class, loop, **kwargs) | ||
|
|
||
| @asyncio.coroutine | ||
| def start(self, host, port=802, sslctx=None, server_hostname=None): | ||
|
|
@@ -490,7 +492,7 @@ def _create_protocol(self): | |
| """ | ||
| Factory function to create initialized protocol instance. | ||
| """ | ||
| protocol = self.protocol_class(framer=self.framer) | ||
| protocol = self.protocol_class(framer=self.framer, **self._proto_args) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. before this, remove framer from self._proto_args |
||
| protocol.transaction = FifoTransactionManager(self) | ||
| protocol.factory = self | ||
| return protocol | ||
|
|
@@ -506,7 +508,7 @@ class ReconnectingAsyncioModbusUdpClient(object): | |
| #: Maximum delay in milli seconds before reconnect is attempted. | ||
| DELAY_MAX_MS = 1000 * 60 * 5 | ||
|
|
||
| def __init__(self, protocol_class=None, loop=None): | ||
| def __init__(self, protocol_class=None, loop=None, **kwargs): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. before this, remove protocol_class and loop from kwargs |
||
| """ | ||
| Initializes ReconnectingAsyncioModbusUdpClient | ||
| :param protocol_class: Protocol used to talk to modbus device. | ||
|
|
@@ -523,6 +525,7 @@ def __init__(self, protocol_class=None, loop=None): | |
| self.port = 0 | ||
|
|
||
| self.connected = False | ||
| self._proto_args = kwargs | ||
| self.reset_delay() | ||
|
|
||
| def reset_delay(self): | ||
|
|
@@ -572,7 +575,7 @@ def _create_protocol(self, host=None, port=0): | |
| """ | ||
| Factory function to create initialized protocol instance. | ||
| """ | ||
| protocol = self.protocol_class() | ||
| protocol = self.protocol_class(**self._proto_args) | ||
| protocol.host = host | ||
| protocol.port = port | ||
| protocol.factory = self | ||
|
|
@@ -637,7 +640,7 @@ class AsyncioModbusUdpClient(object): | |
| Client to connect to modbus device over UDP. | ||
| """ | ||
|
|
||
| def __init__(self, host=None, port=502, protocol_class=None, loop=None): | ||
| def __init__(self, host=None, port=502, protocol_class=None, loop=None, **kwargs): | ||
| """ | ||
| Initializes Asyncio Modbus UDP Client | ||
| :param host: Host IP address | ||
|
|
@@ -656,6 +659,7 @@ def __init__(self, host=None, port=502, protocol_class=None, loop=None): | |
| self.port = port | ||
|
|
||
| self.connected = False | ||
| self._proto_args = kwargs | ||
|
|
||
| def stop(self): | ||
| """ | ||
|
|
@@ -674,7 +678,7 @@ def _create_protocol(self, host=None, port=0): | |
| """ | ||
| Factory function to create initialized protocol instance. | ||
| """ | ||
| protocol = self.protocol_class() | ||
| protocol = self.protocol_class(**self._proto_args) | ||
| protocol.host = host | ||
| protocol.port = port | ||
| protocol.factory = self | ||
|
|
@@ -842,7 +846,7 @@ def init_tcp_client(proto_cls, loop, host, port, **kwargs): | |
| :return: | ||
| """ | ||
| client = ReconnectingAsyncioModbusTcpClient(protocol_class=proto_cls, | ||
| loop=loop) | ||
| loop=loop, **kwargs) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. before this, remove loop and protocol_class from kwargs |
||
| yield from client.start(host, port) | ||
| return client | ||
|
|
||
|
|
@@ -863,7 +867,8 @@ def init_tls_client(proto_cls, loop, host, port, sslctx=None, | |
| :return: | ||
| """ | ||
| client = ReconnectingAsyncioModbusTlsClient(protocol_class=proto_cls, | ||
| loop=loop, framer=framer) | ||
| loop=loop, framer=framer, | ||
| **kwargs) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. before this, remove loop and framer from kwargs |
||
| yield from client.start(host, port, sslctx, server_hostname) | ||
| return client | ||
|
|
||
|
|
@@ -880,6 +885,6 @@ def init_udp_client(proto_cls, loop, host, port, **kwargs): | |
| :return: | ||
| """ | ||
| client = ReconnectingAsyncioModbusUdpClient(protocol_class=proto_cls, | ||
| loop=loop) | ||
| loop=loop, **kwargs) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. before this, remove from kwargs (i.e. {arg:argv[arg] for arg in kwargs if arg not in ["loop", "protocol_class"]} |
||
| yield from client.start(host, port) | ||
| return client | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,8 +77,7 @@ def io_loop_factory(host="127.0.0.1", port=Defaults.Port, framer=None, | |
| return protocol, future | ||
|
|
||
|
|
||
| def async_io_factory(host="127.0.0.1", port=Defaults.Port, framer=None, | ||
| source_address=None, timeout=None, **kwargs): | ||
| def async_io_factory(host="127.0.0.1", port=Defaults.Port, **kwargs): | ||
| """ | ||
| Factory to create asyncio based asynchronous tcp clients | ||
| :param host: Host IP address | ||
|
|
@@ -91,14 +90,14 @@ def async_io_factory(host="127.0.0.1", port=Defaults.Port, framer=None, | |
| """ | ||
| import asyncio | ||
| from pymodbus.client.asynchronous.async_io import init_tcp_client | ||
| loop = kwargs.get("loop") or asyncio.new_event_loop() | ||
| proto_cls = kwargs.get("proto_cls", None) | ||
| loop = kwargs.pop("loop", None) or asyncio.new_event_loop() | ||
| proto_cls = kwargs.pop("proto_cls", None) | ||
| if not loop.is_running(): | ||
| asyncio.set_event_loop(loop) | ||
| cor = init_tcp_client(proto_cls, loop, host, port) | ||
| cor = init_tcp_client(proto_cls, loop, host, port, **kwargs) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. before this, remove from kwargs (i.e. {arg:argv[arg] for arg in kwargs if arg not in ["proto_cls","loop","host","port"]} |
||
| client = loop.run_until_complete(asyncio.gather(cor))[0] | ||
| else: | ||
| cor = init_tcp_client(proto_cls, loop, host, port) | ||
| cor = init_tcp_client(proto_cls, loop, host, port, **kwargs) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. before this, remove from kwargs (i.e. {arg:argv[arg] for arg in kwargs if arg not in ["proto_cls","loop","host","port"]} |
||
| future = asyncio.run_coroutine_threadsafe(cor, loop=loop) | ||
| client = future.result() | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,8 +52,7 @@ def io_loop_factory(host="127.0.0.1", port=Defaults.Port, framer=None, | |
| return protocol, future | ||
|
|
||
|
|
||
| def async_io_factory(host="127.0.0.1", port=Defaults.Port, framer=None, | ||
| source_address=None, timeout=None, **kwargs): | ||
| def async_io_factory(host="127.0.0.1", port=Defaults.Port, **kwargs): | ||
| """ | ||
| Factory to create asyncio based asynchronous udp clients | ||
| :param host: Host IP address | ||
|
|
@@ -66,9 +65,9 @@ def async_io_factory(host="127.0.0.1", port=Defaults.Port, framer=None, | |
| """ | ||
| import asyncio | ||
| from pymodbus.client.asynchronous.async_io import init_udp_client | ||
| loop = kwargs.get("loop") or asyncio.get_event_loop() | ||
| proto_cls = kwargs.get("proto_cls", None) | ||
| cor = init_udp_client(proto_cls, loop, host, port) | ||
| loop = kwargs.pop("loop", None) or asyncio.get_event_loop() | ||
| proto_cls = kwargs.pop("proto_cls", None) | ||
| cor = init_udp_client(proto_cls, loop, host, port, **kwargs) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. before this, remove from kwargs (i.e. {arg:argv[arg] for arg in kwargs if arg not in ["proto_cls","loop","host","port"]} |
||
| if not loop.is_running(): | ||
| client = loop.run_until_complete(asyncio.gather(cor))[0] | ||
| else: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before this, remove protocol_class and loop from kwargs