Crestron SIMPL+ Programming Manual
Crestron SIMPL+ Programming Manual

Crestron SIMPL+ Programming Manual

Crestron simpl+ software: software guide
Hide thumbs Also See for SIMPL+:

Advertisement

Crestron SIMPL+
Software
Programming Guide

Advertisement

Table of Contents
loading

Summary of Contents for Crestron SIMPL+

  • Page 1  Crestron SIMPL+ Software Programming Guide...
  • Page 2 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.
  • Page 3: Table Of Contents

     Crestron SIMPL+ Contents  SIMPL+ Introduction ... 1 What is SIMPL+? ... 1 For Whom is this Guide Intended?... 1 Using SIMPL vs. SIMPL+... 2 What is Needed to Use SIMPL+?... 2 Where Can I Get More Information?... 2 Quick Start...
  • Page 4 Compiler Errors... 50 Run-time Errors... 50 Debugging with Print()... 51 Software License Agreement... 52 Return and Warranty Policies ... 54 Merchandise Returns / Repair Service ... 54 CRESTRON Limited Warranty... 54 ii • Contents  Crestron SIMPL+ Programming Guide – DOC. 5789A...
  • Page 5: Simpl

     Crestron SIMPL+  SIMPL+ Introduction What is SIMPL+? SIMPL+ is a language extension to SIMPL Windows but instead it enhances it. With SIMPL+ it is now possible to use a procedural “C- like” language to code elements of the program that were difficult, or impossible with SIMPL alone.
  • Page 6: Using Simpl Vs. Simpl

    SIMPL and when in SIMPL+. The answer of course is not cut-and-dry, and just about any task can be accomplished entirely in one language or the other. However, the true power of Crestron system programming is unleashed when the strengths of both environments are harnessed simultaneously.
  • Page 7 (or until it is rebooted). From the skeleton program, find the section of the program that says “Function Main”. Edit it to read the following. Programming Guide – DOC. 5789A Print( “Hello world!”\n ); Print( “Crestron people make the difference”\n ); Software  • 3 SIMPL+...
  • Page 8: Making It Work

    Making it Work This section describes how to make the simple SIMPL+ program written in the last section work inside a Crestron control processor. As was mentioned earlier, SIMPL+ programs cannot run all by themselves. They must be enclosed inside a SIMPL wrapper.
  • Page 9: The Structure Of A Simpl+ Program

     Crestron SIMPL+ program by clicking on the compile toolbar button or selecting Project | Convert/Compile. The compile process automatically recognizes that there is a SIMPL+ module in the program and compiles it along with the SIMPL code (even though it was already compiled when it was saved; SIMPL Windows always recompiles because it must link the modules together with the SIMPL Windows program).
  • Page 10 Examine the following equivalent program, which uses constant definitions in place of actual numbers.  6 • SIMPL+ switcher_input = 3; switcher_output = 2; // video projector switcher_input = 4; switcher_output = 2; // video projector  Crestron SIMPL+ Programming Guide – DOC. 5789A...
  • Page 11: Include Libraries

     Crestron SIMPL+ #DEFINE_CONSTANT VCR_INPUT 3 #DEFINE_CONSTANT DVD_INPUT 4 #DEFINE_CONSTANT VPROJ_OUTPUT 2 PUSH vcr_select PUSH dvd_select Note the use of capital letters for the constant definitions. This is not required, but it makes it clear to see the difference between variables and constants when reading through a program (but of course is not useful if all caps are used for the rest of the program).
  • Page 12: Variable Declarations

    Software Crestron-Libraries are provided from Crestron and are contained within the Crestron Database. Variable Declarations Variables can be thought of as storage areas to keep data. When writing all but the most basic of programs, users need to use variables to store values.
  • Page 13  Crestron SIMPL+ variables are also available with the INTEGER and STRING datatype. Integers are 16 bit quantities. For the 2-series control system, 32 bit quantities are supported with the LONG_INTEGER datatype. Both INTEGER and LONG_INTEGER are treated as unsigned values. Signed versions for both of these datatypes are available by using the SIGNED_INTEGER and SIGNED_LONG_INTEGER datatypes.
  • Page 14: User-Defined Functions

    (negative- or falling-edge). For example, the following code sends a string to a camera unit to pan left when the left button is pressed and then send a stop command when the button is released.  10 • SIMPL+ <statements>  Crestron SIMPL+ Programming Guide – DOC. 5789A...
  • Page 15  Crestron SIMPL+ DIGITAL_INPUT cam_up, cam_down, cam_left, cam_right; This example assumes that STRING_OUTPUT camera_command; the camera unit being controlled continues to move in a given direction until a PUSH cam_left stop command is issued. Some devices function this way, but others do not.
  • Page 16: Function Main

    // this code runs when any of // these inputs goes high // this code runs anytime anything // on the input list changes x = 0; // this code executes only once  Crestron SIMPL+ Programming Guide – DOC. 5789A...
  • Page 17: Working With Data (Variables)

     Crestron SIMPL+ This loop runs continuously for as long as the control system is on. If a construct like this is used, it is recommended that a ProcessLogic or Delay function in the loop be included to allow the logic processor a chance to handle the rest of the system. If one of these statements is not included, the operating system forces a task switch at some point in time.
  • Page 18 To understand this, the user must realize what is being seen when looking at the contents of an output variable in a  14 • SIMPL+  Crestron SIMPL+ Programming Guide – DOC. 5789A...
  • Page 19  Crestron SIMPL+ SIMPL+ program. The value of any output is the value of the signal as seen by the outside SIMPL program at that instant. This is critical considering that SIMPL+ does not necessarily “propagate” outputs to the SIMPL program each time they are changed in the program.
  • Page 20: All About Variables

    Depending upon which operations are perform on a number, the control system decides whether to treat that number as signed or unsigned.  16 • SIMPL+  Crestron SIMPL+ Programming Guide – DOC. 5789A...
  • Page 21  Crestron SIMPL+ When an integer has a value of between 0 and 32767, it is identical whether it is considered signed or unsigned. However, numbers above 32767 may be treated as negative numbers. If they are, they will have a value of x – 65536, where x is the unsigned value of the number.
  • Page 22 5797). Finally, note that the square brackets were not included after the variable  18 • SIMPL+ a = 100; b = -4; c = a / b; // c = 0 (100/65532) d = a S/ b; // d = -25 (100/-4)  Crestron SIMPL+ Programming Guide – DOC. 5789A...
  • Page 23  Crestron SIMPL+ name, as was done when it was declared. When assigning a value to a string, that value is always assigned starting at the first character position. It is important to note that the length of the this value does not exceed total length allocated for myString (in this case, 50 characters).
  • Page 24: Arrays

    = 0; for (i = 1 to len(argData)) checksum = checksum + byte(argData,i); return (argData + chr(checksum)); // 1-D integer array with 16 elements // 1-D string array with 9 elements  Crestron SIMPL+ Programming Guide – DOC. 5789A...
  • Page 25  Crestron SIMPL+ The first two examples above define 1D and 2D integer arrays, respectively. The last example looks like it declares a 2D array of strings, yet the comments states that it actually declares a 1D array of strings. Recall that in “Strings”, it was necessary to define the maximum size of the string in square brackets, which is the same notation used for arrays.
  • Page 26: Operators, Expressions, And Statements

    Typically, relational operators are used to help control the program flow. That is, test certain conditions and the result determines what happens next. This is discussed in more detail in “Controlling Program Flow: Branching” on page 24.  22 • SIMPL+  Crestron SIMPL+ Programming Guide – DOC. 5789A...
  • Page 27: Expressions

     Crestron SIMPL+ Expressions As reading through the later parts of this guide, as well as the latest revision of the SIMPL+ Language Reference Guide (Doc. 5797), the term expression is mentioned in many places. For example, in describing the syntax of the if-else construct, it may...
  • Page 28: Statements

    24 • SIMPL+ x = MyInt / 10; print("hello, world!\n"); checksum = atoi(MyString) + 5; // do something here Crestron SIMPL+ // An assignment // A function call /* Assignment using function calls and operators */ Programming Guide – DOC. 5789A...
  • Page 29  Crestron SIMPL+ Expressions a = 3 b*4 - a/3 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.
  • Page 30: Switch-Case

    // code here executes if // expression = expression1 case (expression2): // code here executes if // expression = expression2 default: // code here executes if none // of the above cases are true  Crestron SIMPL+ Programming Guide – DOC. 5789A...
  • Page 31: Controlling Program Flow: Loops

     Crestron SIMPL+ Examine an example using the switch-case construct. Perhaps there is a variable that should hold the number of days in the current month. The following example uses switch-case to set the value of this variable. switch (getMonthNum()) Notice that curly braces did not enclose many of the statements in the previous example.
  • Page 32 = checksum + byte(someString,i); using the chr function. Note that in this example we only use the low-order byte from the checksum variable */  Crestron SIMPL+ // a trigger signal // the index variable // a 15-element array // event function...
  • Page 33: While And Do-Until Loops

     Crestron SIMPL+ while and do-until Loops The for loop discussed in an earlier section is useful for iterating through code a specific number of times. However, sometimes the exact number of times a loop should repeat is unknown. Instead, it may be necessary to check to see if a condition is true after each loop to decide whether or not the loop should execute again.
  • Page 34: Exiting From Loops Early

    A function is essentially a more complicated  30 • SIMPL+ y = y + x*3 – z*z; if (y = 0) break; y = y + x*3 – z*z; x = x + 1;  Crestron SIMPL+ Programming Guide – DOC. 5789A...
  • Page 35: User Defined Functions

     Crestron SIMPL+ programming task that has been predefined and given a name. Many of the examples in previous sections of this document have used special types of functions called system functions (or built-in functions). To employ system functions, use the following format.
  • Page 36: Function Definitions

    The syntax of a SIMPL+ function call is as follows: FUNCTION MyUserFunction( [parameter1][, parameter2][, parametern] ) INTEGER_FUNCTION MyUserIntFunction( [parameter1][, parameter2][, parametern] ) STRING_FUNCTION MyUserStrFunction( [parameter1][, parameter2][, parametern] )  32 • SIMPL+ <statements> <statements> <statements>  Crestron SIMPL+ Programming Guide – DOC. 5789A...
  • Page 37  Crestron SIMPL+ The FUNCTION keyword is used to tell the SIMPL+ compiler that what follows is the definition of a function and not a function call. The FUNCTION keyword also specifies that there will be no return value for this function. INTEGER_FUNCTION and STRING_FUNCTION specify that an integer or string value will be returned as the result of the function.
  • Page 38: Defining Local Variables In Functions

    MyUserFunction1(); x = MyUserFunction2( x, 10 ); i = j * 2; k = i – 1; j = i + k; i = 1; j = 2; k = 3;  Crestron SIMPL+ Programming Guide – DOC. 5789A...
  • Page 39: Passing Variables To Functions As Arguments

     Crestron SIMPL+ In this program, it should be clear to see that both of the functions defined, as well as the push event, have access to the three global integers i, j, and k. Local variables, on the other hand, can only be accessed within the function in which they are defined.
  • Page 40: Functions That Return Values

     36 • SIMPL+ localStr = left(var3, 10); STRING leftpart[20], rightpart[20]; leftpart = left(string1,position); rightpart = right(string1,position); string1 = leftpart + string2 + rightpart;  Crestron SIMPL+ Programming Guide – DOC. 5789A...
  • Page 41  Crestron SIMPL+ String1 = itoa(int1); position = find(“Artist”,CD_data); int3 = max(int1, int2); For clarity, here are some example statements using system functions that do not have return values: Print(“Variable int1 = %d\n”,int1); ProcessLogic(); CancelWait(VCRWait); It should be clear that, at least as far as system functions go, whether or not a function returns a value depends largely upon what that function is designed to do.
  • Page 42: Function Libraries

    = 0; // initialize variable for (i = 1 to len(command)) checksum = checksum + byte(command,i); return(command + chr(checksum)); vcr_out = appendChecksum(“PLAY”); vcr_out = appendChecksum(“STOP”); Crestron SIMPL+ // calculate the sum //append the byte Programming Guide – DOC. 5789A ...
  • Page 43: Compact Flash Functions

    "MyStringFunctionLib.usl." Any number of user libraries can be included within a SIMPL+ module. Special function libraries that are created by Crestron and made available to all customers can be used in a similar manner. The only difference is the use of the #CRESTRON_LIBRARY compiler directive in place of #USER_LIBRARY.
  • Page 44: Reading And Writing Data

    (Function Main). Because of this, the functions, StartFileOperations and EndFileOperations should not be used here. StartFileOperations(); if (CheckForDisk() = 1) Call ReadMyCompactFlashCard(); else if ( WaitForNewDisk() = 0 ) Call ReadMyCompactFlashCard(); EndFileOperations();  Crestron SIMPL+ Programming Guide – DOC. 5789A...
  • Page 45  Crestron SIMPL+ DIGITAL_INPUT readCompactFlashCard; DIGITAL_INPUT writeCompactFlashCard; INTEGER myInt; LONG_INTEGER myLongInt; STRING myStr[50]; PUSH writeCompactFlashCard PUSH readCompactFlashCard The functions, ReadStructure and WriteStructure, automate the reading and writing of the individual fields within the structure. These functions do not return the number of bytes read or written.
  • Page 46: Working With Time

    INTEGER nNumBytes; StartFileOperations() nFileHandle = FileOpen( "\\CF0\\MyFile.txt", _O_CREAT ); if( nFileHandle >= 0 ) ReadStructure( nFileHandle, myInt, nNumBytes ); Print( “The number of bytes read = %d”, nNumBytes ); FileClose( nFileHandle ); EndFileOperations();  Crestron SIMPL+ Programming Guide – DOC. 5789A...
  • Page 47: Pulse

     Crestron SIMPL+ PUSH startMe It is important to realize that the control system never allows a SIMPL+ program to “lock up” the rest of the system for any significant amount of time. Thus, whenever a delay function is reached, the control system performs a task switch, meaning that the execution of the current SIMPL+ module stops momentarily as the natural flow through the SIMPL program continues.
  • Page 48 CancelWait(sysOffWait); // cancel the system off wait event Pulse(2000, screen_down); // lower screen for 20 sec. Pulse(9500, lift_down); // lower lift for 9.5 sec. Wait (1000, sysOnWait1) // 10 second delay Pulse(PULSETIME, vcr_on); Pulse(PULSETIME, dvd_on); Pulse(PULSETIME, lights_pre_1); Crestron SIMPL+ DESCRIPTION Programming Guide – DOC. 5789A ...
  • Page 49: Working With Strings

     Crestron SIMPL+ } // end of push event PUSH system_off } // end of push event Notice that in this example, the CancelWait function was used to cancel any pending waits when the SYSTEM ON or SYSTEM OFF buttons were pressed. This is analogous to using the reset input on the Delay symbol in SIMPL.
  • Page 50  46 • SIMPL+ ACTION theString empty “Now is” “the time” “Now is” jukebox_in = "Artist=Frank Sinatra, Trac" Crestron SIMPL+ theBuffer empty “Now is” “Now is the time” “Now is the time Now is” Programming Guide – DOC. 5789A ...
  • Page 51: Removing Data From Buffers

     Crestron SIMPL+ second pass: third pass: If this signal, jukebox_in, were then connected to a STRING_INPUT of a SIMPL+ program, it is likely that the string might not be seen as one complete piece. Thus the artist’s name, the track name, and the album name might not be parsed out for display on a touchpanel.
  • Page 52 = Find(searchStr,tempStr) + len(searchStr); track = mid(tempStr, startpos, Find("\r",tempStr,startpos) - startpos); searchStr = "Album="; startpos = Find(searchStr,tempStr) + len(searchStr); album = mid(tempStr, startpos, Find("\r",tempStr,startpos) - startpos); tempStr = ""; } until (len(jukebox) = 0);  Crestron SIMPL+ Programming Guide – DOC. 5789A...
  • Page 53: Understanding Processing Order

     Crestron SIMPL+ This example introduces two new system functions, which are extremely useful for string manipulation, the Find and Mid functions. To search for the existence of a substring inside of another string, use Find. If it is located, the return value of the function is the character position where this string was found.
  • Page 54: Debugging

    Trying to use a variable that has not been declared, or misspelling a variable • Attempting to assign a value to an input variable (digital, analog, string, or buffer) • Syntax errors  Crestron SIMPL+ Programming Guide – DOC. 5789A...
  • Page 55: Debugging With Print()

    To determine if a run-time error is occurring in your program, watch the status of the control system's computer port with a program such as the Viewport (available through SIMPL Windows or Crestron VisionTools or some other error message can clue the user in to a problem. Locate the problem by strategically placing Print statements in the code.
  • Page 56: Software License Agreement

    This Agreement may only be modified by a writing signed by an authorized officer of Crestron. Updates may be licensed to You by Crestron with additional or different terms. This is the entire agreement between Crestron and You relating to the Software and it supersedes any prior representations, discussions, undertakings, communications or advertising relating to the Software.
  • Page 57 “applets” incorporated into the Software), the accompanying media and printed materials, and any copies of the Software are owned by Crestron or its suppliers. The Software is protected by copyright laws and international treaty provisions. Therefore, you must treat the Software like any other copyrighted material, subject to the provisions of this Agreement.
  • Page 58: Return And Warranty Policies

    CRESTRON shall not be liable to honor the terms of this warranty if the product has been used in any application other than that for which it was intended, or if it has been subjected to misuse, accidental damage, modification, or improper installation procedures.
  • Page 59  Crestron SIMPL+ Software This page intentionally left blank.  • 55 Programming Guide – DOC. 5789A SIMPL+...
  • Page 60 Crestron Electronics, Inc. Programming Guide – DOC. 5789A 15 Volvo Drive Rockleigh, NJ 07647 04.03 Tel: 888.CRESTRON Fax: 201.767.7576 Specifications subject to www.crestron.com change without notice.

Table of Contents