Skip to content

Fragmentation support - #994

Merged
gijzelaerr merged 6 commits into
gijzelaerr:masterfrom
hs2bws:Fragmentation
Nov 16, 2026
Merged

gijzelaerr merged 6 commits into
gijzelaerr:masterfrom
hs2bws:Fragmentation

Conversation

@hs2bws

@hs2bws hs2bws commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

b_send(), b_recv(), as_b_send() and as_b_recv() now allows fragmentation into multiple network frames. This enables transmissions of up to 65,534 bytes per request.

b_send(), b_recv(), as_b_send() and as_b_recv() now allows fragmentation into multiple network frames. This enables transmissions of up to 65,534 bytes per request.

@gijzelaerr gijzelaerr left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @hs2bws. Points 1 (send side) and 4 are fixed, the shared _b_recv_loop() helper is what I meant, and the three fragment tests from your capture pin the wire format. The 101 partner tests pass for me locally. What is left:

  1. Empty message on receive. The frame b_send() builds for an empty payload is now identical to master. But _parse_partner_data_pdu() only takes the R-ID when the announced length is at least 1, so an empty message comes back with R-ID 0. Please drop the data_bsend_lengh >= 1 condition.
  2. Unrecognised PDUs. A PDU with another function group or subfunction, or with an error code set, still returns an empty payload, and _b_recv_loop() acks it. Please raise S7Error there too, with the error code in the message.
  3. Length checks. Two cases still raise struct.error:
    • a parameter block of 5 to 11 bytes (param[5:12] is unpacked after only checking for 5);
    • a 13-byte data section in a first or unfragmented PDU (data[12:14] needs 14).
  4. Limits.
    • b_send() refuses more than 65,534 bytes with S7ConnectionError. That is not a connection problem; please use S7Error or ValueError.
    • _b_recv_loop() stops at 65,534 bytes. Please stop as soon as the fragments exceed the length announced in the first one.
  5. Lint. ruff check reports four E712 errors (== False, == True), and ruff format wants to reformat snap7/partner.py and tests/test_partner.py. uv run pre-commit run --all-files fixes the formatting; the comparisons need not x / x by hand.

Small things: _b_recv_loop() returns an empty message when there is no connection, where raising S7ConnectionError would be clearer, and the commented-out lines (#return bytes(0x00), ..., #sequence = ...) can go.

Please push further changes to this branch, so the review stays in one place.

@hs2bws

hs2bws commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

I hope this works now. Regarding the length tests, please note that the u_send parameters and data areas have different lengths - this is relevant for the next step. That is why I am verifying the lengths in several stages.

@gijzelaerr

Copy link
Copy Markdown
Owner

Thanks, @hs2bws, that covers all the functional points: I checked the empty message, the unrecognised PDUs, the short parameter and data blocks and the announced-length limit against this commit, and each now behaves as asked. Staging the length checks for u_send is fine.

The only thing left is pre-commit. One run fixes everything, including the new E701 (else: raise ... on one line):

uv run pre-commit run --all-files

Commit what it changes and push. While you are at it, the two commented-out lines (#return bytes(0x00), ... and #sequence = ...) can go.

hs2bws and others added 2 commits November 16, 2026 19:22
pre-commit fix
two commented-out lines removed
Formatting only: ruff format on snap7/partner.py and tests/test_partner.py,
and trailing whitespace in CHANGES.md.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@gijzelaerr

Copy link
Copy Markdown
Owner

Thanks, @hs2bws, the lint errors are gone. Only the formatting was left, so I pushed it to your branch myself (48686cf, formatting only, no code changes). The pre-commit check now passes.

Please run git pull on your Fragmentation branch before you change anything else, so your next push does not conflict with that commit.

@gijzelaerr gijzelaerr left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All points from the review are covered and CI is green. Thanks, @hs2bws.

@gijzelaerr
gijzelaerr merged commit 652a0d3 into gijzelaerr:master Nov 16, 2026
17 checks passed
@hs2bws

hs2bws commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the help. I was able to learn a lot.

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