﻿ Expression (IEC 61131-3) - A Computation to Return a Value

# IEC 61131-3 Expressions

Help Contents

## Introduction

An IEC 61131-3 expression is a sequence of:

An IEC 61131-3 expression produces a single result.

You can use an IEC 61131-3 expression in any of these areas:

### Constant Values (Literals)

The simplest possible expression is a literal defining a constant value. For example:

```12
'A string'
T#5s```

See Numeric Literals, Time Literals, Date Literals, or String Literals for more information on supported literals.

### Tag References

A tag reference is a way of referring to a SCADA tag. For example:

Tag ReferenceEvaluation Order
%"PumpStation.TotalCurrent"Returns the value of the tag PumpStation.TotalCurrent
%"PumpStation.TotalCurrent.Quality"Returns the quality of the tag PumpStation.TotalCurrent

See Tag References for other ways to refer to SCADA tags in IEC 61131-3 code.

### Unary Operator

A unary operator performs an operation on a single value. These unary operators are supported:

OperatorDescriptionExample
-Negation- A
NOTComplementNOT B

### Binary Operator

A binary operator performs an operation on two values to return a single result. These binary operators are supported:

OperatorDescriptionPrecedence
ORLogical OR1
XORLogical Exclusive OR2
AND &Logical AND3
= <>Equality4
> >= < <=Comparison5
-Subtraction6
*Multiply7
/Divide7
MODModulo7
**Power8

When multiple operators are present in an expression, higher precedence operators are evaluated before lower precedence operators. When two operators have equal precedence, the left operator is evaluated before the right operator. For example:

ExpressionEvaluation Order
A + B * CB is multiplied by C, then the result is added to A
A + B + CB is added to A, then C is added to the result of A + B
A * B + CA is multiplied by B, then C is added to the result of A * B

### Parentheses

Parentheses alter the order of evaluation of operators. An expression inside parentheses is always evaluated first, regardless of operator precedence. For example:

ExpressionEvaluation Order
(A + B) * CB is added to A, then the result of A + B is multiplied by C

### Variable References

A variable is a value that can change, depending on the actions of the program code.

A variable reference is a way of referring to a variable in an expression.

Expressions can include references to elementary type variables. For example:

A - Reference to variable A.

B - Reference to element number 4 of the array B.

C.M - Reference to the M member variable of structure C.

See Variable References for information on how to reference variable values.

### Function Calls

Expressions can include calls to:

Function calls can be Formal or Informal. For example:

LIMIT( EN:=True, MN:=10.5, IN:=Voltage, MX:=13.4 ) - Formal call to the standard function LIMIT.

LIMIT( 10.5, Voltage, 13.4 ) - Informal call to the standard function LIMIT.

## Further Information

To learn about the different types of literals.

Functions

To learn about standard and user defined functions.

Glossary

For the meaning of terms used in Fernhill SCADA.