Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions doc/source/library/pymodbus.client.asynchronous.factory.rst

This file was deleted.

1 change: 0 additions & 1 deletion doc/source/library/pymodbus.client.asynchronous.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Subpackages
.. toctree::

pymodbus.client.asynchronous.async_io
pymodbus.client.asynchronous.factory

Submodules
----------
Expand Down
18 changes: 9 additions & 9 deletions pymodbus/client/asynchronous/async_io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ async def _connect(self):
except Exception as exc: # pylint: disable=broad-except
txt = f"Failed to connect: {exc}"
_logger.warning(txt)
asyncio.ensure_future(self._reconnect(), loop=self.loop)
asyncio.ensure_future(self._reconnect())
else:
txt = f"Connected to {self.host}:{self.port}."
_logger.info(txt)
Expand Down Expand Up @@ -324,7 +324,7 @@ def protocol_lost_connection(self, protocol):
self.connected = False
self.protocol = None
if self.host:
asyncio.ensure_future(self._reconnect(), loop=self.loop)
asyncio.ensure_future(self._reconnect())
else:
_logger.error(TEST_FACTORY)

Expand Down Expand Up @@ -384,7 +384,7 @@ async def connect(self):
except Exception as exc: # pylint: disable=broad-except
txt = f"Failed to connect: {exc}"
_logger.warning(txt)
# asyncio.asynchronous(self._reconnect(), loop=self.loop)
# asyncio.asynchronous(self._reconnect())

def protocol_made_connection(self, protocol):
"""Notify successful connection."""
Expand All @@ -408,7 +408,7 @@ def protocol_lost_connection(self, protocol):
self.connected = False
self.protocol = None
# if self.host:
# asyncio.asynchronous(self._reconnect(), loop=self.loop)
# asyncio.asynchronous(self._reconnect())
else:
_logger.error(TEST_FACTORY)

Expand Down Expand Up @@ -464,7 +464,7 @@ async def _connect(self):
except Exception as exc: # pylint: disable=broad-except
txt = f"Failed to connect: {exc}"
_logger.warning(txt)
asyncio.ensure_future(self._reconnect(), loop=self.loop)
asyncio.ensure_future(self._reconnect())
else:
txt = f"Connected to {self.host}:{self.port}."
_logger.info(txt)
Expand Down Expand Up @@ -564,7 +564,7 @@ async def _connect(self):
except Exception as exc: # pylint: disable=broad-except
txt = f"Failed to connect: {exc}"
_logger.warning(txt)
asyncio.ensure_future(self._reconnect(), loop=self.loop)
asyncio.ensure_future(self._reconnect())

def protocol_made_connection(self, protocol):
"""Notify successful connection."""
Expand Down Expand Up @@ -658,7 +658,7 @@ async def connect(self):
except Exception as exc: # pylint: disable=broad-except
txt = f"Failed to connect: {exc}"
_logger.warning(txt)
# asyncio.asynchronous(self._reconnect(), loop=self.loop)
# asyncio.asynchronous(self._reconnect())

def protocol_made_connection(self, protocol):
"""Protocol notification of successful connection."""
Expand All @@ -682,7 +682,7 @@ def protocol_lost_connection(self, protocol):
self.connected = False
self.protocol = None
# if self.host:
# asyncio.asynchronous(self._reconnect(), loop=self.loop)
# asyncio.asynchronous(self._reconnect())
else:
_logger.error(TEST_FACTORY)

Expand Down Expand Up @@ -784,7 +784,7 @@ def protocol_lost_connection(self, protocol):
self._connected_event.clear()
self.protocol = None
# if self.host:
# asyncio.asynchronous(self._reconnect(), loop=self.loop)
# asyncio.asynchronous(self._reconnect())
else:
_logger.error(TEST_FACTORY)

Expand Down
1 change: 0 additions & 1 deletion pymodbus/client/asynchronous/factory/__init__.py

This file was deleted.

37 changes: 0 additions & 37 deletions pymodbus/client/asynchronous/factory/serial.py

This file was deleted.

40 changes: 0 additions & 40 deletions pymodbus/client/asynchronous/factory/tcp.py

This file was deleted.

53 changes: 0 additions & 53 deletions pymodbus/client/asynchronous/factory/tls.py

This file was deleted.

37 changes: 0 additions & 37 deletions pymodbus/client/asynchronous/factory/udp.py

This file was deleted.

26 changes: 21 additions & 5 deletions pymodbus/client/asynchronous/serial.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
"""SERIAL communication."""
import asyncio
import logging

from pymodbus.client.asynchronous.async_io import AsyncioModbusSerialClient as serialClient
from pymodbus.client.asynchronous.factory.serial import async_io_factory
from pymodbus.factory import ClientDecoder
from pymodbus.client.asynchronous.async_io import (
AsyncioModbusSerialClient,
ModbusClientProtocol,
)

_logger = logging.getLogger(__name__)


class AsyncModbusSerialClient(serialClient):
class AsyncModbusSerialClient(AsyncioModbusSerialClient):
"""Actual Async Serial Client to be used.

To use do::
Expand All @@ -29,5 +32,18 @@ def __new__(cls, framer, port, **kwargs):
:return:
"""
framer = framer(ClientDecoder())
yieldable = async_io_factory(framer=framer, port=port, **kwargs)
return yieldable
try:
loop = kwargs.pop("loop", None) or asyncio.get_running_loop()
except RuntimeError:
loop = asyncio.new_event_loop()

proto_cls = kwargs.get("proto_cls") or ModbusClientProtocol

client = AsyncioModbusSerialClient(port, proto_cls, framer, **kwargs)
coro = client.connect
if not loop.is_running():
loop.run_until_complete(coro())
else: # loop is not asyncio.get_event_loop():
future = asyncio.run_coroutine_threadsafe(coro(), loop=loop)
future.result()
return client
Loading