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
3 changes: 0 additions & 3 deletions doc/source/library/pymodbus.client.asynchronous.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Subpackages

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

Submodules
----------
Expand Down Expand Up @@ -49,5 +48,3 @@ pymodbus\.client\.asynchronous\.udp module
:members:
:undoc-members:
:show-inheritance:


This file was deleted.

6 changes: 2 additions & 4 deletions examples/common/async_asyncio_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

# from pymodbus.client.asynchronous.udp import (
# AsyncModbusUDPClient as ModbusClient)
from pymodbus.client.asynchronous import schedulers

# ----------------------------------------------------------------------- #
# Import the required asynchronous client
Expand Down Expand Up @@ -132,7 +131,7 @@ def run_with_not_running_loop():
assert not loop.is_running() # nosec
asyncio.set_event_loop(loop)
new_loop, client = ModbusClient( # pylint: disable=unpacking-non-sequence
schedulers.ASYNC_IO, port=5020, loop=loop
port=5020, loop=loop
)
loop.run_until_complete(start_async_test(client.protocol))
loop.close()
Expand Down Expand Up @@ -163,7 +162,6 @@ def start_loop(loop):
assert loop.is_running() # nosec
asyncio.set_event_loop(loop)
loop, client = ModbusClient( # pylint: disable=unpacking-non-sequence
schedulers.ASYNC_IO,
port=5020,
loop=loop,
)
Expand All @@ -182,7 +180,7 @@ def run_with_no_loop():
"""Create a loop."""
_logger.debug("---------------------RUN_WITH_NO_LOOP-----------------")
loop, client = ModbusClient( # pylint: disable=unpacking-non-sequence
schedulers.ASYNC_IO, port=5020
port=5020
)
loop.run_until_complete(start_async_test(client.protocol))
loop.close()
Expand Down
2 changes: 0 additions & 2 deletions examples/common/async_asyncio_serial_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import asyncio
import logging

from pymodbus.client.asynchronous import schedulers
from pymodbus.client.asynchronous.serial import AsyncModbusSerialClient as ModbusClient

# --------------------------------------------------------------------------- #
Expand Down Expand Up @@ -128,7 +127,6 @@ async def start_async_test(client): # pylint: disable=redefined-outer-name
# socat -d -d PTY,link=/tmp/ptyp0,raw,echo=0,ispeed=9600 PTY,
# link=/tmp/ttyp0,raw,echo=0,ospeed=9600
loop, client = ModbusClient( # pylint: disable=unpacking-non-sequence
schedulers.ASYNC_IO,
port="/tmp/ttyp0", # nosec
baudrate=9600,
method="rtu",
Expand Down
2 changes: 0 additions & 2 deletions examples/contrib/asynchronous_asyncio_modbus_tls_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# -------------------------------------------------------------------------- #
import ssl

from pymodbus.client.asynchronous.schedulers import ASYNC_IO
from pymodbus.client.asynchronous.tls import AsyncModbusTLSClient

# -------------------------------------------------------------------------- #
Expand Down Expand Up @@ -39,7 +38,6 @@ async def start_async_test(client):
# pass SSLContext which is the context here to ModbusTcpClient()
# ----------------------------------------------------------------------- #
loop, new_client = AsyncModbusTLSClient( # pylint: disable=unpacking-non-sequence
ASYNC_IO,
"test.host.com",
8020,
sslctx=sslctx,
Expand Down
4 changes: 1 addition & 3 deletions pymodbus/client/asynchronous/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

Example run::

from pymodbus.client.asynchronous import schedulers

# Import The clients

from pymodbus.client.asynchronous.tcp import AsyncModbusTCPClient as Client
from pymodbus.client.asynchronous.serial import AsyncModbusSerialClient as Client
from pymodbus.client.asynchronous.udp import AsyncModbusUDPClient as Client

# For asynchronous client use
event_loop, client = Client(schedulers.ASYNC_IO, port=5020)
event_loop, client = Client(port=5020)
"""
2 changes: 1 addition & 1 deletion pymodbus/client/asynchronous/factory/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def async_io_factory(port=None, framer=None, **kwargs):


def get_factory():
"""Get protocol factory based on the backend scheduler being used.
"""Get protocol factory.

:return: new factory
"""
Expand Down
2 changes: 1 addition & 1 deletion pymodbus/client/asynchronous/factory/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def async_io_factory(host="127.0.0.1", port=Defaults.Port, **kwargs):


def get_factory():
"""Get protocol factory based on the backend scheduler being used.
"""Get protocol factory.

:return: new factory
"""
Expand Down
2 changes: 1 addition & 1 deletion pymodbus/client/asynchronous/factory/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def async_io_factory(


def get_factory():
"""Get protocol factory based on the backend scheduler being used.
"""Get protocol factory.

:return: protocol object
"""
Expand Down
2 changes: 1 addition & 1 deletion pymodbus/client/asynchronous/factory/udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def async_io_factory(host="127.0.0.1", port=Defaults.Port, **kwargs):


def get_factory():
"""Get protocol factory based on the backend scheduler being used.
"""Get protocol factory.

:return: new factory
"""
Expand Down
4 changes: 0 additions & 4 deletions pymodbus/client/asynchronous/schedulers/__init__.py

This file was deleted.

11 changes: 2 additions & 9 deletions pymodbus/client/asynchronous/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging

from pymodbus.client.asynchronous.factory.serial import get_factory
from pymodbus.client.asynchronous.schedulers import ASYNC_IO
from pymodbus.exceptions import ParameterException
from pymodbus.factory import ClientDecoder
from pymodbus.transaction import (
Expand Down Expand Up @@ -42,29 +41,23 @@ def _framer(cls, method):

raise ParameterException("Invalid framer method requested")

def __new__(cls, scheduler, method, port, **kwargs):
"""Use scheduler async_io (asyncio).
def __new__(cls, method, port, **kwargs):
"""Do setup of client.

The methods to connect are::
- ascii
- rtu
- binary
:param scheduler: R.I.P.
:param method: The method to use for connection
:param port: The serial port to attach to
:param stopbits: The number of stop bits to use
:param bytesize: The bytesize of the serial messages
:param parity: Which kind of parity to use
:param baudrate: The baud rate to use for the serial device
:param timeout: The timeout between serial requests (default 3s)
:param scheduler:
:param method:
:param port:
:param kwargs:
:return:
"""
if scheduler != ASYNC_IO:
_logger.error("Scheduler is no longer used.")
factory_class = get_factory()
framer = cls._framer(method)
yieldable = factory_class(framer=framer, port=port, **kwargs)
Expand Down
5 changes: 0 additions & 5 deletions pymodbus/client/asynchronous/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging

from pymodbus.client.asynchronous.factory.tcp import get_factory
from pymodbus.client.asynchronous.schedulers import ASYNC_IO
from pymodbus.constants import Defaults

_logger = logging.getLogger(__name__)
Expand All @@ -17,7 +16,6 @@ class AsyncModbusTCPClient: # pylint: disable=too-few-public-methods

def __new__(
cls,
scheduler,
host="127.0.0.1",
port=Defaults.Port,
framer=None,
Expand All @@ -27,7 +25,6 @@ def __new__(
):
"""Scheduler to use async_io (asyncio)

:param scheduler: R.I.P.
:param host: Host IP address
:param port: Port
:param framer: Modbus Framer to use
Expand All @@ -36,8 +33,6 @@ def __new__(
:param kwargs: Other extra args specific to Backend being used
:return:
"""
if scheduler != ASYNC_IO:
_logger.error("Scheduler is no longer used.")
factory_class = get_factory()
yieldable = factory_class(
host=host,
Expand Down
7 changes: 1 addition & 6 deletions pymodbus/client/asynchronous/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging

from pymodbus.client.asynchronous.factory.tls import get_factory
from pymodbus.client.asynchronous.schedulers import ASYNC_IO
from pymodbus.constants import Defaults
from pymodbus.factory import ClientDecoder
from pymodbus.transaction import ModbusTlsFramer
Expand All @@ -19,7 +18,6 @@ class AsyncModbusTLSClient: # pylint: disable=too-few-public-methods

def __new__( # pylint: disable=too-many-arguments
cls,
scheduler,
host="127.0.0.1",
port=Defaults.TLSPort,
framer=None,
Expand All @@ -31,9 +29,8 @@ def __new__( # pylint: disable=too-many-arguments
timeout=None,
**kwargs
):
"""Use scheduler async_io (asyncio)
"""Do setup of client.

:param scheduler: R.I.P.
:param host: Target server"s name, also matched for certificate
:param port: Port
:param framer: Modbus Framer to use
Expand All @@ -46,8 +43,6 @@ def __new__( # pylint: disable=too-many-arguments
:param kwargs: Other extra args specific to Backend being used
:return:
"""
if scheduler != ASYNC_IO:
_logger.error("Scheduler is no longer used.")
framer = framer or ModbusTlsFramer(ClientDecoder())
factory_class = get_factory()
yieldable = factory_class(
Expand Down
7 changes: 1 addition & 6 deletions pymodbus/client/asynchronous/udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging

from pymodbus.client.asynchronous.factory.udp import get_factory
from pymodbus.client.asynchronous.schedulers import ASYNC_IO
from pymodbus.constants import Defaults

_logger = logging.getLogger(__name__)
Expand All @@ -17,17 +16,15 @@ class AsyncModbusUDPClient: # pylint: disable=too-few-public-methods

def __new__(
cls,
scheduler,
host="127.0.0.1",
port=Defaults.Port,
framer=None,
source_address=None,
timeout=None,
**kwargs
):
"""Use scheduler async_io (asyncio).
"""Do setup of client.

:param scheduler: R.I.P.
:param host: Host IP address
:param port: Port
:param framer: Modbus Framer to use
Expand All @@ -36,8 +33,6 @@ def __new__(
:param kwargs: Other extra args specific to Backend being used
:return:
"""
if scheduler != ASYNC_IO:
_logger.error("Scheduler is no longer used.")
factory_class = get_factory()
yieldable = factory_class(
host=host,
Expand Down
6 changes: 1 addition & 5 deletions test/test_client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import pytest

from pymodbus.client.asynchronous import schedulers
from pymodbus.client.asynchronous.async_io import (
AsyncioModbusSerialClient,
ReconnectingAsyncioModbusTlsClient,
Expand Down Expand Up @@ -63,9 +62,7 @@ def test_tcp_asyncio_client(

def test_tls_asyncio_client(self):
"""Test the TLS AsyncIO client."""
_, client = AsyncModbusTLSClient( # pylint: disable=unpacking-non-sequence
schedulers.ASYNC_IO
)
_, client = AsyncModbusTLSClient() # pylint: disable=unpacking-non-sequence
assert isinstance(client, ReconnectingAsyncioModbusTlsClient) # nosec
assert isinstance(client.framer, ModbusTlsFramer) # nosec
assert isinstance(client.sslctx, ssl.SSLContext) # nosec
Expand Down Expand Up @@ -115,7 +112,6 @@ async def test_serial_asyncio_client(
loop,
client,
) = AsyncModbusSerialClient(
schedulers.ASYNC_IO,
method=method,
port=pytest.SERIAL_PORT,
loop=loop,
Expand Down
6 changes: 1 addition & 5 deletions test/test_client_async2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import pytest

from pymodbus.client.asynchronous import schedulers
from pymodbus.client.asynchronous.async_io import (
AsyncioModbusSerialClient,
ReconnectingAsyncioModbusTlsClient,
Expand Down Expand Up @@ -51,9 +50,7 @@ class TestAsynchronousClient:
# -----------------------------------------------------------------------#
def test_tls_asyncio_client(self):
"""Test the TLS AsyncIO client."""
_, client = AsyncModbusTLSClient( # pylint: disable=unpacking-non-sequence
schedulers.ASYNC_IO
)
_, client = AsyncModbusTLSClient() # pylint: disable=unpacking-non-sequence
assert isinstance(client, ReconnectingAsyncioModbusTlsClient) # nosec
assert isinstance(client.framer, ModbusTlsFramer) # nosec
assert isinstance(client.sslctx, ssl.SSLContext) # nosec
Expand Down Expand Up @@ -101,7 +98,6 @@ def test_serial_asyncio_client(
loop,
client,
) = AsyncModbusSerialClient(
schedulers.ASYNC_IO,
method=method,
port=pytest.SERIAL_PORT,
loop=loop,
Expand Down
16 changes: 5 additions & 11 deletions test/test_client_async_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import pytest

from pymodbus.bit_read_message import ReadCoilsRequest, ReadCoilsResponse
from pymodbus.client.asynchronous import schedulers
from pymodbus.client.asynchronous.async_io import (
BaseModbusAsyncClientProtocol,
ModbusClientProtocol,
Expand Down Expand Up @@ -98,7 +97,6 @@ def test_factory_initialization_state(self):
async def test_initialization_tcp_in_loop(self):
"""Test initialization tcp in loop."""
_, client = AsyncModbusTCPClient( # pylint: disable=unpacking-non-sequence
schedulers.ASYNC_IO,
port=5020,
)
client = await client
Expand All @@ -109,30 +107,26 @@ async def test_initialization_tcp_in_loop(self):

async def test_initialization_udp_in_loop(self):
"""Test initialization udp in loop."""
_, client = AsyncModbusUDPClient( # pylint: disable=unpacking-non-sequence
schedulers.ASYNC_IO, port=5020
)
_, client = AsyncModbusUDPClient() # pylint: disable=unpacking-non-sequence
client = await client

assert client.connected # nosec
assert client.port == 5020 # nosec
assert client.port == 502 # nosec
assert client.delay_ms < client.DELAY_MAX_MS # nosec

async def test_initialization_tls_in_loop(self):
"""Test initialization tls in loop."""
_, client = AsyncModbusTLSClient( # pylint: disable=unpacking-non-sequence
schedulers.ASYNC_IO, port=5020
)
_, client = AsyncModbusTLSClient() # pylint: disable=unpacking-non-sequence
client = await client

assert not client.connected # nosec
assert client.port == 5020 # nosec
assert client.port == 802 # nosec
assert client.delay_ms < client.DELAY_MAX_MS # nosec

def test_initialization_serial_in_loop(self):
"""Test initialization serial in loop."""
_, client = AsyncModbusSerialClient( # pylint: disable=unpacking-non-sequence
schedulers.ASYNC_IO, port="/tmp/ptyp0", baudrate=9600, method="rtu" # nosec
port="/tmp/ptyp0", baudrate=9600, method="rtu" # nosec
)
assert client.port == "/tmp/ptyp0" # nosec
assert client.baudrate == 9600 # nosec
Expand Down