diff --git a/pymodbus/framer/base.py b/pymodbus/framer/base.py index 9e704c8f6..392698f50 100644 --- a/pymodbus/framer/base.py +++ b/pymodbus/framer/base.py @@ -69,12 +69,14 @@ def specific_decode(self, data: bytes, data_len: int) -> tuple[int, bytes]: return data_len, data - def encode(self, pdu: bytes, _dev_id: int, _tid: int) -> bytes: + def encode(self, pdu: bytes, dev_id: int, _tid: int) -> bytes: """Encode ADU. returns: modbus ADU (bytes) """ + if dev_id and dev_id not in self.dev_ids: + self.dev_ids.append(dev_id) return pdu def buildPacket(self, message: ModbusRequest | ModbusResponse) -> bytes: diff --git a/test/framers/test_framer.py b/test/framers/test_framer.py index 5a729e9cf..89bc10e57 100644 --- a/test/framers/test_framer.py +++ b/test/framers/test_framer.py @@ -31,6 +31,9 @@ def test_base(self): framer = FramerBase(ClientDecoder(), []) framer.decode(b'') framer.encode(b'', 0, 0) + dev_id = 2 + framer.encode(b'', dev_id, 0) + assert dev_id in framer.dev_ids @pytest.mark.parametrize(("entry"), list(FramerType)) async def test_framer_init(self, test_framer): @@ -373,4 +376,3 @@ def test_specific_decode(self, test_framer): res_len, res_data = test_framer.specific_decode(msg, 0) assert not res_len assert not res_data -