Learn about functions and operators
- Last UpdatedJan 28, 2025
- 6 minute read
- PI System
- PI Connector for UFL 1.3.2.139
- Connectors
Fields can be assigned values, which are the results of expressions or functions. In other words, the resulting value on the right-hand side of an assignment is stored into the field (variable) on the left-hand side. For example:
Value = Value + 1
FIELD(3)=FIELD(1)+FIELD(2)
FIELD(4)=UPPER(Tag)
TimeStamp=NOW()
Note: Fields are NULL when declared; that is, their value is undefined.
The following sections describe the operations you can perform on data in fields. The data types of all operands in the expression on the assignment's right hand side are implicitly converted as needed.
Arithmetic and logical operators
|
Function |
Description |
Data Types |
|---|---|---|
|
|
Multiply and Divide. |
Number, Int32, Time |
|
|
Add and Subtract. |
Number, Int32, DateTime, Time |
|
|
String concatenation. |
String |
|
|
Logical AND. Returns 1 if both operands are non-zero, else returns 0. |
Number, Int32 |
|
|
Logical OR. Returns 1 if either operand is non-zero, else returns 0. |
Number, Int32 |
|
|
Checks if a field is a NULL |
Any |
|
|
Checks if a field is not a NULL |
Any |
Mathematical functions
|
Function |
Description |
Data Types |
|---|---|---|
|
|
Absolute value |
Number ABS (x Number) |
|
, , , , , , |
Trigonometric functions. Angles are in radians. |
Number ACOS (x Number) … Number ATAN2 (x Number, y Number) |
|
|
Rounds a number with a fractional portion to the next higher integer. |
Number CEILING (x Number) |
|
|
Exponential value to base e (Euler's number ≈ 2.71828). |
Number EXP (x Number) |
|
|
Rounds a number with a fractional portion to the next lower integer. |
Number FLOOR (x Number) |
|
|
Logarithm to base e (Euler's number ≈ 2.71828). |
Number LOG (x Number) |
|
|
Logarithm to base 10. |
Number LOG10 (x Number) |
|
|
Mathematical constant. Ratio of a circle's circumference to its diameter. ≈ 3.14159. |
Number PI () |
|
|
Rounds the value. Numbers that are right in the middle, for example 0.5, are rounded up. |
Number ROUND (x Number) |
String functions
|
Function |
Description |
Data Types |
|---|---|---|
|
|
Converts an int32 ASCII code (0-255) to a character. |
String CHAR (n Int) |
|
|
Concatenate two strings. |
String CONCAT (x String, y String) |
|
|
Returns the position of the given occurrence of a specified substring. Positions start with 1. Returns 0 if specified substring is not found. |
Int INSTR (x String, substring String, start Int, occurrence Int) |
|
|
All characters lower-case. |
String LOWER (x String) |
|
|
Returns the leftmost n characters. |
String LEFT (x String, n Int) |
|
|
Number of characters excluding leading and trailing blanks. |
Int LEN (x String) |
|
|
Trim the leading blanks. Note: Blanks are space characters. |
String LTRIM (x String) |
|
|
Find the specified string and replace it with the third parameter. |
String REPLACE (x String, findWhat String, replaceWith String) |
|
|
Returns the rightmost n characters. |
String RIGHT (x String, n Int) |
|
|
Trim the trailing blanks. Note: Blanks are space characters. |
String RTRIM (x String) |
|
|
Character string consisting of n spaces. |
String SPACE (n Int) |
|
|
String consisting of LEN characters starting at start position. |
String SUBSTR (x String, start Int, LEN Int) |
|
|
Trim leading and trailing blanks. Note: Blanks are space characters. |
String TRIM (x String) |
|
|
All characters upper-case. |
String UPPER (x String) |
DateTime and Time functions
The following functions extract a portion of a DateTime or Time value.
|
Function |
Data Types |
|---|---|
|
|
Int32 DAY (x DateTime) |
|
(Extracts the sub-seconds) |
Number FRACTION (x DateTime) Number FRACTION (x Time) |
|
|
Int32 HOUR (x DateTime) Int32 HOUR (x Time) |
|
|
Int32 MINUTE (x DateTime) Int32 MINUTE (x Time) |
|
|
Int32 MONTH (x DateTime) |
|
|
String MONTHNAME (x DateTime) |
|
|
Int32 SECOND (x DateTime) Int32 SECOND (x Time) |
|
|
Int32 WEEK (x DateTime) |
|
|
Int32 YEAR (x DateTime) |
Functions for extracting from well-known data formats
Extract elements from the CSV and JSON input. There are more examples on GitHub - PI Connector for UFL Samples, showing the syntax and the use with concrete CSV and JSON structures.
|
Function |
Description |
|---|---|
|
|
Function applicable in the condition part of the statement. It populates the predefined string variable _ITEM. (String) is a succession of delimited values. (String) can be one or more characters. Note: The is case sensitive. Returns false if the end of the delimited values was reached, otherwise it returns true. Example: FOREACH(CsvGetItem(__MESSAGE, ";")) DO |
|
|
Function applicable in the condition part of the statement. It populates the following predefined variables:
|
|
|
Function for extracting a single element from a JSON input. (String) must be a valid JSON structure. (String) full path (backslash delimited) to a single JSON element. Note: The is case sensitive. Returns the referenced JSON element in a String form. To convert a string form to the required data type, assign the returned string to a variable which has the required type. Example: Value_String = JsonGetValue(__MESSAGE, "Elem1\Elem11") Note: Use the function to verify that the conversion from String to Number is valid. IF(IsNumber(Value_String) == 1) THEN |
Miscellaneous functions
Specify actions in the message-specific section that filters and processes messages.
|
Function |
Description |
|---|---|
|
|
Adds a name-value pair or just a value into the collection. |
|
|
Returns 1 (Int32) when it is the first line of the stream. Otherwise returns 0. |
|
|
Clears the collection. |
|
|
Converts a numeric Julian date to a PI time stamp. A Julian date represents an interval of time as days and fractions of a day since January 1, 4713 BCE Greenwich noon. |
|
|
Returns 1 (Int32) when it is the last line of the stream. Otherwise returns 0. |
|
|
Determines whether the string parameter can be converted to a numeric value. Returns 1 if a meaningful conversion exists, 0 if not. Note: Beginning with version 1.3.0.106, numeric values with a padded white space, such as " 123.45 ", "676 ", and " 893", will return 1 when passed as an input to isNumber ( ). |
|
|
Returns the current local time stamp in DateTime format. For all messages read from a file, Now() returns the same time stamp, the time when the file is opened for reading. |
|
|
Returns the current local time stamp in UTC format. For messages from a file, NowUTC() returns the same time stamp, the time when the file is opened for reading. |
|
|
Converts a string containing a hexadecimal number to Int32. |
|
|
Converts a string containing a hexadecimal number to Int16. |
|
|
Prints the string or variable value to the log. Returns the variable converted to string. |
|
|
Changes the order in which filters are applied to messages. By default, filters are applied in the order in which they are specified in the configuration file. This action redirects the specified number of messages to the filter for the specified message. If you omit the number of messages, all subsequent messages are directed to the specified filter. |
|
|
Skips the remaining lines that arrive in an input stream. This action can be used when, for example, a certain line indicates that the remaining rows are invalid. |
|
|
Skips the specified number of lines from the input stream. |
|
, , or |
Sends data to PI point(s). If the referenced point does not exist, the connector creates it. |
|
|
Creates or updates a PI AF element. If the referenced element does not exist, the connector creates it. |
|
|
Creates or updates an event frame. If the referenced event frame does not exist, the connector creates it. |
|
|
Returns the variable (field name) converted to string. |
Predefined variables
The following predefined string variables are recognized within the INI logic. Their meaning summarizes the following table:
|
Variable name |
Description |
|---|---|
|
__DSNAME |
The name of the configured data source (on the connector administration page). |
|
__DSDESCRIPTION |
Data source description. |
|
__DSADDRESS |
Data source address. |
|
__ITEM_Name |
A string variable which is assigned the name of the selected JSON element each time the function is evaluated. |
|
__ITEM |
A string variable which is assigned a value each time the or functions are evaluated. |
|
__MESSAGE |
The content of the current message (line). |
|
__STREAMINFO |
Stream information. For the File channel, this variable has the following format: filename|modification date|creation date For example, will return: For the REST(server) channel, this variable has the following format: Source IP Address|Port For example, will return: For the REST(client) channel, this variable has the following format: Endpoint address For example, will return: https://restcountries.eu/rest/v1/alpha/LIE |