Skip to content

Move S7CommPlus into s7/ package, simplify to 2-layer architecture#662

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

Move S7CommPlus into s7/ package, simplify to 2-layer architecture#662
gijzelaerr wants to merge 4 commits intomasterfrom
s7-unified-package

Conversation

@gijzelaerr
Copy link
Copy Markdown
Owner

Summary

  • Moves all S7CommPlus protocol code from snap7/s7commplus/ into a new top-level s7/ package
  • Simplifies 3 layers (snap7, snap7.s7commplus, s7) down to 2: snap7/ (legacy, untouched) and s7/ (unified frontend)
  • Fallback logic now lives in one place only: s7.Client tries S7CommPlus, falls back to snap7.Client
  • Includes the session setup fix from Complete S7CommPlus V1 session handshake #661 (ServerSessionVersion echo)

How it works

from s7 import Client, Protocol

client = Client()
client.connect("192.168.1.10", 0, 1)  # auto-detects best protocol
data = client.db_read(1, 0, 4)
print(client.protocol)  # Protocol.S7COMMPLUS or Protocol.LEGACY

What changed

  • snap7/s7commplus/ deleted entirely
  • Protocol files (codec, vlq, protocol, connection, legitimation) moved to s7/
  • Pure S7CommPlus clients (s7/_s7commplus_client.py) stripped of fallback logic
  • Unified s7.Client/s7.AsyncClient own the fallback decision
  • Tests renamed test_s7commplus_*test_s7_* with updated imports
  • Docs, pyproject.toml, tox.ini, Makefile, CLAUDE.md updated

Supersedes #657 and #661.

Test plan

  • All 1320 tests pass
  • mypy clean (69 files)
  • ruff check + format clean
  • E2E against real PLC when available

🤖 Generated with Claude Code

gijzelaerr and others added 4 commits March 27, 2026 08:42
Instead of probing data operations and falling back on ERROR2, properly
complete the V1 session setup by parsing ServerSessionVersion (attribute
306) from the CreateObject response and echoing it back via
SetMultiVariables. This should fix the ERROR2 (0x05A9) rejections from
real S7-1200/1500 PLCs with firmware v4.0+.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collapse 3 layers (snap7, snap7.s7commplus, s7) into 2:
- snap7/ stays untouched as legacy S7 protocol
- s7/ is the new unified frontend with S7CommPlus + legacy fallback

Key changes:
- Move all S7CommPlus protocol code from snap7/s7commplus/ to s7/
- Remove duplicated fallback logic — now lives only in s7.Client
- Pure S7CommPlus clients (_s7commplus_client.py) have no fallback
- s7.Client tries S7CommPlus first, falls back to snap7.Client
- Rename tests: test_s7commplus_* → test_s7_*
- Update all imports, docs, tooling (mypy, ruff, tox)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Resolve conflicts in s7/_s7commplus_client.py and
s7/_s7commplus_async_client.py — keep our refactored versions
which already include the session setup fix from #661 but
without the fallback logic (now owned by s7.Client).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- s7.Client.db_write() and s7.AsyncClient.db_write() now return int (0)
  matching snap7.Client behavior
- s7.AsyncClient.disconnect() now returns int (0) matching snap7.AsyncClient
- doc/introduction.rst: explain two-package architecture (snap7 vs s7)
- doc/connecting.rst: add tip about s7 package for S7-1200/1500
- Keep S7CommPlus marked as experimental throughout

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