Software
Crestron
SIMPL+
User-Defined Functions
The term checksum byte is
commonly used in serial
communications to represent
a byte (or bytes) that is
appended to a command
string. This byte is calculated
from the other characters in
the string using some
specified algorithm.
Checksum bytes are used to
provide error-checking when
communicating between
devices.
In programming, it is common to reuse the same code over and over again. For
example, when writing a program to generate strings (to control a device), there may
be a need to calculate a checksum byte. Once the code to calculate this byte is
formulated, paste it in to the program after each instance where a command string is
created.
This technique has many flaws. First, the program can grow unnecessarily large and
become hard to manage and debug. Second, if there is a need to change the code, it
must be changed every place it was used, which is time consuming and error prone.
The solution is to create user-defined functions to perform common tasks. A user-
defined function is very similar to a “built-in” function like Date or MakeString,
with some important exceptions.
To invoke a user-defined function, use the following syntax:
CALL MyUserFunction();
Event Functions
Event functions make up the heart of most SIMPL+ programs. Since a well-designed
control system is “event-driven” in nature, most code is activated in response to
certain events when they occur. Event functions allow the user to execute code in
response to some change that has occurred to one or more of the input signals
feeding the SIMPL+ module from the SIMPL program.
Two things must be realized about event functions. They can be used with input
variables only (not with locally defined variables). Also, they are only triggered by
the operating system at the appropriate time (that is, they cannot be called manually
by the programmer).
Like everything else in the control system, event functions are multi-tasking. That is,
an event can be triggered even if another event in the same SIMPL+ module is
already processing. As described in “Understanding Processing Order” on page 49,
this only happens if events are triggered on the same logic wave, or if one event
function has caused a task switch.
The structure of an event function is as follows.
event_type <input list>
{
<statements>
}
In SIMPL+ there are three basic event types that can occur: PUSH, RELEASE, and
CHANGE. In addition to these three is a fourth type simply called "EVENT." These
event types are discussed in the following subsections.
PUSH and RELEASE Events
Push and release events are valid only for DIGITAL_INPUT variables. The push
event is triggered when the corresponding digital input goes from a low to a high
state (positive- or rising-edge). The release event occurs when the signal goes from a
high to a low (negative- or falling-edge). For example, the following code sends a
string to a camera unit to pan left when the left button is pressed and then send a stop
command when the button is released.
10
•
SIMPL+
Programming Guide – DOC. 5789A