Chapter 7
Understanding Discrete I/O
7-4
The routine in Example 7.A writes data into the KTx output image table in
the dual port. Attempts to write beyond the logical size of the device will
be rejected, e.g., the caller requests a write of a full rack of data to a device
that is a half-rack in size.
Example 7.A was designed, in part, to demonstrate how the data in the
adapter status table may be accessed and used. For performance reasons,
some applications may perform a block move of data to update multiple
adapters. The boundary checking in this example provides you with a level
of security when addressing the output image table by preventing it from
accidentally overwriting another adapter’s output image.
Example 7.A
#include ”ktx_dp.h”
/* 1784–KTX Scanner Dualport definition */
#include ”ktx_err.h”
/* 1784–KTX Scanner error codes */
#include ”ktxconst.h”
/* 1784–KTX Scanner constants */
UBYTE put_output_data (KTX_DUALPORT far *dp,
UBYTE link_address, IO_BUFFER *io)
{
int
i, max_xfer_size;
UBYTE
*q;
UBYTE
status = SUCCESS;
ADAPTER_CONFIG_INFO far *p;
/**** Point to the adapter status table ****/
p = &dp–>adapter_status_table[link_address].adapter_config_info;
/**** Validate the input parameters ****/
if (link_address > 127)
return INVALID_ADAPTER_ADDRESS;
max_xfer_size = 2 * (p–>size + 1);
if (io–>count > max_xfer_size)
return ADAPTER_SIZE_OVERLAP;
/**** Return status of adapter to caller ****/
if (!p–>in_scan)
status = ADDRESS_NOT_IN_SCAN_LIST;
else if (!p–>exists)
status = ADAPTER_NONEXISTENT;
/**** Transfer the data ****/
for (i=0; i<io–>count; i++)
dp–>output_image_table[(link_address * 2) + i] = io–>data[i];
return status;
}