05.05.2014 Views

csmstr - Omega Engineering

csmstr - Omega Engineering

csmstr - Omega Engineering

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

MULTIPLE CONDITIONS<br />

CRIMSON USER MANUAL - MODULAR CONTROLLER<br />

OPERATOR PRIORITY EXAMPLE<br />

Bit Selection Group 1 Input.2<br />

The example shown tests bit 2 (ie. the bit with a value of 4) within the indicated tag.<br />

If you want to test for a bit being equal to zero, you can use the logical NOT operator…<br />

OPERATOR PRIORITY EXAMPLE<br />

Logical NOT Group 2 !Input.2<br />

This example is equal to 1 if bit 2 of the indicated tag is equal to 0, and vice versa.<br />

MULTIPLE CONDITIONS<br />

If you want to define an expression that is true if a number of conditions are all true, you can<br />

use the logical AND operator. Similarly, if you want to define an expression that is true if any<br />

of a number of conditions are true, you can use the logical OR operator. The examples below<br />

show each operator in use…<br />

OPERATOR PRIORITY EXAMPLE<br />

Logical AND Group 11 A>10 && B>10<br />

Logical OR Group 12 A>10 || B>10<br />

The logical AND operator produces a value of 1 if and only if the expressions on the<br />

left-hand and right-hand sides are true, while the logical OR operator produces a value of 1 if<br />

either expression is true. Note that—unlike the bitwise operators referred to elsewhere in this<br />

section—the logical operators stop evaluating once they know what the answer will be. This<br />

means that in the above example for logical AND, the right-hand side of the operator will<br />

only be evaluated if A is greater than 10, as, if this were not true, the result of the AND<br />

operator must already be zero. While this property makes little difference in the examples<br />

given above, if the left-hand or right-hand expressions call a program or make a change to a<br />

data value, this behavior must be taken into account.<br />

CHOOSING VALUES<br />

You may find situations where you want to select between two values—be they integers,<br />

floating-point values or strings—depending on the value of some condition. For example, you<br />

may wish to set a motor’s speed equal to 500 rpm or 2000 rpm based on a flag tag. This<br />

operation can be performed using the ?: operator, which is unique in that it takes three<br />

arguments, as shown in the example below…<br />

OPERATOR PRIORITY EXAMPLE<br />

Selection Group 13 Fast ? 2000 : 500<br />

This example will evaluate to 2000 if Fast is true, and 500 otherwise. The operator can be<br />

thought to be equivalent to the IF function found in applications such as Microsoft Excel.<br />

PAGE 264<br />

http://www.redlion.net/controller

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

Saved successfully!

Ooh no, something went wrong!