	PROGRAM RMDMO1

C+
C
C                              Copyright (C) 1981
C         Digital Equipment Corporation, Maynard, Massachusetts 01754
C
C   This software is furnished under a license and may be used and  copied
C   only  in  accordance  with  the  terms  of  such  license and with the
C   inclusion of the above copyright notice.  This software or  any  other
C   copies  thereof may not be provided or otherwise made available to any
C   other person.  No title to and ownership of  the  software  is  hereby
C   transferred.
C
C   The information in this software is subject to change  without  notice
C   and  should  not  be  construed  as  a commitment by Digital Equipment
C   Corporation.
C
C   Digital Equipment Corporation assumes no responsibility for the use or
C   reliability  of  its  software  on  equipment which is not supplied by
C   Digital Equipment Corporation.
C
C+
C
C	Version: 	1.0
C
C	Date: 		20-October-1982
C
C	Authors: 	Thomas A. Turano
C
C	Purpose:	This program demonstrates several REAL11
C			functions using the intertask communications
C			feature of RSX11S DECNET.
C
C			A task RMDEMO1 on the VAX host requests that
C			this task be started on the LABSTATION 23 node.
C			This task then does the following:
C
C			    1. Collects 3 buffers of data (at 2048 words/
C			buffer) from an A/D on the LABSTATION and transmits 
C			the data as each buffer is collected across DECNET to 
C			the VAX	for display and storage.
C			
C				This rountine makes use of the MNCAD
C			and MNCKW modules on the remote node.
C				
C-

C
C	set up arrays
C

	DIMENSION istat(40)		!network status buffer
	DIMENSION ibuff1(2048),ibuff2(2048),ibuff3(2048)!a/d collection buffers
	BYTE trans1(4096),trans2(4096),trans3(4096)!transmission buffers 
	BYTE mlbx(98)			!mailbox buffer
	EQUIVALENCE (ibuff1(1),trans1(1))!trans1 and ibuff1 share space
	EQUIVALENCE (ibuff2(1),trans2(1))!trans2 and ibuff2 share space
	EQUIVALENCE (ibuff3(1),trans3(1))!trans3 and ibuff3 share space

C
C	set up variables
C
C		errflg		error flag
C		ibufno 		number of next buffer in user queue
C		ibufsz		buffer size
C		icount		number of buffers transmitted
C		ind		success indicator
C		iost		I/O status block
C		iprset		clock preset
C		irate		clock rate
C		mltype		mailbox buffer type

		INTEGER*2 errflg,ibufno,ibufsz,icount,ind,iost(2)
		INTEGER*2 iprset,irate,mltype,mstat(3)

C
C	set error flag to 0
C

	errflg=0	

C
C	prepare for DECnet communications by:
C
C		1. accessing the network
C		2. getting the network data
C		3. accepting the connect request from the host
C

	CALL opnntw(3,iost,mstat)	!open network
	  IF(iost(1).NE.1)GOTO 999	!if error simply exit
	CALL gndntw(iost,mltype,98,mlbx)!get network data
	  IF(iost(1).LT.0)GOTO 989	!if error close net first
20	CALL accntw(4,iost,mlbx)	!accept connect request
	  IF(iost(1).EQ.1)GOTO 30	!if connected go on to the REAL11 part
	  IF(iost(1).EQ.-1)GOTO 20	!if resources not available try again
	  IF(iost(1).LE.-3)GOTO 989	!if anything else shutdown

C
C	prepare for REAL11 tasks
C	
C
C		1. set the buffers for the A/D conversion
C

30	CONTINUE
	CALL setibf(istat,ind,,ibuff1,ibuff2,ibuff3)!initialize buffers
	  IF(ind.EQ.0)GOTO 988		!on error shut down net
	CALL rlsbuf(istat,ind,0,1,2)	!release buffers in order
	  IF(ind.EQ.0)GOTO 988		!on error shut down net

C
C		2. set the clock parameters
C

	dwell=.01			!time between samples
	CALL xrate(dwell,irate,iprset)	!get the rate
	CALL clocka(irate,iprset,ind)	!start the clock
	  IF(ind.EQ.0)GOTO 988		!on error shut down net

C
C		3. start the A/D sweep
C

	ibufsz=2048			!define the size of the buffer
	CALL adswp(istat,ibufsz,0,0,iprset,,,3,1) !start the sweep
	icount=0			!initialize to buffer counter
50	CALL iwtbuf(istat,,ibufno,ind)!wait for the buffer
	  IF(ind.EQ.1)GOTO 60		!if successful continue
	   errflg=1			!if error set flag and
	   GOTO 100			! then stop sweep
60	CONTINUE

C
C	determine which buffer is to be sent, send it and increment the
C	counter
C

	if (ibufno .eq. 0) goto 65
	if (ibufno .eq. 1) goto 70
	if (ibufno .eq. 2) goto 75
65	CONTINUE
	 CALL sndntw(4,iost,4096,trans1)	!send buffer1
	 GOTO 80
70	CONTINUE
	  CALL sndntw(4,iost,4096,trans2)	!send buffer2
	  GOTO 80
75	CONTINUE				
	  CALL sndntw(4,iost,4096,trans3)	!send buffer3
80	CONTINUE
	  IF(iost(1).EQ.1)GOTO 100		!if successful continue
	  errflg=1				!else set error flag to 1

C
C	collect only 3 buffers then stop the sweep
C

100	CONTINUE
	icount=icount+1			!increment counter
	  IF(errflg.EQ.1)GOTO 110	!if error flag set stop the sweep
	CALL rlsbuf(istat,ind,ibufno)	!release the buffer 
	  IF(ind.EQ.0)GOTO 110		!on error stop the sweep
	  IF(icount.LT.3)GOTO 50	!if not N sent get next buffer
110	CONTINUE
	CALL stpswp(istat,0,ind)	!stop the sweep

C
C	terminate the link
C
C		1. disconnect the network
C		2. close the network

988	CONTINUE
	CALL dscntw(4,iost)		!disconnect net
989	CONTINUE
	CALL clsntw(iost(1))		!close net
999	CONTINUE
	CALL exit
	END
