Repository navigation
Fragmentation support - #994
Conversation
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
left a comment
There was a problem hiding this comment.
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:
- Empty message on receive. The frame
b_send()builds for an empty payload is now identical tomaster. 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 thedata_bsend_lengh >= 1condition. - 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 raiseS7Errorthere too, with the error code in the message. - 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).
- a parameter block of 5 to 11 bytes (
- Limits.
b_send()refuses more than 65,534 bytes withS7ConnectionError. That is not a connection problem; please useS7ErrororValueError._b_recv_loop()stops at 65,534 bytes. Please stop as soon as the fragments exceed the length announced in the first one.
- Lint.
ruff checkreports four E712 errors (== False,== True), andruff formatwants to reformatsnap7/partner.pyandtests/test_partner.py.uv run pre-commit run --all-filesfixes the formatting; the comparisons neednot x/xby 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.
|
I hope this works now. Regarding the length tests, please note that the |
|
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 The only thing left is pre-commit. One run fixes everything, including the new E701 ( Commit what it changes and push. While you are at it, the two commented-out lines ( |
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>
|
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 |
gijzelaerr
left a comment
There was a problem hiding this comment.
All points from the review are covered and CI is green. Thanks, @hs2bws.
|
Thanks for the help. I was able to learn a lot. |
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.