- various small bugfixes

- added driver for the lock-in amplifier
This commit is contained in:
zolliker
2006-10-27 08:14:13 +00:00
parent 980efacf6f
commit d6198ad3a3
8 changed files with 260 additions and 5 deletions

1
ease.c
View File

@ -67,6 +67,7 @@ void EaseWriteError(EaseBase *eab) {
eab->p.name); eab->p.name);
break; break;
case EASE_ILL_ANS: case EASE_ILL_ANS:
if (eab->p.verbose < 1) break;
l = strlen(eab->cmd); l = strlen(eab->cmd);
if (l > 0 && eab->cmd[l-1] < ' ') { if (l > 0 && eab->cmd[l-1] < ' ') {
l--; l--;

View File

@ -317,6 +317,7 @@ static long IghRead(long pc, void *object) {
} }
EaseWrite(eab, "R0"); EaseWrite(eab, "R0");
return __LINE__; case __LINE__: /**********************************/ return __LINE__; case __LINE__: /**********************************/
if (EaseGetUpdate(drv, SORBS_FLAG)) goto skip0;
drv->sorbS = OxiGet(eab, 1, NULL, drv->sorbS); drv->sorbS = OxiGet(eab, 1, NULL, drv->sorbS);
skip0: skip0:
@ -361,6 +362,7 @@ static long IghRead(long pc, void *object) {
if (EaseGetUpdate(drv, MIXP_FLAG)) goto skip4; if (EaseGetUpdate(drv, MIXP_FLAG)) goto skip4;
EaseWrite(eab, "R4"); EaseWrite(eab, "R4");
return __LINE__; case __LINE__: /**********************************/ return __LINE__; case __LINE__: /**********************************/
if (EaseGetUpdate(drv, MIXP_FLAG)) goto skip4;
drv->mixP = OxiGet(eab, 5 - drv->e, NULL, drv->mixP/10) * 10; drv->mixP = OxiGet(eab, 5 - drv->e, NULL, drv->mixP/10) * 10;
skip4: skip4:
@ -369,6 +371,7 @@ static long IghRead(long pc, void *object) {
if (EaseGetUpdate(drv, STILL_FLAG)) goto skip5; if (EaseGetUpdate(drv, STILL_FLAG)) goto skip5;
EaseWrite(eab, "R5"); EaseWrite(eab, "R5");
return __LINE__; case __LINE__: /**********************************/ return __LINE__; case __LINE__: /**********************************/
if (EaseGetUpdate(drv, STILL_FLAG)) goto skip5;
drv->stillP = OxiGet(eab, 1, NULL, drv->stillP); drv->stillP = OxiGet(eab, 1, NULL, drv->stillP);
skip5: skip5:
@ -377,6 +380,7 @@ static long IghRead(long pc, void *object) {
if (EaseGetUpdate(drv, SORBP_FLAG)) goto skip6; if (EaseGetUpdate(drv, SORBP_FLAG)) goto skip6;
EaseWrite(eab, "R6"); EaseWrite(eab, "R6");
return __LINE__; case __LINE__: /**********************************/ return __LINE__; case __LINE__: /**********************************/
if (EaseGetUpdate(drv, SORBP_FLAG)) goto skip6;
drv->sorbP = OxiGet(eab, 3, NULL, drv->sorbP); drv->sorbP = OxiGet(eab, 3, NULL, drv->sorbP);
skip6: skip6:
@ -385,6 +389,7 @@ static long IghRead(long pc, void *object) {
if (EaseGetUpdate(drv, MOT_FLAGS+V6)) goto skip7; if (EaseGetUpdate(drv, MOT_FLAGS+V6)) goto skip7;
EaseWrite(eab, "R7"); EaseWrite(eab, "R7");
return __LINE__; case __LINE__: /**********************************/ return __LINE__; case __LINE__: /**********************************/
if (EaseGetUpdate(drv, MOT_FLAGS+V6)) goto skip7;
drv->mv[V6] = OxiGet(eab, 1, NULL, drv->mv[V6]); drv->mv[V6] = OxiGet(eab, 1, NULL, drv->mv[V6]);
time(&now); time(&now);
delta = (now - drv->v6time) / 2.64; /* speed: 1/2.64 %/sec */ delta = (now - drv->v6time) / 2.64; /* speed: 1/2.64 %/sec */
@ -403,6 +408,7 @@ static long IghRead(long pc, void *object) {
if (EaseGetUpdate(drv, MOT_FLAGS+V12A)) goto skip8; if (EaseGetUpdate(drv, MOT_FLAGS+V12A)) goto skip8;
EaseWrite(eab, "R8"); EaseWrite(eab, "R8");
return __LINE__; case __LINE__: /**********************************/ return __LINE__; case __LINE__: /**********************************/
if (EaseGetUpdate(drv, MOT_FLAGS+V12A)) goto skip8;
drv->mv[V12A] = OxiGet(eab, 1, NULL, drv->mv[V12A]); drv->mv[V12A] = OxiGet(eab, 1, NULL, drv->mv[V12A]);
skip8: skip8:
@ -411,6 +417,7 @@ static long IghRead(long pc, void *object) {
if (EaseGetUpdate(drv, MOT_FLAGS+V1K)) goto skip9; if (EaseGetUpdate(drv, MOT_FLAGS+V1K)) goto skip9;
EaseWrite(eab, "R9"); EaseWrite(eab, "R9");
return __LINE__; case __LINE__: /**********************************/ return __LINE__; case __LINE__: /**********************************/
if (EaseGetUpdate(drv, MOT_FLAGS+V1K)) goto skip9;
drv->mv[V1K] = OxiGet(eab, 1, NULL, drv->mv[V1K]); drv->mv[V1K] = OxiGet(eab, 1, NULL, drv->mv[V1K]);
skip9: skip9:

140
linadriv.c Normal file
View File

@ -0,0 +1,140 @@
/*---------------------------------------------------------------------------
linadriv.c
Driver for the Lock IN Amplifier SIGNAL RECOVERY Model 7265
Markus Zolliker, Oct 2006
----------------------------------------------------------------------------*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <sys/time.h>
#include <math.h>
#include <tcl.h>
#include <fortify.h>
#include <sics.h>
#include <splitter.h>
#include <obpar.h>
#include <devexec.h>
#include <nserver.h>
#include <interrupt.h>
#include <emon.h>
#include <evcontroller.h>
#include <evcontroller.i>
#include <servlog.h>
#include <sicsvar.h>
#include <evdriver.i>
#include <rs232controller.h>
#include "linahdl.h"
#include "fsm.h"
#include "initializer.h"
typedef struct {
EaseDriv d;
float x, y;
} Lina;
static ParClass linaClass = { "LINA", sizeof(Lina) };
/*----------------------------------------------------------------------------*/
static void LinaParDef(void *object) {
Lina *drv = ParCast(&linaClass, object);
EaseBase *eab = object;
ParName(""); ParTail("units");
ParFloat(&drv->x, PAR_NAN);
ParName("x"); ParTail("");
ParFloat(&drv->x, PAR_NAN);
ParName("y"); ParTail("");
ParFloat(&drv->y, PAR_NAN);
EaseBasePar(drv);
EaseSendPar(drv);
/*
EaseDrivPar(drv, "%.5g", "K");
*/
ParStdDef();
EaseMsgPar(drv);
}
/*----------------------------------------------------------------------------*/
static long LinaRead(long pc, void *object) {
Lina *drv = ParCast(&linaClass, object);
EaseBase *eab = object;
char *p;
switch (pc) { default: /* FSM BEGIN *******************************/
EaseWrite(eab, "XY.");
return __LINE__; case __LINE__: /**********************************/
p = strchr(eab->ans, ',');
if (p) {
*p='\0';
p++;
drv->x = atof(eab->ans);
drv->y = atof(p);
}
ParLog(drv);
fsm_quit: return 0; } /* FSM END *********************************/
}
/*----------------------------------------------------------------------------*/
static long LinaStart(long pc, void *object) {
Lina *drv = ParCast(&linaClass, object);
EaseBase *eab = object;
switch (pc) { default: /* FSM BEGIN *******************************/
EaseWrite(eab, "ID");
return __LINE__; case __LINE__: /**********************************/
if (0 != strncmp(eab->version, "7265", 4)) {
snprintf(eab->msg, sizeof eab->msg, "unknown lock in amplifier version: %s",
eab->version);
ParPrintf(drv, eError, "ERROR: %s", eab->msg);
EaseStop(eab);
goto quit;
}
ParPrintf(drv, eStatus, "connected to %s", eab->version);
FsmCall(LinaRead);
return __LINE__; case __LINE__: /**********************************/
quit:
return 0; } /* FSM END ********************************************/
}
/*----------------------------------------------------------------------------*/
static long LinaSet(long pc, void *object) {
Lina *drv = ParCast(&linaClass, object);
EaseBase *eab = object;
char cmd[32];
int upd;
switch (pc) { default: /* FSM BEGIN *******************************/
/*
snprintf(cmd, sizeof cmd, "SETP %.5g;SETP?", drv->d.targetValue);
EaseWrite(eab, cmd);
*/
quit:
return 0; } /* FSM END ********************************************/
}
/*----------------------------------------------------------------------------*/
static int LinaInit(SConnection *con, int argc, char *argv[], int dynamic) {
/* args:
MakeObject objectname lina <rs232>
MakeObject objectname lina <host> <port>
*/
Lina *drv;
drv = EaseMakeDriv(con, &linaClass, argc, argv, dynamic, 7,
LinaParDef, LinaHandler, LinaStart, NULL, LinaRead,
LinaSet);
if (drv == NULL) return 0;
/*
setRS232ReplyTerminator(drv->d.b.ser,"\n");
setRS232SendTerminator(drv->d.b.ser,"\n");
*/
return 1;
}
/*----------------------------------------------------------------------------*/
void LinaStartup(void) {
ParMakeClass(&linaClass, EaseDrivClass());
MakeDriver("LINA", LinaInit, 0, "Lock in amplifier SIGNAL RECOVERY Model 7265");
}

81
linahdl.c Normal file
View File

@ -0,0 +1,81 @@
/*---------------------------------------------------------------------------
linahdl.c
lina (signal recovery lock in amplifier model 7265) handler
Markus Zolliker, Oct 2006
----------------------------------------------------------------------------
there is no error return value, eab->errCode is used. On success, eab->errCode
is not changed, i.e. an existing errCode is not overwritten.
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fortify.h>
#include "sics.h"
#include "oxinst.h"
/*----------------------------------------------------------------------------*/
int LinaHandler(void *object) {
int iret, l;
EaseBase *eab = EaseBaseCast(object);
char *corr;
if (eab->state < EASE_idle) goto quit;
if (availableNetRS232(eab->ser) || availableRS232(eab->ser)) {
eab->msg[0] = '\0';
l = sizeof(eab->ans);
iret = readRS232TillTerm(eab->ser, eab->ans, &l);
if (eab->state != EASE_expect && eab->state != EASE_lost) {
if (iret == 1) {
ParPrintf(eab, eError, "unexpected answer: %s", eab->ans);
}
goto quit;
}
if (iret == 1) {
ParPrintf(eab, -2, "ans: %s", eab->ans);
if (eab->state == EASE_lost) {
goto quit;
} else if (strncmp(eab->cmd,"ID",2) == 0) {
if (strcmp(eab->ans, eab->version) == 0) {
/* we are still connected with the same device */
} else if (*eab->version == '\0') {
strncat(eab->version, eab->ans, sizeof(eab->version)-1);
} else { /* version (and therefore device) changed */
eab->errCode = EASE_DEV_CHANGED;
eab->state = EASE_idle;
goto error;
}
eab->state = EASE_idle;
goto quit;
} else {
eab->tmo = 120;
}
}
if (iret != 1) {
eab->errCode = iret;
eab->state = EASE_idle;
goto error;
}
eab->state = EASE_read;
} else if (eab->state == EASE_expect) {
if (time(NULL) > eab->cmdtime + eab->tmo) {
eab->state = EASE_lost;
}
} else if (eab->state == EASE_lost) {
/*
if (time(NULL) > eab->cmdtime) {
EaseWrite(eab, "RS");
eab->state = EASE_lost;
}
*/
}
goto quit;
error:
/* EaseWriteError(eab); */
quit:
return EaseHandler(eab);
}

16
linahdl.h Normal file
View File

@ -0,0 +1,16 @@
/*---------------------------------------------------------------------------
linahdl.h
lina (signal recovery lock in amplifier model 7265) handler
Markus Zolliker, Oct 2006
----------------------------------------------------------------------------*/
#ifndef LINAHDL_H
#define LINAHDL_H
#include "ease.h"
int LinaHandler(void *eab);
#endif

View File

@ -46,6 +46,9 @@ static void Lsc370ParDef(void *object) {
ParName(""); ParTail("K"); ParName(""); ParTail("K");
ParFloat(&drv->t, PAR_NAN); ParFloat(&drv->t, PAR_NAN);
ParName("htr"); ParTail("%");
ParFloat(&drv->htr, PAR_NAN);
EaseBasePar(drv); EaseBasePar(drv);
EaseSendPar(drv); EaseSendPar(drv);
EaseDrivPar(drv, "%.5g", "K"); EaseDrivPar(drv, "%.5g", "K");
@ -64,7 +67,13 @@ static long Lsc370Read(long pc, void *object) {
EaseWrite(eab, "HTR?"); EaseWrite(eab, "HTR?");
return __LINE__; case __LINE__: /**********************************/ return __LINE__; case __LINE__: /**********************************/
drv->htr = atof(eab->ans); drv->htr = atof(eab->ans);
if (EaseGetUpdate(drv, EASE_RUN)) goto skipGetSet;
EaseWrite(eab, "SET?");
return __LINE__; case __LINE__: /**********************************/
if (EaseGetUpdate(drv, EASE_RUN)) goto skipGetSet;
drv->d.targetValue = atof(eab->ans);
skipGetSet:
ParLog(drv); ParLog(drv);
fsm_quit: return 0; } /* FSM END *********************************/ fsm_quit: return 0; } /* FSM END *********************************/
} }
@ -100,12 +109,12 @@ static long Lsc370Set(long pc, void *object) {
switch (pc) { default: /* FSM BEGIN *******************************/ switch (pc) { default: /* FSM BEGIN *******************************/
upd = EaseNextUpdate(drv); upd = EaseNextUpdate(drv);
if (upd != EASE_RUN) goto quit; if (upd != EASE_RUN) goto quit;
EaseWrite(eab, "MODE 1:MODE?"); /* remote mode */ EaseWrite(eab, "MODE 1;MODE?"); /* remote mode */
return __LINE__; case __LINE__: /**********************************/ return __LINE__; case __LINE__: /**********************************/
snprintf(cmd, sizeof cmd, "SETP %.5g:SETP?", drv->d.targetValue); snprintf(cmd, sizeof cmd, "SETP %.5g;SETP?", drv->d.targetValue);
EaseWrite(eab, cmd); EaseWrite(eab, cmd);
return __LINE__; case __LINE__: /**********************************/ return __LINE__; case __LINE__: /**********************************/
EaseWrite(eab, "MODE 0:MODE?"); /* local mode */ EaseWrite(eab, "MODE 0;MODE?"); /* local mode */
quit: quit:
return 0; } /* FSM END ********************************************/ return 0; } /* FSM END ********************************************/
} }

View File

@ -22,7 +22,7 @@ OBJ=psi.o buffer.o ruli.o dmc.o nxsans.o nextrics.o sps.o pimotor.o \
MZOBJ=fsm.o logger.o sugar.o pardef.o ease.o strobj.o oxinst.o logreader.o \ MZOBJ=fsm.o logger.o sugar.o pardef.o ease.o strobj.o oxinst.o logreader.o \
ipsdriv.o ilmdriv.o itcdriv.o ighdriv.o euro2kdriv.o modbus.o arrobj.o \ ipsdriv.o ilmdriv.o itcdriv.o ighdriv.o euro2kdriv.o modbus.o arrobj.o \
lscsupport.o lsc370driv.o lscsupport.o lsc370driv.o linadriv.o linahdl.o
libpsi.a: $(OBJ) libpsi.a: $(OBJ)
rm -f libpsi.a rm -f libpsi.a

1
psi.c
View File

@ -84,6 +84,7 @@ void SiteInit(void) {
INIT(LogReaderInit); INIT(LogReaderInit);
INIT(ArrayObjStartup); INIT(ArrayObjStartup);
INIT(Lsc370Startup); INIT(Lsc370Startup);
INIT(LinaStartup);
} }