Skip to content

Commit ef9aee0

Browse files
committed
use TIA Portal EXPLORE format for V1-initial PLCs
V1-initial PLCs expect a 4-byte big-endian InObjectId in the EXPLORE payload instead of a VLQ-encoded explore_id. Match the format observed in TIA Portal v19 pcaps: InObjectId + fixed params + sequence byte. Default explore target is 0x38 (system object for PLC program tree), matching what TIA Portal sends.
1 parent ac84da7 commit ef9aee0

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

s7/_s7commplus_client.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,10 @@ def explore(self, explore_id: int = 0) -> bytes:
261261
if self._connection is None:
262262
raise RuntimeError("Not connected")
263263

264-
payload = _build_explore_payload(explore_id)
264+
if self._connection._session_key is not None:
265+
payload = _build_explore_payload_v3(explore_id if explore_id else 0x38)
266+
else:
267+
payload = _build_explore_payload(explore_id)
265268
response = self._connection.send_request(FunctionCode.EXPLORE, payload)
266269
return response
267270

@@ -720,6 +723,19 @@ def _build_explore_payload(explore_id: int = 0) -> bytes:
720723
return bytes(payload)
721724

722725

726+
def _build_explore_payload_v3(explore_id: int, sequence: int = 10) -> bytes:
727+
"""Build a V3-style EXPLORE request payload matching TIA Portal format.
728+
729+
V1-initial PLCs use a 4-byte big-endian InObjectId followed by
730+
fixed parameters, rather than the VLQ-based format.
731+
"""
732+
payload = struct.pack(">I", explore_id)
733+
payload += bytes([0x00, 0x01, 0x00, 0x01, 0x00, 0x00])
734+
payload += bytes([sequence & 0xFF])
735+
payload += bytes([0x00, 0x00, 0x00, 0x00, 0x00])
736+
return payload
737+
738+
723739
def _build_invoke_payload(state: int) -> bytes:
724740
"""Build an INVOKE request payload for SetPlcOperatingState.
725741

0 commit comments

Comments
 (0)