diff --git a/arrobj.c b/arrobj.c index 6629a84..5b2c657 100644 --- a/arrobj.c +++ b/arrobj.c @@ -243,11 +243,11 @@ static void ArrayObjParDef(void *object) ArrayObj *arr = ParCast(&arrayObjClass, object); FILE *saveFile; ArrayItem *item, *next; - char *u; + char *u, *v; WrtObjContext context; static int doNotNest = 0; int saveObjects; - + saveFile = ParSaveFile(); if (!doNotNest && saveFile && arr->saveFile && *arr->saveFile) { saveObjects = WrtObjOpen(&context, arr->saveFile); @@ -261,8 +261,18 @@ static void ArrayObjParDef(void *object) } else { u = ""; } - fprintf(saveFile, " %s makeitem %s \"%s\" \"%s\"\n", arr->p.name, - item->name, item->value, u); + if (item->value) { + v = item->value; + } else { + v = ""; + } + if (strchr(v, '\n') != NULL) { + fprintf(saveFile, " %s makeitem %s {%s} \"%s\"\n", arr->p.name, + item->name, v, u); + } else { + fprintf(saveFile, " %s makeitem %s \"%s\" \"%s\"\n", arr->p.name, + item->name, v, u); + } if (saveObjects) { WrtObj(&context, item->name); } diff --git a/ease.c b/ease.c index 722c3a3..89528f2 100644 --- a/ease.c +++ b/ease.c @@ -934,11 +934,63 @@ void EaseMsgPar(void *object) int EaseRestartWrapper(void *object, void *userarg, int argc, char *argv[]) { EaseBase *eab = EaseBaseCast(object); - + char *colon; + char *hostpos; + int port, i; + char host[64], hostport[80]; + char *cCmd; + + /* short string with length 0 or 1: connect to previous host/port */ + if (argc > 0 && strlen(argv[0]) > 1) { + colon = strchr(argv[0], ':'); + if (!colon || argc > 1) { + ParPrintf(object, eError, "ERROR: illegal syntax for: %s restart", + eab->p.name); + return 0; + } + port = atoi(colon + 1); + i = colon - argv[0]; + if (i >= sizeof host) { + ParPrintf(object, eError, "ERROR: host name too long"); + return 0; + } + strncpy(host, argv[0], i); + host[i] = '\0'; + if (eab->p.creationCmd != NULL) { + hostpos = strstr(eab->p.creationCmd, eab->ser->pHost); + if (hostpos != NULL) { + /* replace the second part of creationCmd with new host/port */ + snprintf(hostport, sizeof hostport, "%s:%d", host, port); + hostpos[0]='\0'; + cCmd = calloc(1, strlen(eab->p.creationCmd) + strlen(hostport) + 1); + strcpy(cCmd, eab->p.creationCmd); + strcat(cCmd, hostport); + free(eab->p.creationCmd); + eab->p.creationCmd = cCmd; + } + } + if (eab->ser->pHost != NULL) { + free(eab->ser->pHost); + } + eab->ser->pHost = strdup(host); + eab->ser->iPort = port; + } + EaseStop(eab); EaseRestart(eab); return 0; } +/*----------------------------------------------------------------------------*/ +int EaseDisconnectWrapper(void *object, void *userarg, int argc, char *argv[]) +{ + EaseBase *eab = EaseBaseCast(object); + + ParPrintf(object, eWarning, "%s disabled (enable with: %s restart)", + eab->p.name, eab->p.name); + EaseStop(eab); + return 0; +} + /*----------------------------------------------------------------------------*/ void EaseBasePar(void *object) { @@ -950,6 +1002,10 @@ void EaseBasePar(void *object) ParAccess(usUser); ParCmd(EaseRestartWrapper, NULL); + ParName("disconnect"); + ParAccess(usUser); + ParCmd(EaseDisconnectWrapper, NULL); + if (ParActionIs(PAR_KILL)) { if (eab->ser) { KillRS232(eab->ser); diff --git a/euro2kdriv.c b/euro2kdriv.c index 1995c71..91730e7 100644 --- a/euro2kdriv.c +++ b/euro2kdriv.c @@ -63,6 +63,7 @@ typedef struct { Statistics *stat; double lastRd; char *model; + int rdonly; } Euro2k; static ParClass euro2kClass = { "EURO2K", sizeof(Euro2k) }; @@ -231,6 +232,11 @@ void Euro2kParDef(void *object) EaseUpdate(EURO2K_SET); ParFloat(&drv->setpoint, PAR_NAN); + ParName("rdonly"); + ParLogAs(NULL); + ParAccess(usUser); + ParInt(&drv->rdonly, 0); + ParName("task"); ParAccess(usUser); ParList(NULL); @@ -367,6 +373,11 @@ static long Euro2kRead(long pc, void *object) switch (pc) { default: /* FSM BEGIN ****************************** */ EasePchk(drv); + if (drv->rdonly) { + if (getTime() < drv->lastRd + 10) { + goto fsm_quit; + } + } if (drv->script && drv->script[0] != '\0' && 0 != strcmp(drv->script, "0")) { pTcl = InterpGetTcl(pServ->pSics); @@ -482,6 +493,8 @@ static long Euro2kSet(long pc, void *object) default: /* FSM BEGIN ****************************** */ EasePchk(drv); loop: + if (drv->rdonly) + goto fsm_quit; upd = EaseNextUpdate(drv); if (upd == EASE_RUN) { drv->setpoint = drv->d.targetValue; @@ -594,6 +607,8 @@ static long Euro2kStart(long pc, void *object) drv->unit = strdup("K"); } unitGiven: + if (drv->rdonly) + goto quit; ModBusPutValue(eab, 111, modBusFloat, drv->d.upperLimit); return __LINE__; case __LINE__: /**********************************/ diff --git a/pardef.c b/pardef.c index bf73daa..022e670 100644 --- a/pardef.c +++ b/pardef.c @@ -472,11 +472,13 @@ static int ParExecute(SConnection * con, SicsInterp * sics, void *object, if (argc >= 2 && 0 == strcasecmp(argv[1], "loggeditems")) { pDynString dyn = CreateDynString(124,128); for (info = o->infoList; info != NULL; info = info->next) { - if (info->log) { + if (info->log && (argc==2 || strcasecmp(argv[2], info->name) == 0)) { DynStringConcat(dyn, " "); DynStringConcat(dyn, argv[0]); - DynStringConcat(dyn, "."); - DynStringConcat(dyn, info->name); + if (info->name[0] != '\0') { + DynStringConcat(dyn, "."); + DynStringConcat(dyn, info->name); + } } } SCWrite(con, GetCharArray(dyn) + 1, eValue); @@ -1058,8 +1060,8 @@ void ParOut(char *buf) } else { p = ""; } - ParPrintf(NULL, eValue, "%s%s%s = %s", ctx->callName, p, ctx->parName, - buf); + ParPrintf(NULL, eValue, "%s%s%s = %s", ctx->callName, + p, ctx->parName, buf); break; case PAR_SET: if (ctx->parName[0]) { @@ -1100,8 +1102,13 @@ void ParOut(char *buf) } break; case PAR_SAVE: - fprintf(ctx->saveFile, " %s %s %s\n", ctx->obj->name, ctx->parName, - buf); + if (strchr(buf, '\n') != NULL) { + fprintf(ctx->saveFile, " %s %s {%s}\n", ctx->obj->name, + ctx->parName, buf); + } else { + fprintf(ctx->saveFile, " %s %s %s\n", ctx->obj->name, + ctx->parName, buf); + } break; default: break; diff --git a/tecs/make_crv b/tecs/make_crv index 371f586..d764413 100644 --- a/tecs/make_crv +++ b/tecs/make_crv @@ -374,6 +374,12 @@ $(CFGDIR)x55606.crv: ccrv inp/x55606.inp $(CFGDIR)x55918.crv: ccrv inp/x55918.inp $Q -p$(CFGDIR) +$(CFGDIR)x58599.crv: ccrv inp/x58599.inp + $Q -p$(CFGDIR) + +$(CFGDIR)x58600.crv: ccrv inp/x58600.inp + $Q -p$(CFGDIR) + $(CFGDIR)z030114.crv: ccrv inp/z030114.inp $Q -p$(CFGDIR) @@ -503,6 +509,8 @@ all_crv: dev.list \ $(CFGDIR)x51079.crv \ $(CFGDIR)x55606.crv \ $(CFGDIR)x55918.crv \ + $(CFGDIR)x58599.crv \ + $(CFGDIR)x58600.crv \ $(CFGDIR)z030114.crv \ ALLINP= \ @@ -631,5 +639,7 @@ inp/x50991.inp \ inp/x51079.inp \ inp/x55606.inp \ inp/x55918.inp \ +inp/x58599.inp \ +inp/x58600.inp \ inp/z030114.inp \ diff --git a/tecs/tecs.c b/tecs/tecs.c index 0593aaf..2e19c59 100644 --- a/tecs/tecs.c +++ b/tecs/tecs.c @@ -111,8 +111,9 @@ static Plug static float set, /* set T */ setH, /* set T on heat exchanger */ - set2, /* set T of seconds loop in two loop mode */ + set2, /* set T of second loop in two loop mode */ htr, power=DATA_UNDEF, /* heater current percentage, heater power */ + power2=DATA_UNDEF, /* heater2 power */ tLimit, /* temperature limit */ tMaxLimit, /* maximal temperature limit */ maxPowerFlt, /* max. Power */ @@ -220,7 +221,6 @@ static char static char *alarmList[N_SENSORS], /* enabled alarms */ - *table=NULL, /* environment devices table */ *cache=NULL, /* curve list cache */ *logfile=""; @@ -560,16 +560,6 @@ int InstalCurve(SensorT *sensor, char *devArg) { return -1; } -int ReadTable(void) { /* obsolete */ - char nbuf[256]; - if (table!=NULL) { FREE(table); table=NULL; }; - str_copy(nbuf, binDir); - str_append(nbuf, TABLE_FILE); - ERR_P(table=str_read_file(nbuf)); - return 1; - OnError: return -1; -} - void InitSensor(SensorT *s) { s->t=DATA_UNDEF; s->scale=1; @@ -584,10 +574,10 @@ void InitSensor(SensorT *s) { } int PrepInput(char *label) { - char *t, *e; - char nam[16], chans[8], typ; + char *t; + char nam[16], typ; char buf[256]; - int i, j, l; + int i, j; SensorT *s; char *cfg; @@ -602,14 +592,9 @@ again: str_append(buf, nam); str_append(buf, ".cfg"); cfg=str_read_file(buf); - if (cfg==NULL) { /* will be obsolete */ - logfileOut(LOG_MAIN, "%s not found, try tecs.cfg\n", buf); - ERR_I(ReadTable()); - t=strstr(table, label); - if (t==NULL) ERR_MSG("device not found"); - e=strchr(t, '\''); - if (e==NULL || e>strchr(t,'\n')) ERR_MSG("missing ' or device name in table file"); - t=e+1; + if (cfg==NULL) { + logfileOut(LOG_MAIN, "%s not found\n", buf); + ERR_MSG("device not found"); } if (cfg && *cfg=='@') { /* alias */ t=strchr(cfg,'\n'); @@ -641,35 +626,30 @@ again: resist=10; nScan=0; unit=1; + empty=0; + full = -1; } else { InitSensor(&sensC); - InitSensor(&sensD); + if (strcasecmp(nam, "none") == 0) { + /* exception: he sensor is not cleared when stick is none */ + if (full < 0 || sensB.type[0]=='\0' || sensD.type[0] != 'h') { + InitSensor(&sensD); + } + } else { + empty = 0; + full = -1; + InitSensor(&sensD); + } } for (i=5;i<9;i++) { InitSensor(sensors[i]); } - empty=0; dev[0]='\0'; str_copy(heUnits, "%"); - if (cfg==NULL) { /* will be obsolete */ - i=sscanf(t, "%12s%n", nam, &l); - if (i<1) ERR_MSG("missing device name"); - nam[strlen(nam)-1]='\0'; /* strip off quote */ - t+=l; - str_copy(chans, "____"); - i=sscanf(t, "%8s%n", chans, &l); - if (i<1) ERR_MSG("missing chans"); - t+=l; - - /* interprete settings until '+' appeares (after whitespace) */ - ERR_P(CocReadVars(t, '+')); - if (strlen(chans)>4) ERR_MSG("no more than 4 channels allowed"); - } else { - ERR_P(CocReadVars(cfg, '\0')); - } + ERR_P(CocReadVars(cfg, '\0')); if (loop!=2) loop=1; if (plug==&plug0) { @@ -678,16 +658,6 @@ again: j=2; } str_copy(plug->descr, dev); - if (cfg==NULL) { /* will be obsolete */ - sensA.type[0]=chans[0]; - sensA.type[1]='\0'; - sensB.type[0]=chans[1]; - sensB.type[1]='\0'; - sensC.type[0]=chans[2]; - sensC.type[1]='\0'; - sensD.type[0]=chans[3]; - sensD.type[1]='\0'; - } if (sensA.type[0]>'0' && sensA.type[0]<='4') { nScan=sensA.type[0]-'0'; for (i=5;i<5+nScan;i++) { @@ -713,6 +683,7 @@ again: } maxPowerFlt=25; sscanf(maxPower, "%f", &maxPowerFlt); + for (i=j; itype[0]; @@ -1257,13 +1228,19 @@ int ReadHeater(int full) { static int cntOff=3; time_t now; + power2 = DATA_UNDEF; if (loop==1) { if (full) { if (relay) { ERR_P(LscCmd(ser, "HTRST?>htrst")); htr=0; } else { - ERR_P(LscCmd(ser, "HTR?>htr;HTRST?>htrst;RELAYST?1>relay;RANGE?>ibuf")); + if (twoloops) { + ERR_P(LscCmd(ser, "HTR?>htr;HTRST?>htrst;RELAYST?1>relay;RANGE?>ibuf;AOUT?2>fbuf")); + power2 = fbuf*fbuf*1e-5; + } else { + ERR_P(LscCmd(ser, "HTR?>htr;HTRST?>htrst;RELAYST?1>relay;RANGE?>ibuf")); + } if (jRange!=0 && ibuf==0) { if (swRangeOn) { time(&now); @@ -1404,7 +1381,7 @@ int SetTemp(int switchOn) { } } ERR_P(LscCmd(ser, "SETP?[loop]>fbuf")); - if (fabsf(setH-fbuf) >= (fbuf+setH)*1.0e-5) { + if (fabsf(setH-fbuf) >= (fbuf+setH)*1.0e-5 || twoloops) { ERR_P(LscCmd(ser, "SETP [loop]:[setH]")); if (twoloops) { ERR_P(LscCmd(ser, "SETP 2:[set2]")); @@ -1989,12 +1966,8 @@ int ConfigByName(int plugNr) { logfileOut(LOG_MAIN+LOG_STAT ,"configure plug%d for %s\n", plugNr, plug->device); plug->sensor1->present=0; plug->sensor2->present=0; - if (0!=strcmp(plug->device, "none")) { - sprintf(buf, "'%s'", plug->device); - ERR_I(PrepInput(buf)); - } else { - plug->descr[0]='\0'; - } + sprintf(buf, "'%s'", plug->device); + ERR_I(PrepInput(buf)); settingsFlag=1; return 0; OnError: @@ -3439,6 +3412,7 @@ int main(int argc, char *argv[]) { CocDefFlt(ramp, RW); CocHdl(SetHdl); CocDefFlt(still, RW); CocHdl(StillHdl); CocDefFlt(power, RW); CocHdl(PowerHdl); + CocDefFlt(power2, RD); CocDefFlt(mout, RW); CocHdl(MoutHdl); CocDefFlt(tLimit, RW); CocHdl(TLimitHdl); CocDefFlt(tMaxLimit, RD); @@ -3682,6 +3656,7 @@ int main(int argc, char *argv[]) { ERR_P(DataCreateSet(NULL, "T4", &sensA4.t, logPeriod, LOGLIFETIME, tim)); ERR_P(DataCreateSet(NULL, "Aux", &aux, logPeriod, LOGLIFETIME, tim)); ERR_P(DataCreateSet(NULL, "P", &power, logPeriod, LOGLIFETIME, tim)); + ERR_P(DataCreateSet(NULL, "power2", &power2, logPeriod, LOGLIFETIME, tim)); ERR_P(DataCreateSet(NULL, "ScanChan", &scanChan, logPeriod, LOGLIFETIME, tim)); DataUndef(0); ERR_P(DataCreateSet(NULL, "Set", &set, logPeriod, LOGLIFETIME, tim));