beautypg.com

Program execution, Simple example – Contemporary Control Systems BASview User Manual

Page 65

background image

TD110500-0MC

65

Program Execution

Before the program is executed for the first time (after it is edited and saved, or after a reboot), all of the
points the program requires are read from the network and only then is the program executed. If one or
more points could not be read properly, because of an offline device or other reason, the program will not
be executed.

At each execution, the program is run from the top to the bottom and then ended. It does not loop back to
the top on the next execution, rather it is completely restarted.

Local Python variables and their values are not maintained between each execution of the program.
There is a way to remember variable values between executions. See "Saved Variables" below.

Each program is limited to a maximum of 3 seconds to fully execute and end. In practice, a program
should never be written to take anywhere near 3 seconds to execute because it will bog down the rest of
the system. Programs should never execute long "for" or "while" loops, or anything else that could take
more than a few milliseconds.

The 3 second timeout is a failsafe to keep a program from hogging resources. If a program takes longer
than 3 seconds, it will be shut down, flagged as disabled and not run again until it is modified and saved
or the unit is rebooted.

Simple Example

if getValue(@mySwitch)>0:

#Is the switch being pressed?

setValue(@myLights,1,3600)

#override myLights on for 1 hour

overrideSchedule(@mySched,1,3600)

#override schedule on for 1 hour

In the above example, the program will continually check the point "mySwitch" to see if it is being
pressed. If it is being pressed (if its value is greater than 0), the point "myLights" will be turned ON (set to
1) for 3600 seconds (1 hour) and the schedule "mySchedule" will also be overridden ON for 1 hour.

Something to note about the above example is the way points are read and written using "getValue" and
"setValue". Those functions are the only way to access points on the network.

getValue() will return the value of the point specified by the reference name. Note that the getValue
function does not go out and read the value of the point from the network. It has already been read and
stored before the program executed for the first time and it is continually updated in the background. On
a busy network, the stored value could possibly be several seconds old at any given time.

setValue() will set the value of the point specified by the reference name to the value given as the second
argument. An optional third argument may be used to set a timed override in seconds. If the override
time is not supplied, the value will be set until something changes it. Note that the point must have the
"Allow modifications" option checked in its properties screen for setValue to work.

Note that any time a point reference name is used, it must be prefixed with the @ symbol.