Complete reference for all built-in functions available in the UniLogic ST editor.
Functions are grouped by category. All functions accept a single parameter of any compatible primitive type unless otherwise noted.
|
I want to... |
Use these functions |
|
Convert a value from one type to another |
TO_INT, INT(x), REAL_TO_INT, MOVE |
|
Do math on numbers |
ABS, SQRT, LN, LOG, EXP, SIN, COS, TAN, ASIN, ACOS, ATAN |
| Choose between values based on a condition |
SEL, MAX, MIN, LIMIT, MUX |
|
Work with text strings |
LEN, LEFT, RIGHT, MID, FIND, CONCAT, INSERT, DELETE, REPLACE |
|
Convert or read date and time values |
DT_TO_UDINT, UDINT_TO_DT, TO_TIME, TO_DT |
|
Do advanced math on numbers |
SINH, COSH, TANH, DEG, RAD |
|
Work with numeric tags, ranges, and structs |
RESET_NUMERIC, IN_RANGE, COPY_STRUCT, COMPARE_STRUCT |
Use type conversion when you need to move a value from one data type to another - for example, converting a REAL sensor reading to an INT for display, or converting a BOOL flag to a numeric value.
Three conversion styles are supported and produce identical results. Use whichever style you prefer or that matches your existing code:
|
Style |
Example |
When to use |
|
TO_* function |
TO_INT(myReal) |
Original UniLogic style |
|
IEC cast |
INT(myReal) |
Common in IEC environments |
| Source-to-target |
REAL_TO_INT(myReal) |
Explicit - makes the source type clear at a glance |
|
REAL to INT conversion truncates toward zero in all three styles: INT(3.9)=3, not 4. |
|
Function |
Returns |
Notes |
|
TO_REAL / REAL |
REAL |
Any numeric -> REAL |
|
TO_DINT / DINT |
DINT |
Truncates toward zero |
| TO_INT / INT |
INT |
Truncates toward zero |
|
TO_SINT / SINT |
SINT |
Truncates toward zero |
|
TO_UDINT / UDINT |
UDINT |
Truncates toward zero |
|
TO_UINT / UINT |
UINT |
Truncates toward zero |
| TO_USINT / USINT |
USINT |
Truncates toward zero |
| TO_BOOL / BOOL |
BOOL |
0 -> FALSE, anything else -> TRUE |
| TO_TIME / TIME |
TIME |
Compatible value -> TIME duration |
| TO_DT / DT |
DATE_AND_TIME |
Compatible value -> timestamp |
| MOVE (src) |
Same as src |
Copy with implicit conversion. |
All math functions accept any compatible numeric type (INT, DINT, REAL, etc.).
|
Function |
Description |
|
ABS |
Absolute value |
|
SQRT |
Square root |
| LN |
Natural logarithm |
|
LOG |
Base-10 logarithm |
|
EXP |
Exponential function (e^v) |
|
SIN |
Sine (radians) |
| COS |
Cosine (radians) |
|
TAN |
Tangent (radians) |
|
ASIN |
Arc sine |
| ACOS |
Arc cosine |
|
ATAN |
Arc tangent |
| SINH |
Hyperbolic sine |
|
TANH |
Hyperbolic tangent |
| COSH |
Hyperbolic cosine |
|
DEG |
Converts radians to degrees |
|
RAD |
Converts degrees to radians |
|
Function |
Description |
|
SEL (G, IN0, IN1) |
Returns IN1 if G is TRUE, IN0 if FALSE. |
|
MAX (a, b) |
Returns the larger of two values (same primitive type) |
| MIN (a, b) |
Returns the smaller of two values (same primitive type) |
|
LIMIT (MN, IN, MX) |
Clamps IN between MN and MX. |
|
MUX (K, IN0, ..., INn) |
Returns INK - the input at index K. |
These functions provide ST access to selected Ladder elements. They use ST function-call syntax and are compiled to the corresponding Ladder operation.
|
Function |
Description |
|
RESET_NUMERIC |
Resets a numeric tag. |
|
IN_RANGE |
Returns TRUE when value is within the specific range. |
| COPY_STRUCT (src, dst) |
Copies one struct to another. |
|
COMPARE_STRUCT (struct1, struct2) |
Compares two structs of the same type and returns TRUE when they are equal. |
String functions use 1-based indexing; position 1 is the first character.
The position (P) and length (L) parameters accept tag values, not just constants.
All string functions support mixed string types. You can freely mix STRING, STRING8, STRING16, STRING32, and WSTRING.
|
Function |
What it does |
Example |
|
LEN (IN) |
Returns the length of the string |
LEN("hello")->5 |
|
LEFT (IN, L) |
First L characters |
LEFT ("hello", 3) -> "hel" |
| RIGHT (IN, L) |
Last L characters |
RIGHT ("hello", 3) -> "llo" |
|
MID (IN, L, P) |
L characters starting at position P |
MID ("hello", 2, 2) -> "el" |
|
FIND (IN1, IN2) |
Position of IN2 in IN1. Returns -1 if not found. |
FIND("hello", "ll") -> 3 |
|
CONCAT (IN1, IN2) |
Join two strings. Also: IN1 + IN2 |
CONCAT("hi", "world") -> "hi world" |
| INSERT (IN1, IN2, P) |
Inserts IN2 into IN1 at position P |
INSERT("hllo", "e", "2")->"hello" |
|
DELETE (IN, L, P) |
Remove L characters starting at P. |
DELETE (hello", 2, 2) -> "hlo" |
|
REPLACE (IN1, IN2, L, P) |
Replace L characters at P with IN2. |
REPLACE("hello", "a", 1, 2)->"halo" |
Mixing STRING with WSTRING
|
Conversion |
Behavior |
|
STRING -> WSTRING (widening) |
No characters are lost |
|
WSTRING -> STRING (narrowing) |
Characters outside 0-255 become '?' |
Use these functions to convert between the DATE_AND_TIME type and numeric values, or to convert between TIME and other types.
|
Function |
Description |
|
DT_TO_UDINT |
Copies the UINT32 representation of a DATE_AND_TIME value |
|
UDINT_TO_DT |
Converts a UINT32 value to DATE_AND_TIME |
| TO_TIME |
Converts a compatible value to TIME |
|
TO_DT |
Converts a compatible value to DATE_AND_TIME |
| String functions use 1-based indexing. Position 1 is the first character. |