Programming Examples
Appendix B
B-24
bt _read.c file
/***************************************************************************
**
**
UBYTE bt_read (KTX_DUALPORT far * dp, UBYTE slot_number,
**
UBYTE link_address, BT_BUFFER *bt_buf,
**
UBYTE trans_num, USHORT timeout)
**
**
This routine instructs the KTX scanner to perform a Block Transfer
**
Read.
**
**
INPUTS
**
KTX_DUALPORT far *dp
– points to the base of the KTX dualport
**
UBYTE slot_number
– BT module slot number (0–15)
**
UBYTE link_address
– device link address
**
BT_BUFFER *bt_buf
– BT data buffer which is to be written on
**
completion of the BT
**
UBYTE trans_num
– transaction_number
**
USHORT timeout
– time (in seconds) to wait for completion
**
**
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 bt_read (KTX_DUALPORT far *dp, UBYTE slot_number, UBYTE link_address,
BT_BUFFER *bt_buf, UBYTE trans_num, USHORT timeout)
{
int
i;
UBYTE status;
/**** Initialize the command buffer ****/
dp–>cmd_buffer.host_command = BT_READ;
dp–>cmd_buffer.transaction_num = trans_num;
dp–>cmd_buffer.command_length = 3;
dp–>cmd_buffer.cmd.bt_read.module_slot_address = slot_number;
/**** Convert the link address to logical rack address ****/
dp–>cmd_buffer.cmd.bt_read.logical_rack_address = link_address >> 2;
dp–>cmd_buffer.cmd.bt_read.bt_data_length = bt_buf–>count;
/**** Send the command ****/
dp–>int_status_from_host = SCANNER_COMMAND_FROM_HOST;
dp–>host_to_ktx_int_reg = INTERRUPT_KTX;
/**** Get and process the confirmation ****/
status = get_confirmation(dp, trans_num, timeout);
switch (status) {
/* break if no confirmation was available */
case CONFIRMATION_TIMED_OUT:
break;
/* break if the transaction numbers didn’t match */
case TRANS_NUM_MISMATCH:
break;
/* when successful, copy BT read data to caller */
/* and acknowledge the confirmation */
case SUCCESS:
bt_buf–>count = dp–>confirmation_buffer.conf_length/2;
for (i=0; i < bt_buf–>count; i++)
bt_buf–>bt_data[i] = dp–>confirmation_buffer.conf.bt_read.bt_data[i];
acknowledge_confirmation(dp);
break;