Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto fill device ids for clients. #2372

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Loading