Page 2
Reproduction of the contents of this copyrighted publication, in whole or in part, without written permission of Allen-Bradley Company, Inc., is prohibited. Throughout this manual we use notes to make you aware of safety...
Use this document to understand, program, and employ the scanner function of the 1784-KTX, 1784-KTXD, and 1784-KTS Communication Interface cards. In this document, we refer to the 1784-KTX, 1784-KTXD, and 1784-KTS cards collectively as “1784-KTx” or “scanner.” Audience To use this product effectively, you must be familiar with:...
The scanner uses the remote I/O protocol to communicate with Relate to I/O Allen-Bradley I/O modules. You don’t have to know the specifics of the protocol to use the scanner with the I/O modules, but you do need to know a few terms.
Page 9
16 I/O modules. The adapter is the communication interface between the scanner and the chassis. The scanner communicates with the adapter through Allen-Bradley-approved cable. In turn, the adapter monitors and controls the I/O modules through the backplane of the chassis.
Chapter 1 Understanding I/O Scanner Concepts Discrete I/O is characterized by one terminal (or point) per I/O image table bit. Your program handles discrete I/O through I/O image tables, where each input or output terminal corresponds to one of the 4096 input and 4096 output image table bits (256 x 16 bits = 4096 bits).
1F hexadecimal. In viewing the binary representation, the address breaks down as follows: 0 – 00111 – 11. The high order bit is 0, the rack address is 00111, and the starting quarter is 11. Examine the examples on page 1-5. Allen-Bradley Parts...
Page 12
Chapter 1 Understanding I/O Scanner Concepts This physical rack assumes 2 link addresses and contains 3/4 of logical rack 2 and 1/4 of logical rack 3. Rack 2 Rack 2 Rack 2 Rack 3 Quarter 2 Quarter 3 Quarter 4 Quarter 1 Full rack starting in first I/O group"...
To convert a logical address to a link address, shift left twice and add the starting quarter. #define LOGICAL_TO_LINK(link,logical,sq) ((link)=(((logical)<<2)+sq)) Address Range The 1784-KTx scanner will service as many as 32 logical racks (32 physical node addresses) with a maximum of 4096 discrete inputs and 4096 discrete outputs. What the Scanner Does The scanner runs asynchronously in relation to the host, a personal computer.
Chapter 1 Understanding I/O Scanner Concepts The scan list is circular: each time the scanner reaches the end of the scan list it starts again at the beginning. An I/O scan (sometimes called just a scan) is one complete cycle by the scanner through the scan list, from any point to the same point.
The adapter tells the discrete output module to update its outputs with the new information. The discrete output module turns on the output. Any external device attached to the output module then becomes active. For timing information, see Timing of Discrete I/O in chapter 7, “Understanding Discrete I/O.” Allen-Bradley Parts...
Chapter 1 Understanding I/O Scanner Concepts Scanner Commands As its second primary responsibility, the host issues these types of scanner commands: management commands block-transfer commands A management command affects the operation of the scanner itself. There are five management commands: Command Action changes the scanner's operating mode to Program,...
De assert (Reset) Z80 (byte :0803h) Write a 01h to this address to de-assert (reset) the Z80 and halt execution of the loaded binary file. Subsequent writes to this address while the Z80 is de-asserted will have no effect. Allen-Bradley Parts...
Page 18
Chapter 2 Start up and Shutdown KTx Status Register (byte :0804h) Important: This is a read-only byte. This byte reports the status of several properties of the KTx card. This table describes what each bit contains. Status Code Meaning 0 = Z80 is de asserted 1 = Z80 is asserted 0 = Z80 is in the halt state 1 = Z80 is not in the halt state...
Dual port Functionality Test To check the functionality of the dual-port interface, follow these steps: Clear the dual-port memory by writing 00h to dual-port locations :0000h through :07FFh. Read and check :0000h through :07FFh for compliance. Allen-Bradley Parts...
Page 20
Chapter 2 Start up and Shutdown Write FFh to dual-port locations :0000h through :07FFh. Read and check :0000h through :07FFh for compliance. Three Power on Self diagnostic Tests: RAM, CTC, and SIO Your driver must run these three power-on self-diagnostic tests (and they must be performed in this order): Random Access Memory (RAM) Test —...
Page 21
Make sure the KTx card is seated properly in the backplane and the configuration of the KTx card does not produce any conflicts with other adapter cards in the host (such as other KTx cards, memory cards, video memory). Allen-Bradley Parts...
Page 22
Chapter 2 Start up and Shutdown See Table 2.B for RAM test status codes. Table 2.B Status Codes for RAM Test RAM test status code Meaning of code No Errors Detected Failure of Z80 RAM 0 Failure of Dual port RAM Failure of both RAM 0 and Dual port RAM Failure of Z80 RAM 1 Failure of both RAM 0 and RAM 1...
Chapter 2 Start up and Shutdown Running the Allen-Bradley has taken several measures to facilitate proper data transfer Host Compatibility Test between an IBM PC and the KTx across the ISA bus. We implemented a byte swapper on the application-specific integrated circuit (ASIC) that drives both byte lanes of the ISA bus with odd-byte data during an odd-byte read of the dual port, i.e., SBHE=0, A0=1.
Page 24
Chapter 2 Start up and Shutdown Check Mode Before you run the diagnostic, verify that the card is being operated in extended M16 mode. Read the status registe r, address 804, and check if bit 5 of bits 0:7 is set to 1 or 0.
Page 25
16-bit writes of the value ‘count’ to memory, incrementing ‘count’ and the word address until the dual port is full. Verify that the dual port contains word values incrementing from 0x0000 to 0x03FF. Report pass or fail to the user. Allen-Bradley Parts...
Chapter 2 Start up and Shutdown Enable M16 Operation Write the key bytes to enable M16 operation. Verify that the key bytes are operational by writing: to the key 0 write register, address 805, with a 0x00H to the key 1 write register, address 807, with a 0x00H Access the key read register, address 800, with a 16-bit read.
Page 27
Repeat the loading blocks procedure (steps 1–6) until finished. Reset the K T x card by writin g 01h to byte :0803h. Refer t o Table 2. E to see what each address will contain once you have completed the download. Allen-Bradley Parts 2-11...
Chapter 2 Start up and Shutdown Table 2.E Loader Memory Map of Dual Port Host Dual port Address Dual port Contents :0000h - :006Fh LOADPCL.BIN :0070h Total Word (low byte) :0071h Total Word (high byte) :0072h Size Word (low byte) :0073h Size Word (high byte) :0074h...
INIT_DONE_INTERRUPT (1) into int_status_to_host writes SUCCESS in init_status interrupts host sets scanner to Program mode sets the LED to solid red turns off LED halts its processor interrupts host waits for host commands Allen-Bradley Parts 2-13...
Chapter 2 Start up and Shutdown Shutdown The host can shut down the scanner at any time by writing any value to the KTx Deassert Register. Shutdown can be verified by reading the KTx Status register, which should show the card in the Reset state. What's Next Chapter 3 describes programming: dual-port layout, handshaking, and interrupts.
You must also be familiar with the command interface and know how to handle host interrupts. Dual port Layout The dual-port RAM of the KTx is used for communication between the host and the 1784-KTx scanner. Briefly, the dual port is divided as follows. DP offset Memory area :000h 017h...
Chapter 3 Programming Overview I/O Image Tables This image table holds input input data transmitted to the scanner by the adapters in I/O replies The KTx updates the table as data is received on the remote I/O link. The host may read this data at any time but should not modify. output output data that the scanner will transmit to the adapters in I/O commands...
CONFIRMATION_PROCESSED. Writes 0 into int_status_to_host. Interrupts the KTx by writing any value to KTx register :801h, host_to_ktx_int_reg. On receipt of interrupt, copies the next confirmation into the confirmation buffer (if a confirmation is available). Writes 0 to int_status_from_host. Allen-Bradley Parts...
Chapter 3 Programming Overview Handling Host Interrupts To properly handle interrupts from the KTx, the host (in this example, an IBM PC-compatible running DOS) must first install an interrupt service routine (ISR) and enable the appropriate interrupt. To install the interrupt service routine, first the hardware interrupt (0–15) must be converted to a software interrupt number (0–7,0x70–0x78).
/* Enable the interrupt by setting the appropriate bit in the PICMask to 0 */ PICMask = inportb(PICPortBase+1); delay(50); /* Delay for PIC to settle */ outportb(PICPortBase+1, PICMask & ~(1 << (InterruptNumber % 8))); delay(50); /* Delay for PIC to settle */ Allen-Bradley Parts enable (); /* Re–enable interrupts */...
The code fragment in Example 3.B is an example of an interrupt service Interrupt Service Handler routine for the 1784-KTx. Important: This example routine does not do any data handling; it is just intended to serve as a skeleton to build on.
Page 37
***** capable of handling these interrupts in a timely fashion. ****/ /*============================================================================ Service the regular interrupt next, since it is queued 1) see what type it is 2) service by type... =============================================================================*/ /**** dp–>int_status_to_host is the interrupt type ****/ switch (dp–>int_status_to_host) { Allen-Bradley Parts...
Basic Command and Commands from the host to the 1784-KTx scanner use this structure: Confirmation Structures Command Syntax Confirmations from the 1784-KTx scanner to the host use this structure: Confirmation Syntax The 1784-KTx responds to every command with a confirmation.
Chapter 4 Host Commands Of the seven 1784-KTx host commands, five are scanner management commands: Set Mode Set Scan List Autoconfigure Set Fault Group Get Scan List We describe these in detail, including command syntax, error codes, and the confirmation process for that command.
Page 41
= 1; dp–>cmd_buffer.cmd.set_mode.scanner_mode = mode; /**** 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; Allen-Bradley Parts...
Page 42
Chapter 4 Set Scan List The scanner continuously reads and writes discrete I/O points from/to I/O adapter devices on the remote I/O network. The scanner must be configured to know what adapter modules are on the network. Do this by using the command to specify all of the link addresses that are Set Scan List...
Page 43
If the new scan list would create a fault dependent group (FDG) orphan, the orphan’s address is copied to the caller in addition to the status code. Allen-Bradley Parts...
Page 45
An command Autoconfigure requires the scanner to poll all 128 possible link addresses on the remote I/O link, which can take as long as 6 seconds when operating at 57.6K baud. Allen-Bradley Parts...
Page 47
Command Syntax This command queues a confirmation immediately. The confirmation looks like this: Set Fault Group Confirmation Table 4.D Set Fault Group Error Conditions Error Mnemonic Code Description Allen-Bradley Parts...
Page 48
Chapter 4 The routine in Example 4.D instructs the scanner to replace the existing fault group list with the new one specified in the command. Example 4.D #include ”ktx_dp.h” /* 1784–KTX scanner dualport definition #include ”ktx_err.h” /* 1784–KTX scanner error codes #include ”ktxconst.h”...
Page 49
Command Syntax This command queues a confirmation immediately. The confirmation looks like this: Get Scan List Confirmation The routine in Example 4.E instructs the scanner to return the current scan list. Allen-Bradley Parts 4-11...
For a read BT, if the BT was successful, the scanner also returns the data that it read. In the following sections we’ll be taking a closer look at these steps. Allen-Bradley Parts...
Chapter 5 Issuing Block Transfer Commands Adapter Decide Length For most operations, the host dictates to the BT module how much data is (ADL) to be transferred in a BT Read or Write. There are circumstances, such as when first configuring a BT module, when the host allows the BT module to specify the number of words to be transferred.
Page 53
BT reply packet from the adapter, or when the 4-second timer has expired. The confirmation looks like: Host BT Write Confirmation host_command transaction_number 0 - 255 (whatever host supplied) confirmation_status (see Table 5.A) confirmation_length data Allen-Bradley Parts...
Page 54
Chapter 5 Issuing Block Transfer Commands Table 5.A Host BT Write Error Conditions Error Mnemonic Code Description SUCCESS The BT Write was successful. BAD_COMMAND_DATA_LENGTH Command data length exceeds maximum. Logical rack address or slot address is out of range. BT_BAD_ADDRESS BT address is not in scan list.
Page 55
(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; Allen-Bradley Parts...
Chapter 5 Issuing Block Transfer Commands Host BT Read The host application issues a command when it wants to Host BT Read initiate a block transfer from an adapter. To match the response to the request on completion of the block transfer, the host must supply: the logical rack address the block-transfer module slot address the data size to read from the module...
Page 57
Host requested a read, module responded with a write request. USER_MODULE_LENGTH_MISMATCH Length mismatch between what the host requested and the adapter requested. BT_CHECKSUM_ERROR Checksum error detected in reply packet. BT data invalidated. The routine in Example 5.B instructs the scanner to perform a Host BT Read Allen-Bradley Parts...
Time per BT: At 57.6K baud or 115.2K baud, the time is 5.0 ms. Number of Words: The total number of words of BT data to be exchanged. This includes all BTs in the queue. Time per Word: At 57.6K baud, this time is 0.3 ms; at 115.2K baud, 0.2 ms. Allen-Bradley Parts...
Chapter 5 Issuing Block Transfer Commands Number of Scans The total number of scans needed to empty the scanner’s BT queue is equal to the largest (effective) number of scans needed to service all of the BTs queued to any single adapter. In other words, determine the effective number of scans each individual adapter needs, then use the largest one.
The scanner maintains status information in the dual port that the host may use to monitor the state of scanner and adapter operation. The scanner updates this information as its state changes. The hardware register on the KTx card holds data about the current hardware status. Allen-Bradley Parts...
When bit is set, scanner is in Program mode. test_mode When bit is set, scanner is in Test mode. run_mode When bit is set, scanner is in Run mode. debug_mode Reserved for Allen-Bradley use only. unsolicited_bt Unsolicited BT request received. bt_pending BT in progress. fault_exists At least one adapter is faulted.
These bits indicate the physical device size of the adapter's rack: size bits physical device size quarter rack half rack three quarter rack full rack node_adapter When set, this bit indicates that the adapter is a node adapter device. undefined Reserved for future use. Allen-Bradley Parts...
Page 64
Chapter 6 Reporting KTx Scanner Status Adapter Fault Byte The host uses the adapter fault byte to determine the current state of an adapter and its relationship to a fault dependent group. This table defines the bits of the adapter fault byte. Bit # Mnemonic Description...
Page 65
OPERATING_STATUS operating_status; Declare adapter status table as an array with 128 members, where each member has a configuration byte, fault byte, and retry count byte. ADAPTER_STATUS adapter_status_table[128]; COMMAND cmd_buffer; CONFIRMATION confirmation_buffer; UWORD input_image_table[256]; UWORD output_image_table[256]; } KTX_DUALPORT; Allen-Bradley Parts...
Chapter 6 Reporting KTx Scanner Status KTx Hardware The KTx Hardware Status Register holds the current status of the KTx Status Register hardware, including the Z84 running state, and a bit to indicate that the scanner initiated a host interrupt. The host may read this information at any time and should do so when a non-recoverable error has occurred.
Page 67
When the host is declared dead, the scanner sets the host_dead bit in the word in the operating_status Allen-Bradley Parts dual port, interrupts the host, and halts.
Page 68
Chapter 6 Reporting KTx Scanner Status Scanner Watchdog Suppose that your program crashes, either because of logic errors or because of operator intervention. Or suppose that through logic errors your program gets into an infinite loop. In these cases the program is no longer sending meaningful information to the scanner.
/**** Let KTX know that the host is still alive ****/ dp–>alive_flag = HOST_ALIVE; wdg_accum = 0; /**** Call the old routine ****/ oldhandler(); What's Next Chapter 7 explains how to access the scanner I/O image tables to read and modify discrete I/O. Allen-Bradley Parts...
Chapter Understanding Discrete I/O Chapter Preview This chapter explains how to access the scanner I/O image tables to read and modify discrete I/O. After reading this chapter, you should be able to: examine any discrete inputs set or clear any discrete outputs examine any outputs that you set or cleared previously input change of state detection interrupt at end of scan list...
AND a mask that contains 1 bits everywhere except in the bit little trickier; position of the terminal to be cleared. The C language operator ~ is made for this kind of operation: input_image_table[4*0+7] &= ~(1<<3); Allen-Bradley Parts...
Chapter 7 Understanding Discrete I/O Programming Hint We suggest that you define constants for the addresses of your I/O modules. This makes your programs easier to understand, and helps you in debugging. For example: #define ALARM_ADDRESS 5 #define ALARM_GRP #define ALARM_TERM 017 .
Page 73
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; Allen-Bradley Parts...
Page 74
Chapter 7 Understanding Discrete I/O The routine in Example 7.B reads data from the KTx I/O image tables in the dual port 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.
COS detection regardless of the state of the bit. When autoconfiguration or configuration of the new enable_cos_detect scan list is complete, normal operation of COS detection will resume (based on the state of the bit). enable_cos_detect Allen-Bradley Parts...
Chapter 7 Understanding Discrete I/O Time Constraints COS detection requires real-time response from the host. At 230K baud, there can be as little as 1.2ms between COS interrupts in a dynamic system. These interrupts are not queued, so it is possible the host could miss a COS interrupt if it is unable to meet the timing requirements.
Used by the KTx and host for handshaking. The host may interrupt the KTx with one of two interrupt types: COMMAND (01) or CONFIRMATION_PROCESSED (02). The KTx will write INTERRUPT_PROCESSED (0) when it has finished processing the interrupt from the host. Allen-Bradley Parts...
Page 78
Appendix A Dual port Layout Address Mnemonic Size Host Description :00E host_dead_counter If zero, the host dead counter is disabled. A non-zero value defines the timeout period: 20ms * value The host must set the alive_flag = 0 before the timeout expires or the scanner will declare the host dead.
Page 79
Bits 0-7: cumulative count of retries to this adapter See chapter 6 for additional information. :200 host2ktx_msg_buf 100H Host to KTx command buffer :300 ktx2host_msg_buf 100H KTx to Host confirmation buffer :400 input_image_table 200H Input Image Table :600 output_image_table 200H Output Image Table Allen-Bradley Parts...
Appendix Programming Examples Appendix Preview This appendix includes these programming examples in their entirety: Programming example Description Page ktx_dp.h dual port definition and data structures ktx_err.h error codes ktxconst.h miscellaneous constructs ktx_xmpl.c main body of example code B 10 confirm.c process a KTx to host confirmation B 14 init_ktx.c...
Source code for an interrupt service routine has been included to demonstrate how an application might handle KTx interrupts. The interrupt service routine has not been integrated with the rest of the example source code. That task has been left to the application programmer. Allen-Bradley Parts...
Page 82
Appendix B Programming Examples ktx_dp.h file /************************************************************************ KTX_DP.H Description: This file contains defintions for all of the common structures and type definitions used by the example 1784–KTX Scanner software. * History: 02/22/93 Original creation. ************************************************************************/ #ifndef KTX_DP_H /* Prevent multiple inclusions */ #define KTX_DP_H 1 /**** atomic data types ****/ #define...
Page 86
Appendix B Programming Examples ktx_err.h file /************************************************************************ KTX_ERR.H Description: This file contains all errors that are configured in the 1784–KTX Scanner firmware. History: 07/08/93 Original creation. ************************************************************************/ #ifndef KTX_ERR_H #define KTX_ERR_H 1 init_status values #define IN_PROGRESS #define INVALID_LINK_ADDRESS #define BINARY_PROTOCOL_MISMATCH #define INVALID_BAUD_RATE #define UNAUTHORIZED_PROTOCOL #define FAILED_PROGRAM_CRC...
Page 87
#define SET_MODE #define SET_SCAN_LIST #define AUTOCONFIG #define BT_WRITE #define BT_READ #define SET_FAULT_GROUP #define GET_SCAN_LIST modes of operation #define PROGRAM #define TEST #define RUN /* number of words by rack size */ #define QUARTER_RACK_SIZE #define HALF_RACK_SIZE #define THREE_QUARTER_RACK_SIZE #define FULL_RACK_SIZE Allen-Bradley Parts...
Page 88
Appendix B Programming Examples /* miscellaneous #define ADAPTER_DECIDE_LENGTH #define INPUT_TABLE /* point to input image table #define OUTPUT_TABLE /* point to output image table */ #define COS_ACKNOWLEDGE 0xFF #define INTERRUPT_KTX #define ACKNOWLEDGE_KTX /* host/KTX watchdog values */ #define WDG_SCALER /* used to scale KTX ticks to host ticks */ #define HOST_ALIVE #define KTX_ALIVE /* timeout values */...
Page 89
SCAN_LIST auto_scan_list; SCAN_LIST expected_scan_list = {3, {0x04, 0x0E, 0x13}}; SCAN_LIST runtime_scan_list = {4, {0x04, 0x0E, 0x04, 0x13}}; /**** Extract dualport base address from command line ****/ Allen-Bradley Parts if ((argc != 2) || (strncmp(argv[1],”–a”,2) && strncmp(argv[1],”–A”,2))) { printf(”\Usage: ktxexmpl –aXXXX\n”); B-10...
Page 90
Appendix B Programming Examples exit(FAIL); sscanf(&argv[1][2], ”%4X”, &segment); if (segment == NULL) exit(FAIL); dp = (KTX_DUALPORT far *) MK_FP(segment, 0x0000); /**** Initialize the KTX scanner ****/ if (initialize_KTX (dp, LINK_57_KBAUD, INIT_TMO) != SUCCESS) { printf(”\nScanner initialization failed. Error code: %d”,dp–>init_status); exit(FAIL);...
Page 91
= bt_write (dp, 13, 0x04, &bt_buffer, ++trans_count, BT_WRITE_TMO); /**** Reset the old interrupt handler before exiting */ setvect(CLOCK_INTR, oldhandler); /**** Turn off watchdog ****/ dp–>host_dead_counter = 0; dp–>alive_flag = HOST_ALIVE; /**** Deassert the KTX ****/ dp–>deassert_reg = TRUE; exit (FAIL); Allen-Bradley Parts B-12...
Page 92
Appendix B Programming Examples /**************************************************************************** void interrupt KTX_watchdog() This routine performs the watchdog handshaking with the KTX (if enabled). If the KTX is dead, it resets the Clock interrupt handler, printf’s a message, and exits. *****************************************************************************/ void interrupt KTX_watchdog() /**** If accumulated == preset, check alive_flag */ if (++wdg_accum == wdg_preset) { if (dp–>alive_flag != KTX_ALIVE) { /**** Setting this to FALSE will allow main routine ****/...
Page 93
PROCESSING_PROBLEM_INTERRUPT : unrecoverable_error(dp); break; /**** Confirmations: match up transaction #’s ****/ /**** If they match, return completion status ****/ case CONFIRMATION_INTERRUPT : if (dp–>confirmation_buffer.transaction_num != trans_num) status = TRANS_NUM_MISMATCH; else status = dp–>confirmation_buffer.conf_status; default: break; return status; Allen-Bradley Parts B-14...
Page 94
Appendix B Programming Examples /*************************************************************************** void acknowledge_confirmation (KTX_DUALPORT far * dp) This routine performs the handshaking with the KTX to indicate that the host has completed processing of the last confirmation. responsibility to acknowledge the confirmation. INPUTS KTX_DUALPORT far *dp – points to the base of the KTX dualport OUTPUT none ***************************************************************************/...
Page 95
/**** 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; Allen-Bradley Parts B-16...
Page 96
Appendix B Programming Examples 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.
Page 97
= 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; Allen-Bradley Parts return status; B-18...
Page 98
Appendix B Programming Examples set_mode.c file /*************************************************************************** UBYTE set_mode (KTX_DUALPORT far * dp, UBYTE mode, UBYTE trans_num, USHORT timeout) This routine set the KTX scanner mode. INPUTS KTX_DUALPORT far *dp – points to the base of the KTX dualport UBYTE mode –...
Page 99
/* break if the transaction numbers didn’t match */ case TRANS_NUM_MISMATCH: break; /* If an adapter became a FDG orphan, copy /* orphan’s address to caller. */ /* (fall through to acknowledge confirmation) */ case SCAN_LIST_CAUSES_FDG_ORPHAN: *orphan = dp–>confirmation_buffer.conf.set_list.orphan; acknowledge_confirmation(dp); break; Allen-Bradley Parts B-20...
Page 100
Appendix B Programming Examples /* if a different error occurred or SUCCESS, acknowledge */ /* the confirmation and return the status to the caller case SUCCESS: default: acknowledge_confirmation(dp); break; return status; B-21...
Page 101
= 0; /**** 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; Allen-Bradley Parts B-22...
Page 102
Appendix B Programming Examples 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 –...
Page 103
/* 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); Allen-Bradley Parts break; B-24...
Page 104
Appendix B Programming Examples /* if an error occurred, acknowledge the confirmation */ /* and return the status to the caller default: acknowledge_confirmation(dp); break; return status; B-25...
Page 105
= *fdg; /**** 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); if ((status != CONFIRMATION_TIMED_OUT) && (status != TRANS_NUM_MISMATCH)) acknowledge_confirmation(dp); return status; Allen-Bradley Parts B-26...
Page 106
Appendix B Programming Examples getscanl.c file /*************************************************************************** UBYTE get_scan_list (KTX_DUALPORT far *dp, SCAN_LIST *sl, UBYTE trans_num, USHORT timeout) This routine instructs the KTX scanner to return the current scan list. INPUT KTX_DUALPORT far *dp – points to the base of the KTX dualport SCAN_LIST *sl –...
Page 107
PIC */ if (InterruptNumber < 8) PICPortBase = LowPICPort; else PICPortBase = HighPICPort; /* Convert from hardware interrupt numbers (0–7) to software interrupt numbers 0x8–0xf and hardware interrupt numbers (8–15) to software interrupt numbers 0x70–0x78 Allen-Bradley Parts B-28...
Page 108
Appendix B Programming Examples SWInterruptNumber = InterruptNumber + 0x8; if (SWInterruptNumber > 0xf) SWInterruptNumber += 0x60; /* Save the old interrupt handler vector, and install the new one */ /* Need to disable interrupts when changing vectors */ disable (); OldInterruptServiceRoutine = getvect(SWInterruptNumber);...
Page 109
/**** dp–>int_status_to_host is the interrupt type ****/ switch (dp–>int_status_to_host) { /**** Host ack’d last interrupt ****/ case NO_KTX_INT_AVAILABLE : break; /**** Initialization is complete ****/ case INIT_DONE_INTERRUPT : /**** Check completion status ****/ Allen-Bradley Parts if (dp–>init_status != SUCCESS) unrecoverable_error(dp); B-30...
Page 110
Appendix B Programming Examples /**** If good, clear interrupt type ****/ else dp–>int_status_to_host = 0; break; /**** A confirmation is available ****/ case CONFIRMATION_INTERRUPT : /**** The application programmer needs to write a routine ***** that handles confirmations. The other examples ***** provided show how to do it when the application ***** waits for a confirmation before proceeding to the ***** next command.
Page 111
(argv[i][0] == ’–’) switch(argv[i][1]) { case ’f’: case ’F’: /* Copy string into file name */ strcpy(loadfile_name, &argv[i][2]); break; case ’d’: case ’D’: /* Set flag to copy directly to dual port */ file_into_dp = TRUE; break; Allen-Bradley Parts B-32...
Page 112
Appendix B Programming Examples case ’a’: case ’A’: /* Get the address of the board */ sscanf(&argv[i][2], ”%x”, &address); if (!(address & 0xff00)) address <<= 8; /* If address given as a /* byte, shift it to a word */ break;...
Page 113
= read(loadfile, base, 0x800); /* Check to see if user requested a file which was too long to fit in dual port. if (length == 0x800) { printf(”\nFile is too long to fit in dual port.\n”); exit(1); Allen-Bradley Parts B-34...
Page 114
Appendix B Programming Examples printf(”\nTotal bytes downloaded to dual port: %04x\n”, length); return(0); void usage(char *argv[]) printf(”Usage:\n”); if (strrchr(argv[0], ’\\’)) printf(”%s –a<xx> –f<nnnnnnnn.eee> [–d]\n”, strrchr(argv[0], ’\\’) + 1); else printf(”%s –a<xx> –f<nnnnnnnn.eee> [–d]\n”, argv[0]); printf(” Where: ––> Upper byte of address of KTX board (e.g. D3)\n”); printf(”...
LED Blink. When set, the LED will blink if on. Bit 6: LED Color. When clear, the LED is green if on. When set, the LED is red if on. Bit 7: LED On. When set, the LED is on. Allen-Bradley Parts...
Appendix Glossary Appendix Preview This glossary contains definitions of terms commonly used in Allen-Bradley scanner documentation. ASIC ASIC is an acronym for application-specific integrated circuit. Block transfer The transfer of data to or from an intelligent I/O module, as many as 64 words at a time.
Page 117
Position in an I/O chassis the width of one discrete I/O module. Standard density module Discrete I/O module having 4, 6, or typically 8 input or output points. Two slot addressing Addressing where an I/O group represents two slots. Allen-Bradley Parts...
Page 118
Allen Bradley Publication Problem Report If you find a problem with our documentation, please complete and return this form. 1784 KTx Scanner Reference Manual Pub. Name 1784 KTX, KTXD, KTS 1784 6.5.20 December 1994 955118 10 Cat. No. Pub. No. Pub.
Page 119
PLEASE FOLD HERE NO POSTAGE NECESSARY IF MAILED IN THE UNITED STATES BUSINESS REPLY MAIL First Class Mail Permit No. 18235 Cleveland, OH POSTAGE WILL BE PAID BY ADDRESSEE TECHNICAL COMMUNICATION 747 ALPHA DRIVE HIGHLAND HEIGHTS OH 44143 9919 Allen-Bradley Parts...
Support Services At Allen-Bradley, customer service means experienced representatives at Customer Support Centers in key cities throughout the world for sales service and support. Our value-added services include: Technical Support SupportPlus programs telephone support and 24-hour emergency hotline software and documentation updates...