/* dev34410A.c
 *
 * Agilent 34410A DVM device support (asyn)
 *
 */

#include <epicsStdio.h>
#include <devCommonGpib.h>

/***********************************************************************
* asynDriver is distributed subject to a Software License Agreement
* found in file LICENSE that is included with this distribution.
***********************************************************************/
#defineDSET_AIdevAi34410A
#defineDSET_AOdevAo34410A
#defineDSET_BIdevBi34410A
#defineDSET_BOdevBo34410A
#defineDSET_LIdevLi34410A
#defineDSET_LOdevLo34410A
#defineDSET_MBBOdevMbbo34410A
#defineDSET_MBBIdevMbbi34410A
#define DSET_WF devWf34410A
#defineDSET_SIdevSi34410A
#defineDSET_SOdevSo34410A
#define DSET_WF devWf34410A #include <devGpib.h> #include <string.h> #include <strings.h> #include <stdlib.h>
#defineTIMEOUT0.8
#define TIMEWINDOW 0.4 static int rd_wf_data(struct gpibDpvt *pdpvt, int p1, int p2, char **p3); //static int readString(gpibDpvt *pdpvt,int P1, int P2, char **P3); /* * Define end-of-string character(s) here to allow * easier changes when testing the driver. */ /* static float NPLCVal[]={0.006,0.02,0.06,0.2,1,2,10,100}; static char *NPLClist[]=("0.006","0.02","0.06","0.2","1","2","10","100"} static struct devGpibNames NPLC ={4,NPLClist, NPLCVal, 8); */ #define EOSNL "\n" static struct gpibCmd gpibCmds[] = { /* COMMAND 0 reset */ {&DSET_BO, GPIBWRITE, IB_Q_LOW, NULL, "RST;*CLS\n", 0, 32, NULL, 0, 0, NULL, NULL, EOSNL }, /* COMMAND 1 DISP OFF */ {&DSET_BO, GPIBWRITE, IB_Q_LOW, NULL, "DISP OFF\n",0, 32, NULL, 0,0, NULL, NULL, EOSNL }, /* COMMAND 2 DISP ON */ {&DSET_BO, GPIBWRITE, IB_Q_LOW, NULL, "DISP ON\n",0,32, NULL, 0,0, NULL,NULL, EOSNL}, /* COMMAND 3 DCV SET */ {&DSET_AO, GPIBWRITE, IB_Q_LOW, NULL, "CONF:VOLT:DC %lf\n", 0, 32, NULL, 0, 0, NULL, NULL, EOSNL}, /* COMMAND 4 Aperter time set */ {&DSET_AO, GPIBWRITE, IB_Q_LOW, NULL, "SENS:VOLT:DC:APER %lf\n",0, 32, NULL, 0,0, NULL, NULL, EOSNL}, /* COMMAND 5 AUTO ZERO OFF */ {&DSET_BO, GPIBWRITE, IB_Q_LOW, NULL, "SENS:VOLT:ZERO:AUTO OFF\n", 0, 32, NULL, 0, 0, NULL, NULL, EOSNL}, /* COMMAND 6 AUTO ZERO ON */ {&DSET_BO, GPIBWRITE, IB_Q_LOW, NULL, "SENS:VOLT:ZERO:AUTO ON\n", 0, 32, NULL, 0, 0, NULL, NULL, EOSNL}, /* COMMAND 7 Internal Trigger */ {&DSET_BO, GPIBWRITE, IB_Q_LOW, NULL, "TRIG:SOUR IMM\n", 0, 32, NULL, 0, 0, NULL, NULL, EOSNL}, /* COMMAND 8 External Trigegr */ {&DSET_BO, GPIBWRITE, IB_Q_LOW, NULL, "TRIG:SOUR EXT\n",0, 32, NULL, 0, 0, NULL, NULL, EOSNL}, /* COMMAND 9 TRIG COUNT INF */ {&DSET_BO, GPIBWRITE, IB_Q_LOW, NULL, "TRIG:COUN INF\n", 0, 32, NULL, 0, 0, NULL, NULL, EOSNL}, /* COMMAND 10 TRIGGER DELAY */ {&DSET_LO, GPIBWRITE, IB_Q_LOW, NULL, "TRIG:DEL %ld\n", 0, 32, NULL, 0, 0, NULL, NULL, EOSNL}, /* COMMAND 11 Fromat set */ {&DSET_BO, GPIBWRITE, IB_Q_LOW, NULL, "FORM REAL,32;:FORM:BORD SWAP\n", 0, 32, NULL, 0, 0, NULL, NULL, EOSNL}, /* COMMAND 12 START */ {&DSET_BO, GPIBWRITE, IB_Q_LOW, NULL, "INIT\n", 0, 32, NULL, 0, 0, NULL, NULL, EOSNL}, /* COMMAND 13 NPLC set */ {&DSET_AO, GPIBWRITE, IB_Q_LOW, NULL, "SENS:VOLT:DC:NPLC %lf\n", 0, 32, NULL, 0, 0, NULL, NULL, EOSNL}, /* COMMAND 14 get waveform */ {&DSET_WF, GPIBREAD, IB_Q_HIGH, "R? 8000\n", NULL, 0,45000, rd_wf_data, 0, 0, NULL, NULL,NULL}, /* COMMAND 15 abort */ {&DSET_BO, GPIBWRITE, IB_Q_LOW, NULL, "ABOR\n", 0, 32, NULL, 0, 0, NULL ,NULL,EOSNL} }; /* The following is the number of elements in the command array above. */
#define NUMPARAMSsizeof(gpibCmds)/sizeof(struct gpibCmd)
/****************************************************************************** * * Initialization for device support * This is called one time before any records are initialized with a parm * value of 0. And then again AFTER all record-level init is complete * with a param value of 1. * ******************************************************************************/ static long init_ai(int parm) { if(parm==0) { devSupParms.name = "dev34410A"; devSupParms.gpibCmds = gpibCmds; devSupParms.numparams = NUMPARAMS; devSupParms.timeout = TIMEOUT; devSupParms.timeWindow = TIMEWINDOW; devSupParms.respond2Writes = -1.0; } return(0); } /* static int readString(gpibDpvt *pdpvt,int P1, int P2, char **P3) { stringinRecord *prec = (stringinRecord*)pdpvt->precord; strncpy(prec->val,pdpvt->msg,sizeof(prec->val)); prec->val[sizeof(prec->val) - 1] = 0; 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; char ll[80000]; int n,n1; float *temparray, *lx,lf[200000]; unsigned long numElem; int i; lx=(float * )lf; temparray = (float *)pwf->bptr; craw = pdpvt->msg; strncpy(ll,craw,1); ll[1]=NULL; /* printf("craw 1st %s\n",ll); if (ll !="#"){ printf("Invalid data %x\n",ll[0]); return(-1); } */ strncpy(ll,craw+1,1); ll[1]=NULL; n = atoi(ll); strncpy(ll,craw+2,n); ll[n]=NULL; n1 = atoi(ll); numElem = n1 >> 2; /* printf("numElem %ld\n",numElem); */ memcpy(ll,craw+2+n,n1); lx = (float *)ll; pwf->nord = numElem; while(numElem --){ *temparray++ = *lx++; } return(0); }