	SUBROUTINE NULL( OUTBUF, NCHAR, ISTAT)
C  Jim Walker, Aug 1987.
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 2 seconds for verification.
C  Blanks are skipped.
C  ISTAT returns QIO error code or -2 for Bell character recieved.
C  ISTAT = 1 when terminator is null (databox ready for input)
C  ISTAT = -1 for timeout error
C  Terminators for read will be Null and Bell (^@ and ^G)
C
	IMPLICIT NONE
C  Interface specific common blocks.
	INCLUDE 'INTERFACE.COM'
	CHARACTER*(*) OUTBUF
	COMMON /RADIXC/ INBUF
	CHARACTER*255 INBUF
C
	PARAMETER TIMEOUT=2	! use at least 2 seconds
	INTEGER*4 SYS$QIOW, ISTAT, NCHAR, I, J, MASK(2)
	DATA MASK/0,129/	! Terminator mask.
C
C  Get a parameter definitions for system codes.
	INCLUDE '($IODEF)'
	INCLUDE '($SSDEF)'
C
C  Send the characters one at a time.
      DO 30, I=1,NCHAR
	IF(OUTBUF(I:I).EQ.' ') GOTO 30
C
C  Send the character and wait for a Null.
	ISTAT = SYS$QIOW( , %VAL(ICHAN),
	1	%VAL( IO$_READPROMPT+IO$M_NOECHO+IO$M_TIMED+IO$M_PURGE ),
	2	IOSB, , ,
	3	%REF(INBUF), %VAL(255), %VAL(TIMEOUT), MASK, 
	4	%REF(OUTBUF(I:I)), %VAL(1) )
C
C  If there was a "directive error" then signal it and bail out.
	IF(.NOT.ISTAT) THEN
		CALL LIB$SIGNAL(%VAL(ISTAT))
		GOTO 99
	ENDIF
C
C  Now we only worry about I/O errors.
	IF(ISTAT) ISTAT=IOSB(1)
C
C  If we timed out, check input buffer to see if character was echoed.
	IF(IOSB(1).EQ.SS$_TIMEOUT) THEN
		DO 10, J=1,IOSB(2)
C  Character was echoed, continue normally.
		IF(INBUF(J:J).EQ.OUTBUF(I:I)) THEN
			ISTAT = 1
			GOTO 20
			ENDIF
10		CONTINUE
C
C  Character not found, bail out with ISTAT = -1
		ISTAT = -1
		GOTO 99
	ENDIF
C
C  If there was an input error then bail out.
	IF(.NOT.IOSB(1)) THEN
		CALL LIB$SIGNAL(%VAL(IOSB(1)))
		GOTO 99
	ENDIF
C
C  In debug mode print data recieved from interface.
20	IF(DEBUG) THEN
	   IF(IOSB(1).EQ.SS$_TIMEOUT) TYPE*,' Soft timeout'
	   TYPE *,'"',(INBUF(J:J),J=1,IOSB(2)),'"'
14	   FORMAT(' ',72A1,'-')
	ENDIF
C
C  If Bell character was recieved than bail out with ISTAT=-2.
	IF(IOSB(1).EQ.SS$_NORMAL .AND. IOSB(3).EQ.7) THEN
	   ISTAT = -2
	   GOTO 99
	ENDIF
C
C  Go through main loop again unless we are done.
30    CONTINUE
C
C All done here, go back to main program.
C
99    IF(DEBUG) TYPE*,'NULL ISTAT=',ISTAT
      RETURN
      END
