- various improvements in SE drivers
This commit is contained in:
78
euro2kdriv.c
78
euro2kdriv.c
@ -32,6 +32,7 @@ Markus Zolliker, August 2005
|
||||
|
||||
#define EURO2K_SET 1
|
||||
#define EURO2K_MODE 2
|
||||
#define EURO2K_PAR 3
|
||||
|
||||
typedef enum {read_only, settable, to_set} Euro2kAccess;
|
||||
|
||||
@ -49,13 +50,17 @@ typedef struct Euro2kPar {
|
||||
typedef struct {
|
||||
EaseDriv d;
|
||||
char *unit;
|
||||
int mode, manual;
|
||||
int mode;
|
||||
char *script;
|
||||
int warned;
|
||||
float temperature;
|
||||
float output;
|
||||
float position;
|
||||
float range;
|
||||
float asymmetry;
|
||||
float setpoint;
|
||||
Euro2kPar *pars, *readPar;
|
||||
Statistics *stat;
|
||||
} Euro2k;
|
||||
|
||||
static ParClass euro2kClass = { "EURO2K", sizeof(Euro2k) };
|
||||
@ -68,7 +73,7 @@ static int Euro2kMakePar(void *object, void *userarg, int argc, char *argv[])
|
||||
int iarg;
|
||||
|
||||
assert(drv);
|
||||
if (argc < 1) goto Usage;
|
||||
if (argc < 2) goto Usage;
|
||||
last = &drv->pars;
|
||||
for (par = drv->pars; par != NULL; par = par->next) {
|
||||
if (strcasecmp(argv[0], par->name) == 0) {
|
||||
@ -155,11 +160,17 @@ void Euro2kParDef(void *object) {
|
||||
ParName("mode"); ParEnum(modeList); ParList(0); EaseUpdate(EURO2K_MODE);
|
||||
ParInt(&drv->mode, 1);
|
||||
|
||||
ParName("manual"); ParEnum(modeList);
|
||||
ParInt(&drv->manual, 1);
|
||||
|
||||
ParName("output"); ParTail("%");
|
||||
ParFloat(&drv->output, PAR_NAN);
|
||||
|
||||
ParName("position"); ParTail("%");
|
||||
ParFloat(&drv->position, PAR_NAN);
|
||||
|
||||
ParName("asymmetry"); ParAccess(usUser);
|
||||
ParFloat(&drv->asymmetry, PAR_NAN);
|
||||
|
||||
ParName("range"); ParAccess(usUser);
|
||||
ParFloat(&drv->range, PAR_NAN);
|
||||
|
||||
ParName("set"); ParTail(drv->unit); EaseUpdate(EURO2K_SET);
|
||||
ParFloat(&drv->setpoint, PAR_NAN);
|
||||
@ -206,7 +217,7 @@ void Euro2kParDef(void *object) {
|
||||
ParFmt(par->fmt);
|
||||
}
|
||||
if (par->set >= settable) {
|
||||
if (EaseUpdate(EURO2K_SET)) {
|
||||
if (EaseUpdate(EURO2K_PAR)) {
|
||||
par->set = to_set;
|
||||
}
|
||||
}
|
||||
@ -217,7 +228,7 @@ void Euro2kParDef(void *object) {
|
||||
ParName("makepar"); ParAccess(usUser); ParCmd(Euro2kMakePar, NULL);
|
||||
|
||||
EaseBasePar(drv);
|
||||
EaseDrivPar(drv, "%#.5g", drv->unit);
|
||||
EaseDrivPar(drv, "%.5g", drv->unit);
|
||||
ParStdDef();
|
||||
EaseMsgPar(drv);
|
||||
if (ParActionIs(PAR_KILL)) {
|
||||
@ -239,6 +250,9 @@ void Euro2kParDef(void *object) {
|
||||
free(par);
|
||||
}
|
||||
drv->pars = NULL;
|
||||
if (drv->stat) {
|
||||
StatisticsKill(drv->stat);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@ -249,13 +263,16 @@ static long Euro2kRead(long pc, void *object) {
|
||||
Tcl_Interp *pTcl = NULL;
|
||||
char *p;
|
||||
int l, m, iRet;
|
||||
float dif;
|
||||
float dif, a;
|
||||
char buf[4];
|
||||
|
||||
Statistics *old;
|
||||
|
||||
switch (pc) { default: /* FSM BEGIN *******************************/
|
||||
if (drv->script && drv->script[0] != '\0' && 0 != strcmp(drv->script, "0")) {
|
||||
pTcl = InterpGetTcl(pServ->pSics);
|
||||
old = StatisticsBegin(drv->stat);
|
||||
iRet = Tcl_Eval(pTcl,drv->script);
|
||||
StatisticsEnd(old);
|
||||
if (iRet == TCL_OK) {
|
||||
if (drv->warned > 0) drv->warned--;
|
||||
} else if (drv->warned<3) {
|
||||
@ -263,13 +280,18 @@ static long Euro2kRead(long pc, void *object) {
|
||||
ParPrintf(drv, eError, "ERROR: %s in %s.task '%s'", pTcl->result, eab->p.name, drv->script);
|
||||
}
|
||||
}
|
||||
ModBusRequestValue(eab, 273); /* get manual or auto */
|
||||
if (EaseGetUpdate(drv, EURO2K_MODE)) goto skipMode;
|
||||
ModBusRequestValue(eab, 273, modBusInt); /* get manual or auto */
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
m = ModBusGetValue(eab, modBusInt);
|
||||
if (m != drv->manual) { /* mode changed manually */
|
||||
drv->mode = m;
|
||||
if (!EaseGetUpdate(drv, EURO2K_MODE)) {
|
||||
m = ModBusGetValue(eab, modBusInt);
|
||||
if (m != drv->mode) { /* mode changed manually -> change disp */
|
||||
drv->mode = m;
|
||||
EaseSetUpdate(drv, EURO2K_MODE, 1);
|
||||
}
|
||||
}
|
||||
drv->manual= m;
|
||||
skipMode:
|
||||
|
||||
ModBusRequestFloats(eab, 1, 3);
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
drv->temperature = ModBusGetFloat(eab, 1);
|
||||
@ -277,11 +299,19 @@ static long Euro2kRead(long pc, void *object) {
|
||||
drv->setpoint = ModBusGetFloat(eab, 2);
|
||||
}
|
||||
drv->output = ModBusGetFloat(eab, 3);
|
||||
a = drv->output * eab->p.period / drv->range;
|
||||
if ((drv->position > 50.) == (drv->output > 0)) {
|
||||
drv->position += a * (1 - drv->asymmetry * 0.01);
|
||||
} else {
|
||||
drv->position += a * (1 + drv->asymmetry * 0.01);
|
||||
}
|
||||
if (drv->position < 0) drv->position = 0;
|
||||
if (drv->position > 100) drv->position = 100;
|
||||
par = drv->pars;
|
||||
loop:
|
||||
if (par == NULL) goto finish;
|
||||
if (par->adr == 0 || par->set == to_set) goto skipPar;
|
||||
ModBusRequestValue(eab, par->adr);
|
||||
ModBusRequestValue(eab, par->adr, par->type);
|
||||
drv->readPar = par;
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
par = drv->readPar;
|
||||
@ -333,8 +363,10 @@ static long Euro2kSet(long pc, void *object) {
|
||||
if (drv->mode == 0) goto loop;
|
||||
drv->mode = 0;
|
||||
mode:
|
||||
drv->manual = drv->mode;
|
||||
ModBusPutValue(eab, 273, 1, drv->manual); /* set manual to 0 */
|
||||
if (drv->mode) drv->mode = 1;
|
||||
ModBusPutValue(eab, 106, modBusInt, drv->mode*5); /* set display std or blank */
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
ModBusPutValue(eab, 273, modBusInt, drv->mode); /* set manual to 0 */
|
||||
setIt:
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
goto loop;
|
||||
@ -347,13 +379,17 @@ static long Euro2kStart(long pc, void *object) {
|
||||
EaseBase *eab = object;
|
||||
|
||||
switch (pc) { default: /* FSM BEGIN *******************************/
|
||||
ModBusRequestValue(eab, 1);
|
||||
ModBusRequestValue(eab, 1, modBusFloat);
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
if (0 == ModBusGetValue(eab, modBusFloat)) {
|
||||
ParPrintf(drv, eError, "bad or no response on ModBus");
|
||||
goto quit;
|
||||
}
|
||||
ParPrintf(drv, eStatus, "connected to euro2k");
|
||||
ModBusPutValue(eab, 111, modBusFloat, drv->d.upperLimit);
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
ModBusPutValue(eab, 112, modBusFloat, drv->d.lowerLimit);
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
FsmCall(Euro2kRead);
|
||||
return __LINE__; case __LINE__: /**********************************/
|
||||
|
||||
@ -367,19 +403,21 @@ static int Euro2kInit(SConnection *con, int argc, char *argv[], int dynamic) {
|
||||
<host> <port>
|
||||
*/
|
||||
Euro2k *drv;
|
||||
char sn[64];
|
||||
|
||||
drv = EaseMakeDriv(con, &euro2kClass, argc, argv, dynamic, 7,
|
||||
Euro2kParDef, ModBusHandler, Euro2kStart, NULL, Euro2kRead,
|
||||
Euro2kSet);
|
||||
if (drv == NULL) return 0;
|
||||
drv->pars = NULL;
|
||||
snprintf(sn, sizeof sn, "%s task", argv[1]);
|
||||
drv->stat = StatisticsNew(sn);
|
||||
setRS232ReplyTerminator(drv->d.b.ser,"");
|
||||
setRS232SendTerminator(drv->d.b.ser,"");
|
||||
ParPrintf(drv, eValue, "Eurotherm 2xxx");
|
||||
return 1;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void Euro2kStartup(void) {
|
||||
ParMakeClass(&euro2kClass, EaseDrivClass());
|
||||
MakeDriver("EURO2K", Euro2kInit, 0);
|
||||
MakeDriver("EURO2K", Euro2kInit, 0, "Eurotherm 2xxx");
|
||||
}
|
||||
|
Reference in New Issue
Block a user