Device(R3172)
%{
static float get_onedata(char wa1[]);
static int rd_data(char wav[], float temp[]);
static int rd_datab(unsigned char wav[], short temp[]);
static int rd_wf_data(struct gpibDpvt *pdpvt,  int p1, int p2, char **p3);
STATIC int mySrqHandler(struct hwpvt *phwpvt, int srqStatus);

}%
TimeOut 600;

NameTable Xdbn="10dB/","5dB/","2dB/","1dB/";
NameTable TrName = "501","1001";
NameTable HsName = "OFF","ON";

EfastTable Xdbe="0","1","2","3";
EfastTable TrMode = "0","1";
EfastTable HsMode = "0","1";

SrqHandler=mySrqHandler UNSolicited_SRQ;

ParamTable{
	set_center_freq{rec=ao,command="DL0; CF%lfHZ\r\n"}
	get_center_freq{rec=ai,command="DL0; CF?\r\n",conv="%lf\r\n",leng=511}
	set_start_freq{rec=ao,command="DL0; FA%lfHZ\r\n"}
	get_start_freq{rec=ai,command="DL0; FA?\r\n",conv="%lf\r\n",leng=511}
	set_stop_freq{rec=ao,command="DL0; FB%lfHZ\r\n"}
	get_stop_freq{rec=ai,command="DL0; FB?\r\n",conv="%lf\r\n",leng=511}
	set_center_freq_step{rec=ao,command="DL0; CS %lfHZ\r\n"}
	set_center_freq_auto{rec=ao,command="DL0; CA\r\n"}
	get_center_freq_step{rec=ai,command="DL0; CS?\r\n",conv="%lf\r\n",leng=511}
	set_span{rec=ao,command="DL0; SP%lfHZ\r\n"}
	get_span{rec=ai,command="DL0; SP?\r\n",conv="%lf\r\n",leng=511}	

	set_rbw{rec=ao,command="DL0; RB%lfHZ\r\n"}
	set_rbw_auto{rec=ao,command="DL0; BA\r\n"}
	get_rbw{rec=ai,command="DL0; RB?\r\n",conv="%lf\r\n",leng=511}
	set_vbw{rec=ao,command="DL0; VB%lfHZ\r\n"}
	set_vbw_auto{rec=ao,command="DL0; VA\r\n"}
	get_vbw{rec=ai,command="DL0; VB?\r\n",conv="%lf\r\n",leng=511}
	set_sweep{rec=ao,command="DL0; SW%lfSC\r\n"}
	set_sweep_auto{rec=ao,command="DL0; AS\r\n"}
	get_sweep{rec=ai,command="DL0; SW?\r\n",conv="%lf\r\n",leng=511}
	set_attenuation{rec=ao,command="DL0; AT%lfDB\r\n"}
	set_attenuation_auto{rec=ao,command="DL0; AA\r\n"}
	get_attenuation{rec=ai,command="DL0; AT?\r\n",conv="%lf\r\n",leng=511}
	
	set_couple_all_auto{rec=ao,command="DL0; AL\r\n"}

	set_log_scale{rec=ao,command="DL0; DD%lfDB\r\n"}
	get_log_scale{rec=mbbi,command="DL0; DD?\r\n",efast=Xdbe,name=Xdbn}

	set_reference_level{rec=ao,command="DL0; RL%lfDB\r\n"}
	get_reference_level{rec=ai,command="DL0; RL?\r\n",conv="%lf\r\n",leng=511}
	
	set_tgpwr{rec=ao,command="DL0; TGL%lfDB\r\n"}
	set_tgpwr_on{rec=ao,command="DL0; TG\r\n"}
	set_tgpwr_off{rec=ao,command="DL0; TGF\r\n"}
	get_tgpwr{rec=ai,command="DL0; TGL?\r\n",conv="%lf\r\n",leng=511}

	set_srccal{rec=ao,command="DL0; TGA\r\n"}

	set_title{rec=so,command="DL0; LON/%s/\r\n"}
        set_title_off{rec=ao,command="DL0; LOF\r\n"}
	
	get_trace_a{rec=wf,command="DL2 TBA?",leng=8191,
		    conv=rd_wf_data}
	get_trace_b{rec=wf,command="DL2 TBB?",leng=8191,
		    conv=rd_wf_data}
	
	set_trigger_single{rec=ao,command="DL0; SI\r\n"}
	set_trigger_start{rec=ao,command="DL0; SR\r\n"}
	set_trigegr_cont{rec=ao,command="DL0; CONTS\r\n"}
	set_trace_a_clrw{rec=ao,command="DL0; AB\r\n"}
	set_trace_b_clrw{rec=ao,command="DL0; BB\r\n"}

	set_marker_peak{rec=ao,command="DL0; PS\r\n"}
	set_marker_on{rec=ao,command="DL0; MN 1\r\n"}
	set_market_off{rec=ao,command="DL0; MO\r\n"}
	set_marker_delta{rec=ao,command="DL0; MKD 1\r\n"}
	set_marker_normal{rec=ao,command="DL0; MN 1\r\n"}
	get_marker_freq{rec=ai,command="DL0; MF?\r\n",
                        conv="%lf\r\n",leng=511}
	get_marker_amp{rec=ai,command="DL0; ML?\r\n",
	                conv="%lf\r\n",leng=511}
	
	set_sa_init{rec=ao,command="DL0; IP\r\n"}

	set_trace_writeA{rec=ao,command="DL0; AW\r\n"}
	set_trace_writeB{rec=ao,command="DL0; BW\r\n"}
	set_trace_viewA{rec=ao,command="DL0; AV\r\n"}
	set_trace_viewB{rec=ao,command="DL0; BV\r\n"}
	set_trace_maxholdA{rec=ao,command="DL0; AMAX ON\r\n"}
	set_trace_maxholdB{rec=ao,command="DL0; BMAX ON\r\n"}

	set_trace_vavgA{rec=lo,command="DL0; AG%d\r\n"}
	set_trace_vavgA_start{rec=ao,command="DL0; AGR\r\n"}
	set_trace_vavgA_stop{rec=ao,command="DL0; AGS\r\n"}
	set_header_off{rec=ao,command="DL0; S2\r\n"}
	set_trace_vavgB{rec=lo,command="DL0; BG%d\r\n"}
	set_trace_vavgB_start{rec=ao,command="DL0; BGR\r\n"}
	set_trace_vavgB_stop{rec=ao,command="DL0; BGS\r\n"}
	set_srccal_man{rec=lo,command="TGM %d\r\n"}
	
	set_srq_on{rec=so,type=CMD,command="DL0; OPR 8; S0\r\n"}
	set_srq_off{rec=so,type=CMD,command="DL0; S1\r\n"}
	UNSolicited_SRQ{rec=so,type=CMD,command="DL0; S2\r\n"}

	set_trace_501{rec=so,type=CMD,command="DL0; TPS\r\n"}
	set_trace_1001{rec=so,type=CMD,command="DL0; TPL\r\n"}
	get_trace_num{rec=mbbi,command="DL0; TP?\r\n",efast=TrMode,name=TrName}
	
	set_hisense_on{rec=so,type=CMD,command="DL0;HS\r\n"}
	set_hisense_off{rec=so,type=CMD,command="DL0;HS OFF\r\n"}
	get_hisense{rec=mbbi,command="DL0;HS?\r\n",efast=HsMode,name=HsName}


}


%{
#define	R3172_GOODBITS	0x3f
#define R3172_UNCAL	0x1
#define R3172_ENDCAL	0x2
#define R3172_ENDSW  	0x4
#define R3172_ENDAV	0x8
#define R3172_ERR	0x20

STATIC int mySrqHandler(struct hwpvt *phwpvt, int srqStatus)
{
  int   status = IDLE;          /* assume device will be idle when finished */
  int rqsBit,errorBit,busyBit;
  CALLBACK *pcallback;

  if (phwpvt->unsolicitedDpvt != NULL){
      
      pcallback=&(phwpvt->unsolicitedDpvt->head.callback);
      callbackSetCallback(devGpibLib_processCallback, pcallback);
      callbackSetPriority(priorityHigh, pcallback);
      callbackSetUser((void*)phwpvt->unsolicitedDpvt, pcallback);

      callbackRequest(pcallback);
    }
    else{
	logMsg("R3172 UNKNOWN SRQ\n");

    }
  return(status);
}




static float get_onedata(char wa1[])
{
  return atof(wa1);
}

static int rd_data(char wav[], float data[])

{
  int i;
  char wa1[8191];

  strcpy(wa1,strtok(wav,"\r\n"));
  data[0]=get_onedata(wa1);
  for (i=1; i<1001; i++)
   {

     strcpy(wa1,strtok(NULL,"\r\n"));
/*	printf("wa1=%s\n",wa1); */
     data[i] = get_onedata(wa1);
   }
  return 0;
}

static int rd_datab(unsigned char wav[], short data[])
{
  int i;
  
  for (i=0; i<1001; i++)
  {
    data[i]= wav[i*2]*256+wav[i*2+1];
  }
  return 0;
}

STATIC int rd_wf_data(struct gpibDpvt *pdpvt,  int p1, int p2, char **p3)
{
  struct waveformRecord *pwf = (struct waveformRecord *) (pdpvt->precord);
  unsigned char	*craw;
  short *temparray;
  short  temp[8191],*ptemp;
  int	s[8191],ok_flag;        
  unsigned long	numElem;

  temparray = (unsigned short *) pwf->bptr;
  craw = pdpvt->msg; 

/*	logMsg("craw = %s\n",craw);
	printf("craw -- end\n");*/
/*  craw = strtok(craw,"\r\n");

  if (craw == NULL) 
    {
      devGpibLib_setPvSevr(pwf, READ_ALARM, INVALID_ALARM);
      logMsg("null data in R3172\n");
      return(ERROR);
    }
*/
  
  ok_flag = rd_datab(craw,temp);
  /* logMsg("1,2,3,4 %d %d %d %d\n",temp[0],temp[1],temp[2],temp[3]); */
  if (ok_flag != 0) 
    {
      devGpibLib_setPvSevr(pwf,READ_ALARM, INVALID_ALARM);
      logMsg("Not OK R3172\n");
      return(ERROR);
    }
  
  numElem = 1001;
  if (numElem > pwf->nelm)      numElem = pwf->nelm;
  pwf->nord = numElem;
  ptemp=temp;	
  while (numElem--)
    {
	/*      logMsg( "\n%d-th data: %f",numElem, *ptemp); */  
      *temparray++ = (short) *ptemp++;
    }
  /*  logMsg( "\nread_wf end normally\n"); */
  return(OK);
}


}%

%{
}%