Programming Examples
Appendix B
B-17
put_data.c file
/*************************************************************************************
**
** UBYTE put_output_data (KTX_DUALPORT far *dp, UBYTE link_address, IO_BUFFER *io)
**
**
This routine writes data into the KTX Output Image Table in the
**
dualport. 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.
**
This example was designed, in part, to demonstrate how the
**
data in the adapter status table may be accessed an used. For
**
performance reasons, some applications may perform a block move
**
of data to update multiple adapters. The boundary checking in
**
this example provides the user a level of security when addressing
**
the Output Image Table by preventing it from accidentally overwriting
**
another adapter’s output image.
**
**
INPUT
**
KTX_DUALPORT far *dp – points to the base of the KTX dualport
**
UYBTE link_address – address of device whose data is to be written
**
IO_BUFFER *io – if successful, I/O data will be copied from this
**
this variable into dualport
**
**
OUTPUT
**
UBYTE status – completion status of the command
**
*************************************************************************************/
#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;
}