CPL
CPL
Custom Programming
This book applies to
Tracer Summit software
version 6.0 and later.
Volume 5
BMTS-IOP-504
November 1997
This is Volume 5 in a seven-volume set. Refer to engineering bulletin BAS-EB-57 for a list of literature numbers
applicable to the current and previous versions of Tracer Summit software.
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . i
Tracer Summit Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . i
About This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . i
Trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . i
Typographical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ii
Screen Nomenclature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ii
Additional Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ii
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-14
FOR...NEXT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15
FOR NEXT OBJECT Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16
FUNCTION...END FUNCTION Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-17
GOTO Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-19
IF...THEN...ELSE...END IF Statement. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20
Table of Contents
Appendix A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-1
Example CPL Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-1
Appendix B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-1
CPL Error Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-1
Preface
Tracer Summit Software
Trademarks
The following are trademarks of their
respective companies: ARCNET from
Datapoint Corporation, BACnet from
ASHRAE, IBM, Operating System/2,
OS/2, and PS/2 from IBM Corporation,
Paintbrush and PC Paintbrush from
ZSoft Corporation, Paint Shop Pro from
JASC, Inc., Windows from Microsoft,
Pentium from INTEL Corporation, and
Collage and Collage PM from Inner
Media, Inc.
Preface
Typographical Conventions
The following typographical conventions are
used throughout this manual:
BOLD ITALICIZED
UPPER CASE
Italicized
Menu selections,
check boxes, and push
buttons selectable with
the mouse.
Volume 7: Library
Bold
ITALICIZED UPPER
CASE
User-dependent
information you enter
(for example, date or
time).
Screen Nomenclature
The diagrams on the following pages display
names assigned to different areas of typical
Tracer Summit windows and dialog boxes.
ii
Preface
Title Bar
Minimize/Maximize Buttons
Menu Bar
Window Display
Areas
Scroll Bar
Selected
Menu Item
Description
Pull-down
Menus
Slider Bars
iii
Preface
Entry Field
Check Box
Radio Buttons
Group
Push Buttons
List Box
Scroll Bars
iv
General Information
This chapter serves as a programming
reference for system supervisors and
qualified technicians (hereafter referred to
collectively as programmers) using the
Custom Programming Language (CPL)
application. Use CPL to perform functions
and calculations that cannot be done by
other applications within Tracer Summit.
CPL Features & Applications
CPL allows programs to be customized to
meet the applications required to monitor or
operate the site, building, and/or system.
CPL can be used to write programs in the
CPL Editor, compile programs on the PC
Workstation, create CPL programs (as
objects) in the database, and execute
programs in a BCU. The list below defines
CPL features and typical applications.
1-1
General Information
3.
4.
2.
1-2
General Information
2.
3.
1-3
General Information
New. Use this command to create a new CPL text file. The Edit window is cleared and the cursor is
placed at the top left corner.
Open... Use this command to display an existing CPL text file in the CPL Editor. An Open dialog
box displays allowing you to retrieve a CPL text file from a specific drive and subdirectory.
Merge...Use the Merge command to insert an existing CPL text file into the displayed file at the
current cursor position. An Open dialog box displays, allowing you to merge a CPL text file from a
specific drive and subdirectory.
Save. Use the Save command store an existing CPL text file to disk with the same name.
Save As... Use the Save As command to store the existing CPL text file to disk with a different
name.
Delete...Use the Delete command to specify the name of the CPL text file to be deleted.
Print Setup... Use this command to configure printer settings, such as layout and paper size.
Print The Print command sends the CPL text file to the system printer.
Token Dump This option is used for troubleshooting by BASD personnel. If you are having troubles
compiling a CPL text file, BASD personnel may ask you to perform a token dump, which displays
below the CPL file, and send either a printout or a file to them for inspection. BASD uses the data to
verify whether files are compiling correctly.
Save Token Dump As . . . This option saves troubleshooting information, which is used by BASD
personnel. If you are having problems compiling a CPL text file, BASD personnel may ask you to
perform a token dump and save it to a file. BASD uses the information to verify whether files are
compiling correctly.
Exit. Use the Exit command to close the CPL Editor and return to the Tracer Summit Main
Window.
1-4
General Information
Undo. Use the Undo command to undo the last editing change made.
Cut. Cut removes the selected text from the CPL text file and places it in the clipboard.
Copy. Copy takes the selected text and places it in the clipboard without removing it from the CPL
text file.
Paste. Paste takes the contents of the clipboard and places it in the CPL text file at the current
cursor location.
Delete. Delete removes the selected text from the CPL text file and discards it. Unlike the Cut
command, it does not get placed in the clipboard.
Add Statement. This command displays a list box containing all the CPL statement structures. To
enter a statement, select the desired statement from the list. It is inserted in the CPL text file at the
current cursor location.
Add Function. This command presents a list box containing all the functions provided with CPL.
To add a function to the program, select the desired function from the list. It is inserted in the CPL
text file at the current cursor location.
Add Object. This command displays the standard Objects and Properties dialog box. By
selecting the desired object, you can add it to the CPL file at the current cursor location.
Add Obj&Property. This command displays the standard Objects and Properties dialog box. By
selecting the desired object and property, you can add it to the CPL file at the current cursor
location.
Add Enum Bool. This command displays the standard Objects and Properties dialog box. By
selecting the desired object and property, you can select an enumeration that is entered into the
CPL file at the current cursor location. This is useful for multi-state and binary properties.
Find/Change. This command displays a dialog box where you enter the text string. The CPL
Editor then scans the text file for the text string. Once entered, the search is begun at the current
cursor location and proceeds to the end of the CPL text file. The dialog box also allows you to
enter a text string to be scanned and the text string to replace it. Beginning at the current cursor
location, each occurrence of the search string is found and replaced with the change string until
the end of the CPL text file.
Select all. This command selects every line in the CPL program. The selected text can then be cut
or copied to the clipboard.
Go To Line... This command prompts you for the line number to move to. The cursor is placed at
the beginning of the entered line if that line number exists.
1-5
General Information
Open CPL Object... This command displays an existing CPL program object in the CPL Editor. A
Select CPL Program dialog box displays, which allows you to select a CPL object. The CPL object
is automatically decompiled and presented in a text file format.
Create CPL Obj... Use this command to download a compiled CPL text file as a new CPL object
to the system database.
Replace CPL Obj... Use this command to download a compiled CPL text file over an existing CPL
object to the system database.
Compile. This command works on the CPL text file currently in the CPL Editor. It performs a syntax
check and verifies that all objects and properties in the text file exist in the database. A successful
compile results in a CPL program object file being built.
Syntax Check. This command checks the syntax of the CPL text file. Syntax check differs from
Compile in that object and property names are not verified with the system database and the CPL
object is not built. Syntax Check is useful when CPL programs are being created on an offline PC
Workstation.
1-6
General Information
Run Program. This command executes the program from the current statement line and continues
to the next break point or to the end of the program.
Debug Program. This is a dual function command that allows you to select a CPL program object
to test. The selected program is ready for execution at the first statement. Stop Debug
discontinues the debug program function.**
Step. This command executes the next statement in the program.
Halt. This command stops/halts a running debug program that has not returned control to the
CPL Editor.
View Variable... Use this command to view the current value of variables and properties used in
this program. By stepping through the program and viewing the variables and properties, you can
debug the program.
Set Break. Use this command to set breakpoints at the beginning of statements. Breakpoints halt
execution when and if they are reached.
Clear Break. Use this command to remove an existing breakpoint.
Next Breakpoint. Use this command to view each sequential breakpoint in turn.
Home Halt Point. This command places the cursor to the statement where the program is
currently halted.
Calling Sequence. Use this command to view all calls to subroutines and functions used to get to
the current point in the program.
Inhibit DB writes. Use this command to run a CPL program object without performing any outputs
to the system database.
Debug Color. Use this command to select a color for the background that appears while the debug
program is running.
+
+
1-7
General Information
Description Bar. This command is a check item switch used to select whether menu and command
descriptions are displayed at the bottom of the CPL Editor screen.
Query Lines. This command displays the total number of source statement lines in the current CPL
program object file.
Word Wrap. This command is a toggle that enables or disables auto word wrapping at the end of
the CPL text file statement lines.
Background Color. Use this command to change the background color of the CPL Editor screen.
Screen Font. Use this command to change the test font that displays on the CPL Editor screen.
1-8
2.
3.
4.
5.
6.
7.
2-1
Example Program:
Program AREA1_SHUTDOWN
// Written: December 15, 1992 by Ryan Smith
// Modifications:
//
//
1/12/93 RAS:
Added enumerations for On and Off
// Properties modified:
//
//
//
//
//
// Define enumerations
2-2
End If
End
2-3
DEFOBJ RTU
not
RTU1 = {FINANCE DEPT TCM}.{PRESENT VALUE}
Syntax:
Whether selected or directly typed, the
object name portion is delimited with
opening and closing braces { } and
optionally followed by a property name
separated by a period ({FINANCE DEPT
TCM}.{Present Value}). To specify the
2-4
Assigning Enumerations
In the Tracer Summit system, all binary and
multi-state properties are treated internally
as an integer. For example, the state of a
binary output objects present value property
is either On or Off. Internally, On is
associated with the integer 1 and Off is
associated with the integer 0.
To make CPL programs easier to read, these
internal numbers (integers) can be converted
to Enumerations. Enumerations are the
association between words and integers. For
example, it can be specified in a CPL
program that anytime the word Off
appears in the program, the Tracer Summit
software interprets that word as the integer 0.
Enumerations are created using the DEFINT
statement (refer to Chapter 3 for more
information on DEFxxx statements). If you
know the integers associated with the
enumeration, you can define these directly
while creating the CPL program (some
common enumerations are: On = 1, Off = 0,
Enabled = 1, Disabled = 0). However, the
defined integers associated with a particular
propertys enumerations are not always
known (for instance, the numbers associated
with the switch settings for the chiller front
panel).
To assist in assigning enumerations, select
the Add Enum Bool submenu from the Edit
menu in the CPL Editor (refer to page 2-7).
The Select Object Type, Name, and
Property dialog box appears. Select the
desired property from the list and click the
2-5
1.
2.
2-6
3.
4.
5.
2-7
Example Program 1:
This is an example of a CPL text file before
an enumeration is assigned.
Program AHU1_SHUTDOWN
// Written: December 15, 1992 by Ryan Smith
// Modifications:
//
None
// Properties modified:
//
2-8
Example Program 2:
This is the same CPL text file after the CPL
Editor assigns the enumeration.
Defint Priority_Shutdown = 6
Program AHU1_SHUTDOWN
// Written: December 15, 1992 by Ryan Smith
// Modifications:
//
None
// Properties modified:
//
IF
2-9
Assigning Arrays
Tracer Summit CPL allows arrays of objects
and/or properties to be created to reduce the
number of CPL statements needed for a CPL
program. Arrays also make it easier to edit a
CPL program once it has been created by
arranging objects/properties in a specific
order. Arrays are typically used in CPL
programs where repetitive calculations are
performed (such as programs that use
FOR...NEXT statements).
Syntax:
Defint
[6]
[1]={object}.{property}
BIP[2]={object}.{property}
BIP[3]={object}.{property}
BIP[4]={object}.{property}
BIP[5]={object}.{property}
BIP[6]={object}.{property}
BIP
BIP
Defobj
[6]
[1]={object}
BOP[2]={object}
BOP[3]={object}
BOP[4]={object}
BOP[5]={object}
BOP[6]={object}
BOP
BOP
2-10
Example Program:
The following example is a program that
looks at the status of binary inputs set up in
an array, goes through this array in the
program, and matches a binary output to the
binary input. The binary output might be
directed to another TCM binary output that
controls a lighting status panel somewhere
else in the facility.
PROGRAM
Motion_Status_Lights
2-11
DEFOBJ
BOPS[NUMB]
2-12
2-13
Example Program:
In the following example, a timing function
is performed based on a local saved value.
Program Exhaust_Fan1
// Written 3/22/97 by Eugene Jones
// Properties modified:
//
{Exhaust Fan1}.{Present Value}
//
Local.{Saved Value}[1]
// Properties read:
//
{Warehouse Temperature}.{Present Value}
//
{Warehouse Exhaust Fan Setpoint}.{Present Value}
/// This program controls the exhaust fan for the warehouse on anytime the space
/// temperature exceeds setpoint for 10 minutes.
/// This program is executed every minute to keep timers in sync.
/// This CPL object uses the text file named EXHAUST1.CPL
Defint
Off = 0, //Enumeration for Off
On = 1, //Enumeration for On
Timer_1
// If space temperature is 1 F above setpoint, start 10 minute timer
If
({Warehouse Temperature}.{Present Value} > ({Warehouse Exhaust Fan Setpoint}.{Present
Value} +1))
Then
Timer_1 = Local.{Saved Value}[1] + 1
Else
Timer_1 = 0
End If
// Control the exhaust fan On or Off
If (Timer_1 > 10) Then
Control({Exhaust Fan1}, {Present Value}, On, 5, SET)
Else
Control({Exhaust Fan1}, {Present Value}, Off, 5, SET)
End If
// Store Timer value for the next execution
Local.{Saved Value}[1] = Timer_1
End
2-14
2.
3.
4.
5.
2-15
2.
3.
4.
5.
6.
2-16
3.
2.
3.
4.
5.
2-17
2.
4.
2-18
b.
2.
c.
d.
2-19
e.
f.
2-20
g.
h.
i.
j.
3.
b.
c.
2-21
3.
2.
2-22
CPL Syntax
CPL Program Words
ABS
AFTER
AND
AVG
Reserved words
CALL
Reserved words are those in the language
CASE
that have a predefined meaning like FOR, IF, CONTROL
or PROGRAM. Reserved words are case
CLNG
insensitive, meaning that the mix of
DATE
capitalized letters and lower case letters does DATENOW
not matter. For and FOR are regarded as
DATEVALUE
HOUR
IF
IMP
INT
IS
LESS_EQUAL
LET
DAY
DAYOFWEEK
DO
User-defined words
DEFINT
User-defined words are created by you and
are used as program names, variable names, DEFLNG
DEFFLT
subroutines, functions, and labels (for goto
DEFDBL
statements). Unlike reserved words,
DEFOBJ
user-defined words are case sensitive. This
means that the variables Temperature and DEFSTR
ELSE
temperature are different since in one
ELSEIF
instance the beginning letter is capitalized
and the other is lower case. You cannot use a END
EQV
reserved word as a user-defined word.
ERROR
User-defined words can be up to 32
EXIT
characters long (no spaces or reserved
characters). You are also restricted to 256
FIX
LOG
LOOP
MAX
MIN
MINUTE
MOD
MONTH
NEXT
NOT
NOT_EQUAL
NOW
OBJECT
OR
PRINT
PROGRAM
RELEASE
FOR
FUNCTION
GOTO
GREATER_EQUAL
REPEAT
RESUME
SECOND
SELECT
SET
SGN
SQR
STEP
STOP
SUB
SWITCH
TASK
THEN
TIME
TIMENOW
TIMEVALUE
TIMER
TO
UNTIL
VALUE
WAIT
WEEKDAY
WHEN
WHILE
XOR
YEAR
3-1
CPL Syntax
CPL Terminology
array
array bounds
assignment
boolean expression
condition
constant
expression
expression list
line label
logical operators
numerical operators
^, *, /, \, MOD, +, -
numeric-expression
object_var
operand
operator
prop-name
relational operation
relational operators
variable
3-2
CPL Syntax
Scope
Global scope names are those names visible
anywhere in the program. All function and
subroutine names have global scope and can
be used anywhere in the program, as well as
variables defined outside of a function,
subroutine, and the main program body.
Names defined in the main program body, a
subroutine, and a function have local scope
and can only be referenced inside the
routines encompassing body. It is possible
to define the same local and global variable
and, in this case, the compiler uses the local
name. When a variable name is referenced,
the compiler first checks local names for a
match and then it tries the global names for
resolution.
Names can be referenced before their
definition. Functions, subroutines, labels,
and variables can be used even when their
definition appears later in the program.
3-3
CPL Syntax
CPL Comments
Comments begin with two or three forward
slashes and extend to the end of the line as
follows:
// This is a comment that goes to the end of this line.
3-4
CPL Syntax
2.
2.
Object Variable
An object variable references an object on
the database.
Type characters are needed to identify
parameter types and function return values.
The type names, characters, and declaration
statements are shown in the table below.
Data Types
Type Name
Type
Character
Declaration
Statement
Integer
DEFINT
Long integer
&
DEFLNG
Single floating
point
DEFFLT
Double floating
point
DEFDBL
DEFOBJ
Object pointer
3-5
CPL Syntax
CPL Expressions
Expressions range from the simple to very
complex.
a = 1 // where 1 would be a simple expression
a = (((t / a) - 99.9) * ({Obj Ref}.{Property Ref}) * index) // a more complex expression
Description
Operators
=
< >
Not equal
Minus operator between two operands or unary minus with one operand
Multiplication operator
Division operator
Addition operator
3-6
<
Less than
>
Greater than
<=
>=
MOD
Modulo operator
CPL Syntax
CPL Statements
CPL statements are CPL specific keywords,
operators, and variables that perform
predefined operations.
Description
name
[optional item]
{choice1 | choice2}
repeating elements...
Three periods following indicate that more of the same item may
appear.
...statement_block...
3-7
CPL Syntax
CALL Statement
Syntax:
CALL subroutine-name [(argument-list)]
Comments:
The CALL statement transfers control to a
subroutine, not a function. The CALL
statement branches to a subroutine written in
CPL that is also in the text file. The
arguments to the subroutine must match the
parameters as specified in the definition of
the subroutine. The arguments may be either
variables, arrays, or expressions.
Arguments are passed by reference or by
value to procedures written in CPL. A
reference parameter passes the address of the
parameter so the original calling variable is
changed. When called by value, the original
variable is not modified. To prevent a
variable from being a reference parameter,
the variable is enclosed in parenthesis in the
CALL statement. CPL passes a copy of the
variable.
Example:
call sub_array_init( a[ ] )
call sub_var_init( i )
3-8
CPL Syntax
CONTROL Statement
Syntax :
({object-name}, {Present Value}, value, priority, SET | RELEASE)
CONTROL
Comments:
The CONTROL statement requests a change
to the state or value of the present value of an
object. The object must be specified. The
priority array for applications requesting
control of the same property is shown below.
Priority
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
NA
BACnet Default
Manual Life Safety
Auto Life Safety
Miscellaneous
Miscellaneous
Critical Equipment Control
Minimum On/Off
Custom Programming - High
Manual Operator
VAV Air Systems
Chiller Plant Control
Area Control
Manual Operator - Low
Miscellaneous
Timed Override
Time of Day Scheduling
Custom Programming - Low
Relinquish Default
Note: You can choose between the Tracer Summit and BACnet default priority levels. The names for
each priority level are editable and are customizable to suit each circumstance. Refer to Volume 2,
Software Setup in the Tracer Summit literature set for more information on customizing priority levels.
Note: BACnet defaults are applicable for Tracer Summit Version 5.0 and above. Refer to Volume
2, Software Setup or BAS-EB-59 for more information on BACnet.
Example:
Control statement using an object name:
control ({Object Reference}, {Present Value}, 10, 5, RELEASE) // using constants
3-9
CPL Syntax
DEFxxx Statement
Syntax:
xxx variable-name[(subscripts )],variable-name[(subscripts)]...
DEF
Comments:
The DEFxxx statement declares variables for
use in a CPL program. Note that variable
names are case sensitive, which means that
the variable temp is not the same as Temp.
Reserved words such as DEFINT are not case
sensitive and are recognized whatever the
mixture of capitals and lower case
characters. Arrays cannot be initialized and
begin with 1. There is no array[0]. Available
DEFxxx statements are:
DEFINT
Integer
DEFLNG
Long Integer
DEFFLT
DEFDBL
DEFOBJ
Object Pointer
Example:
temperature, average, outside_temp // simple variables
price = 10.23, percent = 100.00 // defines with initializations
DEFINT rooms[20], halls[10] // array declarations (arrays cant be initialized but can
// be assigned later).
DEFINT cnt, I = 0, seconds[60] // a mixture
DEFINT
DEFFLT
DEFOBJ
DEFINT LIMIT
DEFFLT
3-10
CPL Syntax
DO... Statement
Syntax:
DO
LOOP
Comments:
Condition is any expression the CPL
interpreter can determine to be true (non
zero) or false (0). CPL repeats the program
lines contained in the statement block(s) as
long as a WHILE condition is true or an
UNTIL condition is false.
When an EXIT DO statement is executed,
control is transferred to the statement that
follows the LOOP statement. When used
within a nested loop, an EXIT DO statement
moves control out of the immediately
enclosing loop.
Example:
Do while 1
// an endless loop
call Check_air_flow
call Check_temperature
wait 0:30:0
// Wait 30 minutes
Loop
Do While ( {Inside}.{Air Temperature}<Comfort_level )
call Increase_heat
Loop
Do while 1
// endless loop
wait 1:0:0
/// Beep the guard every hour to keep him awake
call beep_the_guard
if ( {Building}.{On Fire} )
exit DO
end if
Loop
3-11
CPL Syntax
ERR Variable
Syntax:
ERR
Comments:
ERR is a predefined variable that holds the
run-time error code for the last error that was
trapped by the interpreter. This predefined
variable is case sensitive. Using the
RESUME and WHEN ERROR statements
resets the ERR value to 0. To retain the value
of the error code stored in ERR, it should be
assigned to a variable. The value of ERR can
be set directly through an assignment
statement, and indirectly through the ERROR
statement.
A run-time error occurs at times when a
database access fails. An example is when a
CPL program is written referencing an object
in a BCU that is NOT AVAILABLE.
Example:
Error_handler: // label for error WHEN ERROR statement
if ( error_cnt = max_errors) // make sure we dont exceed the bounds of the array
stop
errors[ error_cnt ] = ERR // save the error code for later examination
error_cnt = error_cnt + 1 // increase the error count
ERR
RESUME AFTER
3-12
CPL Syntax
ERROR Statement
Syntax:
ERROR
errorcode
Comments:
ERROR errorcode simulates the occurrence
of a CPL or user-defined error. The
errorcode argument, which represents the
error code, must be an integer between 1 and
32,767. If an errorcode is one that CPL
already uses, the ERROR statement simulates
an occurrence of that error.
User-defined error codes should employ
values greater than those used for standard
CPL error codes. To ensure that non-CPL
error codes are chosen, user-defined codes
should work down from 32,767.
If an ERROR statement is executed, and
there is no error-handling routine enabled,
CPL ignores this statement and continues
running.
3-13
CPL Syntax
EXIT Statement
Comments:
EXIT statements are used with DO, FOR
functions, and REPEAT substatements and
routines. For more information on the use of
EXIT statements, refer to these CPL
statement descriptions for examples.
3-14
CPL Syntax
FOR...NEXT Statement
Syntax:
FOR
NEXT
Comments:
The FOR...NEXT statement repeats the
statement block a fixed number of times,
determined by the values of start, end and
step. (see the table below).
Example:
DEFINT
a[10], b[10], i
Argument
counter
Description
start
end
increment
3-15
CPL Syntax
FOR NEXT OBJECT Statement
Syntax:
FOR
Comments:
The NEXT OBJECT statement steps the
object_pointer variable to the next
occurrence of the object of the type the
object_pointer is referencing. This affects all
objects of this type in a given BCU.
Example:
Defobj chiller_obj = {Chiller 1}
chiller_obj
chiller_obj.{Diagnostic Exists} = 0
chiller_obj.{Summit Free Cooling Request} = 0
FOR
NEXT OBJECT
3-16
CPL Syntax
FUNCTION...END FUNCTION Statement
Syntax:
name type_character [(argument-list)]
name = expression
FUNCTION
END FUNCTION
Comments:
The FUNCTION...END FUNCTION structure
defines a function procedure. The purpose of
a function is to produce and return a single
value of a specified type. Recursion is
supported.
The parameters are specified as a
comma-separated list of parameter names.
Currently, the parameter names must end
with a type character (%, &, !, #, or @). If
no parameters are defined, the parenthesis
should not be used.
CPL procedures use both the
call-by-reference and call-by-value
conventions.
3-17
CPL Syntax
Example:
// This function returns the average of three temperatures supplied by the caller
Function Average_Temperature! (temp1!, temp2!, temp3!)
Average_Temperature = (temp1+temp2+temp3) / 3
End Function
Program Boca_Raton Hall_Temperature
defint hall_temperature
hall_temperature = Average_Temperature ({Hall 1}.{Present Value}, {Hall 2}.{Present Value},
{Hall 3}.{Present Value})
end
3-18
CPL Syntax
GOTO Statement
Syntax:
GOTO
{line label}
Comments:
GOTO sends control to a label. CPL does not
use line numbers. A label has the same
format as any other CPL name and it is
followed by a colon(:).
GOTOs cannot be used to transfer control out
Init_temps( Temps[] )
For i = 1 to 10
if (Temps[I] = 100) then
goto jump_here
end if
end for
jump_here:
call cool_it
end // frog
3-19
CPL Syntax
IF...THEN...ELSE...END IF Statement
Syntax A:
IF
Syntax B:
condition THEN
...statement_block...
[ELSEIF expression THEN
...statement_block...]
[ELSE
...statement_block...]
IF
END IF
Comments:
The IF...THEN...ELSE...END IF structure
organizes alternative actions into separate
blocks of code. The resulting action depends
on the logical value of one or more
conditions expressed in the structure.
The condition can be any expression that is
evaluated as true (non-zero) or false (zero).
Example:
if ((outside < 80) and (inside < 60))
then
call warm_it(inside, outside)
inside = new_temperature
end if
if (inside_temp < 90)
then
call under_ninety
elseif (inside_temp < 100)
then
call under_100
else
call over_100
end if
3-20
CPL Syntax
Comments:
Local is a predefined object variable that
provides the ability to reference the program
currently being written. It resolves a
chicken and egg situation when you want
to change the saved value array of the
program being written. Since the object has
not been created, any references to itself
would be unresolved at compile time and
generate an error.
3-21
CPL Syntax
Program_name
END
Comments:
One main program body has to appear in a
CPL program. Local variables may be
defined and used in its scope. The first
statement in the main program body is the
first statement executed when the program is
started. The program_name is the default
CPL program description when the program
object is created, but this description can be
changed in the CPL Editor. The program
name cannot have any spaces and can be up
to 32 characters long.
Example:
PROGRAM
Sample
(Program Statements)
END
3-22
CPL Syntax
REPEAT...Statement
Syntax:
REPEAT
...statement_block...
[EXIT REPEAT]
...statement_block...
LOOP {WHILE | UNTIL} condition
Comments:
Condition is any expression that CPL can
determine to be true (non zero) of false (0).
CPL repeats the program lines contained in
the statement block(s) as long as a WHILE
condition is true or an UNTIL condition is
false. At least one iteration of the loop
happens.
When an EXIT REPEAT statement is
executed, control is transferred to the
statement that follows the LOOP statement.
When used within a nested loop, an EXIT
REPEAT statement moves control out of the
immediately enclosing loop.
Example:
Cnt = 0
REPEAT
Cnt = Cnt + 1
(Cnt = 10)
LOOP UNTIL
3-23
CPL Syntax
RESUME Statement
Syntax:
RESUME [AFTER]
Comments:
The RESUME statement halts error-handling
code and returns back to the exact statement
that caused the error. When the RESUME
AFTER statement is used, control is passed
to the statement that immediately follows the
statement where the error occurred.
Example:
See WHEN ERROR or ERR
3-24
CPL Syntax
SELECT CASE Statement
Syntax:
test expression
[CASE expression list
...statement_block...]
[CASE expression list
...statement_block... ]
SELECT CASE
.
.
[CASE ELSE
...statement_block... ]
END SELECT
Comments:
The SELECT CASE statement executes one
of a series of statement blocks, depending on
the value of an expression.
The test expression can be any expression.
Each ...statement_block... can contain any
number of statements on any number of
lines.
The expression list(s) may be a
comma-separated list of expressions of the
following forms:
expression
expression TO expression
IS comparison_operator expression
3-25
CPL Syntax
1, 3, 5
Stop
CASE 2, 4, 6
Even = True
Go to Continue
CASE 7 TO 10, 17 TO 20 // short for 7, 8, 9, 10, 17, 18, 19, 20
call middle
call high_middle
CASE IS > 20 // all values greater than 20
call upper
CASE IS < 10 // all remaining values below 10
call lower
CASE index, Error_cnt - 1 // using variables and expressions
call variable
CASE ELSE // all leftovers
call leftovers
CASE
END SELECT
STOP
3-26
CPL Syntax
STOP Statement
Syntax:
STOP
Comments:
The STOP function halts program execution.
STOP statements can be used in any
statement block to terminate execution.
Example:
If (Outside Air Temperature > 50) Then
Cooling = On
Else
Stop
End If
3-27
CPL Syntax
SUB...END Statement
Syntax:
SUB
name [(parameters)]
EXIT SUB
END SUB
Comments:
The SUB...END SUB structure defines a
subroutine procedure. A call to a subroutine
stands alone as a separate statement. (See the
CALL statement.) Recursion is supported.
Parameters are specified as a commaseparated list of parameter names. Currently,
the parameter names must end with a type
character (@, %, &, !, or #). If no
parameters are defined, do not use
parenthesis.
The subroutine returns to the caller when the
END SUB statement is reached or when an
EXIT SUB statement is executed.
Subroutines have to be defined outside of
the main program body, functions, and other
subroutines. Subroutines can be referenced
before they are declared. The following
example does not cause a problem.
Example:
Program example // The programs main body can go anywhere in the program
call sub1 // defined below but not a problem
End
Sub sub1
defint b[10] // ten integers all aligned in an array
call sub2( b[ ] ) // The array will be changed by sub2
End Sub1
Sub sub2( array_var%[ ] )
array_var[1] = 10
End sub
3-28
CPL Syntax
Task Switch
Syntax:
Task Switch
Comments:
The Task Switch statement causes the
program to relinquish execution and allows
other active CPL programs an opportunity to
run.
Normally, CPL programs relinquish
execution by completing or waiting on some
condition. The Task Switch is useful for CPL
programs that have extremely long and/or
continuous (loop) runtimes.
Example:
For i = 1 to 100
VAV[i] = i + 2
If (i = 50) then
Task Switch
End If
Next
3-29
CPL Syntax
WAIT Statement
Syntax A:
WAIT
Wait_time
Syntax B:
WAIT
Syntax C:
WAIT
Comments:
The WAIT statement causes a pause at the
current point in the execution of this CPL
program. The wait can be time-based,
conditional, or a combination. Once the
WAIT is satisfied, control transfers to the
statement following the WAIT statement.
Time-based waits specify the number of
hours, minutes, and seconds to wait in the
following format:
For example: 0:1:0 // one minute
Conditional waits using the WHILE keyword
generate a pause in the execution as long as
the condition is true (zero), and continues
once the condition becomes false (non-zero).
Conditional waits using the UNTIL keyword
generate a pause in the execution as long as
the condition is false (non-zero), and
continue once the condition becomes true
(zero).
Example:
WAIT 24:0:0 // waits a day
// Wait 2 hours, 2 minutes, and 2 seconds or if the temperature level goes too low
WAIT 2:2:2 OR UNTIL ({Obj Ref}.{Present Value} < Comfort_level)
3-30
CPL Syntax
WHEN ERROR Statement
Syntax:
WHEN ERROR GOTO
label
Comments:
The WHEN ERROR statement enables an
error-handling alternative other than the
interpreter, specifying the location of the
CPL code within the procedure. Unless a
WHEN ERROR statement is used, any
run-time error is fatal (such as CPL
terminates the execution of the program).
The GOTO label enables the error-handling
routine that starts at label. The designated
label has to be in the same procedure as the
WHEN ERROR statement.
A runtime error occurs at times when
database access fails. Once an error-handling
routine is enabled, a run-time error results in
program control switching to the
error-handling label and activating the
error-handler. The error-handler remains
active from the time the run-time error is
trapped until a RESUME statement is
executed in the error-handler.
Example:
DEFINT
error_cnt = 0
3-31
CPL Syntax
WHEN ERROR
for i = 1 to how_many
obj_array[i].{Maximum} = limit // on error code below just in case...
next
EXIT SUB
error_handler:
error_cnt = error_cnt + 1
RESUME AFTER
end sub
3-32
CPL Syntax
WHILE...WHILE END Statement
Syntax:
condition
...statement_block...
WHILE
WHILE END
Comments:
The WHILE...WHILE END structure control a
repetitive action. As long as the condition
remains true (non-zero), the statements in the
statement_block are executed. Once the
condition becomes false (non-zero) control is
transferred to the statement following the
WHILE END.
Example:
While {Object Ref}.{Present Value} < minimum
call adjust
While end
3-33
CPL Syntax
CPL Functions
CPL functions are built-in subroutines that
return a single value to the CPL program.
The following section defines and illustrates
some uses for CPL functions. The following
predefined functions may appear as a simple
expression or in a complex expression.
ABS Function __________________________________
Syntax:
(numeric-expression)
ABS
Comments:
The ABS function returns the positive value
of the specified numeric-expression.
Example:
Temperature = Abs (Inside - 10)
Syntax:
(expression [, expression]...)
AVG
Comments:
AVG accepts a variable parameter list and
returns the average of the variables values.
Example:
DEFFLT VAVAVG
VAVAVG = AVG
3-34
CPL Syntax
CLNG Function
Syntax:
CLNG
(numeric-expression)
Comments:
Converts a numeric-expression to a long (4
byte) integer by rounding the fractional part
of the expression.
Example:
DEFINT
i=10
DEFLNG l
l = clng( i ) // converts the integer (i) to a long
DATE Function _________________________________
DATE
Comments:
Returns a 32-bit long value that is the date
for the passed in parameters. Parameters
are: four-digit year, month 1-12, day 1-31
Example:
DEFLNG date_of_Christmas
date_of_Christmas = date(1993, 12, 25)
3-35
CPL Syntax
DATENOW Function
Syntax:
DATENOW
Comments:
Returns a 32-bit long value that is the
current date. No parameters.
Example:
date_of_Christmas, today
date_of_Christmas = date(1993, 12, 25)
today = datenow
if (today = date_of_Christmas) then
...
end if
if (datenow = date_of_Christmas) then
end if
DEFLNG
DATEVALUE Function___________________________
DATEVALUE
Comments:
Returns a 32-bit long value that is the date
for the passed in string. The string format
is mm-dd-yyyy
Example:
DEFLNG
date_of_Christmas
3-36
CPL Syntax
DAY Function
Syntax:
(expression)
DAY
Comments:
Returns 1-31 from a time-date long value.
Example:
DEFLNG
the_day
(numeric-expression)
Comments:
FIX returns the integer part of a
numeric-expression. The argument given is
any numeric-expression. For both positive
and negative numeric-expressions, FIX
removes the fractional part of the expression
and returns the integer part only. For
example: FIX (1.5) returns 1, FIX (-1.5)
returns -1.
Example:
DEFINT
a, b
DEFFLT
b, f=10.5
a = -10
b = abs( a ) + fix( f ) // b would have the value of 20.0
3-37
CPL Syntax
HOUR Function
Syntax:
HOUR
(expression)
Comments:
Returns 0-23 from a time-date long value.
Example:
hour_is
hour_is = hour(timenow)
DEFINT
Comments:
INT returns the largest integer less than or
equal to the numeric-expression. The INT
function returns the integer part of any
numeric-expression. For positive
numeric-expressions, INT removes the
fractional part of the expression and returns
the integer part only. For negative
numeric-expressions, INT returns the largest
integer less than or equal to the expression.
For example, INT (1.5) returns 1, and INT
(-1.5) returns -2.
3-38
CPL Syntax
LOG Function
Syntax:
LOG
(numeric-expression)
Comments:
LOG returns the natural logarithm of the
numeric-expression.
Example:
Defflt
OATEMP
OATEMP
(expression [, expression]...)
Comments:
MAX accepts a variable parameter list and
returns the largest value in it.
Example:
DEFFLT VAVMAX
VAVMAX = MAX
3-39
CPL Syntax
MIN Function
Syntax:
MIN (expression [, expression]...)
Comments:
MIN accepts a variable parameter list and
returns the minimum value from it.
Example:
DEFFLT VAVMIN
VAVMIN = MIN
Syntax:
(expression)
MINUTE
Comments:
Returns 0-59 from a long value (typically
the return from the TIMENOW function).
Example:
minute_is
minute_is = minute(timenow)
DEFINT
3-40
CPL Syntax
MONTH Function
Syntax:
MONTH
(expression)
Comments:
Returns 1-12 from a long value (typically
the return from the DATENOW function).
Example:
month_is
month_is = month(datenow)
DEFINT
Comments:
Returns a 32-bit long value that is the
current date and time. No parameters.
Example:
DEFLNG
todays_date_and_time = now
3-41
CPL Syntax
SECOND Function
Syntax:
Second (expression )
Comments:
Returns 0-59 from a long value (typically
the return from the TIMENOW function).
Example:
second_is
second_is = second(timenow)
DEFINT
Syntax:
SGN
(numeric-expression)
Comments:
SGN returns a value indicating the
numeric-expression sign. The value is:
+1 if numeric-expression
0 if numeric-expression
-1 if numeric-expression
> 0.
= 0.
< 0.
(numeric-expression)
Comments:
SQR returns the square root of the
numeric-expression.
Example:
Velocity
Velocity = Flow_Coef x SQR(Pressure - 4)
DEFINT
3-42
CPL Syntax
TIME Function
Syntax:
TIME
Comments:
Returns a 32-bit long value that is the time
for the passed in parameters. Parameters
are: hour, minute, second. The TIME
function returns the number of seconds that
have elapsed since midnight.
Example:
DEFLNG
noon
noon = time(12, 0, 0)
TIMENOW Function _____________________________
Syntax:
TIMENOW
Comments:
Returns a 32-bit long value that is the
current time. No parameters. The TIMENOW
function returns the number of seconds that
have elapsed since midnight.
Example:
DEFLNG noon
noon = time(12, 0 , 0)
if (noon > timenow) then
...
end if
3-43
CPL Syntax
TIMER Function
Syntax:
TIMER
Comments:
The TIMER function returns the number of
seconds that have elapsed since midnight.
Example:
DEFLNG A
A = TIMER
Syntax:
(String-Constant)
TIMEVALUE
Comments:
Returns a 32-bit long value that is the time
for the passed in string. The string format
is hh:mm:ss.
Example:
noon
noon = timevalue(12:00:00")
DEFLNG
3-44
CPL Syntax
WEEKDAY Function
Syntax:
WEEKDAY
(expression)
Comments:
Returns a 32-bit long value that is the date
for the passed in parameters. Parameters
are: Sunday = 1.
Example:
DEFINT
current_day = Weekday(now)
Syntax:
(expression)
YEAR
Comments:
Returns a four-digit year value from a
time-date long value.
Example:
year_is
year_is = year(datenow)
DEFINT
3-45
CPL Syntax
3-46
Appendix A
Example CPL Programs
The following programs present previously created CPL programs that may be modified to
suit your needs when setting up the Tracer Summit system.
Resetting an Air Handler
Program AHU_Reset
//
// Written: March 18, 1997 by R. Trane
//
// Properties Modified:
//
{AHU 1 Setpoint}.{Present Value}
//
// Properties Read:
//
{Zone X Temperature}.{Present Value} (X = 1 - 4)
//
{AHU 1 Setpoint}.{Present Value}
//
/// Entrant: This program should have an execution frequency of once a minute.
//
/// This program determines the setpoint for Air Handler based
/// on the maximum temperature of the areas it serves.
//
/// This program uses the text file AHURESET.CPL
Defflt
MaxTemp,
TempSetpt,
ActualSetpt
// Determine the maximum temperature of the four zones.
MaxTemp = Max({Zone 1 Temperature}.{Present Value},
{Zone 2 Temperature}.{Present Value},
{Zone 3 Temperature}.{Present Value},
{Zone 4 Temperature}.{Present Value})
(Continued on next page...)
A-1
Appendix A
A-2
Appendix A
A-3
Appendix A
For i = 15 to 2 Step -1
Local.{Saved Value}[i] = Local.{Saved Value}[i-1]
Next
For i = 1 to 3 Step 1
Phase[i] = Volts[i] * Amps[i]
Power = Power + Phase[i]
Next
Watts = Power * PowFac / 100
Local.{Saved Value}[1] = Watts / 1000
For i = 1 to 15 step 1
Powersum = Powersum + Local.{Saved Value}[i]
Next
Local.{Saved Value}[16] = Powersum / 15
End
A-4
Appendix A
Chiller Rotation
Program Chiller_Rotation
//
// Written 3/1/97 by Carl Summit
//
// Properties Read:
//
{Chiller #1 Sequence Number}.{Present Value}
//
// Properties Modified:
//
{Chiller #1 Sequence Number}.{Present Value}
//
/// This program will change the Chiller Sequence numbers if
/// the current day and time in the BCU are equal to the selected
/// Rotation day and time.
//
/// This program is executed every hour.
//
/// This CPL object uses the text file named CHLR_ROT.CPL
Defint
Chlrs = 3,
RotDay = 4,
RotHour = 9,
CurDay, // Current Day
CurHour,
TempSeq
// Number of Chillers
// Rotation Day
// Rotation Hour
// Current Hour
// Temporary Sequence Number
// If rotation day and time are correct, rotate the chillers. (Wed, 9:00 A.M.)
If ((CurDay = RotDay) And (CurHour = RotHour))
Then
TempSeq = TempSeq + 1
If TempSeq > Chlrs Then
TempSeq = 1
End If
End If
// Make sure Temporary Sequence is a valid number
TempSeq = Min(TempSeq, Chlrs)
TempSeq = Max(TempSeq, 1)
// Set current sequence equal to Temporary Sequence
Control({Chiller #1 Sequence Number}, {Present Value}, TempSeq, 5, Set)
End
A-5
Appendix A
Calculating Dewpoint
Program Dewpoint
//
// Written: March 1, 1997 by R. Trane
//
// Modifications:
//
3/8/97 DJU;
//
Divide humidity by 100 to attain percent. Testing
//
indicates correct value.
//
// Properties modified:
//
{Dewpoint}.{Present Value}
//
// Properties read:
//
{Outdoor Air Temperature).{Present Value}
//
{Humidity}.{Present Value}
//
/// Entrant: This program should have an execution frequency of once a minute.
//
/// This program determines the dewpoint based on dry bulb temperature and Humidity.
/// The result is stored in the present value of the dewpoint object. It also triggers the
/// execution of the Enthalpy CPL routine.
//
/// This CPL object uses the text file named DEWPOINT.CPL.
Defflt
Humidity,
Dry_Bulb,
Dewpnt // Dewpoint value.
A-6
Appendix A
Calculating Enthalpy
Program Enthalpy
//
// Written: March 1, 1997 by R. Trane
// Testing indicates correct value.
//
// Properties modified:
//
{Enthalpy}.{Present Value}
//
// Properties read:
//
{Outdoor Air Temperature}.{Present Value}
//
{Outdoor Air Humidity}.{Present Value}
//
/// Entrant: This program is run from the Dewpoint CPL routine.
//
/// This program determines enthalpy based on Dry Bulb temperature and Humidity.
/// The result is stored in the present value of the enthalpy object.
//
/// This program uses the text file named ENTHALPY.CPL
Defflt
Dry_Bulb,
Humidity,
Enthlpy // Enthalpy value.
A-7
Appendix A
//
{System Chilled Water Setpoint}.{Present Value}
//
// Properties Modified:
//
{Upstream Chiller Setpoint}.{Present Value}
//
// Routine Summary:
/// This routine calculates the setpoint for the upstream chiller in a series chiller pair.
//
/// Routine Execution: This program is executed every minute.
//
/// Routine Text File: This CPL object uses the text file named SER_STPT.CPL
//
//
***** Define and Initialize Variables *****
// In the first three sections of this routine, the programmer must define the variables used
// throughout this routine. Only variables in the User Edited Variables section should
// be changed.
Defobj
Upstream_Chlr,
Downstream_Chlr,
Setpoint
Sys_Sup,
Sys_Ret,
Sys_Delta,
Sys_Stpt,
Upstream_Stpt,
Defflt
Setpoint
//******************** User edited variables ***********************
Min_Setpt = 40.0
// minimum Chiller chilled water setpoint
A-8
Appendix A
Defint
Upstream_Cap = 400,
Downstream_Cap = 400
//
***** Initialize Objects *****
// In this section chiller and setpoint objects are assigned. The object names must match the
// names in the database exactly. The programmer should use the Add Object
// selection found under the Edit menu in the CPL editor to complete this section.
Upstream_Chlr = {Chiller 1}
Downstream_Chlr = {Chiller 2}
Setpoint = {Upstream Chiller Setpoint}
//
***** Initialize Variables *****
// In this section system temperatures are assigned or calculated. The object and property
// names must match the names in the database exactly. The programmer should use the Add
// Obj&Property selection found under the Edit menu in the CPL editor to complete this
// section.
Sys_Sup = {Chilled Water Supply}.{Present Value}
Sys_Ret = {Chilled Water Return}.{Present Value}
Sys_Stpt = {System Chilled Water Setpoint}.{Present Value}
//************* End of user edited variables *********************
//
***** Calculate and Validate Upstream Chiller Setpoint *****
// In this section the upstream chiller setpoint is calculated. If both chillers are not in the
// occupied mode the setpoint is set to the system setpoint. The setpoint calculation is done
// only when both chillers are occupied. In both instances the new setpoint is validated so it is
// never less than the minimum setpoint. No changes are required in this section.
Sys_Delta = Sys_Ret - Sys_Sup
If (Upstream_Chlr.{Present Value} <> 0) and (Downstream_Chlr.{Present Value} <> 0) Then
Upstream_Stpt=Sys_Stpt+(Sys_Delta*(Upstream_Cap/(Upstream_Cap+Downstream_Cap)))
Else
Upstream_Stpt = Sys_Stpt
End If
Upstream_Stpt = Max (Upstream_Stpt, Min_Setpt)
(Continued next page...)
A-9
Appendix A
//
***** Upstream Chiller Chilled Water Setpoint *****
// In this section the Analog output point in the database is controlled to the value calculated in
// the section above. The control is // only done when a change occurs. No changes are
// required in this section.
If (Setpoint.{Present Value} <> Upstream_Stpt) Then
(Setpoint,{Present Value},Upstream_Stpt,16,SET)
CONTROL
End If
End
A-10
// end of routine
Appendix A
st
Floor VAV
Program VAV_INFO
//
// Written: July 9, 1997 by R. Trane
//
// Properties Modified:
//
Local.{Saved Value}[1] = First floor Max Air Valve Position
//
Local.{Saved Value}[2] = First floor Max Zone Temperature
//
Local.{Saved Value}[3] = First floor Min Air Valve Position
//
Local.{Saved Value}[4] = First floor Min Zone Temperature
//
Local.{Saved Value}[5] = First floor Avg Zone Temperature
//
// Properties Read:
//
{Room 100}.{Air Valve Position}
//
{Room 100}.{Zone Temperature}
//
{Room 110}.{Air Valve Position}
//
{Room 110}.{Zone Temperature}
//
{Room 120}.{Air Valve Position}
//
{Room 120}.{Zone Temperature}
//
{Room 130}.{Air Valve Position}
//
{Room 130}.{Zone Temperature}
//
{Room 140}.{Air Valve Position}
//
{Room 140}.{Zone Temperature}
//
{Room 150}.{Air Valve Position}
//
{Room 150}.{Zone Temperature}
//
{Room 160}.{Air Valve Position}
//
{Room 160}.{Zone Temperature}
//
{Room 170}.{Air Valve Position}
//
{Room 170}.{Zone Temperature}
//
{Room 180}.{Air Valve Position}
//
{Room 180}.{Zone Temperature}
//
{Room 190}.{Air Valve Position}
//
{Room 190}.{Zone Temperature}
//
/// Entrant: This program should have an execution frequency
/// of once a minute.
//
/// This program determines the maximum and minimum air valve
/// positions as well as maximum, minimum and average zone
/// temperatures for the VAV boxes on the first floor.
//
/// This program uses the text file VAV_INFO.CPL
A-11
Appendix A
Defint
i,
// For loop index.
Boxes = 10
(Continued...)
vavbox[Boxes]
Defobj
Defflt
TempSum,
// Sum of the temperatures for average
calculation.
Position, // Air valve position of the VAV box being processed.
Temp, // Zone temp of the VAV box being processed.
MaxPos, // Maximum air valve position (initialized to 0).
MaxTemp,
// Maximum zone temperature (initialized to 0).
MinPos = 100.0,
// Minimum air valve position (initialized to
100).
MinTemp = 100.0,
// Minimum zone temperature (initialized to
100).
AvgTemp
// Average zone temperature (initialized to 0).
// Load the vavbox array with the VAV objects.
vavbox[1] = {Room 100}
vavbox[2] = {Room 110}
vavbox[3] = {Room 120}
vavbox[4] = {Room 130}
vavbox[5] = {Room 140}
vavbox[6] = {Room 150}
vavbox[7] = {Room 160}
vavbox[8] = {Room 170}
vavbox[9] = {Room 180}
vavbox[10] = {Room 190}
For i = 1 to Boxes step 1
Position = vavbox[i].{Air Valve Position}
Temp = vavbox[i].{Zone Temperature}
TempSum = TempSum + Temp
// Check each box for having an Air Valve position greater than the previous
// maximum position. Update if necessary.
A-12
Appendix A
If (Position>MaxPos) Then
MaxPos = Position
End If
// Check each box for having a Zone Temperature greater than the previous
// maximum temperature. Update if necessary.
If (Temp > MaxTemp) Then
MaxTemp = Temp
End If
// Check each box for having an Air Valve position less than the previous
// minimum position. Update if necessary.
If (Position < MinPos) Then
MinPos = Position
End If
// Check each box for having a zone temperature less than the previous
// minimum temperature. Update if necessary.
If (Temp < MinTemp) Then
MinTemp = Temp
End If
Next
// Save the calculated values.
Local.{Saved Value}[1] = MaxPos
Local.{Saved Value}[2] = MaxTemp
Local.{Saved Value}[3] = MinPos
Local.{Saved Value}[4] = MinTemp
Local.{Saved Value}[5] = TempSum / Boxes
End
// Program VAV_INFO
A-13
Appendix A
// Define enumerations
A-14
Appendix A
A-15
Appendix A
A-16
Appendix B
CPL Error Codes
Error
Error-30
Error-39
Possible Cause
Possible Solution
Error-103
Error-250
Error-251
B-1
Appendix B
Error
Possible Cause
Possible Solution
Error-252
Error-253
Error-254
CPL
BCX_ITRP
Error-255
Error-256
Error-257
Error-258
Error-259
Error-260
B-2
Appendix B
Error
Possible Cause
Possible Solution
Error-261
Error-262
Error-263
Error-264
Error-265
Error-266
Error-267
Error-268
Error-269
Error-307
B-3
Appendix B
B-4
Index
A
ABS function, 3-34
Add
Function, 1-5
Object, 1-5
Object & Prop., 1-5
Statement, 1-5
Add Enum. Bool., 1-5 2-5
example program, 2-8
Assigning arrays, 2-10
example program, 2-11
Assigning enumerations, 2-5
Assigning objects and properties, 2-4
directly referencing objects, 2-4
indirectly referencing objects, 2-4
AVG function, 3-34
C
CALL statements, 3-8
Calling Sequence, 1-7
CASE ELSE statements, 3-26
Check box, 1-iv
Checking text file syntax, 2-17
Clear Break, 1-7
CLNG functions, 3-35
Comments, 3-4
Compile, 1-6
Compiling
CPL text files, 2-16
text files, 2-18
Control Statements
priority, 3-9
CONTROL statements, 3-9
CPL
Add Enum. Bool, 2-5
applications, 1-1
assigning arrays, 2-10
assigning enumerations, 2-5
assigning objects and properties, 2-4
checking text file syntax, 2-17
comments, 3-4
compiling CPL text files, 2-16
compiling text files, 2-18
creating a CPL objects, 2-19
creating text files, 2-1
editing text files, 2-1
error codes, B-1
example programs, 2-2 A-1
expressions, 3-6
features, 1-1
functions, 3-34
loading files into the editor, 2-16
menu location, 1-3
overview, 1-2
program words, 3-1
purpose, 1-1
replacing CPL objects, 2-21
required procedures, 1-2
saving CPL text files, 2-15
statements, 3-7
Terminology, 3-2
testing CPL programs, 2-22
using saved values, 2-13
CPL terms, 3-1
Create CPL Object function, 1-6
Creating CPL objects, 2-19
Creating CPL text files, 2-1
Index-1
Index
D
Data types, 3-5
Floating Point variables, 3-5 3-10
Integer variables, 3-10
Object variables, 3-5 3-10
Data Types
Integer variables, 3-5
DATE functions, 3-35
DATENOW functions, 3-36
DATEVALUE functions, 3-36
DAY functions, 3-37
Debug Color, 1-7
Debug Program, 1-7
DEFxxx statements, 3-10
DO... statements, 3-11
Drop down list box, 1-iv
E
Editing CPL text files, 2-1
assigning arrays, 2-10
assigning enumerations, 2-5
assigning objects and properties, 2-4
checking text file syntax, 2-17
compiling CPL text files, 2-16
compiling text files, 2-18
creating CPL objects, 2-19
loading files into the editor, 2-16
replacing CPL objects, 2-21
saving CPL text files, 2-15
testing CPL programs, 2-22
using saved values, 2-13
Entry field, 1-iv
ERR variable, 3-12
Error codes, B-1
Index-2
F
FIX functions, 3-37
Floating Point variables, 3-5
Double, 3-5 3-10
Single, 3-5
Floating Point Variables
Single, 3-10
FOR NEXT OBJECT statements, 3-16
FOR...NEXT statements, 3-15
FUNCTION...END FUNCTION statements,
3-17
Functions, 3-34
ABS, 3-34
AVG, 3-34
CLNG, 3-35
DATE, 3-35
DATENOW, 3-36
DATEVALUE, 3-36
DAY, 3-37
FIX, 3-37
HOUR, 3-38
INT, 3-38
LOG, 3-39
MAX, 3-39
MIN, 3-40
MINUTE, 3-40
MONTH, 3-41
NOW, 3-41
SECOND, 3-42
SGN, 3-42
SQR , 3-42
TIME, 3-43
TIMENOW, 3-43
TIMER, 3-44
Index
TIMEVALUE, 3-44
WEEKDAY, 3-45
YEAR, 3-45
MONTH functions,
3-41
H
Home Halt Point,
HOUR functions,
1-7
3-38
I
IF...THEN...ELSE...END IF statements,
3-20
Inhibit DB Writes, 1-7
INT functions, 3-38
Integer variables, 3-5
Integer, 3-5 3-10
Long Integer, 3-5 3-10
L
List box, 1-iv
Loading files into the editor,
Local - Predefined variable,
LOG functions, 3-39
Long Integer, 3-5 3-10
Priority
Control statements, 3-9
Program END statements, 3-22
Program words, 3-1
CPL terms, 3-1
reserved words, 3-1
scope, 3-3
user-defined words, 3-1
Push buttons, 1-iv
Q
2-16
3-21
M
MAX functions, 3-39
Maximize button, 1-iii
Menu description, 1-4 - 1-8
Menu location, 1-3
MIN functions, 3-40
Minimize button, 1-iii
MINUTE functions, 3-40
Query Lines,
1-8
R
Radio button, 1-iv
Repeat statements, 3-23
Replace CPL Object function, 1-6
Replacing CPL objects, 2-21
Required procedures, 1-2
Reserved words, 3-1
RESUME statements, 3-24
Run Program, 1-7
S
Index-3
Index
U
User-defined words, 3-1
Using saved values, 2-13
example program, 2-14
V
Variable
ERR, 3-12
Local - Predefined,
View Variable, 1-7
3-21
W
WAIT statements, 3-30
WEEKDAY functions, 3-45
WHEN ERROR statements, 3-31
WHILE...WHILE END statements,
Word Wrap, 1-8
3-33
Y
YEAR functions,
3-45
T
Task switch, 3-29
Terminology, 3-2
Index-4