From 4b8ab6f7b1d150dd8a78e6a75cda1e03084ce819 Mon Sep 17 00:00:00 2001 From: jan iversen Date: Tue, 5 Mar 2024 10:55:10 +0100 Subject: [PATCH] ASCII+TLS integrated. --- pymodbus/framer/ascii_framer.py | 7 ++++++- pymodbus/framer/tls_framer.py | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pymodbus/framer/ascii_framer.py b/pymodbus/framer/ascii_framer.py index 0d999cb73..b965dbc27 100644 --- a/pymodbus/framer/ascii_framer.py +++ b/pymodbus/framer/ascii_framer.py @@ -113,7 +113,12 @@ def buildPacket(self, message): packet.extend(b2a_hex(encoded)) packet.extend(f"{checksum:02x}".encode()) packet.extend(self._end) - return bytes(packet).upper() + packet = bytes(packet).upper() + + data = message.function_code.to_bytes(1,'big') + encoded + packet_new = self.message_handler.encode(data, message.slave_id, message.transaction_id) + assert packet == packet_new, "ASCII FRAMER BuildPacket failed!" + return packet # __END__ diff --git a/pymodbus/framer/tls_framer.py b/pymodbus/framer/tls_framer.py index f37729953..70cd821ce 100644 --- a/pymodbus/framer/tls_framer.py +++ b/pymodbus/framer/tls_framer.py @@ -82,6 +82,10 @@ def buildPacket(self, message): data = message.encode() packet = struct.pack(TLS_FRAME_HEADER, message.function_code) packet += data + + data_new = message.function_code.to_bytes(1,'big') + data + packet_new = self.message_encoder.encode(data_new, message.slave_id, message.transaction_id) + assert packet == packet_new, "TLS FRAMER BuildPacket failed!" return packet