	SUBROUTINE ECHO( OUTBUF, NCHAR, ISTAT)
C  Jim Walker, Aug 1987 for Diffrac-500 with a Radix Databox.
C  This is for a VAX talking to a RADIX DATABOX
C  Send NCHAR characters in OUTBUF to the terminal on ICHAN 
C  and wait up to 5 seconds for each to come back.
C  ISTAT returns QIO error code or -2 for unexpected character returned
C  or -1 for timeout error.
C
	IMPLICIT NONE
	INCLUDE 'INTERFACE.COM'
	CHARACTER*(*) OUTBUF
	CHARACTER*1 INBUF
	INTEGER*4 SYS$QIOW, ISTAT, NCHAR, I
	INCLUDE '($IODEF)'
	INCLUDE '($SSDEF)'
	PARAMETER TIMEOUT=5	! use at least 2 seconds.
C
      DO 10, I=1,NCHAR
	ISTAT = SYS$QIOW( , %VAL(ICHAN),
	1	%VAL( IO$_READPROMPT + IO$M_NOECHO + IO$M_TIMED ),
	2	IOSB, , ,
	3	%REF(INBUF), %VAL(1), %VAL(TIMEOUT), , 
	4	%REF(OUTBUF(I:I)), %VAL(1) )
C
	IF(.NOT.ISTAT) CALL LIB$SIGNAL(%VAL(ISTAT))
	IF(ISTAT) ISTAT=IOSB(1)
	IF(IOSB(1).EQ.SS$_TIMEOUT) ISTAT = -1
	IF(IOSB(1).NE.SS$_NORMAL) GOTO 99
	IF(INBUF.NE.OUTBUF(I:I)) GOTO 98
10    CONTINUE
      GOTO 99
98	ISTAT = -2
99	IF(DEBUG) TYPE*,'ECHO ISTAT=',ISTAT
	RETURN
	END
