feat(s7commplus): add multi-write APIs - #819
Conversation
Co-Authored-By: Codex <noreply@openai.com>
|
@bvanelli I refreshed this branch onto current Since you have both current V2 and legacy/session-key PLC coverage, could you also try one pip install --upgrade "python-snap7 @ git+https://github.com/gijzelaerr/python-snap7.git@feat/795-s7commplus-multi-write"The current head passes 1,826 tests, the complete pre-commit suite, and the package build. |
|
@bvanelli Following up on the earlier hardware-testing request: could you also review the current multi-write implementation and API shape when you have a moment? |
|
Hello @gijzelaerr , I did take a look during the week. The plc returns an error, so I was instead trying to report exactly what was failing: there were some theories like pvalue implementation, integrity id handling, etc. I'll report it whenever I have time next week again. |
|
I'll post the traceback tomorrow, but I instructed one agent to figure out what was causing the problem. Here is what it did:
Here was the final run from the agent (you can ignore some of the output, since it's assuming things): Would you rather have me try to find a BLOB datatype to write instead, then tackle datatype handling in a different PR? |
Co-Authored-By: Codex <noreply@openai.com>
|
Implemented the hardware-test findings in 6ad0fa5. The fixed literal after ObjectQualifier was acting as a second IntegrityId once the connection inserted its tracked counter. All multi/area/symbolic read and write builders now leave IntegrityId insertion exclusively to the connection. Multi-write items can now specify the PLC datatype as a fourth tuple element, for example: client.db_write_multi([
(7, 0, struct.pack(">f", 2.0), DataType.REAL),
(7, 4, b"\x02\x00", DataType.WORD),
])Existing three-tuples remain BLOB writes for compatibility. Explicit fixed-width types are length-validated, and the same typed encoding is used by the legacy substreamed fallback. Validation: 1,779 passed, 82 skipped; full pre-commit suite and source/wheel build pass. A real-PLC round trip with the explicit datatype form would be the remaining useful confirmation. |
Co-Authored-By: Codex <noreply@openai.com>
bvanelli
left a comment
There was a problem hiding this comment.
I have tested the code against a live PLC. It worked for writing a REAL. I can try writing an integer, but according to the reference, it needs different encoding.
Regarding the WithIntegrityId flag, I wonder if we could do some testing with the TIA portal to confirm communication behaviour.
|
LGTM. Some details from hardware testing:
|
|
Thanks @bvanelli — the INT, DINT, UDINT, and WORD results provide the integer hardware confirmation we were missing. Your BLOB rejection result also means the three-tuple default is a misleading contract for scalar targets. I have implemented a follow-up locally that requires The same follow-up adds Local validation: 1,944 tests passed, 78 skipped; all pre-commit hooks and source/wheel builds passed. The broader mypy run has 207 existing errors versus 208 on unchanged master, with no new diagnostics. The branch is not published yet; I will link the reviewable PR when it is available. |
|
The datatype follow-up is now available in #873, commit 232f0d4. It requires explicit four-element multi-write tuples and adds typed symbolic/area writes to both clients. Install the tested revision with: python -m pip install 'python-snap7[s7commplus] @ git+https://github.com/gijzelaerr/python-snap7.git@232f0d41d66ef76762f6d5c5b71fc2082792ecf7'@bvanelli could you review the explicit-type contract and, when convenient, confirm an existing typed integer test still works on this revision? Your previous INT/DINT/UDINT/WORD hardware results remain recorded; the new regression checks cover the public sync/async APIs and reject missing types before any multi-write is sent. |
Summary
db_write_multi()to the synchronous and asynchronous S7CommPlus clientswrite_multi()convenience aliasSET_MULTI_VARIABLESrequestSET_VAR_SUBSTREAMEDrequest per itemDataTypeas a fourth tuple element while preserving three-tuple BLOB writesThe explicit
REALform has completed a successful write/read/restore round trip against a real S7-1500 V2 PLC. A typed integer round trip would provide additional hardware confirmation of the VLQ encoding.Verification
uv run --frozen --extra test --extra s7commplus pytest -q(1,905 passed, 78 skipped)uv run --frozen pre-commit run --all-filesuv build --no-sourcesFixes #795