You are on page 1of 109

SurvalentONE

CS-400
COMMAND SEQUENCING
USER GUIDE

Version 1.14
CS-400 Command Sequencing User's Guide

Copyright, Notices and Trademarks


Copyright © Survalent Technology Corporation. All rights reserved. The software
described in this document is furnished under license and can only be used or copied in
accordance with the terms of such license. The content of this manual has been carefully
checked for accuracy. If you find any errors, please notify the Survalent Technology
Corporation.

Survalent Technology Corporation


7965 Heritage Road
Brampton, Ontario L6Y 5X5

(905) 826 5000

(905) 826 7144

support@survalent.com

www.survalent.com
FAX (905) 826-7144

The software described in this document is furnished under license and may only
be used or copied in accordance with the terms of such license.

About This Publication


This manual describes how to use the Command Sequencing programming
environment in the Windows SCADA system.
CS-400 Command Sequencing User's Guide

Revisions

Version Description
1.0 Added historical data functions (FCAST and AVGMAX) useful for supervising load
shedding.

Added Load Shed LCR Type 7 for RCCA devices.


LS is a command, not a function.

1.2 Added Load Shed LCR Type 8 for devices supported by RTC 1032.

The sequence state point is now optional.

1.3 Added DNPTIME function – see Time Functions (TIME and DNPTIME).

Added LIMIT command to set analog limits.

Added short forms ‘SEC’ and ‘MIN’ as parameters in TIME function.

Added documentation for COND, START, STOP commands.


1.4 Added BLOCK, UNBLOCK and EVENTDATA commands.

1.5 Added RANDOM function.

Added DISKSPACE function. Added SETLOG command. Added additional


parameter to ALARM command. Added UNNACKEDALARMS function.

Added GETTIME and SYNC commands. Added Restart checkbox.

Enhanced LS command for MultiSpeak load shed and added LSM command.
Added BITAND, BITOR and BITXOR arithmetic functions.

1.6 Enhance AVXMAX function to add data qualifiers.


Allow text parameter of ALARM command to be a string variable.

Add MAXV, MINV, AVG, enhanced FCAST, editor Find

Add new form of START and STOP command (comlines, deservers, mapboards,
cmdseq).

Add ISBLOCKED function (section 3.5.16, Point Functions)


CS-400 Command Sequencing User's Guide

Version Description
1.7 Added UNSET condition.

Corrected description of Save pushbutton.

Added milliseconds to DELAY command.

1.8 Added TASKRUNNING function.

Added POLL command.

Added DATA command.

Added .INTERLOCKED. status and SET_INTERLOCK command.

Added TIME(‘DAYOFWEEK’).
1.9 Added OUTPUT command.

Added FAULTMSG command.

Added POINTNAME function.

Added OV. point condition check.

1.10 Added METER commands.

Added METERSTATUS function.

Added StartReport command.


1.11 Added analog alarm limits data items.

Added Wait command.


1.12 Added monthly data, analog limits in DATA function.

Updated description of the TAG command.

Added StationsInMaint function.

Added TAGLEVEL function.


1.13 Added a note on forcing a voice code from a command sequence.

Document HLIB\SAMPLE (available in server versions 1.17.0105 and above).

Added LINESECTION and LSNAME functions.


1.14 Added GetStatus, SetStatus, ResetStatus.

Added new logo and updated cover.


CS-400 Command Sequencing User's Guide

Contents

1 Introduction 1-1

1.1 Other Documents ............................................................................................................................ 1-3

2 Command Sequence Editing 2-1

2.1 Command Sequence Editor ............................................................................................................. 2-1


2.1.1 Toolbar ........................................................................................................................................ 2-2
2.1.2 Sequence #................................................................................................................................... 2-3
2.1.3 Name ........................................................................................................................................... 2-4
2.1.4 Description .................................................................................................................................. 2-4
2.1.5 State Point ................................................................................................................................... 2-4
2.1.6 Auto Startup ................................................................................................................................ 2-4
2.1.7 Restart.......................................................................................................................................... 2-4
2.1.8 Source .......................................................................................................................................... 2-5
2.1.9 Sequence Status ........................................................................................................................... 2-5
2.1.10 Log............................................................................................................................................... 2-6
2.1.11 Exit .............................................................................................................................................. 2-6
2.2 Starting and Stopping a Command Sequence ................................................................................. 2-6
2.3 Triggering By Status Change .......................................................................................................... 2-7

Command Sequencing Contents i


CS-400 Command Sequencing User's Guide

3 Command Sequence Language 3-1

3.1 Statement Format ............................................................................................................................ 3-1


3.2 Syntax ............................................................................................................................................. 3-2
3.2.1 Operators ..................................................................................................................................... 3-2
3.2.2 Variables and Expressions .......................................................................................................... 3-2
3.2.3 Arrays .......................................................................................................................................... 3-5
3.3 Control Structures ........................................................................................................................... 3-6
3.3.1 IF/ELSE/ENDIF .......................................................................................................................... 3-6
3.3.2 DO/WHILE/ENDWHILE ........................................................................................................... 3-7
3.3.3 ONGOTO .................................................................................................................................... 3-8
3.4 Commands ...................................................................................................................................... 3-9
3.4.1 ACKNOWLEDGE ...................................................................................................................... 3-9
3.4.2 ALARM....................................................................................................................................... 3-9
3.4.3 CALL......................................................................................................................................... 3-11
3.4.4 CMD .......................................................................................................................................... 3-12
3.4.5 COND ........................................................................................................................................ 3-12
3.4.6 DELAY ..................................................................................................................................... 3-13
3.4.7 WAIT......................................................................................................................................... 3-14
3.4.8 EXIT .......................................................................................................................................... 3-15
3.4.9 FAULTMSG ............................................................................................................................. 3-16
3.4.10 SET ............................................................................................................................................ 3-16
3.4.11 OUTPUT ................................................................................................................................... 3-16
3.4.12 SETLOG.................................................................................................................................... 3-17
3.4.13 START command sequence, communications line, data exchange server ............................... 3-18
3.4.14 STOP ......................................................................................................................................... 3-18
3.4.15 TEST ......................................................................................................................................... 3-19
3.4.16 TAG ........................................................................................................................................... 3-20
3.4.17 SET_INTERLOCK ................................................................................................................... 3-21
3.4.18 LS .............................................................................................................................................. 3-22
3.4.19 LSM ........................................................................................................................................... 3-27
3.4.20 LIMIT ........................................................................................................................................ 3-28
3.4.21 BLOCK ..................................................................................................................................... 3-29
3.4.22 UNBLOCK ................................................................................................................................ 3-30
3.4.23 EVENTDATA ........................................................................................................................... 3-31
3.4.24 GETTIME ................................................................................................................................. 3-31
3.4.25 SYNC ........................................................................................................................................ 3-32
3.4.26 POLL ......................................................................................................................................... 3-33
3.4.27 METER commands ................................................................................................................... 3-33
3.4.28 StartReport ................................................................................................................................ 3-34
3.4.29 Status with timestamp processing (GetStatus, SetStatus) ......................................................... 3-34
3.5 Functions ....................................................................................................................................... 3-35
3.5.1 Arithmetic Functions ................................................................................................................. 3-35
3.5.2 Logarithmic/Exponential Functions .......................................................................................... 3-36
3.5.3 Trigonometric Functions ........................................................................................................... 3-37
3.5.4 String Functions ........................................................................................................................ 3-38
3.5.5 Time Functions (TIME and DNPTIME) ................................................................................... 3-39
3.5.6 Template Function (TPLATE) .................................................................................................. 3-40
3.5.7 Table Lookup Function (LOOKUP) ......................................................................................... 3-40

Command Sequencing Contents ii


CS-400 Command Sequencing User's Guide

3.5.8 Maximum Sample Value (MAXV) ........................................................................................... 3-40


3.5.9 Minimum Sample Value (MINV) ............................................................................................. 3-41
3.5.10 Average Sample Value (AVG).................................................................................................. 3-41
3.5.11 Get Sample (Sample)................................................................................................................. 3-42
3.5.12 Forecast Function (FCAST) ...................................................................................................... 3-42
3.5.13 Average of Maximums (AVGMAX) ........................................................................................ 3-43
3.5.14 Random Value (RANDOM) ..................................................................................................... 3-44
3.5.15 Free Space on Disk (DISKSPACE) .......................................................................................... 3-44
3.5.16 Point Functions .......................................................................................................................... 3-44
3.5.17 Get Meter Status (METERSTATUS) ....................................................................................... 3-45
3.5.18 Is a Windows Task Currently Active (TASKRUNNING) ........................................................ 3-46
3.5.19 Data function ............................................................................................................................. 3-46
3.5.20 Line Section Commands ........................................................................................................... 3-49
3.5.21 GetStatus ................................................................................................................................... 3-50

4 Templates 4-51

4.1 Template Editor ............................................................................................................................ 4-51


4.1.1 TOOLBAR ................................................................................................................................ 4-52
4.1.2 TEMPLATE # ........................................................................................................................... 4-53
4.1.3 NAME ....................................................................................................................................... 4-53
4.1.4 DESCRIPTION ......................................................................................................................... 4-54
4.1.5 PARAMETER DEFINITION ................................................................................................... 4-54
4.1.6 SOURCE ................................................................................................................................... 4-54
4.1.7 LOG ........................................................................................................................................... 4-54
4.2 Language Restrictions in Templates ............................................................................................. 4-55
4.3 Example of a Template ................................................................................................................. 4-55
4.4 Using Templates on CALCED ..................................................................................................... 4-57
4.5 Using Templates in Command Sequences .................................................................................... 4-59

5 Table Lookup 5-1

5.1 Lookup Matrix Editor ..................................................................................................................... 5-1


5.2 Matrix Editor Data Fields ............................................................................................................... 5-3
5.2.1 MATRIX ID ................................................................................................................................ 5-3
5.2.2 NAME ......................................................................................................................................... 5-3
5.2.3 DESCRIPTION ........................................................................................................................... 5-4
5.2.4 ORIGIN ....................................................................................................................................... 5-4
5.2.5 DELTA ........................................................................................................................................ 5-4
5.2.6 SIZE............................................................................................................................................. 5-4
5.2.7 MATRIX ELEMENTS ............................................................................................................... 5-4
5.3 Lookup Function ............................................................................................................................. 5-5

Command Sequencing Contents iii


CS-400 Command Sequencing User's Guide

6 Messages 6-1

6.1 Compiler Error Messages ............................................................................................................... 6-1


6.1.1 Array type mismatch ................................................................................................................... 6-2
6.1.2 Command is not supported in Templates .................................................................................... 6-2
6.1.3 Database point point_name - invalid type/action ........................................................................ 6-2
6.1.4 DO structure is nested too deeply ............................................................................................... 6-2
6.1.5 ERROR Saving............................................................................................................................ 6-2
6.1.6 Failed to add variable variable_name to internal tables ............................................................. 6-2
6.1.7 fatal error - scanner input buffer overflow .................................................................................. 6-2
6.1.8 Generated object code is too large - shorten command sequence ............................................... 6-3
6.1.9 Global variable variable_name - invalid type/action .................................................................. 6-3
6.1.10 IF structure is nested too deeply .................................................................................................. 6-3
6.1.11 input buffer overflow, can't enlarge buffer because scanner uses REJECT ............................... 6-3
6.1.12 Label: label_name is not defined ................................................................................................ 6-3
6.1.13 Listing is too large ....................................................................................................................... 6-3
6.1.14 Local variable variable_name - invalid type/action .................................................................... 6-3
6.1.15 No matching DO statement ......................................................................................................... 6-3
6.1.16 No matching IF statement ........................................................................................................... 6-4
6.1.17 out of dynamic memory in yy_create_buffer() ........................................................................... 6-4
6.1.18 Parse error ................................................................................................................................... 6-4
6.1.19 Parse error, expecting symbol or symbol ..................................................................................... 6-4
6.1.20 Time: time_type is invalid ........................................................................................................... 6-4
6.1.21 Too many nested function calls ................................................................................................... 6-4
6.1.22 Variable variable_name is already defined................................................................................. 6-4
6.1.23 Variable type STRING is not supported ..................................................................................... 6-4
6.1.24 Variable: variable_name - invalid type ....................................................................................... 6-5
6.2 Non-Fatal Run-Time Error Messages ............................................................................................. 6-5
6.2.1 Timeout Messages ....................................................................................................................... 6-5
6.2.2 Error Messages ............................................................................................................................ 6-6
6.3 Fatal Run-Time Error Messages ..................................................................................................... 6-7
6.3.1 Error Message List ...................................................................................................................... 6-9
6.4 Information Messages ................................................................................................................... 6-18
6.5 TLCALC Error Messages ............................................................................................................. 6-19

7 Example 7-1

Command Sequencing Contents iv


CS-400 Command Sequencing User's Guide

1 Introduction

The Command Sequencing language is an easy to use high-level programming language that is
specifically designed to be used with Windows SCADA systems. The programming environment allows
you to define and execute programs that use database points as variables. Command sequence
programs can be used for calculations, open-loop control sequences or for closed-loop control.

The source code for a command sequence program is edited and compiled using a special command
sequence editor. A command sequence program may be started and stopped via the command
sequence editor or from poke points on WorldView maps. A command sequence may also be defined to
be activated automatically by a change of state of one or more status points.

The Command Sequence language has the following features:

• Arithmetic and Boolean operators

• Evaluation of arithmetic and Boolean expressions

• Circular, exponential and logarithmic functions

• Minimum, maximum, absolute value, modulus functions

• Current time function

• Comparison and test

• Branch forward or backward to labels

• Delay or Wait

• Capability to issue controls and setpoints

Command Sequencing Introduction 1-1


CS-400 Command Sequencing User's Guide

• Capability to raise alarms

• Virtually unlimited temporary variables per command sequence

• 5 permanent variables (preserved across restarts)

• Arrays of point names and numeric constants

• Comments

• Capability to call other command sequences as subroutines

• Templates. These are command sequencing subroutines that can be defined with both input and
output parameters. Because templates can also be referenced on CALCED, this feature allows
you to develop complex custom calculations for periodic execution.

• Two-dimensional table lookup

• Tag command

• Set analog alarm limits

• Event triggering (command sequences can be automatically triggered by status changes)

• Generate reports

Chapter 2 describes how to use the Command Sequence editor to enter and compile command
sequences, and how to operate command sequences.

Chapter 3 describes the syntax of the Command Sequencing language.

Chapter 4 describes how to create templates in Command Sequencing language, and how to use
templates in command sequences, CALCED and user-written applications.

Chapter 5 describes how to define two-dimensional lookup tables that can be used by command
sequences and templates.

Chapter 6 contains a list of compile-time and run-time messages.

Chapter 7 briefly describes an example of a command sequence application that uses multiple command
sequences, templates and lookup tables for a close-loop generation control application.

Command Sequencing Introduction 1-2


CS-400 Command Sequencing User's Guide

1.1 Other Documents


Table 1-1 contains a list of manuals that contain other information useful to your understanding of
Command Sequencing.

Table 1-1 Other Manuals

Document Number Document


DB-400 Windows SCADA Database Editing Overview
DB-401 Windows SCADA Point Database Editing Guide

The DB-400 document provides an overview of the Windows SCADA system, and describes the use of the
SCADA Explorer.

The DB-401 document describes how to define database points that may be used as variables in your
command sequence programs.

Command Sequencing Introduction 1-3


CS-400 Command Sequencing User's Guide

2 Command Sequence Editing

This chapter describes how to operate the Command Sequence editor.

2.1 Command Sequence Editor


The Command Sequence editor is accessed via the SCADA Explorer. Selecting the Command
Sequences item in the left pane of the SCADA Explorer will cause a list of existing command sequences
to be shown in the right pane (if any), as seen in Figure 2-1.

To create a new command sequence, use the New toolbar button or right click in the right pane and select
New. This will be bring up the “New Command Sequence” dialog.

To edit an existing command sequence, double click on the sequence to be edited or right click on the
sequence and select Edit. This will bring up the “Edit Command Sequence” dialog, as shown in Figure
2-2.

To delete an existing command sequence, right click on the sequence and select Delete. A dialog will
appear asking you to confirm that you wish to delete the command sequence.

Command Sequencing Command Sequence Editing 2-1


CS-400 Command Sequencing User's Guide

Figure 2-1 Command Sequences in the SCADA Explorer

Each Command Sequence dialog box defines one command sequence. The editor operation and fields
are described below.

2.1.1 Toolbar

The following icons are located on the Command Sequence Editor's toolbar

Start Sequence
This starts the execution of the current command sequence. If the sequence was changed but
not compiled, the last compiled version will be executed, not the sequence currently being
displayed.

Stop Sequence
This will stop the execution of the current command sequence.

Command Sequencing Command Sequence Editing 2-2


CS-400 Command Sequencing User's Guide

Save

This saves the edited sequence but does not compile it.

Compile
This saves the command sequence and then checks for syntax errors and compiles the command
sequence so that it can be executed. If any errors are detected, they will be listed in the Log text
box. If no errors are detected, the command sequence is now ready to be executed. Note that if the
sequence does not compile because of errors, it is still saved.

Figure 2-2 Command Sequence Editor

2.1.2 Sequence #

This is the sequence number. This is a unique number by which the sequence is operated (started and
stopped).

When a new sequence is created, this number can be changed to another valid number, before the
sequence is saved. Saving the sequence for the first time creates the command sequence record with the
indicated sequence number.

Command Sequencing Command Sequence Editing 2-3


CS-400 Command Sequencing User's Guide

A valid sequence number is any number that is not already used by a command sequence or a template
and is below the maximum number of command sequences/templates. Since sequences and templates
share the same database, a sequence and template cannot share the same number.

2.1.3 Name

This is the 32-character name of the command sequence.

This field maybe left blank. The command sequence name is not essential since a command sequence is
operated (started and stopped) by its command sequence number.

2.1.4 Description

This field contains a 64-character description of the command sequence. This field may be left blank.

2.1.5 State Point

This field contains the name of a status point. The command sequence processor maintains this point to
indicate the status of the command sequence as follows:

• The point’s status is set to 1 when the sequence is activated.


• The point’s status is set to 0 when the sequence terminates or is stopped by an operator.

The state point is optional. You can save the sequence without specifying a state point.

2.1.6 Auto Startup

Checking this field allows you to specify that the sequence is to resume execution automatically following
a system restart or failover, whether the sequence was running before the restart or failover or not.

If you clear the Auto Startup checkbox and the Restart checkbox (see below), the command sequence will
not automatically restart after a system restart or failover even if it was running immediately prior to the
system restart or failover. In this case, an operator would have to manually restart the sequence.

On an automatic restart, the command sequence starts executing at the first line of code in the sequence,
unless the command sequence had executed a SYNC command. See section 3.4.25, SYNC.

2.1.7 Restart

Checking this field allows you to specify that the sequence is to resume execution automatically following
a system restart or failover, but only if the sequence was running before the restart or failover.

If you clear both the Auto Startup checkbox (see above) and the Restart checkbox, the command
sequence will not automatically restart after a system restart or failover even if it was running immediately
prior to the system restart or failover. In this case, an operator would have to manually restart the
sequence.

On an automatic restart, the command sequence starts executing at the first line of code in the sequence,
unless the command sequence executed a SYNC command. See section 3.4.25, SYNC.

Command Sequencing Command Sequence Editing 2-4


CS-400 Command Sequencing User's Guide

2.1.8 Source

This field contains the Command Sequence program statements. The definition and syntax of the
Command Sequence program language is described in chapter 3, Command Sequence Language.

The Source Line title displays the current line number being edited, or if the command sequence is
running, the line number that is being executed.

You can right-click in the source window to access the “Print” command and The “Find” command. The
“Find” command allows you to do a test string search in of the code in this command sequence.

2.1.9 Sequence Status

This group of information boxes gives the current status of the command sequence being edited. These
information boxes cannot be edited.

Time
This displays the SCADA system’s current time and date.

Error
This field displays the most recent execution error number, if any.

State
The current running status of the command sequence is displayed here. Table 2-1 contains a list of the
possible states.

Table 2-1 Command Sequencing State Messages

State Message Description


NOT RUNNING (0) The command sequence is not running.
LOADED (1) The command sequence has been loaded, but
is not running.
RUNNING (2) The command sequence is running.
DONE NORMAL (4) The command sequence exited normally.
HALTED (5) The command sequence was halted before
execution completed.
DONE WITH ERROR (6) The command sequence exited with errors.

Command Sequencing Command Sequence Editing 2-5


CS-400 Command Sequencing User's Guide

Msg
This displays the last execution error message or Success if no error has been encountered.

2.1.10 Log

This field contains messages that indicate the results of compilation attempts and operator initiated start
and stop operations.

2.1.11 Exit

The exit pushbutton closes the command sequence editor.

2.2 Starting and Stopping a Command Sequence


A command sequence that has been successfully compiled can be started via the Start Sequence button
in the command sequence editor’s toolbar.

A sequence that is active may be stopped at any time. You can stop execution of a sequence by pressing
the Stop Sequence button in the command sequence editor’s toolbar.

Command sequences may be activated and stopped via task pushbuttons on a WorldView map. It is also
possible to define pop-up menus of command sequences to be activated. The definition and operation of
such pushbuttons and menus is described in the following:

• Paragraph 7.4.3, Task Pushbutton, in the WorldView for Windows Editor’s Guide
(Document number WV-201)

• Section 5.16, Application Control, in the WorldView for Windows Operator’s Guide
(Document number WV-200)

If you activate a command sequence that is already running but not performing a DELAY, it has no effect.
The command sequence ignores the activation request and continues to execute. See paragraph 3.4.4,
DELAY.

If you activate a command sequence that is executing a DELAY statement, the effect is to cause the
command sequence to terminate (cut short) the delay and proceed to execute the next statement after the
delay (after branching, if required).

If a task activation request occurs when a sequence is in a delay, the delay is terminated early.

The WAIT command is NOT interrupted by a start or task activation. The command sequence will be
suspended for the full duration of the WAIT command.

The act of starting or stopping a command sequence is logged on the event printers. See section 6.4,
Information Messages.

Command Sequencing Command Sequence Editing 2-6


CS-400 Command Sequencing User's Guide

2.3 Triggering By Status Change


The SCADA system supports triggering of command sequences on status changes.

You can set this up by using the Station Editor to assign the sequence number as the ALARM TASK
NAME for each status point that is to trigger the command sequence. The desired command sequence
number is identified in the point’s ALARM TASK NAME field by entering a "#" sign followed by the
sequence number (e.g. #43 to have a change in the point trigger sequence #43). See Figure 2-3 below.

Figure 2-3 Status Point That Triggers Command Sequence #43

Command sequences that are triggered by status changes do not log start/stop messages when they start
and finish.

If a command sequence is executing a DELAY statement, a status change trigger causes the command
sequence to continue execution from the delay. If the command sequence is already active but not
executing a delay, a status change trigger has no effect. See paragraph 3.4.4, DELAY.

Command Sequencing Command Sequence Editing 2-7


CS-400 Command Sequencing User's Guide

3 Command Sequence Language

This chapter describes the syntax of the Command Sequence language.

3.1 Statement Format


A command sequence may contain a virtually unlimited number of program lines. Also, a command
sequence may call other command sequences as subroutines.

Each program line may have multiple statements separated by semicolons (;).

An exclamation mark may be used at any point within the program line to indicate that the rest of the line
is a comment. If the "!" is at the front of the program line, the entire line is a comment.

An alpha-numeric label may be included at the front of a program line for purposes of branching. Only
one label per program line is allowed, and the label must be followed by a colon (:). Labels may consist of
a 32-digit name containing any combination of letters and numbers. Labels 0 and 99 are reserved for
special purposes, as described for the ONGOTO function in paragraph 3.3.3, ONGOTO.

The format of a program line that contains a label, multiple statements and a comment is:

label: statement; statement; statement ! comment

An example of such a program line is:

setvalue: $A=0; $B=1; $C=10 ! ASSIGN VALUES

Command Sequencing Templates 3-1


CS-400 Command Sequencing User's Guide

3.2 Syntax

3.2.1 Operators

The Command Sequence language contains the following operators:

parenthesis ()

logical operators .AND.


.NOT.
.OR.
.EQ.
.NE.
.GT.
.GE.
.LT.
.LE.

multiplication *

division /

addition +

subtraction -

exponential **

assignment =

3.2.2 Variables and Expressions

The data items that can be used as arguments in Command Sequencing program statements and
expressions can be numeric constants or variables. The variables supported in the Command Sequence
language are as follows:

• SCADA database points

• 52 predefined working variables $A – $Z and $AA – $ZZ that are global to the command
sequence program and its subroutines.

• Global command result variable, $RESULT

• Global error message variable, $ERRORMESSAGE

• Unlimited local working variables

• 5 predefined permanent working variables $T1 - $T5. These variables are saved to the database
each time they are changed and are available the next time the command sequence starts.

• 7 local parameter variables $P1 to $P7 for use with templates

• Arrays

Command Sequencing Templates 3-2


CS-400 Command Sequencing User's Guide

SCADA database points may be regarded as global permanent variables. Being database points, they
are common to all sequences and any changes made to their values are permanent and remain after the
sequence exits.

Each active command sequence has its own set of predefined working variables ($A – $Z and $AA –
$ZZ). These variables should be regarded as temporary in the sense that they are initialized to zero
whenever a sequence is activated, and their values are lost when the sequence exits. Note, however, that
these variables are global within each command sequence program and its subroutines. That is, any
sequences or templates called by a main sequence will use the same temporary variables as the main
sequence.

Each active command sequence also has its own set of user defined local variables. These variables can
be of type float or string. The variable must be defined with the DEFINE command. The variable name
must start with a dollar sign ($) followed by any combinations of numbers and letters. These variables
should be regarded as temporary in the sense that they are initialized to zero whenever a sequence is
activated, and their values are lost when the sequence exits. Also note, that these variables are local to
the command sequence program in which it was defined and is not accessible by any called sequences or
templates.

Examples of variable definitions are:

DEFINE FLOAT $my_var1, $MY_VAR2, $rabbits

DEFINE STRING $ErrorMsg, $CurrentState

When FLOAT variables are defined, they are initialized to 0. When STRING variables are defined they
are initialized to a null string. Variable definitions may only occur once and may not be defined inside of a
loop. STRING variables only work with the following operators: +, .NE., .EQ. and STR.

Arrays are described in paragraph 3.2.3, Arrays. Numeric arrays are arrays of floating point constants.
Point name arrays are defined as lists of SCADA point names. The values of the elements of point name
arrays are the values of the points that are referenced.

The predefined global command result variable, $RESULT, holds the result of the most recently executed
command. The ONGOTO command uses the $RESULT variable to determine which branch to take. The
$RESULT variable may also be set by a command sequence program. The valid values are as follows:

Table 3-1 Valid $RESULT Codes


Code Meaning
0 Success (SUC)
1 Failure (FAI)
2 Timeout (TMO)

The predefined global error message variable, $ERRORMESSAGE, holds the most recent timeout or
error message. $ERRORMESSAGE is of type STRING. See section, 6.2 Non-Fatal Run-Time Error
Messages, for a list of the possible error messages.

Command Sequencing Templates 3-3


CS-400 Command Sequencing User's Guide

Any variable may be assigned a value that may consist of a fixed constant, the value of another variable,
or the value of an expression based on a combination of fixed constants and variables. The format of an
assignment statement is:

variable = expression

(Note that if the variable is a database point, its value will not be updated if the point is manually set.)

Examples of assignment statements are:

$A = "STN2,POINT3" + "STN2,POINT4"

"STN3,POINT2" = $A + ("STN2,POINT2" + l0.3)**2

DEFINE STRING $ATextString

"STN2,TEXT" = 'TEXT STRING'; $ATextString = "STN2,TEXT"

The general form of an expression is:

variable operator variable …

Examples of expressions and statements using expressions are shown below:

Expression Statement

$A + 10.5 $B = $A + 10.5

($A + "AB,52RA")*5 TEST ($A + "AB,52RA")*5 .GE. 10

$A .AND. $B .AND $C TEST $A .AND. $B .AND $C .TRUE.

The following reserved words designate fixed constant values (primarily for use with status points):

Table 3-2 Keywords for Status Point Values

Keyword Value
.FALSE. 0
.OFF. 0
.OPEN. 0
.TRUE. 1
.ON. 1
.CLOSE. 1
.TRAVEL. 2
.ERROR. 3

Command Sequencing Templates 3-4


CS-400 Command Sequencing User's Guide

3.2.3 Arrays

The Command Sequence language supports two types of data arrays:

• Numeric array, where each element in the array is a numeric constant

• Point name array, where each element in the array is a point name. Any arithmetic operations
that reference elements of point name arrays will be performed using the values of the specified
points.

Arrays are local to the command sequence that created them and are not accessible by called sequences
or templates. You can give them any names you like. However, there are reserved names can be used
to define sequences that are global and can be accessed by called sequences or templates. The
predefined names that define global arrays of numeric constants are:

$GN1, $GN2, … $GN20

The predefined names that define global arrays of points are:

$GI1, $GI2, … $GI20

The arrays, both local and global, are defined via DEFINE NUMARRAY and DEFINE PIDARRAY
commands. After the array is defined, the entire array may be initialized in a single statement.

Example, for numeric arrays:

DEFINE NUMARRAY $name[size]


$name=/[multiple*]value[,value...]/

Example, for point arrays:

DEFINE PIDARRAY $name[size]


$name=/[multiple*]"point name"[,"point name" ...]/

where:

name is an alphanumeric name that uniquely identifies the array (note the required $
sign in front of the name).

[size] defines how many elements are in the array. The brackets are required.

multiple is a number that is used as a multiplier. This is used to define the same value or
point name for multiple elements in the array.

value is a numeric value (constant).

“point name” is a SCADA point name. The quotes are required.

[…] indicates that the section between the brackets is optional.

An array definition may occupy multiple lines. Conversely, more than one array can be defined on a single
line. In this case, a semicolon ";" is needed to separate arrays defined on a single line.

Command Sequencing Templates 3-5


CS-400 Command Sequencing User's Guide

Examples:

DEFINE NUMARRAY $MyTable[20]


! set elements 1-5 = 20.0, 6-10 = 40.0, 11-20 = 80.0
$MyTable = / 5 * 20.0, 5 * 40.0, 10 * 80.0 /

DEFINE PIDARRAY $GI1[4]


! set elements 1,2 = CMDTEST,ANALOG,
! 3 = CMDTEST,STATUS1, 4 = CMDTEST,STATUS2
$GI1 = / 2 * "CMDTEST,ANALOG",
"CMDTEST,STATUS1", "CMDTEST,STATUS2" /

The array elements are referenced in the command sequence by specifying the array name and the
element number. The element number is an expression that must be surrounded by square brackets.
For example:

$N2[4] references the fourth element in the array $N2

$I3[6-2+1] references the fifth element in the array $I3

The global arrays should only be defined once in the main sequence. All called sequences can access the
global arrays but may not redefine them. If a called sequence accesses an undefined array, a ‘Variable:
Name is not defined’ runtime error will be raised. If the array is redefined, the runtime error ‘Variable
$Gxx: Illegal variable redefinition’ will occur.

3.3 Control Structures


The commands that are supported by the Command Sequence language are described below. In each
command description, the “ONGOTO branches” table describes the conditions on which each of the three
ONGOTO branches are followed. See section 3.3.3, ONGOTO, for details.

3.3.1 IF/ELSE/ENDIF

The IF/ELSE/ENDIF construct allows the conditional execution of instructions based on the result of an
expression. If the expression evaluates to a non-zero value, the statements between the IF and the ELSE
are executed (or between IF and ENDIF if there is no ELSE). If the expression evaluates to a zero value,
the statements between the ELSE and the ENDIF are executed. If there is no ELSE, program control is
passed to the first statement that follows the ENDIF.

Command format:

IF (expression)
. . .
statements
. . .
ELSE
. . .
statements
. . .
ENDIF

Command Sequencing Templates 3-6


CS-400 Command Sequencing User's Guide

The ‘IF’ statement supports the following tests on data base points…

.NR. Normal
.TF. Telemetry failed (F)
.MS. Manual set (M)
.CM. Calculated from manual set (*)
.US. Setpoint Unset (U)
.BLOCKED. Point has one or more alarms blocked (B)
.INTERLOCKED. Point has controls disabled through interlock (I)
.OV. (Analog) Point is over range (V)

The ‘IF’ statement supports the following comparison operators…

.EQ. == Equal
.NE. |= Not equal
.LT. < Less then
.LE. <= Less than or equal to
.GT. > Greater than
.GE. >= Greater than or equal to

Examples:

IF ($A .EQ. 10)


!Execute multiple statements
$B = SIN($C)
ELSE
! A is not equal to ten
$B = COS($C)
ENDIF

3.3.2 DO/WHILE/ENDWHILE

The DO/WHILE/ENDWHILE construct allows you to create loops with exits based on the value of an
expression. If the expression evaluates to a non-zero value, the statements between the WHILE and the
ENDWHILE are executed. If the expression evaluates to a zero value, program control is passed to the
first statement that follows the ENDWHILE. Statements that appear between the DO and the WHILE are
always executed at least once. When execution hits the ENDWHILE, program control is passed to the
first statement that follows the DO statement.

Command format:

DO
. . .
statements
. . .
WHILE (expression)
. . .
statements
. . .
ENDWHILE

Command Sequencing Templates 3-7


CS-400 Command Sequencing User's Guide

Examples:

$A = 0
DO
! statements before WHILE are always executed at least once
$A = $A * 10
WHILE (ABS($A) < 200)
! if the ABS($A) is less than 200, execution continues here
$A = $A + 1;
! execution jumps to the first statement after the DO
ENDWHILE
! if $A is greater than 200, execution jumps to here

DO WHILE($A < 200)


! test is made before loop statements are executed
! in this example, the loop is never executed
$A = $A + 400
ENDWHILE

DO
! these statements always execute
! in this example, the loop is executed only once
$A = $A + 400
WHILE($A < 200)
ENDWHILE

3.3.3 ONGOTO

This command transfers program control based on the result of the execution of a command. When a
command is executed, the success/fail/timeout result is stored in the $RESULT variable. The ONGOTO
command checks the value of this variable and then transfers program control to the appropriate label.
Program control is transferred to the first label if the result value is success. Program control is
transferred to the second label if the result value is failure. Program control is transferred to the third label
if the result value is timeout. See Table 3-1 for the set of valid values of $RESULT.

There are 2 labels that have a special meaning. The label 0 specifies that program control should
continue on the next line. The label 99 specifies that program execution should be halted. In this case, if
the current command sequence is a subroutine, the subroutine returns to its caller.

Command format:

ONGOTO success, fail, timeout

Examples:

CMD “TEST,STA001” .CLOSE.


ONGOTO 0, DoFail, DoTimeout
CMD “TEST,STA001” .OPEN.
ONGOTO 0, DoFail, DoTimeout
ALARM 2 'Control commands are successful'
ONGOTO AllDone, AllDone, AllDone ! unconditional jump

DoFail:
ALARM 2 'Control command failed'
ONGOTO 99, 99, 99 ! EXIT program

DoTimeout:
ALARM 2 'Control command experienced a timeout'

Command Sequencing Templates 3-8


CS-400 Command Sequencing User's Guide

ONGOTO 99, 99, 99 ! EXIT program

AllDone:
! Control processing completed

3.4 Commands
The commands that are supported by the Command Sequence language are described below. In each
command description, the “ONGOTO branches” table describes the conditions on which each of the three
ONGOTO branches are followed.

Commands in Command Sequencing do not return a value, so this syntax is correct

ACKNOWLEDGE( “my,point” )

While this syntax is NOT correct

$a = ACKNOWLEDGE( “my,point” )

3.4.1 ACKNOWLEDGE
This command is used to acknowledge all alarms on a specified data base point.

Command format

ACKNOWLEDGE (“point,name”)

ONGOTO branches:

Only the SUC branch is followed after an ACKNOWLEDGE command.

3.4.2 ALARM

This command is used to raise an alarm in the SCADA system. The alarm message text may consist of
up to 40 characters enclosed in single quotes, or a string variable.

An optional priority code (0 – 4) may be specified in front of the alarm text.

An optional alarm format number can be specified after the text.

An optional point name can be specified as the fourth parameter. If a point name is specified, the alarm
will be raised against this point. If the point is not specified, then alarm will be raised against the sequence
state point. If the sequence state point has not been specified, the alarm will be raised against the point
“SYS$,SCADA”.

Command Sequencing Templates 3-9


CS-400 Command Sequencing User's Guide

Command format:

ALARM 'alarm text'

DEFINE STRING $alm


$alm = 'Abc' + 'def'
ALARM $alm

ALARM [priority] 'alarm text'

ALARM [priority] 'alarm text' format

ALARM priority 'alarm text' format "point_name"

ONGOTO branches:

Only the SUC branch is followed after an ALARM command.

Examples:

ALARM 'PUMP FAILED'

ALARM 2 'PUMP FAILED'

ALARM 3 'Pump Failed' 33

Note:
To cause an alarm from a command sequence to use remote alarm annunciation

ALARM priority 'alarm text' format

Or

ALARM priority 'alarm text' format "point_name"

And in the alarm format, add a “V” code to cause alarms that use this format to also force a certain voice
code

Command Sequencing Templates 3-10


CS-400 Command Sequencing User's Guide

In this case this, this format uses voice code 11.

ALARM 4 ‘This is my new alarm’ 15

3.4.3 CALL

The CALL command is used to execute another command sequence. After the called sequence has
completed, control is returned back to the calling sequence. Up to 10 levels of call nesting are permitted.
A command sequence will abort with an error message if the sequence attempts to call a sequence that
has not been defined.

Command format:

CALL nnn

where:

nnn is the number of the sequence being called.

ONGOTO branches:

Only the SUC branch is followed after a CALL command.

Example:

CALL 12 ! CALL SEQUENCE #12

Command Sequencing Templates 3-11


CS-400 Command Sequencing User's Guide

3.4.4 CMD

The CMD command is used to issue a device control for a controllable status point.

The command format allows you to specify an expression for the state to which the point is to be
commanded. The device will be controlled using the point’s open control address if the expression
evaluates to zero. Otherwise, the point’s close control address is used.

On a CMD command, the command sequence processor waits for the expected status change before
proceeding to the next statement. If a control is issued to a point that is already in the target state, or is
manually set or telemetry failed, or has no telemetry address, the CMD command will appear to complete
almost immediately (as soon as the checkback is received from the RTU). If you issue a series of
controls to such points on the same RTU, you may have to execute a DELAY or WAIT statement between
each control because some RTUs cannot accept a series of controls with no time delays. In such cases,
delays of 1 or 2 seconds should be sufficient. See paragraph 3.4.4, DELAY.

The CMD command will not change the state of a point without a telemetry address. To do this, use the
assignment operator.

"point name" = expression

Command format:

CMD "point name" expression

ONGOTO branches:

SUC Control operation was successful (point was controlled to the specified state).
FAI Control request failed (e.g. point is tagged or is not a controllable point).
TMO Control operation timed out (the point did not change state within the timeout).

The value of the timeout is the “device response timeout” parameter defined for the point via the
Station editor.

Examples:

CMD "STN1,POINT1" .ON.

CMD "STN1,POINT2" .OPEN.

3.4.5 COND

The COND command may be used to control the condition code (quality) of data base points.

Command format

COND "STN1,POINT1" .TF.

COND "STN1,POINT2" .NR.

The COND command sets the condition code of the database point. The first argument must be a valid
point name. The second must be a point condition code.

Command Sequencing Templates 3-12


CS-400 Command Sequencing User's Guide

Supported conditions are…

.NR. Normal
.TF. Telemetry failed (F)
.MS. Manual set (M)
.CM. Calculated from manual set (*)
.US. Setpoint Unset (U)
.OV. Overrange (V)

Codes other than these will cause the sequence to fail to compile.

ONGOTO branches:

Only the SUC branch is followed after a COND command.

3.4.6 DELAY

The DELAY command may be used to cause the command sequence to delay for a specific time interval.
The delay time may be specified as either a constant or a simple variable (e.g. a local variable or a point).

If specified as a constant, the delay time may be given in units of milliseconds (MS) seconds (S), minutes
(M), or hours (H).

If the delay time is specified as a variable, units of seconds are assumed. Note that when the delay time is
a variable, the value can include fractions of a second. See the examples section

This example will delay one-half a second or 500 milliseconds.

The delay actually executed is approximate. It may be slightly more or less time than requested.

The maximum delay time interval is greater than a year, and the minimum delay is dependent on
hardware (about 15 milliseconds on most systems).

Command format:

DELAY time[unit]

ONGOTO branches:

SUC Delay expired normally


FAI Delay cut short by the operator (by triggering the sequence)
TMO Not applicable

Examples:

DELAY 15M

DELAY "SYS$,TIME"

$B = 0.500
DELAY $B

Command Sequencing Templates 3-13


CS-400 Command Sequencing User's Guide

When a command sequence DELAY expires normally, the command sequence takes the SUC ONGOTO
branch. When an operator cuts short a command sequence DELAY by activating it during the delay, the
command sequence takes the FAI GOTO branch. You can use this to implement permissive interactions
with the operators.

Figure 3-1 shows an example of a command sequence subroutine that is called from another command
sequence called HWC. The purpose of the subroutine is to request permission from the operators to
shed load. The subroutine first raises an alarm telling the operators that the HWC command sequence
wants to shed load. It then executes a 30-second delay. To grant permission, the operator activates the
sequence from a pushbutton on the map. This causes the delay to take the FAI branch to line 3, which
sets the output variable $X to 1 to indicate that the request has been granted. To refuse the request, the
operator doesn’t have to do anything. When the delay is allowed to expire normally, the SUC branch is
followed to line 2, where $X is set to –1 to indicate that the request was not granted.

Figure 3-1 Permissive Control

3.4.7 WAIT

The WAIT command may be used to cause the command sequence to delay for a specific time interval.
The delay time may be specified as either a constant or a simple variable (e.g. a local variable or a point).

If specified as a constant, the delay time may be given in units of milliseconds (MS) seconds (S), minutes
(M), or hours (H).

Command Sequencing Templates 3-14


CS-400 Command Sequencing User's Guide

If the wait time is specified as a variable, units of seconds are assumed. Note that when the delay time is
a variable, the value can include fractions of a second. See the examples section

This example will delay one-half a second or 500 milliseconds.

The delay actually executed is approximate. It may be slightly more or less time than requested.

The maximum wait time interval is greater than a year, and the minimum delay is dependent on hardware
(about 15 milliseconds on most systems).

Command format:

WAIT time[unit]

ONGOTO branches:

SUC Wait expired normally


FAI Wait failed (time to long)
TMO Not applicable

Examples:

WAIT 15M

WAIT "SYS$,TIME"

$B = 0.500
WAIT $B

When a command sequence WAIT expires normally, the command sequence takes the SUC ONGOTO
branch.

3.4.8 EXIT

This command causes the sequence to stop executing. If the sequence was called from another
sequence (see CALL command), control is returned to the calling sequence. The calling sequence will
resume execution at the statement immediately following the CALL statement.

Command format:

EXIT

ONGOTO branches:

Since the sequence exits, there is no ONGOTO branching.

Example:

EXIT

Command Sequencing Templates 3-15


CS-400 Command Sequencing User's Guide

3.4.9 FAULTMSG
The FAULTMSG function can be used to send messages (in dialog boxes) to all WorldView windows of a
specified type.

Command format:

FAULTMSG (screen, wtype, text, mtype)

where:
screen =0
wtype = 0 for all windows, 1=alarms, 4=oprsum, 8=map
text = message text to be displayed
mtype = 0 for normal (message times out automatically)
= 1 for high priority (message remains until dismissed)

Examples:

FAULTMSG (0, 8, ‘Man the lifeboats’, 1)

3.4.10 SET

The SET command is used to issue a setpoint control to an analog output on an RTU. The argument that
represents the value of the setpoint can be an expression. (To set the value of an analog or status point,
use the assignment syntax, “point,name” = value.)

Command format:

SET "point name" expression

ONGOTO branches:

SUC The setpoint was issued successfully.


FAI The setpoint operation failed (e.g. could not communicate with the RTU).
TMO Not applicable.

Examples:

SET "STNl,SETPT" 15

SET "STNl,SETPT" "STNl,SETPT" + 10

3.4.11 OUTPUT

OUTPUT provides a more highly optimized version of the CMD and SET commands.

The OUTPUT command implements best practices for control and setpoint code automatically.

The OUTPUT command syntax is the same as the CMD and SET commands

OUTPUT acts as described below.

Command Sequencing Templates 3-16


CS-400 Command Sequencing User's Guide

For status points (discrete controls)

OUTPUT controlpoint value

1. If the control point is already in the requested state, do nothing.

2. If the control point is currently being controlled, and the SCADA system is awaiting confirmation of
the status change, do nothing. This state is seen as an S (for selected), X (for closing), or O (for
opening) near the point in WorldView.

3. If the control point is telemetry ‘failed’ (F) it is almost certain that the control will fail. Do nothing.

4. Otherwise, issue the control. In order to improve performance, do not wait for the confirming
status change.

For setpoints (analog control)

OUTPUT setpointpoint value

1. If the point is marked ‘failed’ (F), do nothing.

2. If the setpoint is marked ‘unset’ (U) issue the setpoint control operation.

3. If the setpoint value is different from the requested value, issue the setpoint control operation.

Command format:

OUTPUT "point name" expression

ONGOTO branches:

SUC Control operation was successful (The scan task acknowledged the command)
FAI Control request failed (e.g. point is tagged or is not a controllable point).
TMO Control operation timed out (the control was not acknowledged in time)

The value of the timeout is the “device response timeout” parameter defined for the point via the
Station editor.

Examples:

OUTPUT "STN1,POINT1" .ON.

OUTPUT "STN1,SETPNT" 3.14159

Command Sequencing Templates 3-17


CS-400 Command Sequencing User's Guide

3.4.12 SETLOG

The SETLOG command can be used to control logging of control and setpoint operations that a command
sequence executes. Often you will want a log of the controls and setpoint issued by command
sequences. But, in some cases, the logging from one or more sequences may be excessive. To turn
logging of control commands and setpoints off, issue this command…

SETLOG(0)

To turn logging back on…

SETLOG(1)

3.4.13 START command sequence, communications line, data exchange server


One form of the START command allows a sequence to start execution of another command sequence
by number.

The second format allows startup of command sequences by name, and adds the ability to start scan
tasks, data exchange servers and mapboard drivers.

Command format

START 14
START $a
START "cmdseq:name"
START "comlines:name"
START "deservers:name"
START "mapboards:name"

Unlike the CALL command, the specified sequence begins to run in parallel with the command sequence
that issued the START command. The started sequence may continue to run after the issuing sequence
has exited.

Only one copy of a sequence may be active at a time, so several START commands to the same
sequence will only cause one copy to run.

An event is logged if the target sequence is actually started.

A started sequence may exit at any time without any effect on the sequence that issued the START.

If a sequence tries to start itself, the start will fail.

The second format allows reference to the object to start by the table and name of the object. Note that
the name is case-sensitive.

For comlines, deservers and mapboards, the old program is automatically stopped before the new
instance is started.

ONGOTO branches:

Only the SUC branch is followed after a START command.

See section 3.4.14, STOP.

Command Sequencing Templates 3-18


CS-400 Command Sequencing User's Guide

3.4.14 STOP

The STOP command allows a command sequence to stop the execution of another command sequence.

Command format

STOP 14
STOP $a
STOP "cmdseq:name"
STOP "comlines:name"
STOP "deservers:name"
STOP "mapboards:name"

The STOP command causes a running sequence to stop at the end of the currently executing command.

An event will be logged if a sequence is actually stopped.

A sequence can stop itself.

The second format allows command sequences, scan tasks, data exchange servers and mapboard
drivers to be stopped by name.

Note that names are case sensitive.

ONGOTO branches:

Only the SUC branch is followed after a STOP command.

See section 3.4.13, START.

3.4.15 TEST

The TEST command evaluates an expression and sets the condition for ONGOTO branching according to
the result of the evaluation. The following keywords allow a sequence to test points for certain quality
codes:

.TF. (telemetry failed)


.MS. (manual set)
.US. (setpoint unset)
.OV. Overrange

Command format:

TEST expression

TEST expression [operator expression]

ONGOTO branches:

SUC The expression evaluated to TRUE (or any number other than zero), or the condition specified
by the expression is satisfied.
FAI The expression evaluated to FALSE (or zero) or the condition specified by the expression is
not satisfied.
TMO Not applicable.

Command Sequencing Templates 3-19


CS-400 Command Sequencing User's Guide

Examples:

TEST "STNl,POINTl" .ON.

TEST $A+l0-$B .GE. $C

TEST "STN2,POINT2" .LT. "STN2,POINT3"

TEST "STNl,POINTl" .TF.

In the last example above, the result is TRUE if the point "STN1,POINT1" is telemetry failed.

3.4.16 TAG

The TAG command allows a command sequence program to add and remove a tag from a status point.
Only tags that were added by a command sequence can be removed by a command sequence.

The point parameter can be specified either as a point name or an index into an array of point names.

The tag that’s applied by a command sequence is the highest-level owner tag that constitutes a full tag
(inhibits all control). The command sequence provides the following text in the associated tag comment
field:

"TAGGED FROM COMMAND SEQUENCE nnn"

where "nnn" is the command sequence number.

Any number of tags may be placed on a point from command sequencing, up to a maximum of eight. This
limit includes tags that are applied both by operators and by command sequences.

On an untag operation, the command sequence removes one command sequence-applied tag. A
command sequence tag is any tag with the special comment text identified above.

Tag/untag operations fail if the command sequence attempts to:

• Tag a point that is currently involved in a control

• Tag or untag a point whose tags are currently being edited by an operator

• Untag a point that has no command sequence tags

Command format:

TAG point n

where:

point = point to be tagged or untagged

n = tag command code


1 = tag
0 = untag

Command Sequencing Templates 3-20


CS-400 Command Sequencing User's Guide

ONGOTO branches:

SUC The tag/untag operation was successful.


FAI The tag/untag operation failed.
TMO Not applicable.

Examples:

TAG "STN1,PNT5" 1
TAG ("STN1,PNT5", 1)

applies a tag to point "STNl,PNT5"

TAG $I1[2] 0
TAG ($I1[2, 0)

removes a tag from the second point in array $I1

3.4.17 SET_INTERLOCK

The SET_INTERLOCK command allows a command sequence program to add and remove a interlock
from a status or analog point.

The point parameter can be specified either as a point name or an index into an array of point names.

Command format:

SET_INTERLOCK point n

SET_INTERLOCK (point, n)

where:

point = point to be modified

n = interlock command code


1 = interlock
0 = remove interlock

ONGOTO branches:

SUC The interlock operation was successful.


FAI The interlock operation failed.
TMO Not applicable.

Command Sequencing Templates 3-21


CS-400 Command Sequencing User's Guide

Examples:

Set interlock on a point…

SET_INTERLOCK("STN1,PNT5",1)

Clear interlock on a point…

SET_INTERLOCK("STN1,PNT5",0)

3.4.18 LS

The LS command causes a load shed command to be transmitted (via an RTU) to a load control receiver
(LCR). The address of the LCR and the desired command are specified by parameters that are listed in
round brackets.

Command format:

LS(“rtu”,lcr,a,b,c,d,e,f,g,h,i)

where:

rtu = name of RTU’s status point


lcr = LCR device type
a – i = LCR type dependent arguments

The RTU’s status point is the status point that represents the RTU’s up/down status. Of the arguments
“a” – “i”, only "a" is mandatory.

The arguments "a" to "e" correspond exactly to address fields "A" to "E" on the Control Set editor of the
VMS Load Management subsystem. See the Load Management User’s Guide (document number LM-
804).

Arguments "f' to "i" are used to implement special features of the REMS 101/102 switches using the FS
(frequency synthesizer) protocol.

Unused arguments need not be entered, but all commas preceding any argument must be present, as in:

LS(“LM,RTU1”,2,2,l,,,6)

ONGOTO branches:

SUC The load shed command was successfully issued to the RTU.
FAI The load shed command was not successfully issued to the RTU.
TMO The load shed command was issued to the RTU but the RTU did not reply.

Command Sequencing Templates 3-22


CS-400 Command Sequencing User's Guide

Example:

LS(“LM,RTU2”,l,71)

This statement sends a load shed command to the RTU whose status point is named “LM,RTU2” to shed
loads at block address 71 of AS&E load control receivers.

• The valid LCR device type codes are listed in Table 3-3.

• The meanings of LS arguments ”a” – “i” for each LCR type are summarized in Table 3-4 to Table
3-15.

Table 3-3 LCR Device Type Codes


Type Code Device
0 REMS 100/101/102 (P protocol)
1 AS&E
2 Westinghouse
3 QEI DLC-2020 (Not currently supported)
4 Simulated protocol FS (Frequency Synthesizer)
5 REMS 100 FS (Frequency Synthesizer)
6 REMS 101/102 FS (Frequency Synthesizer)
7 RCCA (Scientific Atlanta)
8 RTC 1032 (Comverge)
9 MultiSpeak

Table 3-4 LS Arguments for REMS 100/101/102 (P protocol) LCR


Field Device
a block address
b transmitter control
c unused
d shed time (0 for REMS 100)
e function code
f unused
g unused
h unused
i unused

Command Sequencing Templates 3-23


CS-400 Command Sequencing User's Guide

Table 3-5 LS Arguments for AS & E LCR


Field Device
a block address
b unused
c unused
d unused
e unused
f unused
g unused
h unused
i unused

Table 3-6 LS Arguments for Westinghouse LCR


Field Device
a block address
b fixed repeater address
c variable repeater address
d shed time code
e function code
f unused
g unused
h unused
i unused

Table 3-7 LS Arguments for QEI DLC-2020 (Not currently supported) LCR
Field Device
a start address
b end address
c random time-out
d base time multiplier
e load classes
f unused
g unused
h unused
i unused

Command Sequencing Templates 3-24


CS-400 Command Sequencing User's Guide

Table 3-8 LS Arguments for Simulated Protocol LCR


Field Device
a sequence number (LDMRTS record 4)
b transmitter control
c transmitter keying delay
d unused
e unused
f unused
g unused
h unused
i unused

Table 3-9 LS Arguments for REMS 100 (FS protocol) LCR


Field Device
a block address
b transmitter control
c random time-out
d unused
e function code
f unused
g unused
h unused
i unused

Table 3-10 LS Arguments for REMS 101/102 (FS protocol) LCR


Field Device
a block address
b transmitter control
c transmitter delay
d shed time
e function code
f function delay
g cycle time
h cycle count
i random time-out

Command Sequencing Templates 3-25


CS-400 Command Sequencing User's Guide

Table 3-11 LS Arguments for RCCA (Scientific Atlanta) LCR


Field Device
a mark tone select code (0 to 63)
b digital message flag (0 to 1)
b=0 tone burst
b=1 digital message
c digital message address (0 to 31)
ignored if b=0
d digital message control code (0 to 7)
ignored if b=0
e unused
f unused
g unused
h unused
i unused

Table 3-12 LS Arguments for RTC 1032 (Comverge) Load Control


Field Device
a Message type dependent argument
b Message type dependent argument
c Message type dependent argument
d Message type dependent argument
e Message type and response required flag
f unused
g unused
h unused
i unused

In the RTC1032 load control command, the “e” parameter is composed of the sub-elements listed in Table
3-13 below:

Table 3-13 Composition of E Address for RTC 1032


Sub-element Meaning
Units and tens digits Message type (0 to 15), see Table 3-14
Hundreds digit Response required flag
1 = response required
0 = response not required

Command Sequencing Templates 3-26


CS-400 Command Sequencing User's Guide

The valid LCR message types that are presently supported are listed in Table 3-14 below.

Table 3-14 Supported Message Types for RTC 1032


Type Code Message Type
0 SA Digital
1 GE 18-bit
2 GE 40-bit
3 Motorola dual 23-bit Golay
4 Regency 9-bit
5 Motorola single tone
6 Motorola two tone sequential
7 Fischer Pierce two tone sequential

For example, e = 107 means message type 7, response required.

The meaning of the a:b:c:d fields depends on the message type that is specified by e. These are
described in the following document:

• RTC 1032 Scan Task User’s Guide

• Document number TL-403

Table 3-15 LS Arguments for MultiSpeak


Field Device
a Message type (only one type is presently supported, = 1)
b Group number
This parameter is loaded into the “groupName” field of the MultiSpeak load shed
message. It represents an address group number.
c Duration
This parameter is loaded into the “duration” field of the MultiSpeak load shed
message. It represents the overall duration of the load shed sequence.
d Cycle time
This parameter is loaded into the “cycleTime” field of the MultiSpeak load shed
message. It represents the length of each cycle of the load shed sequence.
e Duty cycle
This parameter is loaded into the “percentDutyCycle” field of the MultiSpeak load
shed message. It represents the duty cycle (percent shed vs percent restored) of
each cycle of the load shed sequence. It must be a value between 0 and 100. (If
it’s not, the message is not sent.)
f unused
g unused
h unused
i unused

Note: For a MultiSpeak LS command, the “rtu” status point parameter is not used but is still required
(otherwise the command sequence will not compile).

Command Sequencing Templates 3-27


CS-400 Command Sequencing User's Guide

It can be any status point. See section 3.4.19 LSM for a description of an alternative, more convenient,
MultiSpeak-specific load shed command.

See the following document for more details on load shedding via a MultiSpeak interface:

• MultiSpeak Installation and Editing Guide

• Document number MS-400

3.4.19 LSM

The LSM command causes a load shed request to be transmitted to a load management system
MultiSpeak interface. Because no dummy status point or LCR code is required, it’s a slightly more
convenient function to use for MultiSpeak than the LS function described in the previous section.

Command format:

LSM (a, b, c, d, e)

where:

a = message type
b = group number
c = duration
d = cycle time
e = duty cycle

ONGOTO branches:

SUC The load shed command was successfully issued to the MultiSpeak interface.
FAI The load shed command was not successfully issued to the MultiSpeak interface.
TMO Not used.

The meaning of parameters a to “e” are the same as for the LS command. See Table 3-15.

See the following document for more details on load shedding via a MultiSpeak interface:

• MultiSpeak Installation and Editing Guide

• Document number MS-400

Command Sequencing Templates 3-28


CS-400 Command Sequencing User's Guide

3.4.20 LIMIT

The LIMIT command allows a command sequence to modify analog alarm limits.

Command format:

LIMIT(point,n,lim1,n2,lim2...)

where:

point = point name (in quotes) or an entry from an array of point names

n1,n2… = limit number


1 - upper pre-emergency
2 - lower pre-emergency
3 - pre-emergency deadband
4 - upper emergency
5 - lower emergency
6 - emergency deadband
7 - upper reasonability
8 - lower reasonability
9 - reasonability deadband

lim1,lim2... = corresponding limit values

Any combination of limit values may updated.

ONGOTO branches:

SUC The limit command was successful.


FAI The limit command was not successful.
TMO Not applicable.

Requests to set limits may be unsuccessful for any of the following reasons:

• the number of parameters is even


• the point is not an analog point
• the updated limit values do not produce a properly nested set of limits
• a deadband exceeds half the difference between its upper and lower limit values

Examples:

LIMIT("STN1,PNT3",4,150)

sets the upper emergency limit for point "STN1,PNT3" to 150

$U = $B + .5*"SYS$TEMP"
$L = $C - .5*"SYS$TEMP"
LIMIT($I3[$J],1,$U,2,$L)

sets the upper and lower pre-emergency limits for a point in array $I3 to values computed using a simple
formula based on current temperature.

Command Sequencing Templates 3-29


CS-400 Command Sequencing User's Guide

3.4.21 BLOCK

The BLOCK command allows a command sequence to block all alarms on a point. One use of this
function is to automate the blocking of door alarms during normal working hours. The inverse of this
command is UNBLOCK, which removes the “all alarms blocked” status from the point (see next section).

Both block and unblock operations are logged on the event printer(s).

Command format:

BLOCK point

where:

point = point name (in quotes) or an entry from an array of point names

ONGOTO branches:

SUC The BLOCK command was successful.


FAI Not applicable.
TMO Not applicable.

This command always returns a success. An attempt to block all alarms on a point that already has all its
alarms blocked is not considered an error. Similarly, an attempt to unblock alarms on a point that does
not have its alarms blocked is also not considered an error.
Examples:

BLOCK "STN1,PNT3"

Blocks all alarms on point "STN1,PNT3"

Note: The BLOCK command may also be called as a function, as in:

BLOCK(“STN1,PNT3”)

3.4.22 UNBLOCK

The UNBLOCK command allows a command sequence to remove an “all alarms blocked” condition from
a point. It does not unblock specific alarms that were blocked via the alarm display.

Both block and unblock operations are logged on the event printer(s).

Command format:

UNBLOCK point

where:

point = point name (in quotes) or an entry from an array of point names

Command Sequencing Templates 3-30


CS-400 Command Sequencing User's Guide

ONGOTO branches:

SUC The UNBLOCK command was successful.


FAI Not applicable.
TMO Not applicable.

This command always returns a success. An attempt to unblock alarms on a point that does not have all
of its alarms blocked is not considered an error.

Examples:

UNBLOCK "STN1,PNT3"

Removes “all alarms blocked” from point "STN1,PNT3"

Note: The UNBLOCK command may also be called as a function, as in:

UNBLOCK(“STN1,PNT3”)

3.4.23 EVENTDATA

The EVENTDATA command allows a command sequence to record the value of an analog or status point
in the event data recording file. The timestamp that is recorded is the current time.

Command format:

EVENTDATA point

where:

point = point name (in quotes) or an entry from an array of point names

ONGOTO branches:

SUC The EVENTDATA command was successful.


FAI The EVENTDATA command failed (possibly because Event Data Recording is not
licensed.
TMO Not applicable.

Examples:

EVENTDATA "STN1,KW"

Records event data for point "STN1,KW"

Note: The EVENTDATA command may also be called as a function, as in:

EVENTDATA("STN1,KW")

Command Sequencing Templates 3-31


CS-400 Command Sequencing User's Guide

3.4.24 GETTIME

This command does not require any parameters. When called without parameters, it gets the current
system time and loads the time units into variables listed in the table below. Previous values of these
variables are over-written, so don’t use them for other purposes in this sequence if you’re using the
GETTIME function.

Variable Time Unit


$YY Year
$MM Month
$DD Day
$HH Hour
$NN Minute

If an argument is supplied, it is decoded into the time variables, assuming that it is a double-precision
FILETIME as is returned by some DATA functions.

Used as a function, GETTIME returns the time as a string in the format “yyyy-mm-dd hh:mm:ss.mmm”.

Command format:

GETTIME
Example1:

GETTIME
! gets the current time into the usual time variables

Example2:

gettime( $a )
! gets the input time into the usual time variables. ($YY, $MM, $DD, $HH, $NN, $SS)

Example3:

Define string $time


$time = gettime( $a )
! Returns the time as ‘yyyy-mm-dd hh:mm:ss.mmm’ into the string variable

ONGOTO branches:

SUC The GETTIME command was successful.


FAI Not applicable.
TMO Not applicable.

Command Sequencing Templates 3-32


CS-400 Command Sequencing User's Guide

3.4.25 SYNC

The SYNC command allows you to tell the command sequence to record, on disk, its current position in
the sequence and the current values of the variables $A to $ZZ. If a command sequence is running and
has the Restart checkbox checked, and a system failover or restart occurs after one or more SYNC
commands have been executed, the command sequence will restart on the backup computer at the
statement following the most recent SYNC command.

The SYNC command does not require any parameters and can only be used in a primary sequence. In a
secondary sequence (i.e. a sequence called from another sequence), any SYNC commands are ignored.

Much use of SYNC commands can adversely affect system performance because of the additional disk
accesses involved. Exercise caution when using this feature.

Command format:

SYNC

Example:

SYNC

ONGOTO branches:

A SYNC statement does not affect a program line’s GOTO branching. The GOTO branching is based on
the result of the program line’s last non-SYNC statement. If the program line contains just a SYNC
statement, there is no GOTO branching.

3.4.26 POLL

The POLL command allows you to force polling of a point.

The command sends an ‘activate’ command to TSTAT for the named point.

The result of the ‘activate’ is usually an immediate all-date poll. The behavior may differ for different
protocols.

It the point is marked “M” for manual set, the “M” will be removed. The “M” will be replaced with an “F”,
which in turn may be replaced with the blank or normal condition code (if the poll succeeds).

Command format:

POLL “pointname”

ONGOTO Branches:

A POLL statement fails only if the attempt to send the activate to TSTAT fails.

Command Sequencing Templates 3-33


CS-400 Command Sequencing User's Guide

3.4.27 METER commands

The METER commands allow a meter to be PINGed, CONNECTED and DISCONENCTED

The commands are described below.

METER ( DISCONNECT, ‘meter_name’ )

Note: The meter name is a string. Constant strings are surrounded in single quotes.

This command sends a command to disconnect the named meter to the meter executive. If the meter
name cannot be found, an alarm is raised, and the command fails.

METER ( CONNECT, ‘meter_name’ )

This command sends a command to connect the named meter to the meter executive. If the meter name
cannot be found, an alarm is raised, and the command fails.

METER ( PING, ‘meter_name1’ )

This command sends a METER PING command to the named meter. If the meter name cannot be found,
an alarm is raised, and the command fails.

METER ( PING, ‘meter_name1;metername2’ )

This form of the METER PING command sends a METER PING command to the all of the named
meters. If there is more than one meter name, separate them with semicolons. If one or more meter
names cannot be found, an alarm is raised. If no meter name can be found, the command fails.

See the METERSTATUS function.

3.4.28 StartReport

The StartReport command can be used to trigger the generation of a report. The command uses the
name of a Report Schedule entry (not the name of a report). The Report Schedule includes all of the
information required to generate a report and send it to the destination.

The report can be sent to a printer, email address, ftp destination or any other destination supported by
the report system.

The command syntax is

StartReport (‘ReportScheduleName’)

The name in single quotes is the name of the report schedule entry. Case does not matter.

The StartReport command does not return a value but will set $RESULT to 0 on success and a non-zero
value on failure. The most likely cause of failure is that the named report schedule entry does not exist.

Command Sequencing Templates 3-34


CS-400 Command Sequencing User's Guide

3.4.29 Status with timestamp processing (GetStatus, SetStatus)

By default, when command sequencing sets the value of a status point, the current time is used as the
timestamp for the value change. This default behavior is reasonable for most cases.

However, sometimes it may be useful to read the timestamp from one or more status points and then use
the most recent timestamp as the timestamp of a calculated value change in another status point.

The following three routines allow this.

The routines are:

• ResetStatus ()

• $a = GetStatus (‘point, name”)

• SetStatus (“point, name”, value)

• Reset Status is a function that resets (sets to zero) the saved timestamp and should be used
before a calculation sequence for a new status change.

• GetStatus (“point, name”) is a function reads the point value of a status point and returns it to the
caller. It also reads the timestamp of the status point and saves it in special internal storage, if,
and only if, the timestamp is more recent than the saved timestamp.

• SetStatus (“point, name”, value) is a command that updates the value of the status point (if it is
different from the current state) and sets the timestamp of the value change to the saved
timestamp

Example:

This code fragment reset the sored time, then checks each of three status points. If any are in a non-zero
state, the ‘master’ point is set to one. Otherwise the ‘master’ point is set to zero. The timestamp used will
be the most recent timestamp of all the points read by GetStatus.

ResetStatus ()

if ( GetStatus("__ALARM__,M1") .or. GetStatus("__ALARM__,M2") .or. GetStatus("__ALARM__,M3" ) )


SetStatus("__ALARM__,Master", 1)
else
SetStatus("__ALARM__,Master", 0)
endif

Command Sequencing Templates 3-35


CS-400 Command Sequencing User's Guide

3.5 Functions
The functions that are supported by the Command Sequence language are described below.

Functions in Command Sequencing always return a value, so this syntax is correct

$a = ABS (“my, point”)

While this syntax is NOT correct

ABS (“my, point”)

3.5.1 Arithmetic Functions

ABS This function takes one parameter and returns the absolute value.

Format: result = ABS(expression)

Example: $A = ABS($B)

SQRT This function takes one parameter and returns the square root.

Format: result = SQRT(expression)

Example: $A = SQRT($B + $C)

MAX These functions take a list of up to 8 parameters (which may be expressions) and return
MIN the maximum or minimum.

Format: result = MAX(expression1 ,expression2,...)


result = MIN(expression1 ,expression2,...)

Examples: $A = MAX($B,$C,$D+$E,$F)

$A = MIN($B,$C,$D+$E,$F)

MOD This function takes two parameters and returns the modulus of the first parameter with
respect to the second parameter. The result is truncated to an integer value.

Format: result = MOD(expression,expression)

Example: $A = MOD($B,$C)

INT This function takes one parameter and returns the integer part of this parameter.

Format: result = INT(expression)

Example: $A = INT($B)

Command Sequencing Templates 3-36


CS-400 Command Sequencing User's Guide

BITAND This function returns the bitwise AND of two parameters. Arguments and results are
truncated to integers.

Format: result = BITAND(expression,expression)

Example: $A = BITAND($B,1)

BITOR This function returns the bitwise OR of two parameters. Arguments and results are
truncated to integers.

Format: result = BITOR(expression,expression)

Example: $A = BITOR($B,1)

BITXOR This function returns the bitwise XOR (exclusive or) of two parameters. Arguments and
results are truncated to integers.

Format: result = BITXOR(expression,expression)

Example: $A = BITXOR($B,1)

3.5.2 Logarithmic/Exponential Functions

LOG This function takes one parameter and returns the logarithm (base 10).

Format: result = LOG(expression)

Example: $A = LOG($B)

LN This function takes one parameter and returns the natural logarithm (base e).

Format: result = LN(expression)

Example: $A = LN($B)

EXP This function takes one parameter and returns the natural antilog (base e).

Format: result = EXP(expression)

Example: $A = EXP($B)

3.5.3 Trigonometric Functions

SIN This function takes one parameter (in radians) and returns the sine.

Format: result = SIN(expression)

Example: $A = SIN($B)

Command Sequencing Templates 3-37


CS-400 Command Sequencing User's Guide

COS This function takes one parameter (in radians) and returns the cosine.

Format: result = COS(expression)

Example: $A = COS($E)

TAN This function takes one parameter (in radians) and returns the tangent.

Format: result = TAN(expression)

Example: $A = TAN($B)

ASIN This function takes one parameter and returns the arc sine (in radians).

Format: result = ASIN(expression)

Example: $A = ASIN($B)

ACOS This function takes one parameter and returns the arc cosine (in radians).

Format: result = ACOS(expression)

Example: $A = ACOS($B)

ATAN This function takes one parameter and returns the arctangent (in radians).

Format: result = ATAN(expression)

Example: $A = ATAN($B)

3.5.4 String Functions

+ This function takes the left and right parameters and returns a concatenated string.

Format: combined_string = first_part + second_part

Example: $message = ‘Problem encountered: ’ + $errstr

.EQ. This function compares the left and right parameters for equality and returns a TRUE
value (non-zero) if the strings match exactly. The string comparison is case sensitive.

Format: string_1 .EQ. string_2

Example: IF ($LastError .EQ. $CurrentError)

Command Sequencing Templates 3-38


CS-400 Command Sequencing User's Guide

.NE. This function compares the left and right parameters for inequality and returns a TRUE
value (non-zero) if the strings do not match exactly. The string comparison is case
sensitive.

Format: string_1 .NE. string_2

Example: WHILE ($LastError .NE. ‘OK’)

STR This function takes a numeric value and returns a string representation of the value.

Format: string = STR(expression)

Example: $message = ‘Executing step: ’ + STR($Step)

POINTNAME This function takes a point id and returns the point name.
It is most useful in getting the name of a point that is an entry in a point array.

Format: string = POINTNAME ( $id[i] )

Example: $message = 'Error on ' + POINTNAME( $id[i] )

3.5.5 Time Functions (TIME and DNPTIME)

TIME This function takes a text string parameter and returns a corresponding unit of the current
date and time. The single quotes are mandatory.

Format: result = TIME ('item')

where item is one of the following items listed below.

Item Short Form Returns


YEAR Current year
MONTH Current month of year
DAY Current day of month
HOUR Current hour of day
MINUTE MIN Current minute of hour
SECOND SEC Current second of minute
MILLISECOND Current millisecond of second
DAYOFWEEK DOW Current day of week (0=Sunday)

Example: $A = TIME('HOUR')

Note that MIN and SEC are allowed short forms for MINUTE and SECOND.

Command Sequencing Templates 3-39


CS-400 Command Sequencing User's Guide

DNPTIME This function takes three unsigned 16-bit numbers and returns a string containing the
corresponding date and time. The three 16-bit values, when concatenated, represent a
48-bit timestamp such as is transmitted in the DNP protocol.

Format:
result = DNPTIME (high, middle, low)

The high, middle, low parameters can be variables or analog points. The time-string
parameter can be a variable or a text point.

Example:
$A = "Relay,HighTime"
$B = "Relay,MiddleTime"
$C = "Relay,LowTime"
"Relay,TimeStamp" = DNPTIME($A,$B,$C)
(Relay,TimeStamp is a text point)

3.5.6 Template Function (TPLATE)

TPLATE This function performs a call to a template. For details on templates, see chapter 4,
Templates, and in particular, section 4.5, Using Templates in Command Sequences.

Format: result = TPLATE(func,P1,P2,P3,P4,P5,P6,P7)

where: func = template function number (50 – 99)


P1…P7 = function parameters

Example: $C = TPLATE(52, 0, $A, $B+$C)

3.5.7 Table Lookup Function (LOOKUP)

LOOKUP This function takes a matrix number and a pair of X,Y coordinates, performs a table
lookup, and returns the value of the element in the matrix specified by the given
coordinates. If the coordinates do not exactly specify a matrix element, then a two-
dimensional interpolation is performed based on three nearest neighbors. See chapter
5, Table Lookup.

The X and Y coordinates supplied to the LOOKUP function must be within the limits of the
matrix, or the function will fail and abort the sequence. See section 5.3, Lookup Function.
If the coordinate values are calculated, your sequence should range-check them before
passing them to the Lookup function.

Format: result = LOOKUP(n,x,y)

where: n = matrix number


x = horizontal coordinate
y = vertical coordinate

Example: $A = LOOKUP(5, "SYS$,WIND","SYS$,TEMP")

Command Sequencing Templates 3-40


CS-400 Command Sequencing User's Guide

3.5.8 Maximum Sample Value (MAXV)

This function obtains the maximum value of a group of samples of a particular point in a
historical dataset.

Function call:

result = HLIB\MAXV(ds,pn,qual,nsam)

where:

ds = dataset name in the form "HISTDATASETS:dsname" or the data set


number
pn = point name in dataset
qual = historical data qualifier, one of …
VALUE MIN MAX MIN TMAX SUM
MAXA MINA TMAXA TMINA
nsam = number of samples

Function results:

result = maximum value of the most recent "nsam" samples of point name
"pn" with qualifier “qual” in dataset "ds".

3.5.9 Minimum Sample Value (MINV)

This function obtains the minimum value of a group of samples of a particular point in a
historical dataset.

MINV

result = HLIB\MINV(ds,pn,qual,nsam)

where:

ds = dataset name in the form "HISTDATASETS:dsname" or the data set number


pn = point name in dataset
qual = historical data qualifier, one of …
VALUE MIN MAX MIN TMAX SUM
MAXA MINA TMAXA TMINA
nsam = number of samples

Function results:

result = minimum value of the most recent "nsam" samples of point name "pn" with qualifier
“qual” in dataset "ds".

Command Sequencing Templates 3-41


CS-400 Command Sequencing User's Guide

3.5.10 Average Sample Value (AVG)

This function obtains the average value of a group of samples of a particular point in a historical dataset.

Function call:

result = HLIB\AVG(ds,pn,qual,nsam)

where:

ds = dataset name in the form "HISTDATASETS:dsname" or the data set number


pn = point name in dataset
qual = historical data qualifier, one of …
VALUE MIN MAX MIN TMAX SUM
MAXA MINA TMAXA TMINA
nsam = number of samples

Function results:

result = average value of the most recent "nsam" samples of point name "pn" with qual
“qualifier” in dataset "ds"

3.5.11 Get Sample (Sample)

This function obtains the value of a particular point in a particular sample in a historical dataset.

Function call:

result = HLIB\SAMPLE(ds,pn,qual,nsam)

where:

ds = dataset name in the form "HISTDATASETS:dsname" or the data set number


pn = point name in dataset
qual = historical data qualifier, one of …
VALUE MIN MAX MIN TMAX SUM
MAXA MINA TMAXA TMINA
nsam = number of samples back from the most recent. A value of 0 will read the most recent
sample value

Function results:

result = the value of the point whose name is "pn" with qual “qualifier”, nsam back from the
most recent sample in dataset "ds".

Command Sequencing Templates 3-42


CS-400 Command Sequencing User's Guide

3.5.12 Forecast Function (FCAST)

FCAST This function goes to a specified point in a dataset, and computes a prediction of the
point’s value for m sample times ahead. The prediction is performed by extrapolation of a
best-fitting curve that is passed through the last n samples. The function supports linear,
quadratic and cubic curve fitting.

Format:

result = HLIB\FCAST("HISTDATASETS:dsname","pname",n,type,m)
result = HLIB\FCAST("HISTDATASETS:dsname","pname",qual,n,type,m)

where: dsname = name of dataset


pname = point name
qual = historical data qualifier, one of …
VALUE MIN MAX MIN TMAX SUM
MAXA MINA TMAXA TMINA
n = number of historical samples on which to base the curve-fit
type = type of curve-fit (see Table 3-16)
m = number of sample times ahead to predict the value

The function returns the forecasted value for m sample times ahead based on the last n
samples of point pname in the dataset named dsname, using the type of curve-fit
specified by type:

If the qualifier is not specified, “VALUE”, the instantaneous value, is assumed.

Table 3-16 Types of Curve Fit


Type Curve-Fit Minimum Value of n
1 Linear 2
2 Quadratic 3
3 Cubic 4

(Note: Both the dataset and point name specifications must be enclosed in double
quotes.)

Example:

$A = FCAST("HISTDATASETS:SystemLoad","SYS$,LOAD",6,3,4)

In this example, a load is being predicted for 4 sample times ahead based on fitting a
cubic curve through the last 6 historical samples. This function can be used to produce a
supervisory command sequence that triggers load shedding when the immediate-term
forecast (e.g. 15 minutes) of the load exceeds a threshold.

Command Sequencing Templates 3-43


CS-400 Command Sequencing User's Guide

3.5.13 Average of Maximums (AVGMAX)

AVGMAX This function goes to a specified point in a dataset, obtains the last n samples, takes the
m largest values from this set and returns the average of these maximums.

Format:

result = HLIB\AVGMAX("HISTDATASETS:dsname","pname",n,m)
result = HLIB\AVGMAX("HISTDATASETS:dsname","pname",qualifier,n,m)

where: dsname = name of dataset


pname = point name
n = number of historical samples from which to find the maximums
m = number of maximums to average
qualifier = historical data qualifier, one of …
VALUE MIN MAX MIN TMAX SUM
MAXA MINA TMAXA TMINA

The function returns the average of the maximum m values of the last n samples of point
pname in the dataset named dsname.

If the qualifier is not specified, “VALUE”, the instantaneous value, is assumed.

Example:

$A = HLIB\AVGMAX("HISTDATASETS:DailyPeaks","SYS$,LOAD",7,4)

In this example, the dataset contains samples of daily peaks, and the function returns the
average of the largest 4 values from the last week (7 days).

$A = HLIB\AVGMAX("HISTDATASETS:DailyPeaks",MAX,"SYS$,LOAD",7,4)

In this example, the dataset contains samples of daily peaks, and the function returns the
average of the largest 4 maximums from the last week (7 days).

This can be used to initialize a threshold at the beginning of a new month to be the
average of the maximum four of the last seven daily peaks. The purpose of using the
maximum 4 out of the last 7 daily peaks is to base the new threshold on what happened
during the last week of the previous month, excluding Saturday, Sunday and a possible
holiday. To provide a safety margin, the command sequence could multiply the resulting
initial threshold by something like 0.9.

Command Sequencing Templates 3-44


CS-400 Command Sequencing User's Guide

3.5.14 Random Value (RANDOM)

RANDOM This function generates a pseudo-random value from a uniformly distributed range.

Format:

result = RANDOM(min, max)

where: min = minimum of range


max = maximum of range

Example:

$A = RANDOM(0.0,1.0)

In this example, the function returns a random value in the range 0.0 to 1.0.

3.5.15 Free Space on Disk (DISKSPACE)

DISKSPACE This function returns the number of bytes free on the specified disk volume.

Format:

result = DISKSPACE( drivename )

Example:

"SYS$,FREESPACE" = DISKSPACE('C:')

In this example, the function returns the number of bytes free on the “C:” disk drive.

3.5.16 Point Functions

3.5.16.1 UNACKEDALARMS

This function returns the number of unacknowledged alarms on the specified point

Format:

Result = UNACKEDALARMS( pointname )

Example:

$A = UNACKEDALARMS("sys$,mypoint" )

3.5.16.2 STATIONSINMAINT

The StationsInMaint function returns the number of stations that have the “Maintenance” flag set.

If no stations are in maintenance mode, the function will return 0;

Command Sequencing Templates 3-45


CS-400 Command Sequencing User's Guide

Example:

If ( StationsInMaint() )
ALARM ‘At least one station in maintenance mode’
Endif

3.5.16.3 ISBLOCKED

This function returns FALSE (0) or TRUE (1) depending on whether the specified point has any or all
alarms blocked.

Format:

Result = ISBLOCKED( pointname )

Example:

$A = ISBLOCKED("RELAY,HIGHTIME" )

3.5.16.4 TAGLEVEL

This function returns a small number indicating the level of the most restrictive tag on a point.

If the point is not tagged, a 0 is returned. If a ‘full’ tag (no open and no close) a 1 is returned.

If there is an ‘informational’ tag on a point a 4 is returned.

$a = TAGLEVEL( “xxxx,yyyyyy” )

Command Sequencing Templates 3-46


CS-400 Command Sequencing User's Guide

3.5.17 Get Meter Status (METERSTATUS)

METERSTATUS

This function returns the status of a meter. It is assumed that the meter was previously PINGed with the
METER PING command.

The function watches the meter point while the PING timer is active. When the timer expires, the function
returns the status of the meter to the calling command sequence as the return value

Format:

$a = METERSTATUS ( ‘meter_name’ )

If the meter name cannot be found the function fails and the return value is 0. If the meter responds within
the time interval, the return from the function can be as follows:

Table 3-17 Meter Status Codes

Value Symbol
0 METER_STATUS_UNKNOWN
1 METER_STATUS_WITH_POWER
2 METER_STATUS_WITHOUT_POWER
3 METER_STATUS_COMM_FAIL

3.5.18 Is a Windows Task Currently Active (TASKRUNNING)

TASKRUNNING

This function returns FALSE (0) if the named Windows task (process) is not running. If the task is running,
a non-zero number is returned. This number is the number of matching tasks currently running.

Format:

Result = TASKRUNNING( ‘image_name’ )

The argument is the name of the process primary image file. The argument can be a literal string
‘xxx.exe’ or a string variable. The image name should include the extension (usually ‘.exe’). The name is
not case sensitive.

Example:

If ( TASKRUNNING( ‘SCS.EXE’ ) == 0 )
ALARM ‘SCS has exited’
endif

Command Sequencing Templates 3-47


CS-400 Command Sequencing User's Guide

3.5.19 Data function

The DATA function returns data about points. The function allows access to a one of a large number of
current and historical data about an individual point. It follows the syntax of other data-returning functions.

pointname = DATA( pointname, dataitem )


variable = DATA( “pointname”, dataitem )

where:

pointname is a point name (in double quotes) or a pidarray reference.

The dataitem is one of the following listed in the table below.

All Point Types


UPDATETIME Update time Time of last change for any data
TIMESTAMP Event Time Time of last change of value. Often from RTU

Status Points
TRANSCOUNT Transition count Count of changes
NORMALSTATE Normal state (0,1)
CAPTURETIME Time master station processed last change
REFRESHTIME Time of last poll Time of last report opportunity

Analog Points
LIMITSTATE Limit state 1-7, 1= LOLOLO, 4 = Normal, 7 = HIHIHI
PEMGLO LO Pre-Emergency low limit
PEMGHI HI Pre-Emergency high limit
PEMGDB Pre-Emergency dead band
EMGLO LOLO Emergency low limit
EMGHI HIHI Emergency high limit
EMGDB Emergency dead band
REASLO LOLOLO Reasonability low limit
REASHI HIHIHI Reasonability high limit
REASDB Reasonability dead band

AVG15M Average current 15 minute


MIN15M Minimum current 15 minute
MAX15M Maximum current 15 minute
MINTIM15M Time of minimum current 15 minute
MAXTIM15M Time of maximum current 15 minute

AVGP15M Average previous 15 minute


MINP15M Minimum previous 15 minute
MAXP15M Maximum previous 15 minute
MINTIMP15M Time of minimum previous 15 minute
MAXTIMP15M Time of maximum previous 15 minute

AVGH Average current hour


MINH Minimum current hour

Command Sequencing Templates 3-48


CS-400 Command Sequencing User's Guide

MAXH Maximum current hour


MINTIMH Time of minimum current hour
MAXTIMH Time of maximum current hour

AVGPH Average previous hour


MINPH Minimum previous hour
MAXPH Maximum previous hour
MINTIMPH Time of minimum previous hour
MAXTIMPH Time of maximum previous hour
AVGD Average current day
MIND Minimum current day
MAXD Maximum current day
MINTIMD Time of minimum current day
MAXTIMD Time of maximum current day

AVGPD Average previous day


MINPD Minimum previous day
MAXPD Maximum previous day
MINTIMPD Time of minimum previous day
MAXTIMPD Time of maximum previous day

AVGL Average current week or month


MINL Minimum current week or month
MAXL Maximum current week or month
MINTIML Time of minimum current week or month
MAXTIML Time of maximum current week or month

AVGPL Average previous week or month


MINPL Minimum previous week or month
MAXPL Maximum previous week or month
MINTIMPL Time of minimum previous week or month
previous week or month
MAXTIMPL Time of maximum

AVGM Average current month


MINM Minimum current month
MAXM Maximum current month
MINTIMM Time of minimum current month
MAXTIMM Time of maximum current month

AVGPM Average previous month


MINPM Minimum previous month
MAXPM Maximum previous month
MINTIMPM Time of minimum previous month
MAXTIMPM Time of maximum previous month

Command Sequencing Templates 3-49


CS-400 Command Sequencing User's Guide

Examples:

$A = DATA( “MX01,KWH”, AVGP15M )

The variable $A will be loaded with the previous 15 minute average of the point “MX01,KWH”.

“MX01,MAX” = DATA( “MX01,KWH”, MAXPD )

The analog point “MX01,MAX” is loaded with the previous day’s maximum of point “MX01,KWH”.

$N = DATA( $PID[11], NORMALSTATE )

The normal state of the status point in location 11 of PIDARRAY $PID is returned into variable $N.

3.5.20 Line Section Commands

The line section commands allow a command sequence to access certain data about line sections.
There are two syntaxes for most commands. In the first syntax, the line section is referred to by name.
The line section name is entered as a string. The string must be surrounded by single quote marks.

In the second syntax, the line section is referred to by a line section id. The line section id is an integer
value, starting from one.

In general, the line section id version of the syntax is much more efficient, as the line section data can be
directly accessed. The line section name syntax requires a lookup from name to ID. This lookup will run
more slowly and place more demand on compute resource.

Line section functions:

The LINESECTION function takes two arguments. The first is either a line section name or a number
which is the line section id. Calls using the line section ID are much faster.

The second argument is the data requested.

These are listed in the table below.

Data item Return


The Line section id. Use this id in subsequent lookups for faster performance.
LSID
Returns zero if the line section is not found.
ENERGIZED One (true) if the line section is energized, zero otherwise.
LOOPED One (true) if the line section is looped, zero otherwise.
PARALLELED One (true) if the line section is paralleled, zero otherwise.
One (true) if the energized state is partial, that is, only some phases are
PARTIAL
energized, zero otherwise.
GROUNDED One (true) if the line section is grounded, zero otherwise.
The line section ID of the substation feeder supplying this line section. Valid only
SUB_FEEDER
if the line section is energized.
The line section ID of the station feeder supplying this line section. Valid only if
STN_FEEDER
the line section is energized.

Command Sequencing Templates 3-50


CS-400 Command Sequencing User's Guide

Examples

$a = LINESECTION( 'linesection_name', ENERGIZED )

$a = LINESECTION( $lsid, ENERGIZED )

$lsid = LINESECTION( 'linesection_name', LSID )

$a = LINESECTION( ‘$lsid, data_item )

$string = LSNAME( $lsid )

! a simple program to check which of two substation feeders is feeding the line section ‘CONDUCTOR_7’
$a = LINESECTION( ‘FEEDER_1’, LSID )
$b = LINESECTION( ‘FEEDER_2’, LSID )
$c = LINESECTION( ‘CONDUCTOR_77’, LSID )

DO WHILE (1)
IF ( LINESECTION( $C, ENERGIZED ) )
$c = LINESECTION( $C, SUB_FEEDER
IF ( $c .EQ. $a )
ALARM ‘FED FROM FEEDER_1’
ENDIF
IF ( $c .EQ. $B )
ALARM ‘FED FROM FEEDER_2’
ENDIF
$ENDIF
DELAY 1S
ENDWHILE

3.5.21 GetStatus
This function is used to process status changes with timestamps. See section Status with timestamp
processing (GetStatus, SetStatus).

Command Sequencing Templates 3-51


CS-400 Command Sequencing User's Guide

4 Templates

Templates are subroutines written in command sequencing language.

Templates can be used as subroutines in command sequences. Templates can also be referenced as
functions in CALCED as often as required, with different inputs and outputs in each instance.

Each template is defined with a unique number. Each template definition includes specification of the
types of input/output parameters and the frequency of execution (when used on CALCED).

4.1 Template Editor


The Template editor is accessed via the SCADA Explorer. Selecting the Templates item in the left pane
of SCADA Explorer will show a list of existing templates in the right pane (if any), as seen in Figure 4-1.

To create a new template, use the New button in the toolbar or right click in the right pane and select New.
This will be bring up the “New Template” dialog.

To edit an existing template, double click on the sequence to be edited or right click on the template and
select Edit. This will bring up the “Edit Template” dialog, as shown in Figure 4-2.

To delete an existing template, right click on the sequence and select Delete. Alternatively, call up the
template editor and use the delete button.

Command Sequencing Templates 4-52


CS-400 Command Sequencing User's Guide

Figure 4-1 Templates in the SCADA Explorer

Each Template dialog box defines one template. The editor operation and fields are described below.

4.1.1 TOOLBAR

The following icons are located on the Template Editor's toolbar

Save
This saves the edited template but does not compile it.

Compile
This saves the template and then check its for syntax errors and compiles the template so it can
be executed. If any errors are detected, they will be listed in the Log text box. If no errors are
detected, the template is now ready to be used. Note that if the template does not compile
because of errors, it’s still saved.

Command Sequencing Templates 4-53


CS-400 Command Sequencing User's Guide

Figure 4-2 Template Editor

4.1.2 TEMPLATE #

This is the template number. This is a unique number that is used to reference the function on the
calculation editor (CALCED) or in a TPLATE function call in a command program.

When a new template is created, the number that’s allocated for you can be changed to another valid
number before you save the template. When you save the template for the first time, a template record
with the indicated template number is created.

A valid template number is any number that is not already used by an existing command sequence or
template and is below the maximum number of command sequences/templates. Since sequences and
templates share the same database, a sequence and template cannot share the same number.

4.1.3 NAME

This is the 32-character name of the template. This field maybe left blank. The template name is not
essential since a template is referenced by its template number.

Command Sequencing Templates 4-54


CS-400 Command Sequencing User's Guide

4.1.4 DESCRIPTION

This is a 64-character description of the template function. This description is displayed on the
Calculations Editor when the template is referenced on the editor, so it’s a good idea to not leave this
blank.

4.1.5 PARAMETER DEFINITION

The parameter definition group defines how each of the 7 parameters is used.

The first entry box is the display code that describes the parameter. This code is displayed next to the
parameter field on the Calculations Editor.

Next is the IN and OUT check boxes. Check the boxes as described in Table 4-1.

Table 4-1 IN/OUT Usage Codes

Boxes Selected Meaning


none The parameter is not used.
IN The parameter is an input to the function.
OUT The parameter is an output of the function.
IN & OUT The parameter is both an input and an output.

Selecting the Status checkbox allows the parameter to be a status database point.

Selecting the Analog checkbox allows the parameter to be an analog database point.

Selecting the Const checkbox allows the parameter to be a constant.

4.1.6 SOURCE

This field contains the template’s code, in Command Sequence language. The definition and syntax of
the Command Sequence program language is described in chapter 3, Command Sequence Language.

4.1.7 LOG

Compilation errors are shown in this field.

Command Sequencing Templates 4-55


CS-400 Command Sequencing User's Guide

4.2 Language Restrictions in Templates


Because templates can be used in CALCED, some restrictions are placed on the Command Sequence
language when used for template function definition. These restrictions are as follows.

• The following commands and functions are not allowed in a template:

o ALARM
o CMD
o DELAY
o SET
o LS

The reason for excluding these from templates is that they involve interaction with other programs
(either SCADA or user-written) or otherwise may cause delays

• A template cannot call a command sequence as a subroutine, so the CALL command is not allowed.
A template may call another template, however, via the TPLATE function

It is recommended that templates do not employ the DO/WHILE/ENDWHILE construct or use ONGOTO
to branch backwards. This serves to guarantee that a template cannot contain any long (or even endless)
loops and can be executed safely in the relative short period of time required by the calculations program.

A template may use the 52 predefined variables, $A to $Z and $AA to $ZZ and the predefined array
variables, $GN1 to $GN20 and $GI1 to $GI20. When a template is called by CALCED, these temporary
variables are local to that template only, and are initialized to 0 when the template is called. When the
template is called from a Command Sequence, the template uses the sequence's variables.

A template may reference database points directly. This is useful for obtaining system parameter values.

4.3 Example of a Template


An example of a template is shown in Figure 4-3.

This template (template #98) calculates both uncorrected and corrected meter flow volumes from the
following inputs:

• R = Raw meter count

• C = Meter constant

• F = Meter proving factor

• T = Volume correction factor for temperature

• P = Volume correction factor for pressure

Command Sequencing Templates 4-56


CS-400 Command Sequencing User's Guide

The two outputs are as follows:

• V = Gross volume (uncorrected)

• S = Gross standard volume (corrected)

The formulas are as follows:

• V = (R / C) * F

• S=V*T*P

Figure 4-3 Template #98 (Volume Correction Example)

Command Sequencing Templates 4-57


CS-400 Command Sequencing User's Guide

4.4 Using Templates on CALCED


You can add a template function to the Calculations Editor by selecting the appropriate function Templates
drop down box. As with the built-in functions, you must also specify the names of database points that are
to receive the output values as well as the names of points and/or constants that act as inputs to the
function.

The input fields accept either database point names or constants. The input/output or output-only fields
accept only database point names.

All parameter fields are optional. If an input or input/output field is left blank, then by default, it is initialized
to zero before the calculation is executed. If an output or input/output field is left blank, then the result
destined for that parameter will not be output.

After exiting the Calculation Editor, any newly added template functions are automatically placed online.

Figure 4-4 shows an example of configuring template #98 in the Calculation Record Editor.

Figure 4-4 Configuring Template #98 in the Calculations Editor

Command Sequencing Templates 4-58


CS-400 Command Sequencing User's Guide

Figure 4-5 shows an example of template #98 appearing three times in the calculation editor, each time
with different inputs and outputs.

Figure 4-5 Using Template #98 in CALCED

When a template is executed, the calculation program performs the following steps.

1. The frequency of execution is checked to see if the function should be evaluated on this pass. If
not, the function is skipped.

2. The values of the input and input/output parameters are obtained and assigned to the
corresponding temporary parameter variables $P1 to $P7. The condition flags (normal, telemetry
failed, manually set, calculated from manually set data) of these inputs are recorded. The
temporary parameter variables corresponding to output-only or unused parameters are set to
zero.

3. The template function is executed.

4. The final values of the temporary parameter variables corresponding to the output parameters are
stored back in the corresponding database points.

Status points are converted to floating point on input and back to status values on output. The
following table shows how floating point values are converted back to status values.

Table 4-2 Conversion of Floating Point Values to Status Values


Floating Point Value Status Value
-0.5 to 0.499 0
0.5 to 1.499 1
1.5 to 2.499 2
else 3

5. The point condition flags are set on the output points based on the condition flags of the inputs. If
any input was telemetry failed, the outputs are marked telemetry failed. Else, if any input was
manually set or calculated from manually set data, the outputs are marked calculated from
manually set data. Otherwise, the outputs are marked normal.

Command Sequencing Templates 4-59


CS-400 Command Sequencing User's Guide

4.5 Using Templates in Command Sequences


A template may be executed from a command sequence program. This is accomplished via the TPLATE
function. The calling convention is as follows:

result = TPLATE(func,P1,P2,P3,P4,PS,P6,P7)

where:

func = template number

P1...P7 = function parameters

P1 is both an input and an output parameter. Its value is returned as the result of the function.

Templates that are to be called in this manner have certain restrictions placed upon them.

1. $P1 must be an input/output parameter. Its value at the end of function execution is returned as
the result of the function.

2. $P2 to $P7 are used as input parameters only. If they are output or input/output, the output
results will be ignored.

3. The execution frequency for the function is ignored when called from a command sequence. The
function executes whenever it’s called. Only CALCED pays attention to a template’s execution
frequency.

Figure 4-6 shows an example of a command sequence calling our template #98. This template is
described in section 4.3, Example of a Template, and illustrated in Figure 4-3. The following is an
explanation of each line inside the command sequence’s endless loop.

1. Read the values of the temperature correction and pressure correction factors and store them in
variables $A and $B respectively. In this application, these correction factors are the same for all
three meters.

2. Call template #98 to convert the raw meter count from "NX1,MTR101" into a standard volume and
place the result in "NX1,VOL101".

3. Call template #98 to convert the raw meter count from "NX1,MTR102" into a standard volume and
place the result in "NX1,VOL102".

4. Call template #98 to convert the raw meter count from "NX1,MTR103" into a standard volume and
place the result in "NX1,VOL103".

5. Delay for 60 seconds.

Note that the output parameters $P1 and $P2 in the calls to template #98 are specified as zero since the
only legal output parameter when called from a command sequence is $P1, which is only returned as the
result of the function.

A template function can be made to provide additional outputs, if desired, by means of the temporary
variables $A to $ZZ. Obviously, care is required in the use of such variables for this purpose.

Command Sequencing Templates 4-60


CS-400 Command Sequencing User's Guide

Figure 4-6 Using Template #98 in a Command Sequence

Command Sequencing Templates 4-61


CS-400 Command Sequencing User's Guide

5 Table Lookup

This chapter describes the two-dimensional data tables that can be created and used for table lookup in
both command sequences and templates.

5.1 Lookup Matrix Editor


Lookup tables are defined via the Lookup Matrix editor. This editor allows you to define any number of
two-dimensional arrays of floating point constants.

The regularly spaced X and Y (horizontal and vertical) coordinates that specify the elements of the matrix
are defined by entering the origin and the horizontal and vertical increments in engineering units. The
editor automatically calculates and displays the actual coordinate values.

The Lookup Matrix editor is accessed via the SCADA Explorer. Selecting the Lookup Matrices item in the
left pane of SCADA Explorer will show a list of existing matrices in the right pane (if any), as seen in
Figure 5-1.

To create a new matrix, use the New button in the toolbar or right click in the right pane and select New.
This will bring up the “New Lookup Matrix” dialog as shown in

Figure 5-2. Once the matrix parameters are defined, pressing the Matrix button will allow the matrix to be
displayed, as shown in Figure 5-3.

Command Sequencing Table Lookup 5-1


CS-400 Command Sequencing User's Guide

To edit an existing matrix, double click on the matrix to be edited or right click on the matrix and select
Edit. This will bring up the “Edit Lookup Matrix” dialog, as shown in Figure 5-3.

To delete an existing matrix, right click on the matrix and select Delete.

Figure 5-1 Lookup Matrices in the SCADA Explorer

Figure 5-2 Lookup Matrix Editor – Define Matrix

Command Sequencing Table Lookup 5-2


CS-400 Command Sequencing User's Guide

Figure 5-3 Lookup Matrix Editor – Edit Matrix

5.2 Matrix Editor Data Fields


The data fields for the Matrix editor are described below.

5.2.1 MATRIX ID

This is the matrix number. This is a unique number by which the matrix is accessed by programs. For a
newly created matrix, this number can be changed to any valid matrix number before the matrix is saved
for the first time.

5.2.2 NAME

This is the 32-character name of the matrix. This field maybe left blank. The matrix name is not essential
since a matrix is accessed by its matrix ID.

Command Sequencing Table Lookup 5-3


CS-400 Command Sequencing User's Guide

5.2.3 DESCRIPTION

This field contains a 64-character description of the matrix. It’s good practice to enter something for this,
but it’s not a mandatory field.

5.2.4 ORIGIN

These two fields specify engineering values of the origin (coordinates of the first element) of the matrix.
The X parameter origin specifies the value of the first column. The Y parameter origin specifies the value
of the first row.

5.2.5 DELTA

These two fields specify, in engineering units, the increment of the X and Y coordinates for the matrix. The
X parameter delta specifies the incremental change of value of the columns from left to right. The Y
parameter delta specifies the incremental change of value of the rows from top to bottom.

Once defined, the editor uses the ORIGIN and DELTA fields to display coordinate values in engineering
units for each displayed matrix element.

Either or both of these delta values may be negative. This facilitates the definition of a lookup table based
on a chart where the Y value decreases from top to bottom or the X value decreases from left to right.

5.2.6 SIZE

These two fields specify size of the matrix. The X parameter size specifies the number of columns in the
matrix. The Y parameter size specifies the number of rows in the matrix.

5.2.7 MATRIX ELEMENTS

Once the X parameters and Y parameters are defined, you can create the matrix itself by pressing the
Matrix button.

Each matrix element field contains a constant value. To enter a number into a specific cell, double click
the cell and type in the number. The entry is accepted by pressing Enter or by selecting another field.
You can use the arrow keys to navigate to adjacent cells and type in values (in this case, there’s no need
to double click). Blank fields are changed to the value 0 when the matrix is saved.

Command Sequencing Table Lookup 5-4


CS-400 Command Sequencing User's Guide

5.3 Lookup Function


The syntax of the LOOKUP function in the Command Sequence language is as follows:

result = LOOKUP(n,x,y)

where:

n = matrix number
x = horizontal coordinate
y = vertical coordinate

The LOOKUP function returns the value of the element specified by the given coordinates.

If the given coordinates do not lie directly on a matrix element, a planar (two-dimensional) interpolation is
performed on the values of the three nearest neighbor elements as illustrated Figure 5-4.

If the specified coordinates are outside the range of the table, the command sequence declares an “Array
Index Out Of Bounds” error and aborts. See section 6.3, Fatal Run-Time Error Messages.

Figure 5-4 Planar Interpolation in Table Lookup

Z(X0,Y0) Z(X1,Y0)
*--------------------------------*
| |
| | dy
| |
*----------*
| dx Z(X,Y)
|
|
|
|
|
|
*
Z(X0,Y1)

Z(X,Y) = [Z(X1,Y0) - Z(X0,Y0)]dx + [Z(X0,Y1) - Z(X0,Y0)]dy + Z(X0,Y0)

where:

X – X0
dx = --------
X1 – X0

Y – Y0
dy = --------
Y1 – Y0

Command Sequencing Table Lookup 5-5


CS-400 Command Sequencing User's Guide

6 Messages

This chapter describes the messages that are generated by the Command Sequence editor and the run-
time environment.

6.1 Compiler Error Messages


The messages listed in this section are displayed by the Command Sequence editor and represent
compile-time errors that are detected by the editor when you compile the sequence.

Command Sequencing Messages 6-1


CS-400 Command Sequencing User's Guide

6.1.1 Array type mismatch

The array name and data type do not match.

6.1.2 Command is not supported in Templates

The selected command cannot be used in Templates. See section 4.2, Language Restrictions in
Templates, for a list of the commands that are not supported in Templates.

6.1.3 Database point point_name - invalid type/action

The point type of the database point, point_name, is not supported in this context.

6.1.4 DO structure is nested too deeply

The maximum nesting of DO/WHILE/ENDWHILE structures has been exceeded. Restructure the
code through the use of ONGOTO or CALL to limit the nesting of the DO/WHILE/ENDWHILE
structure.

6.1.5 ERROR Saving


Failed to add row to database table.
NOTE: Check for duplicate pkey or full table

The sequence or template number may be already be in use by an existing sequence or template
or the number may be greater than the size of the database. Change the sequence or template
number to an unused number.

6.1.6 Failed to add variable variable_name to internal tables

An internal error occurred and the variable, variable_name, could not be added to the internal data
tables. Try to re-compile. If this does not correct the problem, reduce the number of variables in
the sequence.

6.1.7 fatal error - scanner input buffer overflow


fatal flex scanner internal error--end of buffer missed
fatal flex scanner internal error--no action found
flex scanner push-back overflow

An internal error occurred while compiling the sequence. Try to re-compile the sequence. If this
does not correct the problem, check the code that you just added for errors. Also try reducing the
size of the code.

Command Sequencing Messages 6-2


CS-400 Command Sequencing User's Guide

6.1.8 Generated object code is too large - shorten command sequence

The compiling of the source code resulted in an executable object that is too large to process.
Break up the command sequence into 2 or more sequences.

6.1.9 Global variable variable_name - invalid type/action

The point type of the variable, variable_name, is not supported in this context.

6.1.10 IF structure is nested too deeply

The maximum nesting of IF/ELSE/ENDIF structures has been exceeded. Restructure the code
through the use of ONGOTO or CALL to limit the nesting of the IF/ELSE/ENDIF structure.

6.1.11 input buffer overflow, can't enlarge buffer because scanner uses REJECT
input in flex scanner failed
Invalid array size specified
Label label_name is already defined

The label, label_name, has been previously defined. Remove the duplicate definition.

6.1.12 Label: label_name is not defined

The label, label_name, is not defined. This can be the result of an improperly structured
IF/ELSE/ENDIF or DO/WHILE/ENDWHILE structure.

6.1.13 Listing is too large

The compiling of the source code resulted in a listing file that is too large to save and therefore the
listing file has been truncated. Break up the command sequence into 2 or more sequences.

6.1.14 Local variable variable_name - invalid type/action

The point type of the variable, variable_name, is not supported in this context.

6.1.15 No matching DO statement


No matching DO/WHILE statement

The DO/WHILE/ENDWHILE structure is incomplete. Correct the code to ensure that each DO
command has a matching WHILE and ENDWHILE command.

Command Sequencing Messages 6-3


CS-400 Command Sequencing User's Guide

6.1.16 No matching IF statement


No matching IF/ELSE statement

The IF/ELSE/ENDIF structure is incomplete. Correct the code to ensure that each IF command
has a matching ENDIF and each ELSE command is properly bracketed by a IF/ENDIF pair.

6.1.17 out of dynamic memory in yy_create_buffer()


out of memory expanding start-condition stack
parse error; also virtual memory exceeded
parser stack overflow
start-condition stack underflow
syntax error: cannot back up

An internal error occurred while compiling the sequence. Try to re-compile the sequence. If this
does not correct the problem, check the code that you just added for errors. Also try reducing the
size of the code.

6.1.18 Parse error

There is an error in the program at the selected line.

6.1.19 Parse error, expecting symbol or symbol

There is an error in the program at the selected line. The symbol, symbol, was expected but not
found.

6.1.20 Time: time_type is invalid

The specified time type, time_type, is invalid.

6.1.21 Too many nested function calls

The function calls have been nested too deep. Restructure the code to limit the depth of the calls.

6.1.22 Variable variable_name is already defined

The variable, variable_name, has been previously defined. Remove the duplicate definition.

6.1.23 Variable type STRING is not supported

The STRING variable type is not supported.

Command Sequencing Messages 6-4


CS-400 Command Sequencing User's Guide

6.1.24 Variable: variable_name - invalid type

The variable, variable_name, type is incorrect for the attempted operation.

6.2 Non-Fatal Run-Time Error Messages


When the command sequence processor encounters a non-fatal error (e.g. checkback error), the
following occurs:

• $ RESULT is set to either Timeout or Failure. The following ONGOTO statement, if there is one,
would then take the timeout or failure branch.

• $ERRORMESSAGE is set to an error message describing the timeout/error.

The variable $ERRORMESSAGE may be set to one of the following error messages:

6.2.1 Timeout Messages

CMD: Failed to receive an immediate reply from process within time

A timeout occurred while attempting to send a command request (CMD command) to the control program.
To clear the problem, attempt to re-activate the sequence. If this fails, reboot.

LS: Failed to receive an immediate reply from process within time

A timeout occurred while attempting to send an LS command to the appropriate scan task. To clear the
problem, attempt to re-activate the sequence. If this fails, reboot.

SET: Failed to receive an immediate reply from process within time

A timeout occurred while attempting to send a setpoint request (SET command) to the control program.
To clear the problem, attempt to re-activate the sequence. If this fails, reboot.

Command Sequencing Messages 6-5


CS-400 Command Sequencing User's Guide

6.2.2 Error Messages

CMD: Mailbox: mailbox_name reports error: error

An internal error occurred while attempting to send a command request (CMD command) to the control
program. To clear the problem, attempt to re-activate the sequence. If this fails, reboot.

CMD: Reports check back failure

On execution of a CMD command, the scan task reported a checkback error.

LS: Cannot open RTU Special PID pid_id


LS: Failed to open RTU id= pid_id, abort
LS: PID pid_id does not reference RTU

The RTU with PID pid_id is invalid. Correct the parameters of the LS command and recompile.

LS: Device type 4 not supported yet

Load-shed device type 4 is not supported.

LS: Failed to open CL id= pid_id, abort


LS: Failed to open connection to scan task scan_task_name

The LS command could not connect to the specified communication line. Verify that the communication
line exists and that the scan task is operational. If the communication line is correct, attempt to re-activate
the sequence. If this fails, reboot.

LS: Mailbox: mailbox_name reports error: error

An internal error occurred while attempting to send an LS command to the appropriate scan task. To
clear the problem, attempt to re-activate the sequence. If this fails, reboot.

SET: Mailbox: mailbox_name reports error: error

An internal error occurred while attempting to send a setpoint request (SET command) to the control
program. To clear the problem, attempt to re-activate the sequence. If this fails, reboot.

SET: Reports check back failure

On execution of a SET command, the scan task reported a checkback error.

Command Sequencing Messages 6-6


CS-400 Command Sequencing User's Guide

6.3 Fatal Run-Time Error Messages


When the command sequence processor encounters a fatal error (i.e. execution of the sequence cannot
continue), it raises an alarm with the following text:

Sequence n: sequence_name ABORTED

where:

n = primary sequence number (main program)

sequence_name = name of the primary sequence number (main program)

Following this alarm is a message detailing the cause of the alarm. This alarm contains the following text:

SRCnnn/SRCmmm/lll msg

where:

SRC = sequence type: SEQ (if sequence) or TPL (if template)

nnn = primary sequence number (main program)

mmm = subroutine sequence number (blank if no subroutine was called)

lll = line number where error occurred

msg = text of error message

If the error occurred in a subroutine, the “lll” number is the line number in the subroutine, not the line
number in the caller where the subroutine was called.

The various messages that may appear in the “msg” field are described below. Note that a fatal error in
one sequence does not normally affect the execution of any other sequences.

The alarm message can also be read in the windows event viewer. Open up the event viewer and select
the Application Log branch of the local Event Viewer tree. The Source column will have an entry,
SEQPROn, where n is the main sequence number in which the error occurred. Double click on the entry,
and a dialog box with details of the error will be displayed.

Command Sequencing Messages 6-7


CS-400 Command Sequencing User's Guide

Figure 6-1 Windows Event Viewer

Figure 6-2 Windows Event Properties

Command Sequencing Messages 6-8


CS-400 Command Sequencing User's Guide

6.3.1 Error Message List

**: Math Error – error_message

The math operation, power (**), encountered the error, error_message.

ACOS: Math Error – error_message

The math function, ACOS, encountered the error, error_message.

ADD: Parameter type not supported

The specified parameter is not supported by the ADD (+) operator.

ADD: Mismatched data types

Mis-matched data types have been passed to the ADD (+) operator. The left and right arguments
of the ADD operator must have the same data types.

ALARM: Not supported in Template

The ALARM command cannot be called from a template. Move the ALARM call into a command
sequence.

.AND.: Invalid data type

The .AND. operator does not support the passed data type.

.AND.: Mismatched data types

Mis-matched data types have been passed to the .AND. operator. The left and right arguments of
the .AND. operator must have the same data types.

.AND.: Unsupported operation

The .AND. operator cannot process the passed data type.

AGA8A: Is not supported

The AGA8A command is not supported at this time.

AGA8B: Is not supported

The AGA8B command is not supported at this time.

Command Sequencing Messages 6-9


CS-400 Command Sequencing User's Guide

ASIN: Math Error – error_message

The math function, ASIN, encountered the error, error_message.

ATAN: Math Error – error_message

The math function, ATAN, encountered the error, error_message.

Attempt to assign a non-numeric value to an analog point

Only numeric values can be assigned to analog database point types. Other types such as text
cannot be assigned.

Attempt to assign a non-numeric value to a status point

Only numeric values can be assigned to status database point types. Other types such as text
cannot be assigned.

Attempt to assign a non-string value to a text point

Only strings can be assigned to text database point types.

AUTOSYNC: Is not supported

The AUTOSYNC command is not supported at this time.

CALL: Not supported in Template

The CALL command cannot be called from a template. Move the CALL command into a
command sequence.

Cannot load command sequence sequence_ID error_reason

The command sequence, sequence_ID, could not be loaded because of error_reason. To clear
the problem, attempt to re-activate the sequence. If this fails, recompile and restart the sequence.
If this also fails, reboot.

Cannot open point database

An internal error while opening the point database has occurred. Attempt to re-activate the
sequence. If this fails, reboot.

Command Sequencing Messages 6-10


CS-400 Command Sequencing User's Guide

Cannot save $T1 to $T5 error_reason

The permanent local variables, $T1 to $T5 could not be saved to disk because of error_reason.
To clear the problem, attempt to re-activate the sequence. If this fails, recompile and restart the
sequence. If this also fails, reboot.

COS: Math Error – error_message

The math function, COS, encountered the error, error_message.

Could not read analog point PID: PID_number error_reason


Could not read status point PID: PID_number error_reason
Could not read text point PID: PID_number error_reason

An internal error occurred while attempting to read a database point. The point PID is
PID_number. The source of the problem is error_reason. To clear the problem, attempt to re-
activate the sequence. If this fails, recompile and restart the sequence. If this also fails, reboot.

Could not set analog point PID: PID_number to value error_reason


Could not set status point PID: PID_number to value error_reason
Could not set text point PID: PID_number to value error_reason

An internal error occurred while attempting to write a database point. The point PID is
PID_number. The value being written is value. The source of the problem is error_reason. To
clear the problem, attempt to re-activate the sequence. If this fails, recompile and restart the
sequence. If this also fails, reboot.

CMD: Cmd sent to non-status type

The CMD command can only be sent to status points.

CMD: Failed to create mailbox, abort


CMD: Failed to open connection to tstat
CMD: Failed to receive the indicated mail messages length
CMD: Zero length mail message received

An internal error occurred while attempting to send a command request (CMD command) to the
control program. To clear the problem, attempt to re-activate the sequence. If this fails, reboot.

CMD: Not supported in Templates

The CMD command cannot be called from a template. Move the CMD call into a command
sequence.

DELAY: Not supported in Templates

The DELAY command cannot be called from a template.

Command Sequencing Messages 6-11


CS-400 Command Sequencing User's Guide

DIV: Divide by zero

A divide by 0 has occurred.

.EQ.: error_message

Refer to the .AND. operator description for the error, error_message.

. ERROR.: error_message

Refer to the .AND. operator description for the error, error_message.

EXP: Math Error – error_message

The math function, EXP, encountered the error, error_message.

Expected analog point type not found


Expected status point type not found
Expected status/analog point type not found
Expected text point type not found

The command did not find the database point type that it was expecting to process. Correct the
command sequence and recompile.

Hard loop detected, use delay statements

Too many statements have been executed without execution of a DELAY statement. This may be
due to an extremely long or even infinite loop. The maximum number of consecutive statements
executed without a delay is 1,000,000 p-Code (internal code steps) statements, or approximately
200,000 lines of code.

The command sequence processor counts executed p-Code statements, and resets the counter
to zero whenever it executes a DELAY statement. When the counter reaches 1,000,000, the
command sequence processor assumes that there’s a hard loop and aborts. Correct the program
or add delay statements to the program.

Incompatible database/value assignment

The value being assigned to the database point is not of the correct type. For example you
cannot assign a string value to an analog point.

Internal program error - invalid context

An internal error occurred. To clear the problem, attempt to re-activate the sequence. If this fails,
recompile and restart the sequence. If this also fails, reboot.

Command Sequencing Messages 6-12


CS-400 Command Sequencing User's Guide

Internal stack error - stack is empty

An internal stack error has occurred. Attempt to re-activate the sequence. If this fails, recompile
and restart the sequence. If this also fails, reboot.

.LE.: error_message

Refer to the .AND. operator description for the error, error_message.

LIB: Is not supported

The LIB command is not supported at this time.

LN: Math Error – error_message

The math function, LN, encountered the error, error_message.

LOG: Math Error – error_message

The math function, LOG, encountered the error, error_message.

LOOKUP: Could not open Matrix database


LOOKUP: Table of matrix matrix_id does not exist
LOOKUP: Row index in matrix matrix_id does not exist

An internal error accessing the matrix database occurred. Verify that the matrix exists. If it does,
attempt to re-activate the sequence. If this fails, reboot.

LOOKUP: Matrix matrix_id does not exist

The program attempted to perform a table lookup for a table that has not been defined. The
invalid matrix ID is matrix_id.

LOOKUP: X is out of range. X = value

The program attempted to perform a table lookup with the X coordinate being out of range. The
value of the out of range coordinate is: value.

LOOKUP: Y is out of range. Y = value

The program attempted to perform a table lookup with the Y coordinate being out of range. The
value of the out of range coordinate is: value.

Command Sequencing Messages 6-13


CS-400 Command Sequencing User's Guide

LS: Failed to create mailbox, abort


LS: Failed to receive the indicated mail messages length
LS: Zero length mail message received

An internal error occurred while attempting to send an LS command to the appropriate scan task.
To clear the problem, attempt to re-activate the sequence. If this fails, reboot.

LS: Not supported in Templates

The LS command cannot be called from a template. Move the LS call into a command sequence.

.LT.: error_message

Refer to the .AND. operator description for the error, error_message.

Max call depth (max_depth) exceeded

Command sequence and template calls are nested more than the maximum depth of max_depth.
Rewrite the sequence to ensure the calling depth is not greater than the maximum.

MAX: no arguments

A MAX function requires at least two arguments.

MIN: no arguments

A MIN function requires at least two arguments.

MOD: Divide by zero

A divide by 0 has occurred.

MRTFRZ: Is not supported

The METFRZ command is not supported at this time.

.MS.: Unsupported point type

The database point does not support the “manually set” condition code.

.NE.: error_message

Refer to the .AND. operator description for the error, error_message.

.NOT.: error_message

Refer to the .AND. operator description for the error, error_message.

Command Sequencing Messages 6-14


CS-400 Command Sequencing User's Guide

.OFF.: error_message

Refer to the .AND. operator description for the error, error_message.

Old version: Sequence/Template has to be recompiled

A new command sequence engine has been installed. The source code has to be re-compiled
before it will run on the new software.

.ON.: error_message

Refer to the .AND. operator description for the error, error_message.

.OR.: error_message

Refer to the .AND. operator description for the error, error_message.

Reading past end of program

An internal error occurred that caused the command sequence processor to read beyond the
length of the command sequence program. To clear the problem, attempt to re-activate the
sequence. If this fails, recompile and restart the sequence. If this also fails, reboot.

RUN: Is not supported

The RUN command is not supported at this time.

Program is not loaded

An internal error occurred and the command sequence was found not to be loaded. To clear the
problem, attempt to re-activate the sequence. If this fails, recompile and restart the sequence. If
this also fails, reboot.

SET: Failed to create mailbox, abort


SET: Failed to open connection to tstat
SET: Failed to receive the indicated mail messages length
SET: Zero length mail message received

An internal error occurred while attempting to send a setpoint request (SET command) to the
control program. To clear the problem, attempt to re-activate the sequence. If this fails, reboot.

SET: Not supported in Templates

The SET command cannot be called from a template. Move the SET call into a command
sequence.

Command Sequencing Messages 6-15


CS-400 Command Sequencing User's Guide

SET: Set sent to non-analog type


SET: Set sent to non-setpoint class

The SET command can only be used with analog points with Device Class “Set-Point”.

SIN: Math Error – error_message

The math function, SIN, encountered the error, error_message.

SQRT: Negative parameter

The SQRT function requires a positive number.

Stack: Float or integer expected


Stack: String expected

The expected point type was not found, probably as a result of an internal stack error. Attempt to
re-activate the sequence. If this fails, recompile and restart the sequence. If this also fails,
reboot.

Stack: Nothing to pop

An internal stack error has occurred. Attempt to re-activate the sequence. If this fails, recompile
and restart the sequence. If this also fails, reboot.

Stack: Stack is full

The internal stack is full. Attempt to re-activate the sequence. If this fails, recompile and restart
the sequence. If this also fails, reboot. If all these steps fail, try making the program smaller.

TAG: Inhibit all control tag type is not found, create tag type

A TAG type that inhibits all controls could not be found. Create this tag type and rerun the
sequence.
TAG: Point not found

The point that had the TAG command applied could not be found.

TAG: Tag sent to non-status/analog type

A TAG command can only be applied to a status or analog point.

TAN: Math Error – error_message

The math function, TAN, encountered the error, error_message.

Command Sequencing Messages 6-16


CS-400 Command Sequencing User's Guide

.TF.: Unsupported point type

The database point does not support the “telemetry failed” condition code.

TIME: Invalid time component was specified

The TIME command does not support the specified time value. Only use the following
components: YEAR, MONTH, DAY, HOUR, MINUTE or SECOND.

TPLATE: Invalid number of arguments

An incorrect number of arguments are used in a TPLATE call. Verify the argument definition in
the template. Recompile the template.

TPLATE: Error loading Template template_ID

An error occurred while loading template number, template_ID. Attempt to re-activate the
sequence. If this fails, recompile and restart the sequence. If this also fails, reboot.

. TRAVEL.: error_message

Refer to the .AND. operator description for the error, error_message.

Unknown command encountered


Unknown error encountered
Unsupported command

An internal error occurred. To clear the problem, attempt to re-activate the sequence. If this fails,
recompile and restart the sequence. If this also fails, reboot.

USER: Is not supported

The USER command is not supported at this time.

Variable: Name is not defined

The variable name is not defined with the DEFINE keyword.

Variable type is not supported

An unsupported variable type was encountered. Recompile and restart the sequence. If this fails,
reboot.

Variable variable_name: Array type mismatch

The data type of the array, variable_name, does not match it’s target.

Command Sequencing Messages 6-17


CS-400 Command Sequencing User's Guide

Variable variable_name: Data type is not STRING

The variable, variable_name, is does not have the expected data type of string.

Variable variable_name: Data type is not supported

The variable, variable_name, is an unsupported data type.

Variable variable_name: Illegal variable redefinition

An attempt to redefine the variable, variable_name, has occurred. Variable names can only be
declared once in a program. They should not be declared within a loop as this will result in this
error.

Variable variable_name: Index array_index exceeded array boundaries

The array index, array_index, exceeds the defined length of the array, variable_name. The array
index must be in the range of 1 to the defined size of the array.

Variable variable_name: Invalid array length of array_length

The array, variable_name, cannot be define with the length, array_length.

Variable variable_name: Type mismatch

The data type of variable, variable_name, does not match its target or the value that it is operating
with.

.XOR.: error_message

Refer to the .AND. operator description for the error, error_message.

6.4 Information Messages


The following messages are logged by the command sequence processor to record sequence start/stop
operations.

Sequence nnn:seq_name started from location

Sequence nnn, named, name, was activated from the location, location.

Sequence nnn:seq_name stopped from location

Sequence nnn, named, name, was stopped from the location, location.

Sequence nnn:seq_name completed

The previously started sequence nnn, named, name, has completed execution.

Command Sequencing Messages 6-18


CS-400 Command Sequencing User's Guide

6.5 TLCALC Error Messages


The calculations that are defined on CALCED are executed by a program called TLCALC. When TLCALC
encounters a fatal error in the execution of a template, it raises an alarm with the following text:

TLCALC: ERROR IN EQN#nnnn TEMPLATE #mm (SEE LOGGER)

where “nnn” is the calculation equation number and “mm” is the template number. TLCALC also raises an
alarm containing a message that explains the nature of the error. The format of this message is:

TLCALC: EQN#nnnn TPLmm//ll msg

where

nnnn = CALCED equation number

mm = template number

ll = line number where error occurred

msg = text of error message

The various messages that may appear in the “msg” field are generally the same as those that are listed
for command sequences in section 6.3, Fatal Run-Time Error Messages.

After declaring a fatal error for an equation, TLCALC stops executing that equation until the next failover
or system restart. A fatal error in one equation does not stop execution of any other equations.

Command Sequencing Messages 6-19


CS-400 Command Sequencing User's Guide

7 Example

The following is a practical example of a command sequence program that uses many of the features of
the Command Sequencing language.

In particular, this example illustrates the following:

• Table lookup
• Setpoint controls
• Use of comments to document code
• Use of arrays
• Branching
• Use of templates

The example is a simple generator control program. Based on measured headwater and tailwater levels,
it performs table lookups to obtain optimum generator output MW levels. These desired MW levels are
issued to the generators via setpoint commands to the appropriate RTUs.

Command Sequencing Example 7-1


CS-400 Command Sequencing User's Guide

Figure 7-1 illustrates the main command sequence program. At every control interval, it calls other
subsequences to control groups of generators. In this example, there are three generator groups, and the
control interval is one minute.

For each group of generators, a generator group control subsequence is defined. The subsequence is the
same for each generator group, but the data arrays are different. The generators in each group are
defined by means of these data arrays.

Figure 7-1 Main Generator Control Loop

Figure 7-2 shows a control subsequence for one generator group. Figure 7-3 lists the complete program
as well as the associated data arrays that define the parameter points for the generators in the group. In
this example, there are two generators in the group.

Command Sequencing Example 7-2


CS-400 Command Sequencing User's Guide

Figure 7-2 Control Sequence for One Generator Group

The control subsequence executes the following algorithm for each generator in the group:

• Using a common set of headwater and tailwater level values, the optimum generator MW output
is looked up in the specified table.

• If the result is a new desired MW level, the new level is stored in a database point, a
corresponding new setpoint is issued to the RTU and a timer is started. This timer is later
processed by a subroutine defined in Template #91. The definition of Template #91 is shown in
Figure 7-4. The timer is set to a value that will allow the timer-processing subroutine to alert the
operator if the generator output does not reach within the deadband distance of the new setpoint
within 15 minutes.

• If the result is not a new desired MW output, the subroutine of Template #91 is called to process
the time. The output of this subroutine consists of an updated timer value, and a “generator not
following” status. This status is stored into the specified generator's "generator not following”
status point. If this point is correctly defined, an alarm will be raised when the point’s status goes
to 1 (indicating that the generator is not following).

Command Sequencing Example 7-3


CS-400 Command Sequencing User's Guide

Figure 7-3 Program for Generator Control Subroutine

! .IDENT /13C.01 4-JUN-93 CM/ ! FIRST VERSION


! CALC & SEND SETPOINT. IF NEW, START 15-MIN TIMER.

! DATA ARRAYS FOR ABITIBI CANYON GENERATORS (G2 - G5)


DEFINE NUMARRAY $N1[1], $N2[2], $N3[2]
$N1 = /2/ ! NUMBER OF GENERATORS
$N2 = /2,3/ ! EFFICIENCY TABLE NUMBERS
$N3 = /4,4/ ! CAVITATION TABLE NUMBERS

DEFINE PIDARRAY $I1[2], $I2[2], $I4[2], $I5[2], $I6[2], $I7[2], $I8[2], $I9[2], $I10[2], $I11[2],
$I12[2], $I13[2]

$I1 = /"GEN1,EFF", "GEN2,EFF" / !EFF SETPT


$I2 = /"GEN1,CAV", "GEN2,CAV" / !CAV SETPT
$I4 = /"GEN1,REQMW", "GEN2,REQMW"/ !CUR SETPT
$I5 = /"GEN1,GENMW", "GEN2,GENMW"/ !GEN MW
$I6 = /"GEN1,CTRLM", "GEN2,CTRLM"/ !CONTROL MODE
$I7 = /"GEN1,TBLST", "GEN2,TBLST"/ !TABLE STATUS
$I8 = /"GEN1,TIMER", "GEN2,TIMER"/ !FOLLOW TIMER
$I9 = /"GEN1,GENSP", "GEN2,GENSP"/ !OUTPUT POINT
$I10= /"GEN1,SBAND", "GEN2,SBAND"/ !SHORTBAND
$I11= /"GEN1,DBAND", "GEN2,DBAND"/ !DEADBAND
$I12= /"GEN1,GENMW", "GEN2,GENMW"/ !FOLLOW STATUS
$I13= /"GEN1,GENCE", "GEN2,GENCE"/ !CONTROL ERROR

$HH="ABIT,ANA1"; $TT="ABIT,ANA2" ! HEAD/TAIL LEVELS


$A = 1 ! FIRST GENERATOR

DO WHILE ($A .LE. $N1[1]) ! FOR EACH GENERATOR


$I1[$A]=LOOKUP($N2[$A],$HH,$TT)/1000 ! GET EFF SP
$I2[$A]=LOOKUP($N3[$A],$HH,$TT)/1000 ! GET CAV SP

IF ($I6[$A] .GT. 1) ! IF CONTROL OFF


$I8[$A] = -1 ! DISABLE THE TIMER

ELSE ! ELSE, SELECT SETPT


$S=TPLATE(90,0,$I6[$A],$I1[$A],$I2[$A])

IF ($S .NE. $I4[$A]) ! IF NEW SETPOINT


$I4[$A] = $S ! STORE IT
SET $I9[$A] $I4[$A] ! AND SEND IT
IF ($I8[$A] .LE. 1) ! IF NOT RUNNING
$I8[$A] = 17 ! START TIMER
ENDIF
ENDIF

IF (($I8[$A] .EQ. -1) .OR. ($I7[$A] .OFF.) ) ! IF TIMER DISABLED OR TABLE OFF
SET $I9[$A] $I4[$A] ! SEND SETPOINT
IF ($I8[$A] .EQ. -1) ! IF TIMER DISABLD
$I8[$A] = 0 ! ENABLE IT
ENDIF
ENDIF

$I13[$A] = $I5[$A]-$I4[$A] ! GET CONTROL ERROR


$E = ABS($I13[$A]) ! GET ABS VALUE
$B = $I10[$A]; $D = $I11[$A] ! GET DEADBANDS
$I12[$A]=TPLATE(91,$I12[$A],$I8[$A],$E,$B,$D) ! PROCESS TIMER
$I8[$A] = $T ! UPDATE TIMER
ENDIF

$A = $A + 1 ! NEXT GENERATOR
ENDWHILE

Command Sequencing Example 7-4


CS-400 Command Sequencing User's Guide

For Template #91, the significance of the timer values is as follows:

0 = timer not active


1 = timer active but has expired
>1 = timer active

The algorithm of Template #91 is as follows:

• If the control error is within the deadband, the timer and generator not following status are both set
to zero. This indicates that the generator's output is following the setpoint.

• Otherwise, if the timer is not already active, it is started now. This corresponds to the situation
where the control error had previously been brought to within the deadband but has now deviated
outside it. The timer value is set to 6, so as to expire in five minutes.

• If the timer was already active but not yet expired, then its value is decremented. If the new timer
value is now one, then the timer has expired, and the generator not following status is set to 1.

Figure 7-4 Template to Process Generator Timer

Command Sequencing Example 7-5


CS-400 Command Sequencing User's Guide

Figure 7-5 Program for Process Generator Timer

! CALLER STARTS A 15-MIN TIMER ON A NEW SETPOINT.


! THIS ROUTINE STARTS A 5-MIN TIMER WHEN THE CONTROL
! ERROR FOR AN EXISTING SETPOINT EXCEEDS THE DEADBAND.

! INPUTS: $P1 = GEN STATUS $P4 = SHORTBAND


! $P2 = TIMER VALUE $P5 = DEADBAND
! $P3 = CONTROL ERROR

! OUTPUTS: $P1 = UPDATED GENERATOR STATUS


! $T = UPDATED TIMER VALUE

IF ($P3 .LE. $P5) ! IF ERROR LE DEADBAND


$P1 = 0; $T = 0 ! GENERATOR FOLLOWING
ELSE ! ELSE (ERROR GT DEADBAND)
IF ($P2 .EQ. 0) ! IF TIMER NOT RUNNING
$T = 6 ! START IT NOW (5 MIN)
ELSE ! ELSE (TIMER RUNNING)
$T = $P2 ! GET TIMER VALUE
IF ($T .GT. 1) ! IF TIMER NOT EXPIRED
$T = $T - 1 ! DECREMENT TIMER
IF ($T .EQ. 1) ! IF EXPIRED NOW
$P1 = 1 ! GEN NOT FOLLOWING
ELSE ! ELSE (NOT EXPIRED)
! IF TIME TO CHECK SB ANDIF ERROR GT SB
IF (($T .EQ. 15) .AND. ($P3 .GT. $P4))
$P1 = 1 ! GEN NOT FOLLOWING
ENDIF
ENDIF
ELSE ! ELSE (TIMER EXPIRED)
$P1 = 1 ! GEN NOT FOLLOWING
ENDIF
ENDIF
ENDIF

Command Sequencing Example 7-6

You might also like