Formulas are used for calculating values and statuses of input channels and calculating values of commands. Formulas processing is performed by the Server application.
Formulas are enterd in the Formula column of the Input channels and Output channels tables of the configuration database. To enable the formula, tick the checkbox in the Formula used column. The Formulas table contains additional functions and data structures which can be used in formulas for input and output channels.
The general rules of writing and using formulas:
The rules for calculating input channel formulas:
The rules for calculating output channel formulas:
The variables accessible in formulas:
Variable | Value Type | Description |
---|---|---|
CnlVal, Cnl | double | The input channel value transmitted to Server before calculation |
CnlStat | int | The input channel status transmitted to Server before calculation |
CmdVal, Cmd | double | The command value transmitted to Server before calculation |
CmdData | byte[] | The command data transmitted to Server before calculation |
CnlNum | int | The channel number for which the formula is calculated |
E | double | The natural logarithmic base, specified by the constant, e |
PI | double | The ratio of the circumference of a circle to its diameter, specified by the constant, π |
The functions accessible in formulas:
Fucntion | Value Type | Description |
---|---|---|
N(n) | int | Returns the specified channel number for updating numbers on cloning |
Val() | double | Gets the current value of the formula channel |
Val(n) | double | Gets the current value of the channel n |
SetVal(n, val) | double | Sets the current value of the channel n |
Stat() | int | Gets the current status of the formula channel |
Stat(n) | int | Gets the current status of the channel n |
SetStat(n, stat) | int | Sets the current status of the channel n |
SetData(n, val, stat) | double | Sets the current value and status of the channel n |
Abs(x) | double | Calculates the absolute value of a number |
Sin(x) | double | Calculates the sine of the specified angle |
Cos(x) | double | Calculates the cosine of the specified angle |
Tan(x) | double | Calculates the tangent of the specified angle |
Exp(x) | double | Calculates e raised to the specified power |
Ln(x), Log(x) | double | Calculates the natural (base e) logarithm of a specified number |
Sqr(x) | double | Calculates the square of a specified number |
Sqrt(x) | double | Calculates the square root of a specified number |
Additional formulas, including formulas for calculating averages, are available on GitHub.
If you develop custom formulas, check their syntax and validate whether they work correctly. If the Server service fails to compile the formulas at startup, information about the error is written in the Server log file, and the source code of the formulas that Server tries to compile is available in CalcEngine.cs, which is located in the Server log directory, by default C:\SCADA\ScadaServer\Log\
To develop complex formulas, it is recommended to use Microsoft Visual Studio Community Edition. Add a refererence to the FormulaTester.dll assembly in the project. As an example, use the project mentioned above, which contains formulas.