Virtual PLCs / Documents / LADV-IR-ST

Reference · LADV-IR-ST

Structured Text standard library reference

Every IEC 61131-3 standard function and function block on LADV: numeric, string, selection, time, conversion, timers, counters, edge triggers and bistables.

Download PDFDownload WordRevision 1.0, 1 November 2026

Every standard function and function block the LADV controllers provide.

DocumentStructured Text standard library reference
CodeLADV-IR-ST
Revision1.0, 1 November 2026
FirmwareV1.0.0
Issued byWartens, makers of LADX

1. Functions

Functions take inputs by position or by name and return one value. Those marked with ... take two or more inputs.

Numeric

FunctionCallResult
ABSABS(IN)Absolute value.
SQRTSQRT(IN)Square root of a REAL or LREAL.
LNLN(IN)Natural logarithm.
LOGLOG(IN)Logarithm to base 10.
EXPEXP(IN)e raised to IN.
SINSIN(IN)Sine, IN in radians.
COSCOS(IN)Cosine, IN in radians.
TANTAN(IN)Tangent, IN in radians.
ASINASIN(IN)Arc sine, in radians.
ACOSACOS(IN)Arc cosine, in radians.
ATANATAN(IN)Arc tangent, in radians.
ATAN2ATAN2(Y, X)Angle of the point (X, Y) from the X axis, in radians.
EXPTEXPT(IN1, IN2)IN1 raised to the power IN2.

Arithmetic

FunctionCallResult
ADDADD(IN1, IN2, ...)Sum. Same as +.
MULMUL(IN1, IN2, ...)Product. Same as *.
SUBSUB(IN1, IN2)Difference. Same as -.
DIVDIV(IN1, IN2)Quotient. Same as /. Integer division truncates toward zero; by zero faults with F310.
MODMOD(IN1, IN2)Remainder, with the sign of IN1. By zero faults with F310.
MOVEMOVE(IN)Returns IN. Same as assignment.

Bit shift

FunctionCallResult
SHLSHL(IN, N)Shift left N bits at the width of IN, zeros in.
SHRSHR(IN, N)Shift right N bits at the width of IN, zeros in.
ROLROL(IN, N)Rotate left N bits at the width of IN.
RORROR(IN, N)Rotate right N bits at the width of IN.

Selection

FunctionCallResult
SELSEL(G, IN0, IN1)IN1 when G is TRUE, otherwise IN0.
MAXMAX(IN1, IN2, ...)The largest input.
MINMIN(IN1, IN2, ...)The smallest input.
LIMITLIMIT(MN, IN, MX)IN held between MN and MX.
MUXMUX(K, IN0, IN1, ...)Input number K, counting from 0. K outside the inputs faults with F312.

Comparison

FunctionCallResult
GTGT(IN1, IN2)IN1 > IN2.
GEGE(IN1, IN2)IN1 >= IN2.
EQEQ(IN1, IN2)IN1 = IN2.
LELE(IN1, IN2)IN1 <= IN2.
LTLT(IN1, IN2)IN1 < IN2.
NENE(IN1, IN2)IN1 <> IN2.

String

FunctionCallResult
LENLEN(IN)Number of characters.
LEFTLEFT(IN, L)The first L characters.
RIGHTRIGHT(IN, L)The last L characters.
MIDMID(IN, L, P)L characters starting at position P, counting from 1.
CONCATCONCAT(IN1, IN2, ...)The inputs joined end to end.
INSERTINSERT(IN1, IN2, P)IN2 inserted into IN1 after position P.
DELETEDELETE(IN, L, P)IN with L characters removed from position P.
REPLACEREPLACE(IN1, IN2, L, P)L characters of IN1 from position P replaced by IN2.
FINDFIND(IN1, IN2)Position of the first IN2 in IN1, or 0 when it is not there.

Conversion

FunctionCallResult
TRUNCTRUNC(IN)REAL to integer, toward zero.
BCD_TO_INTBCD_TO_INT(IN)Binary-coded decimal to integer. A digit above 9 faults with F313.
INT_TO_BCDINT_TO_BCD(IN)Integer to binary-coded decimal.

Time and date

FunctionCallResult
ADD_TIMEADD_TIME(IN1, IN2)TIME + TIME.
SUB_TIMESUB_TIME(IN1, IN2)TIME - TIME.
MUL_TIMEMUL_TIME(IN1, IN2)TIME multiplied by a number.
DIV_TIMEDIV_TIME(IN1, IN2)TIME divided by a number.
ADD_TOD_TIMEADD_TOD_TIME(IN1, IN2)Time of day + TIME.
ADD_DT_TIMEADD_DT_TIME(IN1, IN2)Date and time + TIME.
SUB_TOD_TIMESUB_TOD_TIME(IN1, IN2)Time of day - TIME.
SUB_DT_TIMESUB_DT_TIME(IN1, IN2)Date and time - TIME.
SUB_DATE_DATESUB_DATE_DATE(IN1, IN2)DATE - DATE, as TIME.
SUB_TOD_TODSUB_TOD_TOD(IN1, IN2)Time of day - time of day, as TIME.
SUB_DT_DTSUB_DT_DT(IN1, IN2)Date and time - date and time, as TIME.
CONCAT_DATE_TODCONCAT_DATE_TOD(IN1, IN2)A DATE and a time of day as one DT.

Type conversion

Any elementary type converts to another with X_TO_Y, for example INT_TO_REAL, REAL_TO_INT, DINT_TO_INT, BOOL_TO_INT, INT_TO_STRING, STRING_TO_INT, TIME_TO_DINT. TO_Y converts from whatever type the argument has. REAL to integer rounds half to even; TRUNC and REAL_TRUNC_INT truncate. An integer conversion that does not fit wraps at the width of the target, as hardware does.

2. Function blocks

Declare an instance, call it, and read its outputs as instance.name.

BlockInputsOutputsBehaviour
TONIN : BOOL, PT : TIMEQ : BOOL, ET : TIMEOn delay. Q goes TRUE when IN has been TRUE for PT. ET counts up to PT. IN FALSE resets both.
TOFIN : BOOL, PT : TIMEQ : BOOL, ET : TIMEOff delay. Q follows IN up at once, and stays TRUE for PT after IN goes FALSE.
TPIN : BOOL, PT : TIMEQ : BOOL, ET : TIMEPulse. A rising edge on IN gives Q TRUE for exactly PT; IN cannot cut it short or extend it.
LTONIN : BOOL, PT : LTIMEQ : BOOL, ET : LTIMETON with LTIME.
LTOFIN : BOOL, PT : LTIMEQ : BOOL, ET : LTIMETOF with LTIME.
LTPIN : BOOL, PT : LTIMEQ : BOOL, ET : LTIMETP with LTIME.
CTUCU : BOOL, R : BOOL, PV : INTQ : BOOL, CV : INTCount up. Each rising edge on CU adds one to CV. Q is CV >= PV. R sets CV to 0.
CTDCD : BOOL, LD : BOOL, PV : INTQ : BOOL, CV : INTCount down. Each rising edge on CD takes one from CV. Q is CV <= 0. LD loads PV into CV.
CTUDCU : BOOL, CD : BOOL, R : BOOL, LD : BOOL, PV : INTQU : BOOL, QD : BOOL, CV : INTCount up and down. QU is CV >= PV, QD is CV <= 0. R resets, LD loads PV.
CTU_DINTCU : BOOL, R : BOOL, PV : DINTQ : BOOL, CV : DINTCTU with DINT counts.
CTD_DINTCD : BOOL, LD : BOOL, PV : DINTQ : BOOL, CV : DINTCTD with DINT counts.
CTUD_DINTCU : BOOL, CD : BOOL, R : BOOL, LD : BOOL, PV : DINTQU : BOOL, QD : BOOL, CV : DINTCTUD with DINT counts.
CTU_LINTCU : BOOL, R : BOOL, PV : LINTQ : BOOL, CV : LINTCTU with LINT counts.
CTD_LINTCD : BOOL, LD : BOOL, PV : LINTQ : BOOL, CV : LINTCTD with LINT counts.
CTUD_LINTCU : BOOL, CD : BOOL, R : BOOL, LD : BOOL, PV : LINTQU : BOOL, QD : BOOL, CV : LINTCTUD with LINT counts.
CTU_UDINTCU : BOOL, R : BOOL, PV : UDINTQ : BOOL, CV : UDINTCTU with UDINT counts.
CTD_UDINTCD : BOOL, LD : BOOL, PV : UDINTQ : BOOL, CV : UDINTCTD with UDINT counts.
CTUD_UDINTCU : BOOL, CD : BOOL, R : BOOL, LD : BOOL, PV : UDINTQU : BOOL, QD : BOOL, CV : UDINTCTUD with UDINT counts.
CTU_ULINTCU : BOOL, R : BOOL, PV : ULINTQ : BOOL, CV : ULINTCTU with ULINT counts.
CTD_ULINTCD : BOOL, LD : BOOL, PV : ULINTQ : BOOL, CV : ULINTCTD with ULINT counts.
CTUD_ULINTCU : BOOL, CD : BOOL, R : BOOL, LD : BOOL, PV : ULINTQU : BOOL, QD : BOOL, CV : ULINTCTUD with ULINT counts.
R_TRIGCLK : BOOLQ : BOOLRising edge. Q is TRUE for one call when CLK goes from FALSE to TRUE.
F_TRIGCLK : BOOLQ : BOOLFalling edge. Q is TRUE for one call when CLK goes from TRUE to FALSE. Not on the first call.
SRS1 : BOOL, R : BOOLQ1 : BOOLSet dominant bistable. Q1 is TRUE after S1, FALSE after R, and TRUE when both are.
RSS : BOOL, R1 : BOOLQ1 : BOOLReset dominant bistable. Q1 is TRUE after S, FALSE after R1, and FALSE when both are.

Timers measure time between calls, so a timer called every 10 ms has 10 ms resolution. Counters count edges, not scans: a CU held TRUE counts once.