diff --git a/ease.c b/ease.c index 0edd82f..9b4fda6 100644 --- a/ease.c +++ b/ease.c @@ -627,7 +627,7 @@ static int EaseInit(SConnection *pCon, EaseBase *eab, int argc, char *argv[], setRS232ReplyTerminator(eab->ser,"\r"); setRS232SendTerminator(eab->ser,"\r"); - setRS232Timeout(eab->ser,10000); /* milliseconds */ + setRS232Timeout(eab->ser,5000); /* milliseconds */ setRS232Debug(eab->ser,0); eab->task = NULL; diff --git a/ipsdriv.c b/ipsdriv.c index ce4cc3d..ba2b842 100644 --- a/ipsdriv.c +++ b/ipsdriv.c @@ -497,6 +497,7 @@ static int IpsInit(SConnection *con, int argc, char *argv[], int dynamic) { IpsChangeField); if (drv == NULL) return 0; drv->d.maxwait = 999999; + drv->d.tolerance = 0.001; return 1; } /*----------------------------------------------------------------------------*/ diff --git a/lsc370driv.c b/lsc370driv.c new file mode 100644 index 0000000..5ecb9f5 --- /dev/null +++ b/lsc370driv.c @@ -0,0 +1,132 @@ +/*--------------------------------------------------------------------------- +lsc370driv.c + +Driver for the LakeShore Model 370 AC Resistance Bridge + +Markus Zolliker, July 2006 +----------------------------------------------------------------------------*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "lscsupport.h" +#include "fsm.h" +#include "initializer.h" + +typedef struct { + EaseDriv d; + float t; + float htr; +} Lsc370; + +static ParClass lsc370Class = { "LSC370", sizeof(Lsc370) }; + +/*----------------------------------------------------------------------------*/ +static void Lsc370ParDef(void *object) { + Lsc370 *drv = ParCast(&lsc370Class, object); + EaseBase *eab = object; + + ParName(""); ParTail("K"); + ParFloat(&drv->t, PAR_NAN); + + EaseBasePar(drv); + EaseSendPar(drv); + EaseDrivPar(drv, "%.5g", "K"); + ParStdDef(); + EaseMsgPar(drv); +} +/*----------------------------------------------------------------------------*/ +static long Lsc370Read(long pc, void *object) { + Lsc370 *drv = ParCast(&lsc370Class, object); + EaseBase *eab = object; + + switch (pc) { default: /* FSM BEGIN *******************************/ + EaseWrite(eab, "RDGK?1"); + return __LINE__; case __LINE__: /**********************************/ + drv->t = atof(eab->ans); + EaseWrite(eab, "HTR?"); + return __LINE__; case __LINE__: /**********************************/ + drv->htr = atof(eab->ans); + + ParLog(drv); + fsm_quit: return 0; } /* FSM END *********************************/ +} +/*----------------------------------------------------------------------------*/ +static long Lsc370Start(long pc, void *object) { + Lsc370 *drv = ParCast(&lsc370Class, object); + EaseBase *eab = object; + + switch (pc) { default: /* FSM BEGIN *******************************/ + EaseWrite(eab, "*IDN?"); + return __LINE__; case __LINE__: /**********************************/ + if (0 != strncmp(eab->version, "LSCI,MODEL370", 13)) { + snprintf(eab->msg, sizeof eab->msg, "unknown temperature controller version: %s", + eab->version); + ParPrintf(drv, eError, "ERROR: %s", eab->msg); + EaseStop(eab); + goto quit; + } + ParPrintf(drv, eStatus, "connected to %s", eab->version); + FsmCall(Lsc370Read); + return __LINE__; case __LINE__: /**********************************/ + + quit: + return 0; } /* FSM END ********************************************/ +} +/*----------------------------------------------------------------------------*/ +static long Lsc370Set(long pc, void *object) { + Lsc370 *drv = ParCast(&lsc370Class, object); + EaseBase *eab = object; + char cmd[32]; + int upd; + + switch (pc) { default: /* FSM BEGIN *******************************/ + upd = EaseNextUpdate(drv); + if (upd != EASE_RUN) goto quit; + EaseWrite(eab, "MODE 1:MODE?"); /* remote mode */ + return __LINE__; case __LINE__: /**********************************/ + snprintf(cmd, sizeof cmd, "SETP %.5g:SETP?", drv->d.targetValue); + EaseWrite(eab, cmd); + return __LINE__; case __LINE__: /**********************************/ + EaseWrite(eab, "MODE 0:MODE?"); /* local mode */ + quit: + return 0; } /* FSM END ********************************************/ +} +/*----------------------------------------------------------------------------*/ +static int Lsc370Init(SConnection *con, int argc, char *argv[], int dynamic) { + /* args: + MakeObject objectname lsc370 + MakeObject objectname lsc370 + */ + Lsc370 *drv; + + drv = EaseMakeDriv(con, &lsc370Class, argc, argv, dynamic, 7, + Lsc370ParDef, LscHandler, Lsc370Start, NULL, Lsc370Read, + Lsc370Set); + if (drv == NULL) return 0; + setRS232ReplyTerminator(drv->d.b.ser,"\n"); + setRS232SendTerminator(drv->d.b.ser,"\n"); + return 1; +} +/*----------------------------------------------------------------------------*/ +void Lsc370Startup(void) { + ParMakeClass(&lsc370Class, EaseDrivClass()); + MakeDriver("LSC370", Lsc370Init, 0, "LakeShore 370 AC Resistance Bridge"); +} diff --git a/lscsupport.c b/lscsupport.c new file mode 100644 index 0000000..5b165ce --- /dev/null +++ b/lscsupport.c @@ -0,0 +1,82 @@ +/*--------------------------------------------------------------------------- +lscsupport.c + +Communication routines for LakeShore equipment + +Markus Zolliker, July 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 +#include +#include +#include +#include +#include "sics.h" +#include "oxinst.h" + +/*----------------------------------------------------------------------------*/ +int LscHandler(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 (strncmp(eab->ans, "0,123",5) == 0 && eab->state == EASE_lost) { /* response to LOCK? */ + EaseWrite(eab, "*IDN?"); + goto quit; + } else if (eab->state == EASE_lost) { + goto quit; + } else if (strncmp(eab->cmd,"*IDN?",5) == 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, "LOCK?"); + eab->state = EASE_lost; + } + } + goto quit; +error: + /* EaseWriteError(eab); */ +quit: + return EaseHandler(eab); +} diff --git a/lscsupport.h b/lscsupport.h new file mode 100644 index 0000000..b3746f9 --- /dev/null +++ b/lscsupport.h @@ -0,0 +1,16 @@ +/*--------------------------------------------------------------------------- +lscsupport.h + +Communication routines for LakeShore equipment + +Markus Zolliker, July 2006 +----------------------------------------------------------------------------*/ + +#ifndef LSCSUPPORT_H +#define LSCSUPPORT_H + +#include "ease.h" + +int LscHandler(void *eab); + +#endif