Detailed instructions for use are in the User's Guide.
[. . . ] Crestron SIMPL+ Software Programming Guide
This document was prepared and written by the Technical Documentation department at:
Crestron Electronics, Inc. 15 Volvo Drive Rockleigh, NJ 07647 1-888-CRESTRON
All brand names, product names and trademarks are the property of their respective owners. ©2003 Crestron Electronics, Inc.
Crestron SIMPL+
Software
Contents
SIMPL+ 1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . [. . . ] The following are all valid SIMPL+ expressions.
max(x, 15) y * x << z a=3 (26 + byte(aString, i) mod z = 25
Expressions can range from the very simple to the very complex. It is very important to recognize that this operator can have two different meanings based upon where it is used. In the first example above, the equal sign can serve as an assignment operator (assign the value 3 to the variable a) or as an equivalency comparison operator (does the variable a equal 3?). However, an expression cannot contain an assignment (it would then become a statement, discussed in "Statements" on page 24), so it is indeed recognized as a comparison operation. In the second case, the equal sign also serves as a equivalency comparison operator. Here there is no ambiguity since a value cannot be assigned into an expression (as opposed to a variable). Refer to the following example.
x+5 chr(i) + myString a=3 b<c // // // // this evaluates evaluates to a evaluates to 1 evaluates to 1 to an integer string if true, 0 if false if true, 0 if false
The last two expressions are comparisons. In SIMPL+, true expressions result in a value of 1 and false expressions result in a value of 0. Understanding this concept is key to performing decision making in SIMPL+. In reality, any expression that evaluates to a non-zero value is considered TRUE. This concept is discussed in "Controlling Program Flow:
Programming Guide DOC. 5789A
SIMPL+ · 23
Software
Crestron SIMPL+
Branching" and "Controlling Program Flow: Loops" on pages 24 and 27, respectively.
Statements
Statements in SIMPL+ consist of function calls, expressions, assignments, or other instructions. Examples of simple statements are as follows:
x = MyInt / 10; print("hello, world!\n"); checksum = atoi(MyString) + 5; // An assignment // A function call /* Assignment using function calls and operators */
A complex statement is a collection of simple statements surrounded with curly braces ( {} ). An example of a complex statement would be as follows:
{ // start of a complex statement x = MyInt / 10; print("hello, world!\n"); checksum = atoi(MyString) + 5; } // end of a complex statement
Controlling Program Flow: Branching
In any substantial program, making decisions must control the program. SIMPL+ provides two constructs for branching the program based on the value of expressions: if-else and the switch-case statement.
ifelse
if-else is the most commonly used branching construct. In its most basic form, it is structured as follows.
if (expression1) { // do something here }
Where expression1 represents any valid SIMPL+ expression, including variables, function calls, and operators. If this expression evaluates to TRUE, then the code inside the braces is executed. If this expression evaluates to FALSE, the code inside the braces is skipped. As was discussed in "Working with Data (Variables)" on page 13, expressions, which evaluate to a nonzero result, are considered TRUE, and expressions that evaluate to 0 are considered FALSE. For example, refer to the expressions in the table that follows.
24 · SIMPL+
Programming Guide DOC. 5789A
Crestron SIMPL+
Expressions EXPRESSION
a=3 b*4 - a/3 1 0
Software
EVALUATES TO
true if a=3, false otherwise true as long as the result is non-zero always true always false
One limitation with the if construct, as shown above, is that the code inside the if is run whenever expression1 evaluates as TRUE, but any code after the closing braces runs regardless. It is often useful to execute one set of code when a condition is TRUE and then another set of code if that same condition is FALSE. [. . . ] To obtain warranty service for CRESTRON products, contact the factory and request an RMA (Return Merchandise Authorization) number. Enclose a note specifying the nature of the problem, name and phone number of contact person, RMA number, and return address. Products may be returned for credit, exchange, or service with a CRESTRON Return Merchandise Authorization (RMA) number. Authorized returns must be shipped freight prepaid to CRESTRON, Cresskill, N. J. , or its authorized subsidiaries, with RMA number clearly marked on the outside of all cartons. [. . . ]