Directives
CMS also allows the use of "Directives". Directives are something
like the regular script instructions, but they aren't really part of
the script. They give instructions to the compiler itself that are
followed while the script is being compiled rather than causing something
to happen while the script is actually running. This version supports only
one directive, "%DEFINE". It works very
much like the command definitions that are stored in the CMC file, but
it is used in the CMS script rather than the GUI. The directive is
set up something like this:
%DEFINE DefinitionName DefinitionText
Once the definition has been made, the compiler will replace any
occurrence of "DefinitionName" with "DefinitionText". This capability
is mainly used to make your scripts easier to write and easier to
understand.
There are some rules.:
1. The entire %DEFINE statement must appear on one line.
2. It must appear before "DefinitionName" is referenced.
3. "DefinitionText" can be more than a single word. As with the command
files, it's basically a text substitution, so you can really put most
anything there that you could put at the position where you reference
the name. The only thing to be aware of is that if the %DEFINE has an
error in it, the script test compile will stop where the definition
name is referenced in the script. If it does that, the problem is probably
back at the %DEFINE statement itself.
Other than that, you can do pretty much as you please. In practice, it's
best to put all the %DEFINE statements at the very top of the program
just before the SCRIPT statement. That keeps them from cluttering the
script itself, allows them to be referenced anywhere in the script, and
makes it easy to find them when you want to change their value.
The %DEFINE statements make dynamic coloring changes so that the
DefinitionName will be the right color for analog or bit values.
The color data-typing should work just as it does for regular variables
(js1.b1, a3, etc.). The editor has to make this determination based
on the "DefinitionText", and because of the wide variety of what might
be there, it's kind of hard to say this is going to work perfectly,
especially if the %DEFINE is complex. Anyway, we could write:
%DEFINE TimerOutput D5
%DEFINE TimeDuration 100
script
TIMER( ONDELAY, TimerOutput, TimeDuration ) = JS1.B2;
endScript
When the script is downloaded, "TimerOutput" will be replace with "D5",
"TimeDuration" will be replaced with "100". The statement will effectively
be:
TIMER( ONDELAY, D5, 100 ) = JS1.B1
There are a lots of places where this capability can be useful. For
a more elaborate example of how to use the %DEFINE statements, take a
look at Example #4 in the Sample Scripts section.