Programming Examples
Appendix B
B-16
init_ktx.c file
/***************************************************************************
**
**
UBYTE initialize_KTX (KTX_DUALPORT far *dp, UBYTE link_baud_rate,
**
USHORT timeout)
**
**
This routine initializes the KTX. It assumes the 1784–KTX binary
**
has already been downloaded into the card.
**
**
PARAMETERS
**
KTX_DUALPORT far *dp
–
points to the base of the KTX dualport
**
UBYTE link_baud_rate
–
desired baud rate: 57.6, 115.2, or 230.4
**
USHORT timeout
–
time (in seconds) to wait for KTX to
**
complete initialization.
**
***************************************************************************/
#include <time.h>
#include <stdlib.h>
#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
initialize_KTX (KTX_DUALPORT far *dp, UBYTE link_baud_rate,
USHORT timeout)
{
int
i;
UBYTE
status;
time_t
t0;
UBYTE
boot_code[] = {0xC3, 0, 0, 0};
/**** Initialize dualport variables ****/
for (i = 0; i < sizeof(boot_code); i++ )
dp–>boot_code[i] = boot_code[i];
dp–>link_address = SCANNER_LINK_ADDRESS;
dp–>link_protocol = KTX_SCANNER_PROTOCOL;
dp–>link_baud_rate = link_baud_rate;
/**** Start the KTX & timer ****/
dp–>assert_reg = TRUE;
t0 = time(NULL);
/**** Wait for completion ****/
while (dp–>int_status_to_host != INIT_DONE_INTERRUPT) {
if ((time(NULL) – t0) > timeout) {
status = INITIALIZATION_TIMED_OUT;
break;
}
}
/**** If not a timeout, return completion status ****/
if (status != INITIALIZATION_TIMED_OUT)
status = dp–>init_status;
return status;
}