
2920i Programming Reference
Writing custom event handlers is what iRite is for.
Each of the 920i tasks share processor time, but some
tasks have higher priorities than other tasks. If a low
priority task is taking more than its share of processor
time, it will be suspended so a higher priority task can
be given processor time when it needs it. Then, when
all the other higher priority tasks have completed, the
low priority task will be resumed.
Gathering analog weight signals and converting it to
weight data is the 920i’s highest priority. Running a
user-defined program has a very low priority.
Streaming data out a serial port is the lowest priority
task, because of its minimal computational
requirements. This means that if your iRite program
"hangs", the task of streaming out the serial ports will
never get any CPU time and streaming will never
happen. An example of interrupting a task would be if
a user program included an event handler for SP1Trip
(Setpoint 1 Trip Event) and this event "fired".
Let’s assume the logic for the SP1Trip event is
executing at a given moment in time. In this example,
the programmer wanted to display the message
"Setpoint 1 Tripped" on the display. If the SP1Trip
event logic doesn’t complete by the time the 920i
needs to calculate a new weight, for example, the
SP1Trip handler will be interrupted immediately, a
new weight will be calculated, and the SP1Trip event
will resume executing exactly where it was
interrupted. In most circumstances, this happens so
quickly the user will never know that the SP1Trip
handler was ever interrupted.
How Do I write and Compile iRite Programs?
Templates and sample programs are available from
RLWS to provide the skeleton of a working program.
Once you have the iRev Editor open, you are ready to
start writing a program. iRite source files are named
with the .src extension.
In addition to writing .src files you may write include
files with an extension .iri. The iRite language doesn’t
have the ability to include files, but when using iRev
you can. An include file can be helpful in keeping
your .src program from getting cluttered with small
unrelated functions and procedures that get used in
many different programs. For example, you could
create a file named math.iri and put only functions
that perform some kind of math operation not
supported in the iRite library already. When the
program is compiled through iRev, the .iri file is
placed where you told it to be placed in iRev. Because
iRite enforces "declaration before use", the iri file
needs to be placed before any of the subprograms in
your .src file.
When you are ready to compile your program, use the
"Compile" feature from the "Tools" menu in the iRev
Editor. If the program compiles without errors a new
text file is created. This new text file has the same
name but an extension of .cod. The new file named
your_program.cod is a text file containing commands
that can be sent to the 920i via an RS232 serial
communication connection between your computer
and the 920i. Although the .cod file is a text file, most
of it will not be understandable. There is really no
reason to edit the .cod file and we strongly discourage
doing so.
How Do I Get My Program into the 920i?
The 920i indicator must be in configuration mode
before the .cod file can be sent. The easiest way to
send the .cod file to the 920i is to use iRev. You can
use the Send .COD file to Indicator option under the Tools
menu in the iRev Editor, or you can send the .cod file
directly from iRev by using the Download
Configuration… selection on the Communications menu
and specifying that you want to send the .cod file.
If the 920i indicator is not in configuration mode, iRev
will pop-up a message informing you of this
condition. It is strongly recommended that you use
iRev or the iRev Editor to send the compiled program
to the 920i. This method implements error checking
on each string sent to the indicator and helps protect
from data transmission errors corrupting the program.
1.4 Running Your Program
A program written for the 920i is simply a collection
of one or more custom event handlers and their
supporting subprograms. A custom event handler is
run whenever the associated event occurs. The
ProgramStartup event is called whenever the indicator
is powered up, is taken out of configuration mode, or
is sent the RS serial command. It should be
straightforward when the other event handlers are
called. For example, the DotKeyPressed event handler
is called when ever the "." key is pressed.
All events have built-in intrinsic functionality
associated with them, although, the intrinsic
functionality may be to do nothing. If you write a
custom event handler for an event, your custom event
handler will be called instead of the intrinsic function,
and the default action will be suppressed.