Skip to content

Add unified s7 package with protocol auto-discovery#657

Closed
gijzelaerr wants to merge 4 commits intomasterfrom
unified-s7-package
Closed

Add unified s7 package with protocol auto-discovery#657
gijzelaerr wants to merge 4 commits intomasterfrom
unified-s7-package

Conversation

@gijzelaerr
Copy link
Copy Markdown
Owner

Summary

  • Introduces a new top-level s7 package providing a unified Client, AsyncClient, and Server with automatic protocol selection (S7CommPlus vs legacy S7)
  • Users no longer need to choose between snap7.Client and snap7.s7commplus.Clientfrom s7 import Client handles everything
  • Full backward compatibility: all ~100 legacy client methods available via __getattr__ delegation, db_read/db_write route through S7CommPlus when available

How it works

from s7 import Client

client = Client()
client.connect("192.168.1.10", 0, 1)  # tries S7CommPlus, falls back to legacy
data = client.db_read(1, 0, 4)        # uses best available protocol
print(client.protocol)                 # Protocol.LEGACY or Protocol.S7COMMPLUS
  • connect() keeps the legacy positional args for backward compat
  • S7CommPlus extras (use_tls, password) available as keyword-only args
  • protocol=Protocol.LEGACY to skip S7CommPlus entirely
  • Unified Server wraps both legacy and S7CommPlus servers

Test plan

  • uv run pytest tests/test_s7_unified.py — 26 new unit tests pass
  • uv run pytest tests/ — all existing tests unaffected
  • uv run mypy snap7 s7 tests — clean
  • uv run ruff check snap7 s7 tests — clean
  • E2E: from s7 import Client; c = Client(); c.connect(host, rack, slot) against real PLC

🤖 Generated with Claude Code

Introduces a new top-level `s7` package that provides a single Client,
AsyncClient, and Server that automatically select the best protocol
(S7CommPlus or legacy S7) for the target PLC. Users no longer need to
choose between snap7.Client and snap7.s7commplus.Client.

- `from s7 import Client` — unified entry point
- connect() tries S7CommPlus first, falls back to legacy transparently
- Full legacy API (~100 methods) available via __getattr__ delegation
- db_read/db_write route through S7CommPlus when available
- Unified Server wraps both legacy and S7CommPlus servers
- 26 unit tests covering auto-discovery, fallback, and delegation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
gijzelaerr and others added 3 commits March 25, 2026 14:15
Add complete V2 and V3 support including TLS 1.3 encryption,
per-request IntegrityId counters, session setup handshake, and
password authentication (legitimation). Extend server emulator
to support V2/V3 for integration testing without real hardware.

- Fix V3 handling in connection.py (unified V2/V3 code path)
- Add TLS, session setup, and auth to async client
- Add legitimation and IntegrityId emulation to server
- Add 21 TLS integration tests (sync + async, V2 + V3, auth)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant