beautypg.com

Data structure (packet) – Rockwell Automation 6008-SI IBM PC I/O SCNNR 6008-SI User Manual

Page 69

background image

Chapter 7

Scanner Management

7-2

QMR typedef

When you initiate an MR, you pass a packet to the library routines. The
packet has a defined type of QMR.

This defined type is a structure that contains a field used only by the
library routines, plus the following:

qmr_stat

unsigned integer confirmation status, initially equal to SC_PENDING
and then set to the actual completion status after the scanner has finished
with the MR.

qmr_len

unsigned integer length of data in bytes, which you fill in only when
changing the scan list.

qmr_data

character array of 128 bytes, the data area.

Programmer Alert

Your program can get itself into trouble by misusing packets. Here are the
pitfalls that relate to MRs:

Improper reuse of pointers: If the mr_wait routine decides that the

scanner has not responded in a reasonable time, your program is
generally free to use the packet for a different MR. But suppose that
your program had g_timout set too low so that mr_wait didn’t wait
long enough. (A scan list, the slowest request, can take up to 12 units,
about 2/3 of a second.) Then the confirmation of the first request could
come through and wipe out the information in the second request, which
is waiting for a confirmation from the scanner. The library routines
catch some but not all of these situations, and count up the ones they do
catch in g_pkt_err. Generally, your program should not reuse a packet
that contains a status of SC_PENDING unless absolutely sure that the
scanner never responds to that command.

Invalid pointers: Conforming to established C coding conventions,

library routines that need access to user packets take pointers as their
function arguments. There is no way for a called function to check
whether your program has sent it a valid pointer. Therefore, you are
completely responsible for sending valid pointers to the library routines.
If the pointer arguments don’t point to proper packets, your program can
perform incorrectly or crash, possibly locking up the host computer.

Data Structure (Packet)