For a tutorial on SIMPL+ programming, consult the SIMPL+ Programming Guide (Doc. 5789). The latest version of the guide can be obtained from the Downloads | Product Manuals section of the Crestron website (www.crestron.com). Software Requirements SIMPL+ has several versions. Earlier versions of SIMPL+ do not contain features and constructs found in later revisions.
The source code has also been gathered underneath a single directory for your convenience and is available on Crestron's FTP site in the SIMPL Windows directory as directory GNUSOURCE in ftp://ftp.crestron.com/Simpl_Windows and in the \GNUSource directory of the Programming Tools CD.
Page 13
(and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.
Page 14
Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)
Page 16
Copyright (C) yyyy name of author This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
I/O Datatypes (DIGITAL_INPUT, etc.) can no longer be passed to functions as arguments. • Global variables can no longer be declared within User or Crestron Libraries. • If TerminateEvent resides within a Wait Statement Block, it will only exit the Wait Statement Block's function scope - NOT the PUSH, CHANGE, RELEASE or EVENT in which it resides.
- it may, if it were compiled for other targets at some future time. More functions and support are available for 2-Series systems, so do not limit yourself to the X-Generation usages, if they are not needed. ® SIMPL+ Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ NOTE: In previous versions of SIMPL+, the settings for the target types were system-wide. Those settings applied to all SIMPL+ modules that were opened and not specific to the active module being edited. In version 3.00, the target type setting is specific only to the active module being edited and saved within that module.
Page 20
To manually outdent a block of text, highlight the block and press SHIFT and TAB. • If you have manually inserted spaces for tabs, then pressing SHIFT TAB will only outdent by only one space. Language Reference Guide - DOC. 5797G Crestron SIMPL+ ®...
® Crestron SIMPL+ Target Devices Tab Execute SIMPL+ Cross Compiler - After target files are compiled, the cross compiler can be launched from the SIMPL+ environment. This will enable you to generate the target file that will be uploaded to the operating system. Normally, the SIMPL Windows environment will handle this, since it is responsible for uploading the target file to the operating system.
Page 22
Software Crestron SIMPL+ ® Insert #CATEGORY Toolbar Pull-Down Menu in SIMPL+ Symbol Tree Category Pop-Up Window Category Selection Insertion Box ® SIMPL+ Language Reference Guide - DOC. 5797G...
® Crestron SIMPL+ General Information Conventions Used Variable names are placed in <> when discussing syntax. For example, PUSH <variable>. Optional parameters are placed in [ ]. For example, when a list has many parameters, it would be described as <var1>[, <var2>...] When discussing array notation, [ ] is used for array subscripting and is not used to mark optional code.
Full path names have the same restrictions as DOS file names in characters and format, with a maximum length of 256 characters. • Relative path names do not begin with a “\” and start from the current working directory. Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ Operators Operators Overview SIMPL+ operators perform functions between two or more variables. SIMPL+ operators consist of Arithmetic, Bitwise, and Rational Operators. Arithmetic Operators OPERATOR NAME Negation Multiplication Unsigned Division Signed Division Signed Modulo UMOD Unsigned Modulo Addition...
Page 26
X is greater or equal to Y (signed). X && Y True if X and Y are both non-zero. False otherwise. X || Y True if either X or Y is non-zero. False otherwise. Language Reference Guide - DOC. 5797G Crestron SIMPL+ ®...
Page 27
® Crestron SIMPL+ String Operators OPERATOR *NOTE: Not allowed in expressions because of possible confusion with comparison. <> < > For less than and greater than operations, the string is evaluated in ASCII order. For example, the comparison “ABC” > “ABD” would be false. The system looks character by character;...
+ is evaluated first, the expression is written as (3+5)*6, for a result of 48. ® SIMPL+ PRECEDENCE LEVEL - (Negate) ! NOT * / S/ MOD {{ }} << >> > < >= <= S> S> S>= S<= = <> & && 3+5*6 Crestron SIMPL+ OPERATORS Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ Numeric Formats Numeric (Integer) constants may be expressed in three formats; decimal, hexadecimal, or quoted character. Decimal constants are specified by writing a decimal number. Hexadecimal constants are specified by prefacing the hex constant by 0x. Quoted character constants are a single character placed between single quotes (') and have the numeric value specified on an ASCII chart.
Example: ® SIMPL+ DIGITAL_INPUT trig; ANALOG_OUTPUT i; INTEGER j; PUSH trig j=0; FOR(j=0 to 32000) i = j; Language Reference Guide - DOC. 5797G Crestron SIMPL+ ®...
Page 33
® Crestron SIMPL+ A SIMPL program drives the trig signal and monitors the state of the analog_output with an ANALOG DEBUGGER (Speedkey: TEST2) symbol. If the system did not task switch out, the only TEST2 output would show 32000. If this program were run,...
Page 34
NOTE: The event is STILL reentering. It is being forced to terminate immediately and prevent reentry more than one level deep. ® SIMPL+ Running = 1; FOR(I = 0 TO 32000) // code Running = 0; FUNCTION MAIN() Running = 0; Language Reference Guide - DOC. 5797G Crestron SIMPL+ ®...
® Crestron SIMPL+ Task Switching for 2-Series Control Systems In the 2-Series Control Systems, each SIMPL+ module also runs as one or more concurrent tasks in the control system. The MAIN and each event handler run as separate tasks sharing a common global data space.
Page 36
= q; DIGITAL_INPUT diInput1, diInput2; INTEGER I, LastNumSeconds; PUSH diInput1 WHILE (diInput1) // do something main() LastNumSeconds = 0; WHILE (1) seconds = GetNumSeconds(); IF (seconds <> LastNumSeconds) // do something Language Reference Guide - DOC. 5797G Crestron SIMPL+ ®...
Page 37
® Crestron SIMPL+ number of seconds. Since the allotted time for a SIMPL+ task to run is in fractions of a second, it is very unlikely to change during the allotted time. Unless the programmer puts in a DELAY which will put the task to “sleep” for a period of time, this task will dominate the CPU time.
® Crestron SIMPL+ Language Constructs & Functions Language Constructs & Functions Overview Functions take one or more comma-separated parameters and return a result. The following template shows how each language construct and function is explained. Name: The name used to refer to the construct or function.
X-Generation (e.g., CEN-TVAV, CNMSX- AV/PRO, CNRACKX/-DP) and 2-Series control systems. SIMPL+ is not available in the control systems preceding the X generation - CNMS, CNRACK/-D/-DP, CNLCOMP/-232, and ST-CP. ® SIMPL+ Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ Arrays Various one and two dimensional arrays are supported. All input and output arrays are 1-based, meaning that the first element has index 1, not 0. Internal variables are 0-based, meaning that the first element has index 0. In both cases, the index of the last element is the same as the dimension of the array.
Page 42
INTEGER MyArray[10][20]; STRING PhoneNumbers[100][32]; STRING_INPUT in$[32]; STRING_OUTPUT out$[10]; STRING_INPUT in$[5][32]; <struct_type> myStruct[10]; Crestron SIMPL+ MEANING 10 digital inputs, in[1] to in[10] 11 rows by 21 columns of data, from MyArray[0][0] to MyArray[10][20] 101 strings that are a maximum of 32 characters long, e.g.
® Crestron SIMPL+ Compiler Directives Compiler Directives Overview Compiler directives are used by the SIMPL+ compiler to control attributes of the symbol without generating the actual SIMPL+ code. #CATEGORY Name: #CATEGORY Syntax: Description: A Category is the name of the folder in the Logic Symbols library tree where the module is shown.
Name: #CRESTRON_LIBRARY Syntax: Description: Directs the compiler to include code from a Crestron provided library. The module name specified is the Crestron Library Filename without the CSL extension. Example: Directs the compiler to include the Crestron Library “Special Integer Functions.CSL”...
® Crestron SIMPL+ #DEFAULT_NONVOLATILE Name: #DEFAULT_NONVOLATILE Syntax: Description: Program variables retain their value if hardware power is lost. The compiler will default all variables declared within the SIMPL+ module as nonvolatile. Individual variables can use the Volatile keyword to override this default. See also...
Nonvolatile keyword to override this default. See also #DEFAULT_NONVOLATILE on Example: Version: SIMPL+ Version 3.00 Control System: 2-Series only. On an X-generation system, all variables are non-volatile. ® SIMPL+ #DEFAULT_VOLATILE page #DEFAULT_VOLATILE Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ #DEFINE_CONSTANT Name: #DEFINE_CONSTANT Syntax: Description: Define a <constant_value> that will be substituted anywhere in the current source file where <constant_name> is used. Example: Assigns the value of 0x03 to the variable I. Version: SIMPL+ Version 1.00 Language Reference Guide - DOC. 5797G #DEFINE_CONSTANT <constant_name>...
Example: Version: SIMPL+ Version 1.00 ® SIMPL+ #HELP “<help text>” #HELP “This is line 1 of my help text” #HELP “This is line 2 of my help text” Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ #HELP_BEGIN … #HELP_END Name: #HELP_BEGIN … #HELP_END Syntax: Description: The #HELP_BEGIN, #HELP_END pair makes it easier to create help since each line does not need a separate #HELP directive. When F1 is hit either on the symbol in the Symbol Library, in either the Program View or the Detail view, the help text will be displayed.
The #HINT shows up in the status bar and provides a short tactical clue as to the function of the symbol, in the same way that Crestron-defined built-in symbols do. If the hint is specified, it will be visible when the symbol is highlighted in the User Modules section of the Symbol Library.
® Crestron SIMPL+ #IF_DEFINED … #ENDIF Name: #IF_DEFINED … #ENDIF Syntax: Description: Results in compilation of the <code> only if <constant_name> has previously been defined. This construct is generally useful for putting in code for debugging purposes, giving the ability to easily turn the debugging on and off during compilation.
“Checksum Program.USP”, the tree views will show “Checksum Program” as the name. Example: Version: SIMPL+ Version 1.00 ® SIMPL+ #SYMBOL_NAME “<name of symbol>” #SYMBOL_NAME “My SIMPL+ Program” Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ #USER_LIBRARY Name: #USER_LIBRARY Syntax: Description: Directs the compiler to include code from a User written library. The module name specified is the User Library Filename without the USL extension that is used by User Libraries. Pathnames are not allowed as the USL modules are stored in the User SIMPL+ path (refer to Edit | Preferences | Paths in SIMPL Windows).
® Crestron SIMPL+ Declarations Declarations Overview Declarations control the name, type, and number of inputs and outputs on a SIMPL+ symbol. The name is shown as a cue on the symbol in SIMPL Windows and is used as the variable name in the body of the SIMPL+ program. When the symbol is drawn in SIMPL Windows, the inputs are shown in the order of DIGITAL_INPUTs, ANALOG_INPUTs, STRING_INPUTs.
1, assigning "off" sets that variable to 0. The following shows equivalent, given that VALUE is a DIGITAL_OUTPUT: ® SIMPL+ DIGITAL_INPUT YesVotes[10] DIGITAL_INPUT NoVotes[10} DIGITAL_INPUT AbstainVotes[10,5]; VALUE = 1; VALUE = on; VALUE = 0; VALUE = off; Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ ANALOG_INPUT Name: ANALOG_INPUT Syntax: Description: Routes analog inputs from the outside SIMPL program into a SIMPL+ program with the specified variable names. ANALOG_INPUT values are 16-bit numbers. They are treated as signed or unsigned values inside of a SIMPL+ program depending on the operators or functions being used.
For an array of ANALOG_OUTPUTs, the maximum value of SIZE is 65535. Valid indices are 1 through the specified size. ® SIMPL+ ANALOG_OUTPUT <var1>[,<var2>...]; ANALOG_OUTPUT <var[size]>; ANALOG_OUTPUT<var[size[,<min>]]>; Crestron SIMPL+ page page 31, and Declarations on Language Reference Guide - DOC. 5797G ®...
Page 59
® Crestron SIMPL+ Example: Signifies that one analog input is being sent from the SIMPL+ program to the SIMPL program. Signifies that up to 25 analog outputs, referred to as LEVELS[1] through LEVELS[25] are being sent from the SIMPL+ program to the SIMPL program.
Page 60
SIMPL+ Version 2.00 for BUFFER_INPUT arrays and MAX_LENGTH to 65535. SIMPL+ Version 1.00 for everything else. ® SIMPL+ BUFFER_INPUT <var1[max_length]>[,<var2[max_length]>...]; BUFFER_INPUT <var[size][max_length]>; BUFFER_INPUT<var[size[,<min>]][max_length]>; BUFFER_INPUT FromComPort[100]; BUFFER_INPUT ComBuffers[2][100]; BUFFER_INPUT ComBuffers[2,2][100]; Crestron SIMPL+ page page 31, and Declarations on page Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ DIGITAL_INPUT Name: DIGITAL_INPUT Syntax: Description: Routes digital inputs from the outside SIMPL program into a SIMPL+ program under the specified variable names. DIGITAL_INPUT values are either 0 (digital low) or 1 (digital high). Refer to the discussion on arrays on NOTE: DIGITAL_INPUT variables may not be passed to functions in Version 3.00...
For an array of DIGITAL_OUTPUTs, the maximum value of SIZE is 65535. Valid indices are 1 through the specified size. ® SIMPL+ DIGITAL_OUTPUT <var1>[,<var2>...]; DIGITAL_OUTPUT <var[size]>; DIGITAL_OUTPUT <var[size[,<min>]]>; page DIGITAL_OUTPUT State1; State1=1; State1=0; Crestron SIMPL+ page 31, and Declarations on Language Reference Guide - DOC. 5797G ®...
Page 63
® Crestron SIMPL+ Example: Signifies that two digital signals are to be sent to a SIMPL program from this SIMPL+ program. NOTE: For example, if State1 is jammed high via a BUFFER from outside the SIMPL+ program, the value of State1 becomes 1 and should be handled accordingly in the SIMPL+ code.
#DEFAULT_VOLATILE or overridden using the nonvolatile or volatile keywords. NOTE: If no RETURN statement is encountered, the function automatically returns a 0. ® SIMPL+ INTEGER <var1>[,<var2>...]; INTEGER <var1>[size] [,<var2>[size]…]; INTEGER <var1>[rows1][columns1] [,<var2>[rows2][columns2]…]; Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
Page 65
® Crestron SIMPL+ Example: Specifies one locally declared INTEGER in this SIMPL+ program Specifies an array of three INTEGERS that can be referenced under the name CommandBytes. In pictorial form, it appears as: Specifies a two-dimensional array of integers five rows deep by four columns wide.
NOTE: (2-Series) LONG_INTEGERs can be volatile or non-volatile. The default is defined using the compiler directives #DEFAULT_NONVOLATILE or #DEFAULT_VOLATILE or overridden using the nonvolatile or volatile keywords. ® SIMPL+ LONG_INTEGER <var1>[,<var2>...]; LONG_INTEGER <var1>[size] [,<var2>[size]…]; LONG_INTEGER <var1>[rows1][columns1] [,<var2>[rows2][columns2]…]; Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
Page 67
® Crestron SIMPL+ Example: Specifies one locally declared LONG_INTEGER in this SIMPL+ program Specifies an array of three LONG_INTEGERs that can be referenced under the name CommandBytes. In pictorial form, it appears as: CommandBytes[0] Specifies a two-dimensional array of LONG_INTEGERs five rows deep by four columns wide.
NOTE: (2-Series) SIGNED_INTEGERs can be volatile or non-volatile. The default is defined using the compiler directives #DEFAULT_NONVOLATILE or #DEFAULT_VOLATILE or overridden using the nonvolatile or volatile keywords. ® SIMPL+ SIGNED_INTEGER <var1>[,<var2>...]; SIGNED_INTEGER <var1>[size] [,<var2>[size]…]; SIGNED_INTEGER <var1>[rows1][columns1] [,<var2>[rows2][columns2]…]; Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
Page 69
® Crestron SIMPL+ Example: Specifies one locally declared SIGNED_INTEGER in this SIMPL+ program Specifies an array of three SIGNED_INTEGERS that can be referenced under the name CommandBytes. In pictorial form, it appears as: CommandBytes[0] Specifies a two-dimensional array of integers five rows deep by four columns wide.
NOTE: (2-Series) SIGNED_LONG_INTEGERs can be volatile or non-volatile. The default is defined using the compiler directives #DEFAULT_NONVOLATILE or #DEFAULT_VOLATILE or overridden using the nonvolatile or volatile keywords. ® SIMPL+ SIGNED_LONG_INTEGER <var1>[,<var2>...]; SIGNED_LONG_INTEGER <var1>[size] [,<var2>[size]…]; SIGNED_LONG_INTEGER <var1>[rows1][columns1] [,<var2>[rows2][columns2]…]; Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
Page 71
® Crestron SIMPL+ Example: Specifies one locally declared SIGNED_LONG_INTEGER in this SIMPL+ program Specifies an array of three SIGNED_LONG_INTEGERs that can be referenced under the name CommandBytes. In pictorial form, it appears as: CommandBytes[0] Specifies a two-dimensional array of SIGNED_LONG_INTEGERs five rows deep by four columns wide.
NOTE: (2-Series) STRINGs can be volatile or non-volatile. The default is defined using the compiler directives #DEFAULT_NONVOLATILE or #DEFAULT_VOLATILE or overridden using the nonvolatile or volatile keywords. ® SIMPL+ STRING <var1[size1]>[,<var2[size2]>...]; STRING <var1[num_elements1][num_characters1]>[, <var2[num_elements2][num_characters2]>...]; Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
Page 73
® Crestron SIMPL+ Example: Signifies that one local STRING is declared in this SIMPL+ program. Signifies that three strings of 10 characters long have been allocated. To assign values, the following would be legal: Version: SIMPL+ Version 2.00 for SIZE and NUM_CHARACTER up to 65535.
® Crestron SIMPL+ STRING_OUTPUT Name: STRING_OUTPUT Syntax: Description: Routes serial strings from the SIMPL+ program to the SIMPL program. A string length is not required as the output string buffer management is performed by the operating system. Refer to the discussion on arrays on NOTE: These outputs may be jammed with other serial string signals in the SIMPL program, although the value does not propagate back into the SIMPL+ symbol.
Page 76
SIMPL+ Version 3.00 - can no longer be passed to functions by reference. (2-Series Control Systems only) SIMPL+ Version 2.00 for STRING_OUTPUT arrays. SIMPL+ Version 1.00 for everything else. ® SIMPL+ STRING_OUTPUT TheName$; STRING_OUTPUT SortedNames$[5]; STRING_OUTPUT SortedNames$[5,5]; Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ STRUCTURES A structure is a collection of one or more variables grouped together under a single name. These variables, called structure fields or members, may consist of both integer and string datatypes. Structures help organize related data because they allow variables to be grouped together as a unit instead of as separate entities.
If ( OneEntry.Name = “David” ) Return; If ( Entry[5].Name = “David” ) Return; FUNCTION myFunction ( PhoneBookEntry argOneEntry, PhoneBookEntry argEntry[] ) if ( argOneEntry.Name = “David” ) return; if ( argEntry[5].Name = “David” ) return; Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
Page 79
® Crestron SIMPL+ Declaration Modifiers Volatile Name: Volatile Syntax: NOTE: This is not a declaration but a declaration modifier. It works only in conjunction with another declaration keyword. Description: Global integer and string program variables will not retain their value if hardware power is lost.
Example: Version: SIMPL+ Version 3.00 Control System: 2-series only. The X-generation processors will give a message that says all variables are non-volatile. ® SIMPL+ Nonvolatile Nonvolatile integer n; Nonvolatile string s[100]; Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ E-mail Functions Important SendMail Considerations Language Reference Guide - DOC. 5797G 1. In the SIMPL+ function call to “Send Mail”, the parameters “Mailserv”, “To” and “From” fields are MANDATORY, whereas “cc”, “subject” and “message” are not. 2. Only the “SMTP AUTH” authentication type with “LOGIN”...
Page 82
SMTP_SEND_FAILURE SMTP FAILURES (RECOVERABLE ERRORS) ERROR CODE SMTP_FAILURE_TO_RCPT_COMMAND SMTP_FAILURE_CC_RCPT_COMMAND SMTP_FAILURE_DATA_COMMAND ® SIMPL+ Crestron SIMPL+ DESCRIPTION Success DESCRIPTION Any non-recoverable error from the e-mail module of the firmware (for example: if “mailserver”, “from” and “to” are empty). General internal error. Failure to connect to the mailserver.
® Crestron SIMPL+ SendMail Name: SendMail Syntax: Description: Send an e-mail message using SMTP protocol. Parameters: Server - Required. Specifies address of the mail server. It can either be an IP address in dot-decimal notation (ex: 192.168.16.3) or a name to be resolved with a DNS server (ex: mail.myisp.com).
Page 84
= SendMail( “192.168.16.3”, “UserLogonName”, “UserLogonPassword”, “SenderEmailAddress@crestron.com”, “RecipientEmailAddress@crestron.com”, “ccEmailAddress@crestron.com”, “This is the subject”, “This is the message” ); if ( nErr < 0 ) Print( “Error sending e-mail\n” ); else Print( “SendMail successful!\n ); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ Events Events Overview SIMPL+ is an event driven language. There are four functions which deal with activating events in a given SIMPL+ program; CHANGE, EVENT, PUSH, and RELEASE. CHANGE Name: CHANGE Syntax: Description: <variable_name> may be either a DIGITAL_INPUT, ANALOG_INPUT, or STRING_INPUT type.
Page 86
STRING_INPUT some_data$[100]; ANALOG_OUTPUT level; CHANGE some_data$ level=48; ANALOG_INPUT ThingsToAdd[20]; ANALOG_OUTPUT Sum; INTEGER I, Total; CHANGE ThingsToAdd Total=0; FOR(I=0 to 20) if (IsSignalDefined (ThingsToAdd[I])) Total = Total + ThingsToAdd[I]; Sum = Total; Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ EVENT Name: EVENT Syntax: Description: Executes the defined <statements> anytime one of the inputs to the SIMPL+ symbol changes. It is similar to having a CHANGE statement listed for every input, and each change is set up to execute a common block of code. Refer to “Stacked Events” on...
® Crestron SIMPL+ Release Name: RELEASE Syntax: Description: <variable_name> is a DIGITAL_INPUT type. On the trailing edge of <variable_name>, the statements between the opening { and closing } are executed. When using DIGITAL_INPUT arrays, only a change in the entire array can be detected, not an individual element.
CHANGE statements in the order they appear in the source EVENT statement PUSH var1, var2 // code STRING_INPUT A$[100]; DIGITAL_INPUT IN1, IN2, IN3, IN4; ANALOG_INPUT LEVEL; ANALOG_INPUT PRESETS[5]; PUSH IN1 PUSH IN2 CHANGE IN3, LEVEL, A$, PRESETS RELEASE IN3, IN4 // code Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
Page 91
® Crestron SIMPL+ Expressions & Statements An expression consists of operators and operands. i.e., Statements consist of function calls, expressions, assignments, or other instructions. There are two types of statements, Simple and Complex. A simple statement ends with a semicolon (;). Examples of simple statements are: A complex statement is a collection of simple statements that start with '{' and end with '}'.
Page 92
X after it is incremented to the computer port of the control system. Version: SIMPL+ Version 1.00 ® SIMPL+ <statements> [}] UNTIL (<expression>); INTEGER X; X=0; X = X + 1; PRINT(“X = %d\n”, X); UNTIL (X = 25); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ Name: Syntax: Description: This loop executes the <statements> while <variable> iterates from the value of <start_expression> to the value of <end_expression>. The variable is incremented by <step_expression> at the end of the loop, if STEP is specified, else it is incremented by 1.
Page 94
Version: SIMPL+ Version 1.00 ® SIMPL+ STRING_INPUT IN$[100]; INTEGER X; FOR (X = 1 TO LEN(IN$)) PRINT(“Character %d of String %s is %s\n”, X, IN$, MID(IN$, X, 1)); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ WHILE Name: WHILE Syntax: Description: This loop performs a set of <statements> as long as <expression> does not evaluate to zero. If only one statement is present in the body of the loop, then the { and } characters are not required, but may be used.
69. Otherwise, the loop will exit via the normal termination condition. Version: SIMPL+ Version 1.00 ® SIMPL+ BREAK; INTEGER X; ANALOG_INPUT Y; X=0; WHILE(X<25) IF(Y = 69) BREAK; X = X + 1; PRINT(“X=%d\n”, X); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ CSWITCH Name: CSWITCH Syntax: NOTE: In SIMPL+ v3.01.00 and later, the 'break' statement is required to terminate the case statement block that it resides within. If no 'break' statement exists, the program will continuing executing to the next case statement block or default statement block.
CASE (3): X = AIN; // continue executing to next case statement block ==> case(5) CASE (5): X = X + AIN + 1; break; DEFAULT: PRINT(“Unknown command %d!\n”, AIN); break; Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ IF - ELSE Name: IF - ELSE Syntax: Since <statements> can be an IF construct, you can string out a series of IF-ELSE-IF statements of the form: NOTE: A final ELSE may be used to express default handling if none of the previous conditions were met.
® Crestron SIMPL+ SWITCH Name: SWITCH Syntax: NOTE: Many CASE statements may be used in the body of the SWITCH. Description: SWITCH is a more direct method of writing a complex IF-ELSE-IF statement. In the SWITCH, if <expression> is equal to <expression1>, <statements1> is executed. If <expression>...
Page 102
SIMPL+ Version 1.00 with 32 CASE statements maximum ® SIMPL+ ANALOG_INPUT AIN; INTEGER X; SWITCH(AIN) CASE (2): X = 0; CASE (3): X = AIN; CASE (5): X = AIN + 1; DEFAULT: PRINT(“Unknown command %d!\n”, AIN); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ Array Operations Array Operations Overview Array Operations functions are used to perform generalized operations on arrays, such as getting bounds and setting the elements of an array to a known value in a given SIMPL+ program. GetLastModifiedArrayIndex...
Page 104
INTERLOCKED_LIGHT_SCENES[GetLastModifiedArrayIndex()] = DIGITAL_INPUT LIGHT_SCENES[10]; DIGITAL_OUTPUT INTERLOCKED_LIGHT_SCENES[10]; INTEGER I; PUSH LIGHT_SCENES,MORE_LIGHT_SCENES {//this PUSH statement will be called twice (once for LIGHT_SCENES and once for MORE_LIGHT_SCENES) FOR(I=1 to 10) INTERLOCKED_LIGHT_SCENES[I]=0 ProcessLogic(); INTERLOCKED_LIGHT_SCENES[GetLastModifiedArrayIndex()] = Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ GetNumArrayCols Name: GetNumArrayCols Syntax: Description: Finds the number of columns in a two-dimensional array or the size of the array for a one-dimensional array. Parameters: ARRAY_NAME is the array as determined by the size. Return Value: For the data types in the table after this paragraph, the return value of GetNumArrayCols is shown.
Page 106
Software Example: In this example, Columns = 20 will be printed. Version: SIMPL+ Version 2.00 ® SIMPL+ DIGITAL_INPUT TEST; INTEGER My_Array[10][20]; PUSH TEST PRINT(“Columns = %d\n”, GetNumArrayCols(My_Array)); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ GetNumArrayRows Name: GetNumArrayRows Syntax: Description: Returns the number of rows for two-dimensional arrays. One-dimensional arrays return 0. Parameters: ARRAY_NAME is the array name as determined by the size. Return Value: For the data types in the table after this paragraph, the return value of GetNumArrayRows is shown.
Each string in ARRAY_NAME is initialized to CHR (INIT_VALUE). STRING Each string in ARRAY_NAME is set equal to INIT_VALUE. IF INIT_VALUE is longer than the maximum size allowed in the array, it is truncated. Crestron SIMPL+ MEANING Language Reference Guide - DOC. 5797G ®...
Page 109
® Crestron SIMPL+ Example: The first line initializes all elements of the integer array Levels to contain the integer The second line attempts to initialize the elements of the integer array Levels with a string value - an ATOI is done on the “3”, which returns a 3, so that the end result is the same as the first line.
“c” in SOURCE). ® SIMPL+ INTEGER Bit(STRING SOURCE, INTEGER SOURCE_BYTE, INTEGER BIT_IN_BYTE); Actual Byte in SOURCE = (BIT_IN_BYTE / 8) + SOURCE_BYTE Actual Bit in Actual Byte = (BIT_IN_BYTE MOD 8) Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
Page 111
® Crestron SIMPL+ Example: This example takes an input string and creates an output string containing the elements of the input string that do not have the most significant bit (bit 7) set. Version: SIMPL+ Version 1.00 Language Reference Guide - DOC. 5797G STRING_INPUT SOURCE$[100];...
® Crestron SIMPL+ High Name: High Syntax: Description: Returns the upper (most significant) 8-bits of an Integer. Parameters: VALUE is an integer containing the value of the most significant byte. Return Value: The upper 8-bits of the passed value. Example: This will print the input value and the upper 8-bits of the value in hexadecimal.
VALUE is 0x1234, then the output is: Version: SIMPL+ Version 1.00 ® SIMPL+ INTEGER Low(INTEGER VALUE) ANALOG_INPUT VALUE; CHANGE VALUE PRINT(“The lower byte of %X is %X\n”, VALUE, LOW(VALUE)); The lower byte of 1234 is 34. Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ RotateLeft Name: RotateLeft Syntax: Description: Rotate X to the left (more significant direction) by Y bits; full 16 bits used. Same as {{ operator. See RotateRight on Parameters: X is the INTEGER to have bits rotated Y is the amount of bits to rotate Return Value: An INTEGER containing the result of the rotated bits.
If X = 0x1234 and Y is 1 then result is 0x091A Version: SIMPL+ Version 3.01.06 ® SIMPL+ INTEGER RotateRight( INTEGER X, INTEGER Y ); INTEGER X, Y, result; result = RotateRight( X, Y ); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ RotateLeftLong Name: RotateLeftLong Syntax: Description: Rotate X to the left by Y bits; full 32 bits used. Parameters: X is the LONG_INTEGER to have bits rotated Y is the amount of bits to rotate Return Value: A LONG_INTEGER containing the result of the rotated bits.
A LONG_INTEGER containing the result of the rotated bits. Example: Version: SIMPL+ Version 3.01.06 ® SIMPL+ LONG_INTEGER RotateRightLong( LONG_INTEGER X, INTEGER Y LONG_INTEGER X, Y, result; result = RotateRightLong( X, Y ); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ Data Conversion Functions Data Conversion Functions Overview These functions take one form of data (integer or string) and convert it to the opposite type in a given SIMPL+ program. Usually, these functions are for converting number stored in strings to integers, or for converting numbers stored in integers to strings.
Version: SIMPL+ Version 3.00.02 Control System 2-Series Only ® SIMPL+ LONG_INTEGER Atol(STRING SOURCE); STRING_INPUT IN$[100]; LONG_INTEGER VAL; CHANGE IN$ VAL = ATOL(IN$); PRINT(“Value of %s after ATOL is %ld\n”, IN$, VAL); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ Name: Syntax: Description: Takes the integer value specified and returns the corresponding ASCII character as a one-byte string. Parameters: CODE contains a number from 0 to 255 to be converted into an ASCII string. Return Value: A string representing the code. If CODE is greater than 255, lower 8-bits of CODE are used in the computation.
For example, if VALUE was equal to 25, Code$ would contain the string “25”. Version: SIMPL+ Version 1.00 ® SIMPL+ STRING ItoA(INTEGER CODE); out$ = itoa(CODE); makestring(out$, “%d”, CODE); STRING_OUTPUT Code$; ANALOG_INPUT VALUE; CHANGE VALUE Code$ = ITOA(VALUE); PRINT(“Code = %s\n”, Code$); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ ItoHex Name: ItoHex Syntax: Description: Takes the value in CODE and creates a string containing the hexadecimal equivalent. The output string does not contain leading zeros and is expressed in uppercase. Parameters: CODE contains a number from 0 to 65535 to be converted into a hexadecimal string.
® Crestron SIMPL+ LtoHex Name: LtoHex Syntax: Description: Takes the value in CODE and creates a string containing the hexadecimal equivalent. The output string does not contain leading zeros and is expressed in uppercase. Parameters: CODE contains a number from 0 to 2147483647 to be converted into a hexadecimal string.
PC and read on another, e.g. a Crestron control system, or vice versa. Most programmers are used to writing programs that are both written by a PC and read by a PC.
® Crestron SIMPL+ CheckForDisk Name: CheckForDisk Syntax: Description: Tests whether or not a compact flash card is currently installed in the control system. Parameters: None. Return Value: Returns 1 if a compact flash card is currently installed in the control system. Refer to “WaitForNewDisk()”...
® Crestron SIMPL+ FileBOF Name: FileBOF Syntax: Description: Tests whether or not the current file pointer is at the beginning of the file. Parameters: HANDLE specifies the file handle of the previously opened file (from FileOpen). Return Value: Returns 1 if beginning of file or 0 if not end of file. Otherwise, file error code is returned.
® Crestron SIMPL+ FileDate Name: FileDate Syntax: Description: Returns a string corresponding to the current date of the specified file with the specified FORMAT. Parameters: INFO – structure containing the information about a found file (refer to "FindFirst" on page FORMAT is an integer describing the way to format the date for the return.
® Crestron SIMPL+ FileDay Name: FileDay Syntax: Description: Returns the day of the week of the file as a STRING. Parameters: INFO – structure containing the information about a found file (refer to “FindFirst” on page Return Value: The day of the week of the file is returned in a string. Valid returns are Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, or Saturday.
® Crestron SIMPL+ FileEOF Name: FileEOF Syntax: Description: Tests whether or not the current file pointer is at the end of the file. Parameters: HANDLE specifies the file handle of the previously opened file (from FileOpen). Return Value: Returns 1 if end of file or 0 if not end of file. Otherwise, file error code is returned.
® Crestron SIMPL+ FileGetDayOfWeekNum Name: FileGetDayOfWeekNum Syntax: Description: Returns an integer corresponding to the day of the week of file. Parameters: INFO – structure containing the information about a found file (refer to "FindFirst" on page Return Value: The day of the week as an integer from 0 to 6; 0 represents Sunday to 6 representing Saturday.
® Crestron SIMPL+ FileGetMinutesNum Name: FileGetMinutesNum Syntax: Description: Returns an integer corresponding to the number of minutes in the file time. Parameters: INFO – structure containing the information about a found file (refer to "FindFirst" on page Return Value: The number of minutes from 0 to 59.
® Crestron SIMPL+ FileGetSecondsNum Name: FileGetSecondsNum Syntax: Description: Returns an integer corresponding to the number of seconds in the time of the file. Parameters: INFO – structure containing the information about a found file (refer to "FindFirst" on page Return Value: The number of seconds from 0 to 59.
® Crestron SIMPL+ FILE_INFO Structure Use this structure to retrieve information about a file. File Attribute Bit Flags - KEYWORD ARDONLY AHIDDEN ASYSTEM AVOLUME ADIRENT ARCHIVE Version: SIMPL+ Version 3.00.02 or higher (Pro 2 only) NOTE: For an example of how and where to use the FILE_INFO structure, refer to the example code in "FindFirst"...
® Crestron SIMPL+ FileMonth Name: FileMonth Syntax: Description: Returns the month of the file date as a string. Parameters: INFO – structure containing the information about a found file (refer to "FindFirst" on page Return Value: The current month is returned in a string. Valid returns are January, February, March, April, May, June, July, August, September, October, November, or December.
Open succeeds only if file doesn't already exist Truncates file. Mutually exclusive with _O_APPEND Open file for reading only Open file for both reading and writing Open file for writing only Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
Page 149
® Crestron SIMPL+ Examples: (Refer to "File Functions Overview"on page 116) Example 1: Open a read only file: Example 2: Open an existing file to log data to the end Example 3: Truncate an existing file and get rid of previous contents. If it does not exist, create it.
Page 150
Software Version: SIMPL+ Version 3.00.02 or higher (Pro 2 only) Control System: 2-Series Only ® SIMPL+ Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ FileRead Name: FileRead Syntax: Description: Reads data from a file as a series of bytes into a buffer, starting at the current file position. Refer to the section entitled “Reading and Writing Data to a File” on page...
Page 152
IF (nFileHandle >= 0) WHILE (FileRead(nFileHandle, sBuf, 4096) > 0) PRINT ( “Read from file: %s\n”, sBuf ); IF ( FileClose ( nFileHandle ) <> 0 ) PRINT ( “Error closing file\n” ); EndFileOperations(); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ FileSeek Name: FileSeek Syntax: Description: Positions the current file pointer. Parameters: HANDLE specifies the file handle of previously opened file (from FileOpen). OFFSET specifies the number of bytes to move relative to the origin. ORIGIN is on of the file seek flags in the following table.
2. Go to end of file: FileSeek (nFileHandle, O, SEEK_END) 3. Get current file position: CurrentBytePosition= FileSeek (nFileHandle,O, Version: SIMPL+ Version 3.00.02 or higher (Pro 2 only) Control System: 2-Series Only ® SIMPL+ SEEK_CUR) Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ FileTime Name: FileTime Syntax: Description: Returns a string containing the current system time. Parameters: INFO – structure containing the information about a found file (refer to "FindFirst" on page Return Value: The return string contains the time in HH:MM:SS format, in 24-hour time. If a value is not two digits wide, it is padded with leading zeros.
Page 156
Number of bytes written to the file. If the return value is negative, it is an error code. ® SIMPL+ SIGNED_INTEGER FileWrite (INTEGER handle, STRING buffer, INTEGER count ) for a discussion of when to use this function and when to use the related functions Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
Page 157
® Crestron SIMPL+ Example: (Refer to "File Functions Overview"on page 116) Version: SIMPL+ Version 3.01 or higher (Pro 2 only) Control System: 2-Series Only Language Reference Guide - DOC. 5797G SIGNED_INTEGER nFileHandle; STRING sBuf [ 4096 ]; StartFileOperations(); sBuf = “Hello World!”;...
® Crestron SIMPL+ FindFirst Name: FindFirst Syntax: Description: This command searches a directory for file(s) matching the given file specification. Always followed with a FindClose, refer to Requires StartFileOperations(), refer to Parameters: FILESPEC specifies the filename to look for. It can be a full path name or a relative path name with wildcards ( the ‘*’...
Page 160
((FileInfo.File Attributes&ADIRENT) <>0) PRINT (“%s is a directory\n”, FileInfo.Name Else PRINT (“%s is a file\n”,FileInfo.Name Found = FindNext(FileInfo); IF ( FindClose() < 0 ) PRINT ( “Error in closing find operation\n” ); EndFileOperations(); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ FindNext Name: FindNext Syntax: Description: This command continues the current directory for file(s) matching the file specification in the "FindFirst" command. Parameters: INFO – structure containing the information about a found file (refer to "FindFirst" on page Return Value: Returns 0 if a file is found matching the specification and –1 if an error occurred.
SIMPL+ Version 3.00.02 or higher (Pro 2 only) Control System: 2-Series Only ® SIMPL+ STRING GetCurrentDirectory() page 14 for a discussion of setting the current directory. PRINT( “The current directory = GetCurrentDirectory()); Crestron SIMPL+ %s\n”, Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ IsDirectory Name: IsDirectory Syntax: Description: This routine returns whether the specified file is a directory, equivalent to checking info;Attributes. Parameters: INFO – structure containing the information about a found file (refer to "FindFirst" Return Value: Returns 1 if file is a directory and 0 otherwise.
® Crestron SIMPL+ IsReadOnly Name: IsReadOnly Syntax: Description: This routine returns whether the specified file is marked as read-only. Equivalent to checking attributes in FILE_INFO. Refer to Parameters: INFO – structure containing the information about a found file (refer to "FindFirst"...
WHILE (Found = 0) if (IsSystem(FileInfo)) PRINT( “%s is a system file\n”, FileInfo.Name ); Found = FindNext(FileInfo); IF ( FindClose() < 0 ) PRINT ( “Error in closing find operation\n” ); EndFileOperations(); Crestron SIMPL+ 135. Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ IsVolume Name: IsVolume Syntax: Description: This routine returns whether the specified file is a volume label. Equivalent to checking attributes in FILE_INFO. Refer to Parameters: INFO – structure containing the information about a found file (refer to "FindFirst"...
® Crestron SIMPL+ ReadInteger Name: ReadInteger Syntax: Description: Reads an integer from a file starting at the current file position. Two bytes are read, most significant byte first. Refer to the section entitled “Reading and Writing Data to a File” on page...
® Crestron SIMPL+ ReadIntegerArray Name: ReadIntegerArray Syntax: Description: Reads the array from a file starting at the current file position. Two bytes are read, most significant first containing the row dimension of the array, then two more bytes are read, containing the column dimension of the array. Then each integer is read as a two byte quantity, most significant byte first.
® Crestron SIMPL+ ReadLongInteger Name: ReadLongInteger Syntax: Description: Reads a long integer from a file starting at the current file position. Four bytes are read, most significant byte first and least significant byte last. Refer to the section entitled “Reading and Writing Data to a File” on page...
Page 174
= FileOpen ( “MyFile”, _O_RDONLY ); IF (nFileHandle >= 0) iErrorCode = ReadLongInteger(nFileHandle, li); if (iErrorCode > 0) PRINT ( “Read long integer from file correctly.\n”); else PRINT ( “Error code %d\n”, iErrorCode); EndFileOperations(); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ ReadLongIntegerArray Name: ReadLongIntegerArray Syntax: Description: Reads the array from a file starting at the current file position. Two bytes are read, most significant first containing the row dimension of the array, then two more bytes are read, containing the column dimension of the array. Then each long integer is read as a four byte quantity, most significant byte first.
® Crestron SIMPL+ ReadSignedInteger Name: ReadSignedInteger Syntax: Description: Reads a signed integer from a file starting at the current file position. Two bytes are read, most significant first. Refer to the section entitled “Reading and Writing Data to a File” on page...
Page 178
= FileOpen ( “MyFile”, _O_RDONLY ); IF (nFileHandle >= 0) iErrorCode = ReadSignedInteger(nFileHandle, si); if (iErrorCode > 0) PRINT ( “Read signed integer from file correctly\n”); else PRINT ( “Error code %d\n”, iErrorCode); EndFileOperations(); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ ReadSignedIntegerArray Name: ReadSignedIntegerArray Syntax: Description: Reads the array from a file starting at the current file position. Two bytes are read, most significant first containing the row dimension of the array, then two more bytes are read, containing the column dimension of the array. Then each signed integer is read as a two byte quantity, most significant byte first.
Page 181
® Crestron SIMPL+ ReadSignedLongInteger Name: ReadSignedLongInteger Syntax: Description: Reads data from a file starting at the current file position. Each element of the structure is read, without any padding bytes, that might actually be there in memory. Refer to the section entitled “Reading and Writing Data to a File” on page...
® Crestron SIMPL+ ReadSignedLongIntegerArray Name: ReadSignedLongIntegerArray Syntax: Description: Reads the array from a file starting at the current file position. Two bytes are read, most significant first containing the row dimension of the array, then two more bytes are read, containing the column dimension of the array. Then each signed long integer is read as a four byte quantity, most significant byte first.
® Crestron SIMPL+ ReadString Name: ReadString Syntax: Description: Reads a string from a file starting at the current file position. Internally, the string is stored as a 2-byte length, most significant byte first, then the actual string bytes. In the case of a string variable, the total number of bytes written is calculated from the size of the string, not the string allocation size.
® Crestron SIMPL+ ReadStringArray Name: ReadStringArray Syntax: Description: Reads a string from a file starting at the current file position. Internally, the string is stored with the first 2 bytes indicating the total number of string written, then each string follows as a 2-byte length, most significant byte first, then the actual string bytes.
® Crestron SIMPL+ ReadStructure Name: ReadStructure Syntax: Description: Reads data from a file starting at the current file position. Each element of the structure is read, without any padding bytes, that might actually be there in memory. Refer to the section entitled “Reading and Writing Data to a File” on page...
® Crestron SIMPL+ RemoveDirectory Name: RemoveDirectory Syntax: Description: Removes the directory with the specified name. The path name can be a relative link or absolute, refer to page refer to page Parameters: DIRNAME – string containing the name of the desired directory.
® Crestron SIMPL+ StartFileOperations Name: StartFileOperations Syntax: Description: Signifies to the operating system that the current thread is starting its file operations. Parameters: None. Return Value: Returns 0 if successful and –1 if an error occurred. Example: (Refer to "File Functions Overview"on page 116) NOTE: StartFileOperations is required prior to any operation accessing a file.
SIMPL+ Version 3.00.02 or higher (Pro 2 only) Control System: 2-Series Only ® SIMPL+ SIGNED_INTEGER WaitForNewDisk() page 119. while(1) if ( WaitForNewDisk() < 0 ) break; // perform operations on the new disk. Read a file, etc. Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ WriteInteger Name: WriteInteger Syntax: Description: Writes an integer from a file starting at the current file position. Two bytes are written, most significant byte first. Refer to the section entitled “Reading and Writing Data to a File” on page...
® Crestron SIMPL+ WriteIntegerArray Name: WriteIntegerArray Syntax: Description: Writes the array from a file starting at the current file position. Two bytes are written, most significant first containing the row dimension of the array, then two more bytes are written, containing the column dimension of the array. Then each integer is written as a two byte quantity, most significant byte first.
Page 198
= FileOpen ( “MyFile”, _O_WRONLY ); IF (nFileHandle >= 0) iErrorCode = WriteIntegerArray(nFileHandle, iArray); if (iErrorCode > 0) PRINT ( “Array written to file correctly.\n”); else PRINT ( “Error code %d\n”, iErrorCode); EndFileOperations(); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ WriteLongInteger Name: WriteLongInteger Syntax: Description: Writes a long integer from a file starting at the current file position. Four bytes are written, most significant byte first. Refer to the section entitled “Reading and Writing Data to a File” on page...
® Crestron SIMPL+ WriteSignedInteger Name: WriteSignedInteger Syntax: Description: Writes a signed integer from a file starting at the current file position. Two bytes are written, most significant first. Refer to the section entitled “Reading and Writing Data to a File” on page...
® Crestron SIMPL+ WriteSignedIntegerArray Name: WriteSignedIntegerArray Syntax: Description: Writes the array from a file starting at the current file position. Two bytes are written, most significant first containing the row dimension of the array, then two more bytes are Write, containing the column dimension of the array. Then each signed integer is written as a two byte quantity, most significant byte first.
Page 204
= FileOpen ( “MyFile”, _O_WRONLY ); IF (nFileHandle >= 0) iErrorCode = WriteSignedIntegerArray(nFileHandle, isArray); if (iErrorCode > 0) PRINT ( “Array written to file correctly.\n”); else PRINT ( “Error code %d\n”, iErrorCode); EndFileOperations(); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ WriteSignedLongInteger Name: WriteSignedLongInteger Syntax: Description: Writes data from a file starting at the current file position. Each element of the structure is written, without any padding bytes, that might actually be there in memory. Refer to the section entitled “Reading and Writing Data to a File” on page...
Page 206
Software Version: SIMPL+ Version 3.01 or higher (Pro 2 only) Control System: 2-Series Only ® SIMPL+ Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ WriteSignedLongIntegerArray Name: WriteSignedLongIntegerArray Syntax: Description: Writes the array from a file starting at the current file position. Two bytes are written, most significant first containing the row dimension of the array, then two more bytes are written, containing the column dimension of the array. Then each signed long integer is written as a four byte quantity, most significant byte first.
Page 208
= FileOpen ( “MyFile”, _O_WRONLY ); IF (nFileHandle >= 0) iErrorCode = WriteSignedLongIntegerArray(nFileHandle, sliArray); if (iErrorCode > 0) PRINT ( “Array written to file correctly.\n”); else PRINT ( “Error code %d\n”, iErrorCode); EndFileOperations(); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
Page 209
® Crestron SIMPL+ WriteString Name: WriteString Syntax: Description: Writes a string to a file starting at the current file position. Internally, the string is stored as a 2-byte length, most significant byte first, then the actual string bytes. In the case of a string variable, the total number of bytes written is the calculated from the size of the string, not the string allocation size.
Page 210
= FileOpen ( “MyFile”, _O_WRONLY ); IF (nFileHandle >= 0) iErrorCode = WriteString( nFileHandle, s); if (iErrorCode > 0) PRINT ( “String written to file correctly.\n”); else PRINT ( “Error code %d\n”, iErrorCode); EndFileOperations(); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ WriteStringArray Name: WriteStringArray Syntax: Description: Writes a string array to a file starting at the current file position. Internally, the string is stored with the first 2 bytes indicating the total number of strings written, then each string follows as a 2-byte length, most significant byte first, then the actual string bytes.
Page 212
= FileOpen ( “MyFile”, _O_WRONLY ); IF (nFileHandle >= 0) iErrorCode = WriteStringArray( nFileHandle, s); if (iErrorCode > 0) PRINT ( “String written to file correctly.\n”); else PRINT ( “Error code %d\n”, iErrorCode); EndFileOperations(); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ WriteStructure Name: WriteStructure Syntax: Description: Writes data to a file starting at the current file position. Each element of the structure is written, without any padding bytes, that might actually be there in memory. Refer to the section entitled “Reading and Writing Data to a File” on page...
Page 214
< 0 ) PRINT ( “Error writing structure. nTotalBytesWritten ); else PRINT ( “Structure written to file correctly. bytes written = %d\n”, nTotalBytesWritten ); EndFileOperations(); Crestron SIMPL+ Error code = %d\n”, Total Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ Mathematical Functions Mathematical Functions Overview These functions perform general mathematical operations in a given SIMPL+ program by operating on one or more numerical arguments and returning an INTEGER as a result. Name: Syntax: Description: Takes the absolute value of SOURCE. If SOURCE is negative, a positive value is returned.
Version: SIMPL+ Version 1.00 ® SIMPL+ INTEGER Max(INTEGER VAL1, INTEGER VAL2) INTEGER X, Y; FUNCTION MAIN() X = MAX(65535, 0); Y = MAX(25, 26); Crestron SIMPL+ for a further explanation of how the Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ Name: Syntax: Description: Determine the minimum of two values based on an unsigned comparison. Parameters: VAL1 and VAL2 are both INTEGER values on which the test is performed. Return Value: The minimum of Val1, Val2 after an unsigned comparison is performed. Refer to “Signed vs.
INTEGER MulDiv(INTEGER VAL1, INTEGER VAL2, INTEGER VAL3) INTEGER X, Y; FUNCTION MAIN() X = 1970; Y = 40; PRINT(“The result of (%d * %d)/25 = %d\n”, X, Y, MULDIV(X, Y, 25); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ SMAX Name: SMax Syntax: Description: Determine the maximum of two values based on a signed comparison. Parameters: VAL1 and VAL2 are both INTEGER values on which the test is performed. Return Value: The maximum of Val1, Val2 after a signed comparison is performed. Refer to “Signed vs.
Version: SIMPL+ Version 1.00 ® SIMPL+ INTEGER SMin(INTEGER VAL1, INTEGER VAL2) INTEGER X, Y; FUNCTION MAIN() X = SMIN(65535, 0); Y = SMIN(25, 26); Crestron SIMPL+ for a further explanation of how the Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ Random Number Functions Random Number Functions Overview These functions allow a SIMPL+ program to generate a random number. Random Name: Random Syntax: Description: Generate a random number. Refer to “Seed” on Parameters: LowerBound is an INTEGER specifying the lower end of the range.
An INTEGER from 0 to 65535. Example: Version: SIMPL+ Version 1.00 ® SIMPL+ INTEGER Rnd(); 211. INTEGER NUM; FUNCTION MAIN() NUM = RND(); PRINT(“The random number is: %d\n”, NUM); Crestron SIMPL+ page 213 and “Random” on Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ Seed Name: Seed Syntax: Description: Provides a seed or origin for the random number generator so that the numbers returned by RND and RANDOM are pseudo-random numbers. SEED is not required for generating random numbers as the random number generator will be seed with a default value.
NOTE: In the second form, the first argument may not be a variable containing 0, 1, 2. It must be the written as 0, 1, 2. Crestron is discouraging the use of the second form of MAKESTRING in favor of either the PRINT command or alternate methods for activating devices that do not require knowledge of Cresnet packets, which are subject to change.
Page 225
® Crestron SIMPL+ Example: Version: SIMPL+ Version 2.00 for Console, Cresnet, and CPU destinations. SIMPL+ Version 1.00 for everything else. Language Reference Guide - DOC. 5797G INTEGER X; STRING Z[100], OUT[100]; X=10; Z=”Hello”; FUNCTION MAIN() // Puts “This is a string” followed by a CRLF onto OUT.
Syntax: Description: The output of PRINT goes to the CONSOLE port of the control system and can be monitored in the Crestron Viewport. It can print simple text strings or complex formatted strings. Parameters: <Static Specification String> is a quoted string that contains text and formatting information.
Page 227
® Crestron SIMPL+ also checks to make sure the format specifier matches the type of the variable being used (i.e. if %d is used, the variable being used should be INTEGER type). NOTE: If no format specifiers are used, then a simple quoted text string is printed.
® Crestron SIMPL+ String Parsing & Manipulation Functions String Parsing and Manipulation Functions Overview String parsing and manipulation functions are used where the contents of string variables need to be examined or modified. ClearBuffer Name: ClearBuffer Syntax: Description: Deletes the contents of the specified buffer. If a LEN is done on the buffer after a CLEARBUFFER, the return value will be 0.
® Crestron SIMPL+ Gather Name: Gather Syntax: Description: Concatenates the data from SOURCESTRING and issues it on the return string when the specified delimiter has been reached. Note that when GATHER is executed, if SOURCESTRING does not include the DELIMITER, then the equivalent of a PROCESSLOGIC is performed.
Page 232
In the X-Generation Control Systems, the CHANGE event would be called both times. Version: SIMPL+ Version 2.00 ® SIMPL+ BUFFER_INPUT COM$[100]; DIGITAL_INPUT trig; STRING IN$[100]; CHANGE COM$ IN$ = GATHER(“\n”, COM$); PRINT(“The value of IN$ is %s\n”, IN$); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ GetC Name: GetC Syntax: Description: Returns the value at position 1 of SOURCE string and shifts the rest of the buffer up by one. In this way, values may be picked out of a buffer for processing.
® Crestron SIMPL+ Name: Syntax: Description: Returns the length of the actual string, not the declared maximum length. Parameters: SOURCE is a string whose length is to be determined. Return Value: A value from 0 - 65535, which gives the number of characters in the string. An empty string returns a length of 0.
In this example, if IN$ contains “This is a Test 123!”, then LOWER$ will contain “this is a test 123!”. Version: SIMPL+ Version 1.00 ® SIMPL+ STRING Lower(STRING SOURCE); STRING_INPUT IN$[100]; STRING LOWER$[100]; CHANGE IN$ LOWER$ = LOWER(IN$); PRINT(“Lowercase version of %s is %s\n”,IN$, LOWER$); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ Name: Syntax: Description: Returns a string NUM characters long from SOURCE, starting at position START. Parameters: SOURCE is a STRING containing the input string. START is an INTEGER telling MID at which character position in SOURCE to start.
® Crestron SIMPL+ REVERSEFIND Name: ReverseFind Syntax: Description: Finds the position in SOURCE_STRING where MATCH_STRING last occurs. Parameters: MATCH_STRING is a STRING containing the searched for data. SOURCE_STRING is a STRING containing the data to be searched. START_POSITION is an INTEGER which tells REVERSEFIND at what character in the string to start the search, and is 1 based.
® Crestron SIMPL+ SetString Name: SetString Syntax: Description: Overwrites the bytes in DESTINATION with the bytes in SOURCE starting at POSITION in the DESTINATION string. Parameters: DESTINATION is a STRING containing the string to be modified. POSITION is an INTEGER referencing the starting byte to write at in DESTINATION.
Page 242
This would result in DESTINATION containing the string “Space ABCD To Fill”. If the return code were used, it would contain 18 (the string length). Version: SIMPL+ Version 1.00 ® SIMPL+ STRING DESTINATION$[100]; DESTINATION$ = :\”Space XXXX To Fill”; SETSTRING(“ABCD”, 7, DESTINATION$); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ Upper Name: Upper Syntax: Description: Takes a source string and converts characters with the values a-z (lowercase) to A-Z (uppercase). Parameters: SOURCE is a string to be converted to uppercase. SOURCE is not modified, unless it is also used as the return value, e.g., S$=UPPER(S$);...
® Crestron SIMPL+ ProcessLogic Name: ProcessLogic Syntax: Description: Forces a task switch away from the current SIMPL+ module, so that the SIMPL Windows program can process the outputs of the SIMPL+ module. Refer to the discussion on Task Switching on Parameters: None.
This will execute immediately and output a pulse of 5.25 seconds to the digital output OutputToPulse. Version: SIMPL+ Version 1.00 ® SIMPL+ Pulse(TIME, DIGITAL_OUTPUT OUT); // A pulse of 525 hundredths of a second or 5.25 seconds #define_constant MY_PULSE_TIME 525 DIGITAL_OUTPUT OutputToPulse; PULSE(MY_PULSE_TIME, OutputToPulse); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ TerminateEvent Name: TerminateEvent Syntax: Description: Exits a CHANGE, PUSH, or RELEASE event. It may also be used to exit a loop in the main() function if desired. TERMINATEEVENT cannot be used inside of a function. Example: In this example, the CHANGE event will terminate if the ANALOG_INPUT Y equals the value of 69.
216 for a list and description of valid Format Specifiers. Function MyFunc() STRING sNotice; sNotice = "Projector"; GenerateUserNotice( "The %s bulb has a total of %d hours", sNotice, 500 ); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ GenerateUserWarning Name: GenerateUserWarning Syntax: Description: Places a warning message into the control system's error log Parameters: <Static Specification String> is a quoted string that contains text and formatting information. Format specifiers are of the form: %[[Pad]Width]specifier Refer to Return Value: None.
“Print” on page 216 for a list and description of valid Format Specifiers. Function MyFunc() STRING sError; sError = "Projector"; GenerateUserError( "The %s bulb has exceeded %d hours", sError, 1000 ); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ CheckForNVRAMDisk Name: CheckForNVRAMDisk Syntax: Description: Tests whether or not an NVRam Disk is currently installed in the control system. Parameters: None. Return Value: Returns 1 if an NVRam Disk is currently installed in the control system. Example:...
Example: This would print a string such as “The date is 03/25/2002”. Version: SIMPL+ Version 1.00 ® SIMPL+ STRING Date(INTEGER FORMAT); STRING TheDate$[100]; FUNCTION MAIN() TheDate$=DATE(1); PRINT(“The date is %s\n”, TheDate$); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ Name: Syntax: Description: Returns the day of the week as a STRING. Parameters: None. Return Value: The day of the week is returned in a string. Valid returns are Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, or Saturday.
An example output of this would be “The current day of the month is 25”. Version: SIMPL+ Version 1.00 ® SIMPL+ INTEGER GetDateNum(); INTEGER NumDateOfMonth; FUNCTION MAIN() NumDateOfMonth = GetDateNum(); PRINT(“The current day of the month is %d\n”, NumDateOfMonth); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ GETDAYOFWEEKNUM Name: GetDayOfWeekNum Syntax: Description: Returns an integer corresponding to the current day of the week. Parameters: None. Return Value: The day of the week as an integer from 0 to 6; 0 represents Sunday to 6 representing Saturday.
An example output of this would be “The Number of hours on the clock is 22”. Version: SIMPL+ Version 1.00 ® SIMPL+ INTEGER GetHourNum(); INTEGER NumHours; FUNCTION MAIN() NumHours = GetHourNum(); PRINT(“The Number of hours on the clock is %d\n”, NumHours); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ GETHSECONDS Name: GetHSeconds Syntax: Description: Returns an integer corresponding to the number of hundredths of a second based on the system clock. Typically, this function could be used for very fine timing, to determine if a specific amount of time has elapsed.
An example output of this would be “The Number of minutes on the clock is 33”. Version: SIMPL+ Version 1.00 ® SIMPL+ INTEGER GetMinutesNum(); INTEGER NumMinutes; FUNCTION MAIN() NumMinutes = GetMinutesNum(); PRINT(“The Number of minutes on the clock is %d\n”, NumMinutes); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ GETMONTHNUM Name: GetMonthNum Syntax: Description: Returns an integer corresponding to the current month of the year. Parameters: None. Return Value: The month of the year as an integer from 1 to 12. Example: An example output of this would be “The current month of the year is 9”.
An example output of this would be “The Number of seconds on the clock is 25”. Version: SIMPL+ Version 1.00 ® SIMPL+ INTEGER GetSecondsNum(); INTEGER NumSeconds; FUNCTION MAIN() NumSeconds = GetSecondsNum(); PRINT(“The Number of seconds on the clock is %d\n”, NumSeconds); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ GETTICKS Name: GetTicks Syntax: Description: Returns an integer corresponding to the number of system ticks. Each tick is 1/112.5 seconds on an X-generation control system, or 0.01 seconds on a 2-series control system. Typically, this function could be used for very fine timing, to determine if a specific amount of time has elapsed.
An example output from this would be “The current year is 1999”. Version: SIMPL+ Version 1.00 ® SIMPL+ INTEGER GetYearNum(); INTEGER NumYear; FUNCTION MAIN() NumYear = GetYearNum(); PRINT(“The current year is %d\n”, NumYear); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ MONTH Name: Month Syntax: Description: Returns the current month as a string. Parameters: None. Return Value: The current month is returned in a string. Valid returns are January, February, March, April, May, June, July, August, September, October, November, or December.
® Crestron SIMPL+ SETDATE Name: SetDate Syntax: Description: Sets the system date. Parameters: MONTH is an integer containing the month to which the date is set. A valid range is 1 through 12, corresponding to January through December. DAY is an integer containing the day of the month to which the date is set. The range varies from month to month, but always starts at 1.
Example: An example output from this would be “The Time is 14:25:32”. Version: SIMPL+ Version 1.00 ® SIMPL+ STRING TIME(); STRING TheTime$[100]; FUNCTION MAIN() TheTime$=TIME(); PRINT(“The Time is %s\n”, TheTime$); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ Software Wait Events Wait Events Overview When writing a SIMPL+ program, it is often desirable to have an event that will be processed a predetermined amount of time after it is triggered. The WAIT event allows a block of code to be executed after a specified amount of time. There are related functions which allow WAITS to be paused, resumed, cancelled, or have their times changed.
® Crestron SIMPL+ CancelWait Name: CancelWait Syntax: Description: Cancels a specified named WAIT event in the current SIMPL+ program. When an event is cancelled, it is removed from the wait list and will not activate. There is no effect if the wait event has finished running.
® Crestron SIMPL+ PauseWait Name: PauseWait Syntax: Description: Pauses a specified named WAIT event in the current SIMPL+ program. When an event is paused, the timer for it freezes and may later be resumed, retimed, or cancelled. When a wait is resumed, it executes the remaining time from when it was paused until the defined wait time.
Page 272
SecondWait will have 15-seconds more to execute. Version: SIMPL+ Version 1.00 ® SIMPL+ ResumeAllWait(); DIGITAL_INPUT Trig, PauseWaits, ResumeWaits; PUSH Trig WAIT(1000, FirstWait) PRINT(“Wait 1 Triggered!\n”); WAIT(2000, SecondWait) PRINT(“Wait 2 Triggered!\n”; PUSH PauseWaits PauseAllWait(); PUSH ResumeWaits ResumeAllWaits(); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
Page 273
® Crestron SIMPL+ ResumeWait Name: ResumeWait Syntax: Description: Resumes the specified named WAIT event in the current SIMPL+ program that has been previously paused. The WAIT will execute from the time when it was paused until the specified wait time has elapsed.
® Crestron SIMPL+ Wait Name: Wait Syntax: Description: NOTE: There is no semicolon after a WAIT statement because it has a clause or block following it. Adds an event to a list to be executed in TIME hundredths of a second. Giving a WAIT a name is optional, but to cancel, pause, resume, or retime a wait, a name must be specified.
Page 276
( 1 ) // statements (will keep executing during the wait statement) Wait( 500 ) // statements (execute once for each wait statement occurence) // statements (will keep executing during the wait statement) Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ User Defined Functions User Defined Functions Overview A SIMPL+ program may have functions that are defined by users. Typically, a function is defined to modularize code to make repetitive tasks easier to perform or make code easier to read.
The function refers to the passed variable as <variable_name>. Note that for a one- dimensional array, the syntax is <variable_name>[] and for a two-dimensional array the syntax is <variable_name>[][]. ® SIMPL+ [ByRef | ByVal] <INTEGER | LONG_INTEGER | SIGNED_INTEGER | SIGNED_LONG_INTEGER | STRUCTURE> <variable_name> Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ ByRef, ByVal, ReadOnlyByRef NOTE: Passing STRINGs with BYVAL an BYREF is not allowed in the 2-Series Control System. All STRINGs are passed by referenced in the 2-Series Control System. NOTE: Passing I/O datatype variables (DIGITAL_INPUT, ANALOG_INPUT and STRING_INPUT) is not allowed in the 2-Series Control System.
Page 280
SIGNED_LONG_INTEGER SIGNED_LONG_INTEGER array SIGNED_LONG_INTEGER array element STRING STRING array STRING array element STRING_INPUT STRING_INPUT array STRING_INPUT array element STRING_OUTPUT ® SIMPL+ Crestron SIMPL+ ByVal ByRef ReadOnlyByRef [LOCAL [SOURCE] COPY] R, W R, (E1) R, (E1) R, W R, W R, W...
Page 281
® Crestron SIMPL+ VARIABLE TYPE STRING_OUTPUT array STRING_OUTPUT array element STRUCTURE STRUCTURE element (INTEGER) STRUCTURE element (LONG_INTEGER) STRUCTURE element (SIGNED_INTEGER) STRUCTURE element (SIGNED_LONG_INTEGER) STRUCTURE element (STRING) R: Read access allowed. W: Write access allowed. (E1): Generates a RunTime Error, not allowed to be write to INPUT values. The ReadOnlyByRef generates a compile error instead of a RunTime Error.
® Crestron SIMPL+ Function Libraries NOTE: A function may be placed in the same body of code as the caller. In some cases, the same function needs to be used across several different modules. Although the code could be rewritten in all modules (as was the case with SIMPL+ Version 1.00), SIMPL+ Version 2.00 supports function libraries.
2. Input/Output definitions From/To a SIMPL Program 3. Global declarations for the module, including STRING, INTEGER, arrays, structures, etc. 4. FUNCTION declarations 5. PUSH/RELEASE/CHANGE statements 6. FUNCTION MAIN FUNCTION MAIN() MyVar=0; For(I=1 to 10) B[I] = I; Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
Common Runtime Errors Overview The following errors will occur at runtime. In order for these error messages to be seen, the Crestron Viewport must be open and communications with the control system (via Ethernet or the computer port) must be established.
Page 288
200 bytes. If this message is received, reduce the number of variables. If string or buffers have been declared overly large, this is an easy place to reduce memory requirements. ® SIMPL+ Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ Software Example Programs Example 1: Hello, World! // A digital input from the SIMPL program DIGITAL_INPUT TRIG; // Upon the digital signal TRIG going high or low, the Hello, // World! message is printed. CHANGE TRIG PRINT(“Hello, World!\n”);...
Software Crestron SIMPL+ ® Example 2: 8-Level switch on a Pesa switcher #SYMBOL_NAME “Pesa Switcher - 8 Levels” #HINT “Creates Pesa CPU-Link H command for Switching” ************************************************************ ****** DIGITAL, ANALOG and SERIAL INPUTS and OUTPUTS ************************************************************ ******/ // Digital trigger from the SIMPL program - this sends the command // string out.
Page 291
® Crestron SIMPL+ Software // temporary buffer. A Command looks like H{out}{l1}{l2}...{l8} // {2 byte checksum}{CR}{LF} where {out} and {l1}..{l8} are 3 // digit ASCII bytes with leading zeros. An example is // H001001002003004005006007008{2 bytes checksum}{CR}{LF} makestring(PESABUF,”H%03d%03d%03d%03d%03d%03d%03d%03d%03d”, // OUTPUT, LEVEL1, LEVEL2, LEVEL3, LEVEL4, LEVEL5, LEVEL6, // LEVEL7, LEVEL8);...
CASE( 6): Days = 30; // June CASE( 9): Days = 30; // September CASE(11): Days = 30; // November Default: Days = 31; // All others Return(Days); CHANGE MONTH DAYS = ComputeDaysInMonth(MONTH); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ Example 4: Computing the Number of Days in a Month (Using Function Libraries) The following code would be saved as, in this example, “My Function Library.USL”. The following code can be saved as any filename: Language Reference Guide - DOC. 5797G...
Page 294
Number of bytes written to the file. If the return value is negative, it is an error code. ® SIMPL+ SIGNED_INTEGER WriteLongIntegerArray ( INTEGER file_handle, LONG_INTEGER ilArray[m][n] ) Crestron SIMPL+ for a discussion of when to use this Language Reference Guide - DOC. 5797G ®...
Page 295
® Crestron SIMPL+ Example: (Refer to "File Functions Overview"on page 116) Version: SIMPL+ Version 3.01 or higher (Pro 2 only) Control System: 2-Series Only Language Reference Guide - DOC. 5797G INTEGER nFileHandle, iErrorCode; LONG_INTEGER ilArray[10]; nFileHandle = FileOpen ( “MyFile”, _O_RDONLY );...
Page 297
® Crestron SIMPL+ CATEGORY NUMBER MESSAGE TEXT Declaration 1300 Array size missing Errors Array size invalid 1301 Invalid array index 1302 Variable name, ‘<identifier>’, exceeds maximum length of <max> characters 1303 Declaration type not allowed within structure: '<identifier>' Structure cannot contain String Arrays or Structure variables: Structure...
Page 298
'TerminateEvent' statement will only terminate current Wait statement's function scope 1802 #CATEGORY_NAME defined more than once. Using: #CATEGORY_NAME "<number>" 1803 Possible data loss: LONG_INTEGER to INTEGER assignment ® SIMPL+ Crestron SIMPL+ PAGE page 326 page 326 page 327 page 328 page 329 page 329 page 330...
® Crestron SIMPL+ Syntax Errors (Compiler Errors 1000 to 1013) Compiler Error 1000 syntax error: '<identifier>' already defined The specified identifier was declared more than once. A variable can only be declared once within it’s function scope. The same identifier cannot be used for more than one declaration type.
( x = 4 ) return 5; // error – should be return (5); return (6); // ok Crestron SIMPL+ structure definition not specified should be Print (“abc” ); next statement statement Language Reference Guide - DOC. 5797G...
® Crestron SIMPL+ Compiler Error 1003 syntax error: Incorrect type '<decl_type>', expected type(s): '<decl_type1[,decl_type2] [,decl_typen]>' Incorrect type, expected type(s): '<decl_type1[,decl_type2][,decl_typen]>' A specific variable or type was expected and not found. Examples are variables of one type being used in place of another, and incorrect variable types within function arguments.
#DEFINE_CONSTANT MyVarConst substitutions are #DEFINE_CONSTANT MyExprConst are not #DEFINE_CONSTANT MyFuncConst #DEFINE_CONSTANT MyFuncConst Crestron SIMPL+ // ok // error – MyIntConst be in quotes – this will be evaluated as a literal string // ok “abc” // ok (1+2) // error – expressions not allowed // error –...
® Crestron SIMPL+ Compiler Error 1007 syntax error: Missing array index: '<identifier>' A variable declared as an array is being used within an expression without the array index being specified. For two-dimensional arrays, both indices must be specified. When passing entire arrays as function arguments, no index is needed.
// error – ‘j’ has not been declared x = j; for ( s = “a” to “z” ) // error – strings are not allowed Crestron SIMPL+ // ok // error – should be struct.x = j; Language Reference Guide - DOC. 5797G...
® Crestron SIMPL+ Compiler Error 1009 syntax error: Missing structure member: '<identifier>' Variables contained within structures are required when using structures within an expression or statement. When using structures, the ‘dot’ notation is required to specify a structure’s variable. The notation is as follows: <structure_name>.<member_variable>...
// ok else if ( x=3 ) return (); // error – no value or expression is given return (x); // ok Crestron SIMPL+ // ok // ok // error cannot return a value and must return a value Language Reference Guide - DOC. 5797G...
® Crestron SIMPL+ Compiler Error 1012 syntax error: Unterminated string constant A literal string was used and was not contained within quotes. If a quotation character is needed within a literal string, a backslash should be placed before the quotation character (i.e.: \). This will indicate to the compiler that the quotation character is not the terminating quote for the literal string.
// construct (i.e.: if-else, while, etc) INTEGER x; INTEGER y; Print( “outside of everything” ); // error – statement is FUNCTION MyFunc() Crestron SIMPL+ // ok 2; // error – semicolon is not another function or event does nothing), and is not contained...
® Crestron SIMPL+ Compiler Error 1101 fatal error: Abort - Error count exceeded <max_errors> When compiling, if the error count is too large, the compiler will terminate the compile process prematurely. This can not only be a tremendous time saver, but also help reduce the aggravation and stress levels of the programmer.
Page 312
( str = MyFunc(1) ) while ( str < “abc” ) // ok x = (x + ); break; return (1); Crestron SIMPL+ // ok // error – cannot add an integer and string // error – cannot compare an and string // error –...
® Crestron SIMPL+ Compiler Error 1201 expression error: Invalid \\x sequence A hexadecimal sequence within a literal string contained an invalid format. Characters represented by a hexadecimal number must follow the format: \xXX, where ‘\x’ signifies that a hexadecimal sequence is to follow and XX is the 2 digit hexadecimal value.
STRING str[myFunc()]; FUNCTION myFunc( STRING sArg, STRING sArgArr[] ) // Crestron SIMPL+ // ok – str has a length of 100 // ok – strIn has a length of // ok – bufIn has a length of // ok – 51 strings of length 100 // ok - 51 strings of length // ok –...
® Crestron SIMPL+ Compiler Error 1301 declaration error: Invalid array index An index is required when accessing any element of an array. Two dimensional arrays require both indices of the array to be specified. This index must be a valid numeric expression.
Call MyStrFunc( str, strArr ); str[1] = “a”; // error – s is a string, not an array sLocal = str[1]; // error – individual characters within maximum length of <max> characters Crestron SIMPL+ arrays are passed by reference // ok // ok...
® Crestron SIMPL+ Compiler Error 1303 declaration error: Declaration type not allowed within Structure datatypes can only be defined globally. Variables of a defined structure datatype may be declared both globally and locally and passed as function arguments. INTEGER, LONG_INTEGER, SIGNED_INTEGER, SIGNED_LONG_INTEGER and STRING are the only SIMPL+ datatypes allowed to be used as structure member fields.
// error – if-statement block cannot FUNCTION MyFunc() // ok – MyFunc is global FUNCTION MyLocalFunc() // error – MyLocalFunc is local to MyFunc Crestron SIMPL+ // ok // ok // error contain local variables Language Reference Guide - DOC. 5797G...
® Crestron SIMPL+ Compiler Error 1306 declaration error: Declaration type can only be used globally: I/O declarations must be defined globally; they cannot be declared as local variables inside of a function or library file. The following are examples of this error: Language Reference Guide - DOC.
® Crestron SIMPL+ Compiler Error 1308 declaration error: Global variable declaration cannot be I/O declarations and global variables can only be defined in a SIMPL+ module (.usp file). Libraries files (.usl files) are files that only contain functions. Local functions variables, function arguments and function that return values are permitted within library files.
#DEFAULT_VOLATILE // error – global variables have already been FUNCTION MyFunc() //////////////////////////////////////////////////////////// ////// // Example 3 #DEFAULT_VOLATILE // ok – compiler directive exists before Crestron SIMPL+ all global variables declared within this module Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ Compiler Error 1310 declaration error: Compiler directive cannot be in function Compiler directives cannot be used locally within functions. They can only be used at a global level and the directive applies to the entire SIMPL+ module.
CancelWait( AnotherWaitLabel ); // ok PauseWait( MyWaitLabel ); ResumeWait( MyFunc ); valid ResumeWait( someLabel ); not exist Crestron SIMPL+ // ok // error – MyWaitLabel has not been declared yet // ok – Label is not required // ok – MyWaitLabel is unique // error –...
® Crestron SIMPL+ Compiler Error 1312 declaration error: Array boundary exceeded maximum size The maximum number of indices for an array is 65535. The following are examples of this error: Compiler Error 1313 declaration error: Minimum array size invalid The minimum array size cannot exceed the total size of the array. The minimum array size must be between 1 and the total size of the array.
ANALOG_INPUT anlgIn2[10,5]; // ok – no other ANALOG_INPUT has been array size INTEGER x[10]; INTEGER y[10,5]; // error – INTEGER is not an Input or Crestron SIMPL+ // ok // ok – minimum size is 5 variable, digIn2, has already been declared with a minimum array size...
® Crestron SIMPL+ Assignment Errors (Compiler Errors 1400 to 1402) Compiler Error 1400 assignment error: Illegal Assignment Assignments in SIMPL+ require that the value being assigned to a variable must equate to the same type as that variable. Integer variables can only be assigned integer values and string variables can only be assigned a string value.
Print( “str = %s”, str ); written Print( “sOut = %s”, sOut ); // error – the value of sOut is unknown Crestron SIMPL+ // ok // ok – STRINGs can be read and Language Reference Guide - DOC. 5797G...
® Crestron SIMPL+ Function Argument Errors (Compiler Errors 1500 to 1508) Compiler Error 1500 function argument error: Argument <arg_num> cannot be A variable was being passed that can either only have a value assigned to it, or it’s value be copied into another variable or used within an expression. An example of this is trying to pass a STRING_INPUT variable as a function argument;...
FUNCTION MyFunc( ByVal STRING strArr[] ) cannot be FUNCTION MyFunc( ByVal INTEGER intArr[][] ) // error – arrays cannot be FUNCTION MyFunc( ByVal STRING strArr[][] ) cannot be Crestron SIMPL+ // ok cannot be passed by reference // error – arrays passed by value // error –...
® Crestron SIMPL+ Compiler Error 1502 function argument error: Function contains incomplete When calling a functions that contain parameter lists, the number of arguments passed to the function must match the number of parameters defined for that function. The following are examples of this error:...
Print( “My name is %s. My age is %d”, “David” ); error – // %d format specifier does not have a Crestron SIMPL+ or Output signal // error – ‘i’ is not or Output signal // error – ‘5’ is not or Output signal My age is %d”, str, x );...
® Crestron SIMPL+ Compiler Error 1505 function argument error: Format string contains invalid An invalid format specifier was used within a format string. Format strings contain specifications that determine the output format for the arguments. The format argument consists of ordinary characters, escape sequences, and (if arguments follow format) format specifications Format Specifications always begin with a percent sign (%) and are read left to right.
® Crestron SIMPL+ Compiler Error 1508 function argument error: I/O variable cannot be passed to Read file functions (ReadInteger, ReadString, etc.) cannot contain Input or Output variables for the function’s resulting read buffer. The following are examples of this error: Language Reference Guide - DOC.
CSwitch( x ) case (1): // ok – 1 has not been used yet case (2): // ok – 2 has not been used yet Crestron SIMPL+ // ok // error – Main() cannot a value a parameter list Language Reference Guide - DOC. 5797G...
® Crestron SIMPL+ Compiler Error 1602 construct error: Switch statement contains 'default' without The Switch and CSwitch constructs must contain ‘case’ statements if the ‘default’ statement is to be used. The ‘default’ statement is optional. The following are examples of this error: Language Reference Guide - DOC.
// error – the category number should #CATEGORY 99 #DEFINE_CONSTANT MyCategory 6 #CATEGORY MyCategory category Crestron SIMPL+ // ok – “6” is the category number for Lighting // error – the category number, should be used instead of the category symbol name be enclosed in quotation marks // error –...
® Crestron SIMPL+ Compiler Error 1604 construct error: 'EVENT' already has a body The EVENT statement can only be defined once per SIMPL+ module. A previously defined definition of EVENT was already encountered by the compiler. The following are examples of this error:...
// ok } until (1); if (1) break; // error – break cannot exist within an ‘if’ statement EVENT break; // error – TerminateEvent should be used instead Crestron SIMPL+ an event function Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ Compiler Error 1607 construct error: GetLastModifiedArrayIndex may return an ambiguous signal index If an event function (EVENT, PUSH, CHANGE, RELEASE) is acting on more than one input array signal, the specific array will not be able to be determined based on the index returned from GetLastModifiedArrayIndex().
• Make sure the latest version of the Crestron Database is installed. • Make sure the path for the Crestron Database and User SIMPL+ files have been specified within SIMPL Windows. • Make sure the file does not exist with a Read-Only attribute.
® Crestron SIMPL+ Compiler Warnings (Compiler Errors 1800 to 1803) Compiler Warning 1800 compiler warning: 'Return' statement will only terminate A ‘Return’ statement within a Wait Statement’s block of code will cause the Wait Statement to terminate. It will NOT terminate the current function that the Wait Statement resides within.
#CATEGORY “1” #CATEGORY “2” FUNCTION MyFunc() #CATEGORY “3” // this is the resulting category number // for this SIMPL+ module FUNCTION AnotherFunc() Crestron SIMPL+ the Wait Statent, MyLabel2. MyLabel1 will continue to execute Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ Compiler Warning 1803 compiler warning: Possible data loss: LONG_INTEGER to A LONG_INTEGER result was assigned to an INTEGER variable or passed to a function for an INTEGER parameter. The 32-bit LONG_INTEGER will be truncated to 16-bit value and assigned to the integer, resulting in a loss of data.
Software SIMPL+ Revisions For the latest revisions to SIMPL Windows, refer to the release notes installed with the program. This can be accessed in the Start Menu, under Programs | Crestron | SIMPL Windows ® SIMPL+ Crestron SIMPL+ Language Reference Guide - DOC. 5797G...
CIPID is an INTEGER containing the ID of the CIP device to query. JOIN_NUMBER is an INTEGER containing the Join number to get the status. For touchpanels, the join number is identical to the press/feedback number. For other devices, contact Crestron customer service. TYPE is one of several predefined constants: din:...
CRESNET_ID is an INTEGER containing the ID of the Cresnet Network device to query. JOIN_NUMBER is an INTEGER containing the Join number to get the status. For touchpanels, the join number is identical to the press/feedback number. For other devices, contact Crestron customer service. ® SIMPL+ SetSlot(1,2,dout) = GetCIP(0x03,18,din);...
® Crestron SIMPL+ TYPE is one of several predefined constants: din: ain: dout: aout: NOTE: Access to serial signals is not supported. Return Value: An Integer. For Digital values, a non-zero value indicates a logic high and a 0 value indicates a logic low.
Digital inputs from device (symbol output list) Analog inputs from device (symbol output list) Digital outputs to device (symbol input list) Analog outputs to device (symbol input list) SetSlot(1,2,dout) = GetSlot(2,1,din); INTEGER IsSignalDefined <input/output signal>; Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ Description: Retrieves the current SIMPL signal number associated with a particular input or output. This is generally used to determine if a particular input or output on a gate is being used, and generally used with arrayed inputs or outputs. This can be used to build a gate of a predetermined maximum size, and allow the user to add and subtract signals on the input or output of the gate (i.e., the program would be written to iterate...
SIMPL Windows symbol “Send Message to CPU (Speedkey: TMSG).” This function is not used in general programming. Parameters: PACKET is a string containing the command to send to the CPU. Return Value: None. ® SIMPL+ SendCresnetPacket(“\xFF\x03\x02”); SendPacketToCPU(STRING PACKET); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
This example will turn the Super Debugger on, which shows all network transitions on the console port of the control system. This command would normally be typed in manually through the Crestron Viewport, since it is for debugging only. Version: SIMPL+ Version 2.00...
Digital inputs from device (symbol output list) Analog inputs from device (symbol output list) Digital outputs to device (symbol input list) Analog outputs to device (symbol input list) SetCresnet(0x07,69,dout) = GetCresnet(0x07,42,din); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ Control System: X-Generation only SetSlot Name: SetSlot Syntax: Description: Sets the state of the join number on a particular card slot. Note that the device must be defined in SIMPL Windows and the join number to use must have a signal tied to it for this function to work.
Page 356
Here, SIG1 and SIG2 still reference Join #1 and Join #2, but SIG3 has been changed to reference Join #20, and SIG4 references Join #21. Version: SIMPL+ Version 2.00 ® SIMPL+ #ANALOG_INPUT_JOIN<constant> ANALOG_INPUT SIG1, SIG2, SIG3, SIG4; ANALOG_INPUT SIG1, SIG2; #ANALOG_INPUT_JOIN 20 ANALOG_INPUT SIG3, SIG4; Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ #ANALOG_OUTPUT_JOIN Name: #ANALOG_OUTPUT_JOIN Syntax: Description: Changes the join number starting with the next ANALOG_OUTPUT definition to the join number specified by <constant>. Example: In this example, SIG1 references Join #1, SIG2 references Join #2, SIG3 references Join #3, and SIG4 references Join #4.
® Crestron SIMPL+ Description: Changes the join number starting with the next STRING_INPUT or BUFFER_INPUT definition to the join number specified by <constant>. Example: In this example, SIG1 references Join #1, SIG2 references Join #2, SIG3 references Join #3, SIG4 references Join #4, and B1$ references Join#5.
It is treated the same as a DIGITAL_OUTPUT. Example: Version: SIMPL+ Version 2.00 ® SIMPL+ _OEM_BREAK = <expression>; _OEM_BREAK = 1; // Generate A Short Break Crestron SIMPL+ // Write to Variable Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ _OEM_CD Name: _OEM_CD Syntax: Any expression that can use a variable as part of its contents. Description: This variable is treated as a DIGITAL_INPUT and may be read from only. CD is the acronym for Carrier Detect. When a modem is hooked up to an RS-232 port and a connection (carrier) is made, the modem typically drives this pin high to let the connected hardware know that a data connection is present.
The above example will pulse the DTR pin for 5-seconds when the CTS line goes high. Version: SIMPL+ Version 2.00 ® SIMPL+ PUSH _OEM_CTS PRINT(“CTS Pin has gone high!\n”); _OEM_DTR = <value>; PUSH _OEM_CTS PULSE(500, _OEM_DTR); Crestron SIMPL+ Language Reference Guide - DOC. 5797G ®...
® Crestron SIMPL+ _OEM_LONG_BREAK Name: _OEM_LONG_BREAK Syntax: or any expression that can use a variable as part of its contents. Description: When set to a non-zero value, causes the start of a break being transmitted on the port. A break is continuous logic low being generated on the port. In order to stop break generation, the variable should be set to 0.
® Crestron SIMPL+ _OEM_RTS Name: _OEM_RTS Syntax: or any expression that can use a variable as part of its contents. Description: This variable is treated the same as DIGITAL_OUTPUT. In a program where hardware handshaking is not being used, the program may control the RTS pin for its own application.
This Agreement may only be modified by a writing signed by an autho- rized 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, communica- tions or advertising relating to the Software.
Page 372
(90) days from the date of receipt, and (b) that any hardware accompanying the Software will be subject to its own lim- ited warranty as stated in its accompanying written material. Crestron shall, at its option, repair or replace or refund the license fee for any Software found defective by Crestron if notified by you within the warranty period.
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 dam- age, modification, or improper installation procedures.
Page 374
Crestron Electronics, Inc. Language Reference Guide – DOC. 5797G 15 Volvo Drive Rockleigh, NJ 07647 04.03 Tel: 888.CRESTRON Fax: 201.767.7576 Specifications subject to www.crestron.com change without notice...
Need help?
Do you have a question about the SIMPL+ and is the answer not in the manual?
Questions and answers