diff --git a/API_changes.rst b/API_changes.rst index 49c740642..3f3df696c 100644 --- a/API_changes.rst +++ b/API_changes.rst @@ -8,8 +8,9 @@ API changes 3.8.0 - Remove skip_encode parameter. - rename ModbusExceptions enums to legal constants. - enforce client keyword only parameters (positional not allowed). -- added trace_packet/pdu/connect to client -- removed on_connect_callback from client +- added trace_packet/pdu/connect to client/server. +- removed on_connect_callback from client. +- removed response_manipulator, request_tracer from server. API changes 3.7.0 ----------------- diff --git a/examples/server_hook.py b/examples/server_hook.py index b74c7e8c9..301d3dca3 100755 --- a/examples/server_hook.py +++ b/examples/server_hook.py @@ -38,7 +38,6 @@ def server_response_manipulator(self, response): The filter returns: - response, either original or modified - - skip_encoding, signals whether or not to encode the response """ if not self.message_count: print(f"---> RESPONSE: {response}") @@ -46,7 +45,7 @@ def server_response_manipulator(self, response): else: print("---> RESPONSE: NONE") self.message_count -= 1 - return response, False + return response async def setup(self): """Prepare server.""" diff --git a/pymodbus/client/base.py b/pymodbus/client/base.py index 270a9a783..41c574b4b 100644 --- a/pymodbus/client/base.py +++ b/pymodbus/client/base.py @@ -25,9 +25,9 @@ def __init__( framer: FramerType, retries: int, comm_params: CommParams, - trace_packet: Callable[[bool, bytes | None], bytes] | None = None, - trace_pdu: Callable[[bool, ModbusPDU | None], ModbusPDU] | None = None, - trace_connect: Callable[[bool], None] | None = None, + trace_packet: Callable[[bool, bytes], bytes] | None, + trace_pdu: Callable[[bool, ModbusPDU], ModbusPDU] | None, + trace_connect: Callable[[bool], None] | None, ) -> None: """Initialize a client instance. @@ -40,9 +40,9 @@ def __init__( (FRAMER_NAME_TO_CLASS[framer])(DecodePDU(False)), retries, False, - trace_packet=trace_packet, - trace_pdu=trace_pdu, - trace_connect=trace_connect, + trace_packet, + trace_pdu, + trace_connect, ) self.state = ModbusTransactionState.IDLE @@ -119,9 +119,9 @@ def __init__( framer: FramerType, retries: int, comm_params: CommParams, - trace_packet: Callable[[bool, bytes | None], bytes] | None = None, - trace_pdu: Callable[[bool, ModbusPDU | None], ModbusPDU] | None = None, - trace_connect: Callable[[bool], None] | None = None, + trace_packet: Callable[[bool, bytes], bytes] | None, + trace_pdu: Callable[[bool, ModbusPDU], ModbusPDU] | None, + trace_connect: Callable[[bool], None] | None, ) -> None: """Initialize a client instance. @@ -139,9 +139,9 @@ def __init__( self.framer, retries, False, - trace_packet=trace_packet, - trace_pdu=trace_pdu, - trace_connect=trace_connect, + trace_packet, + trace_pdu, + trace_connect, sync_client=self, ) self.reconnect_delay_current = self.comm_params.reconnect_delay or 0 @@ -202,7 +202,7 @@ def _start_send(self): self.state = ModbusTransactionState.SENDING @abstractmethod - def send(self, request: bytes) -> int: + def send(self, request: bytes, addr: tuple | None = None) -> int: """Send request. :meta private: diff --git a/pymodbus/client/serial.py b/pymodbus/client/serial.py index f400354f2..c54ba6a22 100644 --- a/pymodbus/client/serial.py +++ b/pymodbus/client/serial.py @@ -81,8 +81,8 @@ def __init__( # pylint: disable=too-many-arguments reconnect_delay_max: float = 300, timeout: float = 3, retries: int = 3, - trace_packet: Callable[[bool, bytes | None], bytes] | None = None, - trace_pdu: Callable[[bool, ModbusPDU | None], ModbusPDU] | None = None, + trace_packet: Callable[[bool, bytes], bytes] | None = None, + trace_pdu: Callable[[bool, ModbusPDU], ModbusPDU] | None = None, trace_connect: Callable[[bool], None] | None = None, ) -> None: """Initialize Asyncio Modbus Serial Client.""" @@ -111,6 +111,9 @@ def __init__( # pylint: disable=too-many-arguments framer, retries, self.comm_params, + trace_packet, + trace_pdu, + trace_connect, ) @@ -174,8 +177,8 @@ def __init__( # pylint: disable=too-many-arguments reconnect_delay_max: float = 300, timeout: float = 3, retries: int = 3, - trace_packet: Callable[[bool, bytes | None], bytes] | None = None, - trace_pdu: Callable[[bool, ModbusPDU | None], ModbusPDU] | None = None, + trace_packet: Callable[[bool, bytes], bytes] | None = None, + trace_pdu: Callable[[bool, ModbusPDU], ModbusPDU] | None = None, trace_connect: Callable[[bool], None] | None = None, ) -> None: """Initialize Modbus Serial Client.""" @@ -203,9 +206,9 @@ def __init__( # pylint: disable=too-many-arguments framer, retries, self.comm_params, - trace_connect=trace_connect, - trace_packet=trace_packet, - trace_pdu=trace_pdu, + trace_packet, + trace_pdu, + trace_connect, ) self.socket: serial.Serial | None = None self.last_frame_end = None @@ -280,8 +283,9 @@ def _send(self, request: bytes) -> int: # pragma: no cover return size return 0 - def send(self, request: bytes) -> int: # pragma: no cover + def send(self, request: bytes, addr: tuple | None = None) -> int: # pragma: no cover """Send data on the underlying socket.""" + _ = addr start = time.time() if hasattr(self,"ctx"): timeout = start + self.ctx.comm_params.timeout_connect diff --git a/pymodbus/client/tcp.py b/pymodbus/client/tcp.py index 0e662addd..0cd062416 100644 --- a/pymodbus/client/tcp.py +++ b/pymodbus/client/tcp.py @@ -70,8 +70,8 @@ def __init__( # pylint: disable=too-many-arguments reconnect_delay_max: float = 300, timeout: float = 3, retries: int = 3, - trace_packet: Callable[[bool, bytes | None], bytes] | None = None, - trace_pdu: Callable[[bool, ModbusPDU | None], ModbusPDU] | None = None, + trace_packet: Callable[[bool, bytes], bytes] | None = None, + trace_pdu: Callable[[bool, ModbusPDU], ModbusPDU] | None = None, trace_connect: Callable[[bool], None] | None = None, ) -> None: """Initialize Asyncio Modbus TCP Client.""" @@ -93,6 +93,9 @@ def __init__( # pylint: disable=too-many-arguments framer, retries, self.comm_params, + trace_packet, + trace_pdu, + trace_connect, ) @@ -148,8 +151,8 @@ def __init__( # pylint: disable=too-many-arguments reconnect_delay_max: float = 300, timeout: float = 3, retries: int = 3, - trace_packet: Callable[[bool, bytes | None], bytes] | None = None, - trace_pdu: Callable[[bool, ModbusPDU | None], ModbusPDU] | None = None, + trace_packet: Callable[[bool, bytes], bytes] | None = None, + trace_pdu: Callable[[bool, ModbusPDU], ModbusPDU] | None = None, trace_connect: Callable[[bool], None] | None = None, ) -> None: """Initialize Modbus TCP Client.""" @@ -166,7 +169,14 @@ def __init__( # pylint: disable=too-many-arguments reconnect_delay_max=reconnect_delay_max, timeout_connect=timeout, ) - super().__init__(framer, retries, self.comm_params) + super().__init__( + framer, + retries, + self.comm_params, + trace_packet, + trace_pdu, + trace_connect, + ) self.socket = None @property @@ -204,8 +214,9 @@ def close(self): self.socket.close() self.socket = None - def send(self, request): + def send(self, request, addr: tuple | None = None): """Send data on the underlying socket.""" + _ = addr super()._start_send() if not self.socket: raise ConnectionException(str(self)) diff --git a/pymodbus/client/tls.py b/pymodbus/client/tls.py index 852546ca2..1dd67139c 100644 --- a/pymodbus/client/tls.py +++ b/pymodbus/client/tls.py @@ -69,8 +69,8 @@ def __init__( # pylint: disable=too-many-arguments reconnect_delay_max: float = 300, timeout: float = 3, retries: int = 3, - trace_packet: Callable[[bool, bytes | None], bytes] | None = None, - trace_pdu: Callable[[bool, ModbusPDU | None], ModbusPDU] | None = None, + trace_packet: Callable[[bool, bytes], bytes] | None = None, + trace_pdu: Callable[[bool, ModbusPDU], ModbusPDU] | None = None, trace_connect: Callable[[bool], None] | None = None, ): """Initialize Asyncio Modbus TLS Client.""" @@ -92,6 +92,9 @@ def __init__( # pylint: disable=too-many-arguments "", framer=framer, retries=retries, + trace_packet=trace_packet, + trace_pdu=trace_pdu, + trace_connect=trace_connect, ) @classmethod @@ -168,8 +171,8 @@ def __init__( # pylint: disable=too-many-arguments reconnect_delay_max: float = 300, timeout: float = 3, retries: int = 3, - trace_packet: Callable[[bool, bytes | None], bytes] | None = None, - trace_pdu: Callable[[bool, ModbusPDU | None], ModbusPDU] | None = None, + trace_packet: Callable[[bool, bytes], bytes] | None = None, + trace_pdu: Callable[[bool, ModbusPDU], ModbusPDU] | None = None, trace_connect: Callable[[bool], None] | None = None, ): """Initialize Modbus TLS Client.""" @@ -190,6 +193,9 @@ def __init__( # pylint: disable=too-many-arguments "", framer=framer, retries=retries, + trace_packet=trace_packet, + trace_pdu=trace_pdu, + trace_connect=trace_connect, ) @classmethod diff --git a/pymodbus/client/udp.py b/pymodbus/client/udp.py index 76087afec..1163707d8 100644 --- a/pymodbus/client/udp.py +++ b/pymodbus/client/udp.py @@ -71,8 +71,8 @@ def __init__( # pylint: disable=too-many-arguments reconnect_delay_max: float = 300, timeout: float = 3, retries: int = 3, - trace_packet: Callable[[bool, bytes | None], bytes] | None = None, - trace_pdu: Callable[[bool, ModbusPDU | None], ModbusPDU] | None = None, + trace_packet: Callable[[bool, bytes], bytes] | None = None, + trace_pdu: Callable[[bool, ModbusPDU], ModbusPDU] | None = None, trace_connect: Callable[[bool], None] | None = None, ) -> None: """Initialize Asyncio Modbus UDP Client.""" @@ -93,6 +93,9 @@ def __init__( # pylint: disable=too-many-arguments framer, retries, self.comm_params, + trace_packet, + trace_pdu, + trace_connect, ) self.source_address = source_address @@ -149,8 +152,8 @@ def __init__( # pylint: disable=too-many-arguments reconnect_delay_max: float = 300, timeout: float = 3, retries: int = 3, - trace_packet: Callable[[bool, bytes | None], bytes] | None = None, - trace_pdu: Callable[[bool, ModbusPDU | None], ModbusPDU] | None = None, + trace_packet: Callable[[bool, bytes], bytes] | None = None, + trace_pdu: Callable[[bool, ModbusPDU], ModbusPDU] | None = None, trace_connect: Callable[[bool], None] | None = None, ) -> None: """Initialize Modbus UDP Client.""" @@ -166,7 +169,14 @@ def __init__( # pylint: disable=too-many-arguments reconnect_delay_max=reconnect_delay_max, timeout_connect=timeout, ) - super().__init__(framer, retries, self.comm_params) + super().__init__( + framer, + retries, + self.comm_params, + trace_packet, + trace_pdu, + trace_connect, + ) self.socket = None @property @@ -196,11 +206,12 @@ def close(self): """ self.socket = None - def send(self, request: bytes) -> int: + def send(self, request: bytes, addr: tuple | None = None) -> int: """Send data on the underlying socket. :meta private: """ + _ = addr super()._start_send() if not self.socket: raise ConnectionException(str(self)) diff --git a/pymodbus/server/async_io.py b/pymodbus/server/async_io.py index 1f92ea015..36e384ef0 100644 --- a/pymodbus/server/async_io.py +++ b/pymodbus/server/async_io.py @@ -50,7 +50,11 @@ def __init__(self, owner): params, self.framer, 0, - True) + True, + None, + None, + None, + ) def callback_new_connection(self) -> ModbusProtocol: """Call when listener receive new connection request.""" @@ -179,20 +183,16 @@ async def server_async_execute(self, request, *addr): if not broadcast: response.transaction_id = request.transaction_id response.slave_id = request.slave_id - skip_encoding = False if self.server.response_manipulator: - response, skip_encoding = self.server.response_manipulator(response) - self.server_send(response, *addr, skip_encoding=skip_encoding) + response = self.server.response_manipulator(response) + self.server_send(response, *addr) - def server_send(self, message, addr, **kwargs): + def server_send(self, pdu, addr): """Send message.""" - if kwargs.get("skip_encoding", False): - self.send(message, addr=addr) - if not message: + if not pdu: Log.debug("Skipping sending response!!") else: - pdu = self.framer.buildFrame(message) - self.send(pdu, addr=addr) + self.pdu_send(pdu, addr=addr) class ModbusBaseServer(ModbusProtocol): diff --git a/pymodbus/server/simulator/http_server.py b/pymodbus/server/simulator/http_server.py index 44e452fc5..bf5beac22 100644 --- a/pymodbus/server/simulator/http_server.py +++ b/pymodbus/server/simulator/http_server.py @@ -737,7 +737,6 @@ def server_response_manipulator(self, response): The filter returns: - response, either original or modified - - skip_encoding, signals whether or not to encode the response """ if self.call_monitor.trace_response: tracer = CallTracer( @@ -751,12 +750,11 @@ def server_response_manipulator(self, response): self.call_monitor.trace_response = False if self.call_response.active != RESPONSE_INACTIVE: - return response, False + return response - skip_encoding = False if self.call_response.active == RESPONSE_EMPTY: Log.warning("Sending empty response") - return None, False + return None if self.call_response.active == RESPONSE_NORMAL: if self.call_response.delay: Log.warning( @@ -777,13 +775,12 @@ def server_response_manipulator(self, response): err_response.slave_id = response.slave_id elif self.call_response.active == RESPONSE_JUNK: response = os.urandom(self.call_response.junk_len) - skip_encoding = True self.call_response.clear_after -= 1 if self.call_response.clear_after <= 0: Log.info("Resetting manipulator due to clear_after") self.call_response.active = RESPONSE_EMPTY - return response, skip_encoding + return response def server_request_tracer(self, request, *_addr): """Trace requests. diff --git a/pymodbus/transaction/transaction.py b/pymodbus/transaction/transaction.py index a7c38b39b..4da945025 100644 --- a/pymodbus/transaction/transaction.py +++ b/pymodbus/transaction/transaction.py @@ -40,9 +40,9 @@ def __init__( framer: FramerBase, retries: int, is_server: bool, - trace_packet: Callable[[bool, bytes | None], bytes] | None = None, - trace_pdu: Callable[[bool, ModbusPDU | None], ModbusPDU] | None = None, - trace_connect: Callable[[bool], None] | None = None, + trace_packet: Callable[[bool, bytes], bytes] | None, + trace_pdu: Callable[[bool, ModbusPDU], ModbusPDU] | None, + trace_connect: Callable[[bool], None] | None, sync_client = None, ) -> None: """Initialize an instance of the ModbusTransactionManager.""" @@ -58,8 +58,10 @@ def __init__( if sync_client: self.sync_client = sync_client self._sync_lock = RLock() + self.low_level_send = self.sync_client.send else: self._lock = asyncio.Lock() + self.low_level_send = self.send self.response_future: asyncio.Future = asyncio.Future() def dummy_trace_packet(self, sending: bool, data: bytes) -> bytes: @@ -100,10 +102,9 @@ def sync_execute(self, no_response_expected: bool, request: ModbusPDU) -> Modbus raise ConnectionException("Client cannot connect (automatic retry continuing) !!") with self._sync_lock: request.transaction_id = self.getNextTID() - packet = self.framer.buildFrame(self.trace_pdu(True, request)) count_retries = 0 while count_retries <= self.retries: - self.sync_client.send(self.trace_packet(True, packet)) + self.pdu_send(request) if no_response_expected: return ExceptionResponse(0xff) try: @@ -132,10 +133,9 @@ async def execute(self, no_response_expected: bool, request: ModbusPDU) -> Modbu raise ConnectionException("Client cannot connect (automatic retry continuing) !!") async with self._lock: request.transaction_id = self.getNextTID() - packet = self.framer.buildFrame(self.trace_pdu(True, request)) count_retries = 0 while count_retries <= self.retries: - self.send(self.trace_packet(True, packet)) + self.pdu_send(request) if no_response_expected: return None try: @@ -167,6 +167,11 @@ async def server_execute(self) -> tuple[ModbusPDU, int, Exception]: self.response_future = asyncio.Future() return pdu, addr, exc + def pdu_send(self, pdu: ModbusPDU, addr: tuple | None = None) -> None: + """Build byte stream and send.""" + packet = self.framer.buildFrame(self.trace_pdu(True, pdu)) + self.low_level_send(self.trace_packet(True, packet), addr=addr) + def callback_new_connection(self): """Call when listener receive new connection request.""" diff --git a/test/client/test_client.py b/test/client/test_client.py index f6dbb79ba..06c0c552a 100755 --- a/test/client/test_client.py +++ b/test/client/test_client.py @@ -326,6 +326,9 @@ async def test_client_modbusbaseclient(self): port=BASE_PORT + 1, comm_type=CommType.TCP, ), + None, + None, + None, ) client.register(pdu_bit.ReadCoilsResponse) assert str(client) @@ -352,6 +355,9 @@ async def test_client_base_async(self): port=BASE_PORT + 2, comm_type=CommType.TCP, ), + None, + None, + None, ) as client: str(client) client.ctx = mock.Mock() @@ -366,7 +372,7 @@ async def test_client_protocol(self): client.ctx.loop = mock.Mock() client.ctx.callback_connected() client.ctx.callback_disconnected(None) - client = lib_client.AsyncModbusTcpClient("127.0.0.1", trace_connect=1) + client = lib_client.AsyncModbusTcpClient("127.0.0.1", trace_connect=client.ctx.dummy_trace_connect) client.ctx.loop = mock.Mock() client.ctx.callback_connected() client.ctx.callback_disconnected(None) @@ -382,6 +388,9 @@ async def test_client_async_execute(self): port=BASE_PORT + 2, comm_type=CommType.TCP, ), + None, + None, + None, ) as client: str(client) client.ctx = mock.Mock() diff --git a/test/transaction/test_transaction.py b/test/transaction/test_transaction.py index c7d6755c2..0876d0e0e 100755 --- a/test/transaction/test_transaction.py +++ b/test/transaction/test_transaction.py @@ -18,12 +18,36 @@ class TestTransaction: async def test_transaction_instance(self, use_clc): """Test instantiate class.""" - TransactionManager(use_clc, FramerRTU(DecodePDU(False)), 5, False) - TransactionManager(use_clc, FramerRTU(DecodePDU(True)), 5, True) + TransactionManager( + use_clc, + FramerRTU(DecodePDU(False)), + 5, + False, + None, + None, + None, + ) + TransactionManager( + use_clc, + FramerRTU(DecodePDU(True)), + 5, + True, + None, + None, + None, + ) async def test_transaction_manager_tid(self, use_clc): """Test next TID.""" - transact = TransactionManager(use_clc, FramerRTU(DecodePDU(False)), 5, False) + transact = TransactionManager( + use_clc, + FramerRTU(DecodePDU(False)), + 5, + False, + None, + None, + None, + ) assert transact.getNextTID() == 1 for tid in range(2, 12): assert tid == transact.getNextTID() @@ -34,13 +58,29 @@ async def test_transaction_manager_tid(self, use_clc): async def test_transaction_calls(self, use_clc): """Test dummy calls from transport.""" - transact = TransactionManager(use_clc, FramerRTU(DecodePDU(False)), 5, False) + transact = TransactionManager( + use_clc, + FramerRTU(DecodePDU(False)), + 5, + False, + None, + None, + None, + ) transact.callback_new_connection() transact.callback_connected() async def test_transaction_disconnect(self, use_clc): """Test tracers in disconnect.""" - transact = TransactionManager(use_clc, FramerRTU(DecodePDU(False)), 5, False) + transact = TransactionManager( + use_clc, + FramerRTU(DecodePDU(False)), + 5, + False, + None, + None, + None, + ) transact.trace_packet = mock.Mock() transact.trace_pdu = mock.Mock() transact.trace_connect = mock.Mock() @@ -52,19 +92,28 @@ async def test_transaction_disconnect(self, use_clc): @pytest.mark.parametrize("test", [True, False]) async def test_transaction_data(self, use_clc, test): """Test tracers in disconnect.""" - transact = TransactionManager(use_clc, FramerRTU(DecodePDU(False)), 5, False) - transact.framer.processIncomingFrame = mock.Mock(return_value=(0, None)) + pdu = "dummy pdu" packet = b'123' + transact = TransactionManager( + use_clc, + FramerRTU(DecodePDU(False)), + 5, + False, + None, + None, + None, + ) + transact.framer.processIncomingFrame = mock.Mock(return_value=(0, None)) transact.callback_data(packet) assert not transact.response_future.done() - transact.trace_packet = mock.Mock(return_value=packet) - pdu = "dummy pdu" if test: + transact.trace_packet = mock.Mock(return_value=packet) transact.framer.processIncomingFrame.return_value = (1, pdu) transact.callback_data(packet) transact.trace_packet.assert_called_once_with(False, packet) else: + transact.trace_packet = mock.Mock(return_value=packet) transact.trace_pdu = mock.Mock(return_value=pdu) transact.framer.processIncomingFrame.return_value = (1, pdu) transact.callback_data(packet) @@ -75,7 +124,15 @@ async def test_transaction_data(self, use_clc, test): @pytest.mark.parametrize("scenario", range(6)) async def test_transaction_execute(self, use_clc, scenario): """Test tracers in disconnect.""" - transact = TransactionManager(use_clc, FramerRTU(DecodePDU(False)), 5, False) + transact = TransactionManager( + use_clc, + FramerRTU(DecodePDU(False)), + 5, + False, + None, + None, + None, + ) transact.send = mock.Mock() request = ReadCoilsRequest(address=117, count=5) response = ReadCoilsResponse(bits=[True, False, True, True, False]) @@ -114,7 +171,15 @@ async def test_transaction_execute(self, use_clc, scenario): async def test_transaction_receiver(self, use_clc): """Test tracers in disconnect.""" - transact = TransactionManager(use_clc, FramerSocket(DecodePDU(False)), 5, False) + transact = TransactionManager( + use_clc, + FramerSocket(DecodePDU(False)), + 5, + False, + None, + None, + None, + ) transact.send = mock.Mock() response = ReadCoilsResponse(bits=[True, False, True, True, False]) transact.retries = 0 @@ -128,7 +193,15 @@ async def test_transaction_receiver(self, use_clc): @pytest.mark.parametrize("no_resp", [False, True]) async def test_client_protocol_execute_outside(self, use_clc, no_resp): """Test the transaction execute method.""" - transact = TransactionManager(use_clc, FramerSocket(DecodePDU(False)), 5, False) + transact = TransactionManager( + use_clc, + FramerSocket(DecodePDU(False)), + 5, + False, + None, + None, + None, + ) transact.send = mock.Mock() request = ReadCoilsRequest(address=117, count=5) transact.retries = 0 @@ -151,16 +224,57 @@ class TestSyncTransaction: def test_sync_transaction_instance(self, use_clc): """Test instantiate class.""" - client = ModbusBaseSyncClient(FramerType.SOCKET, 5, use_clc) - TransactionManager(use_clc, FramerRTU(DecodePDU(False)), 5, False, sync_client=client) - TransactionManager(use_clc, FramerRTU(DecodePDU(True)), 5, True, sync_client=client) + client = ModbusBaseSyncClient( + FramerType.SOCKET, + 5, + use_clc, + None, + None, + None, + ) + TransactionManager( + use_clc, + FramerRTU(DecodePDU(False)), + 5, + False, + None, + None, + None, + sync_client=client, + ) + TransactionManager( + use_clc, + FramerRTU(DecodePDU(True)), + 5, + True, + None, + None, + None, + sync_client=client, + ) @pytest.mark.parametrize("scenario", range(6)) async def test_sync_transaction_execute(self, use_clc, scenario): """Test tracers in disconnect.""" - client = ModbusBaseSyncClient(FramerType.SOCKET, 5, use_clc) - transact = TransactionManager(use_clc, FramerRTU(DecodePDU(False)), 5, False, sync_client=client) + client = ModbusBaseSyncClient( + FramerType.SOCKET, + 5, + use_clc, + None, + None, + None, + ) + transact = TransactionManager( + use_clc, + FramerRTU(DecodePDU(False)), + 5, + False, + None, + None, + None, + sync_client=client, + ) transact.send = mock.Mock() transact.sync_client.connect = mock.Mock(return_value=True) request = ReadCoilsRequest(address=117, count=5) @@ -201,8 +315,24 @@ async def test_sync_transaction_execute(self, use_clc, scenario): def test_sync_transaction_receiver(self, use_clc): """Test tracers in disconnect.""" - client = ModbusBaseSyncClient(FramerType.SOCKET, 5, use_clc) - transact = TransactionManager(use_clc, FramerRTU(DecodePDU(False)), 5, False, sync_client=client) + client = ModbusBaseSyncClient( + FramerType.SOCKET, + 5, + use_clc, + None, + None, + None, + ) + transact = TransactionManager( + use_clc, + FramerRTU(DecodePDU(False)), + 5, + False, + None, + None, + None, + sync_client=client, + ) transact.sync_client.send = mock.Mock() request = ReadCoilsRequest(address=117, count=5) response = ReadCoilsResponse(bits=[True, False, True, True, False, False, False, False]) @@ -218,8 +348,24 @@ def test_sync_transaction_receiver(self, use_clc): @pytest.mark.parametrize("no_resp", [False, True]) def test_sync_client_protocol_execute_outside(self, use_clc, no_resp): """Test the transaction execute method.""" - client = ModbusBaseSyncClient(FramerType.SOCKET, 5, use_clc) - transact = TransactionManager(use_clc, FramerRTU(DecodePDU(False)), 5, False, sync_client=client) + client = ModbusBaseSyncClient( + FramerType.SOCKET, + 5, + use_clc, + None, + None, + None, + ) + transact = TransactionManager( + use_clc, + FramerRTU(DecodePDU(False)), + 5, + False, + None, + None, + None, + sync_client=client, + ) request = ReadCoilsRequest(address=117, count=5) response = ReadCoilsResponse(bits=[True, False, True, True, False, False, False, False]) transact.retries = 0 @@ -236,8 +382,24 @@ def test_sync_client_protocol_execute_outside(self, use_clc, no_resp): def test_sync_client_protocol_execute_no_pdu(self, use_clc): """Test the transaction execute method.""" - client = ModbusBaseSyncClient(FramerType.SOCKET, 5, use_clc) - transact = TransactionManager(use_clc, FramerRTU(DecodePDU(False)), 5, False, sync_client=client) + client = ModbusBaseSyncClient( + FramerType.SOCKET, + 5, + use_clc, + None, + None, + None, + ) + transact = TransactionManager( + use_clc, + FramerRTU(DecodePDU(False)), + 5, + False, + None, + None, + None, + sync_client=client, + ) request = ReadCoilsRequest(address=117, count=5) response = ReadCoilsResponse(bits=[True, False, True, True, False, False, False, False]) transact.retries = 0