Copyright 2010 Albert York TNAPI can be used to run interactive jobs in a batch environment. It establishes a VT100 telnet connection with the AS/400 and allows you to send keystrokes to the application and receive the resulting screen as data. TNAPI is freeware. You may use it in your applications as long as you include all copyright information, don't represent it as your own, and do not attempt to sell it. Support is not provided, however, if you have any questions and/or comments contact me at albertyork@email.com. Telnet API (TNAPI) The parameters that are used are as follows. Send buffer. The data to send to the AS/400. It can include imbedded cursor control commands (for example %RT to move the cursor to the right). Refer to the program for a complete list of cursor control codes. Normally trailing blanks are not sent. In order to send trailing blanks, follow them with cursor control codes such as %RT%LF that will simply move the cursor back and forth one column. For example: C eval ParmSendBuff = 'ABC %RT%LF' Function key. A function key to send after the send buffer has been sent. The most common are ENTER and F1 through F24. At the end of the job you should call TNAPI with a function key of `EOJ' in order to ensure the connection is closed. Timeout. The number of seconds (to 1/10th of a second) to wait for a response from the AS/400 before returning. TNAPI will return to your program when the AS/400 has completed sending a screen and is waiting for input (unless a wait string is specified; see below) or until the specified timeout has elapsed. Wait String array. An array of up to 20 wait strings. If wait strings are passed TNAPI will wait until the text appears at the specified location on the screen before returning. Multiple strings can be passed, using AND/OR logic. Each wait string is defined as follows: Pos 1-1 - And/Or option. A=and, O=or. First element or blank defaults to O. Pos 2-3 - Row to wait for text Pos 4-5 - Column to wait for text Pos 6-37 - Text string to wait for. If there are trailing blanks then append a null (x'00') If there is no wait string then pass a blank field of 740 bytes. Wait string pointer (2.0) - If wait strings are passed this is a pointer to the array element of the first wait sequence which matched. Return code. 0=Normal return. 1=Application error requiring ERROR RESET be sent. 2=TNAPI timed out waiting for a response from the AS/400. 3=Socket (TCP/IP) error or end of job. Screen data buffer. The current screen (1920 bytes for 24X80 screen). Screen attributes buffer. The current display attributes for each character (1920 bytes for a 24X80 screen). X'20' - Normal display. X'21' - Reverse image X'22' - High intensity. X'23' - High intensity, reverse image. X'24' - Underline X'25' - Underline, reverse image X'26' - High intensity, underline X'27' - Non-display Current row. Row where the cursor is currently positioned. Current column. Column where the cursor is currently positioned. Notes: The first time TNAPI is called it will connect to the AS/400 and wait for the sign on screen. If wait strings are specified TNAPI will return as soon as any of the strings appear. If no wait string is specified and a function key is specified TNAPI will wait until the AS/400 has completed sending the response before returning. If neither a wait string nor a function key is specified, TNAPI will receive any data the AS/400 has sent and transmit the send buffer but will not wait for a response from the AS/400. To have TNAPI log data sent to the AS/400 and screens received create a flat file of 80 bytes named TNAPILOG. To stop logging delete or rename the file. To position the cursor to a particular location on the screen you must send TNAPI a string containing a series of cursor control codes. For example: %RT%RT%RT%UP%UP will move the cursor to the right 3 columns and up 2 rows. For an example of TBAPI use see the program TNAPIEX.