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
7 changes: 4 additions & 3 deletions s7commplus/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
_set_s7_groups,
)
from .protocol import (
FLAGS_34_FUNCTION_CODES,
READ_FUNCTION_CODES,
S7COMMPLUS_LOCAL_TSAP,
S7COMMPLUS_REMOTE_TSAP,
Expand Down Expand Up @@ -737,8 +738,8 @@ async def _send_request(
0x0000,
seq_num,
self._session_id,
# Transport flags: 0x34 for GetMultiVariables and Explore, 0x36 otherwise.
0x34 if function_code in (FunctionCode.GET_MULTI_VARIABLES, FunctionCode.EXPLORE) else 0x36,
# Transport flags: 0x34 for the function codes the reference sends with 0x34.
0x34 if function_code in FLAGS_34_FUNCTION_CODES else 0x36,
)

integrity_id_bytes = b""
Expand Down Expand Up @@ -992,7 +993,7 @@ async def _delete_session(self) -> None:
0x0000,
seq_num,
self._session_id,
0x36,
0x34,
)
request += struct.pack(">I", 0)

Expand Down
9 changes: 4 additions & 5 deletions s7commplus/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

from .codec import decode_header, encode_header, encode_object_qualifier, parse_create_object_attributes
from .protocol import (
FLAGS_34_FUNCTION_CODES,
READ_FUNCTION_CODES,
S7COMMPLUS_LOCAL_TSAP,
S7COMMPLUS_REMOTE_TSAP,
Expand Down Expand Up @@ -716,10 +717,8 @@ def send_request(self, function_code: int, payload: bytes = b"", integrity_tail:
seq_num,
self._session_id,
# Transport flags: 0x34 after SessionKey auth (matches TIA Portal),
# also for GetMultiVariables and Explore; 0x36 for other V1/TLS requests.
0x34
if self._session_key is not None or function_code in (FunctionCode.GET_MULTI_VARIABLES, FunctionCode.EXPLORE)
else 0x36,
# and for the function codes the reference sends with 0x34.
0x34 if self._session_key is not None or function_code in FLAGS_34_FUNCTION_CODES else 0x36,
)

integrity_id_bytes = b""
Expand Down Expand Up @@ -1470,7 +1469,7 @@ def _delete_session(self) -> None:
0x0000,
seq_num,
self._session_id,
0x36,
0x34,
)
request += struct.pack(">I", 0)

Expand Down
20 changes: 20 additions & 0 deletions s7commplus/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,26 @@ class Ids(IntEnum):
}
)

# Function codes whose requests carry transport flags 0x34. The reference sets
# this per request class rather than by read/write, so it is a different split
# than READ_FUNCTION_CODES: the writes SetVariable, SetMultiVariables and
# DeleteObject use 0x34 too. Only CreateObject (0x36) and InitSSL (0x30) differ,
# and a session-setup CreateObject sent with 0x34 makes the PLC reset the
# connection. Subscription and alarm CreateObjects are the documented exception:
# the reference overrides those to 0x34.
#
# Reference: TransportFlags in thomas-v2/S7CommPlusDriver/Core/*Request.cs
FLAGS_34_FUNCTION_CODES: frozenset[int] = frozenset(
{
FunctionCode.DELETE_OBJECT,
FunctionCode.EXPLORE,
FunctionCode.GET_MULTI_VARIABLES,
FunctionCode.GET_VAR_SUBSTREAMED,
FunctionCode.SET_MULTI_VARIABLES,
FunctionCode.SET_VARIABLE,
}
)


class AccessLevel(IntEnum):
"""Protection levels reported by `Ids.EFFECTIVE_PROTECTION_LEVEL`.
Expand Down
Loading