ABSPOSAO ; IHS/FCS/DRS - INITIATE ; [ 09/12/2002 10:05 AM ]
;;1.0;PHARMACY POINT OF SALE;**3**;JUN 21, 2001;Build 38
Q
;
; Future: extra parameter to WAITCHAR to tell it "no big deal if
; the character doesn't come in" - it looks like an error message
; when you don't get the ACK after the ENQ but then again, it's
; rare.
;
;
INITIATE() ;EP - wait for the host to initiate communications
; usually, this is an ENQ
; sometimes, it may be ACK/ENQ or ENQ/ACK (Envoy 4.1 page 6)
; Returns 0 if success, error code if failure
; Error code 30101 - disconnected
; This probably means that the host system only gives us one
; transaction per phone call, and we were hoping for an ENQ to
; let us send a second transaction, but the host sent EOT instead.
; Error code 30102 - nothing received and we hung up
;
D LOG("1 - Waiting for host to initiate with ENQ")
N CH S CH=$$WAITCHAR^ABSPOSAM(ENQ_ACK,30)
N RET,OK ; variable OK can probably be gotten rid of
I CH="ENQ" D
. ; the usual case is ENQ, not ENQ ACK, right? so only give 1 sec.
. S CH=$$WAITCHAR^ABSPOSAM(ACK,1)
. I CH="ACK" D S OK=1
. . D LOG("1 - Host sent ENQ ACK to initiate")
. . S RET=0
. E I CH="" D S OK=1
. . D LOG("1 - Host sent ENQ to initiate")
. . S RET=0
. ;E leave RET undef and CH = retval from WAITCHAR
E I CH="ACK" D
. S CH=$$WAITCHAR^ABSPOSAM(ENQ,30)
. I CH="ENQ" D S OK=1
. . D LOG("1 - Host sent ACK ENQ to initiate")
. . S RET=0
. E D ; leave RET undef and CH = retval from WAITCHAR
. . D LOG("1 - Received ACK but not expected ENQ")
I '$D(RET) D ; if RET not set, then something went wrong
. D LOG("1 - Last WAITCHAR returned "_CH)
. I CH="+++" S RET=30101 ; modem disconnected
. E S RET=30102 D HANGUP ; nothing received
I RET D LOG("1 - Unsuccessful attempt to initiate - "_RET)
Q RET
LOG(X) D LOG^ABSPOSL($T(+0)_" - "_X) Q
HANGUP D HANGUP^ABSPOSAB(DIALOUT) Q
ABSPOSAO ; IHS/FCS/DRS - INITIATE ; [ 09/12/2002 10:05 AM ]
+1 ;;1.0;PHARMACY POINT OF SALE;**3**;JUN 21, 2001;Build 38
+2 QUIT
+3 ;
+4 ; Future: extra parameter to WAITCHAR to tell it "no big deal if
+5 ; the character doesn't come in" - it looks like an error message
+6 ; when you don't get the ACK after the ENQ but then again, it's
+7 ; rare.
+8 ;
+9 ;
INITIATE() ;EP - wait for the host to initiate communications
+1 ; usually, this is an ENQ
+2 ; sometimes, it may be ACK/ENQ or ENQ/ACK (Envoy 4.1 page 6)
+3 ; Returns 0 if success, error code if failure
+4 ; Error code 30101 - disconnected
+5 ; This probably means that the host system only gives us one
+6 ; transaction per phone call, and we were hoping for an ENQ to
+7 ; let us send a second transaction, but the host sent EOT instead.
+8 ; Error code 30102 - nothing received and we hung up
+9 ;
+10 DO LOG("1 - Waiting for host to initiate with ENQ")
+11 NEW CH
SET CH=$$WAITCHAR^ABSPOSAM(ENQ_ACK,30)
+12 ; variable OK can probably be gotten rid of
NEW RET,OK
+13 IF CH="ENQ"
Begin DoDot:1
+14 ; the usual case is ENQ, not ENQ ACK, right? so only give 1 sec.
+15 SET CH=$$WAITCHAR^ABSPOSAM(ACK,1)
+16 IF CH="ACK"
Begin DoDot:2
+17 DO LOG("1 - Host sent ENQ ACK to initiate")
+18 SET RET=0
End DoDot:2
SET OK=1
+19 IF '$TEST
IF CH=""
Begin DoDot:2
+20 DO LOG("1 - Host sent ENQ to initiate")
+21 SET RET=0
End DoDot:2
SET OK=1
+22 ;E leave RET undef and CH = retval from WAITCHAR
End DoDot:1
+23 IF '$TEST
IF CH="ACK"
Begin DoDot:1
+24 SET CH=$$WAITCHAR^ABSPOSAM(ENQ,30)
+25 IF CH="ENQ"
Begin DoDot:2
+26 DO LOG("1 - Host sent ACK ENQ to initiate")
+27 SET RET=0
End DoDot:2
SET OK=1
+28 ; leave RET undef and CH = retval from WAITCHAR
IF '$TEST
Begin DoDot:2
+29 DO LOG("1 - Received ACK but not expected ENQ")
End DoDot:2
End DoDot:1
+30 ; if RET not set, then something went wrong
IF '$DATA(RET)
Begin DoDot:1
+31 DO LOG("1 - Last WAITCHAR returned "_CH)
+32 ; modem disconnected
IF CH="+++"
SET RET=30101
+33 ; nothing received
IF '$TEST
SET RET=30102
DO HANGUP
End DoDot:1
+34 IF RET
DO LOG("1 - Unsuccessful attempt to initiate - "_RET)
+35 QUIT RET
LOG(X) DO LOG^ABSPOSL($TEXT(+0)_" - "_X)
QUIT
HANGUP DO HANGUP^ABSPOSAB(DIALOUT)
QUIT