diff --git a/API_changes.rst b/API_changes.rst index 4ec98de3f..8c3fd1de8 100644 --- a/API_changes.rst +++ b/API_changes.rst @@ -11,6 +11,7 @@ API changes 3.7.0 - on_connect_callback(true/false) added to async clients. - binary framer no longer supported - Framer. renamed to FramerType. +- PDU classes moved to pymodbus/pdu API changes 3.6.0 diff --git a/doc/source/library/pymodbus.rst b/doc/source/library/pymodbus.rst index 9875fd1ed..cdda34602 100644 --- a/doc/source/library/pymodbus.rst +++ b/doc/source/library/pymodbus.rst @@ -6,84 +6,87 @@ Extra functions :undoc-members: :show-inheritance: - -.. automodule:: pymodbus.bit_read_message +.. automodule:: pymodbus.device :members: :undoc-members: :show-inheritance: -.. automodule:: pymodbus.bit_write_message +.. automodule:: pymodbus.events :members: :undoc-members: :show-inheritance: -.. automodule:: pymodbus.device +.. automodule:: pymodbus.exceptions :members: :undoc-members: :show-inheritance: -.. automodule:: pymodbus.diag_message +.. automodule:: pymodbus.factory :members: :undoc-members: :show-inheritance: -.. automodule:: pymodbus.events +.. automodule:: pymodbus.payload :members: :undoc-members: :show-inheritance: -.. automodule:: pymodbus.exceptions +.. automodule:: pymodbus.transaction :members: :undoc-members: :show-inheritance: -.. automodule:: pymodbus.factory +.. automodule:: pymodbus.utilities :members: :undoc-members: :show-inheritance: -.. automodule:: pymodbus.file_message + +PDU classes +=========== + +.. automodule:: pymodbus.pdu.bit_read_message :members: :undoc-members: :show-inheritance: -.. automodule:: pymodbus.mei_message +.. automodule:: pymodbus.pdu.bit_write_message :members: :undoc-members: :show-inheritance: -.. automodule:: pymodbus.other_message +.. automodule:: pymodbus.pdu.diag_message :members: :undoc-members: :show-inheritance: -.. automodule:: pymodbus.payload +.. automodule:: pymodbus.pdu.file_message :members: :undoc-members: :show-inheritance: -.. automodule:: pymodbus.pdu +.. automodule:: pymodbus.pdu.mei_message :members: :undoc-members: :show-inheritance: - :noindex: -.. automodule:: pymodbus.register_read_message +.. automodule:: pymodbus.pdu.other_message :members: :undoc-members: :show-inheritance: -.. automodule:: pymodbus.register_write_message +.. automodule:: pymodbus.pdu.pdu :members: :undoc-members: :show-inheritance: + :noindex: -.. automodule:: pymodbus.transaction +.. automodule:: pymodbus.pdu.register_read_message :members: :undoc-members: :show-inheritance: -.. automodule:: pymodbus.utilities +.. automodule:: pymodbus.pdu.register_write_message :members: :undoc-members: :show-inheritance: diff --git a/examples/client_custom_msg.py b/examples/client_custom_msg.py index 01edf40f2..e4af4f4f1 100755 --- a/examples/client_custom_msg.py +++ b/examples/client_custom_msg.py @@ -14,9 +14,9 @@ import struct 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 +from pymodbus.pdu.bit_read_message import ReadCoilsRequest # --------------------------------------------------------------------------- # diff --git a/examples/message_generator.py b/examples/message_generator.py index eaf7f036e..cf885b36c 100755 --- a/examples/message_generator.py +++ b/examples/message_generator.py @@ -4,14 +4,14 @@ import codecs as c import logging -import pymodbus.bit_read_message as modbus_bit -import pymodbus.bit_write_message as modbus_bit_write -import pymodbus.diag_message as modbus_diag -import pymodbus.file_message as modbus_file -import pymodbus.mei_message as modbus_mei -import pymodbus.other_message as modbus_other -import pymodbus.register_read_message as modbus_register -import pymodbus.register_write_message as modbus_register_write +import pymodbus.pdu.bit_read_message as modbus_bit +import pymodbus.pdu.bit_write_message as modbus_bit_write +import pymodbus.pdu.diag_message as modbus_diag +import pymodbus.pdu.file_message as modbus_file +import pymodbus.pdu.mei_message as modbus_mei +import pymodbus.pdu.other_message as modbus_other +import pymodbus.pdu.register_read_message as modbus_register +import pymodbus.pdu.register_write_message as modbus_register_write from pymodbus.transaction import ( ModbusAsciiFramer, ModbusRtuFramer, diff --git a/pymodbus/client/mixin.py b/pymodbus/client/mixin.py index f686761aa..bb5346d25 100644 --- a/pymodbus/client/mixin.py +++ b/pymodbus/client/mixin.py @@ -5,14 +5,14 @@ from enum import Enum from typing import Any, Generic, TypeVar -import pymodbus.bit_read_message as pdu_bit_read -import pymodbus.bit_write_message as pdu_bit_write -import pymodbus.diag_message as pdu_diag -import pymodbus.file_message as pdu_file_msg -import pymodbus.mei_message as pdu_mei -import pymodbus.other_message as pdu_other_msg -import pymodbus.register_read_message as pdu_reg_read -import pymodbus.register_write_message as pdu_req_write +import pymodbus.pdu.bit_read_message as pdu_bit_read +import pymodbus.pdu.bit_write_message as pdu_bit_write +import pymodbus.pdu.diag_message as pdu_diag +import pymodbus.pdu.file_message as pdu_file_msg +import pymodbus.pdu.mei_message as pdu_mei +import pymodbus.pdu.other_message as pdu_other_msg +import pymodbus.pdu.register_read_message as pdu_reg_read +import pymodbus.pdu.register_write_message as pdu_req_write from pymodbus.exceptions import ModbusException from pymodbus.pdu import ModbusRequest diff --git a/pymodbus/factory.py b/pymodbus/factory.py index c351fa687..50302b50c 100644 --- a/pymodbus/factory.py +++ b/pymodbus/factory.py @@ -12,17 +12,17 @@ # pylint: disable=missing-type-doc from collections.abc import Callable -from pymodbus import bit_read_message as bit_r_msg -from pymodbus import bit_write_message as bit_w_msg -from pymodbus import diag_message as diag_msg -from pymodbus import file_message as file_msg -from pymodbus import mei_message as mei_msg -from pymodbus import other_message as o_msg -from pymodbus import pdu -from pymodbus import register_read_message as reg_r_msg -from pymodbus import register_write_message as reg_w_msg from pymodbus.exceptions import MessageRegisterException, ModbusException from pymodbus.logging import Log +from pymodbus.pdu import bit_read_message as bit_r_msg +from pymodbus.pdu import bit_write_message as bit_w_msg +from pymodbus.pdu import diag_message as diag_msg +from pymodbus.pdu import file_message as file_msg +from pymodbus.pdu import mei_message as mei_msg +from pymodbus.pdu import other_message as o_msg +from pymodbus.pdu import pdu +from pymodbus.pdu import register_read_message as reg_r_msg +from pymodbus.pdu import register_write_message as reg_w_msg # --------------------------------------------------------------------------- # diff --git a/pymodbus/pdu/__init__.py b/pymodbus/pdu/__init__.py new file mode 100644 index 000000000..da3d86f8f --- /dev/null +++ b/pymodbus/pdu/__init__.py @@ -0,0 +1,18 @@ +"""Framer.""" +__all__ = [ + "ExceptionResponse", + "IllegalFunctionRequest", + "ModbusExceptions", + "ModbusPDU", + "ModbusRequest", + "ModbusResponse", +] + +from pymodbus.pdu.pdu import ( + ExceptionResponse, + IllegalFunctionRequest, + ModbusExceptions, + ModbusPDU, + ModbusRequest, + ModbusResponse, +) diff --git a/pymodbus/bit_read_message.py b/pymodbus/pdu/bit_read_message.py similarity index 100% rename from pymodbus/bit_read_message.py rename to pymodbus/pdu/bit_read_message.py diff --git a/pymodbus/bit_write_message.py b/pymodbus/pdu/bit_write_message.py similarity index 100% rename from pymodbus/bit_write_message.py rename to pymodbus/pdu/bit_write_message.py diff --git a/pymodbus/diag_message.py b/pymodbus/pdu/diag_message.py similarity index 100% rename from pymodbus/diag_message.py rename to pymodbus/pdu/diag_message.py diff --git a/pymodbus/file_message.py b/pymodbus/pdu/file_message.py similarity index 100% rename from pymodbus/file_message.py rename to pymodbus/pdu/file_message.py diff --git a/pymodbus/mei_message.py b/pymodbus/pdu/mei_message.py similarity index 100% rename from pymodbus/mei_message.py rename to pymodbus/pdu/mei_message.py diff --git a/pymodbus/other_message.py b/pymodbus/pdu/other_message.py similarity index 100% rename from pymodbus/other_message.py rename to pymodbus/pdu/other_message.py diff --git a/pymodbus/pdu.py b/pymodbus/pdu/pdu.py similarity index 100% rename from pymodbus/pdu.py rename to pymodbus/pdu/pdu.py diff --git a/pymodbus/register_read_message.py b/pymodbus/pdu/register_read_message.py similarity index 100% rename from pymodbus/register_read_message.py rename to pymodbus/pdu/register_read_message.py diff --git a/pymodbus/register_write_message.py b/pymodbus/pdu/register_write_message.py similarity index 100% rename from pymodbus/register_write_message.py rename to pymodbus/pdu/register_write_message.py diff --git a/test/framers/generator.py b/test/framers/generator.py index 038f0d2b6..04344a823 100755 --- a/test/framers/generator.py +++ b/test/framers/generator.py @@ -9,7 +9,7 @@ ModbusTlsFramer, ) from pymodbus.pdu import ModbusExceptions as merror -from pymodbus.register_read_message import ( +from pymodbus.pdu.register_read_message import ( ReadHoldingRegistersRequest, ReadHoldingRegistersResponse, ) diff --git a/test/framers/test_old_framers.py b/test/framers/test_old_framers.py index 6d6aa3e68..7101137fa 100644 --- a/test/framers/test_old_framers.py +++ b/test/framers/test_old_framers.py @@ -4,7 +4,6 @@ import pytest from pymodbus import FramerType -from pymodbus.bit_read_message import ReadCoilsRequest from pymodbus.client.base import ModbusBaseClient from pymodbus.exceptions import ModbusIOException from pymodbus.factory import ClientDecoder @@ -14,6 +13,7 @@ ModbusSocketFramer, ModbusTlsFramer, ) +from pymodbus.pdu.bit_read_message import ReadCoilsRequest from pymodbus.transport import CommType from pymodbus.utilities import ModbusTransactionState diff --git a/test/sub_client/test_client.py b/test/sub_client/test_client.py index 40fc0e86f..b853e8ab0 100755 --- a/test/sub_client/test_client.py +++ b/test/sub_client/test_client.py @@ -6,14 +6,14 @@ import pytest -import pymodbus.bit_read_message as pdu_bit_read -import pymodbus.bit_write_message as pdu_bit_write import pymodbus.client as lib_client -import pymodbus.diag_message as pdu_diag -import pymodbus.file_message as pdu_file_msg -import pymodbus.other_message as pdu_other_msg -import pymodbus.register_read_message as pdu_reg_read -import pymodbus.register_write_message as pdu_req_write +import pymodbus.pdu.bit_read_message as pdu_bit_read +import pymodbus.pdu.bit_write_message as pdu_bit_write +import pymodbus.pdu.diag_message as pdu_diag +import pymodbus.pdu.file_message as pdu_file_msg +import pymodbus.pdu.other_message as pdu_other_msg +import pymodbus.pdu.register_read_message as pdu_reg_read +import pymodbus.pdu.register_write_message as pdu_req_write from examples.helper import get_certificate from pymodbus import FramerType from pymodbus.client.base import ModbusBaseClient diff --git a/test/sub_function_codes/test_all_messages.py b/test/sub_function_codes/test_all_messages.py index 2ab64d879..bfb669df9 100644 --- a/test/sub_function_codes/test_all_messages.py +++ b/test/sub_function_codes/test_all_messages.py @@ -1,17 +1,17 @@ """Test all messages.""" -from pymodbus.bit_read_message import ( +from pymodbus.pdu.bit_read_message import ( ReadCoilsRequest, ReadCoilsResponse, ReadDiscreteInputsRequest, ReadDiscreteInputsResponse, ) -from pymodbus.bit_write_message import ( +from pymodbus.pdu.bit_write_message import ( WriteMultipleCoilsRequest, WriteMultipleCoilsResponse, WriteSingleCoilRequest, WriteSingleCoilResponse, ) -from pymodbus.register_read_message import ( +from pymodbus.pdu.register_read_message import ( ReadHoldingRegistersRequest, ReadHoldingRegistersResponse, ReadInputRegistersRequest, @@ -19,7 +19,7 @@ ReadWriteMultipleRegistersRequest, ReadWriteMultipleRegistersResponse, ) -from pymodbus.register_write_message import ( +from pymodbus.pdu.register_write_message import ( WriteMultipleRegistersRequest, WriteMultipleRegistersResponse, WriteSingleRegisterRequest, diff --git a/test/sub_function_codes/test_bit_read_messages.py b/test/sub_function_codes/test_bit_read_messages.py index 21817d0d7..5d190f023 100644 --- a/test/sub_function_codes/test_bit_read_messages.py +++ b/test/sub_function_codes/test_bit_read_messages.py @@ -9,13 +9,13 @@ import struct from test.conftest import MockContext -from pymodbus.bit_read_message import ( +from pymodbus.pdu import ModbusExceptions +from pymodbus.pdu.bit_read_message import ( ReadBitsRequestBase, ReadBitsResponseBase, ReadCoilsRequest, ReadDiscreteInputsRequest, ) -from pymodbus.pdu import ModbusExceptions res = [True] * 21 diff --git a/test/sub_function_codes/test_bit_write_messages.py b/test/sub_function_codes/test_bit_write_messages.py index 7552cd4e5..94e2066f8 100644 --- a/test/sub_function_codes/test_bit_write_messages.py +++ b/test/sub_function_codes/test_bit_write_messages.py @@ -8,13 +8,13 @@ """ from test.conftest import FakeList, MockContext -from pymodbus.bit_write_message import ( +from pymodbus.pdu import ModbusExceptions +from pymodbus.pdu.bit_write_message import ( WriteMultipleCoilsRequest, WriteMultipleCoilsResponse, WriteSingleCoilRequest, WriteSingleCoilResponse, ) -from pymodbus.pdu import ModbusExceptions # ---------------------------------------------------------------------------# diff --git a/test/sub_function_codes/test_diag_messages.py b/test/sub_function_codes/test_diag_messages.py index 5db301894..673222c93 100644 --- a/test/sub_function_codes/test_diag_messages.py +++ b/test/sub_function_codes/test_diag_messages.py @@ -2,7 +2,8 @@ import pytest from pymodbus.constants import ModbusPlusOperation -from pymodbus.diag_message import ( +from pymodbus.exceptions import NotImplementedException +from pymodbus.pdu.diag_message import ( ChangeAsciiInputDelimiterRequest, ChangeAsciiInputDelimiterResponse, ClearCountersRequest, @@ -42,7 +43,6 @@ ReturnSlaveNoResponseCountRequest, ReturnSlaveNoResponseCountResponse, ) -from pymodbus.exceptions import NotImplementedException class TestDataStore: diff --git a/test/sub_function_codes/test_mei_messages.py b/test/sub_function_codes/test_mei_messages.py index b0db6111a..d553e3461 100644 --- a/test/sub_function_codes/test_mei_messages.py +++ b/test/sub_function_codes/test_mei_messages.py @@ -7,7 +7,7 @@ from pymodbus.constants import DeviceInformation from pymodbus.device import ModbusControlBlock -from pymodbus.mei_message import ( +from pymodbus.pdu.mei_message import ( ReadDeviceInformationRequest, ReadDeviceInformationResponse, ) diff --git a/test/sub_function_codes/test_other_messages.py b/test/sub_function_codes/test_other_messages.py index 5b87c8154..eb43ad21e 100644 --- a/test/sub_function_codes/test_other_messages.py +++ b/test/sub_function_codes/test_other_messages.py @@ -1,7 +1,7 @@ """Test other messages.""" from unittest import mock -import pymodbus.other_message as pymodbus_message +import pymodbus.pdu.other_message as pymodbus_message class TestOtherMessage: @@ -86,7 +86,7 @@ def test_get_comm_event_log_with_events(self): def test_report_slave_id_request(self): """Test report slave id request.""" - with mock.patch("pymodbus.other_message.DeviceInformationFactory") as dif: + with mock.patch("pymodbus.pdu.other_message.DeviceInformationFactory") as dif: # First test regular identity strings identity = { 0x00: "VN", # VendorName @@ -126,7 +126,7 @@ def test_report_slave_id_request(self): def test_report_slave_id(self): """Test report slave id.""" - with mock.patch("pymodbus.other_message.DeviceInformationFactory") as dif: + with mock.patch("pymodbus.pdu.other_message.DeviceInformationFactory") as dif: dif.get.return_value = {} request = pymodbus_message.ReportSlaveIdRequest() request.decode(b"\x12") diff --git a/test/sub_function_codes/test_register_read_messages.py b/test/sub_function_codes/test_register_read_messages.py index dcb1ef6c5..6b0072c21 100644 --- a/test/sub_function_codes/test_register_read_messages.py +++ b/test/sub_function_codes/test_register_read_messages.py @@ -2,7 +2,7 @@ from test.conftest import FakeList, MockContext from pymodbus.pdu import ModbusExceptions -from pymodbus.register_read_message import ( +from pymodbus.pdu.register_read_message import ( ReadHoldingRegistersRequest, ReadHoldingRegistersResponse, ReadInputRegistersRequest, diff --git a/test/sub_function_codes/test_register_write_messages.py b/test/sub_function_codes/test_register_write_messages.py index 2327d090b..e89e97802 100644 --- a/test/sub_function_codes/test_register_write_messages.py +++ b/test/sub_function_codes/test_register_write_messages.py @@ -3,7 +3,7 @@ from pymodbus.payload import BinaryPayloadBuilder, Endian from pymodbus.pdu import ModbusExceptions -from pymodbus.register_write_message import ( +from pymodbus.pdu.register_write_message import ( MaskWriteRegisterRequest, MaskWriteRegisterResponse, WriteMultipleRegistersRequest, diff --git a/test/sub_server/test_server_asyncio.py b/test/sub_server/test_server_asyncio.py index 34c16616b..e3de50956 100755 --- a/test/sub_server/test_server_asyncio.py +++ b/test/sub_server/test_server_asyncio.py @@ -266,7 +266,7 @@ async def test_async_tcp_server_modbus_error(self): BasicClient.data = TEST_DATA await self.start_server() with mock.patch( - "pymodbus.register_read_message.ReadHoldingRegistersRequest.execute", + "pymodbus.pdu.register_read_message.ReadHoldingRegistersRequest.execute", side_effect=NoSuchSlaveException, ): await self.connect_server() diff --git a/test/test_file_message.py b/test/test_file_message.py index ee71ba1ac..e210f6bcb 100644 --- a/test/test_file_message.py +++ b/test/test_file_message.py @@ -8,7 +8,8 @@ """ from test.conftest import MockContext -from pymodbus.file_message import ( +from pymodbus.pdu import ModbusExceptions +from pymodbus.pdu.file_message import ( FileRecord, ReadFifoQueueRequest, ReadFifoQueueResponse, @@ -17,7 +18,6 @@ WriteFileRecordRequest, WriteFileRecordResponse, ) -from pymodbus.pdu import ModbusExceptions TEST_MESSAGE = b"\x00\n\x00\x08\x00\x01\x00\x02\x00\x03\x00\x04" diff --git a/test/test_remote_datastore.py b/test/test_remote_datastore.py index 1f59c62b8..b12d792d4 100644 --- a/test/test_remote_datastore.py +++ b/test/test_remote_datastore.py @@ -3,12 +3,12 @@ import pytest -from pymodbus.bit_read_message import ReadCoilsResponse -from pymodbus.bit_write_message import WriteMultipleCoilsResponse from pymodbus.datastore.remote import RemoteSlaveContext from pymodbus.exceptions import NotImplementedException from pymodbus.pdu import ExceptionResponse -from pymodbus.register_read_message import ReadInputRegistersResponse +from pymodbus.pdu.bit_read_message import ReadCoilsResponse +from pymodbus.pdu.bit_write_message import WriteMultipleCoilsResponse +from pymodbus.pdu.register_read_message import ReadInputRegistersResponse class TestRemoteDataStore: