inSCADA
Ver 2020 EN
Search…
⌃K

Expressions

In nSCADA you can write expressions in javascript. Unlike scripts, expressions can take parameters from the environment in which they are used. Environments they are used;
  • Variable Expression,
  • Variable Logs,
  • Alarms,
  • Alarm Group On-Off-Ack Actions,
  • Animation Elements,
Expressions are not project dependent. Expressions you write can be used in all projects.

Variable Expression

Variable expression is executed during the read, scan of a variable's communication channel. The expression you add to a variable is executed based on the scan period of the Device and Frame to which the Variable is connected.
Variables passed to Expression;
  • initialValue (Number)
  • self (object)
Figure 2 : Variable Custom - Expression
As shown in Figure 2, a custom Expression is written in a Variable. In the Expression definition above, we mentioned that you can get parameters from the environment where the Expressions are executed. When you examine the javascript code written in the example in Figure 2, you will see a variable named "initialValue". The variable "initialValue" is a variable that can only be used in Variable, sent to Expression by the inSCADA platform. This variable contains the value of the corresponding Variable.
if (initialValue<10) {
return 1;
}
else
{
return 0;
}
If you examine the javascript code in Figure 2, it is provided that if the corresponding variable value is less than 10, it will be 1 and if it is greater than or equal will be 0.
Variable Expression is a very powerful and useful feature. In traditional methods, you need to create virtual Variables / Tag for more complex and different calculations of raw data read from devices, then write scripts and process and copy the raw value from Variables / Tags where you read the raw value. However, inSCADA does not allow you to fill your project with untraceable content for such operations. It offers you a more powerful and useful Variable Expression method.
Below are different examples of variable expressions.
// Joule to KCal
var newValue=initialValue/4185.5;
return newValue;
if (self.name.search("BAR">=0) {
return initialValue*1000; // Convert BAR to mBAR
}
if (self.name.search("PSI">=0) {
return initialValue*69; // Convert PSI to mBAR
}
var datetime=new Date(initialValue);
if (self.name.search("YEAR")>=0 {
return datetime.getYear()+1900;
}
if (self.name.search("MONTH")>=0 {
return datetime.getMonth()+1;
}

Variable Logs

Expressions written in variable logs allow the variable value to be saved to the database during the scan period when the result is true.
Below are examples of expression that can be used in variable log.
if initialValue>100 return true; else false;
if (self.name.search("DAILY")>=0 {
var dt=ins.now();
if (dt.getHours()===0 && dt.getMinutes()===0) {
return true; }
}
return false;
Last modified 3yr ago