Programming
Each controller has the
capability to carry out automated tasks.
These tasks are described by a program or script. A script is essentially a set of
instructions. Programs must follow
the specific script syntax. This section gives an overview of programming along with
several examples. The examples are
arranged in increasing complexity.
It is recommended that you review these examples in sequence.
The section “Using Parameters and Variables” gives useful
insights into the effective use of iNetGrow through the System View dialog or through a web browser (see
the section “Integrating with Web Services”).
Overview
Programs consist of a set of
instructions. Ultimately, these
instructions compute the values of the outputs from the values of the
inputs. Thus, the program allows the
implementation of virtually an endless number of automated tasks.
The iNetGrow script contains
five types of variables: inputs, outputs, variables, and parameters, and system
variables. Inputs and outputs are
the user-given names for the various signals that are available at the
modules. Refer to the sections “Configuring I/O Modules” and “Named Variables” for more information about naming the
inputs and outputs. Variables and
parameters are general-purpose memory values. Parameters are stored in non-volatile RAM. Hence, parameters retain their values
even if the power to the controller is interrupted. System variables are values maintained by the controller to
carry out its tasks. System
variables start with the underscore character (‘_’). For example, “_second” is the value kept by the system
clock. Its value is the current
seconds. All variables are 16-bit
signed integers.
The program has two sections:
definitions and statements. The
definitions list all the variables used in the program (excluding the system
variables). The statements
comprise the “business end” of the program. These are the instructions the controller follows when
computing the outputs from the inputs.
The simplest statement is an assignment statement, with the familiar
syntax,
output = expression;
As in C or JAVA, statements are
terminated by a semicolon character.
An expression is a quantity dependent on one or more variables. Expressions may contain many terms. For example,
output = input/2;
Refer to the section “Script Syntax” for the various operators allowed by
iNetGrow. It is important to note
that no operator precedence is assumed.
You must explicitly indicate the precedence by using parantheses. For example,
output = a/b+c;
Is not allowed. Instead, use
output = (a/b)+c;
or
output = a/(b+c);
You may combine one or more
statements by curly brackets to make compound statements. For example,
{
x=1; y=1; }
A condition is an expression, whose
value is evaluated to be zero or one.
Conditional statements use such expressions in the familiar syntax. Note that the action for the
conditional statement is a compound statement.
if(a<b) { x=1;
y=1; }
The “else” clause is also
supported.
if(a>=b) {
x=1; } else {x=2; }
It should be noted that white spaces (blanks, tabs,
new line characters) are ignored by iNetGrow. This allows you to format your script in a more organized fashion. For example,
if(a!=b)
{
x=1;
y=1;
}
else
{
x=2;
y=2;
}
The iNetGrow script does not
support loops or arrays.
The following examples are
arranged in increasing complexity.
Example
1. Simple Thermostat Control
Example
2. Simple Thermostat Control with a Configurable Set point
Example
3. A Two-Step Thermostat Control
Example
4. Using System Variables
Example
5. A Simple Irrigation System
Example
7. Implementing Operating Modes
Example
8. Implementing Manual Triggers
Also see : Automated Tasks, Script
Syntax, Using Parameters and Variables
© Rigel Corporation iNetGrow 2003-2006. All rights reserved.