Device(R3361)
%{
static float get_onedata(char wa1[]);
static int rd_data(char wav[], float temp[]);
static int rd_datab(unsigned char wav[], unsigned 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/","0.5dB/","0.2dB/","0.1dB/";
NameTable Mkfcname "OFF", "ON";
NameTable ViewName = "A","B","C";
NameTable DivName = "8div","12div","N/A";

EfastTable Xdbe="0","1","2","3","4","5","6";
EfastTable Mkfcmode ="MKFC OFF;\r\n", "MKFC ON;\r\n";
EfastTable ViewMode ="VIEW TRA;\r\n", "VIEW TRB;\r\n", "VIEW TRC;\r\n";
EfastTable DivMode = "0","1","2";

SrqHandler=mySrqHandler UNSolicited_SRQ;

ParamTable{
	set_center_freq{rec=ao,command="DL0 CF%lfHZ\r\n"}
	get_center_freq{rec=ai,command="HD0 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="HD0 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 RE%lfDB\r\n"}
	get_reference_level{rec=ai,command="HD0 DL0 RE?\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="HD0 DL2 TBA?",leng=8191,
		    conv=rd_wf_data}
	get_trace_b{rec=wf,command="HD0 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 FR\r\n"}
	set_trace_a_clrw{rec=ao,command="DL0 CWA\r\n"}
	set_trace_b_clrw{rec=ao,command="DL0 CWB\r\n"}

	set_marker_peak{rec=ao,command="DL0 PS\r\n"}
	set_marker_on{rec=ao,command="DL0 MN\r\n"}
	set_market_off{rec=ao,command="DL0 MO\r\n"}
	set_marker_delta{rec=ao,command="DL0 MT\r\n"}
	set_marker_normal{rec=ao,command="DL0 MK\r\n"}
	get_marker_freq{rec=ai,command="HD0 DL0 MF?\r\n",
                        conv="%lf\r\n",leng=511}
	get_marker_amp{rec=ai,command="HD0 DL0 ML?\r\n",
	                conv="%lf\r\n",leng=511}
	
	set_view_traceA{rec=ao,command="DL0 TA\r\n"}
	set_view_traceB{rec=ao,command="DL0 TB\r\n"}
	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 AM\r\n"}
	set_trace_maxholdB{rec=ao,command="DL0 BM\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="HD0 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 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_div_8{rec=so,type=CMD,command="DL0 DV0\r\n"}
	set_div_12{rec=so,type=CMD,command="DL0 DV1\r\n"}
	get_divnum{rec=mbbi,command="DL0 DV?\r\n",efast=DivMode,name=DivName}

}


%{
#define	R3361_GOODBITS	0x3f
#define R3361_UNCAL	0x1
#define R3361_ENDCAL	0x2
#define R3361_ENDSW  	0x4
#define R3361_ENDAV	0x8
#define R3361_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("R3361 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<701; 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[], unsigned short data[])
{
  int i;
  
  for (i=0; i<701; 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;
  unsigned short *temparray;
  unsigned 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 R3361\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 R3361\n");
      return(ERROR);
    }
  
  numElem = 701;
  if (numElem > pwf->nelm)      numElem = pwf->nelm;
  pwf->nord = numElem;
  ptemp=temp;	
  while (numElem--)
    {
	/*      logMsg( "\n%d-th data: %f",numElem, *ptemp); */  
      *temparray++ = (unsigned short) *ptemp++;
    }
  /*  logMsg( "\nread_wf end normally\n"); */
  return(OK);
}


}%

%{
}%