feat(plc): a CODESYS script that exports PLCopen XML for Prüfwerk (#165) #829

Merged
sharang merged 1 commits from feat/codesys-export-script into main 2026-11-04 11:10:10 +00:00
Owner

#165, PR 2 of the plan. Tracker #167. Sharang decided against parsing the binary .project, so the PLCopen XML export is the only route to control-logic SAST. This makes that export cheap to do on every change.

What

  • docs/public/downloads/codesys-export-plcopen.py is a CODESYS Script Engine script, served with the docs at /docs/downloads/codesys-export-plcopen.py.
    • In the IDE (Tools → Scripting → Execute Script File), it exports the open project to <project>.plcopen.xml.
    • Headless: CODESYS.exe --profile=… --noUI --runscript=… --scriptargs:"<project> [<export>]" opens the project, exports it and closes it.
    • The export is every top-level object with its children (get_children(False) plus export_xml(objects, path, True)), in one file. Our PLCopen reader takes every <pou> in it.
    • It creates the export folder.
    • It exits 1 when the project is missing, none is open, or the export holds no <pou.
    • It runs on IronPython 2.7 (the Script Engine) and Python 3.
  • scripts/test_codesys_export.py: offline tests that run the script against a stand-in projects object. They cover arguments, the default path, open and close (a project opened by the script is closed, the open one is left open), the no-POU failure, and running outside CODESYS.
  • CI: the Check job gets a Script tests step (python3 -B -I -m unittest discover -s scripts). It also covers the existing EOL-table tests, which previously ran only in the weekly workflow.
  • Docs: guide/plc has a new section, "Exporting PLCopen XML automatically", and the native-project row in guide/scanning points there. The link uses {target="_self" download} so VitePress does not route it as a page.

Not verified

  • Real CODESYS run: the script has not run against a real CODESYS installation. It uses only the documented Script Engine calls (projects.open, projects.primary, ScriptProject.path, get_children, export_xml, close). One run on a Windows machine with CODESYS confirms the export_xml overload and that graphical POUs (FBD/LD/SFC/CFC) come out as <pou>. That export then becomes the sample for the SFC and CFC PRs.
  • Docs build: docs build only on the main deploy. After merging I'll check that the file downloads from stage.

🤖 Generated with Claude Code

#165, PR 2 of the plan. Tracker #167. Sharang decided against parsing the binary `.project`, so the PLCopen XML export is the only route to control-logic SAST. This makes that export cheap to do on every change. ## What - **`docs/public/downloads/codesys-export-plcopen.py`** is a CODESYS Script Engine script, served with the docs at `/docs/downloads/codesys-export-plcopen.py`. - In the IDE (*Tools → Scripting → Execute Script File*), it exports the open project to `<project>.plcopen.xml`. - Headless: `CODESYS.exe --profile=… --noUI --runscript=… --scriptargs:"<project> [<export>]"` opens the project, exports it and closes it. - The export is every top-level object with its children (`get_children(False)` plus `export_xml(objects, path, True)`), in one file. Our PLCopen reader takes every `<pou>` in it. - It creates the export folder. - It exits 1 when the project is missing, none is open, or the export holds no `<pou`. - It runs on IronPython 2.7 (the Script Engine) and Python 3. - **`scripts/test_codesys_export.py`**: offline tests that run the script against a stand-in `projects` object. They cover arguments, the default path, open and close (a project opened by the script is closed, the open one is left open), the no-POU failure, and running outside CODESYS. - **CI**: the Check job gets a *Script tests* step (`python3 -B -I -m unittest discover -s scripts`). It also covers the existing EOL-table tests, which previously ran only in the weekly workflow. - **Docs**: `guide/plc` has a new section, "Exporting PLCopen XML automatically", and the native-project row in `guide/scanning` points there. The link uses `{target="_self" download}` so VitePress does not route it as a page. ## Not verified - **Real CODESYS run:** the script has not run against a real CODESYS installation. It uses only the documented Script Engine calls (`projects.open`, `projects.primary`, `ScriptProject.path`, `get_children`, `export_xml`, `close`). One run on a Windows machine with CODESYS confirms the `export_xml` overload and that graphical POUs (FBD/LD/SFC/CFC) come out as `<pou>`. That export then becomes the sample for the SFC and CFC PRs. - **Docs build:** docs build only on the main deploy. After merging I'll check that the file downloads from stage. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
sharang added 1 commit 2026-11-04 10:28:01 +00:00
feat(plc): a CODESYS script that exports PLCopen XML for Prüfwerk (#165)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 4m1s
CI / Check (pull_request) Successful in 16m30s
0b13d56b92
Prüfwerk reads CODESYS control logic only from the PLCopen XML export
(decided: no parsing of the binary .project). Exporting by hand before
every upload or commit is easy to forget, so customers get a CODESYS
Script Engine script that does it, in the IDE or headless in CI:

- docs/public/downloads/codesys-export-plcopen.py, served with the docs:
  exports every top-level object with its children into one PLCopen XML
  file (projects.open / projects.primary, get_children, export_xml),
  creates the target folder, and exits with status 1 when the project is
  missing or the export holds no POU. IronPython 2.7 and Python 3.
- scripts/test_codesys_export.py runs it offline against a stand-in for
  the Script Engine's projects object; CI's Check job now runs the
  repository's offline script tests.
- guide/plc: "Exporting PLCopen XML automatically", with both ways to
  run it; guide/scanning points there from the native-project note.

Not yet run against a real CODESYS installation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sharang merged commit e911e75c09 into main 2026-11-04 11:10:10 +00:00
Sign in to join this conversation.