PLCopen XML & IEC 61131-3 Industrial Automation (.xml, .st)
@modelscript/plcopen (languages/plcopen) provides compiler, Virtual PLC cyclic execution, sampled-data DAE lowering, and formal verification for IEC 61131-3 industrial control software and PLCopen XML interchange models.
Supported Extensions & Standards
| Extension | Standard / Format | Description |
|---|---|---|
.xml, .plcopen | PLCopen XML v2.01 / v2.0 | XML exchange format for IEC 61131-3 control programs, POUs, and configurations |
.st | IEC 61131-3 Structured Text | Textual structured control language for PLCs and industrial controllers |
Key Capabilities
1. IEC 61131-3 Program Organization Units (POUs)
- Full support for standard control logic paradigms:
- Structured Text (ST): Variable declarations, conditionals (
IF-THEN-ELSE), case selection, loops (FOR,WHILE), and mathematical expressions. - Function Blocks (FB): State-retaining functional blocks including standard timers (
TON,TOF,TP), counters (CTU,CTD,CTUD), and bistable multivibrators (SR,RS). - Functions (FUN): Pure stateless mathematical computations.
- Structured Text (ST): Variable declarations, conditionals (
2. High-Speed Deterministic Virtual PLC Engine
- Features a cycle-accurate Virtual PLC execution runtime (
VirtualPlc):- Sampled Scan Cycle: Deterministic three-phase execution: input latching
logic evaluation output write. - Configurable Scan Period: Executes discrete scan rates (e.g.,
, , ) coupled with continuous physical models.
- Sampled Scan Cycle: Deterministic three-phase execution: input latching
3. Direct Sampled-Data DAE Lowering
- Compiles discrete state variables, zero-order holds (ZOH), and timer registers into
@modelscript/runtime'sDAEBuilderarena. - Enables closed-loop hardware-in-the-loop (HIL) simulation of PLC control algorithms coupled with continuous Modelica physics (e.g., thermal plants, robotic actuators, motor drives).
4. Polyglot Projections
- Modelica (
plcopenToModelica): Lowers PLC function blocks into standard synchronous Modelica clocked state machines. - SysML v2 (
plcopenToSysML): Maps IEC 61131-3 control architectures to SysML v2action defsuccessions and state machines.
Static Analysis & Safety Linter Rules
10 rules7 error3 warning Run with msx plcopen lint
| Code | Rule | Severity | Message |
|---|---|---|---|
M7701 | unassigned-variable-read | error | Variable '<name>' is read before being assigned or initialized in POU '<pouName>'. |
M7702 | cyclic-task-overrun | warning | Computational complexity in task '<taskName>' (<stmtCount> statements) may exceed cycle time '<interval>'. |
M7703 | recursive-pou-call | error | Recursive invocation of POU '<calleeName>' detected in '<callerName>'. Recursion is prohibited in IEC 61131-3. |
M7704 | io-mapping-collision | error | Hardware I/O address collision at '<address>': multiple variables ('<var1>', '<var2>') assigned to same output. |
M7705 | type-mismatch-assignment | error | Type mismatch in assignment to '<varName>': expected '<expectedType>', got '<actualType>'. |
M7706 | timer-preset-negative | error | Timer preset time '<value>' for '<timerName>' cannot be negative. |
M7707 | unbounded-loop-detected | warning | Loop in POU '<pouName>' does not have a deterministic bounded termination condition. |
M7708 | unknown-pou-type | error | Unknown or unresolvable POU or function block type '<typeName>' instantiated in '<instanceName>'. |
M7709 | unreachable-code | warning | Unreachable code detected after '<stmtKind>' statement in POU '<pouName>'. |
M7710 | invalid-task-interval | error | Task '<taskName>' specifies invalid or non-positive periodic interval '<interval>'. |
Generated from languages/plcopen/src/lints/rules.ts. All languages →
CLI Usage
bash
# Lint an IEC 61131-3 PLCopen XML project
msx plcopen lint AutomationController.xml
# Run 50 discrete scan cycles (dt = 10ms) through the Virtual PLC engine
msx plcopen run-scan AutomationController.xml --cycles 50 --dt 10
# Lower control logic to DAE arena for closed-loop physics co-simulation
msx plcopen to-dae AutomationController.xml --out=controller.dae.json
# Project into Modelica synchronous clocked state machine components
msx plcopen to-modelica AutomationController.xml -o ControllerBlocks.mo
