Skip to content

Commit

Permalink
Auto fill device ids for clients. (#2372)
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen authored Oct 11, 2024
1 parent 047a821 commit f3a2a54
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pymodbus/framer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion test/framers/test_framer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

0 comments on commit f3a2a54

Please sign in to comment.