Sei sulla pagina 1di 5

Expressions

Syntax rules

An expression is made up of operands, operators, functions, constants, and comments. Each


expression must follow a specific syntax to be valid. The basic rules for valid DeltaV syntax
expressions include:

l Calculation/Logic Block definitions have a temporary variable capability.

l The Condition function block evaluates a multi-line expression. The assignment operator
(:=) is not a valid operator.

l The Action block requires the use of the assignment operator (:=). All other operators are
valid in the Action block provided the final evaluation of the expression is an assignment.

l Named set constants are represented by SetName:valueName.

l The only data type supported is floating point.

l An external (or database) reference is represented by a 'path' surrounded by single


quotes.

l The expression should end with a semi-colon (;). DeltaV software usually adds a semi-
colon for you if one is not there.

l Brackets used in an expression must be paired. Non-paired brackets can cause database
migration errors.

l The maximum number of characters in an expression is as follows:


running in a controller -cannot exceed 9941
used in a recipe -cannot exceed 2000
running in a Logic Solver - 9939
You can reduce expression length by relocating part of the expression or by making the
expression code more compact.

Note
The expression evaluator is stack oriented and allows a maximum of 32 operands and operators. The
use of parentheses to organize the expression minimizes the stack usage. The equations are
evaluated using RPN (Reverse Polish Notation).

Relative Notation

The following rules indicate the relative notation of parameters in an expression.

Table: Relative Notation Rules

Notation Relates to Rule Rule

// External References a parameter that is outside this module.


/ Module relative References a parameter within the current module.

^ Block relative References a parameter up one block level.

/+/ Phase relative References a parameter within a batch phase.

Assignment Statements

The := operator is an operator in DeltaV expressions. This operator allows for the assignment
of calculated values to locations inside and outside of the current block. Examples of the
assignment operator follow:

'Block1.mode.target' := MAN;RADIUS := .5;


OUT1:= 5 *RADIUS;

Assignment statements can be in any of the following formats:

output := value;

or

'external reference path' := value;

or

temporary variable := value;

If you wanted to increment a module-level parameter called SYRUP, the expression might look
like this:

'/SYRUP' := '/SYRUP' + 1;

Note
The assignment operator is not valid in the Condition block. However, the assignment operator is
required in the Action block.

If-Then-Else-End_if Statements

The IF-THEN-ELSE-END_IF structure allows you to execute conditional code in expressions.


When a block tests a condition that evaluates to TRUE, it executes one set of the statements;
otherwise, it executes a different set of statements. The following example illustrates the IF-
THEN-ELSE-END_IF structure:

IF '/Block1.mode.ACTUAL' = MAN THEN


'/Block1.mode.TARGET':= AUTO;
ELSE
OUT1:= IN1;
END_IF;

Note
DeltaV software allows you to use ENDIF or END_IF for your convenience. However, structured text
typically requires the use of the keyword END_IF.

In the preceding example, the condition tested is whether 'Block1.mode.ACTUAL' is equal to


manual. Notice that the '=' operator is not used as an assignment operator, but rather to test
the two operands for equality. If the condition is TRUE, the 'Block1.mode.TARGET' is set to
AUTO; otherwise, OUT1 is set to the value of IN1. Multiple statements can be placed between
the THEN keyword and the ELSE keyword as well as between ELSE and the END_IF keyword.

It is not always necessary to use the ELSE portion of the statement. For example, if you
wanted to set the parameter CALC block parameter OUT1 to TRUE when the process variable
of PID1 in LIC-549 goes above 75, the expression would look like this:

IF '//LIC-549/PID1/PV.CV' > 75 THEN


'OUT1.CV' := TRUE;
ENDIF;

Note
The CV extension in this example stands for current value. If the choice exists, ST stands for
status.

After you enter an expression, you can validate the expression syntax. The validation process
identifies syntax problems with the expression and any unresolved parameters. The expression
can be saved to the database with syntax errors, but the errors should be corrected before
downloading the expression.

While-Do-End_While

The WHILE-DO-END_WHILE structure allows you to continue executing a group of statements


while the value of an expression is True. This structure is available in the Calc/Logic and Action
function blocks.

The following example illustrates the WHILE-DO-END_WHILE structure:

I := 1;
WHILE (I <= 5) DO
'^/PARAM1'[I][1]:= I + .12;
I := I + 1;
END_WHILE;

Note
The indices are outside of the single quotes unless the .CV field is used. The parameter syntax must
be exactly as shown in the example ('^/PARAM1'[I][1]). It is recommended to show all access to the
matrix parameter (an input or output parameter defined as a floating point array type) using two
dimensions where the second is always [1].

The absolute limit of the number of iterations of a WHILE loop is 2000. However, nested
loops, IF statements within loops, and Labels within loops may reduce the limit. If a
WHILE loop reaches the limit, the loop stops, BLOCK_ERR and MSTATUS are set, and the
loop is not executed until the module is re-downloaded.
Exit

This structure prematurely exits the innermost WHILE-DO loop currently being executed. The
EXIT statement can only appear inside the statements of a WHILE_DO loop.

The following example illustrates using EXIT in a WHILE-DO loop:

I := 1;
WHILE (I <= 5) DO
'^/PARAM1'[I][1]:= I + .12;
IF ('^/PARAM1'[I][1] > 5) THEN
EXIT;
END_IF;
I := I + 1;
END_WHILE;

Note
This command is only available in the Calc/Logic and Action function blocks because that is where
the WHILE-DO construction is supported.

GOTO label

The GOTO label structure transfers processing to the statement identified by the specified
label. A label definition is a string followed by a colon (:).

The following example illustrates the GOTO label construct:

REM This expression takes IN1 to the IN2 power


cnt:=0;
answer:=1;
REM The following statement creates the label begin
begin:
IF cnt>=IN2 THEN
GOTO end;
END_IF;
answer:=answer*IN1;
cnt:=cnt+1;
GOTO begin;
end:
OUT1:=answer;

Subtopics:
Syntax for SFC Step Actions
Variables in expressions
I/O references
Matrix Parameter References
Inputs/Outputs of the Calc/Logic Block
External References
Internal References
Dynamic References
Diagnostic Parameters in Expressions
Strings
Operands
Operators
Functions
Reserved keywords
SFC Commands and State Transitions

Potrebbero piacerti anche