! 18 Aug 87    &>>Microcom SX Mode<<
!
! Terrence R. Lambert
!
! mdmsxmnp.cmd		-	Microcm AX/???? Series modem dialer
!
! Microcom AX/???? modem dialer (AX Microcom manual used as reference;
!				 Microcom X/9624c modem used for testing)
!
! this dialer script has entry procedures dial, hangup, and answer
!
! NOTE: The Microcom AX/???? series modem supports the standard "AT" command
!	set.  This dialer should be used only if you are unable or unwilling
!	to use the standard set.  Regardless of which command set is used,
!	however, the switch settings should be equivalent, the parity and the
!	wordlength settings on the modem should be 8,NONE,1 (S1P4), and ALL
!	XON/XOFF handshaking should be disabled (SF10, SFM0, SX0) to allow
!	file transfers at speeds over 1200 baud.
!

!
! the "not responding" message.  It's a little more verbose, but it's worth
! saving them a phone call by making sure that:
!		1) modem is reset
!		2) cable is ok
!		3) The front and rear switches are set correctly
!
proc notrsp
	? "The modem dialer you are using assumes that you are using the SX"
	? "command set (referred to as 'The Microcom SX Command Set').  If"
	? "you have been using the Hayes ('AT') command set with another"
	? "software package, you should probably use the Hayes modem dialer"
	? "rather than this one.  If you are still having problems, check"
	? "your cable and switch settings to see that they are correct..."
	? "switches should be as follows:   1  2  3  4  5  6  7  8  9  10"
	? "                         Front-  up up up dn dn xx xx up up up"
	? "                         Back -  dn up up dn up xx xx xx"
	? " where dn is down and xx is whatever you prefer"
endproc notrsp

!
! call number [redials [timeout]]
!
proc call
on abort
! toggle it to disconnect
  init
  display "Call aborted, hanging up"
  xmit "\r"		! Cancel character stops command execution
  wait 2
  flush
  return 2
endon
on error
  do @dhangup
  return 1
endon

! Determine Phone Number and Baud Rate
if '$1' = ''
  display "Usage: dial number [redials] [timeout]"
  return 1
endif

if '$2' = ''
  setvar n 3
else
  setvar n $2
endif
if '$3' = ''
  setvar tmout 60
else
  setvar tmout $3
endif

display "Calling $1"

	xmit "\r"
	wait 1
	flush
	! set options to necessary values
	xmit "SCEOFF\r"			! turn on result codes
	wait "\r\n!",1
	if _timeout
		do @notrsp
		return 1		! modem not responding
	endif
	xmit "SF10\r"			! disable modem<->computer flow control
	wait "\r\n!",1
	if _timeout
		do @notrsp
		return 1		! modem not responding
	endif
	xmit "SFM0\r"			! disable modem<->modem flow control
	wait "\r\n!",1
	if _timeout
		do @notrsp
		return 1		! modem not responding
	endif
	xmit "SX0\r"			! Pass ^s ^q through
	wait "\r\n!",1
	if _timeout
		do @notrsp
		return 1		! modem not responding
	endif
	xmit "S1P4\r"			! 8,none,1 for file transfers
	wait "\r\n!",1
	if _timeout
		do @notrsp
		return 1		! modem not responding
	endif
	xmit "BLK3\r"			! Maximum block size is 256
	wait "\r\n!",1
	if _timeout
		do @notrsp
		return 1		! modem not responding
	endif
	xmit "S1C1\r"			! Carrier detect follows carrier
	wait "\r\n!",1
	if _timeout
		do @notrsp
		return 1		! modem not responding
	endif
	xmit "S1D0\r"			! CTS, DSR always on
	wait "\r\n!",1
	if _timeout
		do @notrsp
		return 1		! modem not responding
	endif
	xmit "SD2\r"			! Hang up if we drop DTR
	wait "\r\n!",1
	if _timeout
		do @notrsp
		return 1		! modem not responding
	endif
	xmit "SE0\r"			! Disable exits except via DTR toggle
	wait "\r\n!",1
	if _timeout
		do @notrsp
		return 1		! modem not responding
	endif
	flush
repeat
	xmit "D $1\r"			! dial the number
	wait "CONNECT",tmout
	if _timeout
		setvar n n-1
		if n <= 0
			display "Too many retries, call aborted"
			do @dhangup
			return 1
		endif
		do @dhangup
		display "Redialing..."
	else
		display "Call connected"
		return 0
	endif
until f
endproc call

!
! hangup line and terminate connection
!
proc hangup
display "Hanging up phone"
! toggle DTR to disconnect
init
xmit "\r"		! go to interactive mode
wait "!",4
if _timeout
	! toggle DTR to disconnect
	init
	xmit "\r"		! go to interactive mode
	wait "!",4
endif
endproc hangup

!
! answer [code]
!
proc answer
if "$1"=""
	? "Usage: @answer code [off wait auto now]"
	return 1
endif
setvar code "$1"
	on abort
	  display "Answer aborted"
	  return 2
	endon
	xmit "\r"			! 8,none,1 for file transfers
	wait "\r\n!",1
	if _timeout
		do @notrsp
		return 1		! modem not responding
	endif
if code = "wait"			! wait for ring BLOWNOUT by S7 timeout
	xmit "A\r"
	display "Waiting for Ring..."
	dwait "CONN",250	! only way to do it.  Sorry.
	dwait "\r\n",1
	wait 1
	flush
	return 0
elseif code = "auto"					! autoanswer ON
	xmit "AAON\r"
	wait "\r\n!",1
	if _timeout
		? "Modem not responding..."
		? "Autoanswer can NOT be set"
		return 1		! modem not responding
	endif
	? "Autoanswer now on."
	return 0
	flush
elseif code = "now"					! answer NOW
	display "Answering phone"
	xmit "A\r"		! only accessable if on hook
	dwait "CONN",250	! only way to do it.  Sorry.
	dwait "\r\n",1
	wait 1
	flush
	return 0
elseif code = "off"					! autoanswer OFF
	xmit "AAOFF\r"
	wait "\r\n!",1
	if _timeout
		? "Modem not responding..."
		? "Autoanswer can NOT be reset"
		return 1		! modem not responding
	endif
	? "Autoanswer now off."
	return 0
	flush
endif
endproc answer

!
! hangup for redial attempts, local procedure
!
proc dhangup
xmit "\r"	! a cr (\r) sign will abort a dial in progress
wait 1
flush
endproc hangup

!set ddtr on		! dtr required, most modems
!set dtr on		! dtr required, most modems
! next line in case of prior carrier loss on system V systems
!init
