Skip to content

Latest commit

 

History

History
187 lines (158 loc) · 7.13 KB

File metadata and controls

187 lines (158 loc) · 7.13 KB

IEC 61131-3 Compliance

STruC++ implements the Structured Text (ST) language from IEC 61131-3. This document lists supported features and known gaps. The compiler also supports common CODESYS extensions where noted.

Data Types

Type Status Notes
BOOL Supported
BYTE, WORD, DWORD, LWORD Supported
SINT, INT, DINT, LINT Supported
USINT, UINT, UDINT, ULINT Supported
REAL, LREAL Supported
TIME Supported Nanosecond precision, int64_t storage
DATE Supported
TIME_OF_DAY Supported
DATE_AND_TIME Supported
LTIME, LDATE, LTOD, LDT Supported 64-bit time types with nanosecond precision
STRING Supported Parameterized length: STRING(N), default 254
WSTRING Supported Parameterized length: WSTRING(N)
CHAR, WCHAR Supported

Derived Types

Type Status Notes
TYPE ... END_TYPE Supported Type aliases
STRUCT ... END_STRUCT Supported With nested structs
Enumerations Supported With optional base type
ARRAY (1D) Supported Arbitrary bounds: ARRAY[1..10] OF INT
ARRAY (2D) Supported ARRAY[1..3, 1..4] OF REAL
ARRAY (3D) Supported ARRAY[1..3, 1..4, 1..5] OF INT
ARRAY[*] (VLA) Supported Variable-length array parameters
Subranges Supported Runtime validation
REF_TO Supported IEC reference type (explicit dereference)
REFERENCE_TO Supported CODESYS reference type (implicit dereference)
POINTER TO Supported CODESYS pointer type with dereference via ^

Not Implemented

Type Notes
UNION CODESYS extension

Program Organization Units

POU Status Notes
PROGRAM Supported With CONFIGURATION/RESOURCE/TASK structure
FUNCTION Supported With return type, all parameter modes
FUNCTION_BLOCK Supported Instantiation, invocation, member access
INTERFACE Supported Method and property signatures

Variable Declarations

Feature Status Notes
VAR Supported Local variables
VAR_INPUT Supported Input parameters
VAR_OUTPUT Supported Output parameters
VAR_IN_OUT Supported Pass-by-reference parameters
VAR_EXTERNAL Supported External references to VAR_GLOBAL
VAR_GLOBAL Supported Global variables
CONSTANT Supported Compile-time constants
RETAIN Supported Tracked in retain variable table
NON_RETAIN Supported
AT %IX0.0 Supported Located variables (I/Q/M areas, X/B/W/D/L sizes)
Multiple names Supported a, b, c : INT := 0;
Initialization Supported := expression

Operators and Expressions

Category Operators Status
Arithmetic +, -, *, /, MOD, ** Supported
Comparison =, <>, <, >, <=, >= Supported
Logical AND, OR, XOR, NOT Supported
Bitwise AND, OR, XOR, NOT (on bit types) Supported
Bit shift SHL, SHR, ROL, ROR Supported
Assignment := Supported
Reference assign REF= Supported
Dereference ^, DREF() Supported
Reference REF() Supported
Parentheses ( ) Supported
Function call name(args) Supported (positional + named)
Method call obj.method(args) Supported
Array access arr[i], arr[i, j] Supported
Field access struct.field Supported
Typed literals INT#5, DINT#42, REAL#3.14 Supported
NEW __NEW(type), __NEW(type, size) Supported
DELETE __DELETE(ptr) Supported

Control Structures

Structure Status Notes
IF / ELSIF / ELSE / END_IF Supported
FOR / TO / BY / DO / END_FOR Supported With optional BY (step)
WHILE / DO / END_WHILE Supported
REPEAT / UNTIL / END_REPEAT Supported
CASE / OF / END_CASE Supported Integer, bit, and enum selectors
EXIT Supported Break from loop
RETURN Supported Early return from POU

OOP Extensions

Feature Status Notes
Methods Supported On FUNCTION_BLOCK, with return types
Properties (GET/SET) Supported Virtual getter/setter methods in C++
Inheritance (EXTENDS) Supported Single inheritance
Interfaces (IMPLEMENTS) Supported Multiple interfaces, generates C++ abstract classes
ABSTRACT Supported Abstract FB (no instantiation) and abstract methods (pure virtual)
FINAL Supported Sealed FB and methods
OVERRIDE Supported Method override with C++ override specifier
PUBLIC/PRIVATE/PROTECTED Supported Access modifiers
THIS Supported Self-reference in methods

Standard Functions

All IEC 61131-3 standard functions are implemented in the C++ runtime:

Category Functions
Numeric ABS, SQRT, LN, LOG, EXP, EXPT
Trigonometric SIN, COS, TAN, ASIN, ACOS, ATAN, ATAN2
Selection SEL, MIN, MAX, LIMIT, MUX
Comparison GT, GE, EQ, LE, LT, NE
Bitwise AND, OR, XOR, NOT, MOVE
Bit Shift SHL, SHR, ROL, ROR
Type Conversion TO (INT_TO_REAL, DINT_TO_STRING, etc.)
String LEN, LEFT, RIGHT, MID, CONCAT, FIND, REPLACE, INSERT, DELETE, UPPER, LOWER, TRIM
System ADR, SIZEOF

Standard Function Blocks

Bundled as a compiled .stlib library (libs/iec-standard-fb.stlib):

FB Description
TON On-delay timer
TOF Off-delay timer
TP Pulse timer
CTU Count-up counter
CTD Count-down counter
CTUD Up/down counter
R_TRIG Rising edge detector
F_TRIG Falling edge detector
SR Set-dominant bistable
RS Reset-dominant bistable

Project Structure

Feature Status Notes
CONFIGURATION Supported
RESOURCE ... ON Supported
TASK ... WITH INTERVAL Supported
Program instances Supported name : programType with task assignment
VAR_GLOBAL in configuration Supported
Namespace configuration Supported Via pragmas

Language Extensions

Feature Status Notes
Nested comments (* (* *) *) Supported Arbitrary nesting depth
Pragmas {...} Supported Including {external} for inline C++
Inline C++ Supported Via {external ...} pragma blocks
Inline function calls Supported Via {call ...} pragma
Global constants (-D) Supported CLI -D NAME=VALUE, emits constexpr
Dynamic memory Supported __NEW(type), __DELETE(ptr)
POINTER TO Supported Full pointer type with dereference
Typed literals Supported INT#5, DINT#42, REAL#3.14

Not Yet Implemented

Feature Notes
UNION CODESYS union type
FB_Init / FB_Exit Constructor/destructor lifecycle methods
__QUERYINTERFACE Runtime interface query
Bit access (var.%X0) Individual bit addressing
ACTION blocks Named action blocks
TRY/CATCH/FINALLY Exception handling
Generics Parameterized types
Conditional compilation Preprocessor-style conditionals