DEV Community

yohan
yohan

Posted on Originally published at cnblogs.com

CODESYS AI Practice — Import/Export Files

In CODESYS v3, code lives inside the project — a binary file. AI cannot open or edit it.

In the AI era we need a way for AI to operate on the files inside the project.

Goal

Close the loop: project ⇄ text ⇄ AI.

Export POUs to text, let the AI edit them, import them back into the project.

Constraints

  • CODESYS must stay the source of truth for the project structure
  • Import must not corrupt an existing project
  • Prefer a small, scriptable tool over a heavy IDE plugin

Approach

  1. Export selected POUs (declaration + implementation) to plain text files
  2. Edit the text (AI or human)
  3. Import: backup, compare, write back, save

Creating or deleting POUs is not supported in this pass — only updating existing ones.

Export, edit, import loop

Exported project tree

Import pipeline

Import does four things before touching the live project:

  1. Backup — snapshot first
  2. Compare — diff bodies
  3. Write back — set POU code
  4. Save — persist the project

Import pipeline: backup, compare, write back, save

Notes

  • Update only: creating or deleting POUs is not supported in this version
  • Declarations and implementations are paired per POU
  • After import, rebuild in CODESYS to verify

Repository and tooling details follow the same codesys-sync / codesys-connect series used elsewhere on this blog.

Top comments (1)

Collapse
 
lastmileops profile image
lastmileops •

One test for the stale-export warning: on a disposable project, export a POU and leave the exported text untouched. Add a code comment to that POU's declaration in the IDE, save and close the project, then import the old export. The linked importer writes back when the texts differ, so even that untouched export can overwrite the newer edit. I'd assert that the import flags the stale export and the comment survives.