Skip to content
Beta.st@modelscript/plcopen 10 diagnostic rules
Parser WASM GLR
Diagnostics 10 rules
DAE Arena Lowering
Simulation Native Solvers
Projections Modelica, SysML v2
Live ExampleDuplexPumpStation.st

IEC 61131-3 / PLCopen Duplex Booster Pump Control

Structured Text PLC control program managing lead/lag pump staging, wet-well level hysteresis, and high-level alarm interlocks.

Playground
Source (27 lines)
1PROGRAM DuplexPumpStation
2VAR_INPUT
3  WetWellLevel_m : REAL := 2.4;
4  HighSetpoint_m : REAL := 3.5;
5  LagSetpoint_m  : REAL := 4.2;
6  LowCutoff_m    : REAL := 1.2;
7  Pump1Fault     : BOOL := FALSE;
8END_VAR
9VAR_OUTPUT
10  LeadPumpRun    : BOOL := FALSE;
11  LagPumpRun     : BOOL := FALSE;
12  HighLevelAlarm : BOOL := FALSE;
13END_VAR
14 
15IF WetWellLevel_m >= HighSetpoint_m AND NOT Pump1Fault THEN
16  LeadPumpRun := TRUE;
17ELSIF WetWellLevel_m <= LowCutoff_m THEN
18  LeadPumpRun := FALSE;
19  LagPumpRun  := FALSE;
20END_IF;
21 
22IF WetWellLevel_m >= LagSetpoint_m OR (WetWellLevel_m >= HighSetpoint_m AND Pump1Fault) THEN
23  LagPumpRun := TRUE;
24END_IF;
25 
26HighLevelAlarm := WetWellLevel_m >= 4.8;
27END_PROGRAM
PLCopen IEC 61131-3 Function Block & Logic Flow
4–20 mA 24V DO «var_input» Wet-Well Inputs «field signals» WetWellLevel_m := 2.4 HighSetpoint_m := 3.5 LagSetpoint_m := 4.2 «program (iec 61131-3)» DuplexPumpStation «hysteresis & failover» Level >= 3.5m → Lead ON Level >= 4.2m → Lag ON Pump1Fault → Auto Failover «var_output» Contactor Outputs «discrete coils» LeadPumpRun : BOOL LagPumpRun : BOOL HighLevelAlarm : BOOL
Drag to pan · Click % to reset

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 ​

ExtensionStandard / FormatDescription
.xml, .plcopenPLCopen XML v2.01 / v2.0XML exchange format for IEC 61131-3 control programs, POUs, and configurations
.stIEC 61131-3 Structured TextTextual 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.

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., 1ms, 10ms, 50ms) coupled with continuous physical models.

3. Direct Sampled-Data DAE Lowering ​

  • Compiles discrete state variables, zero-order holds (ZOH), and timer registers into @modelscript/runtime's DAEBuilder arena.
  • 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 v2 action def successions and state machines.

Static Analysis & Safety Linter Rules ​

10 rules7 error3 warning Run with msx plcopen lint

CodeRuleSeverityMessage
M7701unassigned-variable-readerrorVariable '<name>' is read before being assigned or initialized in POU '<pouName>'.
M7702cyclic-task-overrunwarningComputational complexity in task '<taskName>' (<stmtCount> statements) may exceed cycle time '<interval>'.
M7703recursive-pou-callerrorRecursive invocation of POU '<calleeName>' detected in '<callerName>'. Recursion is prohibited in IEC 61131-3.
M7704io-mapping-collisionerrorHardware I/O address collision at '<address>': multiple variables ('<var1>', '<var2>') assigned to same output.
M7705type-mismatch-assignmenterrorType mismatch in assignment to '<varName>': expected '<expectedType>', got '<actualType>'.
M7706timer-preset-negativeerrorTimer preset time '<value>' for '<timerName>' cannot be negative.
M7707unbounded-loop-detectedwarningLoop in POU '<pouName>' does not have a deterministic bounded termination condition.
M7708unknown-pou-typeerrorUnknown or unresolvable POU or function block type '<typeName>' instantiated in '<instanceName>'.
M7709unreachable-codewarningUnreachable code detected after '<stmtKind>' statement in POU '<pouName>'.
M7710invalid-task-intervalerrorTask '<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

Open-Core under the GNU AGPL v3 License; Enterprise Edition (ee/) under the ModelScript Enterprise License. • Trademark Policy