Functions

Functions process input parameters and return values. Some functions (such as SPLIT_DATE) do not have output parameters.

We have also added support for all data table processing functions, some functions related to contexts, and evaluate function.

Number Processing Functions

Function

Description

Result type

ABS(ANY_NUM IN1)

Returns absolute values. If the argument is non-negative, it returns. If it's negative, argument negation returns.

If argument type is Integer or Long, returned value will be of a Long type.

ANY_NUM

ADD(ANY_NUM IN1, ANY_NUM IN2,...)

Addition (the same as operator +).

ANY_NUM

DIV(ANY_NUM IN1, ANY_NUM IN2)

Division (the same as operator /).

ANY_NUM

SUB(ANY_NUM IN1, ANY_NUM IN2)

Subtraction (the same as operator -).

ANY_NUM

MUL(ANY_NUM IN1, ANY_NUM IN2,...)

Multiplying (the same as operator *).

ANY_NUM

MOD(ANY_INT IN1, ANY_INT2)

Remainder module (the same as operator IN1 MOD IN2).

ANY_INT

SQRT(LREAL IN1)

Square root.

LREAL

LOG(LREAL IN1)

Returns natural logarithm.

LREAL

LOG10(LREAL IN1)

Returns decimal logarithm.

LREAL

EXP(LREAL IN1)

Returns exponent.

LREAL

EXPT(LREAL IN1, LREAL IN2)

Raising IN1 to an IN2 power (the same as operator **).

LREAL

SIN(LREAL IN1)

The Sine of the input value in radians.

LREAL

COS(LREAL IN1)

The Cosine of the input value in radians.

LREAL

TAN(LREAL IN1)

The Tangent of input value in radians.

LREAL

ASIN(LREAL IN1)

Returns arc-sine value.

LREAL

ACOS(LREAL IN1)

Returns arc-cosine value.

LREAL

ATAN(LREAL IN1)

Returns arc-tangent value.

LREAL

ATAN2(LREAL IN1, LREAL IN2)

Returns angle included between positive x-axis and point specified by coordinates (x,y).

LREAL

Bitwise Boolean Functions

Function

Description

Result type

AND(ANY_BIT IN1, ANY_BIT IN2, ...)

Bitwise AND (the same as operator AND or &).

ANY_BIT

OR(ANY_BIT IN1, ANY_BIT IN2, ...)

Bitwise OR (the same as operator OR).

ANY_BIT

XOR(ANY_BIT IN1, ANY_BIT IN2, ...)

Exclusive OR (the same as operator XOR).

ANY_BIT

NOT(ANY_BIT IN1)

Bitwise NOT (the same as operator NOT).

ANY_BIT

Choice Functions

Function

Description

Result type

LIMIT(ANY_ELEMENTARY MN, ANY_ELEMENTARY IN1, ANY_ELEMENTARY MX)

Returns MN if IN1 is less than MN. Returns MX if IN1 is greater than MX, otherwise returns IN1.

ANY_ELEMENTARY

MAX(ANY_ELEMENTARY IN1, ANY_ELEMENTARY IN2, ...)

Returns larger value.

ANY_ELEMENTARY

MIN(ANY_ELEMENTARY IN1, ANY_ELEMENTARY IN2, ...)

Returns minor value.

ANY_ELEMENTARY

MUX(ANY_INT K, ANY_ELEMENTARY IN1, ...)

Returns one of N input variables depending on input variable K.

ANY_ELEMENTARY

SEL(BOOL G, ANY IN1,ANY IN2)

Returns IN1 if G is FALSE, otherwise returns IN2.

ANY

Compare Functions

Function

Description

Result type

SHL(ANY_BIT IN1, ANY_INT IN2)

Left-shifting by IN2 bits, bits on the right are filled with zero.

ANY_BIT

SHR(ANY_BIT IN1, ANY_INT IN2)

Right-shifting by IN2 bits, bits on the left are filled with zero.

ANY_BIT

ROL(ANY_BIT IN1, ANY_INT IN2)

Rotate shift to the left in IN2 bits.

ANY_BIT

ROR(ANY_BIT IN1, ANY_INT IN2)

Rotate shift to the right in IN2 bits.

ANY_BIT

Bit Shift Functions

Function

Description

Result type

SHL(ANY_BIT IN1, ANY_INT IN2)

Left-shifting by IN2 bits, bits on the right are filled with zero.

ANY_BIT

SHR(ANY_BIT IN1, ANY_INT IN2)

Right-shifting by IN2 bits, bits on the left are filled with zero.

ANY_BIT

ROL(ANY_BIT IN1, ANY_INT IN2)

Rotate shift to the left in IN2 bits.

ANY_BIT

ROR(ANY_BIT IN1, ANY_INT IN2)

Rotate shift to the right in IN2 bits.

ANY_BIT

String Processing Functions

Function

Description

Result type

LEN(ANY_STRING IN1)

Returns string length.

INT

LEFT(ANY_STRING IN1, ANY_INT L)

Returns substring beginning from the first symbol and L symbols length.

ANY_STRING

RIGHT(ANY_STRING IN1, ANY_INT L)

Returns substring beginning from the last symbol and L symbols length.

ANY_STRING

MIDDLE(ANY_STRING IN1, ANY_INT L, ANY_INT P)

Returns substring beginning from P position and L symbols length.

ANY_STRING

CONCAT(ANY_CHARS IN1, ANY_CHARS IN2, ...)

Concatenation of two strings.

ANY_STRING

INSERT(ANY_STRING IN1, ABY_CHARS IN2, ANY_INT P)

Insert IN2 in string IN1 after symbol P position.

ANY_STRING

REPLACE(ANY_STRING IN1,

ANY_CHARS IN2, ANY_INT L, ANY_INT P)

Replace L symbols of string IN1 with string IN2 beginning with symbol P position.

ANY_STRING

FIND(ANY_STRING IN1, ANY_CHARS IN2)

Find IN2 first occurrence symbol position in string IN1. If occurrence in string IN2 is not found, it will return 0.

INT

Date/Time Processing Functions

Function

Description

Result type

ADD_DT_TIME(DT IN1, TIME IN2)

Date and time of day addition (the same as operator +).

DT

ADD_TIME(TIME IN1, TIME IN2)

Time addition (the same as operator +).

TIME

ADD_TOD_TIME(TOD IN1, TIME IN2)

Time of day and time addition (the same as operator +).

TOD

SUB_DATE_DATE(DATE IN1, DATE IN2)

Two dates subtraction (the same as operator -).

TIME

SUB_DT_DT(DT IN1, DT IN2)

Two dates subtraction (the same as operator -).

TIME

SUB_DT_TIME(DATE IN1, TIME IN2)

Two dates subtraction (the same as operator -).

DT

SUB_TIME_TIME(TIME IN1, TIME IN2)

Two dates subtraction (the same as operator -).

TIME

SUB_TOD_TIME(TOD IN1, DATE IN2)

Two dates subtraction (the same as operator -).

TOD

SUB_TOD_TOD(TOD IN1, TOD IN2)

Two dates subtraction (the same as operator -).

TIME

MUL_TIME(TIME IN1, ANY_NUM IN2)

Multiplying time by number (the same as operator *).

TIME

DIV_TIME(TIME IN1, ANY_INT IN2)

Dividing time by number (the same as operator /).

TIME

CONCAT_DATE_TOD(DATE IN1, TOD IN2)

Concatenation of date and time.

DT

CONCAT_DATE(ANY_INT YEAR, ANY_INT MONTH, ANY_INT DAY)

Concatenation of date and time.

DATE

CONCAT_TOD(ANY_INT HOUR, ANY_INT MINUTE, ANY_INT SECOND, ANY_INT MILLISECOND)

Concatenation of time.

TOD

CONCAT_DT(ANY_INT YEAR, ANY_INT MONTH, ANY_INT DAY,ANY_INT HOUR, ANY_INT MINUTE, ANY_INT SECOND, ANY_INT MILLISECOND)

Concatenation of date and time.

DT

SPLIT_DATE(DATE IN1, DINT YEAR, DINT MONTH, DINT DAY)

Splitting of date.


SPLIT_DT(DT IN1, DINT YEAR, DINT MONTH, DINT DAY,DINT HOUR, DINT MINUTE, DINT SECOND, DINT MILLISECOND)

Splitting of date and time.


SPLIT_TOD(DINT HOUR, DINT MINUTE, DINT SECOND, DINT MILLISECOND)

Splitting of time.


DAY_OF_WEEK(DATE IN1)

Returns the day of  the week.

DINT

Type Checking Function

Function

Description

Result type

IS_DATATABLE(OBJECT IN1)

Returns TRUE if an argument is DATATABLE.

BOOL

IS_LINT(OBJECT IN1)

Returns TRUE if an argument is LINT.

BOOL

IS_DINT(OBJECT IN1)

Returns TRUE if an argument is DINT.

BOOL

IS_BOOL(OBJECT IN1)

Returns TRUE if an argument is BOOL.

BOOL

IS_LREAL(OBJECT IN1)

Returns TRUE if an argument is LREAL.

BOOL

IS_REAL(OBJECT IN1)

Returns TRUE if an argument is REAL.

BOOL

IS_WSTRING(OBJECT IN1)

Returns TRUE if an argument is WSTRING.

BOOL

IS_DT(OBJECT IN1)

Returns TRUE if an argument is DT.

BOOL

Type Casting Functions

This table shows type casting functions. Every function is called SOURCE_TYPE_TO_TARGET_TYPE (for example, a function of LREAL type casting into BOOL type, will be LREAL_TO_BOOL).

Source type

Target type

real

integer

unsigned

bit

date & times

char

other

LREAL

REAL

LINT

DINT

INT

SINT

ULINT

UDINT

UINT

USINT

LWORD

DWORD

WORD

BYTE

BOOL

TIME

DT

DATE

TOD

WSTRING

WCHAR

DATATABLE

OBJECT

LREAL

X

X

X

X

X

X

X

X

X

X

X

X

X

X

X

X

REAL

X

X

X

X

X

X

X

X

X

X

X

LINT

X

X

X

X

X

X

X

X

X

X

X

X

X

X

X

X

DINT

X

X

X

X

X

X

X

X

X

X

X

X

X

INT

X

X

X

X

X

X

X

X

SINT

X

X

X

X

X

X

X

ULINT

X

X

X

X

X

X

X

X

X

X

X

X

UDINT

X

X

X

X

X

X

X

X

X

UINT

X

X

X

X

X

X

USINT

X

X

X

X

LWORD

X

X

X

X

X

X

X

X

X

X

X

X

X

X

X

DWORD

X

X

X

X

X

X

X

X

X

X

X

X

X

X

WORD

X

X

X

X

X

X

X

X

X

X

X

X

BYTE

X

X

X

X

X

X

X

X

X

X

X

BOOL

X

X

X

X

X

X

X

X

X

X

TIME

X

DT

X

X

X

DATE

X

TOD

X

WSTRING

X

WCHAR

X

X

X

X

X

DATATABLE

X

X

X

X

X

X

X

X

X

X

X

X

OBJECT

X

X

X

X

X

X

X

X

User-Defined Functions

Function type (returned value type) can be any standard data type or type created by a user. Function body can be described in terms of ST or FBD language. SFC usage is forbidden. If the function should have a return type and also be employed in expressions, it's necessary to create a variable with the name matching function (context) name in VAR_OUTPUT ... END_VAR section.

Example: Let's say, we want to create the function with the name "foo". It would return value of BOOL type. Thus, we need to add a variable to the section:

VAR_OUTPUT

   BOOL : foo;

END_VAR

Was this page helpful?