!
! Improved logon script for MCI mail and Dacom Quad modem
!
    INFO "Improved MCI Logon"
    SETUP ( Baud=9600 :Stop=1 :Parity=even :Handshake=XonXoff,RtsCts
    	    Fail=None :Timeout=20 :Echo=off :Data=7 )
    ON send fail goto bad
    SET c1=4
rAlive:
    SEND "AT"
    WAIT 20 ( ON reply "OK<$d><$a>" GOTO alive )
    ON c1 GOTO rAlive
    GOTO merror
alive:
    SENDWAIT 10 "AT&F","OK<$d><$a>" GOTO merror
    SENDWAIT 10 "AT\N0","OK<$d><$a>" GOTO merror
    SENDWAIT 10 "AT&J2","OK<$d><$a>" GOTO merror
    SET C1=3
    GOTO reDial
wait100:
    INFO "Waiting to redial"
    WAIT 60
reDial:
    SEND "ATD<PssNumber>"
    WAIT 60 (
	ON reply "CONNECT" GOTO letsgo
	ON reply "NO DIALTONE" GOTO tele
	ON reply "NO CARRIER" GOTO nocar
	ON reply "ERROR" GOTO black
	ON reply "BUSY" GOTO again )
    GOTO merror
again:
    ON c1 GOTO wait100
    ALERT "Line busy" : EXIT
letsGo:
    INFO "Connected ..."
    WAIT 4 : SEND "<$d>";
    WAIT 4 : SEND "<$d>";
    WAIT 4 : SEND "d1<$d>";
    WAIT 4
    SENDWAIT 60 "<$d>";,"NUI?<$d><$a>" GOTO noNui
    SEND "<MciNumber>"
    SETUP (Data=8 :Parity=none)
    WAIT 60 ( ON REPLY "user name:" GOTO gotUser) : goto noUser
gotUser:
    SENDWAIT 30 "<MciUserName>","Password:" GOTO noPass
    SENDWAIT 90 "<MciPassword>","Command:" GOTO noCom
    EXIT

black:
    ALERT "Number dialled too many times" : EXIT
nocar:
    ALERT "No connection made" : EXIT
tele:
    ALERT "Check connected to telephone" : EXIT
merror:
    ALERT "Check modem connected" : EXIT
bad:
    ALERT "Check RS232 lead connected" : EXIT
noNui:
    ALERT "No NUI? received" : EXIT
noUser:
    ALERT "No user name" : EXIT
noPass:
    ALERT "No password" : EXIT
noCom:
    ALERT "No command"
    EXIT
