Language Reference Guide - DOC. 5797GContents z vii
Software Crestron SIMPL+
®
This page intentionally left blank.
viii z ContentsLanguage Reference Guide - DOC. 5797G
Crestron SIMPL+
®
Introduction
SIMPL+® is a language extension that enhances SIMPL Windows by using a
procedural “C-like” language to code elements of the program that were difficult, or
impossible, with SIMPL alone. This help system provides specific information about
the SIMPL+ language syntax, and can be used as a reference manual.
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
Software Requirements
SIMPL+ has several versions. Earlier versions of SIMPL+ do not contain features
and constructs found in later revisions. Each version of SIMPL+ requires a minimum
revisions of SIMPL Windows and Control System Update (UPZ or, for 2-Series
control systems, CUZ) files. The specifications are listed below.
Software Requirements
SIMPL+ VERSIONMINIMUM SIMPL WINDOWS REQUIREDMINIMUM UPZMINIMUM CUZ
Version 1.001.30.015.04.11N/A
Version 2.001.40.025.10.00N/A
Version 3.002.00N/A1.00
Language Reference Guide - DOC. 5797G SIMPL+® z 1
Software Crestron SIMPL+
Licensing of SIMPL+ Cross Compiler
Crestron SIMPL+ Cross-Compiler Version 1.1 is simply an Installshield-installed version of the Coldfire GNU C
Compiler, which 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.
It includes and references code that is available from www.cygwin.com/cvs.html
Some files are deleted by the Installshield procedure which are not necessary for general use of the C compiler, in order to
save space on user PCs. But it is an unmodified version of this code. The original executables and the source code for them
can be obtained from the authors at the above sites
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. They also include GNU utilities, which are copyrighted by the Free
Software Foundation.
Other Crestron software simply executes this code as a separate executable, and does not incorporate GNU source code into
Crestron software. Crestron's standard licensing agreement does not apply to this software; only the license described here
applies.
®
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.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Refer to the GNU General Public
License for more details.
You should have received a copy of the GNU General Public License along with this program (it is appended to this
document for your convenience); if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
The text for the license agreement below is also available from www.gnu.org/copyleft/gpl.html
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
PREAMBLE
The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU
General Public License is intended to guarantee your freedom to share and change free software--to make sure the software
is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any
other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU
Library General Public License instead.) You can apply it to your programs, too.
2 z SIMPL+
®
Language Reference Guide - DOC. 5797G
Crestron SIMPL+
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make
sure that you have the freedom to distribute copies of free software (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.
To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender
the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you
modify it.
For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the
rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these
terms so they know their rights.
We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal
permission to copy, distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for
this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they
have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.
Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a
free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have
made it clear that any patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and modification follow.
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
®
Software
0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may
be distributed under the terms of this General Public License. The “Program”, below, refers to any such program or work,
and a “work based on the Program” means either the Program or any derivative work under copyright law: that is to say, a
work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in the term “modification”.) Each licensee is addressed as
“you”.
Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The
act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a
work based on the Program (independent of having been made by running the Program). Whether that is true depends on
what the Program does.
1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided
that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty;
keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the
Program a copy of this License along with the Program.
You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in
exchange for a fee.
2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program,
and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of
these conditions:
a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any
change.
b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program
or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.
c) If the modified program normally reads commands interactively when run, you must cause it, when started running for
such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright
notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute
the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program
Language Reference Guide - DOC. 5797G SIMPL+® z 3
Software Crestron SIMPL+
itself is interactive but does not normally print such an announcement, your work based on the Program is not required to
print an announcement.)
These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the
Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms,
do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as
part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License,
whose permissions for other licensee is extend to the entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the
intent is to exercise the right to control the distribution of derivative or collective works based on the Program.
In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the
Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this Licens e .
3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the
terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to
be distributed under the terms of 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.)
®
The source code for a work means the preferred form of the work for making modifications to it. For an executable work,
complete source code means all the source code for all modules it contains, plus any associated interface definition files,
plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source
code distributed need not include anything that is normally distributed (in either source or binary form) wi th the major
components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering access to copy from a designated place, then offering
equivalent access to copy the source code from the same place counts as distribution of the source code, even though third
parties are not compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights
under this License. However, parties who have received copies, or rights, from you under this License will not have their
licenses terminated so long as such parties remain in full compliance.
5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission
to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this
License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your
acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or
works based on it.
6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license
from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not
impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing
compliance by third parties to this License.
7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent
issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of
this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy
simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not
4 z SIMPL+
®
Language Reference Guide - DOC. 5797G
Crestron SIMPL+
distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program
by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this
License would be to refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section
is intended to apply and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity
of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system,
which is implemented by public license practices. Many people have made generous contributions to the wide range of
software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to
decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted
interfaces, the original copyright holder who places the Program under this License may add an explicit geographical
distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time.
Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or
concerns.
Each version is given a distinguishing version number. If the Program specifies a version number of this License which
applies to it and “any later version”, you have the option of following the terms and conditions either of that version or of
any later version published by the Free Software Foundation. If the Program does not specify a version number of this
License, you may choose any version ever published by the Free Software Foundation.
10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different,
write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the
Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of
preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software
generally.
®
Software
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE
PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN
WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS”
WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD
THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY
COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE
PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL,
SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED
INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO
OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED
OF THE POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
Language Reference Guide - DOC. 5797G SIMPL+® z 5
Software Crestron SIMPL+
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this
is to make it free software that everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most
effectively convey the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where
the full notice is found.
One line to give the program's name and an idea of what it does.
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.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Refer to the GNU General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
®
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of
course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks
or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your school, if any, to sign a “copyright disclaimer”
for the program, if necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright
interest in the program `Gnomovision'
written by James Hacker.
signature of Ty Coon, 1 April 2002
Ty Coon, Vice President
This General Public License does not permit incorporating your program into proprietary programs. If your program is a
subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what
you want to do, use the GNU Library General Public License instead of this License.
FSF & GNU inquiries & questions to gnu@gnu.org.
6 z SIMPL+
®
Language Reference Guide - DOC. 5797G
Crestron SIMPL+
®
Software
What's New
Converting from an X-Generation to a 2-Series Target
Select 2-Series Target within SIMPL+ environment (From the SIMPL+
•
application menu, select Build | 2-Series Control System Target. The XGeneration Target may be deselected if no longer needed).
Recompile the SIMPL+ program.
•
X-Generation Target and 2-Series Target Differences
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.
The following functions are no longer available in the 2-Series Control System:
While running SIMPL Windows, select File | New SIMPL+ and the SIMPL+
programming environment appears. This section describes the environment for
SIMPL+ Version 3.00.
The SIMPL+ Module Information template is filled with commented code that makes
it easy to remember the language syntax and structure. Simply locate the necessary
lines, uncomment them, and add the appropriate code. To uncomment a line of code,
either remove the “//” that appears at the start of the line or remove the multi-line
comment indicators /*…*/.
®
Target Selection
Target Selection Pulldown Menu
X Generation (CNX) Control Systems consist of the CEN-TVAV, CNMSX-AV/
PRO, and CNRACKX/-DP.
The 2-Series Control Systems currently consist of the AV2, CP2, CP2E, PAC2,
PAC2M, PRO2, and RACK2.
Selecting a target implies that the module MUST work for that target and any
statements that are not valid for that target are NOT permitted. It does NOT mean that
the module won't work for other targets - 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.
8 z 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. The
toolbar buttons reflect the target type of the active module within the SIMPL+
environment.
One or both targets may be selected to compile the program for both types of control
systems. When compiling a program for a specific type of control system, an error
message appears if a wrong control system target is selected that does not support a
particular function or syntax.. Shown below are the two target selection buttons of the
menu toolbar.
Toolbar Target Selection Buttons.
Software
X-GEN - shortcut to Build | X-Generation Control Systems Target 2 - shortcut to
Build | 2-Series Control Systems Target. (This is the default setting upon opening
SIMPL+.)
NOTE: If a program is compiled for the wrong type of control system, an error
message appears when attempting to upload, and the program must be recompiled.
Edit Preferences
Preferences Toolbar Pull-Down Me nu
Language Reference Guide - DOC. 5797G SIMPL+® z 9
Software Crestron SIMPL+
Text Editor Tab
®
Font - Used to select font to be used in SIMPL+ Text Editor's main window.
Cursor Positioning, Auto-Indent - When the 'enter' key is pressed, the cursor will
automatically indent to the same initial tab position as in the current line.
To manually indent a block of text, highlight the block and press TAB.
•
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.
Cursor Positioning, Allow cursor positioning past end of line - If checked, the
cursor will be allowed to be placed anywhere within the text editor. This includes any
white-space area. Disabling this option will force the cursor to the end of the current
line selected when the cursor is clicked on any white-space past the end of the line.
Tab Size - The number of spaces that equal 1 tab character.
Insert Spaces for tabs - Spaces will be inserted in place of the tab character.
10 z SIMPL+
®
Language Reference Guide - DOC. 5797G
Crestron SIMPL+
®
Target Devices Tab
Software
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.
Display Compile Warnings - When selected, the compiler displays all program
warnings during compile in the compile output window. The total number of
warnings will always be displayed whether this option is selected or not.
Insert Category
Displays a list of all available categories for the symbol tree in the SIMPL Windows
environment. This list is for reference only.
To specify a category for a SIMPL+ module, the #CATEGORY directive must be
used with a category specified in this list. If a category name is typed in that does not
exist in the Symbol Tree Category list, the SIMPL+ module will default to the
category type, Miscellaneous.
Symbol Tree Category List in SIMPL Windows
Language Reference Guide - DOC. 5797G SIMPL+® z 11
Software Crestron SIMPL+
Insert #CATEGORY Toolbar Pull-Down Menu in SIMPL+
Symbol Tree Category Pop-Up Window
®
12 z SIMPL+
Category Selection Insertion Box
®
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.
Examples are placed in a Computer Style font, i.e.,
MyVariable = ATOI(SomeOtherVariable);
Software
Variable Names
Variable names in SIMPL+ may be up to 30 characters long and may not contain any
of the operators specified in the “Operators” section. Valid characters in a variable
name are a-z, A-Z, 0-9, #, _, and $ but may not begin with 0-9.
Variable names may not duplicate existing function or keyword names.
Variable names in SIMPL+ are not case sensitive. For example, declaring a variable
“joe” can be used as “jOe” or “JOE” or any variation of case.
NOTE: Version 3.00.12 users: variable names may be 120 characters for 2-Series
systems.
Comments
It is beneficial to comment code to make it more readable and for documentation.
Comments do not exist in any form after code generation and are not required.
SIMPL+ has two styles of comments, single line and block comments. Single line
comments start with the characters //. The rest of the line (until a carriage return) is
considered a comment. If they occur within a quoted string, such as in PRINT, they
are NOT treated as comment characters, but rather as two backslash (Hex 2F)
characters.
Examples:
PRINT(“Hello, World!\n”); // This stuff is a comment.
PRINT(“hello, // world!\n”); // This stuff is a comment,
// but the string actually
Language Reference Guide - DOC. 5797G SIMPL+® z 13
Software Crestron SIMPL+
// printed is hello,
// world.
The second form of comment characters are the block comments. /* starts a block
comment and */ ends a block comment. This is useful for commenting out large
sections of code or writing large sections of documentation. Note that nested
comments are not supported. Also, if /* or */ appear inside of a quoted string such as
in an PRINT statement, they are not considered comments but part of the string.
Examples:
/*
This
is
all
a comment!
*/
PUSH Trig
{
// code that does something.
}
®
Relative Path Names for Files
Your current working directory is reset to the default (“\” or root) whenever
“StartFileOperations” is performed. It is changed only by “SetCurrentDirectory”.
File names can consist of full path names or relative path names.
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.
14 z SIMPL+
®
Language Reference Guide - DOC. 5797G
Crestron SIMPL+
®
Software
Operators
Operators Overview
SIMPL+ operators perform functions between two or more variables. SIMPL+
operators consist of Arithmetic, Bitwise, and Rational Operators.
Arithmetic Operators
OPERATORNAMEEXA MPLEEXPLANATION
-Negation-XNegate the value of X (2’s Complement of X).
*MultiplicationX *YMultiply X by Y (signed arithmetic).
/Unsigned DivisionX / YDivide X by Y, truncates result (unsigned arithmetic).
S/Signed DivisionX S/ YDivide X by Y, truncates result (signed arithmetic).
MODSigned ModuloX MOD YRemainder after dividing X by Y (signed arithmetic).
UMODUnsigned ModuloX UMOD YRemainder after dividing X by Y (unsigned arithmetic).
Only 2-Series Systems.
+AdditionX + YAdd the value of Y to X.
-SubtractionX - YSubtract the value of Y from X.
Bitwise Operators
OPERATORNAMEEXAMPLEEXPLANATION
<<Shift LeftX << YShift X to the left by Y bits; 0 is Shifted in.
>>Shift RightX >> YShift X to the right by Y bits; 0 is Shifted in.
{{Rotate LeftX {{ YRotate X to the left by Y bits; full 16 bits used. Same as
RotateLeft().
}}Rotate RightX }} YRotate X to the right by Y bits; full 16 bits used. Same as
RotateRight().
NOT1's ComplementNOT(X)Change 0 bits to 1, 1 bits to 0.
&Bitwise ANDX & YAND the bits of X with the bits of Y.
|Bitwise ORX | YOR the bits of X with the bits of Y.
^Bitwise XORX ^ YXOR the bits of X with the bits of Y.
NOTE: For the Shift and Rotate operators, only the lower 5-bits of Y are used, giving
values of Y ranging from 0 to 31. For example, if Y=600, the lower 5-bits equate to
24. Rotating a 16-bit number through 16 positions gives the original number back.
Therefore, for rotating 24, the result is equivalent to rotating through 8. Shifting
greater than 16 will always give a 0 as a result.
Language Reference Guide - DOC. 5797G SIMPL+® z 15
Software Crestron SIMPL+
Relational Operators
OPERATORNAMEEXAMPLEEXPLANATION
=ComparisonX = YTrue if X is equal to Y, False otherwise.
=AssignmentX = YAssigns the contents in Y to X. The assignment
operator cannot be used within expressions.
!Complement! XIf X = 0, X changes to 1. If X is different from 0,
evaluates to 0.
<>Not Equal ToX <> YX is not equal to Y.
<Unsigned Less ThanX < YX is less than Y (unsigned).
>Unsigned GreaterX > YX is greater than Y (unsigned).
<=Unsigned Less Than or EqualX <= YX is less or equal to Y (unsigned).
>=Unsigned Greater Than or Equal X >= YX is greater or equal to Y (unsigned).
S<Signed Less ThanX S< YX is less than Y (signed).
S>Signed Greater ThanX S> YX is greater than Y (signed).
S<=Signed Less Than or EqualX S<= YX is less or equal to Y (signed).
S>=Signed Greater Than or EqualX S>= YX is greater or equal to Y (signed).
&&Logical ANDX && YTrue if X and Y are both non-zero. False
otherwise.
||Logical ORX || YTrue if either X or Y is non-zero. False otherwise.
®
All of the above operators, with the exception of the negation (-), NOT, and
complement (!) operators, are called binary operators. Binary operators take two
values, perform an operation, and return a third value as a result. For example, 5 + 6
would return the value of 11. The arguments for a given operator are called its
operands. In the above example, the + sign is the operator and 5 and 6 are the
operands.
The negation, NOT, and complement operators are called unary operators, which
means it takes a single number and performs an operation. In this case, the negation
operator performs a negate, or 2's complement. A 2's complement takes a 16-bit
number, bitwise inverts it, and adds 1. The operand in a negation is the value being
negated. Operands do not have to be simple numbers. They may also be variables or
the results of a function call. For example, in the expression -X, the - sign is the
operator and the variable X is the operand.
16 z SIMPL+
®
Language Reference Guide - DOC. 5797G
Crestron SIMPL+
®
String Operators
OPERATORNAMEEXAMPLEEXPLANATION
=Assignment*A$ = B$Assigns the value in B$ to A$.
*NOTE: Not allowed in expressions because of possible confusion with comparison .
=ComparisonA$ = B$A$ equal B$
<>Not Equal ToA$ <> B$A$ is not equal to B$
<Less ThanA$ < B$A$ is less than B$
>Greater ThanA$ > B$A$ is greater than B$
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; the first two characters are identical in both strings, and when
it evaluated the characters C (ASCII 67) vs. D (ASCII 68), the result is false. The
comparison “ABC”<“ABCD” is true because a shorter string alphabetically precedes
one that is identical but longer.
Software
Language Reference Guide - DOC. 5797G SIMPL+® z 17
Software Crestron SIMPL+
Signed vs Unsigned Arithmetic
ANALOG_INPUT, ANALOG_OUTPUTs, and INTEGER in SIMPL+ are 16-bit
quantities. A 16-bit quantity can range from 0 - 65535 when it is treated without
having a sign (positive or negative). If a 16-bit number is treated as signed in
SIMPL+, the range becomes -32768 to 32767. The range from -32768 to -1 maps into
32768 to 65535. Expressed mathematically, the mapping is 65536 AbsoluteValue(Number). The values are treated differently depending on whether
signed or unsigned comparisons are used. Another way is as follows.
Assignments may be directly done with negative constants, for example:
INTEGER I, J;
I = -1;
J = 65535;
Results in I being equivalent to J.
Example:
IF (65535 S> 0)
X=0;
ELSE
X=1;
Above, the value of X is set to 1 since in signed arithmetic, 65535 is the same as -1,
which is not greater than 0.
IF (65535 > 0)
X=0;
ELSE
X=1;
Above, the value of X is set to 0 since in unsigned arithmetic, 65535 is greater than 0.
®
18 z SIMPL+
®
Language Reference Guide - DOC. 5797G
Crestron SIMPL+
Datatype Conversions
®
Software
SOURCEDESTINATIONACTION
INTEGERLONG_INTEGERLower 2 bytes of destination = source.
Upper 2 bytes cleared.
INTEGERSIGNED_INTEGERThe 2 bytes of source moved to destination.
2 byte number now treated as signed.
INTEGERSIGNED_LONG_INTEGERLower 2 bytes of destination = source.
Upper 2 bytes cleared.
LONG_INTEGERINTEGER Lower 2 bytes of source moved to destination,
treated as unsigned.
LONG_INTEGERSIGNED_INTEGERLower 2 bytes of source moved to destinatio n,
treated as signed.
LONG_INTEGERSIGNED_LONG_INTEGERThe 4 bytes of destination = source, now treated as
signed.
SIGNED_LONG_INTEGERINTEGERLower 2 bytes of source moved to destination.
SIGNED_LONG_INTEGERSIGNED_INTEGERLower 2 bytes of source moved to destination.
SIGNED_LONG_INTEGERLONG_INTEGERThe 4 bytes of destination = source, now treated as
unsigned.
SIGNED_INTEGERINTEGERLower 2 bytes of source moved to destination, 2 byte
number now treated as unsigned.
SIGNED_INTEGERLONG_INTEGER2 byte source is sign extended to 4 bytes
SIGNED_INTEGERSIGNED_LONG_INTEGER2 byte source is sign extended to 4 bytes
Language Reference Guide - DOC. 5797G SIMPL+® z 19
Software Crestron SIMPL+
Operator Precedence & Grouping
In an expression where many operators are present, some operators have “priority”
over others. Operators with the same precedence level are evaluated strictly left to
right. Grouping is used to change the way an expression is evaluated.
Evaluates to 33 since the multiplication is performed first. It may be beneficial to use
grouping to show which operations are performed first. Grouping is simply starting
an expression with '(' and ending with ')'. Therefore, the expression 3+5*6 is
equivalent to 3+(5*6). Grouping is very important if you want to override the default
behavior and have one piece of the expression evaluated first. Therefore, to make sure
the + is evaluated first, the expression is written as (3+5)*6, for a result of 48.
20 z SIMPL+
®
Language Reference Guide - DOC. 5797G
Loading...
+ 344 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.