UniLogic offers a Structured Text editor that enables you to create functions.
Use these functions in the same way you use standard ladder functions. You can call them just like standard ladder functions, reuse them, and export/import them via the Library. You can also refer to Ladder functions.
The following example shows how to find the location of characters in a string, using three tags and the FIND function provided in the Structured Text library.
This enables you to view global tags in Structured Text functions via online mode, without having to pass them as a parameter.
In the Properties Window:
Click Used Globals.
Begin typing the global name.
Select the desired globals; click Close.
The global tags are included as Var_External
In the function, begin typing the name of the desired tag; click to include it in your code.
Structured Text Function Library
TO_REAL, TO_DINT, TO_INT, TO_SINT, TO_UDINT, TO_UINT, TO_USINT - all receive a single parameter of any primitive type and return it casted to the relevant type (f.e. TO_REAL returns the parameter as a real number).
ABS - absolute value function
SQRT - square root function
LN - natural logarithm
LOG - base 10 logarithm
EXP - the exponent function
SIN, COS, TAN, ASIN, ACOS, ATAN - trigonometric functions
SEL(G, IN0, IN1) - G is a boolean, IN0 and IN1 are of any primitive type, but must be the same type. If G evaluates to true, return IN1, otherwise return IN0
MAX, MIN - receive 2 parameters of the same primitive type and return the max \ min of the two
LIMIT(MN, IN, MX) - all three parameters must be of the same primitive type. equivalent to MIN(MAX(MN, IN), MX)
LEN(IN) - return the length of a string
LEFT, RIGHT (IN, L) - return the left \ right substring of length L of IN (LEFT("hello", 4) -> "hell")
MID(IN, L, P) - return the substring of length L starting at index P of L (MID("hello", 2, 2) -> "el")
DELETE(IN, L, P) - return IN with the substring of length L starting at index P deleted (DELETE("hello", 2, 2) -> "hlo")
INSERT(IN1, IN2, P) - insert the string IN2 to IN1 at index P
REPLACE(IN1, IN2, L, P) - replace L characters of IN1 starting at index P by IN2
FIND(IN1, IN2) - find the character index of the first occurrence of IN2 in IN1. If not found - return -1