Crestron
SIMPL+
Software
#DEFINE_CONSTANT VCR_INPUT 3
#DEFINE_CONSTANT DVD_INPUT 4
#DEFINE_CONSTANT VPROJ_OUTPUT 2
PUSH vcr_select
{
switcher_input = VCR_INPUT;
switcher_output = VPROJ_OUTPUT; // video projector
}
PUSH dvd_select
{
switcher_input = DVD_INPUT;
switcher_output = VPROJ_OUTPUT; // video projector
}
Note the use of capital letters for the constant definitions. This is not required, but it
makes it clear to see the difference between variables and constants when reading
through a program (but of course is not useful if all caps are used for the rest of the
program). Not only is this version of the program easier to read, even for a small
example, but it is obvious that changing a numeric value in one place (the
#DEFINE_CONSTANT) can affect the value everywhere in the program.
Include Libraries
Libraries are a way of grouping common functions into one source file to enable
modularity and reusability of source code. Libraries are different from modules in
that they do not contain a starting point (
Function Main
), and cannot interact with the
control system (through I/O signals and events). Libraries can include other
libraries, but cannot include a SIMPL+ module. Only functions and defined
constants are allowed to be declared and defined within libraries. Global variable
declarations are not allowed. Functions, however, can contain local variables. Other
advantages are:
1. Modularity. SIMPL+ programs can grow to be large and can be better
organized by taking sections of code and placing them into a User-
Library. It is best to create libraries that contain sets of related
functions. For example, a library might be created that contains only
functions that perform certain math related functions. Another library
might be created that contains functions performing special string
parsing routines.
2. Reusability. As modules are written, it is common for SIMPL+
modules to need pieces of functionality that were previously written in
other modules. These common and repeatedly portions of code can be
extracted and placed into one or more libraries. Once placed into a
library, one or more SIMPL+ modules can include and make use of
them.
SIMPL+ modules include libraries using the following syntax:
#USER_LIBRARY “<library_name>”
#CRESTRON_LIBRARY “<library_name>”
Note that
library_name
is the name of the library
without
the file extension. User-
Libraries are libraries that the end user writes. These can exist either in the SIMPL+
module’s project directory, or the User SIMPL+ directory (set in SIMPL Windows).
Programming Guide – DOC. 5789A
SIMPL+
•
7