ST values and operators

A value can be a literal, a tag, a TIMER or COUNTER member, or the result of an expression. Parentheses make the order explicit.

BOOL, whole numbers and reals

Use TRUE or FALSE for BOOL. A literal 1 or 0 also works where a BOOL is expected, including a condition. Other numbers and numeric tags are not BOOL values. Use a comparison to turn a number into a condition.

Whole numbers such as 12 are normally DINT. A decimal point or exponent makes a REAL, such as 12.5 or 1.25e2. A whole-number literal may also stand for a REAL in the contexts described in Data types and conversions.

Tags to create: MotorRun — BOOL; Ready — BOOL; Count — DINT; Speed — REAL.
MotorRun := 1;
Ready := FALSE;
Count := 12;
Speed := 12.5;
Ready := Count > 0;

Time literals

Time is a DINT number of milliseconds here, rather than a separate TIME tag type. Units run from larger to smaller. T#5s is 5000, T#250ms is 250, and T#1m30s is 90000.

Tags to create: DelayMs — DINT; FillTimer — TIMER.
DelayMs := T#5s;
FillTimer.PRE := T#250ms;
DelayMs := T#1m30s;

Operator order

Highest priority first. Operators on the same row group from left to right; unary operators apply to their operand.

OrderOperatorMeaning
1( )Grouping
2callsFunction result
3- and NOTNegate a number; invert a BOOL
4* / MODMultiply, divide, integer remainder
5+ -Add, subtract
6< > <= >=Numeric comparisons
7= <>Equal, not equal
8AND / &Both BOOLs true
9XORExactly one BOOL true
10ORAt least one BOOL true

AND, &, XOR, OR and NOT operate on BOOL values. DINT division keeps an integer result; REAL division keeps a fractional result. MOD takes DINT operands. Division by zero faults the affected statement.

Tags to create: Count — DINT; Ready — BOOL; StopPB — BOOL.
Count := (2 + 3) * 4;
Ready := (Count >= 10) AND NOT StopPB;

Related