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

DiagnosticStatus encode missing tuple check. #1533

Merged
merged 2 commits into from
Apr 27, 2023
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
2 changes: 1 addition & 1 deletion pymodbus/diag_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def encode(self):
packet += self.message.encode()
elif isinstance(self.message, bytes):
packet += self.message
elif isinstance(self.message, list):
elif isinstance(self.message, (list, tuple)):
for piece in self.message:
packet += struct.pack(">H", piece)
elif isinstance(self.message, int):
Expand Down
11 changes: 11 additions & 0 deletions test/test_diag_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,23 @@ class TestDataStore:
(GetClearModbusPlusResponse, b"\x00\x15\x00\x04" + b"\x00\x00" * 55),
]

def test_diagnostic_encode_decode(self):
"""Testing diagnostic request/response can be decoded and encoded."""
for msg in (DiagnosticStatusRequest, DiagnosticStatusResponse):
msg_obj = msg()
data = b"\x00\x01\x02\x03"
msg_obj.decode(data)
result = msg_obj.encode()
assert data == result

def test_diagnostic_requests_decode(self):
"""Testing diagnostic request messages encoding"""
for msg, enc, _ in self.requests:
handle = DiagnosticStatusRequest()
handle.decode(enc)
assert handle.sub_function_code == msg.sub_function_code
encoded = handle.encode()
assert enc == encoded

def test_diagnostic_simple_requests(self):
"""Testing diagnostic request messages encoding"""
Expand Down