Example
4.
Using
System Variables
Each
controller uses several variables while performing its tasks. For example, the controller uses the
time kept by its clock and calendar to decide when to log data. The clock keeps the seconds, minutes,
and hours, while the calendar keeps the day of the month, the month and the
year. Refer to the section “Script Syntax” for more information about the system
variables. Many system variables
may also be used in the program.
These system variables have names that start with the underscore
character (‘_’). For instance,
“_second” and “_minute” give the current seconds and minutes as the clock
reports it. Just like input
variables, in general system variables should also be considered as “volatile
variables.” That is, their values
may change by actions outside the scope of the program.
The
following program illustrates how the output, “out1” is switched on for 20
seconds each minute.
title "example 4a. system variables "
output out1;
out1=(_second<20);
This
program looks very similar to the simple thermostat
control example. As in that
example, the output is switched on when a certain condition holds true. The condition, in this case is
different. The condition is true
when the current seconds is less than 20.
So while the current seconds ticks from 0 to 59, the condition is true
for the first 20 seconds, and false afterwards.
Unlike
the output variable “out1”, note that the system variable “_second” is not
included in the declarations segment of the script. A very simple change to the above program is shown
below. Here, the system variable
“_beep” is used as the output. The
system variable “_beep” is the beeper on the controller. This way, you can beep the output for
20 seconds at the beginning of each minute. Note that there are no inputs or outputs in the declaration
segment.
title "example 4b. system variables "
_beep=(_second<20);
You
may consider using a parameter to change the behavior of the program. Parameters were introduced in Example 2.
title "example 4c. system variables "
parameter pBeep;
_beep= pBeep &&
(_second<20);
In the
above program, the condition is made up of two components. For the condition to be true, both the
parameter “pBeep” must be true (nonzero) and the seconds must be less than
20. As in Example
3, the two components of the condition are AND-ed using the Boolean
operator “&&.” Refer to
the section “Script Syntax” for more information about
the Boolean operators. Now the
feature of beeping 20 seconds at the beginning of each minute may be turned on
or off by modifying the parameter value “pBeep.” As discussed in Example 3, this can
be done from iNetGrow, by clicking the “Peek” button, or, if you have a web
server on the LAN, from a web page through your browser.
Also
see : Programming, Program
Examples, Script Syntax
© Rigel Corporation iNetGrow 2003-2006. All rights reserved.