beautypg.com

Here’s a sample program skeleton – Rockwell Automation 6008-SI IBM PC I/O SCNNR 6008-SI User Manual

Page 35

background image

Chapter 4

Programming Overview

4-8

Here’s a sample program skeleton:

#include
#include
void main(argc, argv)
int argc; char *argv[ ];
{

QMR pkt;
. . .
status = setup_6008(1, 1, 3, 0, &pkt);

if ( status != OK ) {

printf(“setup failed: command=%s status=%s\n”,

xlat_cmd(status), xlat_conf(pkt.qmr_stat));

if ( status != C_AUTOCONF && status != C_SETUP )

printf(“scanner fatal error %d\n”, fatal_6008(

));

abort( );

}
. . .
/* application logic here, including calls to host_active( )
*/
. . .
stop_6008( );

}

As explained in chapter 5, if setup fails the setup_6008 function returns
the number of the failed command and leaves the specific error status in
the packet. The sample above above uses xlat routines, described in
chapters 7 and 9, to display the meanings of the codes in plain English.

Once the setup procedure has succeeded, the scanner and host are talking
and your program can proceed. Your program must call host_active as
explained above.

Also, your program should periodically monitor global variable
g_act_scnr to make sure that communications are still active. (Refer to
chapter 5, Scanner Status, for complete information on g_act_scnr and
other scanner monitoring features.)