Skip to content

Fixed "get_cpu_info" and "__str__" in structure "S7SZL"#692

Merged
gijzelaerr merged 3 commits intogijzelaerr:masterfrom
qzertywsx:cpu_info-fix
Apr 15, 2026
Merged

Fixed "get_cpu_info" and "__str__" in structure "S7SZL"#692
gijzelaerr merged 3 commits intogijzelaerr:masterfrom
qzertywsx:cpu_info-fix

Conversation

@qzertywsx
Copy link
Copy Markdown
Contributor

  • Fix in structure "S7SZL" function "__str__" in file "snap7/type.py", previously gave error "AttributeError: 'S7SZL' object has no attribute 'S7SZHeader'"

  • Fixed function get_cpu_info in file "snap7/client.py", it returned all the field empty.

Now tested working on s7-300 and s7-1500, same output as the old python-snap7 2.1.1.

Fix in structure "S7SZL" function "__str__", previusly gave error "AttributeError: 'S7SZL' object has no attribute 'S7SZHeader'"
Fixed function get_cpu_info, it returned all the field empty.
Now tested working on s7-300 and s7-1500, same output as the old python-snap7 2.1.1.
Fixed function get_cpu_info, it returned all the field empty.
Now tested working on s7-300 and s7-1500, same output as the old python-snap7 2.1.1.
@gijzelaerr gijzelaerr merged commit 99c01ff into gijzelaerr:master Apr 15, 2026
1 check passed
gijzelaerr added a commit that referenced this pull request Apr 15, 2026
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>
gijzelaerr added a commit that referenced this pull request Apr 15, 2026
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>
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>
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