new version of drivers (based on ease instead of eve)

This commit is contained in:
zolliker
2005-09-05 08:00:35 +00:00
parent 22fa164b76
commit 2cca4ba7f0
4 changed files with 1415 additions and 635 deletions

215
ilmdriv.c
View File

@ -2,10 +2,10 @@
ilmdriv.c
Driver for the Oxford Instruments ILM503/ILM4 temperature controller
and for the Oxford lambda controller
Version 2 (based on ease).
Markus Zolliker, Sept 2004
----------------------------------------------------------------------------*/
Markus Zolliker, April 2005
------------------------------------------------------------------------------*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
@ -20,126 +20,169 @@ Markus Zolliker, Sept 2004
#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 "oicom.h"
#include "oxinst.h"
#include "fsm.h"
#include "initializer.h"
typedef enum { ALWAYSNEW, NEW, MEASURING, NOTYETREAD, OLD } ReadState;
typedef enum { UNUSED, N2, PULSED_HE, CONTINOUS_HE, CHANNEL_ERROR = 9 } Usage;
typedef struct {
Eve eve;
float lev2, lev3;
int cod1, cod2, cod3;
} IlmDriv;
EaseBase b;
float lev[3];
Usage usage[3];
ReadState readState[3];
} Ilm;
char *fmts[10]={"unused", "%.1f\t%% N2", "%.1f\t%% He","%.1f\t%% He","",
"","","","","error"};
static ParClass ilmClass = { "ILM", sizeof(Ilm) };
char *tails[10]={"unused", "% N2", "% He","% He","","","","","","error"};
/*----------------------------------------------------------------------------*/
#define A EVE_ACTPAR
#define L EVE_LOGPAR
#define S EVE_EVE_SAVEPAR
static void IlmParDef(void *object) {
Ilm *drv = ParCast(&ilmClass, object);
void IlmPars(IlmDriv *me, EveParArg *arg) {
EveFloatPar(arg, "chan2", &me->lev2, fmts[me->cod2],
usInternal, (me->cod2 > 0) * A + L);
EveFloatPar(arg, "chan3", &me->lev2, fmts[me->cod3],
usInternal, (me->cod3 > 0) * A + L);
EveStdParEnd(arg, fmts[me->cod1], A+L);
ParName("");
if (drv->usage[0]) {
ParFmt("%.1f"); ParTail(tails[drv->usage[0]]);
}
if (drv->readState[0] == NEW) {
ParLogReady(PAR_NOW_READY);
}
ParFloat(&drv->lev[0], PAR_NAN);
ParName("lev2");
if (drv->usage[1]) {
ParFmt("%.1f"); ParTail(tails[drv->usage[1]]);
};
if (drv->readState[1] == NEW) ParLogReady(PAR_NOW_READY);
ParFloat(&drv->lev[1], PAR_NAN);
ParName("lev3");
if (drv->usage[2]) {
ParFmt("%.1f"); ParTail(tails[drv->usage[2]]);
}
if (drv->readState[2] == NEW) ParLogReady(PAR_NOW_READY);
ParFloat(&drv->lev[2], PAR_NAN);
EaseBasePar(drv);
EaseSendPar(drv);
ParStdDef();
EaseMsgPar(drv);
}
/*----------------------------------------------------------------------------*/
void IlmStatus(IlmDriv *me) {
static void IlmStatus(Ilm *drv) {
char *ans;
int *code;
Eve *eve=&me->eve;
int i;
int status;
if (eve->state != readState) return;
ans=eve->ans;
code=&eve->errCode;
if (drv->b.state != EASE_read) return;
ans=drv->b.ans;
code=&drv->b.errCode;
if (ans[0] != 'X' || ans[4] != 'S' || ans[11] != 'R') {
EvePrintf(eve, eError, "illegal status response");
*code = EVE_FAULT;
ParPrintf(drv, eError, "illegal status response");
*code = EASE_FAULT;
return;
}
for (i=1; i<3; i++) {
if (ans[i]<'0' || ans[i] > '9') ans[i]='9';
for (i=0; i<3; i++) {
if (ans[i+1]<'0' || ans[i+1] > '9') {
ans[i+1]='9';
}
drv->usage[i] = ans[i+1] - '0';
if (drv->usage[i] == PULSED_HE) {
sscanf(ans+6+2*i, "%1x", &status);
if (status & 1) { /* measuring */
drv->readState[i] = MEASURING;
} else if (drv->readState[i] == MEASURING) { /* new value */
drv->readState[i] = NOTYETREAD;
}
} else {
drv->readState[i] = ALWAYSNEW;
}
}
me->cod1 = ans[1]-'0';
me->cod2 = ans[2]-'0';
me->cod3 = ans[3]-'0';
return;
}
/*----------------------------------------------------------------------------*/
static int IlmRead(long pc, IlmDriv *me) {
Eve *eve=&me->eve;
static long IlmRead(long pc, void *object) {
Ilm *drv = ParCast(&ilmClass, object);
EaseBase *eab = object;
int i;
FSM_BEGIN
EveWrite(eve, "X");
FSM_NEXT
IlmStatus(me); /* check for errors */
EveWrite(eve, "R1"); /* read sensor 1 */
FSM_NEXT
me->eve.value = OiGetFlt(eve, 1, NULL);
if (me->cod2 == 0) goto skip2;
EveWrite(eve, "R2"); /* read sensor 1 */
FSM_NEXT
me->lev2 = OiGetFlt(eve, 1, NULL);
switch (pc) { default: /* FSM BEGIN *******************************/
EaseWrite(eab, "X");
return __LINE__; case __LINE__: /**********************************/
IlmStatus(drv); /* check for errors */
EaseWrite(eab, "R1"); /* read sensor 1 */
return __LINE__; case __LINE__: /**********************************/
if (drv->readState[0] != MEASURING) drv->lev[0] = OxiGet(eab, 1, NULL);
if (drv->readState[0] == NOTYETREAD) drv->readState[0] = NEW;
if (drv->usage[1] == 0) goto skip2;
EaseWrite(eab, "R2"); /* read sensor 2 */
return __LINE__; case __LINE__: /**********************************/
drv->lev[1] = OxiGet(eab, 1, NULL);
if (drv->readState[1] == NOTYETREAD) drv->readState[1] = NEW;
skip2:
if (me->cod3 == 0) goto skip3;
EveWrite(eve, "R3"); /* read sensor 1 */
FSM_NEXT
me->lev3 = OiGetFlt(eve, 1, NULL);
if (drv->usage[2] == 0) goto skip3;
EaseWrite(eab, "R3"); /* read sensor 3 */
return __LINE__; case __LINE__: /**********************************/
drv->lev[2] = OxiGet(eab, 1, NULL);
if (drv->readState[2] == NOTYETREAD) drv->readState[2] = NEW;
skip3:
FSM_END
if (ParLog(drv) >= 0) { /* logging was done */
for (i=0; i<3; i++) {
if (drv->readState[i] == NEW) {
drv->readState[i] = OLD;
}
}
}
return 0; } /* FSM END ********************************************/
}
/*----------------------------------------------------------------------------*/
static int IlmStart(long pc, IlmDriv *me) {
Eve *eve=&me->eve;
static long IlmStart(long pc, void *object) {
Ilm *drv = ParCast(&ilmClass, object);
EaseBase *eab = object;
FSM_BEGIN
EveWrite(eve, "V");
FSM_NEXT
if (0 == strncmp(eve->version, "ILM", 3)) {
me->eve.syntax = 0;
} else {
EvePrintf(eve, eError, "unknown level meter version: %s", eve->version);
switch (pc) { default: /* FSM BEGIN *******************************/
EaseWrite(eab, "V");
return __LINE__; case __LINE__: /**********************************/
if (0 != strncmp(eab->version, "ILM", 3)) {
snprintf(eab->msg, sizeof eab->msg, "unknown level meter version: %s", eab->version);
ParPrintf(drv, eError, "ERROR: %s", eab->msg);
EaseStop(eab);
goto quit;
}
EvePrintf(eve, eStatus, "connected to %s", eve->version);
FSM_CALL(IlmRead);
ParPrintf(drv, eStatus, "connected to %s", eab->version);
eab->msg[0]='\0'; /* o.k. */
FsmCall(IlmRead);
return __LINE__; case __LINE__: /**********************************/
quit:
FSM_END
return 0; } /* FSM END ********************************************/
}
/*------------------------------------------------------------------------*/
pEVControl IlmMakeEVC(SConnection *pCon, int argc, char *argv[]) {
/*----------------------------------------------------------------------------*/
static int IlmInit(SConnection *con, int argc, char *argv[], int dynamic) {
/* args:
temperature ilm <rs232>
<host> <port>
MakeObject objectname ilm <rs232>
<host> <port>
*/
Eve *eve;
pEVControl evc;
IlmDriv *me = NULL;
Ilm *drv;
evc = MakeEveEVC(argc, argv, calloc(1, sizeof *me), pCon);
if (!evc) return NULL;
me = evc->pDriv->pPrivate;
eve=&me->eve;
eve->run = NULL; /* no run possible */
eve->read = (FsmFunc)IlmRead;
eve->pardef = (EveParDef)IlmPars;
eve->todo = (FsmFunc)IlmStart;
eve->task = FsmStartTask(me, (FsmHandler)OiHandler, (FsmFunc)EveIdle);
evc->pEnvir->IsInTolerance = EveAlwaysOk;
return evc;
drv = EaseMakeBase(con, &ilmClass, argc, argv, dynamic, 0,
IlmParDef, OxiHandler, IlmStart, NULL, IlmRead);
if (drv == NULL) return 0;
ParPrintf(drv, eValue, "OI Level Meter");
return 1;
}
/*----------------------------------------------------------------------------*/
void IlmStartup(void) {
ParMakeClass(&ilmClass, EaseBaseClass());
MakeDriver("ILM", IlmInit, 0);
}