10    ! ARBSRC
20    !----------------------------------------------------------------------
30    ! HPBASIC/IBASIC Program; ARB_EXAMPLE
40    ! This program sets up a data register, generates data of the correct
50    ! size and downloads it into the instrument. It then allows the user to
60    ! view the results, if the source is connected to channel 1. This program
70    ! will also distinguish between IBASIC and HPBASIC run modes.
80    !----------------------------------------------------------------------
90    !
100   ON ERROR GOTO Not_ibasic     ! auto selection of proper select code
110   Device=800                   ! device select code from IBASIC
120   CLEAR Device
130   GOTO Start_prog
140   !
150 Not_ibasic: !
160   Device=711                   ! device select code from external computer
170 Start_prog: !
180   OFF ERROR
190   !
200   !
210   ASSIGN @Analyzer TO Device   ! allows code to be address independent
220   !
230   ! assign an i/o path for binary transfers
240   ASSIGN @Analyzer_bin TO Device;FORMAT OFF
250   !
260   OUTPUT @Analyzer;"*RST"              ! reset the analyzer
270   OUTPUT @Analyzer;"INP2 OFF"          ! put the instrument in 1 channel
280   OUTPUT @Analyzer;"ABOR;:INIT; *WAI"  ! start measurement
290   OUTPUT @Analyzer;"INIT:CONT OFF"     ! pause after the first measurement
300   !
310   INTEGER Res,Max_i,T              ! reserve space for variables
320   DIM Tones(1)                     ! reserve space for array
330   DIM D(20000)                     ! largest expected size for D array
340   RAD                              ! select radians for units of angle
350   !
360   Span=102400                      ! set the span to maximum
370   Res=400                          ! set the resolution
380   !
390   Tones(0)=7680                    ! select the freq of the first tone
400   Tones(1)=32000                   ! select the freq of the second tone
410   !
420   SELECT (Res)                     ! selections relating resolution
430   CASE 100                         ! array size
440     Max_i=255
450   CASE 200
460     Max_i=511
470   CASE 400
480     Max_i=1023
490   CASE 800
500     Max_i=2047
510   CASE ELSE 
520     PRINT "ILLEGAL MEASURMENT RESOLUTION"
530     PAUSE
540   END SELECT 
550   !
560   !
570   REDIM D(Max_i)                   ! allocate memory for the array
580   !
590   Dt=Res/Span/(Max_i+1)
600   FOR T=0 TO 1                     ! pass through for each tone
610     FOR I=0 TO Max_i
620       D(I)=D(I)+SIN(2*PI*Tones(T)*I*Dt) ! compute and sum tones
630     NEXT I
640   NEXT T
650   !
660   ! open up a display window if in IBASIC on the analyzer
670   IF Device=800 THEN
680     OUTPUT @Analyzer;"DISP:FORM QUAD; PROG LOW"
690   ELSE 
700     OUTPUT @Analyzer;"DISP:FORM ULOW;"
710   END IF 
720   !
730   FOR I=0 TO 9      ! print out the first ten values in register D1
740     PRINT D(I)
750   NEXT I
760   !
770   ! Setup the instrument for data loading
780   OUTPUT @Analyzer;"FORM:DATA REAL, 64"   ! 64 bit binary format
790   !
800   ! insure that trace A has time data
810   OUTPUT @Analyzer;"CALC1:FEED 'XTIM:VOLT 1';*WAI"
820   !
830   ! Save trace A time data into D1.  This "conditions" the data
840   ! register so will accommodate time data to be loaded into it
850   ! from this program.
860   OUTPUT @Analyzer;"TRAC:DATA D1,TRAC1;*WAI"
870   !
880   ! Now, output the two tone data to be output on the source.
890   OUTPUT @Analyzer;"TRAC:DATA D1,#0";    ! output the block header
900   OUTPUT @Analyzer_bin;D(*)              ! output the data in binary
910   OUTPUT @Analyzer;CHR$(10) END          ! output a line feed with EOI
920                                          ! at the end of the data block
930   !
940   ! setup the source to output the signal in the data register
950   OUTPUT @Analyzer;"SOUR:FUNC USER "     ! set the cource to the user mode
960   OUTPUT @Analyzer;"SOUR:USER D1"        ! source output from register D1
970   OUTPUT @Analyzer;"SOUR:USER:REP ON"    ! continous source repeat of D1
980   OUTPUT @Analyzer;"SOUR:VOLT .1 VPK"    ! set the source level
990   OUTPUT @Analyzer;"OUTP ON"             ! turn on the source output
1000  !
1010  OUTPUT @Analyzer;"INIT;*WAI;"          ! start measurements
1020  !
1030  END
