A command-line tool that helps you move old CODESYS V2.x PLC programs to the modern CODESYS V3.5+ platform, with optional Raspberry Pi targeting.
If you have a PLC project built in the older CODESYS V2.x IDE and need to upgrade it to V3.5+, this tool automates the tedious parts:
- Reads your old project files (
.expexports,.stsource,.xml, or binary.pro) - Analyzes the code for issues — deprecated function blocks, missing libraries, V2→V3 breaking changes
- Transforms the code — fixes data types, maps old libraries to new ones, generates placeholder stubs for anything it can't map
- Outputs clean V3.5-compatible Structured Text files and PLCopen XML ready to import into the CODESYS V3 IDE
It does not replace the CODESYS IDE — you still import the output into CODESYS V3 for final compilation and deployment.
- Python 3.11+ installed (python.org)
- Your CODESYS V2 project exported as a
.expfile (see How to Export below)
git clone <this-repo>
cd codesys-migrator
pip install -e .# Step 1: Recover — resolve libraries, generate stubs for missing ones
codesys-migrator recover MyProject.exp --out recovered/
# Step 2: Analyze — see what issues exist before migrating
codesys-migrator analyze recovered/ --output report.json
# Step 3: Migrate — transform V2 code to V3.5+ format
codesys-migrator migrate recovered/ --out migrated/
# Step 4 (optional): Adapt for Raspberry Pi
codesys-migrator target migrated/ --device raspberrypi --out deploy/
# Step 5: Open CODESYS V3.5+ IDE → File → Import → select deploy/MyProject.xmlThat's it. Each step produces a folder of files you can inspect and edit before moving on.
| Format | Extension | What You Get |
|---|---|---|
| CODESYS V2 Export | .exp |
Full parsing — this is the primary input format |
| Structured Text | .st |
Full parsing — standalone ST source files |
| PLCopen XML | .xml |
Full parsing — TC6-standard XML projects |
| CODESYS V2 Binary | .pro |
Metadata only — library names, POU names, version info |
.profiles are proprietary binary. You cannot extract program logic from them without the CODESYS V2 IDE. Export to.expfirst (instructions below).
| Command | Purpose | Example |
|---|---|---|
recover |
Fix a broken project: resolve libraries, generate stubs | codesys-migrator recover input.exp --out recovered/ |
extract |
Extract POUs into individual .st files |
codesys-migrator extract input.xml --out extracted/ |
analyze |
Run static analysis and produce a report | codesys-migrator analyze recovered/ --output report.json |
migrate |
Transform V2 code to V3.5+ format | codesys-migrator migrate recovered/ --out migrated/ |
target |
Adapt for a specific device (Raspberry Pi) | codesys-migrator target migrated/ --device raspberrypi --out deploy/ |
Run codesys-migrator --help or codesys-migrator <command> --help for full options.
If you only have a .pro file, you need to export it first:
- Open the project in the CODESYS V2.x IDE (the old one, not V3)
- Go to File → Export...
- Select All POUs, data types, and global variables
- Save as a
.expfile - Now you can run:
codesys-migrator recover MyProject.exp --out recovered/
| Area | What Happens |
|---|---|
| Data types | STRING → STRING(80) (preserves V2 default length), pointer/array types mapped |
| Libraries | Standard.lib → Standard, Util.lib → Util, SysLibTime.lib → SysTime, etc. |
| Missing libraries | Stub function blocks generated with placeholder logic + clear warnings |
| Deprecated FBs | SysTimeGetMs → SysTimeRtcGet, other V2-era FBs replaced |
| Task config | MainTask added if missing, with 20ms default cycle |
| Raspberry Pi | I/O addresses cleared (RPi uses different mapping), GPIO helper FB added, minimum 4ms task interval |
You can connect this tool to VS Code Copilot Chat or Claude Desktop so an AI assistant can analyze and migrate projects for you through conversation.
-
Install with MCP support:
pip install -e ".[mcp]" -
Add to
.vscode/settings.jsonin any workspace:{ "mcp": { "servers": { "codesys-migrator": { "type": "stdio", "command": "python", "args": ["-m", "codesys_migrator.mcp.server"] } } } } -
Restart VS Code. In Copilot Chat (Agent mode), you can now say things like:
- "Analyze the CODESYS project at C:\projects\MyPLC\exported.exp"
- "Migrate the project in recovered/ to V3.5 for Raspberry Pi"
The MCP server exposes 4 tools:
| Tool | What It Does |
|---|---|
analyze_project |
Static analysis — finds issues, produces JSON report |
migrate_project |
Full V2→V3 migration with file output |
recover_project |
Library resolution + stub generation |
extract_project |
Parse a project file into individual .st files |
Add to your Claude config file (%APPDATA%\Claude\claude_desktop_config.json on Windows):
{
"mcpServers": {
"codesys-migrator": {
"command": "python",
"args": ["-m", "codesys_migrator.mcp.server"]
}
}
}python -c "from codesys_migrator.mcp.server import mcp; print([t.name for t in mcp._tool_manager.list_tools()])"
# Should print: ['analyze_project', 'migrate_project', 'recover_project', 'extract_project']Built-in mappings for common CODESYS V2 libraries:
| V2 Library | V3 Equivalent | What Happens |
|---|---|---|
| Standard.lib | Standard | Automatically mapped |
| Util.lib | Util | Automatically mapped |
| SysLibTime.lib | SysTime | Automatically mapped |
| SysLibCallback.lib | (removed in V3) | Stub generated |
| oscat_basic_333.lib | OSCAT Basic | Automatically mapped |
| Building_common.lib | (vendor-specific) | Stub generated |
Unknown vendor libraries get stub function blocks with clear (* WARNING *) comments so you know what to replace.
codesys_migrator/
├── cli/main.py # CLI commands (Typer)
├── parser/ # Input file parsers
│ ├── plcopen_xml.py # PLCopen XML (.xml)
│ ├── exp_parser.py # CODESYS V2 export (.exp)
│ ├── st_parser.py # Structured Text (.st)
│ └── pro_binary.py # Binary metadata (.pro)
├── recovery/ # Library resolution + stub generation
├── analyzer/ # Static analysis + compatibility checks
├── transformer/ # V2→V3 transformation + PLCopen XML output
├── targets/ # Device-specific adapters (Raspberry Pi)
├── models/project.py # Internal data model (Pydantic)
├── mcp/server.py # MCP server for AI integration
└── utils/constants.py # Library mappings, IEC standard definitions
pip install -e ".[dev]"
pytest tests/ -v48 tests covering all parsers, the analyzer, recovery engine, and migration transformer.
- Binary
.profiles — metadata only (library names, POU names, version). You must export to.expfrom the CODESYS V2 IDE for full logic extraction. - Graphical languages — FBD, LD, SFC are detected but only Structured Text (ST) bodies are fully parsed and migrated.
- Vendor libraries — Libraries without known V3 equivalents get stub FBs with no real functionality. You must replace them with the actual V3 implementation.
- Not a compiler — This tool transforms source code. You still need the CODESYS V3 IDE to compile, simulate, and deploy.
- PLCopen XML variations — Handles common TC6 namespace versions. Some vendor-specific extensions may not parse correctly.
MIT — see LICENSE.