Programma Di Script (Inglese)
Programma Di Script (Inglese)
Topics
Script Overview
Script Workflow
Script Programs
Creating a Script Program
Opening a Script Program or Function
Script Keywords
Script Program Flow
FallThru Program Flow
Looping Program Flow
Script Program Instructions
Lines and Line Numbers
Reserved Words
Script Reserved Words
Bindings and Script Programs
Binding Values in Script Editor Using a Binding Template
Local Variable Declarations
Tasks
Adding a Task to a Program
Program Cycles in EcoStruxure Building Operation Software
Configuring the Execution Precedence for a Program
59 Finding Cycles in a Task
59 Script Introduction
59.1 Script Overview
For more information, see section 60.1 “Script Program Components” on page
1651.
For more information, see section 59.4 “Creating a Script Program” on page 1607.
Note
In Script, you can bind using either the Bindings view in WorkStation, or the
Bindings view in Script Editor. For more information, see section 46.10 “Binding
Values Using a Binding Template” on page 1246.
59.3.4 Tasks
Function block and Script programs must be connected to tasks in order to run.
You access Tasks from the Properties dialog box.
The task is a property of the object that defines the program cycles.
When you create a new function block or Script program, Task 3 is the default. This
means that one program cycle executes in 1000 ms.
For more information, see section 59.17 “Tasks” on page 1634.
59.6.1 A-D
This table contains keywords that begin with the lettters A - D.
A B C D
ATAN Buffered
For more information, For more information,
see section 60.160 see section 60.63
“ATAN” on page “Buffered” on page
1877. 1755.
Continued
A B C D
ATAN2
For more information,
see section 60.161
“ATAN2” on page
1878.
AVERAGE
For more information,
see section 60.137
“AVERAGE” on page
1845.
59.6.2 E-H
This table contains keywords that begin with the letters E - H.
E F G H
FOR...NEXT
For more information,
see section 60.51
“FOR...NEXT” on
page 1734.
FREEMEM
For more information,
see section 60.95
“FREEMEM” on page
1793.
59.6.3 I-N
This table contains keywords that begin with the letters I -N.
I L M N
LN MINIMUM
For more information, For more information,
see section 60.121 see section 60.140
“LN” on page 1827. “MINIMUM” on page
1851.
LOG MINITEM
For more information, For more information,
see section 60.122 see section 60.141
“LOG” on page “MINITEM” on page
1828. 1853.
MINUS
For more information,
see section 60.28
“MINUS” on page
1695.
MINUTE
For more information,
see section 60.86
“MINUTE” on page
1782.
MOD
For more information,
see section 60.29
“MOD” on page
1696.
Continued
I L M N
MONTH
For more information,
see section 60.87
“MONTH” on page
1783.
MOVE
For more information,
see section 60.54
“MOVE” on page
1744.
59.6.4 O-S
This table contains keywords that begin with the letters O - S.
O P R S
Continued
O P R S
RIGHT SIN
For more information, For more information,
see section 60.149 see section 60.163
“RIGHT” on page “SIN” on page 1880.
1864.
ROUND StandardDeviatio
n
For more information,
see section 60.134 For more information,
“ROUND” on page see section 60.142
1842. “StandardDeviation”
on page 1855.
STOP
For more information,
see section 60.58
“STOP” on page
1750.
STRING
For more information,
see section 60.44
“STRING” on page
1724.
STRINGFILL
For more information,
see section 60.152
“STRINGFILL” on
page 1867.
STRTODATE
For more information,
see section 60.115
“STRTODATE” on
page 1819.
STRTONUM
For more information,
see section 60.116
“STRTONUM” on
page 1821.
SQRT
For more information,
see section 60.124
“SQRT” on page
1830.
SUM
For more information,
see section 60.125
“SUM” on page
1831.
59.6.5 T-Y
This table contains keywords that begin with the letters T - Y.
T W Y
TAN WebService
For more information, see For more information, see
section 60.164 “TAN” on section 60.46 “ Webservice”
page 1881. on page 1727.
TIMEPIECE WEEKDAY
For more information, see For more information, see
section 60.156 “TIMEPIECE” section 60.91 “WEEKDAY”
on page 1873. on page 1788.
TOD WHILE
For more information, see For more information, see
section 60.89 “TOD” on section 60.60 “WHILE” on
page 1786. page 1752.
TD WriteProperty
For more information, see For more information, see
section 60.78 “TD” on page section 60.129
1772. “WriteProperty” on page
1836.
TH
For more information, see
section 60.77 “TH” on page
1771.
THE
For more information, see
section 60.45 “THE” on page
1726.
TIMES
For more information, see
section 60.31 “TIMES” on
page 1698.
TM
For more information, see
section 60.76 “TM” on page
1770.
TS
For more information, see
section 60.75 “TS” on page
1769.
Continued
T W Y
TURN
For more information, see
section 60.38 “TURN” on
page 1712.
TRUNCATE
For more information, see
section 60.135 “TRUNCATE”
on page 1843.
You configure the trigger for the OCCUPIED point on the b3 field controller. Note
that you can only configure triggers on the b3 device. For more information, see
section 100.10 “Configuring Script FallThru Program Triggers in a b3 BACnet
Device” on page 3746..
• Use one verb element or a list of verb elements after the verb
For example, these Script program instructions are valid:
OPEN THE DAMPER
CLOSE THE VALVE
Open the damper, vent1, vent2, vent3, and vent4
Close the firstvalve, secondvalve, thirdvalve
You cannot use two verbs, such as open and close, in the same instruction.
Therefore, this instruction is invalid:
OPEN THE DAMPER AND CLOSE THE VALVE
Arctange Dt Equal
nt
Arctange Equals
nt2
Arg Erase
Asc Errors
Execute
Asin Exists
Ask Exp
Atan Exponenti
al
Atan2
Continued
A B C D E F G H
Average
Averaged
Avg
Minute Sine
Mod Site
Modify Sqrt
Month Standard
-
Deviation
Move Start
Mth Status
Mult StatusLin
e
Multiplied Step
Stop
String
Stringfill
Continued
I L M N O P R S
StrToDat
e
StrToNu
m
StrToTim
e
Sum
Td Update While
Th UpdateAlarms With
The UpdateExitLog
Then
Through
Thru
Time
TimeOfDay
Timepiece
Times
TmTo
Tod
Touchedcell
Trace
Trunc
Truncate
Continued
T U V W
Ts
Turn
Note
With bindings, you are not limited solely to the properties of points and programs.
You can also use other object types.
For more information, see section 59.16 “Local Variable Declarations” on page
1630.
3. In the Confirm Bindings dialog box, select the bindings that you want to
create.
4. Click OK.
5. In the Bindings View, verify that all bindings are correctly bound.
6. On the toolbar, click Save.
Note
With bindings, you are not limited solely to the properties of points and programs.
You can also use other object types.
During execution, when the program gets the value of an Input variable, the
program gets the value of the object property (the value of a point). When the
program sets the value of an Output variable, the program sets the value of the
object property (the value of a point).
You can use a binding with the following:
• Input variables
• Output variables
• Public variables
• User-Defined Functions
Any hardware or software input, output device like a fan, motion sensor, or a Script
function is represented as an object in the EcoStruxure Building Operation
database. When you create a local variable in Script, that variable is generic and
can potentially be associated with the object property and the local variable that
property is bound to. The object property and the local variable must have similar
types. For example, you bind a numeric local variable to an integer, float, digital, and
enumeration instead of a string or datetime.
Tip
Corresponding properties tabs are displayed, one for each binding type. These
tabs list each of the local variables that can be bound to other objects in the
system.
In Script, you can bind using either the Bindings view in WorkStation, or the
Bindings view in the Script Editor. For more information, see section 46.10 “Binding
Values Using a Binding Template” on page 1246.
Using the Bindings view in Script Editor, you can slide the view, overlay your Script
program, bind the necessary objects, retract the view, and then resume
programming without leaving the Script Editor.
59.17 Tasks
Function block and Script programs must be connected to tasks in order to run.
You access Tasks from the Properties dialog box.
The task is a property of the object that defines the program cycles.
When you create a new function block or Script program, Task 3 is the default. This
means that one program cycle executes in 1000 ms.
Figure: Tasks
The way you schedule programs to execute in Script differs from how you schedule
them to execute in Continuum. For more information, see the Script and Plain
English Program Differences topic on WebHelp.
Task 3 1 seconds
Task 4 5 seconds
Task 5 10 seconds
Figure: In an algebraic loop the execution order of programs cannot easily be determined.
To resolve a cycle and determine which program runs first in the cycle, you use the
execution precedence function. Programs can have execution precedence values
ranging from 0 to 255 where 0 results in the highest priority and 255 results in the
lowest priority. The program with highest execution precedence is always executed
first in the cycle.
Execution Precedence
The execution precedence is configured in the properties for the program. The
default value when you create a new program is 100.
59.19.1 Example A
In this example we have four programs that are connected in a cycle. The execution
order cannot be determined from how programs are bound. Program 1 should run
before Program 2, Program 2 before Program 3, and Program 4 before Program 1.
Figure: Example
However, Program 2 reads from a physical input, Input A, and the information from
this reading is transferred to Program 4, which writes to a physical output, Output
B.
Figure: Example
So, we want to Program 2 to run before Program 4. To do this we use execution
precedence. By configuring the Execution precedence as 99 for Program 2,
Program 2 will be the first program to be executed in the cycle.
Figure: Example
The resulting execution order will be P2, P3, P4 and P1.
59.19.2 Example B
All programs use the default execution precedence that is 100. In this example, it is
not possible to determine the execution order of Program 1 and Program 2 and the
execution order of Program 3 and Program 4. The only thing we can be sure of is
that the cycle with Program 1 and Program 2 is executed before the cycle with
Program 3 and Program 4 due to the fact that Program 3 awaits input from
Program 2.
Figure: Example
To resolve the order we configure Program 2 and Program 3 to have the execution
precedence of 99. Then Program 2 runs before Program 1 in the first cycle and
Program 3 before Program 4 in the second cycle.
Figure: Example
Now the execution order is Program 2, Program 3, Program 4 and Program 1.
4. Click OK.
Topics
Script Program Components
Program Constants
Numeric Constants
String Constants
ASCII Codes
Script Constants
Constant Keywords
Failure
OFF
ON
-ON
Success
Program Operators
Operator Keywords
Bitwise Operators
BITAND
BITNOT
BITOR
BITXOR
Logical Operators
60 AND
EQUALS
IS...
NOT
OR
Mathematical Operators
DIVIDED BY
MINUS
MOD
PLUS
TIMES
Program Statements
Statement Keywords
Action Statements
P
PRINT
SET
TURN
Declaration Statements
ARG
DATETIME
LINE
NUMERIC
STRING
THE
Webservice
Program Control Statements
BASEDON...GOTO
BREAK
60 CONTINUE
FOR...NEXT
GOTO
IF...THEN...ELSE
MOVE
Repeat...Until
RETURN
SELECT CASE
STOP
WAIT
WHILE
Qualifier Statements
INPUT
Buffered
OUTPUT
PUBLIC
Expressions
Variables
Declaring a Variable
Program Variables
Local Program Variables
Variables Pane Types
Program Arrays
System Variables
Script Runtime Variables
TS
TM
TH
TD
60 System Variable Keywords
Date and Time System Variables
DATE
DAYOFMONTH
DAYOFYEAR
HOD
HOUR
MINUTE
MONTH
SECOND
TOD
UTCOffset
WEEKDAY
YEAR
Runtime System Variables
ERRORS
FREEMEM
SCAN
Script Functions
Script Function Workflow
Script Functions without Arguments
Script Functions with Arguments
Script Functions that Return a Value
Script Functions and Programs
Function Declarations and Statements
Declaring and Calling a Script Function
Creating a Script Function
Declaring a Script Function Argument
Checking and Saving a Script Function
60 System Functions
System Function Keywords
Buffered Variable Functions
GetBufferSize
GetBufferedValue
Conversion Functions
NUMTOSTR
STRTODATE
STRTONUM
Mathematical Functions
ABS
EXPONENTIAL
FACTORIAL
LN
LOG
RANDOM
SQRT
SUM
Object Functions
ReadProperty
Relinquish
WriteProperty
PASSED Function
Rounding Functions
CEILING
FLOOR
ROUND
TRUNCATE
Statistical Functions
60 AVERAGE
MAXIMUM
MAXITEM
MINIMUM
MINITEM
StandardDeviation
String Functions
ASC
CHR
LEFT
LENGTH
MID
RIGHT
SEARCH
FIND
STRINGFILL
TAB
Time Functions
DIFFTIME
TIMEPIECE
Trigonometric Functions
ACOS
ASIN
ATAN
ATAN2
COS
SIN
TAN
60 Script Programming
60.1 Script Program Components
60.1.4 Expressions
Instructions that consist of mathematical operations are called expressions.
Expressions can also be item names or constants that return a numeric or string
result.
For more information, see section 60.66 “Expressions” on page 1758.
60.1.5 Variables
A variable is a run-time (dynamically changing) property of an object.
0 NUL
1 SOH
2 STX
3 ETX
4 EOT
5 ENQ
6 ACK
7 Beep
8 Backspace
9 TAB forward
10 Line feed
11 Vertical TAB
12 Form feed
13 Carriage return
14 SO
15 SI
16 DLE
17 DC1
18 DC2
19 DC3
20 DC4
21 NAK
Continued
Code (in Decimal) Character or Action
22 SYN
23 ETB
24 CAN
25 EM
26 SUB
27 ESC
28 FS
29 GS
30 RS
31 US
127 DEL
Note
• Script supports characters at or below ASCII 127. Additional characters are
not supported and are replaced by a question mark (?).
Examples
For example, you might use the ASCII code for a character in the STRINGFILL
function. You must give STRINGFILL the code for the character with which you
want to fill the string. For more information, see section 60.152 “STRINGFILL” on
page 1867.
For example, to make the printer beep, you send the beep code a PRINT
statement, like this:
Print "|7" to Printer1
You can also make a terminal beep as follows:
Print "|7" to Screen1
To feed the paper forward one form feed:
Print "|12" to Printer1
To send an ESCAPE to the printer:
Print "|27" to Printer1
More printer control statements can be available for your printer. See the
manufacturer's documentation.
To create a bar in a chart, you might fill a string with asterisks using STRINGFILL
and the ASCII code for asterisk, 42, as follows:
Stringfill (Kilowatts, 42)
You could make a similar bar in a chart using pound signs:
Friday MonthTo
Date
Function MonthTo
Now
Oct Site_ConfigB
Continued
N O P R S T
October Success
Odd Sun
Off Sunday
Offline
On
-On
OneWeekTo
Date
OneWeekTo
Now
OneYearToD
ate
OneYearToN
ow
Online
Opened
Or
Other
OverRange
Overridden
60.7.1 Failure
Failure is used in expressions to indicate a function has failed to complete. Failure is
always numeric and equal to one. Failure can be used to replace numbers in a
comparison expression.
For more information, see section 60.8 “Failure” on page 1662.
60.7.2 OFF
OFF is used in expressions to indicate an item is OFF or set to bottom of scale.
OFF is always numeric and thus, can be compared to numeric values of points or
variables in a comparison expression.
For more information, see section 60.9 “OFF” on page 1663.
60.7.3 ON
ON is used in expressions to indicate an item is ON or set top of scale.
ON is always numeric and can be compared to input, output, and numeric points or
variables in a comparison expression.
For more information, see section 60.10 “ON” on page 1664..
60.7.4 -ON
-ON is used in expressions to indicate a tri-state point is set to -ON.
-ON is always numeric and thus, can be compared to numeric values of points or
variables in a comparison expression.
For more information, see section 60.11 “-ON” on page 1665..
60.7.5 Success
Success is used in expressions to indicate a process or function has completed
successfully.
Sucess is always numeric and equal to zero.
For more information, see section 60.12 “Success” on page 1666..
60.8 Failure
Failure is used in expressions to indicate a function has failed to complete. Failure is
always numeric and equal to one. Failure can be used to replace numbers in a
comparison expression.
Syntax
Failure
60.9 OFF
OFF is used in expressions to indicate an item is OFF or set to bottom of scale.
OFF is always numeric and thus, can be compared to numeric values of points or
variables in a comparison expression.
Note
Be aware that you need to use the ON/OFF keywords in Infinet device Script
programs to control digital outputs. While the Inactive/Active and True/False
options will not generate any compile or runtime errors, they will also not produce
the expected ON/OFF behavior.
Syntax
Off
Examples
Example 1
Program File
Turn the Lobby_Light Off
Example 2
Program File
If the Lobby_Light is Off then Turn Off the Heat
60.10 ON
ON is used in expressions to indicate an item is ON or set top of scale.
ON is always numeric and can be compared to input, output, and numeric points or
variables in a comparison expression.
Note
Be aware that you need to use the ON/OFF keywords in Infinet device Script
programs to control digital outputs. While the Inactive/Active and True/False
options will not generate any compile or runtime errors, they will also not produce
the expected ON/OFF behavior.
Syntax
On
Example
Script Program File - Using ON and OFF
If timeofday is between 9 and 17 then
Set the Fan to ON
Else
Set the Fan to OFF
Endif
60.11 -ON
-ON is used in expressions to indicate a tri-state point is set to -ON.
-ON is always numeric and thus, can be compared to numeric values of points or
variables in a comparison expression.
Syntax
-On
Example
Program File
If the Flow is greater than SetPoint then set the Damper to -On
60.12 Success
Success is used in expressions to indicate a process or function has completed
successfully.
Sucess is always numeric and equal to zero.
Syntax
Success
Examples
Call a user-defined Script function, which returns either Success or Failure.
If MyUpdateFunction (“Zone1”, “Temperature”, TempValue) =
Success then Print "Update Successful"
Else
user1Goto RecordFailure
Endif
Continued
Operator Description Association
Continued
Operator Example Definition
Continued
Operator Example Definition
Truth Tables
The following table is the truth table for the bit operators:
Note
The Bitwise operators are not valid for Infinet device Script programs.
60.15.1 BITAND
BITAND logically compares the binary equivalents of the two integers, digit by digit.
This operator creates a new binary number that contains a 1 for each digit position,
where the first number's bit and the second number's bit are both 1, and sets all
other digits to zero. The new binary number is then converted to its decimal
equivalent.
For more information, see section 60.16 “BITAND” on page 1678..
60.15.2 BITNOT
BITNOT switches 1s to 0s and 0s to 1s in the binary equivalent of the integer, digit
by digit. (This is called the one’s complement of the binary number.) This operator
creates a new binary number and then converts that number back to its decimal
equivalent.
For more information, see section 60.17 “BITNOT” on page 1679..
60.15.3 BITOR
BITOR logically compares the binary equivalents of the two integers, digit by digit.
This operator creates a new binary number that contains a 1 for each digit position
where the first number's bit or the second number's bit is 1 and where both the first
and second number's bits are 1. The operator also sets all other digits to zero.
BITOR converts the new binary number to its decimal equivalent.
For more information, see section 60.18 “BITOR” on page 1680..
60.15.4 BITXOR
BITXOR logically compares the binary equivalents of the two integers, digit by digit.
This operator creates a new binary number that contains a 1 for each digit position,
where either the first number's bit or the second number's bit is 1, but gives zeros
where both are 1 or both are 0. BITXOR converts the new binary number to its
decimal equivalent.
For more information, see section 60.19 “BITXOR” on page 1681..
60.16 BITAND
BITAND logically compares the binary equivalents of the two integers, digit by digit.
This operator creates a new binary number that contains a 1 for each digit position,
where the first number's bit and the second number's bit are both 1, and sets all
other digits to zero. The new binary number is then converted to its decimal
equivalent.
BITAND carries out comparisons of checksums and similar operations.
Syntax
integer bitand integer
Example
Suppose you want to compare Total1 and Total2:
Total1 = 13 (binary equivalent is 0000000000001101)
Total2 = 11 (binary equivalent is 0000000000001011)
You would compare them with BITAND as follows:
Program File
Set result = Total1 bitand Total2
The comparison would give 0000000000001001. RESULT would be set to 9.
60.17 BITNOT
BITNOT switches 1s to 0s and 0s to 1s in the binary equivalent of the integer, digit
by digit. (This is called the one’s complement of the binary number.) This operator
creates a new binary number and then converts that number back to its decimal
equivalent.
BITNOT carries out bitmasking and similar operations.
Syntax
bitnot integer
Example
Suppose you want to find the one’s complement of AMOUNT:
Amount = 13 (binary equivalent is 0000000000001101)
You could reverse the number with BITNOT as follows:
Program File
Set result = bitnot AMOUNT
The BITNOT of the amount would be 1111111111110010. The statement would
set RESULT to 65522.
60.18 BITOR
BITOR logically compares the binary equivalents of the two integers, digit by digit.
This operator creates a new binary number that contains a 1 for each digit position
where the first number's bit or the second number's bit is 1 and where both the first
and second number's bits are 1. The operator also sets all other digits to zero.
BITOR converts the new binary number to its decimal equivalent.
BITOR carries out comparisons of checksums and similar operations.
Syntax
integer bitor integer
Example
Suppose you want to compare Total1 and Total2:
Total1 = 13 (binary equivalent is 0000000000001101)
Total2 = 11 (binary equivalent is 0000000000001011)
You would compare them with BITOR as follows:
Program File
Set result = Total1 bitor Total2
The comparison would give 0000000000001111. RESULT would be set to 15.
60.19 BITXOR
BITXOR logically compares the binary equivalents of the two integers, digit by digit.
This operator creates a new binary number that contains a 1 for each digit position,
where either the first number's bit or the second number's bit is 1, but gives zeros
where both are 1 or both are 0. BITXOR converts the new binary number to its
decimal equivalent.
BITXOR carries out comparisons of checksums and similar operations.
Syntax
integer bitxor integer
Example
Suppose you want to compare Total1 and Total2:
Total1 = 13 (binary equivalent is 0000000000001101)
Total2 = 11 (binary equivalent is 0000000000001011)
Program File
Set result = Total1 bitxor Total2
The comparison would give 0000000000000110. RESULT would be set to 6.
60.20.1 AND
The AND keyword can be used in two ways.
For more information, see section 60.21 “AND” on page 1683..
60.20.2 EQUALS
EQUALS is similar to the IS... operator.
For more information, see section 60.22 “EQUALS” on page 1686.
60.20.3 IS...
IS... carries out the logical test you specify.
For more information, see section 60.23 “IS...” on page 1687.
60.20.4 NOT
NOT logically negates or inverts a number or expression, changing 0 (FALSE to
OFF) to 1 (TRUE or ON) or vice versa.
For more information, see section 60.24 “NOT” on page 1690..
60.20.5 OR
The OR keyword can be used to provide the logical OR between two expressions,
or positioned in a list of names beween the last two items.
For more information, see section 60.25 “OR” on page 1691..
60.21 AND
Alias: Ampersand (&) is the alias for the logical AND only.
The AND keyword can be used in two ways.
See Syntax for more details.
The controller carries out all other operations (such as adding and subtracting)
before acting on AND or OR. Because AND and OR are acted on last, you can form
logical statements without using too many parentheses. (See Example 3 for using
AND and OR together.)
Syntax
Syntax 1: number and number
Provides the logical AND between two expressions.
Syntax 2: namelist and final_name
When used in a list of names between the last two items, indicates the end of the
series.
Examples
Example 1
Instead of forming IF..THEN statements to turn the heat on when multiple
conditions exist, you can make one statement using AND:
Program File
If Temp < 70 and TOD > 7:00am then turn On the Heat
or
If Temp < 70 & TOD > 7:00am then turn On the Heat
Example 2
To run a series of programs, instead of using RUN several times, you can list the
program names on the same line, using AND (final comma optional) to indicate the
last item in the list:
Program File
Run the Cooling, Heating and Fan
or using the final comma:
Run the Cooling, Heating, and Fan
You cannot use the ampersand (&) for AND in a series. You can, however, leave out
AND as follows:
Run the Cooling, Heating, Fan
Example 3
If OR occurs before AND, the controller interprets OR first because the controller
works from left to right on AND and OR. For example, take this statement:
Program File
If Wkd = Sat or Wkd = Sun and TOD > 9:00 then...
The above statement is interpreted so that the items in parentheses below are
calculated first:
If (Wkd = Sat or Wkd = Sun) and TOD > 9:00 then...
If AND occurs before OR, the controller interprets AND first:
Program File
If TOD > 9:00 and Wkd = Sat or Wkd = Sun then...
is interpreted as:
If (TOD > 9:00 and Wkd = Sat) or Wkd = Sun then...
Example 4
AND is also used with the operator BETWEEN, as in the following example:
Program File
If TOD is between 8:00am and 6:00pm then...
You cannot use the ampersand (&) for AND when AND is used with BETWEEN.
Note
• Use parentheses to enforce the order of interpretations and resolve potential
ambiguities.
Example 5
To set one or more variables to an expression, such as ON, you can use any of the
following:
Program File
D1, D2 = On
D1 and D2 = On
Set D1,D2 to On
Set D1 and D2 to On
D1, D2, D3, D4 = On
D1, D2, D3 and D4 = On
Set D1, D2, D3, D4 to On
Set D1, D2, D3, and D4 to On
In this example, the following line is used to set the variable D1 to On and D2 to On
(In other words, it includes two set statements on the same line).
D1 = On AND D2 = On
However, the line does not get interpreted as such. Instead, it is interpreted as
follows:
D1 = ((On) and (D2 = On))
This results in one statement that sets D1 to the logical expression on the right hand
side of the first equal operator, and does not set D2 all together.
Be aware of the following here:
• A logical operator, such as AND, works only in expressions and not
statements.
• The language rules of precedence always apply when interpreting expressions.
In this case, the Equal operator (=) has a higher precedence than the AND
operator.
Note
• Be sure to always remember to use parentheses to enforce the order of
interpretations and resolve potential ambiguities. For more information, see
section 60.13 “Program Operators” on page 1667.
60.22 EQUALS
EQUALS is similar to the IS... operator.
For more information, see section 60.23 “IS...” on page 1687..
60.23 IS...
IS... carries out the logical test you specify.
Syntax
Greater-than-expression:
number > number
number is greater than number
number is above number
Greater-than-or-equal-to-expression:
number >= number
number is greater than or equal to number
Less-than-expression:
number < number
number is less than number
number is below number
Less-than-or-equal-to-expression:
number <= number
number is less than or equal to number
Equal-expression:
number = number
number is number
number is equal to number
number equals number
Not-equal-expression:
number <> number
number is not number
number is not equal to number
number does not equal number
List-inclusion-expression:
number is in list
number is range (see range-expression below)
number is EITHER list
List-exclusion-expression:
number is not in list
number is not range (see range-element below)
number is neither list
Range-expression:
number is between lower_number AND higher_number
Table: IS...Parameters
Parameter Description
Examples
Example 1
To compare two values, you usually place an IS... statement between IF and THEN
in an IF..THEN statement.
Note
• Because THAN is optional, in the following pairs of statements, each
statement gives the same instructions to the controller.
Program File
If Zone_Temp is greater than 70 then…
If Zone_Temp is greater 70 then…
If Zone_Temp is above 70 then…
If Zone_Temp is less than 70 then…
If Zone_Temp is less 70 then…
If Zone_Temp is below 70 then…
Example 2
The following statements are grouped together and give the same instructions to
the controller, because TO is optional and EQUALS can be used without IS:
Program File
If Zone_Temp is equal to 70 then…
If Zone_Temp is equal 70 then…
If Zone_Temp equals 70 then…
If Zone_Temp is not equal to 70 then…
IF Zone_Temp does not equal 70 then…
Example 3
With IS IN, IS EITHER, IS NOT IN, or IS NEITHER, the comma in the list means OR.
You can also use the word OR before the last item in the list, for example:
Program File
If Zone_Temp is in Occupied, Warmup then…
If Zone_Temp is either Occupied, Warmup, OR Reset then…
If Zone_Temp is not in Occupied, Warmup then...
If Zone_Temp is neither Occupied, Warmup then...
If Zone_Temp is not 8 through 81 then...
Example 4
With IS BETWEEN and IS NOT BETWEEN, you always use AND. IS BETWEEN with
AND is equivalent to IS with THRU. The following statements are equivalent:
Program File
If Zone_Temp is between 70 and 80 then…
If Zone_Temp is 70 thru 80 then…
With THRU or BETWEEN, do not put parentheses around the two elements being
compared. The following parenthesis are not allowed:
If Zone_Temp is (70 thru 80) then…
If Zone_Temp is between (70 thru 80) then…
Program File
If Zone_Temp is not between 70 and 80 then…
If Zone_Temp is not 70 thru 80 then…
If Zone_Temp is not (ROOMTMP-5) thru (ROOMTMP+5)
If Zone_Temp is not ROOMTMP-5 thru ROOMTMP+5
With THRU or BETWEEN, always put the lower number first. The following
examples are not allowed:
If Zone_Temp is 80 thru 70 then…
If Zone_Temp is between 80 and 70 then…
Note
• Both THRU and BETWEEN are always inclusive, so the following are both
TRUE if the ZONE_TEMP is equal to 70 or 80.
60.24 NOT
NOT logically negates or inverts a number or expression, changing 0 (FALSE to
OFF) to 1 (TRUE or ON) or vice versa.
Syntax
not number
Example
Program File
If not OCCUPIED then..
In this example, assume OCCUPIED can be ON or OFF. When OCCUPIED is ON,
placing NOT in front tests for the opposite condition, OFF.
60.25 OR
The OR keyword can be used to provide the logical OR between two expressions,
or positioned in a list of names beween the last two items.
In this second example, OR indicates the end of the series. OR with the last name is
optional. The system carries out all other operations (such as adding and
subtracting) before acting on OR (or AND).
Operators by Precedence compares the order of operations on which the system
software acts. Because OR (and AND) are acted on last, you can form logical
statements without using too many parentheses. See Example 4 for how to use
AND and OR together.
Syntax
number or number
namelist or final_name
Table: OR Parameters
Parameter Description
Examples
Example 1
To take an action only if at least one of several conditions exists, you use OR
between the numbers, so if one of them is true, the resulting action occurs:
Program File
If the Heat is On or the Cool is On then...
Note that in the above statement, you can substitute exclamation mark (!) for OR.
Example 2
To put a list in an IF statement, you can use an OR between the last two names in
the list:
Program File
You cannot use the exclamation mark (!) for OR in a series. You can, however, leave
out OR as follows:
If the Zone is Warming, Occupied, Lowtemp then...
Example 3
You can also combine the logical OR with a name list containing an OR (with or
without the comma before OR) as follows:
Program File
If the Zone is either Warm, Occupied, or Low or Heat is Off then...
The controller always interprets the first OR as the list OR and the second as the
logical OR. If you want to reverse the order of the statement, use parentheses, as
follows:
Program File
If (Heat is Off) or Zone is either Warming, Occupied or Low
then...
Example 4
If OR occurs before AND, the system software interprets OR first because the
software works from left to right on AND and OR. For example, take this statement:
Program File
If WKD = Sat or Wkd = Sun and TOD > 900 then...
The above statement is interpreted so that the items in parentheses below are
calculated first:
If (Wkd = Sat or Wkd = Sun) and TOD > 900 then...
If AND occurs before OR, the controller interprets AND first:
Program File
If TOD > 900 and Wkd = Sat or Wkd = Sun then...
is interpreted as:
If (TOD > 900 and Wkd = Sat) or Wkd = Sun then...
60.26.1 DIVIDED BY
DIVIDED BY divides one number by another. The division operator (/) can be
substituted for DIVIDED BY.
For more information, see section 60.27 “DIVIDED BY” on page 1694..
60.26.2 MINUS
MINUS subtracts number from number.
For more information, see section 60.28 “MINUS” on page 1695..
60.26.3 MOD
MOD returns the remainder of one number divided by another.
For more information, see section 60.29 “MOD” on page 1696..
60.26.4 PLUS
PLUS adds two expressions.
For more information, see section 60.30 “PLUS” on page 1697..
60.26.5 TIMES
TIMES multiplies two numbers.
For more information, see section 60.31 “TIMES” on page 1698..
60.27 DIVIDED BY
Aliases: /, DIV
DIVIDED BY divides one number by another. The division operator (/) can be
substituted for DIVIDED BY.
Syntax
number divided by number
Examples
Example 1
Program File
Usage = kwh divided by 24
Example 2
Program File
Usage = kwh/24
60.28 MINUS
Alias: -
MINUS subtracts number from number.
Syntax
number minus number
Examples
Example 1
Program File
Kwh_day = Kwh_PM minus Kwh_AM
Example 2
Program File
Kwh_day = Kwh_PM - Kwh_AM
60.29 MOD
Alias: REMAINDER
MOD returns the remainder of one number divided by another.
Syntax
number mod number
Example
Program File
Extra = 5 mod 2
The equation divides 5 by 2 and gives a remainder of 1, so EXTRA is set to 1.
60.30 PLUS
Alias : +
PLUS adds two expressions.
Syntax
number plus number
Example
Example 1
Program File
TotalKwh = KwhMonth plus KwhDay
Example 2
Program File
TotalKwh = KwhMonth + KwhDay
60.31 TIMES
Aliases: MULTIPLIED BY, MULT, *
TIMES multiplies two numbers.
Syntax
number times number
Example
Example 1
Program File
Energycost = Building1_KW times 1.78
Example 2
Program File
Energycost = Building1_KW * 1.78
• MOVE
• REPEAT...UNTIL
• RETURN
• SELECT CASE
• STOP
• STOP
• WAIT
• WHILE
For more information, see section 60.47 “Program Control Statements ” on page
1728.
60.34.1 P
P prints the values of one or more variables, points, constants, or other expressions
representing a value, including strings of characters and datetimes, each on a
separate line.
For more information, see section 60.35 “P” on page 1703..
60.34.2 PRINT
PRINT prints a series of characters (text strings, often simply called strings) to a
string object or attribute, a local variable, a printer, or a communications port.
For more information, see section 60.36 “PRINT” on page 1704..
60.34.3 SET
SET assigns a value to a point or variable.
For more information, see section 60.37 “SET” on page 1710..
60.34.4 TURN
TURN sets the name or names to the top of the defined range for the point if ON
and to the bottom of the range if OFF.
For more information, see section 60.38 “TURN” on page 1712..
60.35 P
Alias: PR
P prints the values of one or more variables, points, constants, or other expressions
representing a value, including strings of characters and datetimes, each on a
separate line.
The list can contain different types of items. Prints units with point values.
For points, system variables, and attributes, prints the name of the point (or variable
or attribute), followed by an equal sign, the value of the point, and the units.
Otherwise, only the value prints.
Also, can print to comm ports and string objects (including program string
variables).
Syntax
P list
Table: P Parameter
Parameter Description
Examples
Example 1
Command Line
P SupplyAir, ReturnAir, BurnerStat, CoilStatus
SupplyAir = 46 degrees F
ReturnAir = 68 degrees F
BurnerStat = on
CoilStatus = off
Notice that the name of the point and the units print for each point.
Example 2
Command Line
P OutsideAir, Avg (Temp), AvgSetpt, OutsideAir_Type, TOD
OutsideAir_Type = 46 degrees F
86
AvgSetpt = 64
OutsideAir Type = Input
TIMEOFDAY = 8:32 pm
60.36 PRINT
PRINT prints a series of characters (text strings, often simply called strings) to a
string object or attribute, a local variable, a printer, or a communications port.
You can also print to a string point or local variable to fill that point or variable with a
string of text or numbers. In addition, on WorkStation, you can print to an ASCII file.
Syntax
Format 1: any_of_formats_above to string_point_or_variable
Prints any value or string, including messages, points, or variables, into a string
point or variable to set the value of that string.
Format 2: Print string
Prints a string value of text to the default comm port of the program or report.
Format 3: Print list
Prints the values of one or more variables, points, constants, or other expressions
representing a value. The list can contain different types of items.
Format 4: Print string_format, list
Prints the variables, points, or other expressions in the list in the format you specify.
Formatting Characters
You can indicate the layout of the print line using the following special symbols:
The format must be enclosed in quotation marks. The comma is required after the
format (outside the quotation marks) if an item to insert in the format follows (see
Example 3).
Examples
Continued
No. Program File Output Explanation
Continued
No. Program File Output Explanation
Continued
No. Program File Output Explanation
60.37 SET
Alias: ADJUST and CHANGE (Format 1 only), LET (Format 2 only), MODIFY
SET assigns a value to a point or variable.
Syntax
Syntax 1: Set namelist to number
Syntax 2: Set namelist = number
Examples
Example 1
At any time in a program, you can set the value of a variable or array of variables
using SET and the word TO:
Program File
Set area to height times width
You can also use ADJUST, CHANGE, or MODIFY with TO. With ADJUST and
CHANGE, the TO is required:
Program File
Adjust Valve to Open
Program File
Change Space_SP to 72
Program File
Modify Space_SP to 72
You cannot use the equal sign with ADJUST or CHANGE, but you can use the
equal sign with MODIFY.
Example 2
You can set a variable using SET and an equals sign as in the example below:
Program File
Set KwAbg = Average (KW)
Instead of SET, you can use LET with the equals sign, as follows:
Program File
Let KwAvg = Average (KW)
You cannot use the word TO with LET.
Neither the word SET nor the word LET is required with the equals sign, so you can
set the same variable like this:
Program File
KwAvg = Average (KW)
Example 3
You can set a string variable or point to a particular value:
Program File
Set Stat_Message to "Heat active"
Example 4
You can set several points and variables to a particular value:
Program File
Set KwAvg, OATAvg, HWAvg, CHWAvg = 0
60.38 TURN
TURN sets the name or names to the top of the defined range for the point if ON
and to the bottom of the range if OFF.
Syntax
Format 1: Turn On point_list
TURN OFF point_list
Format 2: Turn point_list On
TURN point_list OFF
Examples
Example 1
Suppose you want to turn on the fan and the pump. You can turn both on in one
program statement:
Program File
Turn on the Fan and the Pump
Example 2
You can place the word ON or OFF after the name of the point:
Program File
Turn the Pump off
Example 3
You can also place ON or OFF before the name of the point:
Program File
Turn off the Pump
60.39.1 ARG
ARG is a keyword that defines an argument and can be given a name. After you
assign an easy-to-remember name to an argument variable, you can then refer to
that variable by its name so your function is easier to understand.
For more information, see section 60.40 “ARG” on page 1715..
60.39.2 DATETIME
DATETIME creates and defines one or more names as local DATETIME variables.
You define the variables inside a program for use only in that particular program.
For more information, see section 60.41 “DATETIME” on page 1716..
60.39.3 LINE
LINE labels a particular line in the program so that program control can later branch
or move to that line with the GOTO (or more advanced BASED ON..GOTO)
statement.
For more information, see section 60.42 “LINE” on page 1718..
60.39.4 NUMERIC
NUMERIC creates and defines one or more names as local numeric variables. You
define the variables inside a program for use only in that particular program.
For more information, see section 60.43 “NUMERIC” on page 1722..
60.39.5 STRING
STRING creates and defines one or more names as local string variables. You
define the variables inside a program for use only in that particular program. You
can specify the length of the string of characters with the string_length.
For more information, see section 60.44 “STRING” on page 1724..
60.39.6 THE
THE performs no function, but enhances readability.
For more information, see section 60.45 “THE” on page 1726..
60.39.7 Webservice
Webservice delares a Web Service in a Script program.
For more information, see section 60.46 “ Webservice” on page 1727.
60.40 ARG
Alias: PARAM
ARG is a keyword that defines an argument and can be given a name. After you
assign an easy-to-remember name to an argument variable, you can then refer to
that variable by its name so your function is easier to understand.
ARG can only be used to declare that variable in a function (Syntax 1). ARG calls the
argument variable by the variable’s number (Syntax 2).
Syntax
Syntax 1: ARG integer_constant name
Syntax 2: ARG [ integer_expression ]
Examples
Example 1
In this example, ARG[5] represents the status of a report. To make that easier to
understand, ARG[5] is named RPTSTATUS. The program refers to RPTSTATUS for
the variable value from then on.
Function File
ARG 5 RptStatus
Example 2
To test to see if the report status equals SUCCESS, you can call on the argument
variable using the easy-to-remember name (from Example 1):
Function File
If RptStatus is Success then…
Example 3
To test to see if the report status equals SUCCESS, you can also call on the
argument variable using ARG[5]:
Function File
If ARG[5] is Success then…
60.41 DATETIME
DATETIME creates and defines one or more names as local DATETIME variables.
You define the variables inside a program for use only in that particular program.
You define the variables as follows:
• Specify an array by including the array_size_number during the array definition
since each variable can be a single variable or an array.
• Add seconds as if the datetime were a number because the datetime is stored
in seconds.
• Define all local datetime variables at the top of your program.
• Set the datetime variable to the time at a given moment using the DATE system
variable.
• Print the datetime variable. When you do, you receive the date and time printed
in this format:
MONTH DD YYYY hh:mm:ss
The month is spelled out; the day is two digits, the year is four digits. The hour,
minute, and second are in 24-hour time.
Binding Qualifiers
Variables can also be bound to the object property of a point outside of the
program. To do this, you must use a keyword, either Input or Output.
Syntax
Datetime Binding_qualifier namelist [ array_size_number ]
Examples
Example 1
In this program, the first statement defines the TEMPTIME as a datetime variable.
The next statement sets the variable to the time at a given moment with the DATE
system variable:
Program File
Datetime TempTime
TempTime = date
Example 2
You can define a series of datetime variables in a single statement:
Program File
Datetime TempTime, FirstTime, LastTime
Example 3
You can define more than one array of datetime variables in a single statement:
Program File
Datetime TempTime[40], Timer[30], Watch[15]
Example 4
You can define several arrays of datetime variables and several single variables in a
single statement:
Program File
Datetime TempTime[40], FirstTime, Timer[30], LastTime
60.42 LINE
LINE labels a particular line in the program so that program control can later branch
or move to that line with the GOTO (or more advanced BASED ON..GOTO)
statement.
Caution
• Line names 0, C, and E are reserved for use by WorkStation. LINE 0 is
predefined for stopping the program, so you cannot label a line LINE 0.
However, you can use GOTO line 0 to stop a program. You can label a line
LINE E and the program automatically goes to that line when an error occurs.
LINE C is reserved for future use.
You can label lines to redirect program flow to any part of the program. For
example, you could return program flow to an earlier line, such as the first line. Or
you could send program flow to a later line to branch into a specific set of actions.
Syntax
Line linename
linename:
Line integer
Integer:
Examples
Example 1
In the following example the first linename is STARTUP, labeled LINE STARTUP.
Follow the program flow to see how the line name directs the control of the
program.
Program File
Line Startup
If Temp > 72 then goto Cooling
If Temp < 70 then goto Heating
Line Heating
Turn on the Heat
...
Goto Startup
Line Cooling
Turn on the Blower
...
Goto Startup
Example 2
This example is the same as the last, only each linename is labeled with the name
followed by a colon:
Program File
Startup:
If Temp > 72 then goto Cooling
If Temp < 70 then goto Heating
Heating:
Turn on the Heat
...
Goto Startup
Turn on the Blower
Cooling:
...
Goto Startup
Example 3
This example shows how to use an integer as a line label:
Program File
LINE 1
Start Fan1
Goto 2
LINE 2
If Fan1_Status is on then goto Shutdown
LINE Shutdown
If Zone1 temperature is less than 60 then
Stop Fan1
Goto 1
Endif
Example 4
This example shows an integer with a colon as a line label:
Program File
1:
Start Fan1
Goto 2
2:
If Fan1_Status is on then goto 3
3:
If Zone1 temperature is less than 60 then
Stop Fan1
Goto 1
Endif
Example 5
This example shows a program that has a line labeled E. The program automatically
goes to line E when an error occurs. If you do not have a line E, the software
automatically disables the program. When an error occurs, you might want the
program to go to a special line. For example, you might want the program to go to a
special line that closes an open comm port (see OPEN).
The following program goes to line E and closes the comm port when an error
occurs:
Program File
Numeric Result
Line OpenPort3
Result = Open (Comm3)
Line TestingOpen
If result = success then goto PrintMenus
Line PrintMenus
Run MenuDisplay
...
If Comm3_PrintDone = true then goto ClosePort3
Line ClosePort3
Result = Close (Comm3)
Line TestingClose
If result = Success then Stop
Line E
Result = Close (Comm3)
60.43 NUMERIC
Alias: NUMBER
NUMERIC creates and defines one or more names as local numeric variables. You
define the variables inside a program for use only in that particular program.
Tip
A numeric variable is a name that represents a number. Numeric variables are
subject to the same range limitations as numeric constants. Numeric constants,
variables, points, expressions (formulas), or functions can be compared to other
numeric type items or used in mathematical calculations.
Each variable can be a single variable or an array. You specify an array by including
the array_size_number during the array definition.
Binding Qualifiers
Varibles can also be bound to the object property of a point outside of the program.
To do this, you must use a keyword, either Input or Output.
Syntax
Numeric Binding_qualifier namelist [array_size_number]
Examples
Example 1
Suppose that you are averaging the values of the ten temperatures. The points that
take the outside air temperature have been defined using menus and windows, but
you define the variable that contains the average using NUMERIC:
Program File
Numeric Avg_Temp
Avg_Temp = Average (Temp)
Print Avg_Temp
Example 2
You can define a series of numeric variables in a single statement:
Program File
60.44 STRING
STRING creates and defines one or more names as local string variables. You
define the variables inside a program for use only in that particular program. You
can specify the length of the string of characters with the string_length.
Tip
A string variable is a name that represents a series of alphanumeric characters.
String constants, variables, points, expressions, or functions can be compared to
other string type items. Strings cannot be used in mathematical calculations
unless they are converted to a numeric type.
Each variable can be a single variable or an array. You specify an array by including
the array_size_number during the array definition.
You must define all local string variables at the top of your program.
STRING is used to store textual information in the current program.
If you do not give a string_length, the string is given the default length, which is 16
characters.
Tip
For EcoStruxure BMS servers, the maximum string_length is 255 characters. For
b3 BACnet devices, the maximum length is 32 characters. The Script compiler
catches any number that is out of range.
Binding Qualifiers
Varibles can also be bound to the object property of a point outside of the program.
To do this, you must use a keyword, either Input or Output.
Syntax
String Binding_qualifier string_length namelist [array_size_number]
Examples
Example 1
To set a string variable, you must first define that variable using STRING. To define a
single string variable of the default length, you enter this program line:
Program File
String VarName
Example 2
To have a program read information from a file containing text, you would create a
series of string variables like those below to contain each piece of text information.
You can create them all in the same program line:
Program File
String 20 LNAME, LOGON, PWORD, ROOM, TERMINAL
The length of each string is 20. To give them different lengths, you must define
(declare) each one separately.
Example 3
To create a string array of variables, you must first define the array. The string called
PUMP below is an eight-character string with 20 variables in the array (PUMP[1],
PUMP[2], PUMP[3], and so on).
Program File
String 8 Pump[20]
Pump[6] = "HeatPump"
Example 4
You can create several arrays of string variables and single string variables all in one
program line:
Program File
String Pump[6], Blower[8], HeaterNM, FanName
60.45 THE
THE performs no function, but enhances readability.
Syntax
the name
Examples
Program File
Turn on the Fan
60.46 Webservice
Webservice delares a Web Service in a Script program.
For more information, see section 62.1 “Script Web Services” on page 1937.
Note
Webservice is not supported in the MP Series controller.
Syntax
Webservice (service name)
Tip
The Web Service declaration name does not need to match the Script Web
Service object you intend to bind.
Example
You declare a Web Service here in order to invoke an online calculator service.
Program File
Webservice wsCalculator
60.47.1 BASEDON...GOTO
BASEDON...GOTO branches to a different line for each value the number can have.
You put the line names in the linelist.
For more information, see section 60.48 “BASEDON...GOTO” on page 1730..
60.47.2 BREAK
BREAK halts the smallest enclosing FOR...NEXT, REPEAT...UNTIL, WHILE, or
SELECT CASE statement.
For more information, see section 60.49 “BREAK” on page 1732..
60.47.3 CONTINUE
CONTINUE stops the current iteration of the smallest enclosing FOR...NEXT,
REPEAT...UNTIL, or WHILE statement and starts the next iteration from the top of
the loop. CONTINUE also exits the SELECT CASE statement.
For more information, see section 60.50 “CONTINUE” on page 1733..
60.47.4 FOR...NEXT
FOR...NEXT carries out all statements in a loop a fixed number of times.
For more information, see section 60.51 “FOR...NEXT” on page 1734..
60.47.5 GOTO
GOTO branches to the line labeled linename.
For more information, see section 60.52 “GOTO” on page 1737..
60.47.6 IF...THEN...ELSE
IF...THEN...ELSE carries out a given statement or series of statements if the
expression is TRUE.
IF...THEN...ELSE can also carry out a given statement or series of statements if the
given expression is FALSE.
For more information, see section 60.53 “IF...THEN...ELSE” on page 1740..
60.47.7 MOVE
MOVE converts engineering units to electrical units to control the output point,
using the top and bottom of scale for that point.
For more information, see section 60.54 “MOVE” on page 1744..
60.47.8 Repeat...Until
Repeat...Until carries out the statements in the loop until the number is true.
For more information, see section 60.55 “Repeat...Until” on page 1745..
60.47.9 RETURN
In a function, the RETURN keyword controls the calling program, returns and sends
the number to the calling program, and returns the contents of the variable.
For more information, see section 60.56 “RETURN” on page 1746..
60.47.11 STOP
With an output point, STOP actually stops the piece of equipment. With an input
point, STOP sets the point to the bottom of the defined scale. With a numeric point,
STOP sets the point to the lowest number in the controller system. You might STOP
an input after using the RUN keyword in order to test whether the input is active.
For more information, see section 60.58 “STOP” on page 1750..
60.47.12 WAIT
WAIT makes a program's execution wait for a specified number of seconds and
then resume right after the WAIT command statement.
For more information, see section 60.59 “WAIT” on page 1751..
60.47.13 WHILE
WHILE carries out the instructions in the statements within the loop over and over
again as long as the given number is TRUE.
For more information, see section 60.60 “WHILE” on page 1752..
60.48 BASEDON...GOTO
BASEDON...GOTO branches to a different line for each value the number can have.
You put the line names in the linelist.
Syntax
Syntax 1:
Basedon (number) Goto linelist
or
Basedon (number) Go to linelist
or
Basedon (number) Go to linelist
Syntax 2:
Basedon (number) Goto Line linelist
or
Basedon (number) Go to Line linelist
Examples
You can have a series of steps (a line) that you want to run every Friday to shut
down equipment not required over the weekend. Then, every Monday you can
restart that equipment.
To run different lines on particular days, you write a program that activates certain
lines based on the day of the week. The lines are labeled with LINE, telling the line
the routine starts on.
Remember that SUN is considered the first day of the week, so in the program
below, the first line listed after GOTO runs on Sunday, the next on Monday, the next
on Tuesday, and so on:
Program File
Basedon Wkd Goto Sun_1, Mon_1, Tue_1, Wed_1, Thu_1, Fri_1, Sat_1
…
Line Sun_1
…
Line Mon_1
…
Line Tue_1
…
Line Wed_1
…
Line Thu_1
…
Line Fri_1
…
Line Sat_1
Note
• The following variations to the BASEDON statement (above) are acceptable.
You can also include the word LINE in front of the line list:
Basedon Wkd Goto Line Sun_1, Mon_1, Tue_1, Wed_1, Thu_1, Fri_1,
Sat_1
You can replace GOTO with the word GO:
Basedon Wkd Go Sun_1, Mon_1, Tue_1, Wed_1, Thu_1, Fri_1, Sat_1
You can separate the word GO from the word TO:
Basedon Wkd Go to Sun_1, Mon_1, Tue_1, Wed_1, Thu_1, Fri_1, Sat_1
You can include the word LINE after GO and TO:
Basedon Wkd Go to Line Sun_1, Mon_1, Tue_1, Wed_1, Thu_1, Fri_1,
Sat_1
60.49 BREAK
BREAK halts the smallest enclosing FOR...NEXT, REPEAT...UNTIL, WHILE, or
SELECT CASE statement.
After BREAK executes, the next statement the controller carries out is the one
immediately following the end of the loop or block.
Syntax
Break
Examples
To check several stored temperatures to see if any is reading over 75 degrees, you
use a FOR...NEXT loop. Normally, the loop below would end after checking the 20
temperatures. To exit the loop as soon as you find one over 75 degrees, you use
the BREAK statement.
Program File
60.50 CONTINUE
CONTINUE stops the current iteration of the smallest enclosing FOR...NEXT,
REPEAT...UNTIL, or WHILE statement and starts the next iteration from the top of
the loop. CONTINUE also exits the SELECT CASE statement.
Each time the loop repeats, the action is an iteration of that loop.
Syntax
Continue
Examples
To check several temperatures stored in an array and print names of those over 75
degrees, you use a FOR...NEXT loop. (See the FOR...NEXT statement.) Normally,
the loop below would print the names of all 20 stored temperatures. To get the loop
to select those over 75, use CONTINUE to break the loop whenever one is less than
or equal to 75, and skip to the next array item.
Program File
60.51 FOR...NEXT
FOR...NEXT carries out all statements in a loop a fixed number of times.
Syntax
Syntax 1:
For numeric_name = begin to end
Statement
Statement
...
Next numeric_name
Syntax 2:
For numeric_name = begin to end step number
Statement
Statement
...
Next numeric_name
Examples
Example 1
A FOR...NEXT loop looks like this:
Program File
For count = 2 to 10 step 2
Print count, " ", (10 + count)
Next count
The statement sets the value of the numeric_name to the begin value, then carries
out the statements after FOR until reaching NEXT. At NEXT, the program goes back
to FOR and gets the next value of numeric_name by adding number to begin.
Here, since begin is 2, end is 10, and number is 2, the numeric_name (often called
the counter) counts 2, 4, 6, 8, 10. The first time through the loop numeric_name is
2, the second time numeric_name is 4, and so on.
As long as numeric_name is less than or equal to end, the statements inside the
loop are carried out. When numeric_name is greater than end the program then
goes to the statement after NEXT.
Here is the output printed by the previous loop:
2 12
4 14
6 16
8 18
10 20
If you do not specify a STEP number, the name automatically increases by one
(increments) each time the loop executes.
The step can also be a negative step, taking the value of the name from a begin of,
for example, 10 to an end of 1 by a number of -1.
The step can also be a negative step, taking the value of the name from a begin of,
for example, 10 to an end of 1 by a number of -1.
Example 2
Before you run functions that use the ARG variables, you can set them all to zero
with one programming statement using FOR...NEXT:
Program File
For count = 1 to 15
Set ARG[count] = 0
Next count
The first time through the loop, ARG[1] is set to 0, the second time ARG[2] is set to
0, the third time ARG[3] is set to 0, and so on.
Example 3
To set every third value in an array to zero, you can go to the third item, then sixth,
then ninth, and so on, using STEP with FOR...NEXT:
Program File
Number count
For count = 3 to 15 step 3
Set Pump[count] = 0
Next count
Example 4
To find a filtered average, you could set up a function called FILT_TOTAL. The
function, shown below, uses FOR...NEXT to loop from ARG[3] through ARG[15],
and add only the numbers with a value between that of ARG[1] and ARG[2].
Function File
60.52 GOTO
GOTO branches to the line labeled linename.
Syntax
Syntax 1: Goto linename
Syntax 2: Goto Line linename
Syntax 3: Go linename
Syntax 4: Go To linename
Syntax 5: Go To Line linename
Examples
Example 1
In the following looping program, the GOTO statement with IF..THEN controls the
heating and cooling processes:
Program File
Line Beginning
If Temp is less than 68 then Goto Heating
If Temp is greater than 76 then Goto Cooling
Line Heating
Turn on Heater1
Goto Beginning
Line Cooling
Turn on Cool1
Goto Beginning
Both Heating and Cooling are line labels. When the temperature changes, GOTO
sends control to the appropriate line.
The controller then executes instructions in the labeled line.
Notice that the GOTOs have been strategically placed so the controller executes
some statements and skips others.
Example 2
You can include the word LINE in front of the line name, as follows:
Program File
Line 1
Start Fan1
Goto Line 2
Line 2
If Fan1_Status is on then Goto Line Shutdown
Line Shutdown
If Zone1 Temp is less than 60 then
Stop Fan1
Goto Line 1
Endif
Example 3
You can leave out TO and type only GO:
Program File
Line Beginning
If Temp is less than 68 then go Heating
If Temp is greater than 76 then go Cooling
Line Heating
Turn On Heater1
Go Beginning
Line Cooling
Turn On Cool1
Go Beginning
Example 4
You can separate GO and TO, as follows:
Program File
Line Beginning
If Temp is less than 68 then Go to Heating
IF Temp is greater than 76 then Go to Cooling
Line Heating
Turn Heater1
Go to Beginning
Line Cooling
Turn On Cool1
Go to Beginning
Example 5
You can separate GO and TO, and include LINE as well:
Program File
Line Beginning
If Temp is less than 68 then Go to Line Heating
If Temp is greater than 76 then Go to Line Cooling
Line Heating
Turn On Heating1
Go to Line Beginning
Line Cooling
Turn On Cool1
Go to Line Beginning
60.53 IF...THEN...ELSE
IF...THEN...ELSE carries out a given statement or series of statements if the
expression is TRUE.
IF...THEN...ELSE can also carry out a given statement or series of statements if the
given expression is FALSE.
For all formats, the following actions take place:
• If the expression is TRUE, the controller carries out the statement or
statements following THEN.
• If the expression is FALSE, the controller skips those statements after THEN
and does either of these actions:
– Carries out the statements after ELSE (if ELSE is used).
– Moves on to the next statement after the IF..THEN block.
Whether the expression is TRUE or FALSE, when the IF..THEN statement is
complete, program flow goes to the statement following the IF..THEN statement
unless the flow is directed to another line using GOTO, BREAK, or CONTINUE.
If you have multiple statements after THEN, they must occur on consecutive
(physical) lines, and the end of the statement must be marked with ENDIF.
Here are some general rules you should follow for all formats:
• IF and THEN must always be on the same physical line.
• THEN can be followed by one statement on the same physical line or many
statements on the physical lines that follow.
• If a multi-line statement, ELSE must always be on a physical line by itself
(Syntax 4).
• ELSE can be followed by one statement on the same physical line or multiple
statements on the physical lines that follow (Syntax 4).
• ENDIF is required to close an IF..THEN block when multiple statements occur
after THEN or when one or more statements occur after ELSE.
• When you use an IF statement after THEN, that statement must be nested
under THEN and end with ENDIF. (See Example of an IF statement after THEN,
below.)
Syntax
Syntax 1:
If expression then statement
Syntax 2:
If expression then
statement
statement
statement
..
ENDIF
Syntax 3:
If expression then statement else statement
Syntax 4:
If expression then
statement
statement
statement
...
Else
statement
statement
statement
...
Endif
Examples
Example of Syntax 1
To take a single action if the expression is TRUE, you use Syntax 1, the single-line
IF..THEN statement:
Program File
If TOD >= 1200 then Goto Noon
If the time of day is greater than 12:00 noon, then program flow moves to the
NOON line. Otherwise, the program continues with the next statement.
Note
• If you put THEN on a separate physical line from IF, a syntax error occurs.
Example of Syntax 2
To take several actions if the expression is TRUE, and take no action if the
expression is FALSE, you use Syntax 2:
Program File
If Wkd = Mon and TOD > 800 and TOD < 1600 then
Run the HeaterProg
Run the FanCheckProg
Stop the PumpProg
Endif
If the expression is FALSE, the controller ignores the statements following THEN
and moves to the statement after ENDIF.
Example of Syntax 3
To take a single action if an expression is TRUE and another single action if the
expression is FALSE, you use Syntax 3:
Program File
If TOD > 800 & TOD < 1700 then Run DayPrg else Run NiteProg
Notice that IF, THEN, and ELSE must all be on one line in this format.
Example of Syntax 4
To take several actions if the expression is TRUE or take several others if the
expression is FALSE, you use Syntax 4:
Program File
If Temp < 72 and [Link] is off then
Turn on the Fan
Close the Damper
Else
Turn off the Fan
Open the Damper
Endif
ELSE stands on a line by itself in this format, and the end of the IF.. THEN..ELSE
statement must be marked by ENDIF.
Example of nested IFs
IF statements can be included (nested) within other IF statements.
Program File
If the Wkd is Either Saturday OR Sunday then
Set Occupancy to Off
Stop the DailyProgram
If the Temp is Greater Than 70 then
Turn On the Fan
Open the Damper
Else
Turn OFF the Fan
Open the Damper
Endif
Else
Set Occupancy to On
Start the DailyProgram
Endif
Notice that each IF ends with an ENDIF. The inner (indented) ENDIF goes with the
inner IF and ELSE, the outer ENDIF with the outer IF and ELSE.
The ELSE and ENDIF that belong to the indented IF are aligned under that IF.
Notice that the last IF ends first.
Example of an IF statement after THEN
Take a look at the following statement with an IF after THEN:
Program File
If the Wkd is Sat then if the Hour is 1 then Goto 1 else Goto 2
Which IF does the ELSE belong to? In this case the ELSE belongs to the second IF.
Why? Because ELSE belongs to the closest previous IF on the same physical line.
An IF..THEN statement that starts right after THEN is always a self-contained
statement that ends on that physical line.
To make the ELSE belong to the first IF, you must form a nested IF arrangement, as
follows:
Program File
If the Wkd is Sat then
If the Hour is 1 then
Goto 1
Endif
Else
Goto 2
Endif
In this nested IF statement, the ELSE belongs with the first IF.
Example of a nonzero value number
Program File
If 10 then start Burner
Here, since 10 is a nonzero value, 10 is interpreted as TRUE and causes the burner
to fire up.
Caution
• Be careful when programming with IF..THEN..ELSE statements if the number
is any nonzero value. When this occurs, the number is interpreted as TRUE
and the THEN block is executed.
60.54 MOVE
Alias: MODULATE
MOVE converts engineering units to electrical units to control the output point,
using the top and bottom of scale for that point.
Set the point or points in output_point_list to number.
The percent sign is optional.
Syntax
MOVE output_point_list TO number
MOVE output_point_list TO number %
Products Supported
CX series, BACnet series, CMX series, SCX series, TCX series, LCX series, ACX
series, DCX 250, EcoStruxure BMS servers
Examples
Example 1
If Valve2 has engineering units of 0 to 90 degrees, and the corresponding electrical
units are 0 to 20 mA, when you move the setting of Valve2 to 45, the electrical unit
sets to 10 mA. To have the engineering units automatically converted to electrical
units, you use MOVE as follows:
Program File
MOVE VALVE2 TO 45
Example 2
For this valve, assume engineering units of 0 to 1 where 0 is closed and 1 is open
and corresponding electrical units of 0 to 20 mA. Moving the setting of Valve2 to
50% gives .5. At .5, the valve is set to the corresponding value of 10 mA.
Program File
MODULATE VALVE2 TO 50%
60.55 Repeat...Until
Repeat...Until carries out the statements in the loop until the number is true.
Syntax
Repeat
statement
statement
...
Until number
The statements within the loop always execute at least once before the expression
is evaluated.
Examples
You want to print all the values in an array:
Program File
Numeric Count
Count = 1
Repeat
Print OutsideAir [Count]
Count = Count + 1
Until Count = OutsideAir_Size
60.56 RETURN
In a function, the RETURN keyword controls the calling program, returns and sends
the number to the calling program, and returns the contents of the variable.
If you expect to use the results of a calculation in more than one program, you set
up a function file and put the calculation instructions inside, thus creating a function.
When you need the function in a program, you call the function by using the
function variable as if that function were any other keyword verb.
Later, the RETURN statement tells the function the value to return to the calling
program.
Make sure to return a number or other value when you want to use the returned
value in the calling program.
Syntax
Return
Return number
Examples
Example 1
You use RETURN without an expression to return to the calling program without
passing parameters. You might do that with a function that contains a series of
actions to be carried out, as in the SHUTDOWN function shown below:
Function File
Turn off the Heat
Turn off the Fan
Run Pump, Cooling
Return
In this case, RETURN returns you to the program that called the SHUTDOWN
function, returning a numeric 0 because you supplied no arguments on the
RETURN statement.
The statement that calls SHUTDOWN in the calling program looks like this:
Program File
Shutdown ()
Example 2
To create a function called GetArea that calculates the cross-sectional area of a
circle, name the function file GetArea and enter the following in the function file:
Function File
ARG 1 radius
Syntax
Select Case test_expression
Case expression_list
statement_list
Case expression_list
statement_list
...
Case Else
else_statement_list
EndSelect
Examples
Example 1
Program File
Select Case Weekday
Case Monday, Tuesday
60.58 STOP
Aliases: CLOSE, SHUT
With an output point, STOP actually stops the piece of equipment. With an input
point, STOP sets the point to the bottom of the defined scale. With a numeric point,
STOP sets the point to the lowest number in the controller system. You might STOP
an input after using the RUN keyword in order to test whether the input is active.
Syntax
Stop point_list
Sets the point (or points) to bottom of its defined scale, turns the equipment off, and
controls the equipment through the point. You can use this statement in a program
to turn off a piece of equipment.
Examples
You can STOP a program from inside a program in response to a certain set of
conditions. For example, to halt the HEATPROG after 8 PM:
Program File
If TOD > 2000 then stop the HeatProg
If you do not name a program after STOP, the controller assumes you mean the
current program.
60.59 WAIT
Alias: Delay
WAIT makes a program's execution wait for a specified number of seconds and
then resume right after the WAIT command statement.
Syntax
WAIT number
Products Supported
EcoStruxure BMS servers
Examples
Wait 5 'waits for 5 seconds
Wait (3) 'waits for 3 seconds
Delay 10 'waits for 10 seconds
Restrictions
You can only use the WAIT keyword in the following situations:
• At the EcoStruxure BMS server level
• In a Script program and not in a Script function
Tip
WAIT is not supported inside a For loop.
60.60 WHILE
WHILE carries out the instructions in the statements within the loop over and over
again as long as the given number is TRUE.
Syntax
While number
statement
statement
...
Endwhile
Examples
Initialize a 10 element manual array:
Program File
Numeric Counter
Set Counterto 1
While Counter <= 10
ManualArray[Counter] = Counter*10
Counter = Counter + 1
Endwhile
60.61.1 INPUT
INPUT is a binding qualifier that identifies a variable declaration as an input variable.
You can bind an input variable to an object property outside of the program. The
input variable takes on the same value as the property it is bound to. You cannot
set an input variable's value.
For more information, see section 60.62 “INPUT” on page 1754..
60.61.2 Buffered
Buffered is used exclusively as a qualifier for an input variable to indicate that the
variable can hold one or more buffered values. The type of input variable may be
Numeric, String, or DateTime.
For more information, see section 60.63 “Buffered” on page 1755.
60.61.3 OUTPUT
OUTPUT is a binding qualifier that identifies a variable declaration as an output
variable. You can bind an output variable to an object property outside of the
program. When the output variable is set, the bound property value will be set to the
same value.
For more information, see section 60.64 “OUTPUT” on page 1756..
60.61.4 PUBLIC
PUBLIC is a binding qualifier that identifies a variable as a public variable. You can
modify a public variable from outside a Script program, such as from a graphic.
For more information, see section 60.65 “PUBLIC” on page 1757..
60.62 INPUT
INPUT is a binding qualifier that identifies a variable declaration as an input variable.
You can bind an input variable to an object property outside of the program. The
input variable takes on the same value as the property it is bound to. You cannot
set an input variable's value.
Syntax
variable_declaration input namelist
Examples
Program File
If you have a program that controls a fan based on the value of a temperature input
point, you define an input variable to bind to the input's value property.
Numeric_input Temp_DegF
If Temp_DegF is greater than 75 then
Turn Fan On
Endif
60.63 Buffered
Buffered is used exclusively as a qualifier for an input variable to indicate that the
variable can hold one or more buffered values. The type of input variable may be
Numeric, String, or DateTime.
Note
The buffering of values is performed on a First-In, First-Out basis (that is, a
queue).
Syntax
type buffered input variable_name
Example
You declare a buffered input variable (BIn1) and a pair of output variables in this
sample program. BIn1 has the same value every time it is used as expected.
Note
Buffered inputs are supported only in EcoStruxure BMS server programs. They
are not supported in functions, or on b3 BACnet, Infinet, or MP Series controllers.
Program File
Numeric Buffered Input BIn1
Numeric Buffered Input BIn2
Numeric Output Out1
Out1 = BIn1 + BIn2
60.64 OUTPUT
OUTPUT is a binding qualifier that identifies a variable declaration as an output
variable. You can bind an output variable to an object property outside of the
program. When the output variable is set, the bound property value will be set to the
same value.
Syntax
variable_declaration output namelist
Examples
Program File
If you have a program that controls a thermostat temperature, you define an output
variable to bind to the thermostat's temperature property.
Numeric output Thermostat_Temp_DegF
Thermostat_Temp_DegF = 72.5
60.65 PUBLIC
PUBLIC is a binding qualifier that identifies a variable as a public variable. You can
modify a public variable from outside a Script program, such as from a graphic.
Public behaves like an output variable, so you may bind the public variable to the
value of a point, or to the input variable of a Script program as you would with any
output variable. Unlike an output variable, you do not have to use the force
capability to modify Public from the Script property grid, or from a graphic.
You should use the Public binding qualifier when you need to directly modify that
variable from the Script property grid (that is, modify the value the Public binding
variable is bound to). Unlike an output variable, you can manually change the value
of the Public variable from a graphic. You can also use Public to monitor and control
user input values from the Script property grid or a graphic.
The advantage here is that you can use Public quickly without forcing the value or
having to edit and save the Script program. Public holds its value even after a Script
program save, power failure, warm start, cold start, or reboot from the Device
Administrator.
Syntax
variable_declaration public namelist
Examples
Program File
Assume you want to set an output in your Script program using the PUBLIC
variable.
Numeric public ReceivedValue
Numeric Output OutputValue
Set OutputValue to ReceivedValue
60.66 Expressions
Instructions that consist of mathematical operations are called expressions.
Expressions can also be item names or constants that return a numeric or string
result.
60.67 Variables
A variable is a run-time (dynamically changing) property of an object.
Script supports program, system, and runtime variables.
To declare a variable
1. In Script Editor, declare the variable you want to use in the program or
function:
• Declare the variable using the type keyword Numeric, String, or DateTime
before the name of the variable.
• Declare the variable using the binding keyword Input, Output, or Public
after the type keyword, and before the name of the variable, to enable
bindings to the variable.
You have now declared the variables in your Script program or function. These
declarations are then followed by one or more program lines or instructions that
specify the operations to perform.
Note
• Script supports characters at or below ASCII 127. Additional characters are
not supported and are replaced by a question mark (?).
Note
• The array index option is not supported for binding variables.
Examples
Numeric A
Datetime D
String S
Numeric Input A1
Numeric Input A2, A3, A4
Numeric Input A2, A3, A4
String Input S1
Datetime Input DT1
Numeric Output B1
String Output outstr1
Datetime Output outdt1
Numeric Fan_SP [20], Temp [20]
You can declare local variable types using the following keyword statements:
• Numeric
• String
• DateTime
• Function
• WebService
Numeric keyword
The Numeric keyword assigns the name that follows as a local numeric variable:
Numeric RateOfRise
String Keyword
The String keyword assigns the name that follows as a local string variable:
String DirtyFilterMsg
DateTime Keyword
The DateTime keyword assigns the name that follows as a local variable that
accepts a date and time:
DateTime LocalDateTime
Function Keyword
The Function keyword assigns the name that follows as a local variable, which you
bind to a Script user-defined function.
Function MyFunction
WebService Keyword
The WebService keyword assigns the name that follows as a local variable, which
you bind to a Script Web Service object.
WebService wsCalculator
Tip
The Input and Output qualifiers apply only to the Numeric, String, and DateTime
types.
The type of the object property you bind a local variable to must match the type of
the local variable you plan to bind to. For example, you must bind a Numeric local
variable to object property types such as integer, double, float, digital, and
enumeration. Similarly, you must also bind strings to string type properties, and
datetimes to datetime properties.
1 8.00
2 8.51
3 9.00
4 9.62
5 10.00
6 10.75
7 11.00
8 11.25
CLOCK[1] is 8.00, CLOCK[2] is 8.51, CLOCK[3] is 9.00, and so on. Each entry in an
array is referred to as an element. An array can contain up to 32,767 elements.
You can also put a numeric variable in place of the index number, such as
CLOCK[COUNT]. The variable is called an index variable.
When you define an array variable, you must specify a type (numeric, string, or
datetime) and the number of elements. The following statement defines (declares) a
local array called “Temperature” as numeric with 50 elements:
NUMERIC TEMPERATURE[50]
60.74.1 TS
TS is a Script program runtime property that contains the number of seconds (Time
in Seconds) that have elapsed since the program has been on the current line.
TS stands for Time in Seconds.
For more information, see section 60.75 “TS” on page 1769..
60.74.2 TM
TM is a Script program runtime property that contains the number of minutes (Time
in Minutes) that have elapsed since the program has been on the current line.
TM stands for Time in Minutes.
For more information, see section 60.76 “TM” on page 1770..
60.74.3 TH
TH is a Script program runtime property that contains the number of hours (Time in
Hours) that have elapsed since the program has been on the current line.
TH stands for Time in Hours.
For more information, see section 60.77 “TH” on page 1771..
60.74.4 TD
TD is a Script program runtime property that contains the number of days (Time in
Days) that have elapsed since the program has been on the current line.
TD stands for Time in Days.
For more information, see section 60.78 “TD” on page 1772..
60.75 TS
TS is a Script program runtime property that contains the number of seconds (Time
in Seconds) that have elapsed since the program has been on the current line.
TS stands for Time in Seconds.
Syntax
TS
Example
To allow for a 90-second valve stroke time, see if 90 seconds have elapsed since
you opened the valve.
Program File:
The controller measures 90 seconds starting the instant that the program is on the
line making the request for elapsed time.
60.76 TM
TM is a Script program runtime property that contains the number of minutes (Time
in Minutes) that have elapsed since the program has been on the current line.
TM stands for Time in Minutes.
Syntax
TM
Example
To have a 5-minute warmup of a fan before turning on the pump, you would check
to see if the fan has been running for 5 minutes after activation.
Program File:
The controller measures 5 minutes starting the instant that the program is on the
line making the request for elapsed time.
60.77 TH
TH is a Script program runtime property that contains the number of hours (Time in
Hours) that have elapsed since the program has been on the current line.
TH stands for Time in Hours.
Syntax
TH
Example
To have the lead fan run 1 hour then run the lag fan, you would check to see if the
fan has been running for 1 hour after activation.
Program File:
The controller measures 1 hour starting the instant that the program is on the line
making the request for elapsed time.
60.78 TD
TD is a Script program runtime property that contains the number of days (Time in
Days) that have elapsed since the program has been on the current line.
TD stands for Time in Days.
Syntax
TD
Example
In order to have a lead pump run for 3 days, then turn on the lag pump, you would
check to see if the pump has been running for 3 days after activation.
Program File:
The controller measures 3 days starting the instant that the program is on the line
making the request for elapsed time.
Tip
You can print out a datetime variable to see what date and time the variable
contains. However, the date and time that prints out is a predefined format you
cannot change. The date and time prints in this format (in the 24-hour clock):
MONTH DD YYYY hh:mm:ss
60.80.1 DATE
DATE retrieves the current system date and time so that you can then store them in
a variable.
The value for DATE is always the current date.
DATE is designed to be used with DIFFTIME, along with a datetime variable (defined
using the DATETIME statement).
For more information, see section 60.81 “DATE” on page 1777..
60.80.2 DAYOFMONTH
DAYOFMONTH gives the day of month from 1 to 31.
You cannot change the DAYOFMONTH. The EcoStruxure BMS server
automatically updates this value.
For more information, see section 60.82 “DAYOFMONTH” on page 1778..
60.80.3 DAYOFYEAR
DAYOFYEAR gives the number of the day of the year, between 1 and 366.
You cannot change the DAYOFYEAR. The EcoStruxure BMS server automatically
updates this value
For more information, see section 60.83 “DAYOFYEAR” on page 1779..
60.80.4 HOD
HOD gives the time in a decimal form from 0.0 to 23.99.
You cannot change the HOD. The system automatically updates this value.
60.80.5 HOUR
HOUR gives the current hour, from 0 to 23.
If the time is 5:23:02, the hour is 5.
The system automatically updates the HOUR variable.
For more information, see section 60.85 “HOUR” on page 1781..
60.80.6 MINUTE
MINUTE gives the exact minute of the current hour, from 0 to 59.
The minute is the minute on the controller clock, so if the time is 5:23:02, the minute
is 23.
You cannot change the MINUTE. The EcoStruxure BMS server automatically
updates this value.
For more information, see section 60.86 “MINUTE” on page 1782...
60.80.7 MONTH
MONTH gives you the current month of year, from January to December.
You cannot change the MONTH. The EcoStruxure BMS server automatically
updates this value.
For more information, see section 60.87 “MONTH” on page 1783...
60.80.8 SECOND
SECOND gives the exact number of seconds of the current minute, from 0 to 59.
The number of seconds is as indicated by the EcoStruxure BMS server clock. If the
time is 10:02:12, then SECOND equals 12.
For more information, see section 60.88 “SECOND” on page 1785..
60.80.9 TOD
TOD gives the time of the day from 0 (midnight) to 2359, where 2359 is the
equivalent of 23:59 on the 24-hour clock.
The time of day is the time from the controller clock. You cannot change TOD since
the controller automatically updates that setting.
For more information, see section 60.89 “TOD” on page 1786..
60.80.10 UTCOffset
UTCOffset specifies the current Universal Time Coordinate (UTC) offset in seconds.
It represents the difference in seconds between your local time and Greenwich
Mean Time (GMT) as follows:
• 18000 indicates you are 18000 seconds, or 300 minutes, or 5 hours ahead of
GMT.
• -18000 indicates you are 18000 seconds, or 300 minutes or 5 hours behind
GMT.
For more information, see section 60.90 “UTCOffset” on page 1787.
60.80.11 WEEKDAY
WEEKDAY gives current day of week, from SUNDAY through SATURDAY.
When printed, the weekday is spelled out as Sunday, Monday, Tuesday,
Wednesday, and so on through Saturday.
For more information, see section 60.91 “WEEKDAY” on page 1788..
60.80.12 YEAR
YEAR gives the current year. You cannot change the YEAR. The system
automatically updates the value.
When printed, the four-digit year is given.
For more information, see section 60.92 “YEAR” on page 1790...
60.81 DATE
Alias: TIME
DATE retrieves the current system date and time so that you can then store them in
a variable.
The value for DATE is always the current date.
DATE is designed to be used with DIFFTIME, along with a datetime variable (defined
using the DATETIME statement).
Syntax
Date
Example
Once you have defined the datetime variable called TEMP_DATE using the
DATETIME statement, you can then set the value of that variable using the DATE
system variable, as follows:
Program file
Datetime Temp_Date
Temp_Date = Date
This way, TEMP_DATE retrieves the exact system date and time at a given
moment.
You can, for example, record the date and time that a point changes. You can use
the variable you have created in subsequent calculations.
60.82 DAYOFMONTH
Alias: DOM
DAYOFMONTH gives the day of month from 1 to 31.
You cannot change the DAYOFMONTH. The EcoStruxure BMS server
automatically updates this value.
Syntax
DayOfMonth
Example
Example 1
To print out a headline that contains the date, you would use DAYOFMONTH, as
shown below:
Program File
Print "The kwh history for", MONTH, DayofMonth, "," , YEAR
The resulting header would print the actual month, day of the month, and year, like
this:
The kwh History for October 15, 2008
Example 2
To make some events occur only on particular days of each month, you could set
up an IF..THEN statement that would check for the day of the month:
Program File
If DayofMonth is between 7 and 14 then…
60.83 DAYOFYEAR
Alias: DOY
DAYOFYEAR gives the number of the day of the year, between 1 and 366.
You cannot change the DAYOFYEAR. The EcoStruxure BMS server automatically
updates this value
Syntax
DayOfYear
Example
Suppose on a certain date, you need to switch off the heating and switch on
cooling. You would use DAYOFYEAR to instruct the controller:
Program File
If DayofYear is 152 then
Stop the Heating_Prog
Run the Cooling_prog
Endif
60.84 HOD
Alias: HOUROFDAY
HOD gives the time in a decimal form from 0.0 to 23.99.
You cannot change the HOD. The system automatically updates this value.
Syntax
HOD
Example
Example 1
You can use the decimal form of the time to see if the time is past 5:30 a.m.:
Program File
If HOD is greater than 5.50 then...
Example 2
A simple way to calculate the StartTime based on OutsideAir could use HOD as
follows:
Program File
If OutsideAir > 70 then Goto CoolStart
Set StartTime = (8.00 - (70-OutsideAir) * RateOfRise)
If HOD = StartTime then Goto StartBldg
60.85 HOUR
Alias : HR
HOUR gives the current hour, from 0 to 23.
If the time is 5:23:02, the hour is 5.
The system automatically updates the HOUR variable.
Syntax
Hour
Example
To take action every day at 5:00 a.m., you would check the hour with the following
statement:
Program File
If Hour is equal to 5 then Goto Startup
60.86 MINUTE
Alias: MIN
MINUTE gives the exact minute of the current hour, from 0 to 59.
The minute is the minute on the controller clock, so if the time is 5:23:02, the minute
is 23.
You cannot change the MINUTE. The EcoStruxure BMS server automatically
updates this value.
Syntax
Minute
Example
Suppose you have eight programs to run every hour. To avoid customizing scan
time by running all the programs at once, you could run two programs in each
quarter of any hour:
Program File
If Minute equals 15 then
Run the System_Check
Run the Power_Usage
Endif
If Minute equals 30 then
Run the Temp_Check
Run the Temp_Rept
Endif
If Minute equals 45 then
Run the Fan_Check
Run the Damper_Check
Endif
If Minute equals 0 then
Run the Heater_Check
Run the CO_Check
Endif
The SYSTEM_CHECK and POWER_USAGE programs now run at 15 minutes after
the hour every hour of every day, 24 hours a day and 365 days a year.
The TEMP_CHECK and TEMP_REPT programs now run at 30 minutes after the
hour every hour of every day, 24 hours a day and 365 days a year.
The FAN_CHECK and DAMPER_CHECK programs now run at 45 minutes after the
hour every hour of every day, 24 hours a day and 365 days a year.
The HEATER_CHECK and CO_CHECK programs now run on the hour every hour
of every day, 24 hours a day and 365 days a year.
60.87 MONTH
Alias: MTH
MONTH gives you the current month of year, from January to December.
You cannot change the MONTH. The EcoStruxure BMS server automatically
updates this value.
When printed, the month is spelled out as January, February, March, and so on
through December. You can also compare the MONTH to:
• The numbers (1 through 12).
• The abbreviated three-letter names (first three letters).
All values for MONTH are listed below:
1 JAN JANUARY
2 FEB FEBRUARY
3 MAR MARCH
4 APR APRIL
5 MAY MAY
6 JUN JUNE
7 JUL JULY
8 AUG AUGUST
9 SEP SEPTEMBER
10 OCT OCTOBER
11 NOV NOVEMBER
12 DEC DECEMBER
Syntax
Month
Example
Example 1
You can use the spelled out (long) names for printing or for comparing to an actual
month:
Program File
If Month is December then print Month
Output
Saturday
Example 2
You can use the short names for comparing the month:
Program File
If Month is either JUN, JUL, AUG or SEP then…
Example 3
You can use the constants 1 through 12 for comparing the month:
Program File
If Month is 2 then…
60.88 SECOND
Alias: SEC
SECOND gives the exact number of seconds of the current minute, from 0 to 59.
The number of seconds is as indicated by the EcoStruxure BMS server clock. If the
time is 10:02:12, then SECOND equals 12.
Syntax
Second
Example
If you want to take action every time 50 seconds of the minute have gone by, you
enter the following program statement:
Program File
If Second is greater than 50 then…
60.89 TOD
Alias: TIMEOFDAY
TOD gives the time of the day from 0 (midnight) to 2359, where 2359 is the
equivalent of 23:59 on the 24-hour clock.
The time of day is the time from the controller clock. You cannot change TOD since
the controller automatically updates that setting.
Syntax
TOD
Example
Example 1
To check to see if the time of day is past 5:00 AM, you enter the following program
line:
Program File
If TOD is greater than 500 then…
Example 2
When you print out TOD, as in the following example, you always receive the 24-
hour time:
Print TOD
The time displays as follows:
20.000 (that means 8:00:00 PM)
60.90 UTCOffset
Alias: none
UTCOffset specifies the current Universal Time Coordinate (UTC) offset in seconds.
It represents the difference in seconds between your local time and Greenwich
Mean Time (GMT) as follows:
• 18000 indicates you are 18000 seconds, or 300 minutes, or 5 hours ahead of
GMT.
• -18000 indicates you are 18000 seconds, or 300 minutes or 5 hours behind
GMT.
Syntax
UTCOffset
Example
To adjust the local date by the UTC offset of the local server, you enter the
following:
Program File
Datetime Output MyDate
MyDate = Date + UTCOffset
60.91 WEEKDAY
Alias: WKD
WEEKDAY gives current day of week, from SUNDAY through SATURDAY.
When printed, the weekday is spelled out as Sunday, Monday, Tuesday,
Wednesday, and so on through Saturday.
You can also compare the WEEKDAY to:
• The numbers 1 through 7 (1 equal to Sunday).
• The abbreviated three-letter names (first three letters).
Note
• If you use both Script and Function Block programming, for example, when
using control sequences, be aware of the following. Script uses Sunday as
the first day of the week and assigns a value of 1 to that day, while Function
Block uses Monday as the first day of the week and assigns Monday a value
of 1.
1 SUN SUNDAY
2 MON MONDAY
3 TUE TUESDAY
4 WED WEDNESDAY
5 THU THURSDAY
6 FRI FRIDAY
7 SAT SATURDAY
Syntax
Weekday
Example
Example 1
You can spell out names for printing or for comparing to an actual day:
Program File
If Weekday is Saturday then Print Weekday
Output
Saturday
Example 2
You can use the short name or the constants 1 through 7 for comparing the
weekday in an IF statement:
Program File
If Weekday > Sun OR Weekday < 7 then…
60.92 YEAR
Alias: YR
YEAR gives the current year. You cannot change the YEAR. The system
automatically updates the value.
When printed, the four-digit year is given.
Syntax
Year
Example
To take an action in the distant future, such as sending a reminder message to
check certain pieces of equipment, you use the YEAR system variable to test the
year:
Program File
If year is 2010 THEN PRINT "Welcome to the year Two Thousand and
Ten."
60.93.1 ERRORS
ERRORS, a variable the controller maintains, indicates the number of system errors
pending. The number increments (increases by one) each time a new error occurs
and is cleared when manually reset to zero (0).
For more information, see section 60.94 “ERRORS” on page 1792..
60.93.2 FREEMEM
FREEMEM contains the number of bytes of free memory in the largest single
contiguous memory block on a controller.
For more information, see section 60.95 “FREEMEM” on page 1793..
60.93.3 SCAN
SCAN indicates the length in seconds of the last interpreter scan interval, which the
program updates regularly.
For more information, see section 60.96 “SCAN” on page 1794..
60.94 ERRORS
ERRORS, a variable the controller maintains, indicates the number of system errors
pending. The number increments (increases by one) each time a new error occurs
and is cleared when manually reset to zero (0).
The controller automatically updates ERRORS. You can only reset the controller to
zero.
The controller increments ERRORS when any of the following occurs:
• A Script program error disables a program (which also sets the program
ERROR attribute).
• The controller’s input reference voltage goes out of its normal range, usually
when you apply too much voltage to one or more inputs.
• The controller’s output reference voltage goes out of its normal range, usually
when drawing too much current from one or more inputs.
• The EcoStruxure BMS server has trouble transmitting or receiving data.
• Someone resets a controller.
• Someone turns off the AC power to a controller so that the AC power shuts
down, but the battery retains memory.
Syntax
Errors
Example
Since the ERRORS variable automatically decrements after you acknowledge an
error, the value of the variable should never get very large.
In the sample program below, you set a limit to how many errors can accumulate
and generate a report on all errors if the limit is exceeded:
Program File
If Errors > 10 then
Goto Report_Error
60.95 FREEMEM
FREEMEM contains the number of bytes of free memory in the largest single
contiguous memory block on a controller.
For system managers only. Primarily designed to be used on the command line
only, not in programs, because the value of FREEMEM does not change
dynamically. Primarily, FREEMEM is used in the programs to slow the controller
scan.
Syntax
Freemem
Example
If you want to know the size of the largest block of free memory available on a
controller, enter the following:
Program File
Print Freemem
60.96 SCAN
Alias: SC
SCAN indicates the length in seconds of the last interpreter scan interval, which the
program updates regularly.
Syntax
Scan
Example
To find the average number of seconds per scan, you would run the following
program once every scan after all other programs have been run.
Program File
Numeric Tot_Scan_SCS, Scan_Count, Scan_Avg
Set Tot_Scan_SCS, Scan_Count, Scan_Avg = 0
Line Totaling
Tot_Scan_SCS = Tot_Scan_SCS + Scan
Scan_Count = Scan_Count + 1
If TOD = 2359 then
Scan_Avg = Tot_Scan_SCS/Scan_Count
Print "The average scan for", WKD " is", Scan_Avg, "sec"
Set Scan_Avg = 0
Set Scan_Count = 0
Set Tot_ScSCS = 0
Endif
For each scan the program adds the seconds that scan took to the total seconds
for the day. Also for each scan, the program adds 1 to the scan counter.
At the end of the day (2359, or 11:59 PM), the program divides the scan total by the
number of scans to get the average length of the scans that day. The program then
prints the average for the day.
The numeric variables used to calculate the average number of scans per day are all
set to zero at the end of each day, so that they start at zero the next day.
Note
Script functions support up to 15 arguments.
Tip
You can use the RETURN statement to return a value to the calling program or
function.
For more information, see section 60.101 “Script Functions that Return a Value” on
page 1800.
Note
• Use a variable instead of an expression in the RETURN statement because
the name of the variable, when created, should generally describes its
purpose.
• LOG
• RANDOM
• SQRT
• SUM
For more information, see section 60.117 “Mathematical Functions” on page
1822...
• MINIMUM
• MINITEM
• StandardDeviation
For more information, see section 60.136 “Statistical Functions” on page 1844...
• TAN
For more information, see section 60.157 “Trigonometric Functions” on page
1874.. .
60.110.1 GetBufferSize
GetBufferSize returns the current buffer size (that is, the number of buffered values)
of a passed buffered input variable.
For more information, see section 60.111 “GetBufferSize” on page 1814.
60.110.2 GetBufferedValue
GetBufferedValue gets the next available value of the passed buffered input
variable. This function returns Success or Failure.
For more information, see section 60.112 “GetBufferedValue” on page 1816.
60.111 GetBufferSize
GetBufferSize returns the current buffer size (that is, the number of buffered values)
of a passed buffered input variable.
GetBufferSize is not supported in the MP Series controller.
Note
A returned value of 0 indicates that the passed argument is not a buffered input
variable, or that there is no buffered input variable value. If two or more arguments
are passed, the program goes to Line E if one exists. When the program goes to
Line E, it indicates that an error has occurred.
Syntax
GetBufferSize (variable_name)
Example
You can use the following program to check the buffer size and if the number of
items in the buffer exceeds 15, empty the buffer.
Program File
Note
This program, [Link], is included in the Sample Import Files
folder in the Code Library. For more information, see section 61.24 “Working with
Code Library Sample Import Files” on page 1919.
60.112 GetBufferedValue
GetBufferedValue gets the next available value of the passed buffered input
variable. This function returns Success or Failure.
GetBufferValue is not supported in the MP Series controller.
Note
If the returned value is zero, it is not a buffered input variable. If two or more
arguments are passed, the program is disabled or goes to Line E if one exists.
When the program goes to Line E, it indicates an error has occurred.
Syntax
GetBufferedValue (variable_name)
Example
You declare two buffered input variables (BIn1 and BIn2) and two output variables in
this example. BIn1 has the same value every time it is used as expected until a call
is made to the function GetBufferedValue to obtain the next buffered value. This
example checks to see if there are any buffered values for BIn1 by calling the
GetBufferSize function and making sure that the number of buffered values is
greater than zero. Then, it gets the next available value from the buffer. BIn1
assumes that newly-obtained value.
Program File
Numeric Buffered Input BIn1
Numeric Buffered Input BIn2
Numeric Output Out1
Numeric Output Out2
Out1 = BIn1 + BIn1
Out2 = 0
While GetBufferSize (BIn2) > 0
if GetBufferedValue (BIn2) = Success then
Out2 = Out2 + Bin2 'add all buffered values
Endif
EndWhile
60.113.1 NUMTOSTR
NUMTOSTR converts a number in a numeric variable or other numeric form to a
string variable so the number can be used in string operations. NUMTOSTR returns
the converted string value.
For more information, see section 60.114 “NUMTOSTR” on page 1818...
60.113.2 STRTODATE
STRTODATE returns a datetime that corresponds to the particular date and time
you specify in the date_time. The controller has a unique number for each
understandable moment in time.
For more information, see section 60.115 “STRTODATE” on page 1819..
60.113.3 STRTONUM
STRTONUM converts a string that contains a number in a string variable or other
string form to a numeric variable for use in mathematical operations. StrToNum
returns the converted numeric value.
For more information, see section 60.116 “STRTONUM” on page 1821..
60.114 NUMTOSTR
NUMTOSTR converts a number in a numeric variable or other numeric form to a
string variable so the number can be used in string operations. NUMTOSTR returns
the converted string value.
Syntax
NumToStr ( number )
Examples
The following program translates the number 240 into a string:
Program File
String Trans
Trans = NumToStr (240)
Print TRANS
TRANS is no longer numeric and cannot be used in calculations.
60.115 STRTODATE
Alias: STRTOTIME
STRTODATE returns a datetime that corresponds to the particular date and time
you specify in the date_time. The controller has a unique number for each
understandable moment in time.
The system uses this date_time to process information about the date and time. If
you print a variable that is equal to a STRTODATE, you receive the date_time.
Note
Be aware that STRTODATE converts a text string to local rather than UTC time.
To receive the date and time from STRTODATE, you must enter both the date and
the time in one continuous input line. You can position the time before the date on
that line, if you prefer.
You can set up the date in any reasonably interpretable format—using all numbers
or spelling the month as either the full word or the three-letter abbreviation. You can
also separate the month, day, and year with spaces, slashes, dashes, periods,
commas, or any combination of these punctuation characters.
DAY and MONTH If you prefer to put the day first, ensure that the day is obviously a
day. There are two ways that a day cannot be misinterpreted as a month:
• Spell the month as a word so that the day is the only other number so low.
• Use numbers for both month and day only if the day is greater than 12, since
any number between 1 and 12 could be a month.
The month can be any of the following options:
• JAN[UARY]
• FEB[RUARY]
• MAR[CH]
• APR[IL]
• MAY
• JUN[E]
• JUL[Y]
• AUG[UST]
• SEP[TEMBER]
• OCT[OBER]
• NOV[EMBER]
• DEC[EMBER]
YEAR
You must enter the year as a four-digit year after 2008.
WEEKDAY
Since the controller already knows the day of the week that corresponds to each
date, you don’t need the day. You can, however, place the day of the week after
the date. The day of week must be either the three-letter abbreviation or the
completely spelled-out name of the day.
Syntax
StrToDate (date_time)
Examples
Program File
CONV_DATE = StrToDate (‘SEPTEMBER-21-2000 11:00 pm’)
60.116 STRTONUM
Alias: VAL
STRTONUM converts a string that contains a number in a string variable or other
string form to a numeric variable for use in mathematical operations. StrToNum
returns the converted numeric value.
Once a number is in a numeric variable, the number can be used in mathematical
expressions and operations.
Syntax
StrToNum (string)
Examples
If you receive string input from the keyboard, but want the input to be numeric so
you can add another number, you use STRTONUM. The following program adds
the string (in quotation marks) that contains 78.5 to the number 92.8:
Program File
Numeric Trans
Trans = StrToNum ("78.5") + 92.8
Output
171.3
60.117.1 ABS
ABS returns the absolute value of number. The absolute value of any number,
positive or negative, is always the positive number.
For more information, see section 60.118 “ABS” on page 1824..
60.117.2 EXPONENTIAL
EXPONENTIAL returns a value equal to the base e raised to the number power.
For more information, see section 60.119 “EXPONENTIAL” on page 1825..
60.117.3 FACTORIAL
FACTORIAL returns the factorial of integer_expression.
For more information, see section 60.120 “FACTORIAL” on page 1826..
60.117.4 LN
LN returns the natural logarithm of any number_expression.
For more information, see section 60.121 “LN” on page 1827..
60.117.5 LOG
LOG returns the base 10 logarithm of integer_expression.
For more information, see section 60.122 “LOG” on page 1828..
60.117.6 RANDOM
RANDOM returns a random number from 0 to 32,767 using number. Random is
used to simulate real-life values to test programs.
For more information, see section 60.123 “RANDOM” on page 1829..
60.117.7 SQRT
SQRT returns the square root of the number.
60.117.8 SUM
SUM returns the sum of the listed items (Syntax 1), the sum of an array (Syntax 2),
or the sum of a numeric log (Syntax 3).
For more information, see section 60.125 “SUM” on page 1831.
60.118 ABS
ABS returns the absolute value of number. The absolute value of any number,
positive or negative, is always the positive number.
Syntax
ABS (number)
Examples
Example 1
You find the absolute value of -3 as follows:
Program File
Result=ABS(-3)
This statement sets RESULT to 3.
To maintain a setpoint temperature to within plus or minus 3 degrees, when the
temperature changes in either direction, the fan should blow in either the heating or
cooling as required.
In this situation, you should find the absolute value of the change to control the fan.
Whether the change is positive or negative makes no difference.
Example 2
Program File
If ABS(Temp_SP - Temp_2) >= 3 then run Fan_2
60.119 EXPONENTIAL
Alias: EXP
EXPONENTIAL returns a value equal to the base e raised to the number power.
Syntax
Exponential (number)
Examples
Example 1
Program File
EVAL = Exponential (0)
The result of e to the 0 power is 1. Because the EXPONENTIAL function returns 1,
EVAL is set to 1.
Example 2
Program File
R_VAL = Exponential (-1)
The result of e to the -1 power is 0.368, so R_VAL is set to 0.368.
60.120 FACTORIAL
Alias: FACT
FACTORIAL returns the factorial of integer_expression.
Syntax
Factorial (integer_expression)
Examples
The following statement sets FVAL to the result of factorial 3:
Program File
FVAL = Factorial (3)
The function returns 6, so FVAL = 6.
60.121 LN
LN returns the natural logarithm of any number_expression.
Syntax
LN (number_expression)
Table: LN Parameter
Parameter Description
Examples
Program File
LGVAL = LN(3.2)
The natural log is returned and placed in LGVAL.
60.122 LOG
LOG returns the base 10 logarithm of integer_expression.
Syntax
LOG (number_expression)
Examples
Program File
Result = LOG(10)
This statement sets RESULT equal to 1.
60.123 RANDOM
Alias: RND
RANDOM returns a random number from 0 to 32,767 using number. Random is
used to simulate real-life values to test programs.
You must vary the number to generate different random sequences. If you do not
vary the number, you can see a repetitious pattern of values emerging over time.
Syntax
Random (number)
Examples
To simulate fluctuations of temperature between 50 and 70 degrees, you put any
number in the number. To generate a result in the range of 20 possible
temperatures, you divide the random number you generate by 32767, which gives
you a number between 0 and 1. Then multiply the result by 20. Finally, add 50
degrees to set the bottom of the range.
Program File
Random (8)/32767 times 20
Finally you add the bottom of the range you are trying to simulate to the random
number:
Program File
Temp = (Random (8)/32767 times 20) + 50
60.124 SQRT
SQRT returns the square root of the number.
Syntax
SQRT (number)
Examples
Program File
MVAL = SQRT (4)
The SQRT function returns 2 and the statement sets MVAL to 2.
60.125 SUM
SUM returns the sum of the listed items (Syntax 1), the sum of an array (Syntax 2),
or the sum of a numeric log (Syntax 3).
Items in the list must all be either numbers or variables that contains numbers.
If any of the items in the list in Syntax 1 is an array or a log, the controller retrieves
the first item from the array or log and treats that item like any other single one in the
list.
Syntax
Format 1: Sum (numeric_list)
Format 2: Sum (numeric_array)
Format 3: Sum (numeric_log)
Examples
Example 1
To sum several timers, you place them directly in the SUM function statement. You
list them in parentheses after SUM, as follows:
Program File
Total_Timers = Sum (Timer1, Timer2. Timer3, Timer4)
Example 2
You have been storing calculated values in an array called PARTTME. You then use
the sum on that array, as follows:
Program File
TotalTime = Sum (PartTime)
Example 3
You have been logging temperatures in a log for several hours. To find the sum of
them, you find the sum of that log, as follows:
Program File
HourlyTot = Sum (TempLog)
Example 4
You find the sum of several temperatures in a list, including the current value of
TEMPLOG, as follows:
Program File
HourlyAvg = Sum (Tmp801, Tmp802, TempLog)
60.126.1 ReadProperty
ReadProperty retrieves the value of a property of a BACnet object.
For more information, see section 60.127 “ReadProperty” on page 1834...
60.126.2 Relinquish
Relinquish relinquishes a command. (You may also use WriteProperty and pass no
argument for the value).
For more information, see section 60.128 “Relinquish” on page 1835..
60.126.3 WriteProperty
WriteProperty sets the value of a property of a BACnet object. The returned value is
either SUCCESS or FAILURE.
For more information, see section 60.129 “WriteProperty” on page 1836..
60.127 ReadProperty
ReadProperty retrieves the value of a property of a BACnet object.
Syntax
ReadProperty (object_property)
Products Supported
b3 series controllers, EcoStruxure BMS servers
Examples
Example 1
Use ReadProperty to get a property value, without designating the property name:
Numeric Input AV1
Numeric Temp
Temp = ReadProperty (AV1)
Example 2
Use ReadProperty to get the description of an analog point and place it in a string
point:
String Input AV1_Description
String StringPoint
StringPoint = ReadProperty (AV1_Description)
60.128 Relinquish
Relinquish relinquishes a command. (You may also use WriteProperty and pass no
argument for the value).
Either an application program or operator issues a command to write to the
commandable property of a BACnet object, or relinquishes a command issued at
an earlier time.
A relinquish operation is similar to a WriteProperty operation, except that it places a
NULL value in the Priority_Array corresponding to the appropriate priority. When
that occurs, the next lower priority, non-NULL position, takes control of the
property.
If all the priority table array elements are NULL, the commandable property
assumes the one defined in the Relinquish Default property of the object.
Note
• Present Value is the commandable property for the following classes: Analog
Output, Binary Output, Multistate Output, Analog Value, Multistate value,
Binary Value.
Syntax
Relinquish (object_property, priority)
Products Supported
b3 series controllers, EcoStruxure BMS servers
Example
Use Relinquish to relinquish the last command issued with priority 5. This statement
places a NULL in the fifth entry of the priority array (1-biased):
Numeric Output AV1
Relinquish (AV1,5)
60.129 WriteProperty
WriteProperty sets the value of a property of a BACnet object. The returned value is
either SUCCESS or FAILURE.
Syntax
WriteProperty (object_property, value, priority, index)
Products Supported
b3 series controllers, EcoStruxure BMS servers
Examples
Example 1
Use WriteProperty to set the analog value of an object to 100.
‘Value property is assumed
Numeric Output AV1
WriteProperty (AV1, 100)
Example 2
Use WriteProperty to set the Present_Value property of an object to 100, using
priority 5:
Numeric Output AV1
WriteProperty (AV1, 100, 5)
Example 3
Use WriteProperty to relinquish a command using priority 5:
Exceptions
When an EcoStruxure BMS server program uses the WriteProperty keyword to set
the value of a BACnet object (including b3 objects), the value is always written to
priority 16. For example, if you bind the program’s output to an analog value in
$SERVER/BACnet Device/Application and add it to a task, the value is written to
the analog output’s priority 16.
To write to a specific priority in a BACnet object from an EcoStruxure BMS server
program, the program must be bound directly to the priority you wish to write to.
This means that the priority no longer gets passed an argument as shown in the
examples that follow.
‘bound to BACnet analog value AV1 Priority 5
Numeric output x
Numeric a
‘places the value of 100 into AV1 Priority 5 slot
WriteProperty (x, 100)
‘places the value of AV1 Priority 5 into variable a
a = ReadProperty (x)
‘relinquishes the AV1 Priority 5 value
Relinquish (x)
‘relinquishes the AV1 Priority 5 value
‘Value argument is not passed into the WriteProperty
‘function
WriteProperty (x, )
WriteProperty (x)
Syntax
Passed (arg_number)
Examples
You can create a function that takes an argument and checks to see if the
argument is passed. The function below returns the number of the argument that
has the highest value and also returns after finding the first argument that is not
passed. The function called MAXITEM, predefined in the language, is shown as
follows:
Function File
Numeric Count, Lastmax
Lastmax = 1
For Count = 1 TO 15
If not(Passed (Count)) then return (Lastmax)
If ARG[Count] > Lastmax then Lastmax = Count
Next Count
60.131.1 CEILING
CEILING rounds a number to the next larger integer on the number line and returns
that integer.
For more information, see section 60.132 “CEILING” on page 1840..
60.131.2 FLOOR
FLOOR returns the next smaller integer on the number line and returns that integer.
For more information, see section 60.133 “FLOOR” on page 1841..
60.131.3 ROUND
ROUND rounds a number to the nearest integer and returns that value.
For more information, see section 60.134 “ROUND” on page 1842..
60.131.4 TRUNCATE
TRUNCATE drops the fractional part of number and returns the integer.
For more information, see section 60.135 “TRUNCATE” on page 1843..
60.132 CEILING
CEILING rounds a number to the next larger integer on the number line and returns
that integer.
See ROUND for a comparison of all rounding functions.
Syntax
Ceiling (number)
Examples
Example 1
Program File
The following shows how the controller calculates the ceiling of -2.7:
Top = Ceiling(-2.7)
This statement returns -2.
Example 2
Program File
RndVal = Ceiling(4.3)
This statement returns 5.
60.133 FLOOR
FLOOR returns the next smaller integer on the number line and returns that integer.
Syntax
Floor (number)
Examples
Example 1
Program File
TmpVar = Floor (42.7)
This statement returns 42.
Example 2
Program File
Result = Floor(-1.1)
This statement returns -2.
60.134 ROUND
ROUND rounds a number to the nearest integer and returns that value.
The number is any number or expression.
ROUND, CEILING, FLOOR, and TRUNCATE are similar, but differ in the following
ways:
• ROUND rounds up if the decimal is .5 or higher and down if the decimal is
below .5. ROUND (-1.7) gives -2 (see figure below).
• CEILING always rounds up. CEILING (-2.7) gives the closest higher number on
the number line, -2. For more information, see section 60.132 “CEILING” on
page 1840.
• FLOOR always rounds down. FLOOR (-3.8) gives the closest lower number on
the number line, -4. For more information, see section 60.133 “FLOOR” on
page 1841.
• TRUNCATE cuts off the decimal value. TRUNCATE (-3.8) gives the integer
without the decimal, -3.
The following table illustrates how the four functions differ:
ROUND 4 5 -3 -4
CEILING 5 5 -3 -3
FLOOR 4 4 -4 -4
TRUNCATE 4 4 -3 -3
Syntax
Round (number)
Parameter Description
Examples
Example 1
Program File
Tmpvar = Round (-42.7)
This statement returns -43.
Example 2
Program File
Rndval = Round (4.3)
This statement returns 4.
60.135 TRUNCATE
Alias: TRUNC
TRUNCATE drops the fractional part of number and returns the integer.
Syntax
Truncate (number)
Examples
Example 1
Program File
CHP = Truncate (4.5)
TRUNCATE returns 4 and the program statement sets CHP to 4.
Example 2
Program File
VAL_C = Truncate (-1.7)
TRUNCATE returns -1 and the program statement sets VAL_C to -1.
60.136.1 AVERAGE
AVERAGE returns the average of a list of items, the average of the items in an array
you name, or the average of the items in the log you name.
For more information, see section 60.137 “AVERAGE” on page 1845..
60.136.2 MAXIMUM
MAXIMUM finds the maximum number in a list of numeric values, a numeric array,
or a numeric log.
For more information, see section 60.138 “MAXIMUM” on page 1847..
60.136.3 MAXITEM
MAXITEM finds the position of the largest number in a list, an array, or a log. For
example, MAXITEM returns 1 if the largest number is the first one in the list.
For more information, see section 60.139 “MAXITEM” on page 1849..
60.136.4 MINIMUM
MINIMUM finds the minimum number in a list of numeric values, a numeric array, or
a numeric log.
For more information, see section 60.140 “MINIMUM” on page 1851..
60.136.5 MINITEM
MINITEM finds the position of the smallest number in a list, an array, or log. For
example, MINITEM returns 1 if the smallest number is the first one in the list.
For more information, see section 60.141 “MINITEM” on page 1853..
60.136.6 StandardDeviation
StandardDeviation finds the standard deviation of a series of numbers.
For more information, see section 60.142 “StandardDeviation” on page 1855..
60.137 AVERAGE
Alias: AVG
AVERAGE returns the average of a list of items, the average of the items in an array
you name, or the average of the items in the log you name.
Syntax
Format 1: Average (numeric_list)
Format 2: Average (numeric_array)
Format 3: Average (numeric_log)
• Format 1 is supported in a Script program running in an EcoStruxure BMS
server and in field devices, such as b3 BACnet devices.
• Format 2 is supported for local variables declared in a Script program running
in an EcoStruxure BMS server and in field devices, such as b3 BACnet
devices.
• Format 2 is not supported in a Script program running in an EcoStruxure BMS
server. This is true for binding variables bound to a numeric, manual, array
external to the program.
• Format 3 is supported in a Script program running in a field device, such as a
b3 BACnet device, that accesses a numeric log.
• Format 3 is not supported in a Script program running in an EcoStruxure BMS
server. This is true for binding variables bound to any numeric log in the
EcoStruxure BMS server itself or any other devices, including field devices such
as b3 BACnet devices.
Items in the list must all be either numbers or variables that contain numbers.
Element numbers are not required. Omitting element numbers averages the entire
array or log.
Examples
Example 1
To average several temperatures, you place them directly in the AVERAGE function
statement. You list them in parentheses after AVERAGE, as follows:
Program File
Flr8_AVG = Average (TMP801, TMP802, TMP803, TMP804)
Example 2
Since you know a certain temperature varies, you have been storing readings in an
array called OAT. You then use the AVERAGE function on that array, as follows:
Program File
OAT_AVG = Average (OAT)
Example 3
You have been logging temperatures in a log, called TEMPLOG, for several hours.
To find their average, you use the AVERAGE function as follows:
Program File
HourlyAVG = Average (TEMPLOG)
60.138 MAXIMUM
Alias: MAX
MAXIMUM finds the maximum number in a list of numeric values, a numeric array,
or a numeric log.
Syntax
Format 1: Maximum (numeric_list)
Format 2: Maximum (numeric_array)
Format 3: Maximum (numeric_log)
• Format 1 is supported in a Script program running in an EcoStruxure BMS
server and in field devices, such as b3 BACnet devices.
• Format 2 is supported for local variables declared in a Script program running
in an EcoStruxure BMS server and in field devices, such as b3 BACnet
devices.
• Format 2 is not supported in a Script program running in an EcoStruxure BMS
server. This is true for binding variables bound to a numeric, manual, array
external to the program.
• Format 3 is supported in a Script program running in a field device, such as a
b3 BACnet device, that accesses a numeric log.
• Format 3 is not supported in a Script program running in an EcoStruxure BMS
server. This is true for binding variables bound to any numeric log in the
EcoStruxure BMS server itself or any other devices, including field devices such
as b3 BACnet devices.
Items in the list must all be either numbers or variables that contain numbers.
If any of the items in the list in Format 1 is an array or a log but does not indicate an
element number, the controller retrieves the current value of the point and treats
that point like any other single item in the list.
Examples
Example 1
The MAXIMUM function finds the maximum number in a list of variables as follows:
Program File
TOPNUMBER = Maximum (Zone1, Zone2, Zone3, Zone4)
The TOPNUMBER variable is assigned the maximum value found.
Example 2
You can find the maximum number of kilowatts (KW) in the array of variables as
follows:
Program File
TOPNUMBER = Maximum (KW)
Example 3
You find the highest of several temperatures, including the current value of
TEMPLOG, as follows:
Program File
TOPNUMBER = Maximum (TMP801, TMP802, TEMPLOG)
In this example, TEMPLOG is interpreted as the current value of TEMPLOG.
60.139 MAXITEM
MAXITEM finds the position of the largest number in a list, an array, or a log. For
example, MAXITEM returns 1 if the largest number is the first one in the list.
Syntax
Format 1: Maxitem (numeric_list)
Format 2: Maxitem (numeric_array)
Format 3: Maxitem (numeric_log)
• Format 1 is supported in a Script program running in an EcoStruxure BMS
server and in field devices, such as b3 BACnet devices.
• Format 2 is supported for local variables declared in a Script program running
in an EcoStruxure BMS server and in field devices, such as b3 BACnet
devices.
• Format 2 is not supported in a Script program running in an EcoStruxure BMS
server. This is true for binding variables bound to a numeric, manual, array
external to the program.
• Format 3 is supported in a Script program running in a field device, such as a
b3 BACnet device, that accesses a numeric log.
• Format 3 is not supported in a Script program running in an EcoStruxure BMS
server. This is true for binding variables bound to any numeric log in the
EcoStruxure BMS server itself or any other devices, including field devices such
as b3 BACnet devices.
If any of the items in the list in Format 1 is an array or a log, the controller retrieves
the first item from the array or log and treats that item like any other single item in
the list.
Examples
Example 1
To find the position of the largest number in a series of numbers, you enter the
series in the parentheses:
Program File
Temp1 = 60
Temp2 = 65
Temp3 = 70
Temp4 = 67
60.140 MINIMUM
MINIMUM finds the minimum number in a list of numeric values, a numeric array, or
a numeric log.
Items in the list must all be either numbers or variables that contains numbers.
If any of the items in the list in Format 1 is an array or a log but does not indicate an
element number, the controller retrieves the current value of the point and treats
that value like any other single item in the list.
Syntax
Format 1: Minimum (numeric_list)
Format 2: Minimum (numeric_array)
Format 3: Minimum (numeric_log)
• Format 1 is supported in a Script program running in an EcoStruxure BMS
server and in field devices, such as b3 BACnet devices.
• Format 2 is supported for local variables declared in a Script program running
in an EcoStruxure BMS server and in field devices, such as b3 BACnet
devices.
• Format 2 is not supported in a Script program running in an EcoStruxure BMS
server. This is true for binding variables bound to a numeric, manual, array
external to the program.
• Format 3 is supported in a Script program running in a field device, such as a
b3 BACnet device, that accesses a numeric log.
• Format 3 is not supported in a Script program running in an EcoStruxure BMS
server. This is true for binding variables bound to any numeric log in the
EcoStruxure BMS server itself or any other devices, including field devices such
as b3 BACnet devices.
Examples
Example 1
The MINIMUM function finds the minimum number in a list of variables as follows:
Program File
BotNumber = Minimum (Zone1, Zone2, Zone3, Zone4)
The BotNumber variable is assigned the minimum value found.
Example 2
You can find the minimum number of kilowatts in the array of variables as follows:
Program File
BottomNumber = Minimum (KW)
Example 3
You find the minimum of several temperatures, including the current value of
TEMPLOG, as follows:
Program File
BottomNumber = Minimum (TMP801, TMP802, TEMPLOG)
In this example, TEMPLOG is interpreted as the current value of TEMPLOG.
Example 4
You have a log called AV_TEMP that holds the average temperature for each of the
last five days. You can use the MINIMUM function to find the minimum temperature:
Program File
WklyMin = Minimum (AV_TEMP)
If AV_TEMP contains 110, 114, 112, 108, 109, MINIMUM returns 108 and the
program statement sets WKLYMIN to 108.
60.141 MINITEM
MINITEM finds the position of the smallest number in a list, an array, or log. For
example, MINITEM returns 1 if the smallest number is the first one in the list.
If any of the items in the list in Format 1 is an array or a log, the controller retrieves
the first item from the array or log and treats that item like any other single item in
the list.
Syntax
Format 1: Minitem (numeric_list)
Format 2: Minitem (numeric_array)
Format 3: Minitem (numeric_log)
• Format 1 is supported in a Script program running in an EcoStruxure BMS
server and in field devices, such as b3 BACnet devices.
• Format 2 is supported for local variables declared in a Script program running
in an EcoStruxure BMS server and in field devices, such as b3 BACnet
devices.
• Format 2 is not supported in a Script program running in an EcoStruxure BMS
server. This is true for binding variables bound to a numeric, manual, array
external to the program.
• Format 3 is supported in a Script program running in a field device, such as a
b3 BACnet device, that accesses a numeric log.
• Format 3 is not supported in a Script program running in an EcoStruxure BMS
server. This is true for binding variables bound to any numeric log in the
EcoStruxure BMS server itself or any other devices, including field devices such
as b3 BACnet devices.
Examples
Example 1
To find the position of the smallest number in a series of numbers, you enter the
series in the parentheses:
Program File
Temp1 = 60
Temp2 = 65
Temp3 = 70
Temp4 = 67
Minitem (Temp1, Temp2, Temp3, Temp4)
The MINITEM statement returns 2, because the second item in the list contains the
smallest number.
Example 2
To find the index position of the smallest number in an array, you give the array
name in parentheses:
Program File
Minindex = Minitem (KW)
Example 3
To find the index position of the smallest number in a log, called TEMPLOG, you
give the log name in parentheses:
Program File
Minindex = Minitem (TEMPLOG)
Example 4
You find the position of the lowest of several temperatures in a list, including the
current value of TEMPLOG, as follows:
Program File
Minindex = Minitem(TMP801, TMP802, TEMPLOG)
In this example, TEMPLOG is interpreted as the current value of TEMPLOG.
60.142 StandardDeviation
Alias: SD
StandardDeviation finds the standard deviation of a series of numbers.
The standard deviation is the result of the following steps:
Items in the list must all be either numbers or variables that contain numbers.
If any of the items in the list in Format 1 is an array or a log but does not indicate an
element number, the controller retrieves the current value of the point and treats
that point like any other single item in the list.
Syntax
Format 1: StandardDeviation (numeric_list)
Returns the standard deviation of the listed items.
Format 2: StandardDeviation (numeric_array)
Returns the standard deviation of the items in the array.
Format 3: StandardDeviation (numeric_log)
Returns the standard deviation of the items in the log.
• Format 1 is supported in a Script program running in an EcoStruxure BMS
server and in field devices, such as b3 BACnet devices.
• Format 2 is supported for local variables declared in a Script program running
in an EcoStruxure BMS server and in field devices, such as b3 BACnet
devices.
• Format 2 is not supported in a Script program running in an EcoStruxure BMS
server. This is true for binding variables bound to a numeric, manual, array
external to the program.
• Format 3 is supported in a Script program running in a field device, such as a
b3 BACnet device, that accesses a numeric log.
Examples
Example 1
To find the standard deviation of several temperatures, you place them directly in
the STANDARDDEVIATION statement. You list them in parentheses as follows:
Program File
TempDev = StandardDeviation (70, 72, 74)
The standard deviation returned is 2.
Example 2
Since you know a certain temperature varies, you have been storing readings in an
array called VARTMP. You then use the STANDARDDEVIATION function on that
array, as follows:
Program File
Variation = StandardDeviation (VARTMP)
Example 3
You have been logging temperatures in a log for several hours. You find the
standard deviation of them as follows:
Program File
Deviance = StandardDeviation (TEMPLOG)
Example 4
You find the standard deviation of several temperatures in a list, including the
current value of TEMPLOG, as follows:
Program File
StdDev = StandardDeviation (TMP1, TMP2, TEMPLOG)
In this example, TEMPLOG is interpreted as the current value of TEMPLOG.
60.143.1 ASC
ASC returns the ASCII value of the first character of the string.
For more information, see section 60.144 “ASC” on page 1859..
60.143.2 CHR
CHR returns one character whose ASCII code is number. CHR can be used to
send non-printing characters to a terminal, computer, or printer to initiate action.
For more information, see section 60.145 “CHR” on page 1860..
60.143.3 LEFT
LEFT returns a string consisting of the leftmost characters of string with a length
specified by integer.
For more information, see section 60.146 “LEFT” on page 1861..
60.143.4 LENGTH
LENGTH returns the number of characters in the string.
For more information, see section 60.147 “LENGTH” on page 1862..
60.143.5 MID
MID returns a string number character extracted from the string starting at offset.
For more information, see section 60.148 “MID” on page 1863..
60.143.6 RIGHT
RIGHT returns the number of requested characters (the integer) from the text string
starting from the right side (end) and counting left.
For more information, see section 60.149 “RIGHT” on page 1864..
60.143.7 SEARCH
SEARCH returns the position of the given search_string within string or 0 if the
controller can’t find the search_string.
For more information, see section 60.150 “SEARCH” on page 1865..
60.143.8 FIND
FIND performs a case sensitive or insensitive string search.
For more information, see section 60.151 “FIND” on page 1866.
60.143.9 STRINGFILL
STRINGFILL returns a string of number length containing a particular character that
you specify with the ASCII character code named by character code.
For more information, see section 60.152 “STRINGFILL” on page 1867..
60.143.10 TAB
TAB returns a series of continuous blank spaces. The number of blank spaces is
number.
For more information, see section 60.153 “TAB” on page 1869..
60.144 ASC
ASC returns the ASCII value of the first character of the string.
Syntax
ASC (string)
Examples
This statement returns 83, which is the ASCII value of the character S:
Program File
ASC ("S")
60.145 CHR
CHR returns one character whose ASCII code is number. CHR can be used to
send non-printing characters to a terminal, computer, or printer to initiate action.
Syntax
CHR (number)
Examples
Example 1
After several pages of messages print, you then want to send a report to that
printer.
You make sure the report starts on a clean sheet of paper by sending an instruction
telling the printer to bring the paper to the top of a new page. This action is called a
formfeed. The code to generate a formfeed is 12. You write the formfeed as follows:
Program File
‘Generate a formfeed and report title
Print CHR(12); "Weekly Energy Report"
Example 2
Another way to use the CHR function is to send a bell to a terminal, computer, or
printer to warn that the ERRORS variable has reached a critically high value. The
ASCII code to generate a bell sound is 7. You write the errors variable notification as
follows:
Program File
‘Decides if too many errors are not acknowledged and generates a
bell
If errors > 15 then print CHR(7)
60.146 LEFT
Alias: FIRST
LEFT returns a string consisting of the leftmost characters of string with a length
specified by integer.
Syntax
Left (string, integer)
Examples
Example 1
Program File
LVAL = Left("ABCDEF", 2)
This statement returns AB.
Example 2
Suppose that the TEXT variable contains ROOM808; the following statement
retrieves the word ROOM by carrying out the LEFT function:
Program File
LVAL = Left(TEXT, 4)
This statement returns ROOM.
60.147 LENGTH
Alias: LEN
LENGTH returns the number of characters in the string.
Syntax
Length (string)
Examples
Example 1
Program File
Result = Length ("ABCDE")
The LENGTH function returns 5 and the statement sets RESULT to 5.
Example 2
Program File
Result = Length ("")
The LENGTH function returns 0 and the statement sets RESULT to 0.
60.148 MID
MID returns a string number character extracted from the string starting at offset.
Syntax
MID (string, offset, number)
Examples
Example 1
Program File
MIDSTR = MID("ABCDE", 2, 3)
MID returns BCD and the statement sets MIDSTR to BCD.
Example 2
Program File
PARTSTR = MID (ABCDE, 9, 2) returns " ".
60.149 RIGHT
Alias: LAST
RIGHT returns the number of requested characters (the integer) from the text string
starting from the right side (end) and counting left.
Syntax
Right ( string, integer )
Example
Program File
RGTVAL = Right ("ABCDE", 3)
This statement returns CDE.
60.150 SEARCH
SEARCH returns the position of the given search_string within string or 0 if the
controller can’t find the search_string.
Tip
SEARCH is case sensitive. If you would like to perform a case insensitive string
search, use the FIND keyword instead. For more information, see section 60.151
“FIND” on page 1866.
Syntax
Search (string, search_string)
Examples
Example 1
Program File
NSTR = Search ("ABCDE", "BC")
The search returns 2 and sets NSTR to 2, the position BC starts at in the string.
Example 2
Program File
NSTR = Search ("ABCDE", "CB")
The search returns 0 and sets NSTR to 0 because CB is not in the string.
60.151 FIND
FIND performs a case sensitive or insensitive string search.
Syntax
Find (string, search_string, [0 or 1])
Examples
Example 1
Program File
NSTR = Find ("ABCDE", "bc")
The find returns 2 and sets NSTR to 2, the position bc starts at in the string.
Example 2
Program File
NSTR = Find ("ABCDE", "CB")
The find returns 0 and sets NSTR to 0 because CB is not in the string.
Example 3
Program File
NSTR = Find ("ABCDE", "bc", 0)
The find returns 0 and sets NSTR to 0 because the search string is case sensitive
and the lowercase bc is not present in the string.
Example 4
Program File
NSTR = Find ("ABCDE", "bc", 1)
The find returns 2 and sets NSTR to 2 because the search is case insensitive and 2
is the position bc starts at in the string.
60.152 STRINGFILL
STRINGFILL returns a string of number length containing a particular character that
you specify with the ASCII character code named by character code.
Syntax
Stringfill (number, charactercode)
Examples
Example 1
Suppose you want to print a series of 60 asterisks across the top of a report. You
use STRINGFILL to print the asterisks by providing the number 60 for the number of
asterisks, and the number 42 as the ASCII code for the asterisk, as follows:
Print Stringfill(60, 42)
Example 2
You can draw dashed horizontal lines in a report using STRINGFILL by providing
the number of spaces you want the line to print across (60) and the ASCII code for a
dash (45):
Report File
Print Stringfill(60, 45)
Example 3
Suppose you want to design a graph to show the peak kilowatt demand for each
day in the last week. You can create a bar graph by filling the appropriate number of
spaces with, for example, asterisks. The following program sets up such a graph:
Program File
Numeric ShortDays, DayX
Print "Peak KW Demand for Week"
Print " "
For DayX = 1 TO 7
Print ST(ShortDays, DayX);" | "; ~
Stringfill (KWD[DayX]/100, 42)
Next DayX
Print " +----+----+----+----+----+"
Print " 0 500 1000 1500 2000 2500 "
The program prints the title and proceeds to a FOR...NEXT loop.
Inside the FOR...NEXT loop, the program first prints the short name of the weekday,
based on the number for the day (1 for SUN) using a customized function called ST.
Next, the program prints a plus sign after the name.
STRINGFILL then uses two values to print the kilowatt demand for that day:
Kilowatt demand for the day from the KWD array (KWD[1] = Sunday’s kilowatt
demand, KWD[2] = Monday’s kilowatt demand, and KWD[3] = Tuesday’s kilowatt
demand, and so on.
ASCII code for the asterisk (42).
To see how STRINGFILL uses these two values, take a look at Sunday in the graph
the program produces:
Program File Output
PEAK KWDEMAND FOR WEEK
SUN +******
MON +**********
TUE +********
WED +*********
THU +*******
FRI +********
SAT +***
+---+-----+-----+-----+-----+
0 500 1000 1500 2000 2500
First the program retrieves Sunday’s kilowatt demand from the KWD array.
Sunday’s kilowatt demand is 600 Kw. The program divides the demand by 100,
giving 6. So STRINGFILL prints six asterisks for Sunday.
The program then retrieves Monday’s kilowatt demand from the KWD array.
Monday’s kilowatt demand is 1000 Kw. The program divides the demand by 100,
giving 10. So STRINGFILL prints 10 asterisks for Monday.
The program continues to carry out the same process for each day of the week.
After printing Saturday’s kilowatt demand, the program prints the scale for the
graph, which displays 0 to 2500 Kw.
60.153 TAB
TAB returns a series of continuous blank spaces. The number of blank spaces is
number.
Syntax
Tab (number)
Examples
Program File
Print Tab (10); "This is a Title"
Output
This is a Title
The text is moved ten spaces to the right.
60.154.1 DIFFTIME
DIFFTIME calculates the difference in whole seconds, minutes, hours, or days
between two dates and times, date_time1 and date_time2. (Subtracts date_time1
from date_time2.)
For more information, see section 60.155 “DIFFTIME” on page 1871..
60.154.2 TIMEPIECE
TIMEPIECE retrieves the piece of time (hour, minute, second) or the piece of the
date (weekday, month, day of the month, year, day of the year) from a variable or
point.
For more information, see section 60.156 “TIMEPIECE” on page 1873..
60.155 DIFFTIME
DIFFTIME calculates the difference in whole seconds, minutes, hours, or days
between two dates and times, date_time1 and date_time2. (Subtracts date_time1
from date_time2.)
Syntax
Syntax 1: Difftime ( SECOND, date_time1, date_time2 )
Calculates the difference in whole seconds between two dates and times,
date_time1 and date_time2. (Subtracts date_time1 from date_time2.)
Syntax 2: Difftime ( MINUTE, date_time1, date_time2 )
Calculates the different in whole minutes between two dates and times, date_time1
and date_time2. (Subtracts date_time1 from date_time2.)
Syntax 3: Difftime ( HOUR, date_time1, date_time2 )
Calculates the different in whole hours between two dates ad times, date_time1
and date_time2. (Subtracts date_time1 from date_time2.)
Syntax 4: Difftime ( WKD, date_time1, date_time2 )
Calculates and returns the different in whole days between two times and dates,
date_time1 and date_time2. (Subtracts date_time1 from date_time2.)
Examples
Example 1
You can use DIFFTIME with SECOND to determine how many seconds have
passed. The sample program below calculates the difference between two readings
of the datetime variable TIMER.
Program File
Datetime Timer[2]
If Difftime (second, Timer[1], Timer[2]) > 30 then Run Test
The statement determines the result of TIMER[2] - TIMER[1]. If the difference is
greater than 30 seconds, TEST runs.
You would substitute MINUTE or HOUR in the above example to get time difference
in minutes or hours.
Example 2
You can use DIFFTIME with WKD to determine how many days have passed. The
sample program that follows calculates the difference between the old date (stored
in the OLDDATE variable) and the current date (in the DATE system variable).
Program File
Datetime Timer[2]
Result = Difftime (WKD, OLDTIME, DATE)
The statement sets RESULT to the number of days that DATE - OLDDATE gives.
60.156 TIMEPIECE
TIMEPIECE retrieves the piece of time (hour, minute, second) or the piece of the
date (weekday, month, day of the month, year, day of the year) from a variable or
point.
Note
Be aware that the days of the week correspond to the following digits:
• Sunday = 1
• Monday = 2
• Tuesday = 3
• Wednesday = 4
• Thursday = 5
• Friday = 6
• Saturday = 7
Syntax
Timepiece (datetime_system_variable, datetime_name)
Examples
Example 1
Program File
Datetime Date1
Numeric CurrentMin
Date1 = StrToDate ("5-25-98 11:13:23")
CurrentMin = Timepiece (Minute, Date1)
In this program, the TIMEPIECE function retrieves the minute from DATE1 and
returns 13.
Example 2
Program File
Numeric TodayMonth
TodayMonth = Timepiece (Month, Date)
In this program, the TIMEPIECE function retrieves the month from the DATE system
variable. If the date is June 20, 2005, TODAYMONTH is set to JUNE.
60.157.1 ACOS
ACOS returns the arccosine of the given number.
For more information, see section 60.158 “ACOS” on page 1875..
60.157.2 ASIN
ASIN returns the arcsine of the number.
For more information, see section 60.159 “ASIN” on page 1876..
60.157.3 ATAN
ATAN returns the arctangent of number.
For more information, see section 60.160 “ATAN” on page 1877..
60.157.4 ATAN2
ATAN2 returns an angle with a sine of sin and a cosine of cos.
For more information, see section 60.161 “ATAN2” on page 1878..
60.157.5 COS
COS returns the cosine of number.
For more information, see section 60.162 “COS” on page 1879..
60.157.6 SIN
SIN returns the sine of the angle you specify.
For more information, see section 60.163 “SIN” on page 1880..
60.157.7 TAN
TAN returns the tangent of number.
For more information, see section 60.164 “TAN” on page 1881..
60.158 ACOS
Alias: ARCCOSINE
ACOS returns the arccosine of the given number.
Syntax
ACOS (number)
Examples
Program File
AN_VALUE = ACOS(.7071)
60.159 ASIN
Alias: ARCSINE
ASIN returns the arcsine of the number.
Syntax
ASIN (number)
Examples
Program File
Result = ASIN(1)
60.160 ATAN
Alias: ARCTANGENT
ATAN returns the arctangent of number.
Syntax
ATAN (number)
Examples
Program File
Val_ARC = ATAN(0)
60.161 ATAN2
Alias: ARCTANGENT2
ATAN2 returns an angle with a sine of sin and a cosine of cos.
Syntax
ATAN2 (sin, cos)
Examples
Program File
Ang_Damper = ATAN2(0.0, 1.0)
60.162 COS
Alias: COSINE
COS returns the cosine of number.
Syntax
COS (number)
Examples
Example 1
Program File
My_COS = COS(3.14159/2)
Example 2
Program File
My_COS = COS(angle)
60.163 SIN
Alias: SINE
SIN returns the sine of the angle you specify.
Syntax
SIN (number)
Examples
Program File
Result = SIN (1)
60.164 TAN
Alias: TANGENT
TAN returns the tangent of number.
Syntax
TAN (number)
Examples
Program File
Position = TAN (3.14159/180)
Topics
Script Editor Overview
Script Editor Program Creation
Script Compiler Errors
Script Runtime Errors
Script Editor Features
Script Editor Program Elements and Colors
Keyboard Shortcuts for Script Editor
Collapsible Code Segments
Adding a Line
Script Auto-Completion
Using Script Auto-Completion
Script Editor Initial Binding Variable Values
Comments in Script Programs
Adding a Comment
Checking and Saving a Script Program
Executing a Script Program
Importing Script Program Code
Exporting a Script Program
Converting a Plain English File
Customizing the Script Editor
61 Using a Collapsible Script Code Block
Adding an Entry to the Code Library
Working with Code Library Folders
Working with Code Library Sample Import Files
Working with Code Library Items
Inserting a Code Library Item in a Script Program or
Function
Referencing the Code Library File
Finding Text in Script Editor
Using Undo and Redo in Script Editor
Script Debugger
Script Debugger Function Keys
Debugging a Script Program
Controlling the Trace Operation in the Script Debugger
Changing Values in the Script Debugger Local or Binding
Variables Pane
BACnet Priority Level Access
Configuring BACnet Priority Level Access
Configuring BACnet Priority Level Access for a b3 BACnet
Device
61 Script Editor
61.1 Script Editor Overview
Important
Ensure that you have a working and available Script license. A working license is
required to start Script. For more information, see the Licenses topic on
WebHelp.
By using bindings, you can increase the flexibility of your building automation
system. For example, you can use your OfficeLights program to control lighting and
ventilation in one room and then use that program for another room by changing
the bindings. You do not need to change all of the local variable names to suit the
new program. When you are finished, you use Script Editor to check the program
for errors and save the program.
1001
Continued
Error Error Text
Continued
Error Error Text
1095 No Errors.
Stack Overflow
Illegal argument
Invalid destination
Illegal import ID
Preparse failed
Continued
Error Text
Execution failed
Comm failed
Text Black
Keyword Blue
Value Maroon
String Red
Number Navy
Operator Teal
Comment Green
Ctrl + Insert or CTRL + C Copies selected text and stores that text in
the clipboard.
Shift + Delete or CTRL + X Cuts the selected text and stores that text in
the clipboard.
Shift + Insert or CTRL + V Pastes the text you last cut or copied at the
current cursor position in your program.
61.8.1 Clipboard
You use the Clipboard pane as the area to store copied and cut items while
programming. You can paste items from the Clipboard into any of the program
editor panes that are being used. For example, by double-clicking on an item in the
clipboard pane, you can insert that text into the program where the cursor is
currently located.
You access the cut, copy, and paste commands in one of two ways:
• By using the toolbar buttons
• Through the use of keyboard shortcuts
Figure: Folders
A code library folder is made up of frequently used units of text called entries. These
entries can be single words, a full code line, a function, or even an entire Script
program. You can decide how much and what kind of text is stored as an item
according to your programming preferences.
You can also give entries meaningful names to help you identify and use them
easily. You can reference the code library file from anywhere on the PC that you use
to run WorkStation.
To add a line
1. In Script Editor, type a line label that is preceded by the Line keyword or
followed by a colon, and then add the instructions that belong to the line label.
You have now added line labels and instructions in your program.
Figure: Auto-completion
As more characters are typed, the list shrinks as the possible matches decrease. If
there are no matches, the box closes automatically.
ToolTips display next to the text options with information about each, such as
function description, keyword name, and function parameters. You can use
ToolTips to auto-complete the text by selecting any of the options listed.
Tip
With this method, you can issue a GoTo statement to the initialization line
anywhere in the program. This GoTo statement directs the program to re-execute
the initialization statements and start over (based on program execution logic).
Note
• Script supports characters at or below ASCII 127. Additional characters are
not supported and are replaced by a question mark (?).
To add a comment
1. In Script Editor, type a single quotation mark (') and then type a comment.
You can add a comment at the beginning of the program or function to explain its
purpose. You can also add comments at the end of any statement in a Script
program or function.
Important
If you save a program that contains errors, that program will not run. The progam
must have a successful check before running.
For more information, see section 59.3 “Script Programs” on page 1605.
Tip
• When a Plain English .txt file is imported, you have to load the file
and complete a conversion process. As a result of these
conversions, you may need to make adjustments to the
imported script program code.
Note
• To import text into a new program, create the program in a text editor first
and then import the .txt file.
For more information, see section 59.3 “Script Programs” on page 1605.
4. Click the Script menu icon , point to Import and then click Plain
English.
5. In the Import Plain English dialog box, click Load file to load an entire PE
file, or paste the text you want from your PE program or function into the Plain
English Editor pane.
6. Select the .txt file you want to convert.
7. Click Open.
8. Convert all or part of the file:
• Click Convert all to convert the entire PE file to a Script program.
• Select the lines you want to convert and then click Convert selected to
convert the selected lines to the Script program or function.
9. Correct any errors that occur during the conversion.
10. Click Close.
11. In Script Editor, click Save.
Tip
By default, the path for the import is the Server. You cannot change
the path.
4. Click Import.
All of the objects contained in the import sample file are created in the
EcoStruxure BMS server.
5. In the List View, click the City variable.
6. On the File menu, click Properties.
7. In the Basic tab, enter the city name.
8. Click OK.
9. Drag these City values to the Watch pane and observe the functioning
program as it obtains the temperature and weather conditions for Boston.
10. In the List View, click the Get US City Weather by ZIP program.
11. On the Actions menu, click Edit.
12. View and edit the program as needed.
13. Click Save to execute the updated Get US City Weather by Zip program.
Important
• Use this method when you want to search only the current program.
For more information, see section 61.5 “Script Editor Features” on page 1896.
1. In Script Editor, click the Undo button to undo the last keystroke or
action.
2. Click the Redo button to repeat the last keystroke or action that you
previously undid.
Note
• The limit of Undo and Redo actions is forward or backwards by
24 instances.
Note
Nested function calls are also not supported in the Script Debugger.
Note
The icon beside the program name changes to indicate the Script
Editor is now in Debug mode. Be aware that you can only debug one
program at a time.
Note
• The ReadProperty and WriteProperty keywords are available in
Script, but the priority level argument is not needed in the
statement. It is assumed based on the binding information.
Topics
Script Web Services
Script Web Services Workflow
Creating a Script Web Service Interface
Configuring a Script Web Service Interface
Configuring a Script Program to use Web Services
Script SOAP Web Services Data Type
Script RESTful Web Services
Using Script to Send a Request to a RESTful Web Service
Using Script to Obtain a Secure Web Page from a RESTful
Web Service
62 Script Web Services
62.1 Script Web Services
For more information, see section 62.2 “Script Web Services Workflow” on page
1939.
You then create a Script program named Calculator Program and configure this
Script program to use Web Services. In this example, you use the Webservice
keyword to declare the Web Service in the program.
Tip
• When you create a Web Service, you should ensure that your PC
can connect to the target service.
6. In the EndPoint box, type the URL of the machine where the Web Service
calls are processed.
Note
• Typically, the WSDL file defines the EndPoint, in which case, this
box is completed automatically. In some circumstances, you
may still need to enter an EndPoint, however.
7. Click OK.
Tip
Web Service method calls need their own execution lines within Script programs.
Tip
Script programs do not support compression in EcoBuilding Building Operation
software. When a Script program attempts to call a Web Service method that
employs compression, it fails and the program does not execute as expected.
Tip
When you create a Web Service, be sure that your PC can connect to the target
service.
62.7.1 SendWebRequest
The SendWebRequest system function sends a request to a Uniform Resource
Locator (URL). Requests are sent from the running program in Script to a particular
Universal Resource Identifier (URI) following standard HTTP protocols.
Note
SendWebRequest is not supported in the MP Series controller.
62.7.2 UrlEncode
The UrlEncode system function encodes the entire URL, including the message
with its query-string values. If characters, such as blanks, punctuation marks, and
arithmetic are passed directly to the HTTP stream, they may be misinterpreted and
result in the return of incorrect results. This function converts characters that are not
allowed in a URL into their equivalents.
Note
UrlEncode is not supported in the MP Series controller.
Topics
Script Editor
Script Editor Toolbars
Script Editor – Binding Variables Pane
Script Editor – Local Variables Pane
Script Editor Context Menu
Import Plain English Dialog Box
Script Editor Code Library
Script Program Properties – Basic Tab
Script Program Properties – Advanced Tab
Script Program Properties – Inputs Tab
Script Program Properties – Outputs Tab
Script Program Properties – Publics Tab
Script Program Properties – Functions Tab
Script Program Properties – Web Services Tab
Script Function Properties – Basic Tab
Script Function Properties – Inputs Tab
Script Function Properties – Outputs Tab
Script Function Properties – Publics Tab
Script Function Properties – Functions Tab
Script Web Service – Basic Tab
63 Script Web Service – Methods Tab
63 Script User Interface
63.1 Script Editor
Figure:
Clipboard pane
Use this pane to store copied and cut items
to use in Script programming. By double-
clicking on an item in the clipboard pane,
you can insert that text into the program
where the cursor is currently located.
Continued
Number Description
Status bar
Use this pane to review the path of the active
Script program or function. You can view the
line and column where the cursor is
positioned within the current editor pane.
The status bar also identifies the input
method, Insert or Overwrite, currently being
used in the editor.
Properties pane
Use this pane to view and change general,
configuration, and runtime information about
your Script programs and fuctions and their
inputs and outputs tabs.
Check pane
Use this pane to review the results of your
program compilation, including any syntax
errors. If the Script Editor checks a program
and finds no errors, a Check Successful
message displays. If errors occur, they
display with the error message number, line
and column location within the program, and
text or keywords involved.
Continued
Number Description
Find pane
Use this pane to locate and display queried
text. The Find pane displays the queried text
in quotes on the first line of the pane, the
open program the instance is located in, the
line number within the program where the
text can be found, and the context in which
the queried text is found.
Bindings view
Click to display the Bindings view for a Script
program. You can access the Bindings view
without leaving the Script Editor. For more
information, see section 59.16 “Local
Variable Declarations” on page 1630.
Open
Click to open an existing Script or b3
program or function.
Save
Click to save the currently active program.
Save All
Click to save all open programs.
Print
Click to print the current program.
Cut
Click to cut the selected text.
Copy
Click to copy the selected text.
Paste
Click to paste text.
Window
Click to open a pane or activate a minimized
pane.
Options
Click to configure program editor options
such as fonts, colors, layout, and code
library path.
Refresh
Click to refresh the focus window in the
Script Editor.
Continued
Button Description
Script Bindings
Click to display the read-only Script Binding
View which shows the path for the local
bindings variables in your Script programs.
Check
Click to check a program file for syntax
errors.
Check All
Click to check all open program files for
syntax errors.
Start
Initiates a Script Debugger session. As the
debugger proceeds, it highlights the current
executing line in the Script program.
Stop
Terminates a Script Debugger session.
Trace On
Initiates a continuous single step operation
without the need to keep pressing the Step
icon.
Trace Off
Terminates the continuous single step
operation.
Go
Continuously executes a Script program until
a breakpoint is reached or execution ends.
Step
Goes to the next executing line in the Script
program.
Find
Click to find a specific word in the current
program.
Replace
Click to replace a specific word in the current
program.
Help
Click to view help topics for Script
programming.
Continued
Button Description
Script menu
Click to open, save, import, export, print, or
close a program. Export exports the current
Script object to a text file. Import imports
text from a text file, or opens the Import
Plain English dialog box which allows you
to import Plain English text for conversion.
For more information, see section 63.6
“Import Plain English Dialog Box” on page
1965.
Save
Click to save a Script program or function.
Undo
Click to undo or revert back one keystroke
or action in the Script Editor to the last state
of the text.
Redo
Click to redo or move ahead one keystroke
or action in the Script Editor to the state of
the text which was previously undone.
Continued
Command Description
Load file Click to locate and load the Plain English file
that you want to add to your current Script
Editor program or function.
Continued
Component Description
Continued
Component Description
Apply Initial Value Select Yes to apply the initial values of the
binding variables. The default No does not
apply the values, thus ensuring, for example,
that an output point does not reset every
time a program that binds to one of its own
output variables is saved.
[Property Name] Set the value of the bound property. Use the
up and down arrow keys to increment the
value up or down by .5 of a point. Click the
[Property name] Set the value of the bound property. Use the
up and down arrow keys to increment the
value up or down by .5 of a point. Click the
[Property Name] Set the value of the bound property. Use the
up and down arrow keys to increment the
value up or down by .5 of a point. Click the
[Function name] Set the value of the bound property. Use the
up and down arrow keys to increment the
value up or down by .5 of a point. Click the
Wsdl Url Type the URL for the WSDL file. The URL
must end with ?wsdl. SOAP 1.1 and 1.2 files
are supported here.
Topics
Compiler error contains no error text
Runtime error contains no error number
64 Script Troubleshooting
64.1 Compiler error contains no error text
64.1.1 Solution
Use the error number in the compiler error table to find the appropriate error text.
For more information, see section 61.3 “Script Compiler Errors” on page 1891.
64.2.1 Solution
Use the error text in the runtime error table to troubleshoot the problem.
For more information, see section 61.4 “Script Runtime Errors” on page 1894.