2 expression evaluation, 3 numeric results of expression evaluation – Campbell Scientific RTDAQ Software User Manual

Page 88

Advertising
background image

Section 5. Program Creation and Editing

TABLE 5.1-3. Synonyms for True and False

Predefined Constant

True (-1)

False (0)

Synonym High

Low

Synonym On

Off

Synonym Yes

No

Synonym

Trigger

Do Not Trigger

Number

≠0

0

Digital port

5 Volts

0 Volts

5.1.4.11.2 Expression Evaluation

Conditional tests require the datalogger to evaluate an expression and take one
path if the expression is true and another if the expression is false. For
example:
If X>=5 then Y=0
will set the variable Y to 0 if X is greater than or equal to 5.

The datalogger will also evaluate multiple expressions linked with and or or.
For example:
If X>=5 and Z=2 then Y=0
will set Y=0 only if both X>=5 and Z=2 are true.
If X>=5 or Z=2 then Y=0
will set Y=0 if either X>=5 or Z=2 is true (see And and Or in the help). A
condition can include multiple and and or links.

5.1.4.11.3 Numeric Results of Expression Evaluation

The datalogger’s expression evaluator evaluates an expression and returns a
number. A conditional statement uses the number to decide which way to
branch. The conditional statement is false if the number is 0 and true if the
number is not 0. For example:
If 6 then Y=0,
is always true, Y will be set to 0 any time the conditional statement is
executed.
If 0 then Y=0
is always false, Y will never be set to 0 by this conditional statement.

The expression evaluator evaluates the expression, X>=5, and returns -1, if the
expression is true, and 0, if the expression is false.
W=(X>Y)
will set W equal to -1 if X>Y or will set W equal to 0 if X<=Y.

The datalogger uses -1 rather than some other non-zero number because the
and and or operators are the same for logical statements and binary bitwise
comparisons. The number -1 is expressed in binary with all bits equal to 1, the
number 0 has all bits equal to 0. When -1 is anded with any other number the
result is the other number, ensuring that if the other number is non-zero (true),
the result will be non-zero.

5-28

Advertising