Fix server SZL response to match real PLC format (fixes #692 regression)#694
Merged
Conversation
PR #692 corrected get_cpu_info field offsets to match real S7-300/1500 SZL responses. The server emulator was using a simplified sequential layout that didn't match. Update the server to place fields at the correct offsets (ASName@6, ModuleName@40, Copyright@108, SerialNumber@142, ModuleTypeName@176). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3 tasks
gijzelaerr
added a commit
that referenced
this pull request
Apr 21, 2026
* Fix async get_cpu_info SZL offsets to match sync Discussion #700 reports that AsyncClient.get_cpu_info() returns empty fields against a real PLC. Root cause: PR #692 fixed the offsets in the sync Client (0,32,56,80,106,130 → 6,30,40,64,108,134,142,166, 176,208 with the correct field ordering) and #694 updated the server emulator to match, but async_client.py was never touched and kept the pre-#692 layout. Ports the same offsets to the async client so sync/async produce identical output against both real PLCs and the server emulator. Strengthens the async test to assert specific field values (matching the sync test) instead of just checking attribute presence — the prior smoke test passed even with all-empty fields. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Extract SZL and block parsers shared by sync and async clients Follow-on to the async get_cpu_info fix: the root cause was that parsing logic for SZL records (and the block-info dict→struct copy) lived inline in both Client and AsyncClient, so a fix to one side silently drifted from the other. - New snap7/szl.py module with parse_{cpu_info,cp_info,order_code, protection}_szl(szl) helpers. Both clients call them; offsets and field definitions exist in exactly one place. - Two new non-SZL converters live alongside the existing protocol parsers in s7protocol.py (build_blocks_list_from_dict, build_block_info_from_dict) exposed as S7Protocol.parse_list_blocks / S7Protocol.parse_get_block_info. The clients' dict→struct copies disappear. - Strengthened async tests for list_blocks, get_cp_info, get_order_code, get_protection, get_block_info — the previous tests only did hasattr() checks and so could not catch a value regression. They now assert the same concrete values the sync suite asserts. Net: clients shrink by ~280 lines, parsing surface is unified, and the async tests carry the same safety net as sync. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR #692 corrected
get_cpu_infofield offsets to match real S7-300/1500 SZL responses, but the server emulator was still using the old simplified layout. This fixes the server to place CPU info fields at the correct offsets.🤖 Generated with Claude Code