Skip to content
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

Merge new message layer and old framer directory. #2135

Merged
merged 5 commits into from
Mar 29, 2024
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
1 change: 1 addition & 0 deletions API_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ API changes 3.7.0
- on_reconnect_callback() removed from clients (sync/async).
- on_connect_callback(true/false) added to async clients.
- binary framer no longer supported
- Framer.<type> renamed to FramerType.<type>


API changes 3.6.0
Expand Down
2 changes: 1 addition & 1 deletion check_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ codespell
ruff check --fix --exit-non-zero-on-fix .
pylint --recursive=y examples pymodbus test
mypy pymodbus
pytest --cov --numprocesses auto
pytest -x --cov --numprocesses auto
echo "Ready to push"
Binary file modified doc/source/_static/examples.tgz
Binary file not shown.
Binary file modified doc/source/_static/examples.zip
Binary file not shown.
9 changes: 5 additions & 4 deletions doc/source/library/architecture/architecture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ The internal structure of pymodbus is a bit complicated, mostly due to the mixtu

The overall architecture can be viewed as:


Client classes (interface to applications)
mixin (interface with all requests defined as methods)
transaction (handles transactions and allow concurrent calls)
framers (add pre/post headers to make a valid package)
transport (handles actual transportation)
Lower levels are Common

Server classes (interface to applications)
datastores (handles registers/values to be returned)
Lower levels are Common

pdu (build/create response/request class)
transaction (handles transactions and allow concurrent calls)
framers (add pre/post headers to make a valid package)
transport (handles actual transportation)
Expand All @@ -25,4 +27,3 @@ In detail the packages can viewed as:
In detail the classes can be viewed as:

.. image:: classes.png

26 changes: 17 additions & 9 deletions doc/source/library/framer.rst
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
Framer
======

pymodbus\.framer\.ascii_framer module
-------------------------------------
pymodbus\.framer\.old_framer_ascii module
-----------------------------------------

.. automodule:: pymodbus.framer.ascii_framer
.. automodule:: pymodbus.framer.old_framer_ascii
:members:
:undoc-members:
:show-inheritance:

pymodbus\.framer\.rtu_framer module
-----------------------------------
pymodbus\.framer\.old_framer_rtu module
---------------------------------------

.. automodule:: pymodbus.framer.rtu_framer
.. automodule:: pymodbus.framer.old_framer_rtu
:members:
:undoc-members:
:show-inheritance:

pymodbus\.framer\.socket_framer module
--------------------------------------
pymodbus\.framer\.old_framer_socket module
------------------------------------------

.. automodule:: pymodbus.framer.socket_framer
.. automodule:: pymodbus.framer.old_framer_socket
:members:
:undoc-members:
:show-inheritance:

pymodbus\.framer\.old_framer_tls module
---------------------------------------

.. automodule:: pymodbus.framer.old_framer_tls
:members:
:undoc-members:
:show-inheritance:
4 changes: 2 additions & 2 deletions examples/client_custom_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import asyncio
import struct

from pymodbus import Framer
from pymodbus import FramerType
from pymodbus.bit_read_message import ReadCoilsRequest
from pymodbus.client import AsyncModbusTcpClient as ModbusClient
from pymodbus.pdu import ModbusExceptions, ModbusRequest, ModbusResponse
Expand Down Expand Up @@ -118,7 +118,7 @@ def __init__(self, address, **kwargs):

async def main(host="localhost", port=5020):
"""Run versions of read coil."""
async with ModbusClient(host=host, port=port, framer_name=Framer.SOCKET) as client:
async with ModbusClient(host=host, port=port, framer_name=FramerType.SOCKET) as client:
await client.connect()

# new modbus function code.
Expand Down
6 changes: 3 additions & 3 deletions examples/client_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import asyncio
import time

from pymodbus import Framer
from pymodbus import FramerType
from pymodbus.client import AsyncModbusSerialClient, ModbusSerialClient


Expand All @@ -29,7 +29,7 @@ def run_sync_client_test():
print("--- Testing sync client v3.4.1")
client = ModbusSerialClient(
"/dev/ttys007",
framer_name=Framer.RTU,
framer_name=FramerType.RTU,
baudrate=9600,
)
client.connect()
Expand All @@ -56,7 +56,7 @@ async def run_async_client_test():
print("--- Testing async client v3.4.1")
client = AsyncModbusSerialClient(
"/dev/ttys007",
framer_name=Framer.RTU,
framer_name=FramerType.RTU,
baudrate=9600,
)
await client.connect()
Expand Down
6 changes: 3 additions & 3 deletions examples/package_test_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

import pymodbus.client as modbusClient
import pymodbus.server as modbusServer
from pymodbus import Framer, ModbusException, pymodbus_apply_logging_config
from pymodbus import FramerType, ModbusException, pymodbus_apply_logging_config
from pymodbus.datastore import (
ModbusSequentialDataBlock,
ModbusServerContext,
Expand Down Expand Up @@ -160,14 +160,14 @@ def __init__(self, comm: CommType):
if comm == CommType.TCP:
self.server = modbusServer.ModbusTcpServer(
self.context,
framer=Framer.SOCKET,
framer=FramerType.SOCKET,
identity=self.identity,
address=(NULLMODEM_HOST, test_port),
)
elif comm == CommType.SERIAL:
self.server = modbusServer.ModbusSerialServer(
self.context,
framer=Framer.SOCKET,
framer=FramerType.SOCKET,
identity=self.identity,
port=f"{NULLMODEM_HOST}:{test_port}",
)
Expand Down
4 changes: 2 additions & 2 deletions examples/server_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import asyncio
import logging

from pymodbus import Framer, pymodbus_apply_logging_config
from pymodbus import FramerType, pymodbus_apply_logging_config
from pymodbus.datastore import (
ModbusSequentialDataBlock,
ModbusServerContext,
Expand Down Expand Up @@ -63,7 +63,7 @@ async def setup(self):
)
self.server = ModbusTcpServer(
context,
Framer.SOCKET,
FramerType.SOCKET,
None,
("127.0.0.1", 5020),
request_tracer=self.server_request_tracer,
Expand Down
6 changes: 3 additions & 3 deletions examples/simple_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
import pymodbus.client as ModbusClient
from pymodbus import (
ExceptionResponse,
Framer,
FramerType,
ModbusException,
pymodbus_apply_logging_config,
)


async def run_async_simple_client(comm, host, port, framer=Framer.SOCKET):
async def run_async_simple_client(comm, host, port, framer=FramerType.SOCKET):
"""Run async client."""
# activate debugging
pymodbus_apply_logging_config("DEBUG")
Expand Down Expand Up @@ -64,7 +64,7 @@ async def run_async_simple_client(comm, host, port, framer=Framer.SOCKET):
client = ModbusClient.AsyncModbusTlsClient(
host,
port=port,
framer=Framer.TLS,
framer=FramerType.TLS,
# timeout=10,
# retries=3,
# retry_on_empty=False,
Expand Down
6 changes: 3 additions & 3 deletions examples/simple_sync_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
import pymodbus.client as ModbusClient
from pymodbus import (
ExceptionResponse,
Framer,
FramerType,
ModbusException,
pymodbus_apply_logging_config,
)


def run_sync_simple_client(comm, host, port, framer=Framer.SOCKET):
def run_sync_simple_client(comm, host, port, framer=FramerType.SOCKET):
"""Run sync client."""
# activate debugging
pymodbus_apply_logging_config("DEBUG")
Expand Down Expand Up @@ -66,7 +66,7 @@ def run_sync_simple_client(comm, host, port, framer=Framer.SOCKET):
client = ModbusClient.ModbusTlsClient(
host,
port=port,
framer=Framer.TLS,
framer=FramerType.TLS,
# timeout=10,
# retries=3,
# retry_on_empty=False,
Expand Down
4 changes: 2 additions & 2 deletions examples/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import asyncio
import logging

from pymodbus import Framer
from pymodbus import FramerType
from pymodbus.client import AsyncModbusTcpClient
from pymodbus.datastore import ModbusSimulatorContext
from pymodbus.server import ModbusSimulatorServer, get_simulator_commandline
Expand Down Expand Up @@ -74,7 +74,7 @@ async def run_simulator():
client = AsyncModbusTcpClient(
"127.0.0.1",
port=5020,
framer=Framer.SOCKET,
framer=FramerType.SOCKET,
)
await client.connect()
assert client.connected
Expand Down
4 changes: 2 additions & 2 deletions pymodbus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

__all__ = [
"ExceptionResponse",
"Framer",
"FramerType",
"ModbusException",
"pymodbus_apply_logging_config",
"__version__",
"__version_full__",
]

from pymodbus.exceptions import ModbusException
from pymodbus.framer import Framer
from pymodbus.framer import FramerType
from pymodbus.logging import pymodbus_apply_logging_config
from pymodbus.pdu import ExceptionResponse

Expand Down
6 changes: 3 additions & 3 deletions pymodbus/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pymodbus.client.mixin import ModbusClientMixin
from pymodbus.exceptions import ConnectionException, ModbusIOException
from pymodbus.factory import ClientDecoder
from pymodbus.framer import FRAMER_NAME_TO_CLASS, Framer, ModbusFramer
from pymodbus.framer import FRAMER_NAME_TO_CLASS, FramerType, ModbusFramer
from pymodbus.logging import Log
from pymodbus.pdu import ModbusRequest, ModbusResponse
from pymodbus.transaction import ModbusTransactionManager
Expand Down Expand Up @@ -49,7 +49,7 @@ class ModbusBaseClient(ModbusClientMixin[Awaitable[ModbusResponse]], ModbusProto

def __init__(
self,
framer: Framer,
framer: FramerType,
timeout: float = 3,
retries: int = 3,
retry_on_empty: bool = False,
Expand Down Expand Up @@ -308,7 +308,7 @@ class _params:

def __init__(
self,
framer: Framer,
framer: FramerType,
timeout: float = 3,
retries: int = 3,
retry_on_empty: bool = False,
Expand Down
6 changes: 3 additions & 3 deletions pymodbus/client/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from pymodbus.client.base import ModbusBaseClient, ModbusBaseSyncClient
from pymodbus.exceptions import ConnectionException
from pymodbus.framer import Framer
from pymodbus.framer import FramerType
from pymodbus.logging import Log
from pymodbus.transport import CommType
from pymodbus.utilities import ModbusTransactionState
Expand Down Expand Up @@ -69,7 +69,7 @@ async def run():
def __init__(
self,
port: str,
framer: Framer = Framer.RTU,
framer: FramerType = FramerType.RTU,
baudrate: int = 19200,
bytesize: int = 8,
parity: str = "N",
Expand Down Expand Up @@ -158,7 +158,7 @@ def run():
def __init__(
self,
port: str,
framer: Framer = Framer.RTU,
framer: FramerType = FramerType.RTU,
baudrate: int = 19200,
bytesize: int = 8,
parity: str = "N",
Expand Down
6 changes: 3 additions & 3 deletions pymodbus/client/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from pymodbus.client.base import ModbusBaseClient, ModbusBaseSyncClient
from pymodbus.exceptions import ConnectionException
from pymodbus.framer import Framer
from pymodbus.framer import FramerType
from pymodbus.logging import Log
from pymodbus.transport import CommType

Expand Down Expand Up @@ -59,7 +59,7 @@ def __init__(
self,
host: str,
port: int = 502,
framer: Framer = Framer.SOCKET,
framer: FramerType = FramerType.SOCKET,
source_address: tuple[str, int] | None = None,
**kwargs: Any,
) -> None:
Expand Down Expand Up @@ -139,7 +139,7 @@ def __init__(
self,
host: str,
port: int = 502,
framer: Framer = Framer.SOCKET,
framer: FramerType = FramerType.SOCKET,
source_address: tuple[str, int] | None = None,
**kwargs: Any,
) -> None:
Expand Down
6 changes: 3 additions & 3 deletions pymodbus/client/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Any

from pymodbus.client.tcp import AsyncModbusTcpClient, ModbusTcpClient
from pymodbus.framer import Framer
from pymodbus.framer import FramerType
from pymodbus.logging import Log
from pymodbus.transport import CommParams, CommType

Expand Down Expand Up @@ -56,7 +56,7 @@ def __init__(
self,
host: str,
port: int = 802,
framer: Framer = Framer.TLS,
framer: FramerType = FramerType.TLS,
sslctx: ssl.SSLContext = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT),
server_hostname: str | None = None,
**kwargs: Any,
Expand Down Expand Up @@ -153,7 +153,7 @@ def __init__(
self,
host: str,
port: int = 802,
framer: Framer = Framer.TLS,
framer: FramerType = FramerType.TLS,
sslctx: ssl.SSLContext = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT),
server_hostname: str | None = None,
**kwargs: Any,
Expand Down
6 changes: 3 additions & 3 deletions pymodbus/client/udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from pymodbus.client.base import ModbusBaseClient, ModbusBaseSyncClient
from pymodbus.exceptions import ConnectionException
from pymodbus.framer import Framer
from pymodbus.framer import FramerType
from pymodbus.logging import Log
from pymodbus.transport import CommType

Expand Down Expand Up @@ -60,7 +60,7 @@ def __init__(
self,
host: str,
port: int = 502,
framer: Framer = Framer.SOCKET,
framer: FramerType = FramerType.SOCKET,
source_address: tuple[str, int] | None = None,
**kwargs: Any,
) -> None:
Expand Down Expand Up @@ -143,7 +143,7 @@ def __init__(
self,
host: str,
port: int = 502,
framer: Framer = Framer.SOCKET,
framer: FramerType = FramerType.SOCKET,
source_address: tuple[str, int] | None = None,
**kwargs: Any,
) -> None:
Expand Down
Loading