The Scripting Node allows users with basic programming knowledge to freely define custom operational logic using code.
To configure the node, the script must be written using the integrated IDE and then executed by the Logic Module.
The method called by default is:
MainMethod
Additional input parameters can be created by adding parameters to the method signature.
For example:
public static object MainMethod(object parameter1, object parameter2, object parameterN)
To complete the script execution successfully, the method must return a value.
The MainMethod is the entry point of the script.
Each parameter declared in the method signature becomes available as an input connector of the node.
For example:
public static object MainMethod(object a, object b)
creates two input parameters:
The method can then use these values inside the custom logic.
The script must return a value to complete its execution successfully.
For example:
public static object MainMethod(object a, object b)
{
return Convert.ToDouble(a) + Convert.ToDouble(b);
}
The returned result is sent to the default output of the Scripting Node.
Example of an addition script
The parameters declared in the MainMethod signature define the input connectors available on the Scripting Node.
For example:
public static object MainMethod(object temperature, object setpoint, object enable)
creates three input parameters:
Each parameter receives the value coming from the corresponding connector and can be used inside the script.
A practical example could be:
public static object MainMethod(object temperature, object setpoint, object enable)
{
bool active = Convert.ToBoolean(enable);
if (!active)
return 0;
double t = Convert.ToDouble(temperature);
double sp = Convert.ToDouble(setpoint);
if (t < sp)
return 1;
return 0; }
In this example:
The parameter names used in the MainMethod should be clear and descriptive, because they identify the corresponding values used by the script.
If more than one output value is required, additional parameters can be defined and used both as inputs and as outputs.
This allows the script to return the main result through the normal function return value and update additional values through the declared parameters.
Example of return parameter 2 value
The Scripting Node follows this sequence:
A simple addition can be implemented as:
public static object MainMethod(object value1, object value2)
{
double a = Convert.ToDouble(value1);
double b = Convert.ToDouble(value2);
return a + b; }
If:
value1 = 10
and:
value2 = 5
the returned result is:
15
The Scripting Node can also be used to implement custom conditions.
For example:
public static object MainMethod(object temperature, object setpoint)
{
double t = Convert.ToDouble(temperature);
double sp = Convert.ToDouble(setpoint);
if (t > sp)
return 1;
return 0; }
The script returns:
The Scripting Node is useful when the required logic cannot be conveniently implemented using standard Logic Module nodes.
Typical applications include:
The Scripting Node can be tested using the Logic Module simulation tools.
A typical test procedure is the following: