beautypg.com

4 logical expressions, Crbasic example 22. constants to longs or floats – Campbell Scientific CR1000 Measurement and Control System User Manual

Page 145

background image

Section 7. Installation

145

 

CRBasic Example 22. Constants to LONGs or FLOATs 

Public

I

As Long

Public

A1, A2

Const

ID = 10

BeginProg

A1 = A2 + ID
I = ID * 5

EndProg

 

In CRBasic example Constants to LONGs or FLOATs

(p. 145),

I is an integer. A1

and A2 are FLOATS. The number 5 is loaded As FLOAT to add efficiently with
constant ID, which was compiled As FLOAT for the previous expression to avoid
an inefficient runtime conversion from LONG to FLOAT before each floating
point addition.

7.7.3.9.4 Logical Expressions

Measurements can indicate absence or presence of an event. For example, an RH
measurement of 100% indicates a condensation event such as fog, rain, or dew.
The CR1000 can render the state of the event into binary form for further
processing, i.e., the event is either occurring (true), or the event has not occurred
(false).

True = -1, False = 0

In all cases, the argument 0 is translated as FALSE in logical expressions; by
extension, any non-zero number is considered "non-FALSE." However, the
argument TRUE is predefined in the CR1000 operating system to only equal -1,
so only the argument -1 is always translated as TRUE. Consider the expression

If

Condition(1) = TRUE

Then

...

This condition is true only when Condition(1) = -1. If Condition(1) is any other
non-zero, the condition will not be found true because the constant TRUE is
predefined as -1 in the CR1000 system memory. By entering = TRUE, a literal
comparison is done. So, to be absolutely certain a function is true, it must be set
to TRUE or -1.

Note 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, i.e., if X is not zero. When a variable of
data type BOOLEAN is assigned any non-zero number, the CR1000 internally
converts it to -1.

The CR1000 is able to translate the conditions listed in table Binary Conditions of
TRUE and FALSE

(p. 146)

to binary form (-1 or 0), using the listed instructions and

saving the binary form in the memory location indicated. Table Logical
Expression Examples

(p. 146)

explains some logical expressions.

Non-Zero = True (Sometimes)

Any argument other than

0

or

-1

will be translated as

TRUE

in some cases and

FALSE

in other cases. While using only

-1

as the numerical representation of