! Instrument Driver for the HP 54615B Digitizing Oscilloscope Family
! including the HP54615B and HP54616B
!Rev. A.00.04
! Copyright (C) Hewlett-Packard Co. 1996, 1997.  All rights reserved.
! Modified 1/17/97 by WAB - Added 2500 pt Waveforms & fixed bugs with NUM_POINTS
! Modified 1/29/97 by WAB - allowed for recovery of Blank channel after DIGitize
REVISION 2.00;

INITIALIZE RESET;
ERROR COMPONENT stat_err;
STORE COMPONENT STORE_STATE;
RECALL COMPONENT RECALL_STATE;
update component WF_DATA;

component bogus nogen noerrcheck;
    type integer;
    initial invalid;
    set actions;
        if livemode then;
            output string "*CLS; *SRE 32; *ESE 1;"; flush;
            output string "*OPC?; *OPC"; flush;
            if livemode then;
              fetch addr;
              fetch 100;
              lt;
              if stack then;  ! serial
                wait time 0.01;
              else;           !hpib
                wait spoll bit 5;
              end if;
            end if;
            enter stack format K;
        end if;
        invalidate bogus;
    end actions;
end component;

COMPONENT OPTIONS;
  TYPE DISCRETE;
  VALUES NORMAL,TEST_AUTOMATION,MEAS_STORAGE;
  INITIAL NORMAL;
  GET ACTIONS;
    OUTPUT STRING "*OPT?";
    ENTER OPTIONS FORMAT K;
    FETCH OPTIONS;
    dup;
    FETCH 2; EQ;
    fetch 52; eq; or;
    IF STACK THEN;
       GOSUB Kill_meas_stor_fns;
       HIDE DISPLAY_SUBSYSTEM, DISPLAY_MEM_CONTROLS;
    END IF;
  END ACTIONS;
END COMPONENT;

COMPONENT RESET NOTSAVED;
  TYPE INTEGER;
  INITIAL DONTCARE;
  coupled NUM_POINTS,trig_level,acq_points,COMPLETION;
  SET ACTIONS;
    CLEAR; output string "*CLS"; flush;
    OUTPUT STRING "*RST"; FLUSH;
    output string "DISP:CONN OFF"; ! turn vectors off
    POKEINITIAL; ! invalidates 'acquired' values -- waveforms, msmts, ...
    if livemode then;
      fetch addr;
      fetch 100;
      lt;
      if stack then;  ! serial.  It loses characters while resetting
        wait time 1.0;
      end if;
    end if;

    gosub set_init;
    GET OPTIONS;

  END ACTIONS;
  panel set actions;
    gosub update_trace_data;
  end actions;
END COMPONENT;

COMPONENT SUBSYSTEM NOGEN NOERRCHECK;
  TYPE DISCRETE;
  VALUES MAIN,TIMEBASE,CHANNEL,TRIGGER,MEASURE,MARKERS,
  WAVEFORM,DISPLAY,STATUS,ABOUT;
  INITIAL MAIN;
  PANEL SET ACTIONS;
        HIDE CONTROLS, STANDARD;
        HIDE CONTROLS, TIMEBASE_SUBSYSTEM;
        HIDE CONTROLS, CHANNEL_SUBSYSTEM;
        HIDE CONTROLS, TRIGGER_SUBSYSTEM;
        HIDE CONTROLS, MARKER_SUBSYSTEM;
        HIDE CONTROLS, MEASURE_SUBSYSTEM;
        HIDE CONTROLS, WAVEFORM_SUBSYSTEM;
        HIDE CONTROLS, DISPLAY_SUBSYSTEM;
        HIDE CONTROLS, STATUS_PANEL;
        HIDE CONTROLS, ABOUT_PANEL;

        SELECT SUBSYSTEM;
        CASE MAIN;
          SHOW CONTROLS, STANDARD; output string ":MENU 1";
        CASE TIMEBASE;
          SHOW CONTROLS, TIMEBASE_SUBSYSTEM; output string ":MENU 9";
        CASE CHANNEL;
          SHOW CONTROLS, CHANNEL_SUBSYSTEM; set CHANNEL;
        CASE TRIGGER;
          SHOW CONTROLS, TRIGGER_SUBSYSTEM; output string ":MENU 6";
        CASE MARKERS;
          SHOW CONTROLS, MARKER_SUBSYSTEM; output string ":MENU 12";
        CASE MEASURE;
          SHOW CONTROLS, MEASURE_SUBSYSTEM; output string ":MENU 11";
        CASE WAVEFORM;
          SHOW CONTROLS, WAVEFORM_SUBSYSTEM; output string ":MENU 15";
        CASE DISPLAY;
          SHOW CONTROLS, DISPLAY_SUBSYSTEM; output string ":MENU 15";
        CASE 'STATUS';
          SHOW CONTROLS, STATUS_PANEL; output string ":MENU 16";
        CASE 'ABOUT';
          SHOW CONTROLS, ABOUT_PANEL; output string ":MENU 1";
        END SELECT;

      END ACTIONS;
END COMPONENT;

COMPONENT CHARSTRING NOTSAVED NOGEN NOERRCHECK;
  TYPE STRING 128;
  INITIAL INVALID;
END COMPONENT;

COMPONENT NUM_BUFFER NOTSAVED NOGEN NOERRCHECK;
  TYPE CONTINUOUS;
  INITIAL INVALID;
END COMPONENT;

component disp_temp notsaved nogen noerrcheck;
    type integer;
end component;

!=======================
! LEARN STRING SUPPORT
!=======================

COMPONENT LEARN_LENGTH;
  TYPE INTEGER;
END COMPONENT;

COMPONENT LEARN_STRING;
  TYPE IARRAY 218;
  INITIAL INVALID;
END COMPONENT;

COMPONENT LEARN_BYTE;
  TYPE STRING 2;
END COMPONENT;

COMPONENT STORE_STATE NOTSAVED NOGEN NOERRCHECK;
  TYPE INTEGER;
  SET ACTIONS;
    ! Binary Block Format:
    !
    ! '#800000121' 10-byte header
    ! < data block > 218-byte binary data
    ! 'LF' 1-byte LF terminator

    ! get learn string from instrument ...
    OUTPUT STRING ":SYSTEM:SETUP?";
    ! skip the header byte '#'; read the next 218 bytes
    ENTER STACK FORMAT "#,XX,DDDDDDDD";   ! #8<8 digits of length>
    DUP;
    STORE LEARN_LENGTH;
    FETCH 2;
    IDIV;
    ENTER LEARN_STRING FORMAT INT16 0 STACK;

    ! consume 'LF' terminator ...
    FETCH LEARN_LENGTH;
    FETCH 0;
    BIT;
    IF STACK THEN;  !Odd # of bytes
      ENTER LEARN_BYTE FORMAT "A";
    ELSE;
      ENTER CHARSTRING FORMAT "#,A";
    END IF;
  END ACTIONS;
END COMPONENT;

COMPONENT RECALL_STATE NOTSAVED NOGEN NOERRCHECK;
  TYPE INTEGER;
  SET ACTIONS;
    ! download learn string to instrument
    OUTPUT STRING ":SYSTEM:SETUP #8";
    OUTPUT LEARN_LENGTH FORMAT "ZZZZZZZZ";
    FETCH LEARN_LENGTH; FETCH 2;IDIV;
    OUTPUT LEARN_STRING INT16 STACK;
    FETCH LEARN_LENGTH;
    FETCH 0;
    BIT;
    IF STACK THEN;  !Odd # of bytes
      OUTPUT LEARN_BYTE FORMAT "A";
    END IF;
    OUTPUT STRING " ";
    ! sync remaining comp's in driver -- prevents incremental SET's ...
    VALIDATE ALL; ! triggers 'UPDATE ACTIONS' to react ...
  END ACTIONS;
  PANEL SET ACTIONS;
    GOSUB UPDATE_TRACE_DATA;
  END ACTIONS;
END COMPONENT;

! =========================
! SYSTEM UTILITIES
! =========================

COMPONENT RUN NOTSAVED;
  TYPE INTEGER;
  INITIAL 0;
  SET ACTIONS;
    OUTPUT STRING ":RUN;";
  END ACTIONS;
  PANEL SET ACTIONS;
    ! May not capture data on slower sweep speeds ...
    GOSUB UPDATE_TRACE_DATA;
  END ACTIONS;
END COMPONENT;

ACTIONS FLUSH_ERR_QUEUE;

  loop;
        OUTPUT STRING ":SYST:ERR?"; ENTER STACK FORMAT K;
        fetch 0; eq; exit if stack;
  end loop;

END ACTIONS;

actions wait_for_response;
  if livemode then;
    fetch addr;
    fetch 100;
    lt;
    if stack then;  !serial
     wait time 0.01;
    else;           !hpib
     wait spoll bit 4;
    end if;
  end if;
end actions;

!******************** STATUS COMPONENTS ******************************
! error component
 

component stat_err notsaved noerrcheck;
    type integer;
    initial 0,invalid;
    get actions;
        output string ":SYST:ERR?";
        enter stat_err format 'K';
        select stat_err;
            CASE 0;
                  ! no error ...
            CASE ELSE;
                  GOSUB FLUSH_ERR_QUEUE;
        end select;
    end actions;
end component;

!    status panel components

component stat_evnt_evr notsaved;
    type integer;
    initial 0,invalid;
    get actions;
        output string "*ESR?";
        enter stat_evnt_evr format 'K';
    end actions;
end component;

component stat_evnt_enr notsaved;
    type integer;
    values range 0,255;
    initial 0,invalid;
    set actions;
        output stat_evnt_enr format '"*ESE ",K';
    end actions;
    get actions;
        output string "*ESE?";
        enter stat_evnt_enr format 'K';
    end actions;
end component;

component stat_stb notsaved;
    type integer;
    initial 0,invalid;
    get actions;
        output string "*STB?";
        enter stat_stb format 'K';
    end actions;
end component;

component stat_sre notsaved;
    type integer;
    values range 0,255;
    initial 0,invalid;
    set actions;
        output stat_sre format '"*SRE ",K';
    end actions;
    get actions;
        output string "*SRE?";
        enter stat_sre format 'K';
    end actions;
end component;

component stat_opc notsaved;
    type integer;
    set actions;
        output string "*OPC";
    end actions;
end component;

component stat_opcv notsaved;
    type integer;
    initial 0,invalid;
    get actions;
        output string "*OPC?";
        enter stat_opcv format 'K';
    end actions;
end component;

component stat_wai notsaved;
    type integer;
    set actions;
        output string "*WAI";
    end actions;
end component;

component stat_self_test notsaved;
    type string 4;
    initial invalid;
    get actions;
        output string "*TST?";
        gosub wait_for_response;
        enter stack format 'K';
        if stack then;
            fetch "FAIL";
        else;
            fetch "PASS";
        end if;
        store stat_self_test;
    end actions;
end component;

!=================================
! DISPLAY SUBSYSTEM
!=================================

COMPONENT WF_TYPE;
  TYPE DISCRETE;
  VALUES NORMAL,AVERAGE,peak;
  INITIAL NORMAL;
  COUPLED HIT_COUNT, acq_points,
  VIEW_WF_CH1,VIEW_WF_CH2,VIEW_PEAK_CH1,VIEW_PEAK_CH2;
  SET ACTIONS;
    OUTPUT STRING ":ACQ:TYPE ";
    OUTPUT WF_TYPE TABLE 'NORM;','AVER;','PEAK;';
    gosub set_NUM_POINTS;
  END ACTIONS;
  GET ACTIONS;
    OUTPUT STRING ":ACQ:TYPE?;";
    ENTER CHARSTRING FORMAT K;
    SELECT CHARSTRING;
    CASE "NORM";
      FETCH (WF_TYPE)NORMAL;
    CASE "AVER";
      FETCH (WF_TYPE)AVERAGE;
    CASE "PEAK";
      FETCH (WF_TYPE)peak;
    CASE ELSE;
      FETCH WF_TYPE;
    END SELECT;
    STORE WF_TYPE;
  END ACTIONS;
  PANEL SET ACTIONS;
    GOSUB UPDATE_TRACE_DATA;
  END ACTIONS;
END COMPONENT;

COMPONENT HIT_COUNT;
  TYPE discrete;
  VALUES n8,n64,n256;
  INITIAL n8;
  SET ACTIONS;
    output string ":ACQ:COUNT ";
    OUTPUT HIT_COUNT table "8","64","256";
  END ACTIONS;
  GET ACTIONS;
    OUTPUT STRING ":ACQ:COUNT?";
    ENTER stack FORMAT K;
    SELECT stack;
    CASE 8;
      FETCH (HIT_COUNT)n8;
    CASE 64;
      FETCH (HIT_COUNT)n64;
    CASE 256;
      FETCH (HIT_COUNT)n256;
    CASE ELSE;
        fetch HIT_COUNT;
    end select;
    store HIT_COUNT;
  END ACTIONS;
  PANEL SET ACTIONS;
    GOSUB UPDATE_TRACE_DATA;
  END ACTIONS;
END COMPONENT;

COMPONENT XY_GRATICULE nogen noerrcheck;
  TYPE integer;
  initial 1;
END COMPONENT;

component disp_grid;
    type discrete;
    values off,on;
    initial on;
    set actions;
        output string ":DISP:GRID ";
        output disp_grid table "OFF","ON";
    end actions;
    panel set actions;
        if disp_grid then;
            fetch 1; store XY_GRATICULE;
        else;
            fetch 3; store XY_GRATICULE;
        end if;
    end actions;
    get actions;
        output string ":DISP:GRID?";
        enter CHARSTRING format 'K';
        select CHARSTRING;
            case "ON"; fetch (disp_grid)on;
            case "OFF"; fetch (disp_grid)off;
            case else; fetch disp_grid;
        end select;
        store disp_grid;
    end actions;
end component;

COMPONENT MERGE_PM1 NOTSAVED;
  TYPE INTEGER;
  INITIAL DONTCARE;
  SET ACTIONS;
      FETCH OPTIONS;
      FETCH 2;
      NE;
      IF STACK THEN;
       OUTPUT STRING ":MERGE PMEM1;";
      ELSE;
        NOTIFY "Not implemented in Option";
      END IF;
  END ACTIONS;
END COMPONENT;

COMPONENT MERGE_PM2 NOTSAVED;
  TYPE INTEGER;
  INITIAL DONTCARE;
  SET ACTIONS;
      FETCH OPTIONS;
      FETCH 2;
      NE;
      IF STACK THEN;
        OUTPUT STRING ":MERGE PMEM2;";
      ELSE;
        NOTIFY "Not implemented in Option";
      END IF;
  END ACTIONS;
END COMPONENT;

component upload_PM1 notsaved;
    type integer;
    set actions;
      FETCH OPTIONS;
      FETCH 2;
      NE;
      IF STACK THEN;
        output string ":DISP:SOUR PMEM1;DATA?";
        enter data_PM1 format INT16 10 8128;
        ENTER CHARSTRING FORMAT "#,A"; ! consumes 'LF' terminator
      ELSE;
        NOTIFY "Not implemented in Option";
      END IF;
    end actions;
end component;

component upload_PM2 notsaved;
    type integer;
    set actions;
      FETCH OPTIONS;
      FETCH 2;
      NE;
      IF STACK THEN;
        output string ":DISP:SOUR PMEM2;DATA?";
        enter data_PM2 format INT16 10 8128;
        ENTER CHARSTRING FORMAT "#,A"; ! consumes 'LF' terminator
      ELSE;
        NOTIFY "Not implemented in Option";
      END IF;
    end actions;
end component;

component download_PM1 notsaved;
    type integer;
    set actions;
      FETCH OPTIONS;
      FETCH 2;
      NE;
      IF STACK THEN;
        output string "*CLS; *SRE 32; *ESE 1;"; flush;
        output string ":DISP:SOUR PMEM1"; flush;
        output string ":DISP:DATA #800016256";
        output data_PM1 INT16 8128; output string " "; flush;
        output string "*OPC"; flush;
        if livemode then;
          fetch addr;
          fetch 100;
          lt;
          if stack then;  ! serial
            wait time 0.01;
          else;           !hpib
            wait spoll bit 5;
          end if;
        end if;
      ELSE;
        NOTIFY "Not implemented in Option";
      END IF;
    end actions;
end component;

component download_PM2 notsaved;
    type integer;
    set actions;
      FETCH OPTIONS;
      FETCH 2;
      NE;
      IF STACK THEN;
        output string "*CLS; *SRE 32; *ESE 1;"; flush;
        output string ":DISP:SOUR PMEM2"; flush;
        output string ":DISP:DATA #800016256";
        output data_PM2 INT16 8128; output string " "; flush;
        output string "*OPC"; flush;
        if livemode then;
          fetch addr;
          fetch 100;
          lt;
          if stack then;  ! serial
            wait time 0.01;
          else;           !hpib
            wait spoll bit 5;
          end if;
        end if;
      ELSE;
        NOTIFY "Not implemented in Option";
      END IF;
    end actions;
end component;

component erase_PM1 notsaved;
    type integer;
    set actions;
        output string ":ERASE PMEM1";
        invalidate data_PM1;
    end actions;
end component;

component erase_PM2 notsaved;
    type integer;
    set actions;
        output string ":ERASE PMEM2";
        invalidate data_PM2;
    end actions;
end component;

component data_PM1 notsaved nogen noerrcheck;
    type iarray 8128;
    initial invalid;
end component;

component data_PM2 notsaved nogen noerrcheck;
    type iarray 8128;
    initial invalid;
end component;

!>> CHAN1 views ...

COMPONENT VIEW_CH1;
  TYPE DISCRETE;
  VALUES OFF,ON;
  INITIAL ON;
  COUPLED VIEW_WF_CH1,VIEW_PEAK_CH1;
  SET ACTIONS;
    SELECT VIEW_CH1;
    CASE OFF;
      OUTPUT STRING ":BLANK CHAN1;";
    CASE ON;
      OUTPUT STRING ":STOP;:VIEW CHAN1;RUN;";
    END SELECT;
  END ACTIONS;
  PANEL SET ACTIONS;
    if VIEW_CH1 then;
            SELECT WF_TYPE;
                CASE peak; GET PEAK_CH1;
                CASE ELSE; GET WF_CH1;
            END SELECT;
      end if;
  END ACTIONS;
  get actions;
        output string ":STAT? CHAN1";
        enter CHARSTRING format 'K';
        select CHARSTRING;
            case "OFF"; fetch (VIEW_CH1)OFF;
            case "ON"; fetch (VIEW_CH1)ON;
            case else; fetch VIEW_CH1;
        end select;
        store VIEW_CH1;
  end actions;
END COMPONENT;

COMPONENT VIEW_WF_CH1 NOGEN NOERRCHECK;
  TYPE DISCRETE;
  VALUES OFF,ON;
  INITIAL ON;
  GET ACTIONS;
    SELECT VIEW_CH1;
    CASE OFF;
      FETCH (VIEW_WF_CH1)OFF;
    CASE ON;
      SELECT WF_TYPE;
      CASE peak;
        FETCH (VIEW_WF_CH1)OFF;
      CASE ELSE;
        FETCH (VIEW_WF_CH1)ON;
      END SELECT;
    CASE ELSE;
      FETCH VIEW_WF_CH1;
    END SELECT;
    STORE VIEW_WF_CH1;
  END ACTIONS;
END COMPONENT;

COMPONENT VIEW_PEAK_CH1 NOGEN NOERRCHECK;
  TYPE DISCRETE;
  VALUES OFF,ON;
  INITIAL OFF;
  GET ACTIONS;
    SELECT VIEW_CH1;
    CASE OFF;
      FETCH (VIEW_PEAK_CH1)OFF;
    CASE ON;
      SELECT WF_TYPE;
      CASE peak;
        FETCH (VIEW_PEAK_CH1)ON;
      CASE ELSE;
        FETCH (VIEW_PEAK_CH1)OFF;
      END SELECT;
    CASE ELSE;
      FETCH VIEW_PEAK_CH1;
    END SELECT;
    STORE VIEW_PEAK_CH1;
  END ACTIONS;
END COMPONENT;

!>> CHAN2 views ...

COMPONENT VIEW_CH2;
  TYPE DISCRETE;
  VALUES OFF,ON;
  INITIAL OFF;
  COUPLED VIEW_WF_CH2,VIEW_PEAK_CH2;
  SET ACTIONS;
    SELECT VIEW_CH2;
    CASE OFF;
      OUTPUT STRING ":BLANK CHAN2;";
    CASE ON;
      OUTPUT STRING ":STOP;:VIEW CHAN2;RUN;";
    END SELECT;
  END ACTIONS;
  PANEL SET ACTIONS;
    if VIEW_CH2 then;
            SELECT WF_TYPE;
                CASE peak; GET PEAK_CH2;
                CASE ELSE; GET WF_CH2;
            END SELECT;
      end if;
  END ACTIONS;
  get actions;
        output string ":STAT? CHAN2";
        enter CHARSTRING format 'K';
        select CHARSTRING;
            case "OFF"; fetch (VIEW_CH2)OFF;
            case "ON"; fetch (VIEW_CH2)ON;
            case else; fetch VIEW_CH2;
        end select;
        store VIEW_CH2;
  end actions;
END COMPONENT;

COMPONENT VIEW_WF_CH2 NOGEN NOERRCHECK;
  TYPE DISCRETE;
  VALUES OFF,ON;
  INITIAL OFF;
  GET ACTIONS;
    SELECT VIEW_CH2;
    CASE OFF;
      FETCH (VIEW_WF_CH2)OFF;
    CASE ON;
      SELECT WF_TYPE;
      CASE peak;
        FETCH (VIEW_WF_CH2)OFF;
      CASE ELSE;
        FETCH (VIEW_WF_CH2)ON;
      END SELECT;
    CASE ELSE;
      FETCH VIEW_WF_CH2;
    END SELECT;
    STORE VIEW_WF_CH2;
  END ACTIONS;
END COMPONENT;

COMPONENT VIEW_PEAK_CH2 NOGEN NOERRCHECK;
  TYPE DISCRETE;
  VALUES OFF,ON;
  INITIAL OFF;
  GET ACTIONS;
    SELECT VIEW_CH2;
    CASE OFF;
      FETCH (VIEW_PEAK_CH2)OFF;
    CASE ON;
      SELECT WF_TYPE;
      CASE peak;
        FETCH (VIEW_PEAK_CH2)ON;
      CASE ELSE;
        FETCH (VIEW_PEAK_CH2)OFF;
      END SELECT;
    CASE ELSE;
      FETCH VIEW_PEAK_CH2;
    END SELECT;
    STORE VIEW_PEAK_CH2;
  END ACTIONS;
END COMPONENT;

!==============================
! TIMEBASE SUBSYSTEM
!==============================
 

COMPONENT TIME_SENS;
  TYPE CONTINUOUS;
  VALUES RANGE 1E-9,5 LOG 3,1;
  INITIAL 100E-6;
  COUPLED WF_TMIN,WF_TMAX,NUM_POINTS;
  SET ACTIONS;
    FETCH TIME_SENS; FETCH 10; MUL; ! range is 10x sensitivity ...;
    OUTPUT STACK FORMAT '":TIM:RANGE ",K,";"';
    GET TIME_DELAY;
  END ACTIONS;
  GET ACTIONS;
    OUTPUT STRING ":TIM:RANGE?;";
    ENTER STACK FORMAT K; FETCH 10; DIV; ! range is 10x sensitivity ...;
    STORE TIME_SENS;
  END ACTIONS;
  PANEL SET ACTIONS;
    GOSUB UPDATE_TRACE_DATA;
  END ACTIONS;
END COMPONENT;

COMPONENT TIME_DELAY;
  TYPE CONTINUOUS;
  VALUES RANGE -25,125,1E-9;
  INITIAL 0;
  COUPLED WF_TMIN,WF_TMAX,TIME_DELAY;
  SET ACTIONS;
    OUTPUT STRING ":TIM:DELAY ";
    OUTPUT TIME_DELAY FORMAT 'K,";"';
  END ACTIONS;
  GET ACTIONS;
    OUTPUT STRING ":TIM:DELAY?;";
    ENTER TIME_DELAY FORMAT K;
  END ACTIONS;
  PANEL SET ACTIONS;
    GOSUB UPDATE_TRACE_DATA;
  END ACTIONS;
END COMPONENT;

COMPONENT TIME_REF;
  TYPE DISCRETE;
  VALUES LEFT,CENTER;
  INITIAL CENTER;
  COUPLED WF_TMIN,WF_TMAX,TMARKER1,TMARKER2;
  SET ACTIONS;
    OUTPUT STRING ":TIM:REF ";
    OUTPUT TIME_REF TABLE 'LEFT;','CENTER;';
    GET TIME_DELAY;
  END ACTIONS;
  GET ACTIONS;
    OUTPUT STRING ":TIM:REF?;";
    ENTER CHARSTRING FORMAT K;
    SELECT CHARSTRING;
    CASE "LEFT";
      FETCH (TIME_REF)LEFT;
    CASE "CENT";
      FETCH (TIME_REF)CENTER;
    CASE ELSE;
      FETCH TIME_REF;
    END SELECT;
    STORE TIME_REF;
  END ACTIONS;
  PANEL SET ACTIONS;
    GOSUB UPDATE_TRACE_DATA;
  END ACTIONS;
END COMPONENT;

COMPONENT WF_TMIN NOERRCHECK;
  TYPE CONTINUOUS;
  INITIAL -500E-6;
  GET ACTIONS;
    SELECT TIME_REF;
    CASE LEFT;
        FETCH TIME_DELAY; FETCH TIME_SENS; FETCH 1; MUL; SUB;
    CASE CENTER;
        FETCH TIME_DELAY; FETCH TIME_SENS; FETCH 5; MUL; SUB;
    END SELECT;
    STORE WF_TMIN;
  END ACTIONS;
END COMPONENT;

COMPONENT WF_TMAX NOERRCHECK;
  TYPE CONTINUOUS;
  INITIAL 500E-6;
  GET ACTIONS;
    SELECT TIME_REF;
    CASE LEFT;
        FETCH TIME_DELAY; FETCH TIME_SENS; FETCH 9; MUL; ADD;
    CASE CENTER;
        FETCH TIME_DELAY; FETCH TIME_SENS; FETCH 5; MUL; ADD;
    END SELECT;
    STORE WF_TMAX;
  END ACTIONS;
END COMPONENT;

!==============================
! TRIGGER SUBSYSTEM
!==============================

component trig_mode;
    type discrete;
    values auto_lvl,auto,normal,single,tv;
    initial auto_lvl;
    coupled trig_source,trig_level;
    set actions;
        output string ":TRIG:MODE ";
        output trig_mode table "AUTL","AUTO","NORM","SING","TV";
        gosub set_mode_source;
    end actions;
    panel set actions;
        select trig_mode;
            case tv; hide trig_no_tv; show trig_tv;
            case else; hide trig_tv; show trig_no_tv;
        end select;
    end actions;
    get actions;
        output string ":TRIG:MODE?";
        enter CHARSTRING format 'K';
        select CHARSTRING;
            case "AUTL"; fetch (trig_mode)auto_lvl;
            case "AUTO"; fetch (trig_mode)auto;
            case "NORM"; fetch (trig_mode)normal;
            case "SING"; fetch (trig_mode)single;
            case "TV"; fetch (trig_mode)tv;
            case else; fetch trig_mode;
        end select;
        store trig_mode;
    end actions;
end component;

component trig_source;
    type discrete;
    values c1,c2,ext,line;
    initial c1;
    coupled trig_mode,trig_level;
    set actions;
        output string ":TRIG:SOUR ";
        output trig_source table "CHAN1","CHAN2","EXT","LINE";
        gosub set_mode_source;
    end actions;
    get actions;
        output string ":TRIG:SOUR?";
        enter CHARSTRING format 'K';
        select CHARSTRING;
            case "CHAN1"; fetch (trig_source)c1;
            case "CHAN2"; fetch (trig_source)c2;
            case "EXT"; fetch (trig_source)ext;
            case "LINE"; fetch (trig_source)line;
            case else; fetch trig_source;
        end select;
        store trig_source;
    end actions;
end component;

actions set_mode_source;
        select trig_mode;
            case tv; disable trig_source,ext,line;
            case else; enable trig_source,ext,line;
        end select;
        select trig_source;
            case c1; enable trig_mode,tv;
            case c2; enable trig_mode,tv;
            case else; disable trig_mode,tv;
        end select;
end actions;

component trig_coupling;
    type discrete;
    values dc,ac;
    initial dc;
    set actions;
        output string ":TRIG:COUP ";
        output trig_coupling table "DC","AC";
    end actions;
    get actions;
        output string ":TRIG:COUP?";
        enter CHARSTRING format 'K';
        select CHARSTRING;
            case "DC"; fetch (trig_coupling)dc;
            case "AC"; fetch (trig_coupling)ac;
            case else; fetch trig_coupling;
        end select;
        store trig_coupling;
    end actions;
end component;

component trig_holdoff;
    type continuous;
    values range 200E-9,13.42,1E-9;
    initial 200E-9;
    set actions;
        output trig_holdoff format '":TRIG:HOLD ",K';
    end actions;
    get actions;
        output string ":TRIG:HOLD?";
        enter trig_holdoff format 'K';
    end actions;
end component;

component trig_level_min nogen noerrcheck;
    type continuous;
    initial -3000; ! least possible value
end component;

component trig_level_max nogen noerrcheck;
    type continuous;
    initial 3000;  ! max possible value
end component;

component trig_level;
    type continuous;
    values range trig_level_min,trig_level_max,16E-5;
    initial 0;
    coupled trig_level;
    set actions;
        output trig_level format '":TRIG:LEV ",K';
    end actions;
    get actions;
        output string ":TRIG:LEV?";
        enter trig_level format 'K';
    end actions;
end component;

component trig_noise_rej;
    type discrete;
    values off,on;
    initial off;
    set actions;
        output string ":TRIG:NREJ ";
        output trig_noise_rej table "OFF","ON";
    end actions;
    get actions;
        output string ":TRIG:NREJ?";
        enter CHARSTRING format 'K';
        select CHARSTRING;
            case "OFF"; fetch (trig_noise_rej)off;
            case "ON"; fetch (trig_noise_rej)on;
            case else; fetch trig_noise_rej;
        end select;
        store trig_noise_rej;
    end actions;
end component;

component trig_tv_pol;
    type discrete;
    values pos,neg;
    initial neg;
    set actions;
        output string ":TRIG:POL ";
        output trig_tv_pol table "POS","NEG";
    end actions;
    get actions;
        output string ":TRIG:POL?";
        enter CHARSTRING format 'K';
        select CHARSTRING;
            case "POS"; fetch (trig_tv_pol)pos;
            case "NEG"; fetch (trig_tv_pol)neg;
            case else; fetch trig_tv_pol;
        end select;
        store trig_tv_pol;
    end actions;
end component;

component trig_rej;
    type discrete;
    values off,lf,hf;
    initial off;
    set actions;
        output string ":TRIG:REJ ";
        output trig_rej table "OFF","LF","HF";
    end actions;
    get actions;
        output string ":TRIG:REJ?";
        enter CHARSTRING format 'K';
        select CHARSTRING;
            case "OFF"; fetch (trig_rej)off;
            case "LF"; fetch (trig_rej)lf;
            case "HF"; fetch (trig_rej)hf;
            case else; fetch trig_rej;
        end select;
        store trig_rej;
    end actions;
end component;

component trig_slope;
    type discrete;
    values pos,neg;
    initial pos;
    set actions;
        output string ":TRIG:SLOP ";
        output trig_slope table "POS","NEG";
    end actions;
    get actions;
        output string ":TRIG:SLOP?";
        enter CHARSTRING format 'K';
        select CHARSTRING;
            case "POS"; fetch (trig_slope)pos;
            case "NEG"; fetch (trig_slope)neg;
            case else; fetch trig_slope;
        end select;
        store trig_slope;
    end actions;
end component;

component trig_tv_hfrej;
    type discrete;
    values off,on;
    initial off;
    set actions;
        output string ":TRIG:TVHF ";
        output trig_tv_hfrej table "OFF","ON";
    end actions;
    get actions;
        output string ":TRIG:TVHF?";
        enter CHARSTRING format 'K';
        select CHARSTRING;
            case "OFF"; fetch (trig_tv_hfrej)off;
            case "ON"; fetch (trig_tv_hfrej)on;
            case else; fetch trig_tv_hfrej;
        end select;
        store trig_tv_hfrej;
    end actions;
end component;

component trig_tv_mode;
    type discrete;
    values line,field1,field2;
    initial field1;
    set actions;
        output string ":TRIG:TVM ";
        output trig_tv_mode table "LINE","FIELD1","FIELD2";
    end actions;
    get actions;
        output string ":TRIG:TVM?";
        enter CHARSTRING format 'K';
        select CHARSTRING;
            case "LINE"; fetch (trig_tv_mode)line;
            case "FIELD1"; fetch (trig_tv_mode)field1;
            case "FIELD2"; fetch (trig_tv_mode)field2;
            case else; fetch trig_tv_mode;
        end select;
        store trig_tv_mode;
    end actions;
end component;

component trig_show_next notsaved nogen noerrcheck;
    type integer;
    panel set actions;
        hide trig_1; show trig_2;
    end actions;
end component;

component trig_show_prev notsaved nogen noerrcheck;
    type integer;
    panel set actions;
        hide trig_2; show trig_1;
    end actions;
end component;

!==============================
! CHANNEL SUBSYSTEM
!==============================

COMPONENT CHANNEL NOGEN NOERRCHECK;
  TYPE DISCRETE;
  VALUES CH1,CH2;
  INITIAL CH1;
  panel set actions;
          HIDE CHANNEL_SUBSYSTEM, CH1;
          HIDE CHANNEL_SUBSYSTEM, CH2;

          SELECT CHANNEL;
          CASE CH1;
            SHOW CHANNEL_SUBSYSTEM, CH1; output string ":MENU 1";
            fetch (view_ch1)on; fetch view_ch1; eq;
            if stack then;
            else;
              fetch (view_ch1)on; store view_ch1;
              set view_ch1;
              gosub update_trace_data;
            end if;
          CASE CH2;
            SHOW CHANNEL_SUBSYSTEM, CH2; output string ":MENU 2";
            fetch (view_ch2)on; fetch view_ch2; eq;
            if stack then;
            else;
              fetch (view_ch2)on; store view_ch2;
              set view_ch2;
              gosub update_trace_data;
            end if;
          END SELECT;

  end actions;
END COMPONENT;

!>> CHANNEL #1 ...

COMPONENT PROBE_CH1;
  TYPE discrete;
  VALUES x1,x10,x100;
  INITIAL x1;
  COUPLED MIN_SENS_CH1,MAX_SENS_CH1,VMARKER1,VMARKER2,
  SENS_CH1,OFFSET_CH1,VMIN_CH1,VMAX_CH1,SENS_INCR_CH1,
  VMIN_MSMT,VMAX_MSMT;
  SET ACTIONS;
    OUTPUT STRING ":CHAN1:PROBE ";
    OUTPUT PROBE_CH1 table "X1","X10","X100";
  END ACTIONS;
  GET ACTIONS;
    OUTPUT STRING ":CHAN1:PROBE?";
    enter CHARSTRING format 'K';
    select CHARSTRING;
        case "X1"; fetch (PROBE_CH1)x1;
        case "X10"; fetch (PROBE_CH1)x10;
        case "X100"; fetch (PROBE_CH1)x100;
        case else; fetch PROBE_CH1;
    end select;
    store PROBE_CH1;
  END ACTIONS;
  PANEL SET ACTIONS;
    GOSUB INVALIDATE_TRACE_DATA;
    GOSUB UPLOAD_TRACE_DATA; ! upload waveforms to refresh XY screen
  END ACTIONS;
END COMPONENT;

COMPONENT MIN_SENS_CH1 NOGEN NOERRCHECK;
  TYPE CONTINUOUS;
  INITIAL 2E-3;
  GET ACTIONS;
    FETCH 2E-3;
    select PROBE_CH1;
        case x1; fetch 1;
        case x10; fetch 10;
        case x100; fetch 100;
    end select;
    MUL;
    STORE MIN_SENS_CH1;
  END ACTIONS;
END COMPONENT;

COMPONENT MAX_SENS_CH1 NOGEN NOERRCHECK;
  TYPE CONTINUOUS;
  INITIAL 5;
  GET ACTIONS;
    FETCH 5;
    select PROBE_CH1;
        case x1; fetch 1;
        case x10; fetch 10;
        case x100; fetch 100;
    end select;
    MUL;
    STORE MAX_SENS_CH1;
  END ACTIONS;
END COMPONENT;

COMPONENT SENS_CH1;
  TYPE CONTINUOUS;
  VALUES RANGE MIN_SENS_CH1,MAX_SENS_CH1;
  INITIAL 100e-3;
  COUPLED OFFSET_CH1,VMARKER1,VMARKER2, SENS_CH1,
  VMIN_CH1,VMAX_CH1,SENS_INCR_CH1, VMIN_MSMT,VMAX_MSMT;
  SET ACTIONS;
    FETCH SENS_CH1; FETCH 8; MUL;
    OUTPUT STACK FORMAT '":CHAN1:RANGE ",K,";"';
  END ACTIONS;
  GET ACTIONS;
    OUTPUT STRING ":CHAN1:RANGE?;";
    ENTER STACK FORMAT K; FETCH 8; DIV; STORE SENS_CH1;
    gosub update_trig_level;
  END ACTIONS;
  PANEL SET ACTIONS;
    GOSUB UPDATE_TRACE_DATA;
  END ACTIONS;
END COMPONENT;

COMPONENT OFFSET_CH1;
  TYPE CONTINUOUS;
  VALUES RANGE -25000,25000,SENS_INCR_CH1;  ! takes care of x100 attenuation
  INITIAL 0;
  COUPLED VMIN_CH1,VMAX_CH1,VMARKER1,VMARKER2,
  VMIN_MSMT,VMAX_MSMT,OFFSET_CH1;
  SET ACTIONS;
    OUTPUT OFFSET_CH1 FORMAT '":CHAN1:OFFSET ",K,";"';
  END ACTIONS;
  GET ACTIONS;
    OUTPUT STRING ":CHAN1:OFFSET?;";
    ENTER OFFSET_CH1 FORMAT K;
    gosub update_trig_level;
  END ACTIONS;
  PANEL SET ACTIONS;
    GOSUB UPDATE_TRACE_DATA;
  END ACTIONS;
END COMPONENT;

COMPONENT VMIN_CH1 NOERRCHECK;
  TYPE CONTINUOUS;
  INITIAL -0.4;
  GET ACTIONS;
    ! offset-range/2 ...
    FETCH OFFSET_CH1; FETCH SENS_CH1; FETCH 4; MUL; SUB;
    STORE VMIN_CH1;
  END ACTIONS;
END COMPONENT;

COMPONENT VMAX_CH1 NOERRCHECK;
  TYPE CONTINUOUS;
  INITIAL 0.4;
  GET ACTIONS;
    ! offset+range/2 ...
    FETCH OFFSET_CH1; FETCH SENS_CH1; FETCH 4; MUL; ADD;
    STORE VMAX_CH1;
  END ACTIONS;
END COMPONENT;

COMPONENT SENS_INCR_CH1 NOGEN NOERRCHECK;
  TYPE CONTINUOUS;
  INITIAL 8E-3;
  ! 1% of range ...
  GET ACTIONS;
    FETCH VMAX_CH1; FETCH VMIN_CH1; SUB; FETCH 100; DIV;
    STORE SENS_INCR_CH1;
  END ACTIONS;
END COMPONENT;

COMPONENT BWLIMIT_CH1;
  TYPE DISCRETE;
  VALUES OFF,ON;
  INITIAL OFF;
  SET ACTIONS;
    OUTPUT STRING ":CHAN1:BWL ";
    OUTPUT BWLIMIT_CH1 TABLE 'OFF;','ON;';
  END ACTIONS;
  GET ACTIONS;
    OUTPUT STRING ":CHAN1:BWL?;"; ENTER CHARSTRING FORMAT K;
    SELECT CHARSTRING;
    CASE "OFF";
      FETCH (BWLIMIT_CH1)OFF;
    CASE "ON";
      FETCH (BWLIMIT_CH1)ON;
    CASE ELSE;
      FETCH BWLIMIT_CH1;
    END SELECT;
    STORE BWLIMIT_CH1;
  END ACTIONS;
  PANEL SET ACTIONS;
    GOSUB UPDATE_TRACE_DATA;
  END ACTIONS;
END COMPONENT;

COMPONENT COUPLING_CH1;
  TYPE DISCRETE;
  VALUES DC,AC,gnd,dcfifty;
  INITIAL DC;
  SET ACTIONS;
    fetch coupling_ch1; fetch (coupling_ch1)dcfifty; eq;
    if stack then;
      output string ":CHAN1:COUP DC;";
      output string ":CHAN1:INP FIFT;";
    else;
      output string ":CHAN1:INP ONEM;";
      OUTPUT STRING ":CHAN1:COUP ";
      OUTPUT COUPLING_CH1 TABLE 'DC;','AC;','GND;';
    end if;
  END ACTIONS;
  GET ACTIONS;
    OUTPUT STRING ":CHAN1:COUP?;";
    ENTER CHARSTRING FORMAT K;
    SELECT CHARSTRING;
    CASE "DC";
      output string ":CHAN1:INP?;";
      enter charstring format k;
      select charstring;
      case "FIFT";
        FETCH (COUPLING_CH1)dcfifty;
      case "ONEM";
        fetch (coupling_ch1)dc;
      case else;
        fetch coupling_ch1;
      end select;
    CASE "AC";
      FETCH (COUPLING_CH1)AC;
    CASE "GND";
      FETCH (COUPLING_CH1)gnd;
    CASE ELSE;
      FETCH COUPLING_CH1;
    END SELECT;
    STORE COUPLING_CH1;
  END ACTIONS;
  PANEL SET ACTIONS;
    GOSUB UPDATE_TRACE_DATA;
  END ACTIONS;
END COMPONENT;

component invert_ch1;
    type discrete;
    values off,on;
    initial off;
    set actions;
        output string ":CHAN1:INV ";
        output invert_ch1 table "OFF","ON";
    end actions;
    PANEL SET ACTIONS;
       GOSUB UPDATE_TRACE_DATA;
    END ACTIONS;
    get actions;
        output string ":CHAN1:INV?";
        enter CHARSTRING format 'K';
        select CHARSTRING;
            case "ON"; fetch (invert_ch1)on;
            case "OFF"; fetch (invert_ch1)off;
            case else; fetch invert_ch1;
        end select;
        store invert_ch1;
    end actions;
end component;

!>> CHANNEL #2 ...

COMPONENT PROBE_CH2;
  TYPE discrete;
  VALUES x1,x10,x100;
  INITIAL x1;
  SET ACTIONS;
    OUTPUT STRING ":CHAN2:PROBE ";
    OUTPUT PROBE_CH2 table "X1","X10","X100";
  END ACTIONS;
  GET ACTIONS;
    OUTPUT STRING ":CHAN2:PROBE?";
    enter CHARSTRING format 'K';
    select CHARSTRING;
        case "X1"; fetch (PROBE_CH2)x1;
        case "X10"; fetch (PROBE_CH2)x10;
        case "X100"; fetch (PROBE_CH2)x100;
        case else; fetch PROBE_CH2;
    end select;
    store PROBE_CH2;
  END ACTIONS;
  PANEL SET ACTIONS;
    GOSUB INVALIDATE_TRACE_DATA;
    GOSUB UPLOAD_TRACE_DATA; ! upload waveforms to refresh XY screen
  END ACTIONS;
END COMPONENT;

COMPONENT MIN_SENS_CH2 NOGEN NOERRCHECK;
  TYPE CONTINUOUS;
  INITIAL 2E-3;
  GET ACTIONS;
    FETCH 2E-3;
    select PROBE_CH2;
        case x1; fetch 1;
        case x10; fetch 10;
        case x100; fetch 100;
    end select;
    MUL;
    STORE MIN_SENS_CH2;
  END ACTIONS;
END COMPONENT;

COMPONENT MAX_SENS_CH2 NOGEN NOERRCHECK;
  TYPE CONTINUOUS;
  INITIAL 5;
  GET ACTIONS;
    FETCH 5;
    select PROBE_CH2;
        case x1; fetch 1;
        case x10; fetch 10;
        case x100; fetch 100;
    end select;
    MUL;
    STORE MAX_SENS_CH2;
  END ACTIONS;
END COMPONENT;

COMPONENT SENS_CH2;
  TYPE CONTINUOUS;
  VALUES RANGE MIN_SENS_CH2,MAX_SENS_CH2;
  INITIAL 100E-3;
  COUPLED OFFSET_CH2,VMARKER1,VMARKER2, SENS_CH2,
  VMIN_CH2,VMAX_CH2,SENS_INCR_CH2, VMIN_MSMT,VMAX_MSMT;
  SET ACTIONS;
    FETCH SENS_CH2; FETCH 8; MUL;
    OUTPUT STACK FORMAT '":CHAN2:RANGE ",K,";"';
  END ACTIONS;
  GET ACTIONS;
    OUTPUT STRING ":CHAN2:RANGE?;";
    ENTER STACK FORMAT K; FETCH 8; DIV; STORE SENS_CH2;
    gosub update_trig_level;
  END ACTIONS;
  PANEL SET ACTIONS;
    GOSUB UPDATE_TRACE_DATA;
  END ACTIONS;
END COMPONENT;

COMPONENT OFFSET_CH2;
  TYPE CONTINUOUS;
  VALUES RANGE -25000,25000,SENS_INCR_CH2;  ! takes care of x100 attenuation
  INITIAL 0;
  COUPLED VMIN_CH2,VMAX_CH2,VMARKER1,VMARKER2,
  VMIN_MSMT,VMAX_MSMT,OFFSET_CH2;
  SET ACTIONS;
    OUTPUT OFFSET_CH2 FORMAT '":CHAN2:OFFSET ",K,";"';
  END ACTIONS;
  GET ACTIONS;
    OUTPUT STRING ":CHAN2:OFFSET?;";
    ENTER OFFSET_CH2 FORMAT K;
    gosub update_trig_level;
  END ACTIONS;
  PANEL SET ACTIONS;
    GOSUB UPDATE_TRACE_DATA;
  END ACTIONS;
END COMPONENT;

COMPONENT VMIN_CH2 NOERRCHECK;
  TYPE CONTINUOUS;
  INITIAL -0.4;
  GET ACTIONS;
    ! offset-range/2 ...
    FETCH OFFSET_CH2; FETCH SENS_CH2; FETCH 4; MUL; SUB;
    STORE VMIN_CH2;
  END ACTIONS;
END COMPONENT;

COMPONENT VMAX_CH2 NOERRCHECK;
  TYPE CONTINUOUS;
  INITIAL 0.4;
  GET ACTIONS;
    ! offset+range/2 ...
    FETCH OFFSET_CH2; FETCH SENS_CH2; FETCH 4; MUL; ADD;
    STORE VMAX_CH2;
  END ACTIONS;
END COMPONENT;

COMPONENT SENS_INCR_CH2 NOGEN NOERRCHECK;
  TYPE CONTINUOUS;
  INITIAL 8E-3;
  ! 1% of range ...
  GET ACTIONS;
    FETCH VMAX_CH2; FETCH VMIN_CH2; SUB; FETCH 100; DIV;
    STORE SENS_INCR_CH2;
  END ACTIONS;
END COMPONENT;

COMPONENT BWLIMIT_CH2;
  TYPE DISCRETE;
  VALUES OFF,ON;
  INITIAL OFF;
  SET ACTIONS;
    OUTPUT STRING ":CHAN2:BWL ";
    OUTPUT BWLIMIT_CH2 TABLE 'OFF;','ON;';
  END ACTIONS;
  GET ACTIONS;
    OUTPUT STRING ":CHAN2:BWL?;"; ENTER CHARSTRING FORMAT K;
    SELECT CHARSTRING;
    CASE "OFF";
      FETCH (BWLIMIT_CH2)OFF;
    CASE "ON";
      FETCH (BWLIMIT_CH2)ON;
    CASE ELSE;
      FETCH BWLIMIT_CH2;
    END SELECT;
    STORE BWLIMIT_CH2;
  END ACTIONS;
  PANEL SET ACTIONS;
    GOSUB UPDATE_TRACE_DATA;
  END ACTIONS;
END COMPONENT;

COMPONENT COUPLING_CH2;
  TYPE DISCRETE;
  VALUES DC,AC,gnd,dcfifty;
  INITIAL DC;
  SET ACTIONS;
    fetch coupling_ch2; fetch (coupling_ch2)dcfifty; eq;
    if stack then;
      output string ":CHAN2:COUP DC;";
      output string ":CHAN2:INP FIFT;";
    else;
      output string ":CHAN2:INP ONEM;";
      OUTPUT STRING ":CHAN2:COUP ";
      OUTPUT COUPLING_CH2 TABLE 'DC;','AC;','GND;';
    end if;
  END ACTIONS;
  GET ACTIONS;
    OUTPUT STRING ":CHAN2:COUP?;";
    ENTER CHARSTRING FORMAT K;
    SELECT CHARSTRING;
    CASE "DC";
      output string ":CHAN2:INP?;";
      enter charstring format k;
      select charstring;
      case "FIFT";
        FETCH (COUPLING_CH2)dcfifty;
      case "ONEM";
        fetch (coupling_ch2)dc;
      case else;
        fetch coupling_ch2;
      end select;
    CASE "AC";
      FETCH (COUPLING_CH2)AC;
    CASE "GND";
      FETCH (COUPLING_CH2)gnd;
    CASE ELSE;
      FETCH COUPLING_CH2;
    END SELECT;
    STORE COUPLING_CH2;
  END ACTIONS;
  PANEL SET ACTIONS;
    GOSUB UPDATE_TRACE_DATA;
  END ACTIONS;
END COMPONENT;

component invert_ch2;
    type discrete;
    values off,on;
    initial off;
    set actions;
        output string ":CHAN2:INV ";
        output invert_ch2 table "OFF","ON";
    end actions;
    PANEL SET ACTIONS;
       GOSUB UPDATE_TRACE_DATA;
    END ACTIONS;
    get actions;
        output string ":CHAN2:INV?";
        enter CHARSTRING format 'K';
        select CHARSTRING;
            case "ON"; fetch (invert_ch2)on;
            case "OFF"; fetch (invert_ch2)off;
            case else; fetch invert_ch2;
        end select;
        store invert_ch2;
    end actions;
end component;

component math_ch;
    type discrete;
    values off,plus,sub;
    initial off;
    set actions;
      FETCH OPTIONS;
      FETCH (OPTIONS)MEAS_STORAGE;
      NE;
      IF STACK THEN;
        output string ":CHAN:MATH ";
        output math_ch table "OFF","PLUS","SUBT";
      ELSE;
        FETCH 0;
        STORE MATH_CH;
      END IF;
    end actions;
    get actions;
      FETCH OPTIONS;
      FETCH (OPTIONS)MEAS_STORAGE;
      NE;
      IF STACK THEN;
        output string ":CHAN:MATH?";
        enter CHARSTRING format 'K';
        select CHARSTRING;
            case "OFF"; fetch (math_ch)off;
            case "PLUS"; fetch (math_ch)plus;
            case "SUBT"; fetch (math_ch)sub;
            case else; fetch math_ch;
        end select;
        store math_ch;
      ELSE;
        FETCH 0;
        STORE MATH_CH;
      END IF;
    end actions;
end component;

actions update_trig_level;

    ! updates the trigger level IFF the 'current' channel whose
    ! sensitivity/offset is being changed, is same as the triger source

    select trig_source;
        case c1; fetch 1;
        case c2; fetch 2;
        case else; fetch 0;
    end select;

    fetch self; dup; length;  ! last digit of the component is chan no.
    fetch 1; substr; val; eq;

    if stack then;
        get trig_level;
    end if;
end actions;

!==============================
! MEASURE SUBSYSTEM
!==============================

component meas_source;
    type discrete;
    values c1,c2;
    initial c1;
    coupled VMIN_MSMT,VMAX_MSMT,VMARKER1,VMARKER2;
    set actions;
        output string ":MEAS:SOUR CHAN";
        output meas_source table "1","2";
    end actions;
    get actions;
        output string ":MEAS:SOUR?";
        enter CHARSTRING format 'K';
        select CHARSTRING;
            case "CHAN1"; fetch (meas_source)c1;
            case "CHAN2"; fetch (meas_source)c2;
            case else; fetch meas_source;
        end select;
        store meas_source;
    end actions;
end component;

component meas_all notsaved;
    type integer;
    set actions;
        output string ":MEAS:ALL?";
        gosub wait_for_response;
        enter meas_t_freq format '#,K';
        enter meas_t_period format '#,K';
        enter meas_t_pwid format '#,K';
        enter meas_t_nwid format '#,K';
        enter meas_t_rtime format '#,K';
        enter meas_t_ftime format '#,K';
        enter meas_v_pp format '#,K';
        enter meas_t_duty format '#,K';
        enter meas_v_rms format '#,K';
        enter meas_v_max format '#,K';
        enter meas_v_min format '#,K';
        enter meas_v_top format '#,K';
        enter meas_v_base format '#,K';
        enter meas_v_avrg format '#,K';
        enter num_buffer format '#,K';
        enter num_buffer format '#,K';
        enter num_buffer format '#,K';
    end actions;
end component;

component meas_scratch notsaved;
    type integer;
    set actions;
        output string ":MEAS:SCR";
        fetch 0; store marker_state; ! clear markers

        invalidate meas_t_freq ;
        invalidate meas_t_period ;
        invalidate meas_t_pwid ;
        invalidate meas_t_nwid ;
        invalidate meas_t_rtime ;
        invalidate meas_t_ftime ;
        invalidate meas_v_pp ;
        invalidate meas_t_duty ;
        invalidate meas_v_rms ;
        invalidate meas_v_max ;
        invalidate meas_v_min ;
        invalidate meas_v_top ;
        invalidate meas_v_base ;
        invalidate meas_v_avrg ;

    end actions;
end component;

component meas_show_vmeas notsaved nogen noerrcheck;
    type integer;
    panel set actions;
        hide meas_main;
        hide meas_vmeas_more;
        hide meas_tmeas;
        hide meas_tmeas_more;
        show meas_vmeas;
        output string ":MENU 11";
    end actions;
end component;

component meas_show_vmeas_more notsaved nogen noerrcheck;
    type integer;
    panel set actions;
        hide meas_main;
        hide meas_vmeas;
        hide meas_tmeas;
        hide meas_tmeas_more;
        show meas_vmeas_more;
    end actions;
end component;

component meas_show_tmeas notsaved nogen noerrcheck;
    type integer;
    panel set actions;
        hide meas_main;
        hide meas_vmeas;
        hide meas_vmeas_more;
        hide meas_tmeas_more;
        show meas_tmeas;
        output string ":MENU 10";
    end actions;
end component;

component meas_show_tmeas_more notsaved nogen noerrcheck;
    type integer;
    panel set actions;
        hide meas_main;
        hide meas_vmeas;
        hide meas_vmeas_more;
        hide meas_tmeas;
        show meas_tmeas_more;
    end actions;
end component;

component meas_show_main notsaved nogen noerrcheck;
    type integer;
    panel set actions;
        hide meas_vmeas;
        hide meas_vmeas_more;
        hide meas_tmeas;
        hide meas_tmeas_more;
        show meas_main;
    end actions;
end component;

! measurement parameters

! voltage measurements

component meas_v_pp notsaved;
    type continuous;
    initial 0,invalid;
    get actions;
        output string ":MEAS:VPP?";
        gosub wait_for_response;
        enter meas_v_pp format 'K';
    end actions;
end component;

component meas_v_avrg notsaved;
    type continuous;
    initial 0,invalid;
    get actions;
        output string ":MEAS:VAV?";
        gosub wait_for_response;
        enter meas_v_avrg format 'K';
    end actions;
end component;

component meas_v_rms notsaved;
    type continuous;
    initial 0,invalid;
    get actions;
        output string ":MEAS:VRMS?";
        gosub wait_for_response;
        enter meas_v_rms format 'K';
    end actions;
end component;

component meas_v_max notsaved;
    type continuous;
    initial 0,invalid;
    get actions;
        output string ":MEAS:VMAX?";
        gosub wait_for_response;
        enter meas_v_max format 'K';
    end actions;
end component;

component meas_v_min notsaved;
    type continuous;
    initial 0,invalid;
    get actions;
        output string ":MEAS:VMIN?";
        gosub wait_for_response;
        enter meas_v_min format 'K';
    end actions;
end component;

component meas_v_top notsaved;
    type continuous;
    initial 0,invalid;
    get actions;
        output string ":MEAS:VTOP?";
        gosub wait_for_response;
        enter meas_v_top format 'K';
    end actions;
end component;

component meas_v_base notsaved;
    type continuous;
    initial 0,invalid;
    get actions;
        output string ":MEAS:VBASE?";
        gosub wait_for_response;
        enter meas_v_base format 'K';
    end actions;
end component;

! time measurements

component meas_t_freq notsaved;
    type continuous;
    initial 0,invalid;
    get actions;
        output string ":MEAS:FREQ?";
        gosub wait_for_response;
        enter meas_t_freq format 'K';
    end actions;
end component;

component meas_t_period notsaved;
    type continuous;
    initial 0,invalid;
    get actions;
        output string ":MEAS:PER?";
        gosub wait_for_response;
        enter meas_t_period format 'K';
    end actions;
end component;

component meas_t_duty notsaved;
    type continuous;
    initial 0,invalid;
    get actions;
        output string ":MEAS:DUTY?";
        gosub wait_for_response;
        enter meas_t_duty format 'K';
    end actions;
end component;

component meas_t_pwid notsaved;
    type continuous;
    initial 0,invalid;
    get actions;
        output string ":MEAS:PWID?";
        gosub wait_for_response;
        enter meas_t_pwid format 'K';
    end actions;
end component;

component meas_t_nwid notsaved;
    type continuous;
    initial 0,invalid;
    get actions;
        output string ":MEAS:NWID?";
        gosub wait_for_response;
        enter meas_t_nwid format 'K';
    end actions;
end component;

component meas_t_rtime notsaved;
    type continuous;
    initial 0,invalid;
    get actions;
        output string ":MEAS:RISE?";
        gosub wait_for_response;
        enter meas_t_rtime format 'K';
    end actions;
end component;

component meas_t_ftime notsaved;
    type continuous;
    initial 0,invalid;
    get actions;
        output string ":MEAS:FALL?";
        gosub wait_for_response;
        enter meas_t_ftime format 'K';
    end actions;
end component;

component meas_t_tvolt;
    type continuous;
    values range VMIN_MSMT,VMAX_MSMT,16E-5;
    initial 0,invalid;
    set actions;
        get meas_t_tvolt_time;
    end actions;
end component;

component meas_t_tvolt_edge;
    type integer;
    values range -100,100;
    initial 1,invalid;
    set actions;
        get meas_t_tvolt_time;
    end actions;
end component;

component meas_t_tvolt_time notsaved;
    type continuous;
    initial 0,invalid;
    get actions;
        output meas_t_tvolt format '":MEAS:TVOL? ",K,","';
        output meas_t_tvolt_edge format K;
        gosub wait_for_response;
        enter meas_t_tvolt_time format 'K';
        get TMARKER1; get tmarker_delta;
    end actions;
end component;

!==============================
! MARKER SUBSYSTEM
!==============================

!>> Voltage markers ...

COMPONENT VMIN_MSMT NOGEN NOERRCHECK;
  TYPE CONTINUOUS;
  INITIAL -400E-3; ! same as 'vmin_ch1' ...
  GET ACTIONS;
    SELECT meas_source;
    CASE c1;
      FETCH VMIN_CH1;
    CASE c2;
      FETCH VMIN_CH2;
    END SELECT;
    STORE VMIN_MSMT;
  END ACTIONS;
END COMPONENT;

COMPONENT VMAX_MSMT NOGEN NOERRCHECK;
  TYPE CONTINUOUS;
  INITIAL 400E-3; ! same as 'vmax_ch1' ...
  GET ACTIONS;
    SELECT meas_source;
    CASE c1;
      FETCH VMAX_CH1;
    CASE c2;
      FETCH VMAX_CH2;
    END SELECT;
    STORE VMAX_MSMT;
  END ACTIONS;
END COMPONENT;

component marker_state;
    type discrete;
    values off,on;
    initial off;
    set actions;
        output string ":MEAS:SHOW ";
        output marker_state table "OFF","ON";
    end actions;
    panel set actions;
      set vmarker1;
      set vmarker2;
      set tmarker1;
      set tmarker2;
    end actions;
end component;

COMPONENT VMARKER1;
  TYPE CONTINUOUS;
  VALUES RANGE VMIN_MSMT,VMAX_MSMT,16E-5;
  INITIAL INVALID;
  coupled VMARKER1,vmarker_delta;
  SET ACTIONS;
    OUTPUT STRING ":MEAS:VSTART ";
    OUTPUT VMARKER1 FORMAT 'K,";"';
  END ACTIONS;
  GET ACTIONS;
    OUTPUT STRING ":MEAS:VSTART?;";
    ENTER VMARKER1 FORMAT K;
  END ACTIONS;
END COMPONENT;

COMPONENT VMARKER2;
  TYPE CONTINUOUS;
  VALUES RANGE VMIN_MSMT,VMAX_MSMT,16E-5;
  INITIAL INVALID;
  coupled VMARKER2,vmarker_delta;
  SET ACTIONS;
    OUTPUT STRING ":MEAS:VSTOP ";
    OUTPUT VMARKER2 FORMAT 'K,";"';
  END ACTIONS;
  GET ACTIONS;
    OUTPUT STRING ":MEAS:VSTOP?;";
    ENTER VMARKER2 FORMAT K;
  END ACTIONS;
END COMPONENT;

component vmarker_delta notsaved;
    type continuous;
    initial 0,invalid;
    get actions;
        output string ":MEAS:VDELTA?";
        enter vmarker_delta format 'K';
    end actions;
end component;

component v1_next notsaved nogen;
    type integer;
    coupled VMARKER1,vmarker_delta;
    panel set actions;
        fetch VMAX_MSMT; fetch VMIN_MSMT; sub; abs; fetch 32; div;
        fetch VMARKER1; add; dup; fetch VMAX_MSMT; ge;
        if stack then;
            drop;
        else;
            store VMARKER1; set VMARKER1;
        end if;
    end actions;
end component;

component v1_prev notsaved nogen;
    type integer;
    coupled VMARKER1,vmarker_delta;
    panel set actions;
        fetch VMARKER1;
        fetch VMAX_MSMT; fetch VMIN_MSMT; sub; abs; fetch 32; div;
        sub; dup; fetch VMIN_MSMT; le;
        if stack then;
            drop;
        else;
            store VMARKER1; set VMARKER1;
        end if;
    end actions;
end component;

component v2_next notsaved nogen;
    type integer;
    coupled VMARKER2,vmarker_delta;
    panel set actions;
        fetch VMAX_MSMT; fetch VMIN_MSMT; sub; abs; fetch 32; div;
        fetch VMARKER2; add; dup; fetch VMAX_MSMT; ge;
        if stack then;
            drop;
        else;
            store VMARKER2; set VMARKER2;
        end if;
    end actions;
end component;

component v2_prev notsaved nogen;
    type integer;
    coupled VMARKER2,vmarker_delta;
    panel set actions;
        fetch VMARKER2;
        fetch VMAX_MSMT; fetch VMIN_MSMT; sub; abs; fetch 32; div;
        sub; dup; fetch VMIN_MSMT; le;
        if stack then;
            drop;
        else;
            store VMARKER2; set VMARKER2;
        end if;
    end actions;
end component;

!>> Time markers ...

COMPONENT TMARKER1;
  TYPE CONTINUOUS;
  VALUES RANGE WF_TMIN,WF_TMAX,1E-9;
  INITIAL INVALID;
  coupled TMARKER1,tmarker_delta;
  SET ACTIONS;
    OUTPUT STRING ":MEAS:TSTART ";
    OUTPUT TMARKER1 FORMAT 'K,";"';
  END ACTIONS;
  GET ACTIONS;
    OUTPUT STRING ":MEAS:TSTART?;";
    ENTER TMARKER1 FORMAT K;
  END ACTIONS;
END COMPONENT;

COMPONENT TMARKER2;
  TYPE CONTINUOUS;
  VALUES RANGE WF_TMIN,WF_TMAX,1E-9;
  INITIAL INVALID;
  coupled TMARKER2,tmarker_delta;
  SET ACTIONS;
    OUTPUT STRING ":MEAS:TSTOP ";
    OUTPUT TMARKER2 FORMAT 'K,";"';
  END ACTIONS;
  GET ACTIONS;
    OUTPUT STRING ":MEAS:TSTOP?;";
    ENTER TMARKER2 FORMAT K;
  END ACTIONS;
END COMPONENT;

component tmarker_delta notsaved;
    type continuous;
    initial 0,invalid;
    get actions;
        output string ":MEAS:TDELTA?";
        enter tmarker_delta format 'K';
    end actions;
end component;

component t1_next notsaved nogen;
    type integer;
    coupled TMARKER1,tmarker_delta;
    panel set actions;
        fetch WF_TMAX; fetch WF_TMIN; sub;  abs; fetch 50; div;
        fetch TMARKER1; add; dup; fetch WF_TMAX; ge;
        if stack then;
            drop;
        else;
            store TMARKER1; set TMARKER1;
        end if;
    end actions;
end component;

component t1_prev notsaved nogen;
    type integer;
    coupled TMARKER1,tmarker_delta;
    panel set actions;
        fetch TMARKER1;
        fetch WF_TMAX; fetch WF_TMIN; sub;  abs; fetch 50; div;
        sub; dup; fetch WF_TMIN; le;
        if stack then;
            drop;
        else;
            store TMARKER1; set TMARKER1;
        end if;
    end actions;
end component;

component t2_next notsaved nogen;
    type integer;
    coupled TMARKER2,tmarker_delta;
    panel set actions;
        fetch WF_TMAX; fetch WF_TMIN; sub;  abs; fetch 50; div;
        fetch TMARKER2; add; dup; fetch WF_TMAX; ge;
        if stack then;
            drop;
        else;
            store TMARKER2; set TMARKER2;
        end if;
    end actions;
end component;

component t2_prev notsaved nogen;
    type integer;
    coupled TMARKER2,tmarker_delta;
    panel set actions;
        fetch TMARKER2;
        fetch WF_TMAX; fetch WF_TMIN; sub;  abs; fetch 50; div;
        sub; dup; fetch WF_TMIN; le;
        if stack then;
            drop;
        else;
            store TMARKER2; set TMARKER2;
        end if;
    end actions;
end component;

!==============================
! WAVEFORM ACQ SUBSYSTEM
!==============================

!>> Acquisition/scaling parameters

COMPONENT COMPLETION;
  TYPE INTEGER;
  VALUES RANGE 0,100;
  INITIAL 100;
  SET ACTIONS;
    OUTPUT COMPLETION FORMAT '":ACQ:COMP ",K,";"';
  END ACTIONS;
  GET ACTIONS;
    OUTPUT STRING ":ACQ:COMP?;";
    ENTER COMPLETION FORMAT K;
  END ACTIONS;
  PANEL SET ACTIONS;
    GOSUB UPDATE_TRACE_DATA;
  END ACTIONS;
END COMPONENT;

COMPONENT NUM_POINTS;
  TYPE discrete;
  VALUES n100,n200,n250,n400,n500,n800,n1000,n2000,n4000,n5000;
  INITIAL n1000;
  coupled NUM_POINTS;
  SET ACTIONS;
       select NUM_POINTS;
         case n400; fetch (NUM_POINTS)n500;
         case n800; fetch (NUM_POINTS)n1000;
         case n4000; fetch (NUM_POINTS)n5000;
         case else; fetch NUM_POINTS;
      end select;
      store NUM_POINTS;
     OUTPUT string ":WAV:POINTS ";
     output NUM_POINTS table "100","200","250","400","500","800","1000",
           "2500","4000","5000";
  END ACTIONS;
  GET ACTIONS;
     if VIEW_CH1 or VIEW_CH2 then;
       OUTPUT STRING ":WAV:POINTS?";
       enter stack format 'K';
       select stack;
         case 100; fetch (NUM_POINTS)n100;
         case 200; fetch (NUM_POINTS)n200;
         case 250; fetch (NUM_POINTS)n250;
         case 400; fetch (NUM_POINTS)n400;
         case 500; fetch (NUM_POINTS)n500;
         case 800; fetch (NUM_POINTS)n800;
         case 1000; fetch (NUM_POINTS)n1000;
         case 2500; fetch (NUM_POINTS)n2000;
         case 4000; fetch (NUM_POINTS)n4000;
         case 5000; fetch (NUM_POINTS)n5000;
         case else; fetch NUM_POINTS;
      end select;
     store NUM_POINTS;
    end if;
  END ACTIONS;
  PANEL SET ACTIONS;
   ! GOSUB UPDATE_TRACE_DATA;  ! Sorry WAB
     GOSUB INVALIDATE_TRACE_DATA; ! LPH->WAB at least invalidate the traces
  END ACTIONS;
END COMPONENT;

component acq_points notsaved;
    type integer;
    initial 0,invalid;
    get actions;
        output string ":ACQ:POINTS?";
        enter acq_points format 'K';
    end actions;
end component;

COMPONENT YINCREMENT NOTSAVED NOGEN;
  TYPE CONTINUOUS;
  INITIAL INVALID;
END COMPONENT;

COMPONENT YORIGIN NOTSAVED NOGEN;
  TYPE CONTINUOUS;
  INITIAL INVALID;
END COMPONENT;

COMPONENT YREF NOTSAVED NOGEN;
  TYPE CONTINUOUS;
  INITIAL INVALID;
END COMPONENT;

COMPONENT WF_SIZE NOTSAVED;
  TYPE INTEGER;
  VALUES RANGE 1,5000;
  INITIAL 5000;
  GET ACTIONS;
    OUTPUT STRING ":WAV:FORMAT WORD;PRE?;";
    gosub wait_for_response;  ! message available
    ENTER NUM_BUFFER FORMAT "#,K"; ! format
    ENTER NUM_BUFFER FORMAT "#,K"; ! wftype
    ENTER WF_SIZE FORMAT "#,K"; ! wf size
    ENTER NUM_BUFFER FORMAT "#,K"; ! bin count
    ENTER NUM_BUFFER FORMAT "#,K"; ! x-incr
    ENTER NUM_BUFFER FORMAT "#,K"; ! x-origin
    ENTER NUM_BUFFER FORMAT "#,K"; ! x-ref
    ENTER YINCREMENT FORMAT "#,K"; ! y-incr
    ENTER YORIGIN FORMAT "#,K"; ! y-offset
    ENTER STACK FORMAT '#,K'; ! y-ref
    FETCH -1;
    MUL; ! need '-YREF' in conversion expression ...
    STORE YREF;
  END ACTIONS;
END COMPONENT;

COMPONENT X_INC;
  TYPE CONTINUOUS;
  INITIAL 1E-6;
  GET ACTIONS;
    FETCH TIME_SENS; FETCH 10; MUL;
    FETCH WF_SIZE; DIV; STORE X_INC;
  END ACTIONS;
END COMPONENT;

COMPONENT X_MIN;
  TYPE CONTINUOUS;
  INITIAL -500E-6;
  GET ACTIONS;
    SELECT TIME_REF;
    CASE LEFT;
      FETCH TIME_SENS; FETCH -1; MUL;
    CASE CENTER;
      FETCH TIME_SENS; FETCH -5; MUL;
    END SELECT;
    FETCH TIME_DELAY; ADD; STORE X_MIN;
  END ACTIONS;
END COMPONENT;

COMPONENT XMIN_1; TYPE CONTINUOUS; INITIAL INVALID; END COMPONENT;
COMPONENT XINC_1; TYPE CONTINUOUS; INITIAL INVALID; END COMPONENT;
COMPONENT XMIN_2; TYPE CONTINUOUS; INITIAL INVALID; END COMPONENT;
COMPONENT XINC_2; TYPE CONTINUOUS; INITIAL INVALID; END COMPONENT;
COMPONENT XMIN_3; TYPE CONTINUOUS; INITIAL INVALID; END COMPONENT;
COMPONENT XINC_3; TYPE CONTINUOUS; INITIAL INVALID; END COMPONENT;
COMPONENT XMIN_4; TYPE CONTINUOUS; INITIAL INVALID; END COMPONENT;
COMPONENT XINC_4; TYPE CONTINUOUS; INITIAL INVALID; END COMPONENT;

COMPONENT WF_DATA NOTSAVED;
  TYPE INTEGER;
  INITIAL DONTCARE;
  get actions;
        FETCH VIEW_CH1; FETCH VIEW_CH2; ADD;

        IF STACK THEN; ! at least one channel enabled for acquisition

          GOSUB UPDATE_TRACE_DATA;

          IF VIEW_CH1 THEN;
            SELECT WF_TYPE;
            CASE peak;
              CODEGEN GET PEAK_CH1;
            CASE ELSE;
              CODEGEN GET WF_CH1;
            END SELECT;
          END IF;

          IF VIEW_CH2 THEN;
            SELECT WF_TYPE;
            CASE peak;
              CODEGEN GET PEAK_CH2;
            CASE ELSE;
              CODEGEN GET WF_CH2;
            END SELECT;
          END IF;

          CODEGEN PEEK WF_SIZE;

        ELSE;
          NOTIFY "No channels enabled for digitize operation";
        END IF; ! at least one channel enabled for acquisition

  end actions;
END COMPONENT;

!>> NORMAL and AVERAGE waveforms

COMPONENT WF_CH1 NOTSAVED; ! 'GET' does NOT include a 'DIGITIZE' operation ...
  TYPE RTRACE 5000;
  INITIAL INVALID;
  TRACETYPE WAVEFORM;
  POINTS WF_SIZE;
  XMIN XMIN_1;
  XINCR XINC_1;
  XLOG OFF;
  XUNIT "s";
  GET ACTIONS;
   IF VIEW_CH1 THEN; !WAB
    output string ":MENU 0;";
    OUTPUT STRING ":WAV:SOURCE CHAN1;";
    OUTPUT STRING ":WAV:BYT MSBF;";
    SET NUM_POINTS; ! since WAV:SOURCE reset it to big WAB
    GET WF_SIZE; ! gets scaling parameters for CH1 along with wf size ...
    output string "WAV:DATA?;";
    ENTER WF_CH1 FORMAT INT16 10 WF_SIZE; ! "#8<DD..D>" binary block format
    ENTER CHARSTRING FORMAT K; ! consumes NL at end of binary block ...
    MATSCALE 1,YREF WF_CH1; ! subtracts yref from array ...
    MATSCALE YINCREMENT,YORIGIN WF_CH1; ! scales y-data in array ...

    GET X_MIN; FETCH X_MIN; STORE XMIN_1;
    GET X_INC; FETCH X_INC; STORE XINC_1;
  END IF;
 END ACTIONS;
END COMPONENT;
 

COMPONENT WF_CH2 NOTSAVED; ! 'GET' does NOT include a 'DIGITIZE' operation ...
  TYPE RTRACE 5000;
  INITIAL INVALID;
  TRACETYPE WAVEFORM;
  POINTS WF_SIZE;
  XMIN XMIN_2;
  XINCR XINC_2;
  XLOG OFF;
  XUNIT "s";
  GET ACTIONS;
  IF VIEW_CH2 THEN; !WAB
    output string ":MENU 0;";
    OUTPUT STRING ":WAV:SOURCE CHAN2;";
    OUTPUT STRING ":WAV:BYT MSBF;";
    SET NUM_POINTS; ! since WAV:SOURCE reset it to big WAB
    GET WF_SIZE; ! gets scaling parameters for CH2 along with wf size ...
    OUTPUT STRING ":WAV:DATA?;";
    ENTER WF_CH2 FORMAT INT16 10 WF_SIZE; ! "#8<DD..D>" binary block format
    ENTER CHARSTRING FORMAT K; ! consumes NL at end of binary block ...
    MATSCALE 1,YREF WF_CH2; ! subtracts yref from array ...
    MATSCALE YINCREMENT,YORIGIN WF_CH2; ! scales y-data in array ...

    GET X_MIN; FETCH X_MIN; STORE XMIN_2;
    GET X_INC; FETCH X_INC; STORE XINC_2;
  END IF;
  END ACTIONS;
END COMPONENT;

!>> peak waveforms

COMPONENT PEAK_CH1 NOTSAVED;
  TYPE RTRACE 2,1000;
  INITIAL INVALID;
  TRACETYPE WAVEFORM;
  POINTS WF_SIZE;
  XMIN XMIN_1;
  XINCR XINC_1;
  XLOG OFF;
  XUNIT "s";
  GET ACTIONS;
   IF VIEW_CH1 THEN; !WAB
    output string ":MENU 0;";
    OUTPUT STRING ":WAV:SOURCE CHAN1;";
    OUTPUT STRING ":WAV:BYT MSBF;";
    SET NUM_POINTS; !WAB
    GET WF_SIZE; ! gets scaling parameters for CH1 along with wf size ...
    fetch WF_SIZE; fetch 2; div; store WF_SIZE;
    OUTPUT STRING ":WAV:DATA?;";
      ENTER PEAK_CH1 FORMAT INT16 10 WF_SIZE,2;
      ENTER CHARSTRING FORMAT K; ! consumes NL at end of binary block
    MATSCALE 1,YREF PEAK_CH1; ! subtracts yref from array ...
    MATSCALE YINCREMENT,YORIGIN PEAK_CH1; ! scales y-data in array ...

    GET X_MIN; FETCH X_MIN; STORE XMIN_1;
    GET X_INC; FETCH X_INC; STORE XINC_1;
  END IF;
END ACTIONS;
END COMPONENT;

COMPONENT PEAK_CH2 NOTSAVED;
  TYPE RTRACE 2,1000;
  INITIAL INVALID;
  TRACETYPE WAVEFORM;
  POINTS WF_SIZE;
  XMIN XMIN_2;
  XINCR XINC_2;
  XLOG OFF;
  XUNIT "s";
  GET ACTIONS;
   IF VIEW_CH2 THEN; !WAB
   output string ":MENU 0;";
    OUTPUT STRING ":WAV:SOURCE CHAN2;";
    OUTPUT STRING ":WAV:BYT MSBF;";
    SET NUM_POINTS; !WAB
    GET WF_SIZE; ! gets scaling parameters for CH2 along with wf size ...
    fetch WF_SIZE; fetch 2; div; store WF_SIZE;
    OUTPUT STRING ":WAV:DATA?;";
      ENTER PEAK_CH2 FORMAT INT16 10 WF_SIZE,2;
      ENTER CHARSTRING FORMAT K; ! consumes NL at end of binary block
    MATSCALE 1,YREF PEAK_CH2; ! subtracts yref from array ...
    MATSCALE YINCREMENT,YORIGIN PEAK_CH2; ! scales y-data in array ...

    GET X_MIN; FETCH X_MIN; STORE XMIN_2;
    GET X_INC; FETCH X_INC; STORE XINC_2;
  END IF;
END ACTIONS;
END COMPONENT;

!>> Digitize/Upload routines

COMPONENT DIGITIZE NOTSAVED;
  TYPE INTEGER;
  INITIAL DONTCARE;
  COUPLED WF_TMIN,WF_TMAX;

  SET ACTIONS;

    !   Determine if any channels are enabled for 'digitize'
    ! operation -- note that the algorithm depends on a non-zero
    ! representation for 'ON' ...
    FETCH VIEW_CH1; FETCH VIEW_CH2; ADD;

    IF STACK THEN; ! at least one channel enabled for acquisition

        gosub digitize_chan;

            if livemode then;
              fetch addr;
              fetch 100;
              lt;
              if stack then;  ! serial
                wait time 0.01;
              else;           !hpib
                wait spoll bit 5;
              end if;
            end if;

        GOSUB UPDATE_TRACE_DATA;
    else;
        if panelmode then;
            notify "No channels enabled for digitize operation";
        end if;
    END IF;
  END ACTIONS;
END COMPONENT;

component digitize_imm notsaved noerrcheck;
    type integer;
    initial dontcare;
    set actions;

    !   Determine if any channels are enabled for 'digitize'
    ! operation -- note that the algorithm depends on a non-zero
    ! representation for 'ON' ...
    FETCH VIEW_CH1; FETCH VIEW_CH2; ADD;

    IF STACK THEN; ! at least one channel enabled for acquisition
        gosub digitize_chan;
    else;
        if panelmode then;
            notify "No channels enabled for digitize operation";
        end if;
    END IF;
    end actions;
end component;

actions digitize_chan;

    output string "*CLS; *SRE 32; *ESE 1;"; flush;

      IF VIEW_CH1 THEN;
        OUTPUT STRING ":DIG CHAN1";
        IF VIEW_CH2 THEN;
          OUTPUT STRING ",CHAN2";
        END IF;
      ELSE;
        IF VIEW_CH2 THEN;
          OUTPUT STRING ":DIG CHAN2";
        END IF;
      END IF;

    flush; output string "*OPC";

end actions;

ACTIONS UPDATE_TRACE_DATA;
  get probe_ch1;
  get probe_ch2; ! compensate for auto-detect feature in scope
  get MIN_SENS_CH1; get MAX_SENS_CH1;
  get SENS_CH1; get OFFSET_CH1; get VMIN_CH1; get VMAX_CH1; get SENS_INCR_CH1;
  get MIN_SENS_CH2; get MAX_SENS_CH2;
  get SENS_CH2; get OFFSET_CH2; get VMIN_CH2; get VMAX_CH2; get SENS_INCR_CH2;
  get vmarker1; get vmarker2;
  get VMIN_MSMT; get VMAX_MSMT;
  GOSUB INVALIDATE_TRACE_DATA;
  GOSUB UPLOAD_TRACE_DATA; ! upload waveforms to refresh XY screen
END ACTIONS;

ACTIONS INVALIDATE_TRACE_DATA;

  INVALIDATE WF_CH1;
  INVALIDATE WF_CH2;

  INVALIDATE PEAK_CH1;
  INVALIDATE PEAK_CH2;

END ACTIONS;

ACTIONS UPLOAD_TRACE_DATA;

  ! Upload data from channel buffers in scope -- assumes that at least
  ! one channel has been digitized prior to attempted upload operation ...

  IF VIEW_CH1 THEN;
    SELECT WF_TYPE;
    CASE peak;
      GET PEAK_CH1;
    CASE ELSE;
      GET WF_CH1;
    END SELECT;
  END IF;

  IF VIEW_CH2 THEN;
    SELECT WF_TYPE;
    CASE peak;
      GET PEAK_CH2;
    CASE ELSE;
      GET WF_CH2;
    END SELECT;
  END IF;

END ACTIONS;

!==============================
! AUTOSCALE OPERATIONS
!==============================

COMPONENT AUTOSCALE NOTSAVED;

  TYPE INTEGER;
  INITIAL DONTCARE;

  COUPLED   WF_TMIN,WF_TMAX, WF_TYPE,acq_points,

  BWLIMIT_CH1,COUPLING_CH1,invert_ch1,BWLIMIT_CH2,COUPLING_CH2,invert_ch2,
  math_ch,

  SENS_CH1,OFFSET_CH1,VMIN_CH1,VMAX_CH1,SENS_INCR_CH1,
  VIEW_CH1,VIEW_WF_CH1,VIEW_PEAK_CH1,
  SENS_CH2,OFFSET_CH2,VMIN_CH2,VMAX_CH2,SENS_INCR_CH2,
  VIEW_CH2,VIEW_WF_CH2,VIEW_PEAK_CH2,

  trig_mode,trig_source,trig_coupling,trig_slope,trig_level,trig_holdoff,
  trig_rej,trig_noise_rej,

  VMIN_MSMT,VMAX_MSMT,meas_source,

  AUTOSCALE;

  SET ACTIONS;
    OUTPUT STRING ":AUTOSCALE";
    invalidate VMARKER1; invalidate VMARKER2; invalidate vmarker_delta;
    invalidate TMARKER1; invalidate TMARKER2; invalidate tmarker_delta;
    fetch 0; store marker_state;
     enable NUM_POINTS,n100,n200,n250,n400,n500,n800,n1000,n4000,n5000;
     GET TIME_DELAY;
    GET TIME_REF;
  END ACTIONS;
  panel get actions;   ! update the trace only after all the couplings
                       ! are executed.
    GOSUB UPDATE_TRACE_DATA;
  end actions;
END COMPONENT;

actions set_init;
    enable trig_mode,tv; enable trig_source,ext,line;
    enable NUM_POINTS,n100,n200,n250,n400,n500,n800,n1000,n4000,n5000;
   ! set NUM_POINTS;  ! force 500 WAV points at init !NoGood- WAB

    IF PANELMODE THEN;
      SHOW ROOT, CRT;
      SHOW CONTROLS, STANDARD;
      SHOW ROOT, CONTROLS;
      SHOW DISPLAY_SUBSYSTEM, DISPLAY_MEM_CONTROLS;
      show trig_1; show trig_no_tv; show meas_main;
      set SUBSYSTEM;
      GOSUB UPLOAD_TRACE_DATA;
    END IF;
end actions;

actions kill_meas_stor_fns;
  disable math_ch plus,sub;
end actions;
 

actions set_NUM_POINTS;
    select WF_TYPE;
        case peak;
            fetch (NUM_POINTS)n1000; store NUM_POINTS; set NUM_POINTS;
            disable NUM_POINTS,n100,n200,n250,n400,n500,n800,n2000,n4000,n5000;
        case else;
            enable NUM_POINTS,n100,n200,n250,n400,n500,n800,n2000,n4000,n5000;
     end select;
end actions;

! =========================================================
! PANEL ELEMENTS
! =========================================================

PANEL ROOT;

  POSITION 0,0;
  SIZE 428,213;

  PANEL CRT;
    POSITION 0,0;
    SIZE 214,213;

    XY WF_DATA;

      POSITION 5,48;
      SIZE 204,160;

      SCALE -5,5 -4,4;
      GRATICULE XY_GRATICULE;

      TRACE WF_CH1;
        STATE VIEW_WF_CH1;
        FOREGROUND (255,255,0),100;
        SCALE 1,WF_SIZE,VMIN_CH1,VMAX_CH1;
      END TRACE;
      TRACE PEAK_CH1;
        STATE VIEW_PEAK_CH1;
        FOREGROUND (255,255,0),100;
        SCALE 1,WF_SIZE,VMIN_CH1,VMAX_CH1;
      END TRACE;

      TRACE WF_CH2;
        STATE VIEW_WF_CH2;
        FOREGROUND (0,255,255),100;
        SCALE 1,WF_SIZE,VMIN_CH2,VMAX_CH2;
      END TRACE;
      TRACE PEAK_CH2;
        STATE VIEW_PEAK_CH2;
        FOREGROUND (0,255,255),100;
        SCALE 1,WF_SIZE,VMIN_CH2,VMAX_CH2;
      END TRACE;

      ! V/T Markers

      MARKER VMARKER1;
        TYPE HORIZONTAL;
        FOREGROUND (255,255,255),100;
        state marker_state;
        SCALE WF_TMIN,WF_TMAX,VMIN_MSMT,VMAX_MSMT;
      END MARKER;
      MARKER VMARKER2;
        TYPE HORIZONTAL;
        FOREGROUND (255,255,255),100;
        state marker_state;
        SCALE WF_TMIN,WF_TMAX,VMIN_MSMT,VMAX_MSMT;
      END MARKER;
      MARKER TMARKER1;
        TYPE VERTICAL;
        FOREGROUND (255,255,255),100;
        state marker_state;
        SCALE WF_TMIN,WF_TMAX,0,1;
      END MARKER;
      MARKER TMARKER2;
        TYPE VERTICAL;
        FOREGROUND (255,255,255),100;
        state marker_state;
        SCALE WF_TMIN,WF_TMAX,0,1;
      END MARKER;

    END XY;

    BUTTON DIGITIZE;
      POSITION 5,25;
      SIZE 77,19;
      LABEL "Digitize";
      background (0,130,70) 0;
    END BUTTON;

    BUTTON AUTOSCALE;
      POSITION 87,25;
      SIZE 86,19;
      LABEL "Autoscale";
      background (0,130,70) 0;
    END BUTTON;

    BUTTON RUN;
      POSITION 178,25;
      SIZE 32,19;
      LABEL "Run";
      background (0,130,70) 0;
    END BUTTON;

    TOGGLE VIEW_CH1;
      POSITION 5,3;
      SIZE 95,19;
      LABEL "CH1","CH1";
      FOREGROUND (255,255,0),100;
      BACKGROUND (105,95,80),0;
      STYLE "HIGHLIGHT";
    END TOGGLE;

    TOGGLE VIEW_CH2;
      POSITION 115,3;
      SIZE 95,19;
      LABEL "CH2","CH2";
      FOREGROUND (0,255,255),100;
      BACKGROUND (105,95,80),0;
      STYLE "HIGHLIGHT";
    END TOGGLE;

  END PANEL;

  ! =========================
  ! CONTROL PANELS
  ! =========================

  PANEL CONTROLS;

    POSITION 214,0;
    SIZE 214,213;
    FOREGROUND (255,255,255),100;

    ! =========================
    ! RESET & MAIN MENU
    ! =========================

    BUTTON RESET;
      POSITION 6,188;
      SIZE 54,19;
      BACKGROUND (0,130,70), 0;
      LABEL "Reset";
    END BUTTON;

    DISCRETE SUBSYSTEM;
      POSITION 72,188;
      SIZE 136,19;
      BACKGROUND (75,0,240), 0;

      LABEL "Main Panel", "Timebase Panel","Channel Panel",
      "Trigger Panel","Measure Panel", "Markers Panel","Waveform Panel",
      "Display Panel","Status Panel", "About Panel";

    END DISCRETE;

    ! ================================
    ! SUBPANEL: SYSTEM UTILITIES
    ! ================================

    PANEL STANDARD;

      POSITION 0,0;
      SIZE 214,183;
      FOREGROUND (255,255,255),100;

      TEXT 5,157 "Timebase";
      CONTINUOUS TIME_SENS;
        POSITION 115,157;
        SIZE 75,19;
        FORMAT "5 DIGITS";
      END CONTINUOUS;
      button disp_temp;
        position 190,157;
        size 20,19;
        background (105,95,80),0;
        label "s/";
      end button;

        text 5,132,"TRIG Source";
        discrete trig_source;
            position 115,132;
            size 95,19;
            label "Channel 1","Channel 2","External","Line";
        end discrete;

      text 5,107,"TRIG Mode";
      discrete trig_mode;
         position 115,107;
         size 95,19;
         label "Auto LVL","Auto","Normal","Single","TV";
      end discrete;

            text 5,82,"TRIG Level";
            continuous trig_level;
                position 115,82;
                size 80,19;
                format "4 DIGITS";
            end continuous;
            button disp_temp;
                position 195,82;
                size 15,19;
                background (105,95,80),0;
                label "V";
            end button;

      text  84,51,"SENS"; text 162,51,"Probe";

      TEXT 5,25 "CH1";
      CONTINUOUS SENS_CH1;
        POSITION 50,25;
        SIZE 85,19;
        FORMAT "5 DIGITS";
        STEP LOG 3,1;
      END CONTINUOUS;
       button disp_temp;
         position 135,25;
          size 20,19;
          background (105,95,80),0;
           label "V/";
       end button;
      discrete PROBE_CH1;
        POSITION 160,25;
        SIZE 50,19;
        label "1","10","100";
      END discrete;

      TEXT 5,3 "CH2";
      CONTINUOUS SENS_CH2;
        POSITION 50,3;
        SIZE 85,19;
        FORMAT "5 DIGITS";
        STEP LOG 3,1;
      END CONTINUOUS;
       button disp_temp;
         position 135,3;
          size 20,19;
          background (105,95,80),0;
           label "V/";
       end button;
      discrete PROBE_CH2;
        POSITION 160,3;
        SIZE 50,19;
        label "1","10","100";
      END discrete;

    END PANEL; ! SYSTEM SUBSYSTEM

    ! =========================
    ! SUBPANEL: DISPLAY
    ! =========================

    PANEL DISPLAY_SUBSYSTEM;

      POSITION 0,0;
      SIZE 214,183;
      FOREGROUND (255,255,255),100;

      TEXT 5,155 "DISP Mode";
      DISCRETE WF_TYPE;
        POSITION 110,155;
        SIZE 100,19;
        LABEL "Normal","Average","Peak DET";
      END DISCRETE;

        TEXT 5,130 "Grid";
        toggle disp_grid;
          POSITION 110,130;
          SIZE 100,19;
          LABEL "Off","On";
        END toggle;

          TEXT 5,105 "# Average";
          discrete HIT_COUNT;
            POSITION 110,105;
            SIZE 100,19;
            label "8","64","256";
          END discrete;

      PANEL DISPLAY_MEM_CONTROLS;
        POSITION 5,5;
        SIZE 202,95;
        FOREGROUND (255,255,255),100;

        TEXT 5,65 "Merge";
        BUTTON MERGE_PM1;
          POSITION 85,65;
          SIZE 50,19;
          LABEL "PMEM1";
          background (0,130,70) 0;
        END BUTTON;
        BUTTON MERGE_PM2;
          POSITION 145,65;
          SIZE 50,19;
          LABEL "PMEM2";
          background (0,130,70) 0;
        END BUTTON;

        TEXT 5,45 "Download";
        BUTTON download_PM1;
          POSITION 85,45;
          SIZE 50,19;
          LABEL "PMEM1";
          background (0,130,70) 0;
        END BUTTON;
        BUTTON download_PM2;
          POSITION 145,45;
          SIZE 50,19;
          LABEL "PMEM2";
          background (0,130,70) 0;
        END BUTTON;

        TEXT 5,25 "Upload";
        BUTTON upload_PM1;
          POSITION 85,25;
          SIZE 50,19;
          LABEL "PMEM1";
          background (0,130,70) 0;
        END BUTTON;
        BUTTON upload_PM2;
          POSITION 145,25;
          SIZE 50,19;
          LABEL "PMEM2";
          background (0,130,70) 0;
        END BUTTON;

        TEXT 5,5 "Erase";
        BUTTON erase_PM1;
          POSITION 85,5;
          SIZE 50,19;
          LABEL "PMEM1";
          background (0,130,70) 0;
        END BUTTON;
        BUTTON erase_PM2;
          POSITION 145,5;
          SIZE 50,19;
          LABEL "PMEM2";
          background (0,130,70) 0;
        END BUTTON;

      END PANEL;
    END PANEL; ! DISPLAY_SUBSYSTEM

    ! =========================
    ! SUBPANEL: TRIGGER
    ! =========================

    PANEL TRIGGER_SUBSYSTEM;

      POSITION 0,0;
      SIZE 214,183;
      FOREGROUND (255,255,255),100;

      text 5,155,"TRIG Mode";
      discrete trig_mode;
         position 95,155;
         size 115,19;
         label "Auto LVL","Auto","Normal","Single","TV";
      end discrete;

        panel trig_1;
          size 212,150;
          position 0,0;

            text 5,130,"Source";
              discrete trig_source;
                 position 95,130;
                 size 115,19;
                 label "Channel 1","Channel 2","External","Line";
              end discrete;

            text 5,105,"Coupling";
              toggle trig_coupling;
                 position 95,105;
                 size 115,19;
                 label "DC","AC";
              end toggle;

            text 5,80,"Level";
            continuous trig_level;
                position 95,80;
                size 100,19;
                format "6 DIGITS";
            end continuous;
            button disp_temp;
                position 195,80;
                size 15,19;
                background (105,95,80),0;
                label "V";
            end button;

            text 5,55,"Slope";
              toggle trig_slope;
                 position 95,55;
                 size 115,19;
                 label "Positive","Negative";
              end toggle;

            text 5,30,"Holdoff";
            continuous trig_holdoff;
                position 95,30;
                size 100,19;
                format "6 DIGITS";
            end continuous;
            button disp_temp;
                position 195,30;
                size 15,19;
                background (105,95,80),0;
                label "s";
            end button;

            button trig_show_next;
                position 5,5;
                size 205,19;
                background (0,130,70) 0;
                label "Next";
            end button;

        end panel; !  end trig_1 panel

        panel trig_2;
          size 212,150;
          position 0,0;

            panel trig_tv;
                  size 212,95;
                  position 0,55;

                text 5,70,"Polarity (TV)";
                  toggle trig_tv_pol;
                     position 140,70;
                     size 70,19;
                     label "POS","NEG";
                  end toggle;

                text 5,40,"HF Reject (TV)";
                  toggle trig_tv_hfrej;
                     position 140,40;
                     size 70,19;
                     label "Off","On";
                  end toggle;

                text 5,10,"TV Mode";
                  discrete trig_tv_mode;
                     position 140,10;
                     size 70,19;
                     label "Line","Field 1","Field 2";
                  end discrete;

            end panel; ! end panel trig_tv

            panel trig_no_tv;
                  size 212,95;
                  position 0,55;

                text 5,60,"Reject Filter";
                  discrete trig_rej;
                     position 140,60;
                     size 70,19;
                     label "Off","LF","HF";
                  end discrete;

                text 5,20,"Noise Reject";
                  toggle trig_noise_rej;
                     position 140,20;
                     size 70,19;
                     label "Off","On";
                  end toggle;

            end panel; ! end panel trig_no_tv

            button digitize_imm;
                position 5,35;
                size 205,19;
                background (0,130,70) 0;
                label "Digitize (No wait)";
            end button;

            button trig_show_prev;
                position 5,5;
                size 205,19;
                background (0,130,70) 0;
                label "Previous";
            end button;

        end panel; !  end trig_2 panel

    END PANEL; ! TRIGGER_SUBSYSTEM

    ! =========================
    ! SUBPANEL: TIMEBASE
    ! =========================

    PANEL TIMEBASE_SUBSYSTEM;
      POSITION 0,0;
      SIZE 214,183;
      FOREGROUND (255,255,255),100;

        TEXT 5,130 "HORZ Mode";
         button disp_temp;
             position 100,130;
             size 110,19;
             background (105,95,80),0;
              label "Main";
         end button;
 

        TEXT 5,95 "SENS";
        CONTINUOUS TIME_SENS;
          POSITION 100,95;
          SIZE 90,19;
          FORMAT "5 DIGITS";
        END CONTINUOUS;
         button disp_temp;
             position 190,95;
             size 20,19;
             background (105,95,80),0;
              label "s/";
         end button;

        TEXT 5,60 "Delay";
        CONTINUOUS TIME_DELAY;
          POSITION 100,60;
          SIZE 95,19;
          FORMAT "5 DIGITS";
        END CONTINUOUS;
         button disp_temp;
             position 195,60;
             size 15,19;
             background (105,95,80),0;
              label "s";
         end button;

        TEXT 5,25 "Time REF";
        toggle TIME_REF;
          POSITION 100,25;
          SIZE 110,19;
          LABEL "Left","Center";
        END toggle;

    END PANEL; ! TIMEBASE_SUBSYSTEM

    ! =========================
    ! SUBPANEL: CHANNEL
    ! =========================

    PANEL CHANNEL_SUBSYSTEM;
      POSITION 0,0;
      SIZE 214,183;
      FOREGROUND (255,255,255),100;

      toggle CHANNEL;
        POSITION 5,157;
        SIZE 205,19;
        LABEL "Channel 1","Channel 2";
      END toggle;

      PANEL CH1;
        POSITION 0,0;
        SIZE 212,155;

        TEXT 5,135 "Coupling";
        discrete COUPLING_CH1;
          POSITION 105,135;
          SIZE 105,19;
          LABEL "DC","AC","GND","DC-Fifty";
        END discrete;

        TEXT 5,113 "BW Limit";
        TOGGLE BWLIMIT_CH1;
          POSITION 105,113;
          SIZE 105,19;
          LABEL "Off","On";
        END TOGGLE;

        TEXT 5,91 "Probe ATTN";
        discrete PROBE_CH1;
          POSITION 105,91;
          SIZE 105,19;
          LABEL "1","10","100";
        END discrete;

        TEXT 5,69 "SENS";
        CONTINUOUS SENS_CH1;
          POSITION 105,69;
          SIZE 85,19;
          FORMAT "5 DIGITS";
          STEP LOG 3,1;
        END CONTINUOUS;
           button disp_temp;
         position 190,69;
          size 20,19;
          background (105,95,80),0;
           label "V/";
           end button;

        TEXT 5,47 "Offset";
        CONTINUOUS OFFSET_CH1;
          POSITION 105,47;
          SIZE 90,19;
          FORMAT "5 DIGITS";
        END CONTINUOUS;
           button disp_temp;
         position 195,47;
          size 15,19;
          background (105,95,80),0;
           label "V";
           end button;

        TEXT 5,25 "Invert";
        TOGGLE invert_ch1;
          POSITION 120,25;
          SIZE 90,19;
          LABEL "Off","On";
        END TOGGLE;

        TEXT 5,3 "Math";
        discrete math_ch;
          POSITION 120,3;
          SIZE 90,19;
          LABEL "Off","Plus","Sub";
        END discrete;

      END PANEL; ! CH1

      PANEL CH2;
        POSITION 0,0;
        SIZE 212,155;

        TEXT 5,135 "Coupling";
        discrete COUPLING_CH2;
          POSITION 105,135;
          SIZE 105,19;
          LABEL "DC","AC","GND","DC-Fifty";
        END discrete;

        TEXT 5,113 "BW Limit";
        TOGGLE BWLIMIT_CH2;
          POSITION 105,113;
          SIZE 105,19;
          LABEL "Off","On";
        END TOGGLE;

        TEXT 5,91 "Probe ATTN";
        discrete PROBE_CH2;
          POSITION 105,91;
          SIZE 105,19;
          LABEL "1","10","100";
        END discrete;

        TEXT 5,69 "SENS";
        CONTINUOUS SENS_CH2;
          POSITION 105,69;
          SIZE 85,19;
          FORMAT "5 DIGITS";
          STEP LOG 3,1;
        END CONTINUOUS;
           button disp_temp;
         position 190,69;
          size 20,19;
          background (105,95,80),0;
           label "V/";
           end button;

        TEXT 5,47 "Offset";
        CONTINUOUS OFFSET_CH2;
          POSITION 105,47;
          SIZE 90,19;
          FORMAT "5 DIGITS";
        END CONTINUOUS;
           button disp_temp;
         position 195,47;
          size 15,19;
          background (105,95,80),0;
           label "V";
           end button;

        TEXT 5,25 "Invert";
        TOGGLE invert_ch2;
          POSITION 120,25;
          SIZE 90,19;
          LABEL "Off","On";
        END TOGGLE;

        TEXT 5,3 "Math";
        discrete math_ch;
          POSITION 120,3;
          SIZE 90,19;
          LABEL "Off","Plus","Sub";
        END discrete;

      END PANEL; ! CH2

    END PANEL; ! CHANNEL_SUBSYSTEM

    ! =========================
    ! SUBPANEL: MEASURE
    ! =========================

    PANEL MEASURE_SUBSYSTEM;
      POSITION 0,0;
      SIZE 214,183;
      FOREGROUND (255,255,255),100;

        panel meas_main;
            position 0,0;
            size 212,181;

               text 5,150,"MEAS Source";
              toggle meas_source;
                 position 110,150;
                 size 100,19;
                 label "CHAN 1","CHAN 2";
              end toggle;

            button meas_all;
                position 5,105;
                size 205,19;
                background (0,130,70) 0;
                label "Measure ALL";
            end button;

            button meas_scratch;
                position 5,60;
                size 205,19;
                background (0,130,70) 0;
                label "Scratch";
            end button;

            button meas_show_vmeas;
                position 5,3;
                size 100,19;
                background (0,130,70) 0;
                label "VOLT MEAS";
            end button;

            button meas_show_tmeas;
                position 110,3;
                size 100,19;
                background (0,130,70) 0;
                label "Time MEAS";
            end button;

        end panel; ! end panel meas_main

        panel meas_vmeas;
            position 0,0;
            size 212,181;

            text 5,157,"V PP";
            display meas_v_pp;
                position 75,157;
                size 120,19;
                format "8 DIGITS";
            end display;
            button disp_temp;
                position 195,157;
                size 15,19;
                background (105,95,80),0;
                label "V";
            end button;

            text 5,135,"V AVRG";
            display meas_v_avrg;
                position 75,135;
                size 120,19;
                format "8 DIGITS";
            end display;
            button disp_temp;
                position 195,135;
                size 15,19;
                background (105,95,80),0;
                label "V";
            end button;

            text 5,113,"V RMS";
            display meas_v_rms;
                position 75,113;
                size 120,19;
                format "8 DIGITS";
            end display;
            button disp_temp;
                position 195,113;
                size 15,19;
                background (105,95,80),0;
                label "V";
            end button;

            text 5,91,"V MAX";
            display meas_v_max;
                position 75,91;
                size 120,19;
                format "8 DIGITS";
            end display;
            button disp_temp;
                position 195,91;
                size 15,19;
                background (105,95,80),0;
                label "V";
            end button;

            text 5,69,"V MIN";
            display meas_v_min;
                position 75,69;
                size 120,19;
                format "8 DIGITS";
            end display;
            button disp_temp;
                position 195,69;
                size 15,19;
                background (105,95,80),0;
                label "V";
            end button;

            text 5,47,"V TOP";
            display meas_v_top;
                position 75,47;
                size 120,19;
                format "8 DIGITS";
            end display;
            button disp_temp;
                position 195,47;
                size 15,19;
                background (105,95,80),0;
                label "V";
            end button;

            button meas_show_vmeas_more;
                position 5,25;
                size 205,19;
                background (0,130,70) 0;
                label "More Volt MEAS";
            end button;

            button meas_show_tmeas;
                position 5,3;
                size 100,19;
                background (0,130,70) 0;
                label "Time MEAS";
            end button;

            button meas_show_main;
                position 110,3;
                size 100,19;
                background (0,130,70) 0;
                label "MEAS Main";
            end button;

        end panel; ! end panel meas_vmeas

        panel meas_vmeas_more;
            position 0,0;
            size 212,181;

            text 5,157,"V BASE";
            display meas_v_base;
                position 75,157;
                size 120,19;
                format "8 DIGITS";
            end display;
            button disp_temp;
                position 195,157;
                size 15,19;
                background (105,95,80),0;
                label "V";
            end button;

            text 5,135,"V AMPL, OVERSHOOT, and";
            text 5,115,"PRESHOOT not available";
            text 5,95,"with HP-IB module.";

            button meas_show_vmeas;
                position 5,5;
                size 205,19;
                background (0,130,70) 0;
                label "Return";
            end button;

        end panel;

        panel meas_tmeas;
            position 0,0;
            size 212,181;

            text 5,155,"Frequency";
            display meas_t_freq;
                position 100,155;
                size 85,19;
                format "6 DIGITS";
            end display;
            button disp_temp;
                position 185,155;
                size 25,19;
                background (105,95,80),0;
                label "Hz";
            end button;

            text 5,130,"Period";
            display meas_t_period;
                position 100,130;
                size 95,19;
                format "6 DIGITS";
            end display;
            button disp_temp;
                position 195,130;
                size 15,19;
                background (105,95,80),0;
                label "s";
            end button;

            text 5,105,"Duty Cycle";
            display meas_t_duty;
                position 100,105;
                size 110,19;
                format "7 DIGITS";
            end display;

            text 5,80,"POS Width";
            display meas_t_pwid;
                position 100,80;
                size 95,19;
                format "6 DIGITS";
            end display;
            button disp_temp;
                position 195,80;
                size 15,19;
                background (105,95,80),0;
                label "s";
            end button;

            text 5,55,"NEG Width";
            display meas_t_nwid;
                position 100,55;
                size 95,19;
                format "6 DIGITS";
            end display;
            button disp_temp;
                position 195,55;
                size 15,19;
                background (105,95,80),0;
                label "s";
            end button;

            button meas_show_tmeas_more;
                position 5,30;
                size 205,19;
                background (0,130,70) 0;
                label "More Time MEAS";
            end button;

            button meas_show_vmeas;
                position 5,5;
                size 100,19;
                background (0,130,70) 0;
                label "VOLT MEAS";
            end button;

            button meas_show_main;
                position 110,5;
                size 100,19;
                background (0,130,70) 0;
                label "MEAS Main";
            end button;

        end panel; ! end panel meas_tmeas

        panel meas_tmeas_more;
            position 0,0;
            size 212,181;

            text 5,157,"Rise Time";
            display meas_t_rtime;
                position 100,157;
                size 95,19;
                format "6 DIGITS";
            end display;
            button disp_temp;
                position 195,157;
                size 15,19;
                background (105,95,80),0;
                label "s";
            end button;

            text 5,135,"Fall Time";
            display meas_t_ftime;
                position 100,135;
                size 95,19;
                format "6 DIGITS";
            end display;
            button disp_temp;
                position 195,135;
                size 15,19;
                background (105,95,80),0;
                label "s";
            end button;

            text 5,118,"-----------------------";
            text 5,95,"Voltage";
            continuous meas_t_tvolt;
                position 100,95;
                size 95,19;
                format "6 DIGITS";
            end continuous;
            button disp_temp;
                position 195,95;
                size 15,19;
                background (105,95,80),0;
                label "V";
            end button;

            text 5,73,"Edge";
            continuous meas_t_tvolt_edge;
                position 100,73;
                size 110,19;
                format "6 DIGITS";
            end continuous;

            text 40,55,"Time Interval";
            display meas_t_tvolt_time;
                position 5,30;
                size 190,19;
                format "7 DIGITS";
            end display;
            button disp_temp;
                position 195,30;
                size 15,19;
                background (105,95,80),0;
                label "s";
            end button;

            button meas_show_tmeas;
                position 5,5;
                size 205,19;
                background (0,130,70) 0;
                label "Return";
            end button;

        end panel; ! end panel meas_tmeas_more

    END PANEL; ! MEASURE_SUBSYSTEM

    ! =========================
    ! SUBPANEL: MARKERS
    ! =========================

    PANEL MARKER_SUBSYSTEM;
      POSITION 0,0;
      SIZE 214,183;
      FOREGROUND (255,255,255),100;

               text 5,157,"Source";
              toggle meas_source;
                 position 75,157;
                 size 135,19;
                 label "CHAN 1","CHAN 2";
              end toggle;

              toggle marker_state;
                 position 5,135;
                 size 205,19;
                 label "Markers OFF","Markers ON";
              end toggle;

          TEXT 5,113 "V 1";
          button v1_prev;
                position 40,113;
                size 25,19;
                background (0,130,70) 0;
                label "<<";
          end button;
          CONTINUOUS VMARKER1;
            POSITION 65,113;
            SIZE 105,19;
            FORMAT "6 DIGITS";
          END CONTINUOUS;
           button disp_temp;
         position 170,113;
          size 15,19;
          background (105,95,80),0;
           label "V";
           end button;
          button v1_next;
                position 185,113;
                size 25,19;
                background (0,130,70) 0;
                label ">>";
          end button;

          TEXT 5,91 "V 2";
          button v2_prev;
                position 40,91;
                size 25,19;
                background (0,130,70) 0;
                label "<<";
          end button;
          CONTINUOUS VMARKER2;
            POSITION 65,91;
            SIZE 105,19;
            FORMAT "6 DIGITS";
          END CONTINUOUS;
           button disp_temp;
         position 170,91;
          size 15,19;
          background (105,95,80),0;
           label "V";
           end button;
          button v2_next;
                position 185,91;
                size 25,19;
                background (0,130,70) 0;
                label ">>";
          end button;

          TEXT 5,69 "t 1";
          button t1_prev;
                position 40,69;
                size 25,19;
                background (0,130,70) 0;
                label "<<";
          end button;
          CONTINUOUS TMARKER1;
            POSITION 65,69;
            SIZE 105,19;
            FORMAT "6 DIGITS";
          END CONTINUOUS;
           button disp_temp;
         position 170,69;
          size 15,19;
          background (105,95,80),0;
           label "s";
           end button;
          button t1_next;
                position 185,69;
                size 25,19;
                background (0,130,70) 0;
                label ">>";
          end button;

          TEXT 5,47 "t 2";
          button t2_prev;
                position 40,47;
                size 25,19;
                background (0,130,70) 0;
                label "<<";
          end button;
          CONTINUOUS TMARKER2;
            POSITION 65,47;
            SIZE 105,19;
            FORMAT "6 DIGITS";
          END CONTINUOUS;
           button disp_temp;
         position 170,47;
          size 15,19;
          background (105,95,80),0;
           label "s";
           end button;
          button t2_next;
                position 185,47;
                size 25,19;
                background (0,130,70) 0;
                label ">>";
          end button;

          TEXT 5,25 "V Delta";
          display vmarker_delta;
            POSITION 75,25;
            SIZE 120,19;
            FORMAT "6 DIGITS";
          END display;
           button disp_temp;
         position 195,25;
          size 15,19;
          background (105,95,80),0;
           label "V";
           end button;

          TEXT 5,3 "t Delta";
          display tmarker_delta;
            POSITION 75,3;
            SIZE 120,19;
            FORMAT "6 DIGITS";
          END display;
           button disp_temp;
         position 195,3;
          size 15,19;
          background (105,95,80),0;
           label "s";
           end button;

    END PANEL; ! MARKER_SUBSYSTEM

    ! =========================
    ! SUBPANEL: WAVEFORM
    ! =========================

    PANEL WAVEFORM_SUBSYSTEM;
      POSITION 0,0;
      SIZE 214,183;
      FOREGROUND (255,255,255),100;

      TEXT 5,140,"Waveform";
      DISCRETE WF_TYPE;
        POSITION 120,140;
        SIZE 90,19;
        LABEL "Normal","Average","Peak DET";
      END DISCRETE;

        TEXT 5,100 "WAV Points";
        discrete NUM_POINTS;
          POSITION 120,100;
          SIZE 90,19;
          label "100","200","250","400","500","800","1000","2500","4000","5000";
          END discrete;

        TEXT 5,60 "Completion";
        CONTINUOUS COMPLETION;
          POSITION 120,60;
          SIZE 75,19;
          style "NOENGR";
          FORMAT "DDDD";
        END CONTINUOUS;
         button disp_temp;
             position 195,60;
             size 15,19;
             background (105,95,80),0;
              label "%";
         end button;

        TEXT 5,20 "ACQ Points";
        display acq_points;
          POSITION 120,20;
          SIZE 90,19;
          style "NOENGR";
          FORMAT "DDDD";
        END display;

    END PANEL; ! WAVEFORM_SUBSYSTEM

    ! =========================
    ! SUBPANEL: STATUS
    ! =========================

    PANEL STATUS_PANEL;

      POSITION 0,0;
      SIZE 214,183;
      FOREGROUND (255,255,255),100;

        text 5,155,"Self Test";
        display stat_self_test;
            position 130,155;
            size 80,19;
        end display;

        text 5,130,"Event REG";
        display stat_evnt_evr;
            position 130,130;
            size 80,19;
        end display;

        text 5,105,"Event Enable";
        continuous stat_evnt_enr;
            position 130,105;
            size 80,19;
        end continuous;

        text 5,80,"SRQ Enable";
        continuous stat_sre;
            position 130,80;
            size 80,19;
        end continuous;

        text 5,55,"Status Byte";
        display stat_stb;
            position 130,55;
            size 80,19;
        end display;

        text 5,30, "Error";
        display stat_err;
            position 130,30;
            size 80,19;
        end display;

        button stat_opc;
            position 5,5;
            size 45,19;
            background (0,130,70) 0;
            label "OPC";
        end button;

        text 70,5, "OPC?";
        display stat_opcv;
            position 115,5;
            size 25,19;
        end display;

        button stat_wai;
            position 165,5;
            size 45,19;
            background (0,130,70) 0;
            label "WAI";
        end button;

    END PANEL; ! Status panel;

    ! =========================
    ! SUBPANEL: ABOUT ...
    ! =========================

    PANEL ABOUT_PANEL;
      POSITION 0,0;
      SIZE 214,183;
      FOREGROUND (255,255,255),100;

      TEXT "HP 54615B";
        POSITION 36,131;
        FONT 15,25;
      END TEXT;
      TEXT 5,120 "Digitizing Oscilloscope";

      TEXT 5,89 "Option";
      DISPLAY OPTIONS;
        POSITION 65,89;
        SIZE 142,19;
      END DISPLAY;

      TEXT 30,60 "Revision A.00.04";
      TEXT 49,43 "Copyright (C)";
      TEXT 23,26 "Hewlett-Packard Co.";
      TEXT 59,9 "1996, 1997";
    END PANEL;

  END PANEL; ! CONTROLS

END PANEL; ! ROOT