Device(HP8590)
%{
static int rd_data(char wav[], float 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 Couple ="AC", "DC";
NameTable Grat ="ON", "OFF";
NameTable Mkfcname "OFF", "ON";
NameTable ViewName = "A","B","C";

EfastTable CoupleMode ="COUPLE AC;\r\n", "COUPLE DC;\r\n";
EfastTable CoupleRead ="AC\r\n","DC\r\n";
EfastTable GratMode ="GRAT ON;\r\n", "GRAT OFF;\r\n";
EfastTable Mkfcmode ="MKFC OFF;\r\n", "MKFC ON;\r\n";
EfastTable ViewMode ="VIEW TRA;\r\n", "VIEW TRB;\r\n", "VIEW TRC;\r\n";

SrqHandler=mySrqHandler UNSolicited_SRQ;

ParamTable{
	set_center_freq{rec=ao,command="CF %lfHZ;\r\n"}
	set_center_freq_up{rec=ao,command="CF UP;\r\n"}
	set_center_freq_dn{rec=ao,command="CF DN;\r\n"}
	get_center_freq{rec=ai,command="CF?;\r\n",conv="%lf\r\n",leng=511}
	
	set_start_freq{rec=ao,command="FA %lfHZ;\r\n"}
	set_start_freq_up{rec=ao,command="FA UP;\r\n"}
	set_start_freq_dn{rec=ao,command="FA DN;\r\n"}
	get_start_freq{rec=ai,command="FA?;\r\n",conv="%lf\r\n",leng=511}

	set_stop_freq{rec=ao,command="FB %lfHZ;\r\n"}
	set_stop_freq_up{rec=ao,command="FB UP;\r\n"}
	set_stop_freq_dn{rec=ao,command="FB DN;\r\n"}
	get_stop_freq{rec=ai,command="FB?;\r\n",conv="%lf\r\n",leng=511}

	set_center_freq_step{rec=ao,command="SS %lfHZ;\r\n"}
	set_center_freq_step_up{rec=ao,command="SS UP;\r\n"}
	set_center_freq_step_dn{rec=ao,command="SS DN;\r\n"}
	set_center_freq_auto{rec=ao,command="SS AUTO;\r\n"}
	get_center_freq_step{rec=ai,command="SS?;\r\n",conv="%lf\r\n",leng=511}

	set_span{rec=ao,command="SP %lfHZ;\r\n"}
	set_span_up{rec=ao,command="SP UP;\r\n"}
	set_sapn_dn{rec=ao,command="SP DN;\r\n"}
	get_span{rec=ai,command="SP?;\r\n",conv="%lf\r\n",leng=511}	

	set_rbw{rec=ao,command="RB %lfHZ;\r\n"}
	set_rbw_up{rec=ao,command="RB UP;\r\n"}
	set_rbw_dn{rec=ao,command="RB DN;\r\n"}
	set_rbw_auto{rec=ao,command="RB AUTO;\r\n"}
	get_rbw{rec=ai,command="RB?\r\n",conv="%lf\r\n",leng=511}

	set_vbw{rec=ao,command="FB %lfHZ;\r\n"}
	set_vbw_up{rec=ao,command="VB UP;\r\n"}
	set_vbw_dn{rec=ao,command="VB DN;\r\n"}
	set_vbw_auto{rec=ao,command="VB AUTO;\r\n"}
	get_vbw{rec=ai,command="VB?\r\n",conv="%lf\r\n",leng=511}

	set_sweep{rec=ao,command="ST %lfSC;\r\n"}
	set_sweep_up{rec=ao,command="ST UP;\r\n"}
	set_sweep_dn{rec=ao,command="ST DN;\r\n"}
	set_sweep_auto{rec=ao,command="ST AUTO;\r\n"}
	get_sweep{rec=ai,command="ST?;\r\n",conv="%lf\r\n",leng=511}

	set_attenuation{rec=ao,command="AT %lfDB;\r\n"}
	set_attenuation_up{rec=ao,command="AT UP;\r\n"}
	set_attenuation_dn{rec=ao,command="AT DN;\r\n"}
	set_attenuation_auto{rec=ao,command="AT AUTO;\r\n"}
	get_attenuation{rec=ai,command="AT?;\r\n",conv="%lf\r\n",leng=511}
	
	set_couple{rec=mbbo,efast=CoupleMode,name=Couple}
	get_couple{rec=mbbi,efast=CoupleRead,name=Couple}

	set_log_scale{rec=ao,command="LG %lfDB;"}
	set_log_scale_up{rec=ao,command="LG UP;"}
	set_log_scale_dn{rec=ao,command="LG DN;"}
	get_log_scale{rec=ai,command="LG?;\r\n",conv="%lf\r\n",leng=511}

	set_linear{rec=ao,command="LN;"}

	set_reference_level{rec=ao,command="RL %lfDB;\r\n"}
	set_reference_level_up{rec=ao,command="RL UP;\r\n"}
	set_reference_level_dn{rec=ao,command="RL DN;\r\n"}
	get_reference_level{rec=ai,command="RL?;\r\n",conv="%lf\r\n",leng=511}
	
	set_srcat{rec=ao,command="SRCAT %lfDB;\r\n"}
	set_srcat_up{rec=ao,command="SRCAT UP;\r\n"}
	set_srcat_dn{rec=ao,command="SRCAT DN;\r\n"}
	set_srcat_auto{rec=ao,command="SRCAT AUTO;\r\n"}
	get_srcat{rec=ai,command="SRCAT?;\r\n",conv="%lf\r\n",leng=511}

	set_srcpwr{rec=ao,command="SRCPWR %lfDB;\r\n"}
	set_srcpwr_up{rec=ao,command="SRCPWR UP;\r\n"}
	set_srcpwr_dn{rec=ao,command="SRCPWR DN;\r\n"}
	set_srcpwr_on{rec=ao,command="SRCPWR ON;\r\n"}
	set_srcpwr_off{rec=ao,command="SRCPWR OFF;\r\n"}
	get_srcpwr{rec=ai,command="SRCPWR?;\r\n",conv="%lf\r\n",leng=511}

	set_srctkpk{rec=ao,command="SRCTKPK;"}

	set_grat{rec=mbbo,efast=GratMode,name=Grat}

	set_title{rec=so,command="TITLE :%s:;\r\n"}
	
	get_trace_a{rec=wf,command="TDF P;AUNITS DBM;TA;\r\n",leng=8191,
		    conv=rd_wf_data}
	get_trace_b{rec=wf,command="TDF P;AUNITS DBM;TB;\r\n",leng=8191,
		    conv=rd_wf_data}
	get_trace_aeos{rec=wf,command="ONEOS!TDF P; AUNITS DBM;TA;!\r\n",
                    leng=8191,conv=rd_wf_data}
	
	set_trigger_single{rec=ao,command="SNGLS;\r\n"}
	set_trigger_start{rec=ao,command="TS;\r\n"}
	set_trace_a_clrw{rec=ao,command="CLRW TRA;\r\n"}
	set_trace_b_clrw{rec=ao,command="CLRW TRB;\r\n"}

	set_marker_peak_eos{rec=ao,command="ONEOS!MKPK HI;!\r\n"}
	set_marker_peak_nh{rec=ao,command="MKPK NH;\r\n"}
	set_marker_peak_nr{rec=ao,command="MKPK NR;\r\n"}
	set_marker_peak_nl{rec=ao,command="MKPK NL;\r\n"}
	set_marker_delta{rec=ao,command="MKD;\r\n"}
	set_marker_normal{rec=ao,command="MKN;\r\n"}
	get_marker_freq{rec=ai,command="TDF P;MKREAD FRQ;MKF?;\r\n",
                        conv="%lf\r\n",leng=511}
	get_marker_amp{rec=ai,command="TDF P;AUNITS DBM;MKA?;\r\n",
	                conv="%lf\r\n",leng=511}
        set_marker_act{rec=lo,command="MKACT %d;\r\n"}
	get_marker_act{rec=li,command="MKACT?\r\n",conv="%d\r\n",leng=511}

	set_marker_center{rec=ao,command="MKCF;\r\n"}
	set_marker_counter{rec=mbbo,efast=Mkfcmode,name=Mkfcname}
	set_marker_fc_res{rec=lo,command="MKFCR %dHZ;\r\n"}
	get_marker_fc_res{rec=li,command="MKFCR?;\r\n",conv="%d\r\n",leng=511}

	set_maker_off{rec=ao,command="MKOFF ALL;\r\n"}

	get_maker_xpos{rec=li,command="MKP?;\r\n", conv="%d\r\n",leng=511}
	
	set_view_trace{rec=mbbo,efast=ViewMode,name=ViewName}
	set_sa_init{rec=ao,command="IP;\r\n"}
	set_cont_sweep{rec=ao,command="CONTS;\r\n"}
	set_marker_peak{rec=ao,command="MKPK HI;\r\n"}

	dispose_all{rec=ao,command="DISPOSE ALL;\r\n"}
	dispose_oneos{rec=ao,command="DISPOSE ONEOS;\r\n"}

	set_trace_maxhold_a{rec=ao,command="MXMH TRA;\r\n"}
	set_trace_maxhold_b{rec=ao,command="MXMH TRB;\r\n"}
	set_trace_vavg{rec=lo,command="VAVG %d;\r\n"}
	set_trace_vavg_on{rec=ao,command="VAVG ON;\r\n"}
	set_trace_vavg_off{rec=ao,command="VAVG OFF;\r\n"}
	set_trace_clrw_a{rec=ao,command="CLRW TRA;\r\n"}
	set_trace_clrw_b{rec=ao,command="CLRW TRB;\r\n"}
	set_trace_clrw_c{rec=ao,command="CLRW TRB;\r\n"}
	get_trace_eos_peak{rec=ai,command="ONEOS!MKPK HI;TDF P;MKREAD FRQ;MKF?;!\r\n",conv="%lf\r\n",leng=511}
	get_marker_eos{rec=ai,type=readw,command="ONEOS!MKPK HI;TDF P;MKREAD FRQ;MKF?;!\r\n",conv="%lf\r\n",leng=511}
	set_srq{rec=ao,command="RQS 20;\r\n"}
	rel_srq{rec=ao,command="RQS 0;\r\n"}
	get_stb{rec=li,command="STB?;\r\n",conv="%d\r\n",leng=511} 
	UNSolicited_SRQ{rec=si,type=read, command="EVENT?\r",
                        conv="%[^\t]",leng=320}
	set_srctk{rec=lo,command="SRCTK %d;\r\n"}
	get_srctk{rec=li,command="SRCTK?;\r\n",conv="%d\r\n",leng=511}
}





%{
#define	HP8590_GOODBITS	0x3E
#define HP8590_ILLCOM	0x20
#define HP8590_COMMAND  0x10
#define HP8590_HARD     0x08
#define HP8590_SWEEP    0x04
#define HP8590_USER     0x02

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

  /* analyze srqStatus */  
  rqsBit  =srqStatus & HP8590_COMMAND;

  switch (srqStatus & HP8590_GOODBITS) {
  case HP8590_ILLCOM:
	logMsg("HP8590 Illigal command\n");
	break;
  case HP8590_COMMAND:
	if (phwpvt->srqCallback !=NULL)
	  status =((*(phwpvt->srqCallback))(phwpvt->parm,srqStatus));
	else
	  logMsg("HP8590 srqHandler: Unsolicited operation complete from HP8590 device support!\n");
	break;
  case HP8590_HARD:
	logMsg("HP8590 hardware broken!!\n");
	break;
  case HP8590_SWEEP:
	if (phwpvt->srqCallback !=NULL)
	  status =((*(phwpvt->srqCallback))(phwpvt->parm,srqStatus));
	else
	  logMsg("HP8590 srqHandler: Unsolicited operation complete from HP8590 device support!\n");
	break;
  case HP8590_USER:
	break;
  default:
    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("HP8590 UNKNOWN SRQ\n");

    }
  }
  return(status);
}





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

{
  int i;
  char wa1[8191];

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

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

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

  temparray = (float *) 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 HP8590\n");
      return(ERROR);
    }
*/
  ok_flag = rd_data(craw,temp);
  if (ok_flag != 0) 
    {
      devGpibLib_setPvSevr(pwf,READ_ALARM, INVALID_ALARM);
      logMsg("Not OK HP8594\n");
      return(ERROR);
    }
  
  numElem = 399;
  if (numElem > pwf->nelm)      numElem = pwf->nelm;
  pwf->nord = numElem;
  ptemp=temp;	
  while (numElem--)
    {
      /* logMsg( "\n%d-th data: %f",numElem, *ptemp); */ 
      *temparray++ = (float) *ptemp++;
    }
  /*  logMsg( "\nread_wf end normally\n"); */
  return(OK);
}


}%

%{
}%