Programming Examples
Appendix B
B-23
bt _write.c file
/***************************************************************************
**
**
UBYTE bt_write (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 Write.
**
**
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
**
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_write (KTX_DUALPORT far *dp, UBYTE slot_number, UBYTE link_address,
BT_BUFFER *bt_buf, UBYTE trans_num, USHORT timeout)
{
UBYTE status;
int
i,size;
/**** Initialize the command buffer ****/
dp–>cmd_buffer.host_command = BT_WRITE;
dp–>cmd_buffer.transaction_num = trans_num;
/**** Copy entire BT buffer if length is ****/
/**** set to ADAPTER_DECIDE_LENGTH ****/
if (bt_buf–>count == ADAPTER_DECIDE_LENGTH)
size = 64;
else
size = bt_buf–>count;
dp–>cmd_buffer.command_length = 3 + (2*size);
dp–>cmd_buffer.cmd.bt_write.module_slot_address = slot_number;
/**** Convert link address to logical rack address ****/
dp–>cmd_buffer.cmd.bt_write.logical_rack_address = link_address >> 2;
dp–>cmd_buffer.cmd.bt_write.bt_data_length = bt_buf–>count;
for (i=0; i<size; i++)
dp–>cmd_buffer.cmd.bt_write.bt_data[i] = bt_buf–>bt_data[i];
/**** Send the command ****/
dp–>int_status_from_host = SCANNER_COMMAND_FROM_HOST;
dp–>host_to_ktx_int_reg = INTERRUPT_KTX;
/**** Get and acknowledge the confirmation ****/
status = get_confirmation(dp, trans_num, timeout);
if ((status != CONFIRMATION_TIMED_OUT) && (status != TRANS_NUM_MISMATCH))
acknowledge_confirmation(dp);
return status;
}