Skip to content
Open
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ Unreleased
block (method `0x12`) that real engineering tools send; both previously used the header of a request without data
and an 8-byte parameter block (#942).

* `get_order_code` no longer keeps the trailing space padding of the order code on S7-1200/1500 CPUs, for example
`6ES7 212-1BE40-0XB0 ` is now `6ES7 212-1BE40-0XB0` (#949).

### Documentation

* Add a "Tested and Verified Hardware" section to the PLC support matrix, listing the CPUs, firmware versions and
Expand Down
2 changes: 1 addition & 1 deletion snap7/szl.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def _parse_order_code_structured(data: bytes, record_len: int, ndr: int, order_c

if record_id == 0x0001 and record_len >= 22:
found_structured = True
order_code.OrderCode = rec[2:22].rstrip(b"\x00")
order_code.OrderCode = rec[2:22].rstrip(b"\x00 ")
if record_len >= 26 and not has_0x0007 and (rec[23] != 0 or rec[24] != 0):
order_code.V1, order_code.V2, order_code.V3 = rec[23], rec[24], rec[25]

Expand Down
14 changes: 14 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,20 @@ def test_parse_order_code_s71516f(self) -> None:
self.assertEqual(result.V2, 9)
self.assertEqual(result.V3, 2)

def test_parse_order_code_strips_trailing_space(self) -> None:
"""The structured MLFB field is space padded on real PLCs; the padding is not part of the order code."""
from snap7.szl import parse_order_code_szl
from snap7.type import S7SZL

payload = b"\x00\x1c\x00\x01\x00\x01" + b"6ES7 212-1BE40-0XB0 " + b"\x00\x00\x00\x02\x00\x00"
szl = S7SZL()
szl.Header.LengthDR = len(payload)
for i, b in enumerate(payload):
szl.Data[i] = b

result = parse_order_code_szl(szl)
self.assertEqual(result.OrderCode, b"6ES7 212-1BE40-0XB0")

def test_parse_order_code_s71510sp(self) -> None:
"""Parse a real S7-1510SP dump — should use 0x0007 firmware, not 0x0081 boot loader.

Expand Down
Loading