30.06.2015 Views

how to write a linx terminal serial communication program for almost ...

how to write a linx terminal serial communication program for almost ...

how to write a linx terminal serial communication program for almost ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

625 Digital Drive, Plano, TX 75075 Tel: (972) 964-7090 Fax: (972) 964-7643 Web Page: www.<strong>linx</strong>data.com<br />

HOW TO WRITE A LINX TERMINAL<br />

SERIAL COMMUNICATION PROGRAM<br />

FOR ALMOST ANY HOST COMPUTER<br />

• Revision Date: Oc<strong>to</strong>ber 2000<br />

Article 14


INTRODUCTION<br />

LINX II, III, and IV <strong>terminal</strong>s can be attached <strong>to</strong> any host computer that has an RS-232<br />

or RS-422 1 <strong>serial</strong> ASCII <strong>communication</strong>s port.<br />

LINX does not sell special assembly language "drivers" because they are rarely<br />

needed! The exception <strong>to</strong> this rule is <strong>for</strong> Ethernet <strong>communication</strong>s (LINX V<br />

<strong>terminal</strong>s). Refer <strong>to</strong> the TopSail literature <strong>to</strong> handle this type of host interface.<br />

The LINX II, III, and IV <strong>terminal</strong>s were specifically designed <strong>to</strong> communicate with any<br />

device that can transmit and receive an asynchronous, <strong>serial</strong>, ASCII data stream. This<br />

document describes some design criteria <strong>for</strong> a <strong>program</strong> that will run on the host computer<br />

and allow it <strong>to</strong> collect data and control a single <strong>terminal</strong> or a network.<br />

1.1 INTRODUCTION TO LINX COMMUNICATIONS<br />

The first step in designing the LINX-<strong>to</strong>-Host interface <strong>program</strong> is <strong>to</strong> understand <strong>how</strong><br />

LINX <strong>terminal</strong>s communicate. No amount of technical descriptions can replace the<br />

knowledge gained from a short session with a <strong>terminal</strong> emulation <strong>program</strong> running on the<br />

host. Even if your ultimate host will be a mainframe, you can connect a PC or a dumb<br />

<strong>terminal</strong> <strong>to</strong> the LINX using a null-modem cable and see <strong>for</strong> yourself <strong>how</strong> the LINX talks.<br />

We use HyperTerminal <strong>for</strong> our testing at LINX.<br />

Another useful device is a Data Line Moni<strong>to</strong>r, which, placed between the LINX and the<br />

host computer, will display all data records going <strong>to</strong> and from each device.<br />

1 The <strong>terminal</strong> must be ordered with one or the other


This simple <strong>program</strong> can be written in BASIC on a PC <strong>to</strong> receive data from a LINX that<br />

is communicating in XON/XOFF comm mode. You can use it <strong>to</strong> see what the LINX data<br />

records look like.<br />

OPEN "COM1:9600" AS #1<br />

DO<br />

LINE INPUT #1, A$<br />

PRINT A$<br />

LOOP<br />

'Use COM1 port, 9600 baud<br />

'Read in a line from LINX<br />

'Display what you got<br />

'Go back and read another<br />

The data you see will look something like this:<br />

0101000100ON<br />

0101000100MO<br />

Next, read the section in the LINX III User's Guide entitled "Network Directives". Study<br />

the various commands that are available, and the replies that are sent back <strong>for</strong> each one.<br />

After you have experimented with <strong>communication</strong>s between the LINX master <strong>terminal</strong><br />

and the host you will be in a much better position <strong>to</strong> tackle the details of making a host<br />

<strong>program</strong> that can provide all of the required functions.


2.0 GENERAL DESIGN CRITERIA<br />

The host <strong>program</strong> must be able <strong>to</strong> per<strong>for</strong>m the following functions:<br />

a) Get the status of each <strong>terminal</strong> on the network<br />

b) Collect data from the LINX network<br />

c) Send commands <strong>to</strong> one or more <strong>terminal</strong>s<br />

d) Download files <strong>to</strong> one or more <strong>terminal</strong>s<br />

Be<strong>for</strong>e designing the <strong>program</strong>, we must ask several questions of the intended application,<br />

and of the host computer architecture:<br />

a) Is the host operating system multi-tasking?<br />

b) Is data <strong>to</strong> be collected in batch,<br />

or will the host be sending replies <strong>to</strong> the network?<br />

c) Does the collection <strong>program</strong> need <strong>to</strong> be embedded in<br />

an application <strong>program</strong>, or can it be stand-alone?<br />

d) Can the host <strong>to</strong>lerate unsolicited input from the<br />

LINX master?<br />

2.1 Single-task vs Multi-tasking<br />

If the host operating system is multi-tasking, it will be possible <strong>to</strong> <strong>write</strong> a <strong>program</strong> that is<br />

dedicated <strong>to</strong> <strong>communication</strong>s with the LINX network. The <strong>program</strong> will s<strong>to</strong>re data in a<br />

file, or in a memory location where other tasks can access it when they require data. This<br />

makes the job of designing a <strong>communication</strong>s <strong>program</strong> easier than it would be if the<br />

application had <strong>to</strong> have the <strong>communication</strong>s embedded in it.<br />

2.2 Batch Collection vs Interactive<br />

If the data which is collected from the LINX <strong>terminal</strong>s is <strong>to</strong> be simply s<strong>to</strong>red in a<br />

sequential file, then the <strong>communication</strong>s <strong>program</strong> can be relatively simple. It will read<br />

data from the <strong>terminal</strong> and s<strong>to</strong>re it in a file. If records are received from the LINX<br />

network during a <strong>program</strong> or file download, those records can simply be s<strong>to</strong>red in the<br />

destination file <strong>for</strong> later processing.<br />

If, on the other hand, the <strong>program</strong> must per<strong>for</strong>m lookups on a database and send back<br />

replies <strong>to</strong> the network, then some this must be taken in<strong>to</strong> consideration when designing<br />

the <strong>communication</strong>s routines.<br />

For example, as you study the Polled Mode pro<strong>to</strong>col, you will see that you could<br />

potentially receive records from one LINX as you are downloading a file <strong>to</strong> another<br />

LINX. These received records would have <strong>to</strong> be queued up in the host until they can be<br />

processed.


2.3 Embedded vs Stand-alone<br />

There are two ways in which an application <strong>program</strong> might communicate with a LINX<br />

network:<br />

1. Access the <strong>communication</strong>s port directly<br />

2. Call an independent <strong>program</strong> <strong>to</strong> do the <strong>communication</strong>s<br />

If the language used <strong>for</strong> the application <strong>program</strong> does not provide access <strong>to</strong> the<br />

<strong>communication</strong>s port <strong>to</strong> the LINX <strong>terminal</strong> network, then a stand-alone <strong>program</strong> must be<br />

used <strong>to</strong> collect the data and s<strong>to</strong>re it in a file or memory buffer. The application <strong>program</strong><br />

must periodically check that file or buffer <strong>to</strong> see if any data has been collected. For<br />

example, a dBase <strong>program</strong> running on a PC under MS-DOS could collect data by calling<br />

a TSR comm <strong>program</strong>, since dBase does not have the ability <strong>to</strong> talk <strong>to</strong> the COM port<br />

directly.<br />

2.4 Unsolicited Input and Host Log-in Programs<br />

If the LINX Master <strong>terminal</strong> is in XON/XOFF mode, it will transmit unsolicited status<br />

records whenever any <strong>terminal</strong> is taken offline or placed online (See LINX III User's<br />

Guide). The Master <strong>terminal</strong> also notifies the host that it is the master, as do Sub-masters<br />

and other <strong>terminal</strong>s with network personalities. The host computer must be able <strong>to</strong> take<br />

this unsolicited input and handle the data appropriately.<br />

If the Master <strong>terminal</strong> is in POLLED mode (see section 3.1 below), then this is not quite<br />

as much of a problem, because the LINX will not transmit anything until it receives a<br />

carriage return. But if the host has a penchant <strong>for</strong> broadcasting signon screens that<br />

contain carriage returns, then the LINX will reply with a data record <strong>for</strong> every carriage<br />

return. The host will be unwittingly sending polls <strong>for</strong> data, but not s<strong>to</strong>ring the replies,<br />

and the LINX network will lose data records as a result.<br />

For example, you cannot attach a LINX <strong>terminal</strong> <strong>to</strong> a <strong>terminal</strong> port on a CICS system<br />

without setting the appropriate tables <strong>to</strong> au<strong>to</strong>matically log in the <strong>terminal</strong>. If that is not<br />

done, then the status records transmitted by the LINX network will be sent <strong>to</strong> the login<br />

<strong>program</strong>, which will not know what <strong>to</strong> do with them. On IBM mainframes running<br />

CICS, this can be done with table parameters in VTAM and CICS that specify what<br />

userid <strong>to</strong> log in<strong>to</strong>, and what TRANSID <strong>to</strong> append in front of each status record.<br />

On a UNIX system, the line should be DISABLEd <strong>to</strong> prevent incoming records from<br />

being sent <strong>to</strong> the login <strong>program</strong>, rather than an application <strong>program</strong> designed <strong>to</strong> process<br />

and s<strong>to</strong>re them.


On DEC systems running RSTS/E, if a <strong>program</strong> OPENs a KBD, then the system<br />

au<strong>to</strong>matically disables the usual login functions, and the line is "owned" by the<br />

application <strong>program</strong>.<br />

On other systems it is possible <strong>to</strong> treat the port as a simple <strong>communication</strong>s line, so that<br />

incoming unsolicited records do not get sent <strong>to</strong> any login <strong>program</strong>.<br />

If the host computer is unable <strong>to</strong> handle unsolicited records, then some other device<br />

(a PC) must be placed between the Master LINX and the host computer <strong>to</strong> filter<br />

these status records.<br />

3.0 DESIGN DETAILS<br />

The specific combination of subroutines necessary <strong>to</strong> <strong>write</strong> a network management and<br />

data collection <strong>program</strong> depends upon the criteria established in Section 2. If the<br />

<strong>program</strong> needs <strong>to</strong> have an interactive user interface, then attention must be paid <strong>to</strong> the<br />

design of <strong>for</strong>matted screens, graphics, and error messages. If, on the other hand, the<br />

<strong>program</strong> is going <strong>to</strong> be running unattended, or be called from a different application<br />

<strong>program</strong>, then the <strong>program</strong> can be more spartan.<br />

3.1 COMMUNICATIONS PROTOCOLS<br />

The basis of any network management and data collection <strong>program</strong> is its <strong>communication</strong>s<br />

subroutines. The LINX master can communicate with the host in one of the following<br />

pro<strong>to</strong>cols:<br />

- XON/XOFF<br />

- POLLED<br />

- REQUEST RESPONSE<br />

Note that an archaic pro<strong>to</strong>col called DSR mode may still s<strong>how</strong> up in the COMM PORT<br />

menu of older <strong>terminal</strong>s. This pro<strong>to</strong>col was discontinued as of Version V3.1 of the<br />

LINXBasic <strong>terminal</strong> firmware (V7.5 <strong>for</strong> <strong>terminal</strong>s with 128K+ of memory), and should<br />

never be used in older <strong>terminal</strong>s or BARCON <strong>terminal</strong>s.


3.1.1 XON/XOFF<br />

In XON/XOFF pro<strong>to</strong>col, the LINX master <strong>terminal</strong> sends records <strong>to</strong> the host whether the<br />

host is ready <strong>for</strong> them or not. It is there<strong>for</strong>e best used in an interactive environment,<br />

where each transmission from the LINX is answered with an acknowledgement from the<br />

host.<br />

Example:<br />

LINX Sends<br />

Host Replies<br />

Employee Number Employee name looked up<br />

(garbled record)<br />

Non-Acknowledgement<br />

(re-send) Employee # Employee name looked up<br />

Example:<br />

LINX Sends<br />

Host Replies<br />

15 records "I got your 15 records OK"<br />

15 records (garbled) "I got only 10 records"<br />

(re-send) 15 records "I got your 15 records OK"<br />

XON/XOFF is only suitable <strong>for</strong> batch data collection if the LINX Master <strong>terminal</strong> is<br />

guaranteed <strong>to</strong> be constantly connected <strong>to</strong> a functional host. In this mode the LINX master<br />

will dump any records collected by the network <strong>to</strong> the host until it receives an XOFF (hex<br />

13). It will wait <strong>for</strong> an XON (hex 11) be<strong>for</strong>e continuing <strong>to</strong> transmit. Obviously, if the<br />

host crashes and does not send an XOFF, or if the cable is yanked out of the host, the<br />

LINX network will merrily dump all its data records on<strong>to</strong> the floor, where they will be<br />

lost <strong>for</strong>ever.<br />

XON/XOFF is the simplest way <strong>to</strong> hook up a <strong>terminal</strong> emula<strong>to</strong>r, send some commands <strong>to</strong><br />

the LINX network, download <strong>program</strong>s, and otherwise per<strong>for</strong>m routine maintenance on<br />

the network. It is not, <strong>how</strong>ever, recommended <strong>for</strong> long-term, secure <strong>communication</strong>s<br />

where the loss of data is in<strong>to</strong>lerable.


3.1.2 POLLED<br />

POLLED mode is the next most secure pro<strong>to</strong>col. It is the most popular mode, because it<br />

is both simple and, in most environments, entirely adequate from a data security<br />

standpoint.<br />

LINX Technical In<strong>for</strong>mation Document, LINX Polled Mode Pro<strong>to</strong>col, describes this<br />

pro<strong>to</strong>col in detail. Ask <strong>for</strong> this free document be<strong>for</strong>e you attempt <strong>to</strong> <strong>write</strong> a polling<br />

<strong>program</strong>!<br />

In this mode, the LINX master only speaks when spoken <strong>to</strong>. The host sends a Carriage<br />

Return (CR) <strong>to</strong> the LINX <strong>to</strong> request data. There are only 3 valid replies from the LINX:<br />

1. Data record from any <strong>terminal</strong> in the network;<br />

2. Status record from any <strong>terminal</strong> in the network;<br />

3. Asterisk (*) if nothing <strong>to</strong> reply;<br />

No error checking other than character parity is per<strong>for</strong>med, so this pro<strong>to</strong>col is suited <strong>for</strong><br />

direct-connect environments where no checksums are not required. (However,<br />

LinxBASIC <strong>program</strong>s contain their own checksums which are tested by the interpreter.<br />

There<strong>for</strong>e, you can assume that no invalid <strong>program</strong>s will be accepted or run by the LINX,<br />

and any errors which occur during downloading of <strong>program</strong>s will cause an error message<br />

<strong>to</strong> be sent back <strong>to</strong> the host.)<br />

A record will be re-transmitted if the Host sends a (hex 21 or Control/U) <strong>to</strong> the<br />

LINX.<br />

SPECIAL NOTES:<br />

a. Network Directives constitute a valid POLL <strong>for</strong> data, so your <strong>program</strong> should<br />

per<strong>for</strong>m a READ <strong>for</strong> data after you send each Network Directive.<br />

b. Always poll any available data from a LINX be<strong>for</strong>e downloading any new line of<br />

<strong>program</strong> or data. The host should always send a Carriage Return <strong>to</strong> the LINX be<strong>for</strong>e<br />

each line of command or download file, and should retrieve ALL data records waiting<br />

(keep polling until you receive an asterisk) be<strong>for</strong>e sending the next line!


c. ECHO must be disabled! If ECHO is enabled (via the Comm Port Menu), then each<br />

record sent by the Host will first be echoed back <strong>to</strong> the host, and will then be followed by<br />

the data record. This will cause an out of sync condition <strong>to</strong> occur which will eventually<br />

crash the LINX! Make sure you have ECHO disabled on the LINX! You will<br />

occasionally see references in this document <strong>to</strong> POLLED mode using a Question Mark<br />

("?") followed by Carriage Return <strong>for</strong> its polling sequence. This is permissible, and can<br />

be useful in determining if the LINX has its ECHO enabled.<br />

d. If you receive a garbled record, send a (hex 21 or Control/U) instead of a<br />

, and the LINX Master will re-transmit the record.<br />

e. Just because you receive an asterisk does not mean all the <strong>terminal</strong>s are empty. It<br />

is possible <strong>to</strong> have data queued up in <strong>terminal</strong>s, and still get a series of several asterisks<br />

due <strong>to</strong> network polling speeds and other conditions. We suggest you keep polling until<br />

you get several seconds' worth of asterisks be<strong>for</strong>e assuming the <strong>terminal</strong>s are all empty.<br />

3.1.3 REQUEST-RESPONSE<br />

It is axiomatic that the most secure pro<strong>to</strong>cols are very complex and difficult <strong>to</strong> implement<br />

and test. The LINX REQUEST-RESPONSE pro<strong>to</strong>col is very secure! This is a true<br />

pro<strong>to</strong>col which involves transmitting ENQ's and receiving ACK's, NAK's, and WACK's.<br />

It is ideal <strong>for</strong> environments where data is being transmitted via modems or could<br />

otherwise become corrupted by noise on the comm line.<br />

If you have never written a datacomm pro<strong>to</strong>col be<strong>for</strong>e, you will find this a lengthy<br />

development and testing process. Since this is a non-trivial matter, we have a 14-page<br />

manual devoted <strong>to</strong> it. The manual is entitled Request Response LINX Interface Pro<strong>to</strong>col,<br />

and is available from LINX Data Terminals free of charge.


4.0 MACHINE-SPECIFIC HINTS<br />

4.1 UNIX/XENIX<br />

UNIX or XENIX systems, being multi-tasking, can be set up <strong>to</strong> have a dedicated <strong>program</strong><br />

running as a task, communicating with the LINX network. Other tasks can then access<br />

the data once it is s<strong>to</strong>red in a file. Make sure <strong>to</strong> DISABLE the particular tty port being<br />

used, so that unsolicited status records from the LINX do not trigger the login <strong>program</strong>.<br />

Set RESPAWN=OFF (no /etc/getty running on the port).<br />

Also use these parameters on the stty command <strong>for</strong> the LINX port:<br />

parenb -parodd cs7 -cs<strong>to</strong>pb hupcl cread clocal -ignbrk -brkint -ignpar -parmrk -inpck -<br />

istrip -inlcr -igncr -icrnl -iuclc ixon -ixany ixoff -ascedit -isig -icanon -xcase -echo -echoe<br />

-echok -echonl noflsh -opost -olcuc -onlcr -ocrnl -onocr -onlret -ofill -ofdel -page<br />

4.2 VAX<br />

It is important on these systems <strong>to</strong> build in a 1/4 second or longer time delay between<br />

LINX network polls, <strong>to</strong> prevent the CPU from being hogged by the data collection<br />

<strong>program</strong>. The BLC.bas <strong>program</strong>, distributed as part of the LINX I/O package, was<br />

patterned after a working VAX data collec<strong>to</strong>r <strong>for</strong> LINX <strong>terminal</strong>s.


4.3 IBM Mid-Range Computers<br />

The IBM System 36 and 38 are not capable of communicating via RS-232 without an<br />

intervening pro<strong>to</strong>col converter. This can be either a 5250-<strong>to</strong>-RS232 black box, or a PC<br />

with both a 5250 emula<strong>to</strong>r card and some software <strong>to</strong> transfer data <strong>to</strong> and from its RS-232<br />

COM port. Some vendors are IBM, Black Box, and Emerald Technologies.<br />

An RS-232 port is available on IBM AS/400 computers, which can be used <strong>to</strong><br />

communicate directly with LINX networks. LINX distributes a software product <strong>for</strong> the<br />

AS/400 called LinxASCIIplus 2 which is a set of CL commands that per<strong>for</strong>m all the<br />

network management and data collection functions described in this document. Contact<br />

our Sales and Marketing department <strong>for</strong> further in<strong>for</strong>mation.<br />

4.4 Other Computers<br />

LINX resellers have interfaced a wide variety of computers. We will be glad <strong>to</strong> put you<br />

in <strong>to</strong>uch with others who may have developed <strong>program</strong>s <strong>for</strong> the particular machine you<br />

are working with. Contact the Technical Support department at LINX Data Terminals,<br />

Inc.<br />

2 LinxASCIIplus is a trademark of DCS

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!