beautypg.com

Rockwell Automation 6008-SI IBM PC I/O SCNNR 6008-SI User Manual

Page 37

background image

Chapter 4

Programming Overview

4-10

The main program displays identification on the screen and then calls
options (in the same source file) to read and interpret command line
options.

Next the main program calls init (also in the U_D1.C source file). In turn,
init calls setup_6008 and checks for status. If the setup was unsuccessful,
init displays a message and abort execution rather than returning to main.

If setup succeeded, init returns control to main. The main program then
goes into a loop that monitors the scanner activity code g_act_scnr and
calls pick (in source file U_PICK.C) to get a command from the
keyboard.When you enter a command to quit the program, pick returns a
status of NOT_OK to the main program, which terminates the main
program loop. The main program then calls stop_6008 and exits.

You’ll notice that we declare init and options as Bool type functions:
they’ll be returning a value of OK or NOT_OK. pick is declared Bool (in
the header file U_D1.H.) We also have a Bool variable called status that
we use as an “OK to proceed” sentinel. As soon as status takes on a value
of NOT_OK the remaining code is bypassed until the stop_6008
shutdown call.

You may also notice what looks like a violation of the rule we stated
earlier, that setup_6008 or start_6008 must precede calls to any other
routines in our library, and that no calls can follow stop_6008. Actually,
we oversimplified that rule when we stated it. The true rule is that
setup_6008 or start_6008 must be the first call that interacts with the
scanner and stop_6008 must be the last. But it’s OK to call any of the
following routines before startup or after shutdown: sysdate, systime,
sysstamp, pr_array, pr_globl (though some values displayed may not be
meaningful), xlat_cfg, xlat_cmd, xlat_conf, xlat_flt, xlat_opst.

Avoiding Compile Time Name Conflicts

When you write your program, you need to make sure that the variable
names you pick don’t conflict with the variable names in our library or
your compiler’s library. This section and the next tell you how to avoid
conflicts with our names; please consult your compiler manual for hints on
avoiding conflict with its names.