Strings
Section titled “Strings”STRING and WSTRING hold text, for example a barcode or a part number. Write STRING(n) or WSTRING(n) to set the maximum length in characters; without n the default is 80, and n can be 1 to 65535. WSTRING holds Unicode text.
PROGRAM BarcodeVAR code : STRING(20); wide : WSTRING := "Größe";END_VARVAR_EXTERNAL BarcodeText : STRING; END_VAR code := BarcodeText;END_PROGRAM- Literals –
'text'forSTRING,"text"forWSTRING. Escapes start with$:$$,$',$",$Lor$N(line feed),$P(page),$R(carriage return),$T(tab) and$hh(two hex digits). - Assignment – A value longer than
nis truncated ton.STRINGandWSTRINGare converted into each other only withSTRING_TO_WSTRINGandWSTRING_TO_STRING. - Comparison –
=,<>,<,>compare lexicographically by UTF-16 value. - Functions –
LEN,LEFT,RIGHT,MID,CONCAT,INSERT,DELETE,REPLACE,FINDand the conversions<T>_TO_STRING/STRING_TO_<T>. See String functions. - Signals – A
VAR_EXTERNALorATvariable of typeSTRINGbinds to a text signal (PLCInputText / PLCOutputText). If the signal has another type, deploy reports a type conflict. - Watch and snapshots – The watch list shows strings in single quotes. Snapshots keep string values.
Struct and custom data types are not supported yet.
Named states with enums
Section titled “Named states with enums”Declare one or several enum types before the PROGRAM, or share them through a PLC Library:
{attribute 'qualified_only'}{attribute 'strict'}TYPE E_State : (Idle := 0, Run, Fault := 10) UINT := Idle;END_TYPEPROGRAM MainVAR state : E_State; END_VARCASE state OF E_State.Idle: state := E_State.Run; E_State.Run: state := E_State.Fault;END_CASE;END_PROGRAMThe base defaults to INT and may be any supported integer or bit-string type. Omitted member values increment the previous value, starting at 0. All values must fit the base; duplicate names or numeric values are errors. A variable starts with the enum’s explicit default (:= Idle above), otherwise with its member valued 0, otherwise with the first member. A variable’s own initializer takes precedence.
E_State.Run always works. Bare Run is available only without qualified_only; a bare name shared by two enums is ambiguous and must be qualified. An unqualified member cannot share a variable name. strict rejects arithmetic, use as a FOR counter and integer assignments to the enum; comparisons and CASE remain available. Without strict, integer-to-enum assignment produces a warning, and enum-to-integer assignment is allowed. Stored values wrap to the enum base width. Enum externals use existing Int signals without changing their type or direction.
Inline values, hover and the watch list show known members as E_State.Run and unknown numbers as E_State#17. The values saved in snapshots remain numbers. In DES, a transition that wraps back to the current enum step does not protect a counter from D1.
Numbers
Section titled “Numbers”Based literals (2#, 8#, 16#) are bit patterns: if they fit unsigned into the target or promoted context width, signed types interpret them in two’s complement (for example DINT := 16#80000001 gives -2147483647); wider patterns are compile errors, decimal literals keep their numeric range checks, and typed literals use the named type’s width.
- Widths and signedness. SINT/USINT/BYTE use 8 bits, INT/UINT/WORD 16, DINT/UDINT/DWORD 32 and LINT/ULINT/LWORD 64. SINT, INT, DINT and LINT are signed; the others are unsigned. Bit strings display as padded hexadecimal, for example WORD
16#00A5, with a binary tooltip; integer types display in decimal. All watch values are read-only. - Integer storage wraps. Every finite 8/16/32-bit integer or bit-string assignment wraps to the target width, including FB input/output copies and FOR counters. This changes earlier INT/DINT behavior:
x : INT := 32767; x := x + 1;now gives-32768; USINT 255 + 1 gives 0. The same rule applies when storing folded initializers. Typed literals outside their declared range are compile errors. - Intermediate calculations. Integer
+,-, unary minus and*through 32-bit types use 32-bit registers, with exact low-word multiplication (Math.imul): DINT 2147483647 * 2147483647 gives 1. Storage then narrows to the declared width. Unsuffixed integer literals take the target/other operand type when they fit. Mixed operands promote to the wider type; equal-width signed/unsigned operands promote to the next wider signed type (64-bit combinations use LINT). Narrowing between named variables still needs an explicit conversion. - 64-bit limit. LINT, ULINT and LWORD use JavaScript numbers; finite values are limited to exact integers with magnitude at most
2^53 - 1(9007199254740991); unsigned types cannot store finite negative values. An unsafe 64-bit intermediate or stored result raises a RangeError and stops the PLC with error, even if a later operation would reduce it. Invalid literal/constant values are compile errors. Full 64-bit precision and BigInt are not provided. - NaN and Infinity. At runtime, NaN and ±Infinity pass through integer/bit-string conversions, storage and external normalization unchanged, including 64-bit types. Only finite values wrap or undergo the exact-integer/range check. REAL/LREAL-to-integer conversions keep their existing rounding (halves away from zero); other numeric-to-integer conversions truncate toward zero. Non-finite constant/start values are compile errors.
- Bit access. Read or write
w.3on any integer/bit-string variable, including externals. Index 0 is the least significant bit; the index must be an integer literal or constant within the type width. A read returns BOOL;w.0 := TRUEchanges only that bit. REAL/LREAL/TIME bit access is rejected. - Bit operations and shifts. AND/OR/XOR/NOT use the operand width and signedness; BOOL keeps logical semantics. SHL/SHR/ROL/ROR use the width of IN. SHR sign-extends signed integers and zero-fills unsigned/bit-string types. SHL/SHR by the full width or more return 0; rotations use N modulo the width. A negative/invalid count is a runtime error. At 64 bits a result outside the exact range also raises a runtime error.
- Division and real values. Integer division and MOD truncate toward zero; division by zero is a runtime error (a compile error in constants/start values). REAL and LREAL both use double precision; LREAL keeps a distinct type name. Their watch values show three decimal places; TIME keeps its seconds display.
All integer/bit-string externals bind to existing Int signals; REAL/LREAL bind to Float signals. Input values are normalized to the declared ST width without changing the model signal’s type or direction. The local browser SignalStore preserves 4294967295 and 2^40 as JavaScript numbers. Int signals carry 32 bits (signed) through CONNECT. Values above the signed 32-bit range therefore cannot be transported unchanged through CONNECT, even when they fit a local ST type.