COMMON sgcode$, atten$, sgen$, ch$, ctr$
SCREEN 8
COLOR 1, 1

CLS
DIM fr(20)
DIM lev(20)
DIM fr$(20)
DIM lev$(20)
DIM inlev(20)

sgen = 1
atten$ = "7"

ieee:    
'initialise gpib
  OPEN "ieeectrl" FOR RANDOM AS #1
  OPEN "ieeedata" FOR RANDOM AS #2
  PRINT #1, "init" + CHR$(13)
  PRINT #1, "clear" + CHR$(13)
  PRINT #1, "to 10 end=13 eos=13" + CHR$(13)
  SLEEP 5
GOTO test

mar:
IF sgen = 2 THEN RETURN
  IOCTL #1, "3" + CHR$(13)
  IOCTL #2, mar$ + CHR$(13)
RETURN

adret:
IF sgen = 1 THEN RETURN
  IOCTL #1, "3" + CHR$(13)
  IOCTL #2, adret$ + CHR$(13)
RETURN

at:
  IOCTL #1, atten$ + CHR$(13)
  IOCTL #2, att$ + CHR$(13)
RETURN


test:
att$ = "A 100,": GOSUB at
mar$ = "*RST": GOSUB mar
mar$ = "mod:OFF": GOSUB mar
adret$ = "F1000000": GOSUB adret
adret$ = "A -50": GOSUB adret
SLEEP 2

mar$ = "*idn?": GOSUB mar

idn$ = IOCTL$(#2)
idn$ = MID$(idn$, 40, 3)
IF idn$ = "038" THEN sgen$ = "CH_039"
IF idn$ = "021" THEN sgen$ = "CH_0117"
IF idn$ <> "038" AND idn$ <> "021" THEN sgen$ = "CH_0108"

mar$ = "imode normal": GOSUB mar

SLEEP 3
IF sgen$ = "CH_0108" THEN sg$ = "Adret  740 A " ELSE sg$ = "Marconi 2031 "

OPEN "c:\qb\gpr4200\siggen\" + sgen$ FOR INPUT AS #5
start:
CLS
COLOR 11
LOCATE 1, 15
PRINT "Signal Generator Correction Values"
LOCATE 2, 15
PRINT "컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴"
COLOR 14
LOCATE 4, 5
PRINT sg$; TAB(35); "Chase No. "; sgen$
PRINT
PRINT TAB(5); "Frequency";
PRINT TAB(20); "Current level";

lp = 1
DO
  READ fr(lp)
  COLOR 10
  PRINT TAB(5); fr(lp); " MHz";
  INPUT #5, in$
  inlev(lp) = VAL(RIGHT$(in$, 5))
  COLOR 11
  PRINT TAB(20);
  PRINT USING "###.##"; inlev(lp);
  PRINT " dB";
  lp = lp + 1
LOOP UNTIL lp = 10

LOCATE 22, 10
COLOR 12
PRINT "Do you wish to update these values ( y/n ) ";
INPUT ud$
  IF ud$ = "n" OR ud$ = "N" THEN GOTO tests
  IF ud$ = "y" OR ud$ = "Y" THEN GOTO indata
GOTO start


indata:
CLS
COLOR 11
LOCATE 1, 15
PRINT "Signal Generator Correction Values"
LOCATE 2, 15
PRINT "컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴"
COLOR 14
LOCATE 4, 5
PRINT sg$; TAB(35); "Chase No. "; sgen$
PRINT
PRINT TAB(5); "Frequency";
PRINT TAB(20); "Current level";
   
    att$ = "A 0,": GOSUB at
    mar$ = "rflv 0 dbm": GOSUB mar
    mar$ = "rflv:ON": GOSUB mar
    mar$ = "cfrq 20 mhz": GOSUB mar
    adret$ = "F20000000": GOSUB adret
    adret$ = "A 0": GOSUB adret

lp = 1
DO
     fr$ = STR$(fr(lp))
     mar$ = "cfrq " + fr$ + " mhz": GOSUB mar
     adfreq = fr(lp) * 1000000
     adfreq$ = STR$(adfreq)
     adret$ = "f" + adfreq$: GOSUB adret
 
  COLOR 10
  PRINT TAB(5); fr(lp); " MHz";
  COLOR 11
  PRINT TAB(20);
  PRINT USING "###.##"; inlev(lp);
  PRINT " dB";
  PRINT TAB(50);
  COLOR 12
  INPUT lev(lp)
  lp = lp + 1
LOOP UNTIL lp = 10

att$ = "A 100,": GOSUB at
mar$ = "*rst": GOSUB mar
adret$ = "A -50": GOSUB adret


CLOSE
save:
COLOR 14
LOCATE 22, 10
PRINT "Do you wish to save the new values (y/n) ";
INPUT yn$
 
  IF yn$ = "n" OR yn$ = "N" THEN GOTO tests
  IF yn$ = "Y" OR yn$ = "y" THEN
   
    OPEN "c:\qb\gpr4200\siggen\" + sgen$ FOR OUTPUT AS #5
    lp = 1
    DO
      fr$ = STR$(fr(lp))
      lev$ = STR$(lev(lp))
      PRINT #5, fr$,
      PRINT #5, lev$
      lp = lp + 1
    LOOP UNTIL lp = 10
    PRINT : PRINT "Saving correction data"
  ELSE
     GOTO save
  END IF

tests:
  sgcode$ = STR$(sgen)
  CLOSE
  PRINT : PRINT "Loading tests"
  CHAIN "c:\qb\gpr4200\menu"
 
END

DATA 68,90,110,130,150,170,190,210,230



