Programming Examples
Appendix B
B-18
read_iot.c file
/***************************************************************************
**
** UBYTE get_IO_data (KTX_DUALPORT far *dp, UBYTE link_address,
**
IO_BUFFER *io, TABLE_NAME io_table)
**
**
This routine reads data from the KTX I/O Image Tables in the dualport
**
and copies the results into a buffer supplied by the caller. It
**
calculates the number of bytes to copy by reading the size of the
**
device from the KTX status table. If the device is faulted or is not
**
known by the KTX scanner, it returns a error in the status byte.
**
**
INPUT
**
KTX_DUALPORT far *dp – points to the base of the KTX dualport
**
UYBTE link_address – address of device whose data is to be read
**
IO_BUFFER *io – if successful, I/O data will be assigned to
**
this variable
**
TABLE_NAME io_table – either INPUT_TABLE or OUTPUT_TABLE,
**
which is used to create a pointer to the
**
right table
**
**
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 get_IO_data (KTX_DUALPORT far *dp, UBYTE link_address, IO_BUFFER *io,
TABLE_NAME io_table)
{
int
i, xfer_size;
UWORD
far *q;
UBYTE
status = SUCCESS;
ADAPTER_CONFIG_INFO far *p;
/**** Validate the input parameters ****/
if (link_address > 127)
return INVALID_ADAPTER_ADDRESS;
if ((io_table != INPUT_TABLE) && (io_table != OUTPUT_TABLE))
return UNKNOWN_IO_TABLE;
/**** Point to the adapter status table ****/
p = &dp–>adapter_status_table[link_address].adapter_config_info;
/**** Return status of adapter to caller ****/
if (!p–>in_scan)
status = ADDRESS_NOT_IN_SCAN_LIST;
else if (!p–>exists)
status = ADAPTER_NONEXISTENT;
/**** Create pointer to I/O image table and get xfer size ****/
xfer_size = 2 * (p–>size + 1);
if (io_table == INPUT_TABLE)
q = &dp–>input_image_table[link_address * 2];
else
q = &dp–>output_image_table[link_address * 2];
/**** Transfer the data ****/
io–>count = xfer_size;
for (i=0; i<xfer_size; i++, q++)
io–>data[i] = *q;
return status;
}