Software
Crestron
SIMPL+
perform exactly like system functions with the only exception in that they must be
defined before they are used.
Function Definitions
Since user-defined functions are created by the user (the SIMPL+ programmer), the
user must make sure that the SIMPL+ compiler knows about these functions before
the program tries to call them. This is accomplished by creating a function definition,
which is different from a function call. Remember from the discussion of system
functions that a function call is used to invoke a function. A function definition is
what tells the SIMPL+ compiler “this is what this function does”.
User functions are used for several reasons. It is not desirable to create one function
that performs every task for the entire program. To help better organize program
modules, creating several smaller functions makes programming easier to read and
understand, and debug. User defined functions can also be called by any other
function. Rather than have the same programming logic written out in several
functions, one function can be defined with this logic and then called by any other
function within the module. This will also greatly reduce the module’s size.
To help the reusability of functions, any number of variables can be passed to
functions. Variables are passed to functions through the function’s argument list.
This is also called ‘parameter passing’, or ‘function arguments’. Function arguments
can be thought of as passing a value into a function. Other variables or literal values
can be passed to function arguments. Function arguments are another way of
defining local variables. The difference between declaring a local variable within the
function and declaring one as part of the parameter list is that the function argument
will have the value of the calling function’s variable copied into it.
It is also useful for a function to return a value. A function might be written to
compute a value. Another function might want to perform a task and return an error
code that can be evaluated by the calling function. Functions can only return at most
one value, namely integers or strings. When defining a function, the returning value
will determine what type of function to declare. The different types of functions are:
FUNCTION, INTEGER_FUNCTION and STRING_FUNCTION. For the 2-series
compiler, LONG_FUNCTION, SIGNED_INTEGER and
SIGNED_LONG_FUNCTION are also available.
The syntax of a SIMPL+ function call is as follows:
FUNCTION MyUserFunction( [parameter
1
][, parameter
2
][,
parameter
n
] )
{
<statements>
}
INTEGER_FUNCTION MyUserIntFunction( [parameter
1
][,
parameter
2
][, parameter
n
] )
{
<statements>
}
STRING_FUNCTION MyUserStrFunction( [parameter
1
][, parameter
2
][,
parameter
n
] )
{
<statements>
}
32
•
SIMPL+
Programming Guide – DOC. 5789A