17 The SMP Gateway’s Automation Functions 163
17.1.4 Using the Logic Processor 168
SMP Config enables you to derive a data point through a mathematical expression that includes
existing data points.
For instance, you may want to export the value of a certain power aspect such as phase imbalance but no such data point is available. If data points are available for voltage and current, you can simply define three new data points calculated as the voltage times the current for each phase, then check power imbalance between the three points.
The expression for deriving a calculated data point can be evaluated in one of two ways:
By exception.
Whenever there is a transition on the data points included in the expression. If you choose this option, you also specify whether the evaluation is to be triggered by a specific data point or by any data point in the expression.
Periodically.
Every X milliseconds.
You can choose to have the expression evaluated either by exception or periodically, or both. If you choose both, the expression will be evaluated once every X milliseconds as well as anytime there is a transition on a data point or signal used in the expression. If you do not choose either method, the expression will be evaluated only once, on the SMP Gateway’s startup.
Note: This function is not available for the SMP 4-20 and the SMP 8-40.
To create a calculated data point:
In the left pane, at the bottom of the automated functions list, expand Functions and right- click Logic Processor.
In the shortcut menu, select Logic Editor.
The Logic Editor is used to enter the expression that generates the value of the calculated data point. It is displayed across several windows, which allow you to set the attributes of the calculated data point and assist you in editing the expression.
Use the toolbar at the top of the dialog box to validate, save and close the expression, or to undo the last change to the expression.
The table below describes the various areas of the dialog box:
Window Description
Properties Used to specify the different attributes of the calculated data point. These attributes are described in the sections below.
Data Points Used to select and enter existing data points in the expression. You can select data points from the list of available data points. These are grouped together in folders, based on grouping criteria that you established with the Group Settings tab of the Display Options dialog.
If you open the various folders, you will note that binary points are displayed in blue, while analog points are displayed in green.
The list is a memory jogger for selecting I/O points to be used in the expression. Double-click on an item to insert it at the cursor location in the expression window.
Functions Displays the list of all the functions that can be inserted in the expression. Double-click on an item to insert it at the cursor location in the expression
Window Description
in the expression. Double-click on an item to insert it at the cursor location in the expression window. The various operators are described in the sections below.
Expression (empty window at the bottom of the application window)
Used to enter and edit the expression to be evaluated. You can type the expression directly or use the memory-jogging windows described above. The result of the evaluation of the expression is assigned as the value of the calculated data point.
A calculated data point has the following properties:
Properties Description
Produced point Resulting data point.
Name Name of the calculated data point for which the expression is currently being
edited. This field cannot be edited. To edit an expression for another calculated data point, close the editor and select another data point in one of the analog or binary point pages in the Site view.
Description Optional space for you to type a description of the new point.
Timestamp Defines how the calculated data point is to be time-stamped. Specify "Server" if you want the system time to be used as the timestamp, and specify "Triggered point" if you want the timestamp to be the time of the point that triggered the calculation.
By default, the calculated data point is time-stamped by the SMP Gateway.
Quality Specifies whether the quality of the calculated data point will always be good,
or will depends the quality of its source point(s)
If you select Use source quality, as soon as the quality of one of the source points is bad, the calculated data point’s quality will also be bad.
Time-based Specifies whether the expression is to be evaluated on a periodic basis. The time interval is then specified via the Time interval attribute. Normally, expressions are not evaluated on a periodic basis.
Time interval (ms) Specifies that the expression is to be evaluated every X milliseconds. This time interval applies only if the Time-based attribute specifies "Yes". The minimum value is 50 ms. If this condition is
By exception Specifies whether the expression is to be evaluated whenever there is a transition on one of the data points or signals in the expression.
Specific trigger Specifies whether the evaluation of the expression is to be triggered by a single data point ("Yes") or by any data point ("No") in the expression. This attribute is ignored if By exception is set to "No".
Triggered by Used to specify the name of the data point or signal that will trigger the evaluation of the expression. This attribute is ignored if Specific trigger is set to "No".
17.1.4.1
Data Point Names in Expressions
To use a data point in an expression, simply type the name of the data point. Make sure to include the prefix, if applicable.
A data point name used in an expression must adhere to the following Visual Basic-like notation:
It must begin with a letter.
It can include alphanumeric characters (A-Z, a-z, 0-9), the underscore separator " _ " (without the quotes), and special characters, such as a period.
If the data point name contains a special character, it must be surrounded by the delimiter character " (the quotation mark). For example, a physical data point name of T5.APHA must be declared as "T5.APHA".
Here are some examples of valid expressions:
120 + ( CurrentPoint * 0.02 * ( Rand() - 1 ) )
( 0.85 "T5.APHA" * "T5.KVAB" ) / 1000
"1B17.MA" AND ("120-1.MA" AND NOT "120-1.MB" ) AND "1B1.MA"
Imbalance("T5.APHA", "T5.APHB", "T5.APHC")
17.1.4.2
Comments in Expressions
Expressions can span several lines. To insert a comment into an expression, put a single quote at the beginning of the line.
For instance:
' Calculates the imbalance of transformer #5 Imbalance("T5.APHA", "T5.APHB", "T5.APHC")
17.1.4.3
Condition Statements
You can use the following condition statements in expressions:
Statement Description
If <condition> Then <expression> Endif
Evaluates the specified expression if the logical condition is true.
If <condition> Then <true expression> Else
<false expression> Endif
Evaluates the expression specified after the "THEN" if the logical condition is true, or evaluates the expression specified after the "ELSE" if the logical condition is false.
Note that the expression can contain several embedded IF and ELSE statements, in which case each ELSE statement is associated with the IF statement closest to it.
17.1.4.4
Mathematical Functions
You can use the following built-in mathematical functions in expressions:
Function Description
Abs( x ) Calculates the absolute value of x.
Pow( x, y ) Calculates the value of x to the power of y.
Sqrt( x ) Calculates the square root of x.
Exp( x ) Calculates the value of e raised to the power of x.
Log( x ) Calculates the logarithm of x to the base 10.
Sin( x ) Calculates the sine of angle x, expressed in radians.
Cos( x ) Calculates the cosine of angle x, expressed in radians.
Tan( x ) Calculates the tangent of angle x, expressed in radians.
ArcSin( x ) Calculates the arcsine of angle x.
ArcCos( x ) Calculates the arccosine of angle x.
ArcTan( x ) Calculates the arctangent of angle x.
Min( x, y ) Compares the values of x and y, and retains the lesser of the two.
Max( x, y ) Compares the values of x and y, and retains the greater of the
two.
17.1.4.5
Data Point Functions
You can use the following built-in data point functions in expressions.
Function Description
Imbalance( point A, point B, point C )
Calculates the imbalance among three phases, for the current represented by the three data point names.
The calculation is defined as follows for a three-phase current: ((Imax - Imin) / Iavg) * 100
where:
Iavg = (AI + AB + IC) / 3 Imax = max (IA, IB, IC) Imin = min (IA, IB, IC)
IsEqual( point1, point2, precision ) Compares point1 and point2, to the nearest precision significant digits.
The expression evaluates to TRUE or FALSE, depending on whether or not point1 = point2.
IsTrigger( point ) Evaluates to TRUE if the specified point causes the expression to be reevaluated.
QualityOf( point ) Evaluates to TRUE if the value of the specified data point is
valid.
TimestampOf( point ) Returns the timestamp of a point, as a number of milliseconds
that have elapsed since an internal reference date and time. Use this function for the sole purpose of comparing timestamps that were obtained via a previous call to the TimestampOf() function.
BAD_QUALITY Sets the quality of a data point to BAD, which means that the
value of the data point cannot be assumed as valid.
17.1.4.6
Generators
You can use the following built-in generators in expressions. Generators are used to mathematically generate input values for data points.
Generator Description
Sine( amplitude, frequency, phase ) Generates an expression of the form: Sine( A, f, P ). Calculates the value of a sinusoid with an amplitude A, a frequency f in hertz, and an initial phase P in degrees. P is optional and if you don't specify it, it will be assigned a value of 0.
Pulse( amplitude, frequency, duty cycle, delay )
Generates an expression of the form: Pulse( A, f, dc, d ). Calculates the value of a pulse stream with an amplitude A, a frequency f in hertz, a duty cycle cd in percent, and a delay of d milliseconds. d is optional and if you don't specify it, it will be assigned a value of 0.
Saw( amplitude, frequency, delay ) Generates an expression of the form: Saw( A, f, d ).
Calculates the value of a sawtooth wave with an amplitude A, a frequency f in hertz, and a delay of d milliseconds. d is optional and if you don't specify it, it will be assigned a value of 0.
Randn( mean, variance ) Generates an expression of the form: Randn( mean, var ).
Calculates a random value with a normal distribution that has a mean value of mean and a variance of var.
Rand() Generates an expression of the form: Rand( ).
Calculates a random value with a uniform distribution ranging between 0.0 and 1.0.
17.1.4.7
Arithmetic Operators
You can use the following arithmetic operators in expressions:
Operator Description
+ [Add] Calculates the sum of the left and right operands.
- [Subtract] Calculates the difference between the left and right operands.
* [Multiply] Calculates the product of the left and right operands.
/ [Divide] Divides the left operand by the right operand.
( [Opening parenthesis] Expressions are evaluated according to standard operator precedence. Parentheses are used to group sub-expressions and control the order in which expressions are evaluated.
1 + 2 * 3 evaluates to 7 (1 + 2) * 3 evaluates to 9
) [Closing parenthesis] Expressions are evaluated according to standard operator precedence. Parentheses are used to group sub-expressions and control the order in which expressions are evaluated.
1 + 2 * 3 evaluates to 7 (1 + 2) * 3 evaluates to 9
17.1.4.8
Binary Operators
Binary operators are used to manipulate the individual bits of expressions or data points.
You can use the following binary operators in expressions:
Operator Description
BAND Calculates a bitwise AND between the left and right operands.
For instance, 12 BAND 5 evaluates to 4 (1100 BAND 0101 is 0100).
BOR Calculates a bitwise OR between the left and right operands.
For instance, 12 BOR 5 evaluates to 13 (1100 BAND 0101 is 1101).
BNOT Calculates a bitwise NOT of the value to the right.
For instance, BNOT 0 evaluates to -1 (BNOT …0000 is …1111).
BXOR Calculates a bitwise XOR between the left and right operands.
For instance, 12 BXOR 5 evaluates to 9 (1100 BXOR 0101 is 1001).
BEQV Calculates a bitwise EQV between the left and right operands.
17.1.4.9
Logical Operators
Logical operators are used to combine the results of logical expressions such as comparisons.
You can use the following logical operators in expressions:
Operator Description
AND Evaluates to TRUE if the left and right operands are both TRUE.
OR Evaluates to TRUE if either the left or right operand is TRUE.
NOT Evaluates to TRUE if the value to the right is FALSE.
XOR Evaluates to TRUE if the left and right operands have different values.
EQV Evaluates to TRUE if the left and right operands have the same value.
17.1.4.10
Relational Operators
You can use the following relational operators in expressions:
Operator Description
< [Less than] Evaluates to TRUE if the left operand is less than the right operand. > [Greater than] Evaluates to TRUE if the left operand is greater than the right operand. <= [Less than or equal
to]
Evaluates to TRUE if the left operand is less than or equal to the right operand.
>= [Greater than or equal to]
Evaluates to TRUE if the left operand is greater than or equal to the right operand.
= [Equal to] Evaluates to TRUE if the left operand is equal to the right operand.
!= [Not equal to] Evaluates to TRUE if the left operand is different from the right operand.
17.1.4.11
Constants and Variables
You can use the following built-in constants and pseudo-variables in expressions:
Operator Description
CurrentPoint [Point value]
Represents the current value, i.e., the value of the logical point being edited, just prior to its evaluation.