Skip to content

Backport robustness improvements from python-s7comm#580

Merged
gijzelaerr merged 1 commit intomasterfrom
incorporate-s7comm-improvements
Feb 27, 2026
Merged

Backport robustness improvements from python-s7comm#580
gijzelaerr merged 1 commit intomasterfrom
incorporate-s7comm-improvements

Conversation

@gijzelaerr
Copy link
Owner

Summary

Backports concrete robustness improvements from nikteliy/python-s7comm to the native Python S7 implementation:

  • 210+ S7 protocol error codes from Wireshark's S7 dissector — covers USERDATA parameter errors (0xD0xx), protocol errors (0x8xxx), resource errors, and more. parse_response() now raises descriptive S7ProtocolError on header errors, and USERDATA response parsing logs descriptive warnings.
  • Stale packet detection with retry — new validate_pdu_reference() validates response sequence numbers. New _send_receive() helper wraps the send→receive→parse pattern with automatic retry on stale packets (up to 3 retries). Refactored ~15 call sites in client.py to use it.
  • Automatic PDU splitting for read_area()/write_area() — requests exceeding the negotiated PDU length are automatically chunked, preventing PLC rejections on large reads (e.g., db_get() on big DBs).
  • TPDUSize enum (ISO 8073) with configurable COTP negotiation — replaces hardcoded 0x0A with a proper TPDUSize IntEnum (128–8192 bytes).
  • MAX_VARS=20 limit on read_multi_vars()/write_multi_vars() — raises ValueError when exceeding the S7 protocol limit.

Not incorporated: async client, Protocol-based typing, packet-per-class architecture, PCAP-based testing.

Test plan

  • 27 new unit tests in tests/test_improvements.py covering all features
  • All 428 tests pass (401 existing + 27 new)
  • ruff check, ruff format --check, mypy all pass clean

🤖 Generated with Claude Code

@gijzelaerr gijzelaerr force-pushed the incorporate-s7comm-improvements branch from 922b5bd to 8ed1fcc Compare February 27, 2026 07:34
@gijzelaerr gijzelaerr requested a review from nikteliy February 27, 2026 07:43
Backports concrete robustness improvements from nikteliy/python-s7comm
to the native Python S7 implementation:

- 210+ S7 protocol error codes from Wireshark's S7 dissector covering
  USERDATA parameter errors (0xD0xx), protocol errors (0x8xxx), and
  resource errors. parse_response() now raises descriptive S7ProtocolError
  on header errors, and USERDATA response parsing logs warnings.

- Stale packet detection with retry: new validate_pdu_reference()
  validates response sequence numbers. New _send_receive() helper wraps
  the send/receive/parse pattern with automatic retry on stale packets
  (up to 3 retries). Refactored ~15 call sites in client.py to use it.

- Automatic PDU splitting for read_area()/write_area(): requests
  exceeding the negotiated PDU length are automatically chunked,
  preventing PLC rejections on large reads (e.g. db_get() on big DBs).

- TPDUSize enum (ISO 8073) with configurable COTP negotiation: replaces
  hardcoded 0x0A with a proper IntEnum (128-8192 bytes).

- MAX_VARS=20 limit on read_multi_vars()/write_multi_vars(): raises
  ValueError when exceeding the S7 protocol limit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gijzelaerr gijzelaerr force-pushed the incorporate-s7comm-improvements branch from 8ed1fcc to c3b54dd Compare February 27, 2026 07:51
@gijzelaerr gijzelaerr merged commit 154d678 into master Feb 27, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants