Programming for experts
P.
123 of 349
time controls in the branch
The else-branch
a=OFF
b=1
if change(a) then {
if b==1 then write('1/2/3'b01,OFF);b=2 endif
if b==2 then write('1/2/3'b01,ON) endif
} endif
After
a
changes the outer
if
statement becomes invalid. This invalidates all statements in the then-branch. Then the
processing begins: The first inner
if
statement is active, sets
b
to 2 and writes OFF to 1/2/3. The second inner
if
statement receives an "invalid" signal from the outer
if
statement before the first if-statement is active, but it is not yet
processed. In the meantime
b
is set to 2. The second inner
if
statement is now processed and the condition is ON.
Therefore, ON is written to 1/2/3. For all other additional changes of
a
, the outer
if
statement becomes active and
then only the second inner
if
statement (as
b
is not equal to 1).
We change the example as follows:
a=OFF
b=1
if change(a) then {
if b==2 then write('1/2/3'b01,ON) endif
if b==1 then write('1/2/3'b01,OFF);b=2 endif
} endif
Now after the first change of a the first inner
if
statement becomes invalid, too. But the query condition is 0 (OFF),
since the variable
b
is still 1. The second inner
if
statement is invalidating its then-branch and “executes” this branch.
The next (and all other) only the first
if
statement is executed.
As with the first example (referring to variable
y
) the following
if
statement will invalidate the then-branch only, if the
OR operation itself is "invalid":
if '1/2/3'b01 or '1/2/4'b01 then { ... } endif
Time functions are evaluated only in a nested if-statement if the
if
-statement sends an "invalid" to its then-branch.
Please see the following example:
key='1/2/3'b01
a=OFF
if key then {
if htime(12,00,00) then {
a=ON
} endif
} endif
a
is here only set to ON, if the key is pressed exactly at 12:00:00 (
htime
only generates at this time an ON-pulse),
what might not be intentionally. A solution in this case, would be the use of
chtime
. Then
a
is set to ON if the key is
pressed (sending an ON telegram at '1/2/3'b01) after 12:00 and before midnight.
The else branch of an
if
function is like a second stand-alone function with if-negated query condition:
[EibPC]
a=OM
b=1
c='1/2/3'b01
if systemstart() then {
if b==1 then {
write('1/2/3'b01,OFF);b=2
} else {
write('1/2/3'b01,ON)
} endif
} endif
// is same as
// if systemstart() then {
// if b==1 then write('1/2/3'b01,OFF);b=2 endif
// if !(b==1) then write('1/2/3'b01,ON) endif
// } endif
HandbuchEibPC_USA-30.odt, 2017-05-11
Enertex
®
Bayern GmbH - Erlachstraße 13 - 91301 Forchheim - [email protected]