
Appendix B. Introduction to CRBasic Programming
B-14
Logical expressions are used to indicate absence or presence of an event. For
example, a relative humidity measurement of 100% indicates a condensation
event such as fog, rain, or dew. The CR300 can render the state of the event
into binary form for further processing, so the event is either occurring (true),
or the event has not occurred (false).
In all cases,
0
is translated as
False
in logical expressions; by extension, any
non-zero number is considered "non-False." However,
True
is predefined in
the CR300 operating system to equal
–1
, so only
–1
is always translated as
True
. Consider the expression
If
Condition = TRUE
Then
...
This condition is true only when Condition =
–1
. If Condition is any other non-
zero, the condition will not be found true because the constant
True
is
predefined as
–1
in the CR300 system memory. By entering
=
True
, a literal
comparison is done. Consider the expression
If
Condition
Then
...
Since
=
True
is omitted from the expression, Condition is considered true if it
equals any non-zero value.
True
is
–1
so that every bit is set high (–1 is &B11111111 for all
four bytes). This allows the
AND
operation to work correctly. The
AND
operation does an AND Boolean function on every bit, so
True
AND
X
will be non-zero if at least one of the bits in
X
is
non-zero (if
X
is not zero). When a variable of data type
BOOLEAN is assigned any non-zero number, the CR300
internally converts it to
–1
.
B.9.1 Expressions in Arguments
Many CRBasic instruction parameters allow the entry of arguments as
expressions. If an expression is a comparison using logical operators, it will
return
–1
if true and
0
if false. The following code snippet shows the use of an
expression as an argument in the
TrigVar
parameter of the
DataTable()
instruction:
'DataTable(Name, TrigVar, Size)
DataTable
(Temp, TC > 100, 5000)
With the trigger of
TC > 100
, a thermocouple temperature greater than 100 sets
the trigger to
True
and data are stored.
NOTE
Summary of Contents for CR300 series
Page 2: ......
Page 6: ......
Page 68: ...CR300 Series Datalogger 58...
Page 70: ......
Page 85: ......