diff --git a/pymodbus/framer/socket_framer.py b/pymodbus/framer/socket_framer.py index 48616e52f..8460c8a15 100644 --- a/pymodbus/framer/socket_framer.py +++ b/pymodbus/framer/socket_framer.py @@ -75,10 +75,7 @@ def frameProcessIncomingPacket(self, single, callback, slave, tid=None, **kwargs while True: used_len, use_tid, dev_id, data = self.message_handler.decode(self._buffer) if not data: - if not used_len: - return - self._buffer = self._buffer[used_len :] - continue + return self._header["uid"] = dev_id self._header["tid"] = use_tid self._header["pid"] = 0 diff --git a/pymodbus/framer/tls_framer.py b/pymodbus/framer/tls_framer.py index 5b88c1e34..a39de0321 100644 --- a/pymodbus/framer/tls_framer.py +++ b/pymodbus/framer/tls_framer.py @@ -6,7 +6,6 @@ ModbusIOException, ) from pymodbus.framer.base import TLS_FRAME_HEADER, ModbusFramer -from pymodbus.logging import Log from pymodbus.message.tls import MessageTLS @@ -44,25 +43,18 @@ def decode_data(self, data): return {"fcode": fcode} return {} - def frameProcessIncomingPacket(self, single, callback, slave, _tid=None, **kwargs): + def frameProcessIncomingPacket(self, _single, callback, _slave, _tid=None, **kwargs): """Process new packet pattern.""" # no slave id for Modbus Security Application Protocol while True: used_len, use_tid, dev_id, data = self.message_handler.decode(self._buffer) if not data: - if not used_len: - return - self._buffer = self._buffer[used_len :] - continue + return self._header["uid"] = dev_id self._header["tid"] = use_tid self._header["pid"] = 0 - if not self._validate_slave_id(slave, single): - Log.debug("Not in valid slave id - {}, ignoring!!", slave) - self.resetFrame() - return if (result := self.decoder.decode(data)) is None: raise ModbusIOException("Unable to decode request") self.populateResult(result) diff --git a/pymodbus/pdu.py b/pymodbus/pdu.py index 64c48b1e1..13dd7981b 100644 --- a/pymodbus/pdu.py +++ b/pymodbus/pdu.py @@ -249,6 +249,9 @@ def __init__(self, function_code, **kwargs): def decode(self, _data): """Decode so this failure will run correctly.""" + def encode(self): + """Decode so this failure will run correctly.""" + def execute(self, _context): """Build an illegal function request error response. diff --git a/test/test_framers.py b/test/test_framers.py index b43c3f08e..280634d98 100644 --- a/test/test_framers.py +++ b/test/test_framers.py @@ -12,6 +12,7 @@ ModbusAsciiFramer, ModbusRtuFramer, ModbusSocketFramer, + ModbusTlsFramer, ) from pymodbus.transport import CommType from pymodbus.utilities import ModbusTransactionState @@ -481,6 +482,7 @@ def test_processincomingpacket_ok(self, framer, message, slave): (ModbusAsciiFramer, b':01270001000ACD\r\n',), (ModbusRtuFramer, b"\x01\x03\x03\x01\x00\n\x94\x49",), (ModbusSocketFramer, b'\x00\x00\x00\x00\x00\x06\x01\x27\x00\x01\x00\n',), + (ModbusTlsFramer, b'\x54\x00\x7c\x00\x02',), ] ) def test_processincomingpacket_not_ok(self, framer, message):