ABSPOSUT ; IHS/FCS/DRS - POS utilities - testing modem ;
;;1.0;PHARMACY POINT OF SALE;;JUN 21, 2001
Q
; D DIR to get a directory of available tests
DIR ;
N I,X F I=1:1 S X=$T(+I) Q:X="" D
. I X'?1"TEST".E Q
. I $P(X," ")="TESTINIT" Q
. I $P(X," ")="TESTDONE" Q
. I $P(X,"(")="TESTID" Q
. W X,!
Q
; DEST = pointer to dial out, 9002313.55
; IO = the IO device associated with DEST
; SLOT = pointer to logging in ^ABSPECP("LOG",...)
; ISOPEN is true if device is open (and close needed on exit)
; ECHO is true so LOG^ABSPOSL(SLOT) echoes to your screen as well
; D PRINT in this routine prints what's in SLOT
; or later you can DO PRINTLOG^ABSPOSL(SLOT)
; All tests finish via TESTDONE label.
GETDEST ;
N DIC,X,Y,DTIME,DLAYGO,DINUM
S DIC=9002313.55,DIC(0)="AENZ"
D ^DIC W !
I Y<0 S DEST="" Q
S DEST=+Y
S IO=$$IO^ABSPOSA(DEST)
Q
TESTINIT I '$D(DEST) D GETDEST Q:'DEST
S ECHO=1,ISOPEN=0
D INIT^ABSPOSL()
S SLOT=$$GETSLOT^ABSPOSL
W "Logging is to slot ",SLOT,"; D PRINT to display it again",!
D LOG("Testing dial out #"_DEST_" "_$P(^ABSP(9002313.55,DEST,0),U)_" on device "_IO)
S SLOT=$$GETSLOT^ABSPOSL
Q
TESTID(X) D LOG("This is "_X_U_$T(+0)_": "_$P($T(@X)," ",2,255)) Q
OPEN ; do all the OPENing here so it sets ISOPEN
; sets X = zero if success, nonzero if failure
I ISOPEN D
. D LOG("apparently the device we're opening is already open")
. D LOG("So close it first...")
. D CLOSE
S X=$$OPEN^ABSPOSAB(DEST)
I 'X S ISOPEN=1
E D LOG("OPEN failed, error code ="_X)
Q
CLOSE S X=$$CLOSE^ABSPOSAB(DEST)
I 'X S ISOPEN=0
E D LOG("CLOSE failed, error code ="_X)
Q
PRINT D PRINTLOG^ABSPOSL(SLOT)
W "(This came from the log file in ^ABSPECP(""LOG"",",SLOT,")",!
Q
LOG(X) D LOG^ABSPOSL(X,ECHO) Q
GETCMD(X) ;
I X="ECHO OFF" Q "E0"
I X="RESET"!(X="ATZ") Q "Z"
I X="GET STATUS" Q "I0"
D IMPOSS^ABSPOSUE("P","TI","Bad command "_X,,"GETCMD",$T(+0))
Q
COMMAND(X) ;issue a command directly to the modem
I X'?1"AT".E S X="AT"_X
D LOG("Issue modem command "_X)
U IO W X,$C(13)
Q
READ(TIMEOUT,EXPECT) ; read result of a modem command
; returns true if expected string found, false if not
; and sets X=0 if expected string found, nonzero if not found
; (beware - opposite meanings!)
I '$D(EXPECT) S EXPECT=""
S X='$$READ1(EXPECT)
I EXPECT]"",X D LOG("Did not receive expected string "_EXPECT_" in timeout "_TIMEOUT)
Q:$Q 'X Q
READ1(EXPECT) ; expecting EXPECT string (null if nothing particular)
N RESULT ; TRUE if expected string seen, FALSE if not
N X,I,J,T,FIRST S FIRST=1
S X(0)="start at ",T(0)=$H
F I=1:1:100 R X(I):TIMEOUT Q:'$T S T(I)=$H
K X(I) S I=I-1 ; the one it timed out on
F J=1:1:I D
. I X(J)="" S X(J)="null"
. S X="at "_T(J)_": "_X(J)
. N I F I=$L(X):-1:1 I $E(X,I)?1C D
. . S X=$E(X,1,I-1)_"\"_$A(X,I)_$E(X,I+1,$L(X))
. D LOG("X("_J_")="_X)
I I=100 D LOG("OVERFLOW reading modem's response to command!")
N % S %="" F J=1:1:I S %=%_X(J)
Q %[EXPECT
TESTDONE I ISOPEN D CLOSE^ABSPOSAB(DEST)
N MSG I X D
. S MSG="Test FAILED, X="_X
E S MSG="Test SUCCEEDED"
D LOG(MSG)
D RELSLOT^ABSPOSL
U $P W "D PRINT",U,$T(+0)," or D PRINTLOG^ABSPOSL(",SLOT,") to see log file again.",!
Q
TEST1 ; open / use / close
D TESTINIT Q:'DEST
D TESTID("TEST1")
D OPEN I X G TESTDONE
D LOG("Testing the USE command")
U IO
D LOG^ABSPOSL("The USE command works okay")
D CLOSE
G TESTDONE
Q
TEST2 ; test a simple command - ATE0, echo off
D TESTINIT Q:'DEST D TESTID("TEST2")
D OPEN I X G TESTDONE
D COMMAND("E0"),READ(10,"OK")
G TESTDONE
TEST3 ; test the software reset using the ATZ
D TESTINIT Q:'DEST D TESTID("TEST3")
D OPEN I X G TESTDONE
S X=$$ATZ^ABSPOSAB(DEST)
G TESTDONE
TEST4 ; test the modem status command
D TESTINIT Q:'DEST D TESTID("TEST4")
D OPEN I X G TESTDONE
S X=$$MODEMSTS^ABSPOSAB(DEST)
G TESTDONE
TEST5 ; test dialing and connecting
D TESTINIT Q:'DEST D TESTID("TEST5")
S X=$$CONNECT^ABSPOSAA(DEST) I X G TESTDONE
S ISOPEN=1
S X=$$WAITCHAR^ABSPOSAW(DEST,$C(5),30) ; ENQ expected
G TESTDONE
ABSPOSUT ; IHS/FCS/DRS - POS utilities - testing modem ;
+1 ;;1.0;PHARMACY POINT OF SALE;;JUN 21, 2001
+2 QUIT
+3 ; D DIR to get a directory of available tests
DIR ;
+1 NEW I,X
FOR I=1:1
SET X=$TEXT(+I)
IF X=""
QUIT
Begin DoDot:1
+2 IF X'?1"TEST".E
QUIT
+3 IF $PIECE(X," ")="TESTINIT"
QUIT
+4 IF $PIECE(X," ")="TESTDONE"
QUIT
+5 IF $PIECE(X,"(")="TESTID"
QUIT
+6 WRITE X,!
End DoDot:1
+7 QUIT
+8 ; DEST = pointer to dial out, 9002313.55
+9 ; IO = the IO device associated with DEST
+10 ; SLOT = pointer to logging in ^ABSPECP("LOG",...)
+11 ; ISOPEN is true if device is open (and close needed on exit)
+12 ; ECHO is true so LOG^ABSPOSL(SLOT) echoes to your screen as well
+13 ; D PRINT in this routine prints what's in SLOT
+14 ; or later you can DO PRINTLOG^ABSPOSL(SLOT)
+15 ; All tests finish via TESTDONE label.
GETDEST ;
+1 NEW DIC,X,Y,DTIME,DLAYGO,DINUM
+2 SET DIC=9002313.55
SET DIC(0)="AENZ"
+3 DO ^DIC
WRITE !
+4 IF Y<0
SET DEST=""
QUIT
+5 SET DEST=+Y
+6 SET IO=$$IO^ABSPOSA(DEST)
+7 QUIT
TESTINIT IF '$DATA(DEST)
DO GETDEST
IF 'DEST
QUIT
+1 SET ECHO=1
SET ISOPEN=0
+2 DO INIT^ABSPOSL()
+3 SET SLOT=$$GETSLOT^ABSPOSL
+4 WRITE "Logging is to slot ",SLOT,"; D PRINT to display it again",!
+5 DO LOG("Testing dial out #"_DEST_" "_$PIECE(^ABSP(9002313.55,DEST,0),U)_" on device "_IO)
+6 SET SLOT=$$GETSLOT^ABSPOSL
+7 QUIT
TESTID(X) DO LOG("This is "_X_U_$TEXT(+0)_": "_$PIECE($TEXT(@X)," ",2,255))
QUIT
OPEN ; do all the OPENing here so it sets ISOPEN
+1 ; sets X = zero if success, nonzero if failure
+2 IF ISOPEN
Begin DoDot:1
+3 DO LOG("apparently the device we're opening is already open")
+4 DO LOG("So close it first...")
+5 DO CLOSE
End DoDot:1
+6 SET X=$$OPEN^ABSPOSAB(DEST)
+7 IF 'X
SET ISOPEN=1
+8 IF '$TEST
DO LOG("OPEN failed, error code ="_X)
+9 QUIT
CLOSE SET X=$$CLOSE^ABSPOSAB(DEST)
+1 IF 'X
SET ISOPEN=0
+2 IF '$TEST
DO LOG("CLOSE failed, error code ="_X)
+3 QUIT
PRINT DO PRINTLOG^ABSPOSL(SLOT)
+1 WRITE "(This came from the log file in ^ABSPECP(""LOG"",",SLOT,")",!
+2 QUIT
LOG(X) DO LOG^ABSPOSL(X,ECHO)
QUIT
GETCMD(X) ;
+1 IF X="ECHO OFF"
QUIT "E0"
+2 IF X="RESET"!(X="ATZ")
QUIT "Z"
+3 IF X="GET STATUS"
QUIT "I0"
+4 DO IMPOSS^ABSPOSUE("P","TI","Bad command "_X,,"GETCMD",$TEXT(+0))
+5 QUIT
COMMAND(X) ;issue a command directly to the modem
+1 IF X'?1"AT".E
SET X="AT"_X
+2 DO LOG("Issue modem command "_X)
+3 USE IO
WRITE X,$CHAR(13)
+4 QUIT
READ(TIMEOUT,EXPECT) ; read result of a modem command
+1 ; returns true if expected string found, false if not
+2 ; and sets X=0 if expected string found, nonzero if not found
+3 ; (beware - opposite meanings!)
+4 IF '$DATA(EXPECT)
SET EXPECT=""
+5 SET X='$$READ1(EXPECT)
+6 IF EXPECT]""
IF X
DO LOG("Did not receive expected string "_EXPECT_" in timeout "_TIMEOUT)
+7 IF $QUIT
QUIT 'X
QUIT
READ1(EXPECT) ; expecting EXPECT string (null if nothing particular)
+1 ; TRUE if expected string seen, FALSE if not
NEW RESULT
+2 NEW X,I,J,T,FIRST
SET FIRST=1
+3 SET X(0)="start at "
SET T(0)=$HOROLOG
+4 FOR I=1:1:100
READ X(I):TIMEOUT
IF '$TEST
QUIT
SET T(I)=$HOROLOG
+5 ; the one it timed out on
KILL X(I)
SET I=I-1
+6 FOR J=1:1:I
Begin DoDot:1
+7 IF X(J)=""
SET X(J)="null"
+8 SET X="at "_T(J)_": "_X(J)
+9 NEW I
FOR I=$LENGTH(X):-1:1
IF $EXTRACT(X,I)?1C
Begin DoDot:2
+10 SET X=$EXTRACT(X,1,I-1)_"\"_$ASCII(X,I)_$EXTRACT(X,I+1,$LENGTH(X))
End DoDot:2
+11 DO LOG("X("_J_")="_X)
End DoDot:1
+12 IF I=100
DO LOG("OVERFLOW reading modem's response to command!")
+13 NEW %
SET %=""
FOR J=1:1:I
SET %=%_X(J)
+14 QUIT %[EXPECT
TESTDONE IF ISOPEN
DO CLOSE^ABSPOSAB(DEST)
+1 NEW MSG
IF X
Begin DoDot:1
+2 SET MSG="Test FAILED, X="_X
End DoDot:1
+3 IF '$TEST
SET MSG="Test SUCCEEDED"
+4 DO LOG(MSG)
+5 DO RELSLOT^ABSPOSL
+6 USE $PRINCIPAL
WRITE "D PRINT",U,$TEXT(+0)," or D PRINTLOG^ABSPOSL(",SLOT,") to see log file again.",!
+7 QUIT
TEST1 ; open / use / close
+1 DO TESTINIT
IF 'DEST
QUIT
+2 DO TESTID("TEST1")
+3 DO OPEN
IF X
GOTO TESTDONE
+4 DO LOG("Testing the USE command")
+5 USE IO
+6 DO LOG^ABSPOSL("The USE command works okay")
+7 DO CLOSE
+8 GOTO TESTDONE
+9 QUIT
TEST2 ; test a simple command - ATE0, echo off
+1 DO TESTINIT
IF 'DEST
QUIT
DO TESTID("TEST2")
+2 DO OPEN
IF X
GOTO TESTDONE
+3 DO COMMAND("E0")
DO READ(10,"OK")
+4 GOTO TESTDONE
TEST3 ; test the software reset using the ATZ
+1 DO TESTINIT
IF 'DEST
QUIT
DO TESTID("TEST3")
+2 DO OPEN
IF X
GOTO TESTDONE
+3 SET X=$$ATZ^ABSPOSAB(DEST)
+4 GOTO TESTDONE
TEST4 ; test the modem status command
+1 DO TESTINIT
IF 'DEST
QUIT
DO TESTID("TEST4")
+2 DO OPEN
IF X
GOTO TESTDONE
+3 SET X=$$MODEMSTS^ABSPOSAB(DEST)
+4 GOTO TESTDONE
TEST5 ; test dialing and connecting
+1 DO TESTINIT
IF 'DEST
QUIT
DO TESTID("TEST5")
+2 SET X=$$CONNECT^ABSPOSAA(DEST)
IF X
GOTO TESTDONE
+3 SET ISOPEN=1
+4 ; ENQ expected
SET X=$$WAITCHAR^ABSPOSAW(DEST,$CHAR(5),30)
+5 GOTO TESTDONE