04.01.2015 Views

CR1000 Manual - Campbell Scientific

CR1000 Manual - Campbell Scientific

CR1000 Manual - Campbell Scientific

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Section 7. Installation<br />

CRBasic Example 22.<br />

Public I As Long<br />

Public A1, A2<br />

Const ID = 10<br />

BeginProg<br />

A1 = A2 + ID<br />

I = ID * 5<br />

EndProg<br />

Constants to LONGs or FLOATs<br />

7.7.3.9.4 Logical Expressions<br />

In CRBasic example Constants to LONGs or FLOATs (p. 145), I is an integer. A1<br />

and A2 are FLOATS. The number 5 is loaded As FLOAT to add efficiently with<br />

constant ID, which was compiled As FLOAT for the previous expression to avoid<br />

an inefficient runtime conversion from LONG to FLOAT before each floating<br />

point addition.<br />

Measurements can indicate absence or presence of an event. For example, an RH<br />

measurement of 100% indicates a condensation event such as fog, rain, or dew.<br />

The <strong>CR1000</strong> can render the state of the event into binary form for further<br />

processing, i.e., the event is either occurring (true), or the event has not occurred<br />

(false).<br />

True = -1, False = 0<br />

In all cases, the argument 0 is translated as FALSE in logical expressions; by<br />

extension, any non-zero number is considered "non-FALSE." However, the<br />

argument TRUE is predefined in the <strong>CR1000</strong> operating system to only equal -1,<br />

so only the argument -1 is always translated as TRUE. Consider the expression<br />

If Condition(1) = TRUE Then...<br />

This condition is true only when Condition(1) = -1. If Condition(1) is any other<br />

non-zero, the condition will not be found true because the constant TRUE is<br />

predefined as -1 in the <strong>CR1000</strong> system memory. By entering = TRUE, a literal<br />

comparison is done. So, to be absolutely certain a function is true, it must be set<br />

to TRUE or -1.<br />

Note TRUE is -1 so that every bit is set high (-1 is &B11111111 for all four<br />

bytes). This allows the AND operation to work correctly. The AND operation<br />

does an AND boolean function on every bit, so TRUE AND X will be non-zero if<br />

at least one of the bits in X is non-zero, i.e., if X is not zero. When a variable of<br />

data type BOOLEAN is assigned any non-zero number, the <strong>CR1000</strong> internally<br />

converts it to -1.<br />

The <strong>CR1000</strong> is able to translate the conditions listed in table Binary Conditions of<br />

TRUE and FALSE (p. 146) to binary form (-1 or 0), using the listed instructions and<br />

saving the binary form in the memory location indicated. Table Logical<br />

Expression Examples (p. 146) explains some logical expressions.<br />

Non-Zero = True (Sometimes)<br />

Any argument other than 0 or -1 will be translated as TRUE in some cases and<br />

FALSE in other cases. While using only -1 as the numerical representation of<br />

145

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!