!-----------------------------------------------------------------
! Instrument Driver for the TEK VX4224 Universal Counter
! Rev. A.00.00
! Copyright (C) Hewlett-Packard Co. 1996.  All rights reserved.
! Based on the HP E1420 driver.
!-----------------------------------------------------------------

revision 2.0;
initialize reset;
error component stat_err_no;
update component update_reading;
sync component sync;

component reset notsaved;
    type integer;
    set actions;
     pokeinitial;
     clear; output string "*ESE 60"; flush; get model_B;
     output string "*RST; *CLS"; gosub op_wait;
    end actions;
    panel set actions;
     show tkvx4224,reset_panel;
     gosub reset_sub_panels;
     set menu;
    end actions;
end component;

component update_reading;
    type integer;
    get actions;
        get reading;
    end actions;
end component;

component option_010 nogen noerrcheck;
    type integer;
    initial 0;
end component;

component option_030 clone option_010;
component option_040 clone option_010;

actions reset_sub_panels;
 hide config; show meas;
 hide channel2; hide channel3; show channel1;
 gosub set_func1_config;
 hide trig2; show trig1;
 hide stat_reg; show stat_main;
 set inp_chan;
end actions;

component menu notsaved nogen noerrcheck;
    type discrete ;
    values main,input_c,trigger,arm,misc,output,vme_memory,status,about;
    initial main;
    panel set actions;
     hide tkvx4224,main;
     hide tkvx4224,input_c;
     hide tkvx4224,trigger;
     hide tkvx4224,misc;
     hide tkvx4224,arm;
     hide tkvx4224,output;
     hide tkvx4224,vme_memory;
     hide tkvx4224,status;
     hide tkvx4224,about;

     select menu;
      case main;
       show tkvx4224, main;
      case input_c;
       show tkvx4224, input_c;
      case arm;
       show tkvx4224, arm;
      case output;
       show tkvx4224, output;
      case trigger;
       show tkvx4224, trigger;
      case misc;
       show tkvx4224, misc;
      case vme_memory;
       show tkvx4224, vme_memory;
      case status;
       show tkvx4224, status;
      case about;
       show tkvx4224, about;
     end select;
    end actions;
end component;

!
! scratch components
!
component temp_string notsaved nogen noerrcheck ;
    type string 80;
end component;

component temp_str2 notsaved nogen noerrcheck ;
    type string 80;
end component;

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

actions op_wait;
    flush; wait time 0.1;
end actions;
!
! main  panel components -  channels : 1,2,3
!

component prev_channel notsaved nogen noerrcheck;
    type integer;
    initial 1;
end component;

component prev_meas_init_cont notsaved nogen noerrcheck;
    type integer;
    initial 0;
end component;

component channel;
    type discrete;
    values '1','2','3';
    initial '1';
    !! coupled setup_read_operation;
    set actions;

     if prev_meas_init_cont then;
         output string ":INIT"; output prev_channel format K;
         output string ":CONT 0"; gosub op_wait;
     end if;

     invalidate reading;

     select channel;
      case '1';
             fetch 1; store prev_channel;
            set function1;
      case '2';
             fetch 2; store prev_channel;
            set function2;
      case '3';
             fetch 3; store prev_channel;
            set function3;
     end select;

     fetch 0; dup; store meas_init_cont; store prev_meas_init_cont;

     if recalling then;
     else;
        get setup_read_operation;
     end if;

    end actions;
    panel set actions;
     hide channel1; hide channel2; hide channel3;
     select channel;
      case '1';
       fetch unit1; show channel1;
      case '2';
       fetch unit2; show channel2;
      case '3';
       fetch unit3; show channel3;
     end select;
     store unit;
    end actions;
end component;

component model_B;
    type discrete;
    values no,yes;
    initial yes;
    get actions;

    if livemode then;
        disable menu,vme_memory;
            fetch (model_B)yes; store model_B;
            fetch 0; store option_040;

        if sync then; ! Don't send this during sync -- it reprograms the unit
        else;
          ! option 010 check

          clear; output string "*CLS"; flush;
          output string ":SENS:ROSC:SOUR INT"; gosub op_wait;
          spoll; fetch 5; bit;
          if stack then;  ! error
              fetch 0; store option_010;
          else;
              fetch 1; store option_010;
          end if;
          clear; output string "*CLS"; flush;

          ! option 030 check

          output string ":MEAS3:FREQ?"; gosub op_wait;
          spoll; fetch 5; bit;
          if stack then;   ! error
              fetch 0; store option_030;
              disable channel,'3';
          else;
              fetch 1; store option_030;
              enable channel,'3';
          end if;
        end if;

    else;  ! livemode off

        disable menu,vme_memory;
        enable channel,'3';
        fetch 1; store option_010;
        fetch 1; store option_030;
        fetch 0; store option_040;

    end if;

    clear;
    output string "*CLS";

    end actions;
end component;

component unit nogen noerrcheck ;    !
    type string 2;
    initial "Hz";
end component;

component unit1 nogen noerrcheck ;    !
    type string 2;
    initial "Hz";
end component;

component unit2 nogen noerrcheck ;    !
    type string 2;
    initial "Hz";
end component;

component unit3 nogen noerrcheck ;    !
    type string 2;
    initial "Hz";
end component;

component show_config notsaved nogen noerrcheck;
    type integer;
    panel set actions;
         if function1 then; else;
            if expected1 then; else; invalidate expected1; end if;
            if resolution1 then; else; invalidate resolution1; end if;
         end if;
         if function2 then; else;
            if expected2 then; else; invalidate expected2; end if;
            if resolution2 then; else; invalidate resolution2; end if;
         end if;
         if function3 then; else;
            if expected3 then; else; invalidate expected3; end if;
            if resolution3 then; else; invalidate resolution3; end if;
         end if;
        hide meas; show config;
    end actions;
end component;

component show_meas notsaved nogen noerrcheck;
    type integer;
    set actions;
     select channel;
      case '1'; get function1;
      case '2'; get function2;
      case '3'; get function3;
     end select;
    end actions;
    panel set actions;
        hide config; show meas;
    end actions;
end component;
!
!    function components
!     the foll. set of components and actions define the
!     meas function and optional parameters.
!
!
! for channel 1
!
component function1;
    type discrete ;
    values freq,per,rat,risetime,falltime,pwid,nwid,tint,tot,
           acv,dcv,minv,maxv;
    initial freq;
    coupled average_state,relative_even_lev1,relative_even_lev2,
            auto_trigger1,auto_trigger2,inp1_route,aperture; !!,setup_read_operation;
    set actions;
      validate erf1;
      fetch channel; fetch 0; eq;
      if stack then;
       if recalling then;
         gosub check_range1; ! returns 1 if only function changed.
         store function_changed;
       else;
         fetch 1; store function_changed;
         gosub set_range1;    ! set range for expected1 & resolution1
       end if;
       gosub setconf1;    ! actual i/o to 4224 with all parameters
       gosub setunit1;    ! set unit1 to proper value

       if recalling then; else; get setup_read_operation; end if;
     end if;
    end actions;
    panel set actions;
      fetch channel; fetch 0; eq;
      if stack then; gosub set_func1_config; end if;
    end actions;
    get actions;
      output string "CONF1?"; FLUSH;
      IF LIVEMODE THEN;
        SPOLL; FETCH 4; BIT; DUP; NOT;
        IF STACK THEN;
          DROP; WAIT TIME .05; SPOLL; FETCH 4; BIT; DUP; NOT;
          IF STACK THEN; DROP; WAIT TIME .25; SPOLL; FETCH 4; BIT; END IF;
        END IF;
        IF STACK THEN;
          ENTER temp_string FORMAT "X,K";
          FETCH temp_string; DUP; LENGTH; FETCH 1; SUB; FETCH 1; SWAP; SUBSTR;
          TRIMSTR; DUP; STORE temp_string; FETCH STRING " "; POS; DUP;
          IF STACK THEN;
            FETCH temp_string; swap; fetch 1; sub; fetch 1; swap; substr;
          ELSE; FETCH temp_string;
          END IF;
          STORE temp_str2;
          SELECT temp_str2;
          CASE "PER"; fetch 1;
          CASE "FREQ:RAT"; fetch 2;
          CASE "RTIM"; fetch 3;
          CASE "RISE:TIME"; fetch 3;
          CASE "FTIM"; fetch 4;
          CASE "FALL:TIME"; fetch 4;
          CASE "PWID"; fetch 5;
          CASE "NWID"; fetch 6;
          CASE "TINT"; fetch 7;
          CASE "TOT"; fetch 8;
          CASE "AC"; fetch 9;
          CASE "DC"; fetch 10;
          CASE "MIN"; fetch 11;
          CASE "MAX"; fetch 12;
          CASE ELSE; FETCH 0;
          END SELECT;
          store function1;
          gosub set_range1;
          gosub setunit1;
          FETCH temp_string; FETCH temp_str2; ne;
          if stack then;
            FETCH temp_string; FETCH temp_str2; length; dup; fetch 1; add; swap;
            FETCH temp_string; length; swap; sub; substr; trimstr;
            store temp_string;
            select function1;
            case range 3,4;
              fetch lower_ref1; gosub getvalfromstring; store lower_ref1;
              fetch upper_ref1; gosub getvalfromstring; store upper_ref1;
            case range 5,6;
              fetch reference1; gosub getvalfromstring; store reference1;
            case else;
            end select;
            select function1;
            case range 0 7;
              fetch expected1; gosub getvalfromstring; store expected1;
              fetch resolution1; gosub getvalfromstring; store resolution1;
            case else;
            end select;
          end if;
          if function1 then; else;
            if expected1 then; else; invalidate expected1; end if;
            if resolution1 then; else; invalidate resolution1; end if;
          end if;
          set erf1;
          fetch channel; fetch 0; ne;
          if stack then;
             fetch 0; store channel;
             fetch 1; store prev_channel;
             fetch 0; dup; store meas_init_cont; store prev_meas_init_cont;
             hide channel2; hide channel3; show channel1;
             fetch unit1; store unit;
             get setup_read_operation;
          end if;
          gosub set_func1_config;
        ELSE; OUTPUT STRING "*CLS"; FLUSH; ! Some other channel must be conf
        END IF;
      ELSE; ENTER temp_string FORMAT "X,K"; ! Not livemode
      END IF;
    end actions;
end component;

actions getvalfromstring;
  fetch temp_string; fetch 1; dup; substr; store temp_str2;
  select temp_str2;
  case ","; ! use default parameter
  case "D"; ! use default parameter
  case "A"; drop; fetch AUTO;
  case "";  ! use default parameter
  case else; drop; fetch temp_string; val;
  end select;
  fetch temp_string; fetch string ","; pos; dup;
  if stack then;
    fetch temp_string; swap; fetch 1; add; fetch 76; substr;
  else; drop; fetch string "";
  end if;
  store temp_string;
end actions;

actions set_func1_config;
    fetch channel; fetch 0; eq;
    if stack then;
         hide rise_panel; hide width1_panel;
        hide res_exp_only1; hide res_exp_only2; hide res_exp_only3;
         hide tint_panel; hide tot1_panel;
         hide width2_panel; hide tot2_panel;

        select function1;
         case range 3 4;    ! rise & fall time
          show rise_panel;
          case range 5 6;    ! pwid & nwid
          show width1_panel;
         case tint;
          show tint_panel;
         case tot;
          show tot1_panel;
         case else;
            show res_exp_only1;
         end select;
    end if;
end actions;

component function_changed notsaved nogen noerrcheck ;
    type integer;
    initial 0;
end component;

component send_config1 notsaved;
    type integer;
    coupled average_state,aperture;
    set actions setconf1;
    panel set actions;
        hide config; show meas;
    end actions;
end component;

component exp_min1 nogen noerrcheck ;
    type continuous  ;
    initial 0.001;
end component;
component exp_max1 nogen noerrcheck ;
    type continuous  ;
    initial 200E6;
end component;

component res_min1 nogen noerrcheck ;
    type continuous  ;
    initial 1E-9;
end component;
component res_max1 nogen noerrcheck ;
    type continuous  ;
    initial 1E5;
end component;

component expected1 nogen noerrcheck;
    type continuous  ;
    values range exp_min1,exp_max1,auto;
    initial 0,INVALID;
    set actions;
      fetch channel; fetch 0; eq;
      if stack then;
        if recalling then;
          select function1;
          case range 0 7; set function1;
          case else;
          end select;
        else; set erf1;
        end if;
      end if;
    end actions;
end component;

component resolution1 nogen noerrcheck;
    type continuous  ;
    values range res_min1,res_max1,auto;
    initial 0,invalid;
    set actions;
      fetch channel; fetch 0; eq;
      if stack then;
        if recalling then;
          select function1;
          case range 0 7; set function1;
          case else;
          end select;
        else; set erf1;
        end if;
      end if;
    end actions;
end component;

component lower_ref1 nogen noerrcheck;        ! used for fn1 == ftime & rtime
    type integer;
    values range 10,90;
    initial 90;
    set actions;
      fetch channel; fetch 0; eq; fetch recalling; and;
      if stack then;
        select function1;
        case range 3 4; set function1;
        case else;
        end select;
      end if;
    end actions;
end component;

component upper_ref1 nogen noerrcheck;        ! used for fn1 == ftime & rtime
    type integer;
    values range 10,90;
    initial 10;
    set actions;
      fetch channel; fetch 0; eq; fetch recalling; and;
      if stack then;
        select function1;
        case range 3 4; set function1;
        case else;
        end select;
      end if;
    end actions;
end component;

component reference1 nogen noerrcheck;            ! used for fn1 == nwid & pwid
    type integer;
    values range 10,90;
    initial 50;
    set actions;
      fetch channel; fetch 0; eq; fetch recalling; and;
      if stack then;
        select function1;
        case range 5 6; set function1;
        case else;
        end select;
      end if;
    end actions;
end component;

component tinterval_delay;
    type continuous  ;
    values range 0,99.999,1E-3;
    initial 100E-3;
    coupled tinterval_delay;
    set actions;
     output tinterval_delay format '":SENS1:TINT:DEL:TIME ",K';
    end actions;
    get actions;
     output string ":SENS1:TINT:DEL:TIME?";
    if livemode then; wait spoll bit 4; end if;
     enter tinterval_delay format k;
    end actions;
end component;

component tinterval_delay_state;
    type discrete ;
    values off,on;
    initial off;
    set actions;
     output string ":SENS1:TINT:DEL:STAT ";
     output tinterval_delay_state table "OFF","ON";
    end actions;
    get actions;
     output string ":SENS1:TINT:DEL:STAT?";
        if livemode then; wait spoll bit 4; end if;
     enter temp_string format K;
     select temp_string;
      case "0";
       fetch (tinterval_delay_state) off;
      case "1";
       fetch (tinterval_delay_state) on;
      case else;
       fetch tinterval_delay_state;
     end select;
     store tinterval_delay_state;
    end actions;
end component;

component tot1_gate_state;
    type discrete ;
    values off,on;
    initial off;
    !! coupled setup_read_operation;
    set actions;
     output string ":SENS1:TOT:GATE:STAT ";
     output tot1_gate_state table "OFF","ON";
        fetch 0; store tot1_flag;

     if recalling then;
     else;
        get setup_read_operation;
     end if;
    end actions;
    get actions;
      output string ":SENS1:TOT:GATE:STAT?";
        if livemode then; wait spoll bit 4; end if;
      enter temp_string format K;
      select temp_string;
       case "0";
        fetch (tot1_gate_state) off;
       case "1";
        fetch (tot1_gate_state) on;
       case else;
        fetch tot1_gate_state;
      end select;
      store tot1_gate_state;
    end actions;
end component;

component tot1_gate_polarity;
    type discrete ;
    values normal,inverted;
    initial normal;
    set actions;
     output string ":SENS1:TOT:GATE:POL ";
     output tot1_gate_polarity table "NORM","INV";
    end actions;
    get actions;
      output string ":SENS1:TOT:GATE:POL?";
        if livemode then; wait spoll bit 4; end if;
      enter temp_string format K;
      select temp_string;
       case "NORM";
        fetch (tot1_gate_polarity) normal;
       case "INV";
        fetch (tot1_gate_polarity) inverted;
       case else;
        fetch tot1_gate_polarity;
      end select;
      store tot1_gate_polarity;
    end actions;
end component;

component tot1_flag nogen noerrcheck;
    type integer;
    initial 0;
end component;

component meas_init notsaved ;  ! also used for start totalizing
    type integer;
    !! coupled setup_read_operation;
    set actions;
     select channel;
      case '1';
           output string ":INIT1";
           fetch 1; store tot1_flag;
           fetch ":FETC1?";store read_command;
      case '2';
           output string ":INIT2";
           fetch ":FETC2?";store read_command;
      case '3';
           output string ":INIT3";
           fetch ":FETC3?";store read_command;
     end select;

!     if recalling then;
!     else;
!        get setup_read_operation;
!     end if;
    end actions;
end component;

component meas_init_cont;
    type discrete;
    values off,on;
    initial off;
    !! coupled setup_read_operation;
    set actions;
     select channel;
      case '1';
           output string ":INIT1:CONT ";
      case '2';
           output string ":INIT2:CONT ";
      case '3';
           output string ":INIT3:CONT ";
     end select;
        output meas_init_cont table "OFF","ON";
        if meas_init_cont then;
            fetch 1;
        else;
            fetch 0;
        end if;
        store prev_meas_init_cont;

     if recalling then;
     else;
        get setup_read_operation;
     end if;
    end actions;
    get actions;
      select channel;
       case '1'; output string ":INIT1:CONT?";
       case '2'; output string ":INIT2:CONT?";
       case '3'; output string ":INIT3:CONT?";
      end select;
      enter default format "K";
      fetch meas_init_cont; store prev_meas_init_cont;
    end actions;
end component;

actions setconf1;
    !
    ! this sub sends the CONF command along with the the optional parameters.
    ! The sub is called from components function1, expected1 and resolution1
    ! When called from Function1, the optionall parameters are defaulted
    ! by sending DEFs. -- unless recalling
    ! When called from the components res1 & exp1, the values are sent
    ! as selected by user.
    !
    ! The optional parameters sent:
    !
    ! for fn1 = freq, per,rat,
    !    send expected1 & resolution1
    ! for fn1 = risetime & falltime
    !    send lower ref, upper ref, expected1 & resolution1
    ! for fn1 = pwid and nwid,
    !    send refrence, expected1 and resolution1
    ! for other fns, the optional parameters have no meaning.
    !

    output string ":ABOR1"; flush;
    output string ":CONF1:";
    output function1 table "FREQ ","PER ","FREQ:RAT ","RTIM ","FTIM ","PWID ",
            "NWID ","TINT ","TOT ","AC ","DC ","MIN ","MAX ";

    if function_changed then;        ! sub is called from change of function1.

    else;                                ! called from expected1 / resolution1
     select function1;                        ! send the values set.
      case range 0 2;    ! for freq, per & rat
       gosub send_exp_res1;
      case range 3 4;            ! for risetime & falltime;
       output lower_ref1 format 'K,","';
       output upper_ref1 format 'K,","';
       gosub send_exp_res1;
      case range 5 6;
       output reference1 format 'K,","';
       gosub send_exp_res1;
      case tint;
       gosub send_exp_res1;
      case else;
     end select;     ! of function1
    end if;        ! if function_changed

    gosub op_wait;

    fetch 0; store function_changed;
    invalidate reading;
end actions;

actions check_range1;
  ! see if the expected/resolution are default values.
    select function1;
     case freq; fetch 0; fetch 0;
     case  per; fetch 100E-9; fetch 100E-9;
     case rat; fetch 1; fetch 4E-7;
     case risetime; fetch 100E-9; fetch 1E-9;
     case falltime; fetch 100E-9; fetch 1E-9;
     case pwid; fetch 100E-9; fetch 1E-9;
     case nwid; fetch 100E-9; fetch 1E-9;
     case tint; fetch 100E-9; fetch 1E-9;
     case else; fetch expected1; fetch resolution1;
    end select;
    fetch resolution1; eq; swap; fetch expected1; eq; and;
    select function1;
    case risetime;
      fetch 90; fetch lower_ref1; eq; and;
      fetch 10; fetch upper_ref1; eq; and;
    case falltime;
      fetch 10; fetch lower_ref1; eq; and;
      fetch 90; fetch upper_ref1; eq; and;
    case pwid; fetch 50; fetch reference1; eq; and;
    case nwid; fetch 50; fetch reference1; eq; and;
    case else;
    end select;
end actions;

actions set_range1;
!
! set the min and max of the expected1 and resolution1 depending
! on the function
    select function1;
     case freq;
      fetch 0; store expected1; fetch 0; store resolution1;
      invalidate expected1; invalidate resolution1;    ! manual does not
      ! provide the def values for the freq fn. so invalidate
      fetch 0.001; fetch 200E6; fetch 1E-9; fetch 1E5;
     case  per;
      ! default values
      fetch 100E-9; store expected1; fetch 100E-9; store resolution1;
      validate expected1; validate resolution1;
      fetch 5E-9; fetch 1000; fetch 1E-18; fetch 10E-2;
     case rat;
      fetch 1; store expected1; fetch 4E-7; store resolution1;
      validate expected1; validate resolution1;
      fetch 10E-11;fetch 10E11;    fetch 4E-12; fetch 4000;
     case risetime;
      fetch 90; store lower_ref1; fetch 10; store upper_ref1;
      fetch 100E-9; store expected1; fetch 1E-9; store resolution1;
      validate expected1; validate resolution1;
      fetch 15E-9; fetch 30E-3; fetch 100E-12; fetch 1E-3;
     case falltime;
      fetch 10; store lower_ref1; fetch 90; store upper_ref1;
      fetch 100E-9; store expected1; fetch 1E-9; store resolution1;
      validate expected1; validate resolution1;
      fetch 15E-9; fetch 30E-3; fetch 100E-12; fetch 1E-3;
     case pwid;
      fetch 50; store reference1;
      fetch 100E-9; store expected1; fetch 1E-9; store resolution1;
      validate expected1; validate resolution1;
      fetch 5E-9; fetch 10E-3; fetch 100E-12; fetch 100E-9;
     case nwid;
      fetch 50; store reference1;
      fetch 100E-9; store expected1; fetch 1E-9; store resolution1;
      validate expected1; validate resolution1;
      fetch 5E-9; fetch 10E-3; fetch 100E-12; fetch 100E-9;
     case tint;
      fetch 100E-9; store expected1; fetch 1E-9; store resolution1;
      validate expected1; validate resolution1;
      fetch -1E-9; fetch 1000; fetch 100E-12; fetch 100E-9;
     case else;    ! it doesnt matter
      fetch exp_min1; fetch exp_max1; fetch res_min1; fetch res_max1;
    end select;
    store res_max1; store res_min1; store exp_max1; store exp_min1;
    if recalling then; else; set erf1; end if;
end actions;

actions send_exp_res1;
    select expected1;
     case 0;
       select function1;
       case freq;
         if resolution1 then; output string "DEF"; end if;
         validate expected1;
       case else; output expected1 format 'K';
       end select;
     case AUTO; output string "AUTO"; validate expected1;
     case else; output expected1 format 'K';
     end select;     ! expected1

    select resolution1;
     case 0; validate resolution1;
     case AUTO; output string ",AUTO"; validate resolution1;
     case else; output resolution1 format '",",K';
    end select;
end actions;

actions setunit1;
    select function1;
     case freq;
        fetch "Hz";
     case  per;
        fetch "s";
     case rat;
        fetch "*";
     case range 3 7;    ! for rtim,ftim,pwid,nwid and tint
          fetch "s";
     case tot;
          fetch "*";
          fetch 0; store tot1_flag;
     case else;            ! for acv,dcv,minv and maxv
          fetch "V";
    end select;
    dup; store unit1;
    fetch channel; fetch 0; eq;
    if stack then; store unit; else; drop; end if;
end actions;

! for channel 2
!

component function2;
    type discrete ;
    values freq,per,rat,pwid,nwid,tot, acv,dcv,minv,maxv;
    initial freq;
    coupled average_state,relative_even_lev1,relative_even_lev2,
            auto_trigger1,auto_trigger2,inp1_route,aperture; !!,setup_read_operation;
    set actions;
      validate erf2;
      fetch channel; fetch 1; eq;
      if stack then;
        if recalling then;
          gosub check_range2; ! returns 1 if only function changed.
          store function_changed;
        else;
          fetch 1; store function_changed;
          gosub set_range2;    ! set range for expected2 & resolution2
        end if;
        gosub setconf2;    ! actual i/o to 4224 with all parameters
        gosub setunit2;    ! set unit2 to proper value

        if recalling then; else; get setup_read_operation; end if;
      end if;
    end actions;
    panel set actions;
      fetch channel; fetch 1; eq;
      if stack then; gosub set_func2_config; end if;
    end actions;
    get actions;
      output string "CONF2?"; FLUSH;
      IF LIVEMODE THEN;
        SPOLL; FETCH 4; BIT; DUP; NOT;
        IF STACK THEN;
          DROP; WAIT TIME .05; SPOLL; FETCH 4; BIT; DUP; NOT;
          IF STACK THEN; DROP; WAIT TIME .25; SPOLL; FETCH 4; BIT; END IF;
        END IF;
        IF STACK THEN;
          ENTER temp_string FORMAT "X,K";
          FETCH temp_string; DUP; LENGTH; FETCH 1; SUB; FETCH 1; SWAP; SUBSTR;
          TRIMSTR; DUP; STORE temp_string; FETCH STRING " "; POS; DUP;
          IF STACK THEN;
            FETCH temp_string; swap; fetch 1; sub; fetch 1; swap; substr;
          ELSE; FETCH temp_string;
          END IF;
          STORE temp_str2;
          SELECT temp_str2;
          CASE "PER"; fetch 1;
          CASE "FREQ:RAT"; fetch 2;
          CASE "PWID"; fetch 3;
          CASE "NWID"; fetch 4;
          CASE "TOT"; fetch 5;
          CASE "AC"; fetch 6;
          CASE "DC"; fetch 7;
          CASE "MIN"; fetch 8;
          CASE "MAX"; fetch 9;
          CASE ELSE; FETCH 0;
          END SELECT;
          store function2;
          gosub set_range2;
          gosub setunit2;
          FETCH temp_string; FETCH temp_str2; ne;
          if stack then;
            FETCH temp_string; FETCH temp_str2; length; dup; fetch 1; add; swap;
            FETCH temp_string; length; swap; sub; substr; trimstr;
            store temp_string;
            select function2;
            case range 3,4;
              fetch reference2; gosub getvalfromstring; store reference2;
            case else;
            end select;
            select function2;
            case range 0,4;
              fetch expected2; gosub getvalfromstring; store expected2;
              fetch resolution2; gosub getvalfromstring; store resolution2;
            case else;
            end select;
          end if;
          if function2 then; else;
            if expected2 then; else; invalidate expected2; end if;
            if resolution2 then; else; invalidate resolution2; end if;
          end if;
          set erf2;
          fetch channel; fetch 1; ne;
          if stack then;
             fetch 1; store channel;
             fetch 2; store prev_channel;
             fetch 0; dup; store meas_init_cont; store prev_meas_init_cont;
             hide channel1; hide channel3; show channel2;
             fetch unit2; store unit;
             get setup_read_operation;
          end if;
          gosub set_func2_config;
        ELSE; OUTPUT STRING "*CLS"; FLUSH; ! Some other channel must be conf
        END IF;
      ELSE; ENTER temp_string FORMAT "X,K"; ! Not livemode
      END IF;
    end actions;
end component;

actions set_func2_config;
    fetch channel; fetch 1; eq;
    if stack then;
         hide width2_panel; hide tot2_panel;
        hide res_exp_only1; hide res_exp_only2; hide res_exp_only3;
         hide rise_panel; hide width1_panel;
         hide tint_panel; hide tot1_panel;

        select function2;
         case range 3 4;    ! nwid & pwid
          show width2_panel;
         case tot;
          show tot2_panel;
          case else;
            show res_exp_only2;
        end select;
    end if;
end actions;

component send_config2 notsaved;
    type integer;
    coupled average_state,aperture;
    set actions setconf2;
    panel set actions;
        hide config; show meas;
    end actions;
end component;

component exp_min2 nogen noerrcheck ;
    type continuous  ;
    initial 0.001;
end component;
component exp_max2 nogen noerrcheck ;
    type continuous  ;
    initial 100E6;
end component;

component res_min2 nogen noerrcheck ;
    type continuous  ;
    initial 1E-9;
end component;
component res_max2 nogen noerrcheck ;
    type continuous  ;
    initial 1E5;
end component;

component expected2 nogen noerrcheck;
    type continuous  ;
    values range exp_min2,exp_max2,auto;
    initial auto;
    set actions;
      fetch channel; fetch 1; eq;
      if stack then;
        if recalling then;
          select function1;
          case range 0 4; set function2;
          case else;
          end select;
        else; set erf2;
        end if;
      end if;
    end actions;
end component;

component resolution2 nogen noerrcheck;
    type continuous  ;
    values range res_min2,res_max2,auto;
    initial 0,invalid;
    set actions;
      fetch channel; fetch 1; eq;
      if stack then;
        if recalling then;
          select function1;
          case range 0 4; set function2;
          case else;
          end select;
        else; set erf2;
        end if;
      end if;
    end actions;
end component;

component reference2 nogen noerrcheck;        ! used for fn2 == nwid & pwid
    type integer;
    values range 10,90;
    initial 50;
    set actions;
      fetch channel; fetch 1; eq; fetch recalling; and;
      if stack then;
        select function2;
        case range 3,4; set function2;
        case else;
        end select;
      end if;
    end actions;
end component;


component tot2_gate_state;
    type discrete ;
    values off,on;
    initial off;
    !! coupled setup_read_operation;
    set actions;
     output string ":SENS2:TOT:GATE:STAT ";
     output tot2_gate_state table "OFF","ON";

     if recalling then;
     else;
        get setup_read_operation;
     end if;
    end actions;
    get actions;
      output string ":SENS2:TOT:GATE:STAT?";
        if livemode then; wait spoll bit 4; end if;
      enter temp_string format K;
      select temp_string;
       case "0";
        fetch (tot2_gate_state) off;
       case "1";
        fetch (tot2_gate_state) on;
       case else;
        fetch tot2_gate_state;
      end select;
      store tot2_gate_state;
    end actions;
end component;

component tot2_gate_polarity;
    type discrete ;
    values normal,inverted;
    initial normal;
    set actions;
     output string ":SENS2:TOT:GATE:POL ";
     output tot2_gate_polarity table "NORM","INV";
    end actions;
    get actions;
      output string ":SENS2:TOT:GATE:POL?";
        if livemode then; wait spoll bit 4; end if;
      enter temp_string format K;
      select temp_string;
       case "NORM";
        fetch (tot2_gate_polarity) normal;
       case "INV";
        fetch (tot2_gate_polarity) inverted;
       case else;
        fetch tot2_gate_polarity;
      end select;
      store tot2_gate_polarity;
    end actions;
end component;

actions setconf2;

      output string ":ABOR2";flush;
     select function2;
         case tot;    ! cant send using conf. have to use sens.
              output string ':SENS2:FUNC "TOT"';
            fetch 1; store tot2_gate_state; set tot2_gate_state;
          case else;
              output string ":CONF2:";
              output function2 table "FREQ ","PER ","FREQ:RAT ","PWID ","NWID ",
                    "TOT ","AC ","DC ","MIN ","MAX ";
    end select;

    if function_changed then;        ! sub is called from change of function1.

    else;                            ! called from expected2 / resolution2
     select function2;                        ! send the values set.
      case range 0 2;    ! for freq, per & rat
       gosub send_exp_res2;
      case range 3 4;    ! for pwid & nwid
       output reference2 format 'K,","';
       gosub send_exp_res2;
      case else;
     end select;     ! of function2
    end if;        ! if function_changed

    gosub op_wait;

    fetch 0; store function_changed;
    invalidate reading;
end actions;

actions check_range2;
    select function2;
     case freq; fetch 0; fetch 0;
     case  per; fetch 100E-9; fetch 100E-9;
     case rat; fetch 1; fetch 4E-7;
     case pwid; fetch 100E-9; fetch 1E-9;
     case nwid; fetch 100E-9; fetch 1E-9;
     case else; fetch expected2; fetch resolution2;
    end select;
    fetch resolution2; eq; swap; fetch expected2; eq; and;
    select function2;
    case pwid; fetch 50; fetch reference2; eq; and;
    case nwid; fetch 50; fetch reference2; eq; and;
    case else;
    end select;
end actions;

actions set_range2;
!
! set the min and max of the expected2 and resolution2 depending
! on the function
    select function2;
     case freq;
      fetch 0; store expected2; fetch 0; store resolution2;
      fetch 0.001; fetch 100E6; fetch 1E-9; fetch 1E5;
      invalidate expected2; invalidate resolution2;    ! manual does not
      ! provide the def values for the freq fn. so invalidate
     case  per;
      ! default values
      fetch 100E-9; store expected2; fetch 100E-9; store resolution2;
      validate expected2; validate resolution2;
      fetch 10E-9; fetch 1000; fetch 1E-18; fetch 10E-2;
     case rat;
      fetch 1; store expected2; fetch 4E-7; store resolution2;
      validate expected2; validate resolution2;
      fetch 10E-11;fetch 10E11;    fetch 4E-12; fetch 4000;
     case pwid;
      fetch 50; store reference2;
      fetch 100E-9; store expected2; fetch 1E-9; store resolution2;
      validate expected2; validate resolution2;
      fetch 5E-9; fetch 10E-3; fetch 100E-12; fetch 100E-9;
     case nwid;
      fetch 50; store reference2;
      fetch 100E-9; store expected2; fetch 1E-9; store resolution2;
      validate expected2; validate resolution2;
      fetch 5E-9; fetch 10E-3; fetch 100E-12; fetch 100E-9;
     case else;    ! it doesnt matter
      fetch exp_min2; fetch exp_max2; fetch res_min2; fetch res_max2;
    end select;
    store res_max2; store res_min2; store exp_max2; store exp_min2;
    if recalling then; else; set erf2; end if;
end actions;

actions send_exp_res2;
    select expected2;
     case 0;
       if resolution2 then; output string "DEF"; end if;
       validate expected2;
     case AUTO; output string "AUTO"; validate expected2;
     case else; output expected2 format 'K';
     end select;     ! expected2

    select resolution2;
     case 0; validate resolution2;
     case AUTO; output string ",AUTO"; validate resolution2;
     case else; output resolution2 format '",",K';
    end select;
end actions;

actions setunit2;
    select function2;
     case freq;
      fetch "Hz";
     case  per;
      fetch "s";
     case rat;
      fetch "*";
     case range 3 4;    ! for pwid,nwid
      fetch "s";
     case tot;
      fetch "*";
     case else;            ! for acv,dcv,minv and maxv
      fetch "V";
    end select;
    dup; store unit2;
    fetch channel; fetch 1; eq;
    if stack then; store unit; else; drop; end if;
end actions;

! for channel 3
!

component function3;
    type discrete ;
    values freq,per,rat;
    initial freq;
    coupled average_state,aperture; !!,setup_read_operation;
    set actions;
      validate erf3;
      fetch channel; fetch 2; eq;
      if stack then;
        if recalling then;
          gosub check_range3; ! returns 1 if only function changed.
          store function_changed;
        else;
          fetch 1; store function_changed;
          gosub set_range3;    ! set range for expected3 & resolution3
        end if;
        gosub setconf3;    ! actual i/o to 4224 with all parameters
        gosub setunit3;    ! set unit3 to proper value

        if recalling then; else; get setup_read_operation; end if;
      end if;
    end actions;
    panel set actions;
      fetch channel; fetch 2; eq;
      if stack then; gosub set_func3_config; end if;
    end actions;
    get actions;
      output string "CONF3?"; FLUSH;
      IF LIVEMODE THEN;
        SPOLL; FETCH 4; BIT; DUP; NOT;
        IF STACK THEN;
          DROP; WAIT TIME .05; SPOLL; FETCH 4; BIT; DUP; NOT;
          IF STACK THEN; DROP; WAIT TIME .25; SPOLL; FETCH 4; BIT; END IF;
        END IF;
        IF STACK THEN;
          ENTER temp_string FORMAT "X,K";
          FETCH temp_string; DUP; LENGTH; FETCH 1; SUB; FETCH 1; SWAP; SUBSTR;
          TRIMSTR; DUP; STORE temp_string; FETCH STRING " "; POS; DUP;
          IF STACK THEN;
            FETCH temp_string; swap; fetch 1; sub; fetch 1; swap; substr;
          ELSE; FETCH temp_string;
          END IF;
          STORE temp_str2;
          SELECT temp_str2;
          CASE "PER"; fetch 1;
          CASE "FREQ:RAT"; fetch 2;
          CASE ELSE; FETCH 0;
          END SELECT;
          store function3;
          gosub set_range3;
          gosub setunit3;
          FETCH temp_string; FETCH temp_str2; ne;
          if stack then;
            FETCH temp_string; FETCH temp_str2; length; dup; fetch 1; add; swap;
            FETCH temp_string; length; swap; sub; substr; trimstr;
            store temp_string;
            fetch expected3; gosub getvalfromstring; store expected3;
            fetch resolution3; gosub getvalfromstring; store resolution3;
          end if;
          if function3 then; else;
            if expected3 then; else; invalidate expected3; end if;
            if resolution3 then; else; invalidate resolution3; end if;
          end if;
          set erf3;
          fetch channel; fetch 2; ne;
          if stack then;
             fetch 2; store channel;
             fetch 3; store prev_channel;
             fetch 0; dup; store meas_init_cont; store prev_meas_init_cont;
             hide channel1; hide channel2; show channel3;
             fetch unit3; store unit;
             get setup_read_operation;
          end if;
          gosub set_func3_config;
        ELSE; OUTPUT STRING "*CLS"; FLUSH; ! Some other channel must be conf
        END IF;
      ELSE; ENTER temp_string FORMAT "X,K"; ! Not livemode
      END IF;
    end actions;
end component;

actions set_func3_config;
    fetch channel; fetch 2; eq;
    if stack then;
         hide width2_panel; hide tot2_panel;
        hide res_exp_only1; hide res_exp_only2;
         hide rise_panel; hide width1_panel;
         hide tint_panel; hide tot1_panel;

        show res_exp_only3;
    end if;
end actions;

component send_config3 notsaved;
    type integer;
    coupled average_state,aperture;
    set actions setconf3;
    panel set actions;
        hide config; show meas;
    end actions;
end component;

component expected3 nogen noerrcheck;
    type continuous  ;
    values range exp_min3,exp_max3,auto;
    initial auto;
    set actions;
      fetch channel; fetch 2; eq;
      if stack then;
        if recalling then; set function3;
        else; set erf3;
        end if;
      end if;
    end actions;
end component;

component resolution3 nogen noerrcheck;
    type continuous  ;
    values range res_min3,res_max3,auto;
    initial 0,invalid;
    set actions;
      fetch channel; fetch 2; eq;
      if stack then;
        if recalling then; set function3;
        else; set erf3;
        end if;
      end if;
    end actions;
end component;

component exp_min3 nogen noerrcheck ;
    type continuous  ;
    initial 90E6;
end component;
component exp_max3 nogen noerrcheck ;
    type continuous  ;
    initial 2500E6;
end component;

component res_min3 nogen noerrcheck ;
    type continuous  ;
    initial 1E-9;
end component;
component res_max3 nogen noerrcheck ;
    type continuous  ;
    initial 1E5;
end component;

actions setconf3;

    output string ":ABOR3"; flush;
    output string ":CONF3:";
    output function3 table "FREQ ","PER ","FREQ:RAT ";

    if function_changed then;    ! sub is called from change of function1.
    else;                                ! called from expected3 / resolution3
       gosub send_exp_res3;
    end if;        ! if function_changed

    gosub op_wait;

    fetch 0; store function_changed;
    invalidate reading;
end actions;


actions check_range3;
    select function3;
     case freq; fetch 0; fetch 0;
     case  per; fetch 100E-9; fetch 100E-9;
     case rat; fetch 1; fetch 4E-7;
     case else; fetch expected3; fetch resolution3;
    end select;
    fetch resolution3; eq; swap; fetch expected3; eq; and;
end actions;

actions set_range3;
!
! set the min and max of the expected3 and resolution3 depending
! on the function
    select function3;
     case freq;
      fetch 0; store expected3; fetch 0; store resolution3;
      fetch 0.001; fetch 100E6; fetch 1E-9; fetch 1E5;
      invalidate expected3; invalidate resolution3;    ! manual does not
      ! provide the def values for the freq fn. so invalidate
     case  per;
      ! default values
      fetch 100E-9; store expected3; fetch 100E-9; store resolution3;
      validate expected3; validate resolution3;
      fetch .4E-9; fetch 11.11E-9; fetch 1E-18; fetch 10E-2;
     case rat;
      fetch 1; store expected3; fetch 4E-7; store resolution3;
      validate expected3; validate resolution3;
      fetch 10E-11;fetch 10E11;    fetch 4E-12; fetch 4000;
    end select;
    store res_max3; store res_min3; store exp_max3; store exp_min3;
    if recalling then; else; set erf3; end if;
end actions;

actions send_exp_res3;
    select expected3;
     case 0;
       if resolution3 then; output string "DEF"; end if;
       validate expected3;
     case AUTO; output string "AUTO"; validate expected3;
     case else; output expected3 format 'K';
     end select;     ! expected3

    select resolution3;
     case 0; validate resolution3;
     case AUTO; output string ",AUTO"; validate resolution3;
     case else; output resolution3 format '",",K';
    end select;
end actions;

actions setunit3;
    select function3;
     case freq;
      fetch "Hz";
     case  per;
      fetch "s";
     case rat;
      fetch "*";
    end select;
    dup; store unit3;
    fetch channel; fetch 2; eq;
    if stack then; store unit; else; drop; end if;
end actions;


!
! component reading and associated actions
!
component reading notsaved noerrcheck;
    type continuous  ;
    initial invalid;
    get actions;
        if read_ok then;
            gosub read_meas;
        else;
            if read_ok1 then;
                notify "Measurement must be Initialized to start Totalizing";
            end if;
            if read_ok2 then;
                notify "Gating(by 1) state must be ON";
            end if;
        end if;
        get setup_read_operation;
    end actions;
end component;

component multiplier nogen noerrcheck;
    type integer;
    initial 1;
end component;

component read_ok nogen noerrcheck;
    type integer;
    initial 1;
end component;

component read_ok1 nogen noerrcheck;
    type integer;
    initial 0;
end component;

component read_ok2 clone read_ok1;

component read_command nogen noerrcheck;
    type string 10;
    initial ":READ1?";
end component;

component setup_read_operation notsaved nogen noerrcheck;
    type integer;
    set actions;
    end actions;
    get actions;
        select channel;
              case '1'; gosub setup_read_1;
              case '2'; gosub setup_read_2;
              case '3'; gosub setup_read_3;
         end select;
    end actions;
end component;

actions setup_read_1;
    fetch 1; store read_ok;
    fetch 0; store read_ok1;
    fetch 0; store read_ok2;

    select function1;
        case range 9,12; ! acv,dcv,minv,maxv
            fetch attn1; store multiplier;
        case else;
            fetch 1; store multiplier;
    end select;

    if meas_init_cont then;
        fetch ":FETC1?";
    else;
        select function1;
               case tot;
                if tot1_gate_state then;  ! tot by chan 2
                    fetch ":READ1?";
                else;
                    fetch ":FETC1?";
                         if tot1_flag then;
                         else;
                        fetch 0; store read_ok;
                        fetch 1; store read_ok1;
                         end if;
                     end if;
            case else;
                fetch ":READ1?";
        end select;
    end if;

    store read_command;
end actions;

actions setup_read_2;
    fetch 1; store read_ok;
    fetch 0; store read_ok1;
    fetch 0; store read_ok2;

    select function2;
        case range 6,9; ! acv,dcv,minv,maxv
            fetch attn2; store multiplier;
        case else;
            fetch 1; store multiplier;
    end select;

    select function2;
           case tot;  ! tot by chan 1
            if tot2_gate_state then;
            else;
                fetch 0; store read_ok;
                fetch 1; store read_ok2;
               end if;
        case else;
    end select;

    if meas_init_cont then;
        fetch ":FETC2?";
    else;
        fetch ":READ2?";
    end if;

    store read_command;
end actions;

actions setup_read_3;
    fetch 1; store read_ok;
    fetch 0; store read_ok1;
    fetch 0; store read_ok2;
    fetch 1; store multiplier;

    if meas_init_cont then;
        fetch ":FETC3?";
    else;
        fetch ":READ3?";
    end if;

    store read_command;
end actions;

actions clear_error;
    clear; get stat_err_no; output string "*CLS"; flush;
end actions;

actions wait_meas;
    fetch 1;  ! stack as loop counter
    loop;
        dup;
        spoll; dup; fetch 4; bit;
        if stack then;
            drop;
            enter stack format K; fetch multiplier; mul; store reading;
            exit if stack;  ! uses the duplicate value on stack to exit
        end if;
        fetch 5; bit;
        if stack then;
            notify "<< Measurement Error >>";
            gosub clear_error;
            exit if stack;
        end if;

        wait time wait_interval;

        fetch wait_count; eq;
        if stack then;
!            notify "<< Measurement Timeout >>";
            fetch 9.91E37;store reading; !store nan into reading to show bogus
            gosub clear_error;
            fetch 1; exit if stack;
        else;
            fetch 1; add;
        end if;
    end loop;
    drop;
end actions;

actions read_meas;
    if livemode then;
        output read_command format K; flush;
        spoll; dup; fetch 5; bit;
        if stack then;
            notify "<< Measurement Error >>"; drop;
            gosub clear_error;
        else;
            fetch 4; bit;         ! bit 4 check
            if stack then;   ! data available
                enter stack format K; fetch multiplier; mul; store reading;
            else;
                gosub wait_meas;
            end if;
        end if;
    end if;
end actions;

component meas_time_out nogen noerrcheck;
    type continuous;
    values range 0,5000,.1;
    initial 5;
    set actions;
        fetch meas_time_out; fetch 0; eq;
        if stack then;
            fetch 0; store wait_count;
            fetch 0.5; store wait_interval;
        else;
            fetch 50; store wait_count;
            fetch meas_time_out; fetch wait_count; div; store wait_interval;
        end if;
    end actions;
end component;

component wait_count nogen noerrcheck;
    type integer;
    initial 50;
end component;

component wait_interval nogen noerrcheck;
    type continuous;
    initial 0.1;
end component;

! input_config panel components -     channels : 1,2.
!
component inp_chan nogen noerrcheck;
    type discrete;
    values c1,c2;
    initial c1;
    panel set actions;
        hide inp1; hide inp2; hide inp1_a; hide inp2_a;
        select inp_chan;
            case c1;
                    show inp1;
            case c2;
                    show inp2;
        end select;
    end actions;
end component;

component attn1 nogen noerrcheck ;    ! component used to store numerical
    type integer;                    ! attn value for arithmatic
    initial 1;
end component;

component even_minmax1 notsaved nogen noerrcheck;
    type integer;
    get actions;
      if inp1_att then;
       fetch -102.375; store even_min1;
       fetch 102.375;  store even_max1;
       fetch 10;
      else;
       fetch -10.2375; store even_min1;
       fetch 10.2375;  store even_max1;
       fetch 1;
      end if;    ! if inp1_att;
      store attn1;
    end actions;
end component;

component inp1_att;
    type discrete ;
    values x1,x10;
    initial x1;
    coupled even_minmax1,even_lev1; !!,setup_read_operation;
    set actions;
         output inp1_att table ":INP1:ATT 1",":INP1:ATT 10";
        gosub op_wait;

     if recalling then;
     else;
        get setup_read_operation;
     end if;
    end actions;
    get actions;
      output string ":INP1:ATT?";
        if livemode then; wait spoll bit 4; end if;
      enter stack format k;
      select stack;
       case 1;
        fetch (inp1_att) x1;
       case 10;
        fetch (inp1_att) x10;
       case else;
        fetch inp1_att;
      end select;
      store inp1_att;
    end actions;
end component;

component inp1_coup;
    type discrete ;
    values dc,ac;
    initial dc;
    set actions;
     output inp1_coup table ":INP1:COUP DC",":INP1:COUP AC";
    end actions;
    get actions;
      output string ":INP1:COUP?";
        if livemode then; wait spoll bit 4; end if;
      enter temp_string format K;
      select temp_string;
       case "DC";
        fetch (inp1_coup) dc;
       case "AC";
        fetch (inp1_coup) ac;
       case else;
        fetch inp1_coup;
      end select;
      store inp1_coup;
    end actions;
end component;

component inp1_imp;
    type discrete ;
    values '50','1M';
    initial '50';
    set actions;
     output inp1_imp table ":INP1:IMP 50",":INP1:IMP 1E6";
    end actions;
    get actions;
     output string ":INP1:IMP?";
        if livemode then; wait spoll bit 4; end if;
     enter stack;
     select stack;
      case range 0 60;
       fetch (inp1_imp) '50';
      case else;
       fetch (inp1_imp) '1M';
     end select;
     store inp1_imp;
    end actions;
end component;

component inp1_route;
    type discrete ;
    values separate,common;
    initial separate;
    set actions;
         output inp1_route table ":INP:ROUT SEP",":INP:ROUT COMM";
        gosub op_wait;
    end actions;
    get actions;
      output string ":INP:ROUT?";
        if livemode then; wait spoll bit 4; end if;
      enter temp_string format K;
      select temp_string;
       case "SEP";
        fetch (inp1_route) separate;
       case "COMM";
        fetch (inp1_route) common;
       case else;
        fetch inp1_route;
      end select;
      store inp1_route;
    end actions;
end component;

component attn2 nogen noerrcheck;
    type integer;
    initial 1;
end component;

component even_minmax2 notsaved nogen noerrcheck;
    type integer;
    get actions;
      if inp2_att then;
       fetch -102.375; store even_min2;
       fetch 102.375;  store even_max2;
       fetch 10;
      else;
       fetch -10.2375; store even_min2;
       fetch 10.2375;  store even_max2;
       fetch 1;
      end if;   ! if inp2_att;
      store attn2;
    end actions;
end component;

component inp2_att;
    type discrete ;
    values x1,x10;
    initial x1;
    coupled even_minmax2,even_lev2; !!,setup_read_operation;
    set actions;
         output inp2_att table ":INP2:ATT 1",":INP2:ATT 10";
        gosub op_wait;

     if recalling then;
     else;
        get setup_read_operation;
     end if;
    end actions;
    get actions;
      output string ":INP2:ATT?";
        if livemode then; wait spoll bit 4; end if;
      enter stack format k;
      select stack;
       case 1;
        fetch (inp2_att) x1;
       case 10;
        fetch (inp2_att) x10;
       case else;
        fetch inp2_att;
      end select;
      store inp2_att;
    end actions;
end component;

component inp2_coup;
    type discrete ;
    values dc,ac;
    initial dc;
    set actions;
     output inp2_coup table ":INP2:COUP DC",":INP2:COUP AC";
    end actions;
    get actions;
      output string ":INP2:COUP?";
        if livemode then; wait spoll bit 4; end if;
      enter temp_string format K;
      select temp_string;
       case "DC";
        fetch (inp2_coup) dc;
       case "AC";
        fetch (inp2_coup) ac;
       case else;
        fetch inp2_coup;
      end select;
      store inp2_coup;
    end actions;
end component;

component inp2_imp;
    type discrete ;
    values '50','1M';
    initial '50';
    set actions;
     output inp2_imp table ":INP2:IMP 50",":INP2:IMP 1E6";
    end actions;
    get actions;
     output string ":INP2:IMP?";
        if livemode then; wait spoll bit 4; end if;
     enter stack;
     select stack;
      case range 0 60;
       fetch (inp2_imp)'50';
      case else;
       fetch (inp2_imp) '1M';
     end select;
     store inp2_imp;
    end actions;
end component;


!
! arm panel components
!
component arm_start_imm notsaved;
    type integer;
    set actions;
     output string ":ARM:STAR:IMM";
    end actions;
end component;

component arm_stop_imm notsaved ;
    type integer;
    set actions;
         output string ":ARM:STOP:IMM";
    end actions;
end component;

component arm_start_level;
    type discrete ;
    values ecl,gnd,ttl;
    initial ttl;
    set actions;
     output string ":ARM:STAR:LEV ";
     output arm_start_level table "ECL","GND","TTL";
    end actions;
    get actions;
     output string ":ARM:STAR:LEV?";
        if livemode then; wait spoll bit 4; end if;
     enter stack;
     select stack;
      case range -1 1;
       fetch (arm_start_level) gnd;
      case range -5 -0.999;
       fetch (arm_start_level) ecl;
      case range 1.001 5;
       fetch (arm_start_level) ttl;
      case else;
       fetch arm_start_level;
     end select;
     store arm_start_level;
    end actions;
end component;

component arm_stop_level;
    type discrete ;
    values ecl,gnd,ttl;
    initial ttl;
    set actions;
     output string ":ARM:STOP:LEV ";
     output arm_stop_level table "ECL","GND","TTL";
    end actions;
    get actions;
     output string ":ARM:STOP:LEV?";
     if livemode then; wait spoll bit 4; end if;
     enter stack;
     select stack;
      case range -1 1;
       fetch (arm_stop_level) gnd;
      case range -5 -0.999;
       fetch (arm_stop_level) ecl;
      case range 1.001 5;
       fetch (arm_stop_level) ttl;
      case else;
       fetch arm_stop_level;
     end select;
     store arm_stop_level;
    end actions;
end component;

component arm_start_slope;
    type discrete ;
    values positive, negative;
    initial positive;
    set actions;
     output string ":ARM:STAR:SLOP ";
     output arm_start_slope table "POS","NEG";
    end actions;
    get actions;
     output string ":ARM:STAR:SLOP?";
        if livemode then; wait spoll bit 4; end if;
     enter temp_string format K;
     select temp_string;
      case "POS";
       fetch (arm_start_slope) positive;
      case "NEG";
       fetch (arm_start_slope) negative;
      case else;
       fetch arm_start_slope;
     end select;
     store arm_start_slope;
    end actions;
end component;


component arm_stop_slope;
    type discrete ;
    values positive, negative;
    initial positive;
    set actions;
     output string ":ARM:STOP:SLOP ";
     output arm_stop_slope table "POS","NEG";
    end actions;
    get actions;
     output string ":ARM:STOP:SLOP?";
        if livemode then; wait spoll bit 4; end if;
     enter temp_string format K;
     select temp_string;
      case "POS";
       fetch (arm_stop_slope) positive;
      case "NEG";
       fetch (arm_stop_slope) negative;
      case else;
       fetch arm_stop_slope;
     end select;
     store arm_stop_slope;
    end actions;
end component;

component arm_start_source;
    type discrete ;
    values bus,external,immediate,hold,ttltrig0,ttltrig1,ttltrig2,
           ttltrig3,ttltrig4,ttltrig5,ttltrig6,ttltrig7;
    initial immediate;
    coupled arm_stop_source;
    set actions;
     output string ":ARM:STAR:SOUR ";
     output arm_start_source table "BUS","EXT","IMM","HOLD","TTLT0","TTLT1",
                                    "TTLT2","TTLT3","TTLT4","TTLT5","TTLT6",
                                    "TTLT7";
    end actions;
    get actions;
      output string ":ARM:STAR:SOUR?";
        if livemode then; wait spoll bit 4; end if;
      enter temp_string format K;
      select temp_string;
       case "BUS";
        fetch (arm_start_source) bus;
       case "EXT";
        fetch (arm_start_source) external;
       case "IMM";
        fetch (arm_start_source) immediate;
       case "HOLD";
        fetch (arm_start_source) hold;
       case "TTLT0";
        fetch (arm_start_source) ttltrig0;
       case "TTLT1";
        fetch (arm_start_source) ttltrig1;
       case "TTLT2";
        fetch (arm_start_source) ttltrig2;
       case "TTLT3";
        fetch (arm_start_source) ttltrig3;
       case "TTLT4";
        fetch (arm_start_source) ttltrig4;
       case "TTLT5";
        fetch (arm_start_source) ttltrig5;
       case "TTLT6";
        fetch (arm_start_source) ttltrig6;
       case "TTLT7";
        fetch (arm_start_source) ttltrig7;
       case else;
        fetch arm_start_source;
      end select;
      store arm_start_source;
    end actions;
end component;

component arm_stop_source;
    type discrete ;
    values bus,external,immediate,hold,ttltrig0,ttltrig1,ttltrig2,
           ttltrig3,ttltrig4,ttltrig5,ttltrig6,ttltrig7;
    initial immediate;
    coupled arm_start_source;
    set actions;
     output string ":ARM:STOP:SOUR ";
     output arm_stop_source table "BUS","EXT","IMM","HOLD","TTLT0","TTLT1",
                                    "TTLT2","TTLT3","TTLT4","TTLT5","TTLT6",
                                    "TTLT7";
    end actions;
    get actions;
      output string ":ARM:STOP:SOUR?";
        if livemode then; wait spoll bit 4; end if;
      enter temp_string format K;
      select temp_string;
       case "BUS";
        fetch (arm_stop_source) bus;
       case "EXT";
        fetch (arm_stop_source) external;
       case "IMM";
        fetch (arm_stop_source) immediate;
       case "HOLD";
        fetch (arm_stop_source) hold;
       case "TTLT0";
        fetch (arm_stop_source) ttltrig0;
       case "TTLT1";
        fetch (arm_stop_source) ttltrig1;
       case "TTLT2";
        fetch (arm_stop_source) ttltrig2;
       case "TTLT3";
        fetch (arm_stop_source) ttltrig3;
       case "TTLT4";
        fetch (arm_stop_source) ttltrig4;
       case "TTLT5";
        fetch (arm_stop_source) ttltrig5;
       case "TTLT6";
        fetch (arm_stop_source) ttltrig6;
       case "TTLT7";
        fetch (arm_stop_source) ttltrig7;
       case else;
        fetch arm_stop_source;
      end select;
      store arm_stop_source;
    end actions;
end component;

!
! trigger panel components
!

! components for range of event level

component trig_chan nogen noerrcheck;
    type discrete;
    values c1,c2;
    initial c1;
    panel set actions;
        select trig_chan;
            case c1; hide trig2; show trig1;
            case c2; hide trig1; show trig2;
        end select;
    end actions;
end component;

component even_min1 nogen noerrcheck ;
    type continuous  ;
    initial -10.2375;
end component;

component even_min2 clone even_min1;

component even_max1 nogen noerrcheck ;
    type continuous  ;
    initial 10.2375;
end component;

component even_max2 clone even_max1;

component auto_trigger_once1 notsaved;
    type integer;
    coupled auto_trigger1;
    set actions;
     output string ":SENS1:EVEN:LEV:AUTO ONCE";
     gosub op_wait;
    end actions;
end component;

component even_lev1;
    type continuous  ;
    values range even_min1,even_max1,2.5E-3;
    initial 0;
    coupled even_lev1,auto_trigger1;
    set actions;
         fetch even_lev1; fetch attn1; div;
         output stack format '":SENS1:EVEN:LEV ",K';
        gosub op_wait;
    end actions;
    get actions;
         output string ":SENS1:EVEN:LEV?";
        if livemode then; wait spoll bit 4; end if;
         enter stack format k; fetch attn1; mul; store even_lev1;
    end actions;
end component;

component auto_trigger1;
    type discrete ;
    values off,on;
    initial off;
    coupled even_lev1;
    set actions;
     output string ":SENS1:EVEN:LEV:AUTO ";
     output auto_trigger1 table "OFF","ON";
     gosub op_wait;
    end actions;
    get actions;
      output string ":SENS1:EVEN:LEV:AUTO?";
        if livemode then; wait spoll bit 4; end if;
      enter temp_string format K;
      select temp_string;
       case "0";
        fetch (auto_trigger1) off;
       case "1";
        fetch (auto_trigger1) on;
       case else;
        fetch auto_trigger1;
      end select;
      store auto_trigger1;
    end actions;
end component;

component even_slop1;
    type discrete ;
    values positive,negative;
    initial positive;
    set actions;
     output string ":SENS1:EVEN:SLOP ";
     output even_slop1 table "POS","NEG";
    end actions;
    get actions;
      output string ":SENS1:EVEN:SLOP?";
        if livemode then; wait spoll bit 4; end if;
      enter temp_string format K;
      select temp_string;
       case "POS";
        fetch ( even_slop1) positive;
       case "NEG";
        fetch ( even_slop1) negative;
       case else;
        fetch  even_slop1;
      end select;
      store  even_slop1;
    end actions;
end component;

component relative_even_lev1;        ! used only for auto triggering.
    type integer;
    values range 10,90;
    initial 50;
    coupled even_lev1;
    set actions;
     output relative_even_lev1 format '":SENS1:EVEN:LEV:REL ",K';
     gosub op_wait;
    end actions;
    get actions;
     output string ":SENS1:EVEN:LEV:REL?";
        if livemode then; wait spoll bit 4; end if;
     enter relative_even_lev1 format k;
    end actions;
end component;

component auto_trigger_once2 notsaved;
    type integer;
    coupled auto_trigger2;
    set actions;
     output string ":SENS2:EVEN:LEV:AUTO ONCE";
     gosub op_wait;
    end actions;
end component;

component even_lev2;
    type continuous  ;
    values range even_min2,even_max2,2.5E-3;
    initial 0;
    coupled even_lev2,auto_trigger2;
    set actions;
         fetch even_lev2; fetch attn2; div;
         output stack format '":SENS2:EVEN:LEV ",K';
        gosub op_wait;
    end actions;
    get actions;
         output string ":SENS2:EVEN:LEV?";
        if livemode then; wait spoll bit 4; end if;
         enter stack format k; fetch attn2; mul; store even_lev2;
    end actions;
end component;

component auto_trigger2;
    type discrete ;
    values off,on;
    initial off;
    coupled even_lev1;
    set actions;
     output string ":SENS2:EVEN:LEV:AUTO ";
     output auto_trigger2 table "OFF","ON";
     gosub op_wait;
    end actions;
    get actions;
      output string ":SENS2:EVEN:LEV:AUTO?";
        if livemode then; wait spoll bit 4; end if;
      enter temp_string format K;
      select temp_string;
       case "0";
        fetch (auto_trigger2) off;
       case "1";
        fetch (auto_trigger2) on;
       case else;
        fetch auto_trigger2;
      end select;
      store auto_trigger2;
    end actions;
end component;

component even_slop2;
    type discrete ;
    values positive,negative;
    initial positive;
    set actions;
     output string ":SENS2:EVEN:SLOP ";
     output even_slop2 table "POS","NEG";
    end actions;
    get actions;
      output string ":SENS2:EVEN:SLOP?";
        if livemode then; wait spoll bit 4; end if;
      enter temp_string format K;
      select temp_string;
       case "POS";
        fetch ( even_slop2) positive;
       case "NEG";
        fetch ( even_slop2) negative;
       case else;
        fetch  even_slop2;
      end select;
      store  even_slop2;
    end actions;
end component;

component relative_even_lev2;
    type integer;
    values range 10,90;
    initial 50;
    coupled even_lev2;
    set actions;
     output relative_even_lev2 format '":SENS2:EVEN:LEV:REL ",K';
     gosub op_wait;
    end actions;
    get actions;
     output string ":SENS2:EVEN:LEV:REL?";
        if livemode then; wait spoll bit 4; end if;
     enter relative_even_lev2 format k;
    end actions;
end component;

component hysteresis1;
    type discrete ;
    values min,max,def;
    initial def;
    set actions;
     output string ":SENS1:EVEN:HYST ";
     output hysteresis1 table "MIN","MAX","DEF";
    end actions;
    get actions;
      output string ":SENS1:EVEN:HYST?";
        if livemode then; wait spoll bit 4; end if;
      enter temp_string format K;
      select temp_string;
       case "MIN";
        fetch (hysteresis1) min;
       case "MAX";
        fetch (hysteresis1) max;
       case "DEF";
        fetch (hysteresis1) def;
       case else;
        fetch hysteresis1;
      end select;
      store hysteresis1;
    end actions;
end component ;

component hysteresis2;
    type discrete ;
    values min,max,def;
    initial def;
    set actions;
     output string ":SENS2:EVEN:HYST ";
     output hysteresis2 table "MIN","MAX","DEF";
    end actions;
    get actions;
      output string ":SENS2:EVEN:HYST?";
        if livemode then; wait spoll bit 4; end if;
      enter temp_string format K;
      select temp_string;
       case "MIN";
        fetch (hysteresis2) min;
       case "MAX";
        fetch (hysteresis2) max;
       case "DEF";
        fetch (hysteresis2) def;
       case else;
        fetch hysteresis2;
      end select;
      store hysteresis2;
    end actions;
end component ;

! misc panel components
!
component average_state;
    type discrete ;
    values off,on;
    initial off;
    coupled aperture;
    set actions;
     output string ":SENS:AVER:STAT ";
     output average_state table "OFF","ON";
     gosub op_wait;
    end actions;
    get actions;
      output string ":SENS:AVER:STAT?";
        if livemode then; wait spoll bit 4; end if;
      enter temp_string format K;
      select temp_string;
       case "0";
        fetch (average_state) off;
       case "1";
        fetch (average_state) on;
       case else;
        fetch average_state;
      end select;
      store average_state;
    end actions;
end component;

component aperture;
    type continuous  ;
    values range 1E-3,99.999,1E-3;
    initial 100E-3;
    coupled aperture;
    set actions;
         output aperture format '":SENS:FREQ:APER ",K';
         gosub op_wait;
    end actions;
    get actions;
         output string ":SENS:FREQ:APER?";
        if livemode then; wait spoll bit 4; end if;
         enter aperture format k;
    end actions;
end component;

component freq_range;
    type continuous  ;
    values range 0.001,200E6,0.001;
    initial 100E6;
    coupled freq_range,freq_arange;
    set actions;
         output freq_range format '":SENS1:FREQ:RANG:UPP ",K';
    end actions;
    get actions;
         output string ":SENS1:FREQ:RANG:UPP?";
        if livemode then; wait spoll bit 4; end if;
         enter freq_range format k;
         fetch freq_range; fetch 100E6; gt;    ! for freq > 100 MHz,
         if stack then;                        ! pre scaling enabled
                            ! only freq, period and ratio can be meas'ed
              disable function1,risetime,falltime,pwid,nwid,tint,tot,
                          acv,dcv,minv,maxv;
           select function1;
           case freq;
           case per;
           case rat;
           case else; invalidate function1;
           end select;
         else;
              enable function1,risetime,falltime,pwid,nwid,tint,tot,
                          acv,dcv,minv,maxv;
              validate function1;
         end if;    ! if freq > 100 MHz

    end actions;
end component;

component freq_arange;
    type discrete ;
    values off,on;
    coupled freq_range;
    set actions;
     output string ":SENS1:FREQ:RANG:AUTO ";
     output freq_arange table "OFF","ON";
    end actions;
    get actions;
      output string ":SENS1:FREQ:RANG:AUTO?";
        if livemode then; wait spoll bit 4; end if;
      enter temp_string format K;
      select temp_string;
       case "0";
        fetch (freq_arange) off;
       case "1";
        fetch (freq_arange) on;
       case else;
        fetch freq_arange;
      end select;
      store freq_arange;
    end actions;
end component;

component rosc_source;
    type discrete ;
    values clk10,int,ext;
    initial clk10;
    coupled rosc_source;
    set actions;
     if option_010 then;
         output string ":SENS:ROSC:SOUR ";
         output rosc_source table "CLK10","INT","EXT";
     else;
        select rosc_source;
            case int;
              if recalling then; else;
                notify "Hardware Option 010 not installed";
              end if;
            case else;
                 output string ":SENS:ROSC:SOUR ";
                 output rosc_source table "CLK10","CLK10","EXT";
        end select;
     end if;
    end actions;
    get actions;
      output string ":SENS:ROSC:SOUR?";
        if livemode then; wait spoll bit 4; end if;
      enter temp_string format K;
      select temp_string;
       case "CLK10";
        fetch (rosc_source) clk10;
       case "INT";
        fetch (rosc_source) int;
       case "EXT";
        fetch (rosc_source) ext;
       case else ;
        fetch rosc_source ;
      end select;
      store rosc_source;
    end actions;
end component;

component abort notsaved;
    type integer;
    set actions;
         output string ":ABOR";
         output channel table "1","2","3";
        gosub op_wait;
    end actions;
end component;

component trigger notsaved;
    type integer;
    set actions;
         output string "*TRG";
        gosub op_wait;
    end actions;
end component;

!
! output panel components - chl independent
!

component last_gateout_line nogen noerrcheck;
    type string 1;
    initial "0";
end component;

component gateout_line;
    type discrete ;
    values off,ttltrg0,ttltrg1,ttltrg2,ttltrg3,ttltrg4,ttltrg5,ttltrg6,ttltrg7;
    initial off;
    set actions;
        select gateout_line;
         case off;
            output string ":OUTP:TTLT";
            output last_gateout_line format 'K';
            output string " 0";
            fetch "0"; store last_gateout_line;
         case else;
            fetch default; fetch 1; sub; dup;
            output stack format '":OUTP:TTLT",K," 1"';
            valstr; store last_gateout_line;
        end select;
    end actions;
    get actions;
      fetch 0;
      loop;
        dup; output stack format '":OUTP:TTLT",K,"?"';
        enter stack format "K";
      exit if stack;
        fetch 1; add; dup; fetch 8; ge;
      exit if stack;
      end loop;
      dup; fetch 8; ge;
      if stack then; drop; fetch 0;
      else; dup; valstr; store last_gateout_line; fetch 1; add;
      end if;
      store default;
    end actions;
end component;

component rosc_state;
    type discrete ;
    values off,on;
    initial off;
    set actions;
     if option_010 then;
         output string ":OUTP:ROSC:STATE ";
         output rosc_state table "OFF","ON";
     else;
        fetch 0; store rosc_state;
        IF RECALLING THEN; ELSE;
          notify "Hardware Option 010 not installed";
        END IF;
     end if;
    end actions;
    get actions;
     if option_010 then;
      output string ":OUTP:ROSC:STATE?";
        if livemode then; wait spoll bit 4; end if;
      enter temp_string format K;
      select temp_string;
       case "0";
        fetch (rosc_state) off;
       case "1";
        fetch (rosc_state) on;
       case else;
        fetch rosc_state;
      end select;
      store rosc_state;
     else;
        fetch 0; store rosc_state;
     end if;
    end actions;
end component;

!
!  vme memory panel components
!

component vme_mem_addr;
    type continuous  ;
    values range 2097152,14680056,1;
    initial 2097152;
    coupled vme_mem_size,vme_mem_addr,min_vme_mem_addr,max_vme_mem_addr;
    set actions;
      if option_040 then;
        output vme_mem_addr format '":MEM:VME:ADDR ",K';
        gosub op_wait;
      end if;
    end actions;
    get actions;
      if option_040 then;
         output string ":MEM:VME:ADDR?";
        if livemode then; wait spoll bit 4; end if;
         enter vme_mem_addr format k;
      end if;
    end actions;
end component;

component min_vme_mem_addr notsaved ;
    type continuous  ;
    initial invalid;
    get actions;
     if option_040 then;
     output string ":MEM:VME:ADDR? MIN";
        if livemode then; wait spoll bit 4; end if;
     enter min_vme_mem_addr format k;
     end if;
    end actions;
end component;

component max_vme_mem_addr notsaved ;
    type continuous  ;
    initial invalid;
    get actions;
      if option_040 then;
     output string ":MEM:VME:ADDR? MAX";
        if livemode then; wait spoll bit 4; end if;
     enter max_vme_mem_addr format k;
      end if;
    end actions;
end component;

component vme_mem_size;
    type continuous  ;
    values range 0,12582912,1;
    initial 0;
    coupled vme_mem_size,vme_mem_addr,min_vme_mem_addr,max_vme_mem_addr;
    set actions;
      if option_040 then;
         output vme_mem_size format '":MEM:VME:SIZE ",K';
        gosub op_wait;
      end if;
    end actions;
    get actions;
      if option_040 then;
     output string ":MEM:VME:SIZE?";
        if livemode then; wait spoll bit 4; end if;
     enter vme_mem_size format k;
      end if;
    end actions;
end component;

component vme_mem_state;
    type discrete ;
    values off,on;
    initial off;
    set actions;
      if option_040 then;
         output string ":MEM:VME:STAT ";
         output vme_mem_state table "OFF","ON";
        gosub op_wait;
      end if;
    end actions;
    get actions;
      if option_040 then;
      output string ":MEM:VME:STAT?";
        if livemode then; wait spoll bit 4; end if;
      enter temp_string format K;
      select temp_string;
       case "0";
        fetch (vme_mem_state) off;
       case "1";
        fetch (vme_mem_state) on;
       case else;
        fetch vme_mem_state;
      end select;
      store vme_mem_state;
     end if;
    end actions;
end component;

!
! status panel components
!

component stat_err_str notsaved;
    type string 30;
    initial "No Error";
    get actions; end actions;
end component ;

component stat_err_no notsaved noerrcheck;
    type integer;
    initial 0,invalid;
    get actions;
        output string ":SYST:ERR?";
        if livemode then; wait spoll bit 4; end if;
        enter stat_err_no format '#,K';
        enter stat_err_str format 'K';
        if stat_err_no then; get stat_evnt_evr; end if; ! clear it from spoll
    end actions;
end component;

component stat_evnt_evr notsaved;
    type integer;
    initial 0,invalid;
    get actions;
        output string "*ESR?";
        if livemode then; wait spoll bit 4; end if;
        enter stat_evnt_evr format 'K';
    end actions;
end component;

component stat_evnt_enr;
    type integer;
    values range 0,255;
    initial 60;
    set actions;
        output stat_evnt_enr format '"*ESE ",K';
    end actions;
    panel set actions;
        fetch stat_evnt_enr; fetch 60; eq;
        if stack then;
        else;
            notify "CAUTION: This ESE value may hamper error check operation";
        end if;
    end actions;
    get actions;
        output string "*ESE?";
        if livemode then; wait spoll bit 4; end if;
        enter stat_evnt_enr format 'K';
    end actions;
end component;

component stat_op_evr notsaved;
    type integer;
    initial 0,invalid;
    get actions;
        output string ":STAT:OPER?";
        if livemode then; wait spoll bit 4; end if;
        enter stat_op_evr format 'K';
    end actions;
end component;

component stat_op_enr;
    type integer;
    values range 0,32767;
    initial 0,invalid;
    set actions;
        output stat_op_enr format '":STAT:OPER:ENAB ",K';
    end actions;
    get actions;
        output string ":STAT:OPER:ENAB?";
        if livemode then; wait spoll bit 4; end if;
        enter stat_op_enr format 'K';
    end actions;
end component;

component stat_dq_evr notsaved;
    type integer;
    initial 0,invalid;
    get actions;
        output string ":STAT:QUES?";
        if livemode then; wait spoll bit 4; end if;
        enter stat_dq_evr format 'K';
    end actions;
end component;

component stat_dq_enr;
    type integer;
    values range 0,32767;
    initial 0,invalid;
    set actions;
        output stat_dq_enr format '":STAT:QUES:ENAB ",K';
    end actions;
    get actions;
        output string ":STAT:QUES:ENAB?";
        if livemode then; wait spoll bit 4; end if;
        enter stat_dq_enr format 'K';
    end actions;
end component;

component stat_stb notsaved;
    type integer;
    initial 0,invalid;
    get actions;
        output string "*STB?";
        if livemode then; wait spoll bit 4; end if;
        enter stat_stb format 'K';
    end actions;
end component;

component stat_sre;
    type integer;
    values range 0,255;
    initial 0,invalid;
    set actions;
        output stat_sre format '"*SRE ",K';
    end actions;
    get actions;
        output string "*SRE?";
        if livemode then; wait spoll bit 4; end if;
        enter stat_sre format 'K';
    end actions;
end component;

component stat_clear notsaved;
    type integer;
    set actions;
        output string "*CLS";
        invalidate stat_stb; invalidate stat_evnt_evr;
        invalidate stat_op_evr; invalidate stat_dq_evr;
        invalidate stat_opcv;
    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?";
        if livemode then; wait spoll bit 4; end if;
        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_show_reg notsaved nogen noerrcheck;
    type integer;
    panel set actions;
        hide stat_main; show stat_reg;
    end actions;
end component;

component stat_show_main notsaved nogen noerrcheck;
    type integer;
    panel set actions;
        hide stat_reg; show stat_main;
    end actions;
end component;

component sync notsaved;
  type integer;
  initial 0;
  set actions; get sync;
  end actions;
  get actions;
    fetch 1; store sync;
    clear; output string "*ESE 60"; flush;
    get model_B;
    get function1;
      get tinterval_delay; get tinterval_delay_state;
      get tot1_gate_state; get tot1_gate_polarity;
    get meas_init_cont;
    get function2; get tot2_gate_state; get tot2_gate_polarity;
    get function3;
    get inp1_att; get inp1_coup; get inp1_imp; get inp1_route;
    get inp2_att; get inp2_coup; get inp2_imp;
    get arm_start_level; get arm_stop_level;
    get arm_start_slope; get arm_stop_slope;
    get arm_start_source; get arm_stop_source;
    get even_lev1; get auto_trigger1; get even_slop1; get relative_even_lev1;
    get even_lev2; get auto_trigger2; get even_slop2; get relative_even_lev2;
    get hysteresis1; get hysteresis2;
    get average_state;
    get aperture;
    get freq_range; get freq_arange;
    get rosc_source; get rosc_state;
    get gateout_line;
    get vme_mem_addr; get vme_mem_size; get vme_mem_state;
    fetch 0; store sync;
  end actions;
end component;
!
COMPONENT erf1;  ! This causes function to be set if the state of expected
  TYPE INTEGER;  ! or resolution changes--because normally vee/itg won't
  INITIAL 0;     ! set invalid components
  SET ACTIONS;
    IF RECALLING THEN;
      FETCH DEFAULT; FETCH 3; NE; fetch function1; not; and;
      fetch channel; fetch 0; eq; and;
      IF STACK THEN; set function1; END IF;
    ELSE;
      FETCH expected1; fetch 0; ne;
      FETCH resolution1; fetch 0; ne; fetch 2; mul; add;
      STORE DEFAULT;
    END IF;
  END ACTIONS;
END COMPONENT;
!
COMPONENT erf2;  ! This causes function to be set if the state of expected
  TYPE INTEGER;  ! or resolution changes--because normally vee/itg won't
  INITIAL 0;     ! set invalid components
  SET ACTIONS;
    IF RECALLING THEN;
      FETCH DEFAULT; FETCH 3; NE; fetch function2; not; and;
      fetch channel; fetch 1; eq; and;
      IF STACK THEN; set function2; END IF;
    ELSE;
      FETCH expected2; fetch 0; ne;
      FETCH resolution2; fetch 0; ne; fetch 2; mul; add;
      STORE DEFAULT;
    END IF;
  END ACTIONS;
END COMPONENT;
!
COMPONENT erf3;  ! This causes function to be set if the state of expected
  TYPE INTEGER;  ! or resolution changes--because normally vee/itg won't
  INITIAL 0;     ! set invalid components
  SET ACTIONS;
    IF RECALLING THEN;
      FETCH DEFAULT; FETCH 3; NE; fetch function3; not; and;
      fetch channel; fetch 2; eq; and;
      IF STACK THEN; set function3; END IF;
    ELSE;
      FETCH expected3; fetch 0; ne;
      FETCH resolution3; fetch 0; ne; fetch 2; mul; add;
      STORE DEFAULT;
    END IF;
  END ACTIONS;
END COMPONENT;
!
!
!  panel section
!
panel tkvx4224;
    position 0,0;
    size 214,213;

    panel reset_panel;
        position 0,182;
        size 214,31;
        foreground (255,255,255) 100;

        discrete menu;
           position 72,6;
           size 136,19;
           background (75,0,240) 0 ;
         label "Main", "Input CONFIG","Event TRIGing","Arming",
                "MISC","Output CONFIG","Shared Memory","Status","About";
        end discrete;
        !
        button reset;
          position  6,6;
         size 55,19;
         background (0,130,70) 0;
          label "Reset";
         end button;
    end panel;         ! of reset_panel

    panel main;
     position 1,1;
     size 212,180;

    panel meas;
     position 0,0;
     size 212,179;


     display reading;
      position 5,140;
      size 170,30;
      format "6 DIGITS";
      font 15,25;
     end display;
     display unit;
      position 175,140;
      size 35,30;
      font 15,25;
     end display;

     text 5,100,"Channel";
     discrete channel;
      position 90,100;
      size 120,19;
      label "1","2","3";
     end discrete;

     panel channel1;
      position 0,70;
      size 212,30;

      text 5, 0,"Function";
      discrete function1;
       position 90,0;
       size 120,19;
       label "FREQ","Period","FREQ Ratio:2","Rise Time","Fall Time",
             "P Width","N Width","Time INT 1:2","Totalize","AC RMS",
             "DCV","MIN V","MAX V";
      end discrete;

      end panel; ! channel1

     panel channel2;
      position 0,70;
      size 212,30;

      text 5, 0,"Function";
      discrete function2;
       position 90,0;
       size 120,19;
       label "FREQ","Period","FREQ Ratio:1","P Width","N Width",
            "TOT by 1","AC RMS","DCV","MIN V","MAX V";
      end discrete;

      end panel; ! channel2

     panel channel3;
      position 0,70;
      size 212,30;

      text 5, 0,"Function";
      discrete function3;
       position 90,0;
       size 120,19;
       label "FREQ","Period","FREQ Ratio:1";
      end discrete;

      end panel; ! channel3

      text 5, 40,"Initiate";
        button meas_init;
          position  90,40;
         size 35,19;
         background (0,130,70) 0;
          label "IMM";
         end button;
        toggle meas_init_cont;
          position  130,40;
         size 80,19;
          label "CONT Off","CONT On";
         end toggle;

        button show_config;
          position  5,10;
         size 205,19;
         background (0,130,70) 0;
          label "MEAS  Configure";
         end button;

      end panel; ! meas

    panel config;
     position 0,0;
     size 212,179;

    panel res_exp_only1;
      position 0,40;
      size 212,140;

      text 5, 90,"Expected VAL";
      continuous  expected1;
       position 120,90;
       size 65,19;
       format "4 DIGITS";
      end continuous ;
      display unit1;
       position 185,90;
       size 25,19;
      end display;

      text 5,50,"Resolution";
      continuous  resolution1;
       position 120,50;
       size 65,19;
       format "4 DIGITS";
      end continuous ;
      display unit1;
       position 185,50;
       size 25,19;
      end display;

        button send_config1;
          position  5,10;
         size 205,19;
         background (0,130,70) 0;
          label "Send CONFIG";
         end button;

    end panel; ! res_exp_only1;

      panel rise_panel;    ! have addl cmds for rise & fall time msmnts
      position 0,40;
      size 212,140;

      text 5, 110,"Expected VAL";
      continuous  expected1;
       position 120,110;
       size 65,19;
       format "4 DIGITS";
      end continuous ;
      display unit1;
       position 185,110;
       size 25,19;
      end display;

      text 5,85,"Resolution";
      continuous  resolution1;
       position 120,85;
       size 65,19;
       format "4 DIGITS";
      end continuous ;
      display unit1;
       position 185,85;
       size 25,19;
      end display;

       text 5, 60,"Lower REF";
       continuous  Lower_ref1;
        position 120,60;
        size 75,19;
        format "MDDD.DD";
        style "NOENGR";
       end continuous ;
       button disp_temp;
        position 195,60;
        size 15,19;
        background (105,95,80),0;
        label "%";
       end button;

       text 5, 35,"Upper REF";
       continuous  Upper_ref1;
        position 120,35;
        size 75,19;
        format "MDDD.DD";
        style "NOENGR";
       end continuous ;
       button disp_temp;
        position 195,35;
        size 15,19;
        background (105,95,80),0;
        label "%";
       end button;

        button send_config1;
          position  5,10;
         size 205,19;
         background (0,130,70) 0;
          label "Send CONFIG";
         end button;

      end panel;     ! of rise_panel

      panel width1_panel;    ! components for nwidth/pwidth msmt
      position 0,40;
      size 212,140;

      text 5, 100,"Expected VAL";
      continuous  expected1;
       position 120,100;
       size 65,19;
       format "4 DIGITS";
      end continuous ;
      display unit1;
       position 185,100;
       size 25,19;
      end display;

      text 5,70,"Resolution";
      continuous  resolution1;
       position 120,70;
       size 65,19;
       format "4 DIGITS";
      end continuous ;
      display unit1;
       position 185,70;
       size 25,19;
      end display;

       text 5, 40,"Reference";
       continuous  Reference1;
        position 120,40;
        size 75,19;
        format "MDDD.DD";
        style "NOENGR";
       end continuous ;
       button disp_temp;
        position 195,40;
        size 15,19;
        background (105,95,80),0;
        label "%";
       end button;

        button send_config1;
          position  5,10;
         size 205,19;
         background (0,130,70) 0;
          label "Send CONFIG";
         end button;

      end panel;     ! of width1_panel

      panel tint_panel;        ! components for tinterval msmnt
      position 0,40;
      size 212,140;

      text 5, 110,"Expected VAL";
      continuous  expected1;
       position 120,110;
       size 65,19;
       format "4 DIGITS";
      end continuous ;
      display unit1;
       position 185,110;
       size 25,19;
      end display;

      text 5,85,"Resolution";
      continuous  resolution1;
       position 120,85;
       size 65,19;
       format "4 DIGITS";
      end continuous ;
      display unit1;
       position 185,85;
       size 25,19;
      end display;

        text 5, 60,"Delay";
        continuous  tinterval_delay;
         position 120,60;
         size 75,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, 35,"Delay Status";
        toggle tinterval_delay_state;
         position 120,35;
         size 90,19;
         label "Off","On";
        end toggle;

        button send_config1;
          position  5,10;
         size 205,19;
         background (0,130,70) 0;
          label "Send CONFIG";
         end button;

      end panel;     ! of tint_panel

      panel tot1_panel;        ! components for tot by gate msmnt
      position 0,40;
      size 212,140;

      text 5, 110,"Expected VAL";
      continuous  expected1;
       position 120,110;
       size 65,19;
       format "4 DIGITS";
      end continuous ;
      display unit1;
       position 185,110;
       size 25,19;
      end display;

      text 5,85,"Resolution";
      continuous  resolution1;
       position 120,85;
       size 65,19;
       format "4 DIGITS";
      end continuous ;
      display unit1;
       position 185,85;
       size 25,19;
      end display;

       text 5,60,"Gating by 2";
       toggle tot1_gate_state;
        position 120,60;
        size 90,19;
        label "Off","On";
       end toggle;

       text 5,35,"Gate POL";
        toggle tot1_gate_polarity;
         position 120,35;
         size 90,19;
         label "Normal","Inverted";
        end toggle;

        button send_config1;
          position  5,10;
         size 205,19;
         background (0,130,70) 0;
          label "Send CONFIG";
         end button;

      end panel;     ! of tot1_panel1

    panel res_exp_only2;
      position 0,40;
      size 212,140;

      text 5, 90,"Expected VAL";
      continuous  expected2;
       position 120,90;
       size 65,19;
       format "4 DIGITS";
      end continuous;
      display unit2;
       position 185,90;
       size 25,19;
      end display;

      text 5,50,"Resolution";
      continuous  resolution2;
       position 120,50;
       size 65,19;
       format "4 DIGITS";
      end continuous ;
      display unit2;
       position 185,50;
       size 25,19;
      end display;

        button send_config2;
          position  5,10;
         size 205,19;
         background (0,130,70) 0;
          label "Send CONFIG";
         end button;

      end panel;     ! of res_exp_only2;

      panel width2_panel;
      position 0,40;
      size 212,140;

      text 5, 100,"Expected VAL";
      continuous  expected2;
       position 120,100;
       size 65,19;
       format "4 DIGITS";
      end continuous ;
      display unit2;
       position 185,100;
       size 25,19;
      end display;

      text 5,70,"Resolution";
      continuous  resolution2;
       position 120,70;
       size 65,19;
       format "4 DIGITS";
      end continuous ;
      display unit2;
       position 185,70;
       size 25,19;
      end display;

       text 5, 40,"Reference";
       continuous  Reference2;
        position 120,40;
        size 75,19;
        format "MDDD.DD";
        style "NOENGR";
       end continuous ;
       button disp_temp;
        position 195,40;
        size 15,19;
        background (105,95,80),0;
        label "%";
       end button;

        button send_config2;
          position  5,10;
         size 205,19;
         background (0,130,70) 0;
          label "Send CONFIG";
         end button;

      end panel;     ! of width2_panel


      panel tot2_panel;        ! components for tot by gate msmnt
      position 0,40;
      size 212,140;

      text 5,110,"Expected VAL";
      continuous  expected2;
       position 120,110;
       size 65,19;
       format "4 DIGITS";
      end continuous ;
      display unit2;
       position 185,110;
       size 25,19;
      end display;

      text 5,85,"Resolution";
      continuous  resolution2;
       position 120,85;
       size 65,19;
       format "4 DIGITS";
      end continuous ;
      display unit2;
       position 185,85;
       size 25,19;
      end display;

       text 5,60,"Gating by 1";
       toggle tot2_gate_state;
        position 120,60;
        size 90,19;
        label "Off","On";
       end toggle;

       text 5,35,"Gate POL";
        toggle tot2_gate_polarity;
         position 120,35;
         size 90,19;
         label "Normal","Inverted";
        end toggle;

        button send_config2;
          position  5,10;
         size 205,19;
         background (0,130,70) 0;
          label "Send CONFIG";
         end button;

      end panel;     ! of tot2_panel

    panel res_exp_only3;
      position 0,40;
      size 212,140;

      text 5, 90,"Expected VAL";
      continuous  expected3;
       position 120,90;
       size 65,19;
       format "4 DIGITS";
      end continuous ;
      display unit3;
       position 185,90;
       size 25,19;
      end display;

      text 5,50,"Resolution";
      continuous  resolution3;
       position 120,50;
       size 65,19;
       format "4 DIGITS";
      end continuous ;
      display unit3;
       position 185,50;
       size 25,19;
      end display;

        button send_config3;
          position  5,10;
         size 205,19;
         background (0,130,70) 0;
          label "Send CONFIG";
         end button;

     end panel;     ! of res_exp_only3;

        button show_meas;
          position  5,10;
         size 205,19;
         background (0,130,70) 0;
          label "Cancel";
         end button;

     end panel; ! end config

    end panel;         ! of main panel

    panel input_c;
     position 1,1;
     size 212,180;

     toggle inp_chan;
      position 5,150;
      size 205,19;
      label "Channel 1","Channel 2";
     end toggle;

    panel inp1;
     position 1,1;
     size 211,145;

     text 5,110,"Attenuation";
     toggle inp1_att;
      position 120,110;
      size 90,19;
      label "x 1","x 10";
     end toggle;

     text 5,80,"Coupling";
     toggle inp1_coup;
      position 120,80;
      size 90,19;
      label "DC","AC";
     end toggle;

     text 5, 50,"Impedence";
     toggle inp1_imp;
      position 120,50;
      size 90,19;
      label "50 ohm", "1 M ohm";
     end toggle;

     text 5, 20,"Routing";
     toggle inp1_route;
      position 120,20;
      size 90,19;
      label "Separate","Common";
     end toggle;

     end panel;

    panel inp1_a;
     position 1,1;
     size 211,145;

     text 5,100,"Coupling";
     toggle inp1_coup;
      position 120,100;
      size 90,19;
      label "DC","AC";
     end toggle;

     text 5, 60,"Impedence";
     toggle inp1_imp;
      position 120,60;
      size 90,19;
      label "50 ohm", "1 M ohm";
     end toggle;

     text 5, 20,"Routing";
     toggle inp1_route;
      position 120,20;
      size 90,19;
      label "Separate","Common";
     end toggle;

     end panel;

    panel inp2;
     position 1,1;
     size 211,145;

     text 5,110,"Attenuation";
     toggle inp2_att;
      position 120,110;
      size 90,19;
      label "x 1","x 10";
     end toggle;

     text 5,80,"Coupling";
     toggle inp2_coup;
      position 120,80;
      size 90,19;
      label "DC","AC";
     end toggle;

     text 5, 50,"Impedence";
     toggle inp2_imp;
      position 120,50;
      size 90,19;
      label "50 ohm", "1M ohm";
     end toggle;

     text 5, 20,"Routing";
     toggle inp1_route;
      position 120,20;
      size 90,19;
      label "Separate","Common";
     end toggle;

     end panel;

    panel inp2_a;
     position 1,1;
     size 211,145;

     text 5,100,"Coupling";
     toggle inp2_coup;
      position 120,100;
      size 90,19;
      label "DC","AC";
     end toggle;

     text 5, 60,"Impedence";
     toggle inp2_imp;
      position 120,60;
      size 90,19;
      label "50 ohm", "1M ohm";
     end toggle;

     text 5, 20,"Routing";
     toggle inp1_route;
      position 120,20;
      size 90,19;
      label "Separate","Common";
     end toggle;

     end panel;

    end panel;         ! of input_c panel

    panel trigger;
     position 1,1;
     size 212,180;

     toggle trig_chan;
      position 5,150;
      size 205,19;
      label "Channel 1","Channel 2";
     end toggle;

    panel trig1;
     position 1,1;
     size 211,145;

     text 5,110,"Auto TRIG";
     toggle auto_trigger1;
      position 105,110;
      size 40,19;
      label "Off","On";
     end toggle;
     button auto_trigger_once1;
      position 150,110;
      size 60,19;
      background (0,130,70) 0;
      label "Once";
     end button;

     text 5,85,"TRIG Level";
     continuous  even_lev1;
      position 105,85;
      size 90,19;
      style "NOENGR";
      format "MDDD.DDD";
     end continuous ;
     button disp_temp;
       position 195,85;
       size 15,19;
       background (105,95,80),0;
       label "V";
     end button;

     text 5,35,"TRIG Slope";
     toggle even_slop1;
      position 105,35;
      size 105,19;
      label "Positive","Negative";
     end toggle;

     text 5,60,"REL TRIG";
     continuous  relative_even_lev1;
      position 105,60;
      size 90,19;
      style "NOENGR";
      format "DDD.DD";
     end continuous ;
     button disp_temp;
       position 195,60;
       size 15,19;
       background (105,95,80),0;
       label "%";
     end button;

     text 5,10,"Hysteresis";
     discrete hysteresis1;
      position 105,10;
      size 105,19;
      label "Minimum","Maximum","Default";
     end discrete;

     end panel; ! trig1

    panel trig2;
     position 1,1;
     size 211,145;

     text 5,110,"Auto TRIG";
     toggle auto_trigger2;
      position 105,110;
      size 40,19;
      label "Off","On";
     end toggle;
     button auto_trigger_once2;
      position 150,110;
      size 60,19;
      background (0,130,70) 0;
      label "Once";
     end button;

     text 5,85,"TRIG Level";
     continuous  even_lev2;
      position 105,85;
      size 90,19;
      style "NOENGR";
      format "MDDD.DDD";
     end continuous ;
     button disp_temp;
       position 195,85;
       size 15,19;
       background (105,95,80),0;
       label "V";
     end button;

     text 5,35,"TRIG Slope";
     toggle even_slop2;
      position 105,35;
      size 105,19;
      label "Positive","Negative";
     end toggle;

     text 5,60,"REL TRIG";
     continuous  relative_even_lev2;
      position 105,60;
      size 90,19;
      style "NOENGR";
      format "DDD.DD";
     end continuous ;
     button disp_temp;
       position 195,60;
       size 15,19;
       background (105,95,80),0;
       label "%";
     end button;

     text 5,10,"Hysteresis";
     discrete hysteresis2;
      position 105,10;
      size 105,19;
      label "Minimum","Maximum","Default";
     end discrete;

     end panel; ! trig2

    end panel;         ! of trigger panel

    panel misc;
     position 1,1;
     size 212,180;

     text 5,155,"Aperture";
     continuous  aperture;
      position 120,155;
      size 75,19;
      format "5 DIGITS";
     end continuous ;
     button disp_temp;
       position 195,155;
       size 15,19;
       background (105,95,80),0;
       label "s";
     end button;

     text 5,130,"AVRG State";
     toggle average_state;
      position 120,130;
      size 90,19;
      label "Off","On";
     end toggle;

     text 5,105,"Auto FREQ(1)";
     toggle freq_arange;
      position 120,105;
      size 90,19;
      label "Off","On";
     end toggle;

     text 5,80,"MAX FREQ(1)";
     continuous  freq_range;
      position 120,80;
      size 65,19;
      format "4 DIGITS";
     end continuous ;
     button disp_temp;
       position 185,80;
       size 25,19;
       background (105,95,80),0;
       label "Hz";
     end button;

     text 5,55,"ROSC Source";
     discrete rosc_source;
      position 120,55;
      size 90,19;
      label "CLK10","Internal","External";
     end discrete;

     text 5, 30,"MEAS Timeout";
     continuous  meas_time_out;
      position 120,30;
      size 75,19;
      style "NOENGR";
      format "5 DIGITS";
     end continuous ;
     button disp_temp;
       position 195,30;
       size 15,19;
       background (105,95,80),0;
       label "s";
     end button;

     button abort;
      position 5,5;
      size 95,19;
      background (0,130,70) 0;
      label "MEAS Abort";
     end button;

     button trigger;
      position 115,5;
      size 95,19;
      background (0,130,70) 0;
      label "Trigger";
     end button;

    end panel;         ! of misc panel

    panel arm;
     position 1,1;
     size 212,180;

     text 5,157,"Start Source";
     discrete arm_start_source;
      position 115,157;
      size 95,19;
      label "Bus","External","Immediate","Hold","TTL Trig0","TTL Trig1",
            "TTL Trig2","TTL Trig3","TTL Trig4","TTL Trig5","TTL Trig6",
            "TTL Trig7";
     end discrete;

     text 5,135,"Start Level";
     discrete arm_start_level;
        position 115,135;
        size 95,19;
        label "ECL -1.3V","GND 0V","TTL 1.6V";
     end discrete;

     text 5,113,"Start Slope";
     toggle arm_start_slope;
        position 115,113;
        size 95,19;
        label "Positive","Negative";
     end toggle;

     button arm_start_imm;
      position 5,91;
      size 205,19;
      background (0,130,70) 0;
      label "Start Arm Immediate";
     end button;

     text 5,69,"Stop Source";
     discrete arm_stop_source;
      position 115,69;
      size 95,19;
      label "Bus","External","Immediate","Hold","TTL Trig0","TTL Trig1",
            "TTL Trig2","TTL Trig3","TTL Trig4","TTL Trig5","TTL Trig6",
            "TTL Trig7";
     end discrete;

     text 5,47,"Stop Level";
     discrete arm_stop_level;
        position 115,47;
        size 95,19;
        label "ECL -1.3V","GND 0V","TTL 1.6V";
     end discrete;

     text 5,25,"Stop Slope";
     toggle arm_stop_slope;
        position 115,25;
        size 95,19;
        label "Positive","Negative";
     end toggle;

     button arm_stop_imm;
      position 5,3;
      size 205,19;
      background (0,130,70) 0;
      label "Stop Arm Immediate";
     end button;

    end panel;         ! of arm panel

    panel output;
     position 1,1;
     size 212,180;

     text 5,120,"GATE_OUT -->";
     discrete gateout_line;
      position 120,120;
      size 90,19;
      label "Off","TTL Trig0","TTL Trig1","TTL Trig2","TTL Trig3",
              "TTL Trig4","TTL Trig5","TTL Trig6","TTL Trig7";
     end discrete;

     toggle rosc_state;
      position 5,50;
      size 205,19;
      label "INT TBASE Output Off","INT TBASE -->> REF BNC";
     end toggle;

    end panel;         ! of output panel

    panel vme_memory;
     position 1,1;
     size 212,176;

     text 5,150,"MEM Status";
     toggle vme_mem_state;
        position 105,150;
        size 105,19;
        label "Off","On";
     end toggle;

     text 5,115,"MEM Size";
     continuous  vme_mem_size;
        position 105,115;
        size 105,19;
        style "NOENGR";
        format "DDDDDDDD";
     end continuous  ;

     text 5,80,"Start ADDR";
     continuous  vme_mem_addr;
        position 105,80;
        size 105,19;
        style "NOENGR";
        format "DDDDDDDD";
     end continuous ;

     text 5, 45,"MIN ADDR";
     display min_vme_mem_addr;
        position 105,45;
        size 105,19;
        style "NOENGR";
        format "DDDDDDDD";
     end display;

     text 5, 10,"MAX ADDR";
     display max_vme_mem_addr;
        position 105,10;
        size 105,19;
        style "NOENGR";
        format "DDDDDDDD";
     end display;

    end panel;         ! of vme_memory panel

    panel status;
     position 1,1;
     size 212,180;

    panel stat_main;
     position 1,1;
     size 211,179;

        text 5,155, "System Error";
        display stat_err_no;
            position 120,155;
            size 90,19;
            style "NOENGR";
        end display;
        display stat_err_str;
            position 5,130;
            size 205,19;
        end display;

        text 5,95,"Status Byte";
        display stat_stb;
            position 120,95;
            size 90,19;
            style "NOENGR";
        end display;

        text 5,65, "*OPC?";
        display stat_opcv;
            position 120,65;
            size 90,19;
        end display;

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

        button stat_wai;
            position 80,35;
            size 55,19;
            background (0,130,70) 0;
            label "*WAI";
        end button;

        button stat_clear;
            position 155,35;
            size 55,19;
            background (0,130,70) 0;
            label "*CLS";
        end button;

        button stat_show_reg;
            position 5,5;
            size 205,19;
            background (0,130,70) 0;
            label "Status Registers";
        end button;

        end panel; ! stat_main

    panel stat_reg;
     position 1,1;
     size 211,179;

        text 5,159, "REGS -->";
        text 95,159, "Event";
        text 160,159, "ENABL";
        text 5,145,"-----------------------";

        text 5,125,"STD Event";
        display stat_evnt_evr;
            position 95,125;
            size 50,19;
            style "NOENGR";
        end display;

        continuous stat_evnt_enr;
            position 160,125;
            size 50,19;
            style "NOENGR";
        end continuous;

        text 5,95,"STD OPERN";
        display stat_op_evr;
            position 95,95;
            size 50,19;
            style "NOENGR";
        end display;

        continuous stat_op_enr;
            position 160,95;
            size 50,19;
            style "NOENGR";
        end continuous;

        text 5,65,"DATA QUES";
        display stat_dq_evr;
            position 95,65;
            size 50,19;
            style "NOENGR";
        end display;

        continuous stat_dq_enr;
            position 160,65;
            size 50,19;
            style "NOENGR";
        end continuous;

        text 5,35,"SRQ Enable";
        continuous stat_sre;
            position 160,35;
            size 50,19;
            style "NOENGR";
        end continuous;

        button stat_show_main;
            position 5,5;
            size 205,19;
            background (0,130,70) 0;
            label "Status Main";
        end button;

    end panel; ! stat_reg

    end panel;         ! of status panel

    panel about ;
     position 1,1;
     size 212,176;

      text "TEK VX4224";
        position 31,140;
        FONT 15,25;
      end text;

      text 29,114,"Universal Counter";
      text 10,94,"For HP 75000 Series C";
      text 29,74,"Revision A.00.00";
      text 48,54,"Copyright (C)";
      text 21,37,"Hewlett-Packard Co.";
      text 88,20,"1996";
!
    end panel;         ! of about panel

end panel;     ! of tkvx4224 panel