5 sound programming practices – Rice Lake iRite IDE User Manual

Page 7

Advertising
background image

920i

Programming Reference - Introduction

3

For example, the built-in intrinsic function of the

UNITS

key is to switch between primary, secondary,

and tertiary units. If the handler

UnitsKeyPressed

was

defined in a user program, then the

UNITS

key no

longer switches between primary, secondary, and
tertiary units, but instead does whatever is written in
the handler

UnitsKeyPressed

. The ability to turn off the

custom event handler and return to the intrinsic
functionality is provided by the

DisableHandler

function.

It is important to note that only one event handler can
be running at a time. This means that if an event
occurs while another event handler is running, the
new event will not be serviced immediately but
instead will be placed in a queue and serviced after the
current event is done executing.

This means that if you are executing within an infinite
loop in an event handler, then no other event handlers
will ever get serviced. This doesn’t mean that the
indicator will be totally locked-up: The

920i

will still

be executing its other tasks, like calculating current
weights, and running the setpoint engine. But it will
not run any other custom event handlers while one
event is executing in an infinite loop.

There are some fatal errors that an

iRite

program can

make that will completely disable the

920i

. Some of

these errors are "…divide by zero", "string space
exhausted", and "array bounds violation". When they
occur, the

920i

stops processing and displays a fatal

error message on the display. Power must be cycled to
reset the indicator.

After the indicator has been restarted, it should be put
into setup mode, and a new version (without the fatal
error) of the

iRite

program should be loaded. If you

are unfortunate enough to program a fatal error in
your ProgramStartup Handler, then cycling power to
the unit will only cause the ProgramStartup Handler to
be run again and repeat the fatal error.

I n t h i s c a s e y o u m u s t p e r f o r m a
RESETCONFIGURATION. Your program, along
with the configuration, will be erased and set to the
defaults. This will allow you to reload your

iRite

program after you have corrected the code that
generated the fatal error and re-compiled the program.

1.5

Sound Programming Practices

The most important thing to remember about writing
sou rce code is that it has two v ery important
f u n c t i o n s : i t m u s t w o r k , a n d i t m u s t c l e a r l y
communicate how it works. At first glance, especially
to a beginning programmer, it may seem that getting
the program to work is more important than clearly
commenting and documenting how it works.

As a professional programmer, you will realize that a
higher quality product is produced, which is less
costly to maintain, when the source code is well
d o c u m e n t e d . Yo u , s o m e b o d y e l s e a t y o u r
organization, the customer, or RLWS Support
Personnel, may need to look at some

iRite

source

code, months or years from now, long after the
original author has forgotten how the program worked
or isn’t around to ask. This is why we advocate
programming to a specific standard. The template
programs, example programs, and purchased custom
programs that are available from RLWS follow a
single standard. You are welcome to download this
standard from our website, or you can write your own.

The purpose of a standard is to document the way all
programmers will create software for the

920i

indicator. When the standard is followed, the source
code will be easy to follow and understand. The
standard will document: the recommended style and
form for module, program, and subprogram headers,
p rop er n am ing co nv en tions for variables and
functions, guidelines for function size and purpose,
commenting guidelines, and coding conventions.

Advertising
This manual is related to the following products: