The server has a built-in engine for running JS scripts that supports the ECMAScript 5 specification. The script manager provides a flexible mechanism for converting data received, for example, from a Modbus device and presenting them as OPC UA variables or time series.
- Formula between tags
- Mathematical functions and number conversion to and from bytes
- Operators of conditional statements (if-else) and cycles (for, while)
- Working with numbers, strings, date and time, arrays and dictionaries (map)
- Re-use of code (modules)
Module represents a file with program code that can be reused. For example, a constant or frequently used function can be defined in the module to be used in expressions.
return Math.sin(Math.PI / 2);
if (context.data['tag_flag'].state.value == true) return FahrenheitToCelsius(context.data['tag_temperature'].state.value); else return context.data['tag_temperature'].state.value;
Transformation of expression script into binary code involves several steps:
- Syntax check of the expression code
- Linking the imported modules (whose code also passes syntax check)
- Building the expression (converting the resulting code into binary code)
Note that the procedure of binary code creation may lead to memory shortage. For example, there are several thousand expressions defined on the server and they all use the same 10 KB module. In this case, the module code will be linked to each expression, so the module code will be copied into RAM as many times as the number of expressions defined on the server. Let's assume that the module code was erroneously changed and the module size increased to 500 KB. In this case, an avalanche-like increase in RAM consumption will occur (~ 50 times), which may cause the server to crash. To eliminate such problems, the server can be run in safe mode
All expressions are executed in an isolated context, i.e. variables and objects defined in the code are not shared, a special mechanism is provided for data transfer between expressions.