Skip to content

Export and import device-tree sibling devices#30

Merged
gsokoll merged 3 commits into
mainfrom
backport/ws3-device-tree
Jun 12, 2026
Merged

Export and import device-tree sibling devices#30
gsokoll merged 3 commits into
mainfrom
backport/ws3-device-tree

Conversation

@gsokoll

@gsokoll gsokoll commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Continuation of #27, which GitHub closed un-reopenably when its stacked base branch was deleted. Same head branch, rebased onto main (now containing #25 and the staging export from #26/#29), with the script_export_to_files.py conflict resolved: the device-tree export runs inside the device loop and finalize_export_folder follows after it.

All description, credits (reimplemented from ipfedor/codescribe commit 6e08a99, refs #24) and the full live-validation history are on #27, including the two bugs found and fixed during CR711s testing (non-removable fixed package children, and import_native pasting as a child rather than replacing). The combined staging plus device-tree export was re-run live on CODESYS SP11 after the rebase: application, communication and devices folders all produced, no staging leftovers.

gsokoll added 3 commits June 12, 2026 17:36
On standard CODESYS hardware, Ethernet, Modbus and fieldbus devices sit in
the device tree as direct DEVICE children of the PLC device, next to
Plc Logic, and codescribe did not track them. Add
src/device_tree_import_export.py to export each such sibling as a native
recursive xml file under <device>/devices/<name>.xml, import them back, and
strip their children in Save As Template.

Children that carry an Application anywhere in their subtree are excluded
from the export. In compound safety projects such as the IFM CR711s the
SafetyPLC and StandardPLC each carry their own Application and are already
exported through their own device entrypoint, so exporting them here would
duplicate them. The Communication object is also excluded since it has its
own export path.

Adding a _NO_EXPORT folder as a direct child of the PLC device disables the
device-tree export. The existing _NO_EXPORT under Communication keeps
disabling only the Communication export.

Credit: reimplemented from ipfedor/codescribe commit 6e08a99. Refs #24.
get_src_folder(template_project) points at <name>_template_vX, which never
exists on disk, so remove_tracked_device_tree_devices returned early and the
template kept its tracked device-tree children. The tracked list lives in the
primary project export folder.
…ices

Live testing on an IFM CR711s compound project showed two faults in the
original import design. Children of package-fixed devices (Local_IO/Inputs,
HMI/User_LEDs) cannot be removed, which aborted the whole import. And
import_native pastes the archived object as a child of the receiving node
rather than replacing in place, so importing a device xml onto the device
itself produced a rejected HMI_1 paste dialog.

Import now removes the matching device and imports the xml into the PLC
device, which recreates it. Package-fixed devices that refuse removal are
skipped with a message, since the project template carries their
configuration, the same contract as the fixed top-level communication
devices. A device missing from a fresh template-derived project imports
directly instead of raising. Save As Template applies the same semantics.
@gsokoll gsokoll merged commit a9e0bb6 into main Jun 12, 2026
2 checks passed
@gsokoll gsokoll deleted the backport/ws3-device-tree branch June 12, 2026 07:46
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.

1 participant