                                  Appendix D

An Example COMLINK Routine

This appendix explains how to utilize the COMLINK script
file command to allow remote access to a local controller.
All of the script files mentioned here are included on your
original diskette in the \MONITOR\SCR directory.

To simplify the explanation, the following terms will be
used:

CONTROLLER      - The local Andover controller.

LOCAL COMPUTER  - The computer connected to the controller.

REMOTE COMPUTER - The computer that will be dialing into the
		  local computer.


Here is the hardware configuration needed for COMLINK:

**************     *************                                   ************
*   Local    *     *   Local   *     *********          *********  *  Remote  *
* Controller *-----*  Computer *-----* Modem *--|\/\/|--* Modem *--* Computer *
**************   ^ ************* ^   *********          *********  ************
		 |               |
	   Main COM Port   Alarm COM Port


After Using the COMLINK command, the configuration would
effectively be this:

		*-----------------*
**************  |  *************  |                                ************
*   Local    *  |  *   Local   *  |  *********          *********  *  Remote  *
* Controller *--*--*  Computer *--*--* Modem *--|\/\/|--* Modem *--* Computer *
**************   ^ ************* ^   *********          *********  ************
		 |               |
	   Main COM Port   Alarm COM Port


The remote computer now has full access to the controller
and the controller has full access to the modem.


                          CONTINUED ON NEXT PAGE



Once the COMLINK command is used the controller is
effectively connected to the local computers modem and The
Monitor II on the local computer is apparently locked-up. No
alarms will be processed, no auto processes will take place,
etc. until the COMLINK is broken.

The COMLINK can be broken in three different ways:

* Although The Monitor II on the local computer is
  apparently locked-up, it is still monitoring both COM
  ports. If The Monitor II sees the 5 character sequence
  [BRK] pass through either of its COM ports, it will break
  the COMLINK. The characters must be in the exact sequence
  [,B,R,K and ] and the BRK must be in uppercase. This can
  be done by having the controller display a message with
  this sequence, or by having the remote computer transmit
  this sequence to the controller.

* If no activity is taking place on either COM port, The
  Monitor II can optional disconnect after a certain time
  period. This timeout period is specified by the first
  parameter of the COMLINK command. See the COMLINK command
  in chapter 10 for more information.

* If carrier detect is lost on the MAIN COM port or the
  ALARM COM port, the connection MAY be broken. This is an
  option that is specified by the second parameter of the
  COMLINK command. See the COMLINK command in chapter 10
  for more information.

Now lets look at the supplied example.

The three script files needed to for this example are:

COMLINK.SCR - This goes in the \MONITOR\SCR directory of the
	      local computer. It is the script file that
	      will establish the COMLINK and also allow file
	      transfers.

REMOTE.SCR  - This goes in the \MONITOR\SCR directory of the
	      remote computer. It allows file transfers and
	      an option to link directly with the controller
	      to view graphics, etc.

MENU.SCR    - This goes in the \MONITOR\SCR directory of the
	      remote computer. It restarts REMOTE.SCR after
	      the user is done viewing graphics, etc.


                          CONTINUED ON NEXT PAGE


The only other setup involved in this example is to add the
local computer to the remote computers controller database.
The PRE-LOGON STRING on the remote computer should be set to
#00. The PRE-LOGON must be exactly these three characters
and no others, with the following exceptions:

* When a COMLINK is established in this way, the remote
  computer running The Monitor II WILL NOT attempt to logon
  or logoff of the controller. This is what you normally
  would want. If the first number is a '1' (#10), the
  remote Monitor II will attempt to logon and logoff of the
  controller.

* Normally, when a remote computer calls in to the local
  computer, an alarm is added to the alarm disk log on the
  local computer. If you make the second number a '1'
  (#01), this alarm message will also go to the printer.

* You may use both of the options at the same time (#11).


EXAMPLE:  PRE-LOGON STRING:  #01

	  This will print the alarm message on the local
	  computers printer as well as to it's disk alarm
	  log.

The rest of the information in the controller database
should be filled out as you normally would.


***** IT IS NOT NECESSARY TO READ THE FOLLOWING INFORMATION
***** TO USE THE COMLINK COMMAND, IT IS PROVIDED FOR THOSE
***** WHO WISH TO KNOW EXACTLY WHAT IS HAPPENING.

This is the sequence of events that take place when the
remote computer connects with the local computer:

* Someone using the remote computer uses CONNECT from the
  CONTROLLER menu and then selects the local controller.

* The Monitor II running on the remote computer then dials
  the local computers modem.

* The remote Monitor II then sends the alarm:

  {A2Remote Access: Username <COMLINK>}

  to the local computer. This will execute the script file
'COMLINK.SCR' on the local computer.

                          CONTINUED ON NEXT PAGE


* The local computer (now running the COMLINK.SCR script
  file) will then send the alarm {a0 <REMOTE>} to the
  remote computer. This will execute the script file
  'REMOTE.SCR' on the remote computer.

* The two computers are now talking with each other. The
  remote computer now has a menu displayed allowing the
  user to receive a file, send a file, or do a direct
  COMLINK so they can view graphics, etc.

* When the user at the remote computer selects COMLINK, the
  local computer executes the COMLINK command. The remote
  computer now has full access to the local controller and
  is no longer running a script file.

When the remote computer user is finished viewing graphics,
etc. he should execute the MENU.SCR script file from the
EXECUTE SCRIPT menu selection in the SYSTEM menu. This will
send the [BRK] command to the local computer, which will
break the COMLINK and redisplay the original file transfer
menu.


COMLINK.SCR

'this script file will allow a remote site to download files
'from the local computer, and then initiate a COMLINK so the
'remote computer can view graphics, etc.
'
'this file should be named COMLINK.SCR and placed in the '\MONITOR\SCR
'directory of the local computer. it will then be executed when someone calls in from a remote site
'(if they have used the #00 pre-logon option).

'!!!!! IT IS THE RESPONSIBILITY OF THE REMOTE COMPUTER TO DISCONNECT !!!!!

'place a warning at the top of the screen
header "Remote Access Active...Please Do Not Disturb"

'change the active port to the alarm port so we are talking to the remote computer
alarmcom

'and then clear out any received characters
flushbuff

'transmit an alarm message to the remote computer. this will activate the script file "REMOTE.SCR"
'on the remote 'computer.
'(lowercase 'a' will not register as an alarm on remote)

transmit "{a0 <REMOTE>}"     'run script file 'REMOTE.SCR'
                             'on the remote computer

GETRESP:
'the following 'press a key' messages are for dumb terminal users, Monitor II users won't see it.

transmit "Press <Ctrl>-R to Receive a File"
transmit "      <Ctrl>-T to Transmit a File"
transmit "      <Ctrl>-L for COMLINK"
transmit "      [Esc] to Abort"
transmit ""
transmit "Enter Choice:";

'wait up to 30 seconds for remote to respond
for t = 1 to 30*18
    pause 1
    if @buffsize = 0 then next
    getbyte b
    if b=18 then goto DOWNLOAD 'if <Ctrl>-R is received,remote wants to download
    if b=20 then goto UPLOAD   'if <Ctrl>-T is received, remote wants to upload
    if b=12 then goto LINKUP   'if <Ctrl>-L is received, do COMLINK
    if b=27 then retgraphic    'if ESC is received then end
next
retgraphic 'if no response, abort

                          CONTINUED ON NEXT PAGE


'the remote wants to receive a file so ask for filename
DOWNLOAD:
transmit ""
transmit ""
transmit "Enter Filename to RECEIVE, [Enter] Alone to Abort:";
recsetup 13,30*18             'set receive to 30 second timeout
receive f$                    'get filename
sendbyte 13
if @success=0 then transmit "TIMEOUT...":goto GETRESP
stringlen f$,f
if f=0 then transmit "Aborted...":goto GETRESP
transmit "Start your XMODEM Receive Now...<Ctrl>-X to Abort"
xmodemxmit f$                 'transmit the file
goto GETRESP                  'loop back for another choice

'the remote wants to transmit a file so ask for filename
UPLOAD:
transmit ""
transmit ""
transmit "Enter Filename to Transmit, [Enter] Alone to Abort:";
recsetup 13,30*18             'set receive to 30 second timeout
receive f$                    'get filename
sendbyte 13
if @success=0 then transmit "TIMEOUT...":goto GETRESP
stringlen f$,f
if f=0 then transmit "Aborted...":goto GETRESP
transmit "Start your XMODEM Transmit Now...<Ctrl>-X to Abort"
xmodemrec f$                  'receive the file
goto GETRESP                  'loop back for another choice


LINKUP:

transmit ""
transmit "Type [BRK] to break out of COMLINK."
transmit "(type all 5 characters...[ B R K ], B R K must be uppercase)"
transmit ""

'do comlink with 5 minute inactivity breakout
'un-comment the one you wish to use

comlink 5,0   'ignore carrier detect
'comlink 5,1   'breakout if MAIN port loses carrier detect
'comlink 5,2   'breakout if ALARM port loses carrier detect
'comlink 5,3   'breakout if EITHER port loses carrier detect
pause 2*18     'pause 2 seconds
goto GETRESP   'go get next response

                          CONTINUED ON NEXT PAGE



REMOTE.SCR

'this file is used on the remote computer and
'is activated by the local computer after dialing in to it.

'display a message at the top of the screen
header "Remote Connection Established"

GETRESP:
message "Press <R> to Receive a File","<T> to Transmit a File","<L> to Link or [Esc] to Disconnect"

GETRESP1:
getkey


if @keycode=82  then goto DOWNLOAD    'uppercase R
if @keycode=114 then goto DOWNLOAD    'lowercase r

if @keycode=84  then goto UPLOAD      'uppercase T
if @keycode=116 then goto UPLOAD      'lowercase t

if @keycode=76  then goto LINKUP      'uppercase L
if @keycode=108 then goto LINKUP      'lowercase l

if @keycode=27 then goto DISCON       'ESC

goto GETRESP1

DOWNLOAD:
clearmessage            'clear message box
sendbyte 18             'send <Ctrl>-R to tell local we want to receive
getinput f$,"XMODEM Receive","Enter Filename: ",0,35
stringlen f$,f
if f = 0 then transmit "":transmit "":goto GETRESP
transmit f$
xmodemrec f$
goto GETRESP

UPLOAD:
clearmessage            'clear message box
sendbyte 20             'send <Ctrl>-T to tell local we want to transmit
getinput f$,"XMODEM Transmit","Enter Filename: ",0,35
stringlen f$,f
if f = 0 then transmit "":transmit "":goto GETRESP
transmit f$
xmodemxmit f$
goto GETRESP

LINKUP:
clearmessage            'clear message box
sendbyte 12             'send <Ctrl>-L to tell local to COMLINK
inform "When You Are Done Viewing Graphics, etc,","Run the Script File Called 'MENU'"
end

                          CONTINUED ON NEXT PAGE


DISCON:
clearmessage            'clear message box
sendbyte 27             'send [ESC] to tell local we are disconnecting
sendbyte 27
disconnect
end



MENU.SCR

'used in conjunction with REMOTE.SCR & COMLINK.SCR

transmit "[BRK][BRK]"   'xmit breakout code twice just to be sure it gets it

pause 1*18              'pause 1 second
flushbuff               'clear out the com buffer
run "remote"            'run the menu script file called REMOTE.SCR
end

