minor changes in tecs (M.Z.)

This commit is contained in:
cvs
2001-04-27 08:48:58 +00:00
parent e5e594d3af
commit 87bea26315
5 changed files with 193 additions and 59 deletions

View File

@ -45,7 +45,7 @@ typedef struct {
int dirty; /* input config to be reloaded */ int dirty; /* input config to be reloaded */
int try; /* trial count */ int try; /* trial count */
int manual; /* manual device */ int manual; /* manual device */
int code, code1; /* device code, buffer for device code */ int code, code1, code2; /* device code, buffer for device code */
int codChanged; /* code has changed */ int codChanged; /* code has changed */
int codDefined; /* code is not yet confirmed */ int codDefined; /* code is not yet confirmed */
float scale; /* scale for extreme ranges */ float scale; /* scale for extreme ranges */
@ -70,6 +70,7 @@ static float
full, /* full value for helium level */ full, /* full value for helium level */
prop, integ, deriv, /* pid */ prop, integ, deriv, /* pid */
maxShift=2, /* maximal shift in when controlMode=2 */ maxShift=2, /* maximal shift in when controlMode=2 */
fbuf, /* float buffer */
tInt=0; /* integral time (sec.) for setpoint shift */ tInt=0; /* integral time (sec.) for setpoint shift */
static int static int
@ -97,10 +98,12 @@ static int
configuring=1, configuring=1,
stable, /* stable since 2 min. */ stable, /* stable since 2 min. */
resist, /* heater resistance */ resist, /* heater resistance */
cmode=1, /* 1: manual PID, 5: auto PI */
readTemp, /* client requested readTemp */ readTemp, /* client requested readTemp */
cod1, cod2, out1, out2, /* codes read from digital input/output */ cod1, cod2, out1, out2, /* codes read from digital input/output */
iRange, iAmp, /* max. range and max. current code */ iRange, iAmp, /* max. range and max. current code */
htrst, htrst0, /* heater status */ htrst, htrst0, /* heater status */
tuning=0,
per; /* effective period */ per; /* effective period */
static time_t static time_t
@ -111,7 +114,7 @@ static time_t
static int decod[8]={21,20,17,16,5,4,1,0}; /* for code conversion */ static int decod[8]={21,20,17,16,5,4,1,0}; /* for code conversion */
static char static char
status[132], /* status buffer */ status[160], /* status buffer */
device[64], /* concatenated device names */ device[64], /* concatenated device names */
buf1[256], buf2[256], buf3[256], buf4[256], /* buffers for temporary use */ buf1[256], buf2[256], buf3[256], buf4[256], /* buffers for temporary use */
head[64], /* curve header */ head[64], /* curve header */
@ -287,8 +290,12 @@ int instCurve(char *nam, char *channel, int dispFld) {
if (head[0]!='\0' && LscEqPar(head, chead)) { /* header matches: select sensor type and curve */ if (head[0]!='\0' && LscEqPar(head, chead)) { /* header matches: select sensor type and curve */
retstat=-1; /* an error could be fixed */ retstat=-1; /* an error could be fixed */
ERR_P(LscCmd(ser, "RANGE:0;INTYPE [chan]:[intype];INCRV [chan]:[num]")); ERR_P(LscCmd(ser, "RANGE:0"));
ERR_P(LscCmd(ser, "MNMX [chan]:1,1;DISPFLD [fld],[chan],1;DISPLAY [maxfld]")); ERR_P(LscCmd(ser, "INTYPE [chan]:[intype]"));
ERR_P(LscCmd(ser, "INCRV [chan]:[num]"));
ERR_P(LscCmd(ser, "MNMX [chan]:1,1"));
ERR_P(LscCmd(ser, "DISPFLD [fld],[chan],1"));
ERR_P(LscCmd(ser, "DISPLAY [maxfld]"));
logfileOut(LOG_MAIN, "curve %d on channel %s selected\n", num, chan); logfileOut(LOG_MAIN, "curve %d on channel %s selected\n", num, chan);
Progress(100); Progress(100);
@ -300,7 +307,9 @@ int instCurve(char *nam, char *channel, int dispFld) {
if (busy) ERR_MSG("busy"); if (busy) ERR_MSG("busy");
logfileOut(LOG_MAIN, "download curve %d\n", num); logfileOut(LOG_MAIN, "download curve %d\n", num);
/* select sensor type first to display sensor units */ /* select sensor type first to display sensor units */
ERR_P(LscCmd(ser, "RANGE:0;INTYPE [chan]:[intype];DISPLAY:[maxfld]")); ERR_P(LscCmd(ser, "RANGE:0"));
ERR_P(LscCmd(ser, "INTYPE [chan]:[intype]"));
ERR_P(LscCmd(ser, "DISPLAY:[maxfld]"));
Progress(1); Progress(1);
n=3; n=3;
@ -328,8 +337,11 @@ int instCurve(char *nam, char *channel, int dispFld) {
/* write header, select curve */ /* write header, select curve */
str_upcase(head, chead); str_upcase(head, chead);
ERR_P(LscCmd(ser, "CRVHDR [num]:[head];INCRV [chan]:[num]")); ERR_P(LscCmd(ser, "CRVHDR [num]:[head]"));
ERR_P(LscCmd(ser, "MNMX [chan]:1,1;DISPFLD [fld],[chan],1;DISPLAY [maxfld]")); ERR_P(LscCmd(ser, "INCRV [chan]:[num]"));
ERR_P(LscCmd(ser, "MNMX [chan]:1,1"));
ERR_P(LscCmd(ser, "DISPFLD [fld],[chan],1"));
ERR_P(LscCmd(ser, "DISPLAY [maxfld]"));
Progress(1); Progress(1);
logfileOut(LOG_MAIN, "curve selected on channel %s\n", chan); logfileOut(LOG_MAIN, "curve selected on channel %s\n", chan);
saveTime=tim+30; saveTime=tim+30;
@ -418,6 +430,7 @@ int configInput(void) {
i=sscanf(t, "%12s%n", nam, &l); i=sscanf(t, "%12s%n", nam, &l);
if (i<1) ERR_MSG("missing device name"); if (i<1) ERR_MSG("missing device name");
nam[strlen(nam)-1]='\0'; /* strip off quote */
t+=l; t+=l;
/* interprete settings until '+' appeares */ /* interprete settings until '+' appeares */
@ -437,11 +450,12 @@ int configInput(void) {
} else { } else {
if (!samp.manual && (NULL!=strchr(chanS,'A') || NULL!=strchr(chanS,'B'))) { if (!samp.manual && (NULL!=strchr(chanS,'A') || NULL!=strchr(chanS,'B'))) {
samp.dirty=1; /* sample and heat exchanger are on main plug */ samp.dirty=1; /* sample and heat exchanger are on main plug */
samp.code=cryo.code; samp.manual=1;
str_copy(samp.device, nam);
} }
str_copy(ch, chanM); str_copy(ch, chanM);
if (heliumMode==0) { if (heliumMode==0) {
sprintf(helium, "no He-level meter for '%s", nam); sprintf(helium, "no He-level meter for %s", nam);
} else { } else {
sprintf(helium, "He-level meter not yet read", nam); sprintf(helium, "He-level meter not yet read", nam);
} }
@ -451,7 +465,6 @@ int configInput(void) {
if (n==0) return(0); if (n==0) return(0);
if (n>2) ERR_MSG("no more than 2 channels per plug allowed"); if (n>2) ERR_MSG("no more than 2 channels per plug allowed");
nam[strlen(nam)-1]='\0'; /* strip off quote */
if (!tpoint->manual) { /* set device name */ if (!tpoint->manual) { /* set device name */
str_copy(tpoint->device, nam); str_copy(tpoint->device, nam);
concatDevice(); concatDevice();
@ -470,10 +483,11 @@ int configInput(void) {
str_copy(chan, ch+1); str_copy(chan, ch+1);
logfileOut(LOG_MAIN, "auxilliary input on channel %s\n", chan); logfileOut(LOG_MAIN, "auxilliary input on channel %s\n", chan);
if (ch[0]>'b') { if (ch[0]>'b') {
ERR_P(LscCmd(ser, "INTYPE [chan]:0,1,2,1,13;MNMX [chan]:1,3")); ERR_P(LscCmd(ser, "INTYPE [chan]:0,1,2,1,13"));
} else { } else {
ERR_P(LscCmd(ser, "INTYPE [chan]:0,1,2,1,12;MNMX [chan]:1,3")); ERR_P(LscCmd(ser, "INTYPE [chan]:0,1,2,1,12"));
} }
ERR_P(LscCmd(ser, "MNMX [chan]:1,3"));
tpoint->sensor2->present=2; tpoint->sensor2->present=2;
} else { } else {
if (ch[1]<'A' || ch[1]>'D') ERR_MSG("illegal channel"); if (ch[1]<'A' || ch[1]>'D') ERR_MSG("illegal channel");
@ -615,17 +629,17 @@ int ReadTemp(void) {
for (i=1; i<=4; i++) { for (i=1; i<=4; i++) {
sensor=sensors[i]; sensor=sensors[i];
if (sensor->present) { if (sensor->present) {
stat=(sensor->stat1 | sensor->stat2) & 255; stat=(sensor->stat1 | sensor->stat2) & (255-2); /* ignore old reading */
if (stat != sensor->readStat) { if (stat != sensor->readStat) {
sensor->readStat=stat; sensor->readStat=stat;
if (stat & 1) logfileOut(LOG_MAIN, "invalid reading %s\n", sensor->ch); if (stat & 1) logfileOut(LOG_MAIN, "invalid reading %s\n", sensor->ch);
if (stat & 2) logfileOut(LOG_MAIN, "old reading %s\n", sensor->ch); /* if (stat & 2) logfileOut(LOG_MAIN, "old reading %s\n", sensor->ch); */
if (stat & 12) logfileOut(LOG_MAIN, "unknown reading status %s\n", sensor->ch); if (stat & 12) logfileOut(LOG_MAIN, "unknown reading status %s\n", sensor->ch);
if (stat & 16) logfileOut(LOG_MAIN, "temp underrange %s\n", sensor->ch); if (stat & 16) logfileOut(LOG_MAIN, "temp underrange %s\n", sensor->ch);
if (stat & 32) logfileOut(LOG_MAIN, "temp overrange %s\n", sensor->ch); if (stat & 32) logfileOut(LOG_MAIN, "temp overrange %s\n", sensor->ch);
if (stat & 64) logfileOut(LOG_MAIN, "units zero %s\n", sensor->ch); if (stat & 64) logfileOut(LOG_MAIN, "units zero %s\n", sensor->ch);
if (stat &128) logfileOut(LOG_MAIN, "units overrange %s\n", sensor->ch); if (stat &128) logfileOut(LOG_MAIN, "units overrange %s\n", sensor->ch);
if (stat==0) logfileOut(LOG_MAIN, "reading o.k. %s\n", sensor->ch); if (stat==0) logfileOut(LOG_MAIN, "reading o.k. %s\n", sensor->ch);
} }
if (stat==0) { if (stat==0) {
@ -635,7 +649,7 @@ int ReadTemp(void) {
sensor->t = (sensor->t1 + sensor->t2) * 0.5; /* mean of min and max */ sensor->t = (sensor->t1 + sensor->t2) * 0.5; /* mean of min and max */
sensor->band = sensor->band/2; sensor->band = sensor->band/2;
} else { /* probably noisy values */ } else { /* probably noisy values */
logfileOut(LOG_MAIN, "min/max %s: %f %f\n", sensor->ch, sensor->t1, sensor->t2); /* logfileOut(LOG_MAIN, "min/max %s: %f %f\n", sensor->ch, sensor->t1, sensor->t2); */
if (fabs(sensor->t1 - sensor->t) < fabs(sensor->t2 - sensor->t) ) { if (fabs(sensor->t1 - sensor->t) < fabs(sensor->t2 - sensor->t) ) {
sensor->t=sensor->t1; sensor->t=sensor->t1;
sensor->t2 = sensor->t1; sensor->t2 = sensor->t1;
@ -723,14 +737,29 @@ int SetTemp(int switchOn) {
tempH=(tempC+tShift)/scale; tempH=(tempC+tShift)/scale;
if (tempH>tLimit) tempH=tLimit; if (tempH>tLimit) tempH=tLimit;
if (tempC==0) { if (tempC==0) {
ERR_P(LscCmd(ser, "CSET 1:[chan],1,1,0;RANGE:0;SETP 1:0")); ERR_P(LscCmd(ser, "CSET 1:[chan],1,1,0"));
ERR_P(LscCmd(ser, "RANGE:0"));
tempH=0;
} else if (remoteMode==1) { /* in local mode: do not switch on heater */ } else if (remoteMode==1) { /* in local mode: do not switch on heater */
ERR_P(LscCmd(ser, "SETP 1:[tempH]"));
ch=controlChannel; ch=controlChannel;
} else if (switchOn || (htrst>=5 && relay==0)) { /* switch on also when bad heater message and no alarms */ } else if (switchOn) { /* switch on also when bad heater message and no alarms: || (htrst>=5 && relay==0)) */
ERR_P(LscCmd(ser, "CSET 1:[chan],1,1,0;RANGE:[iRange];SETP 1:[tempH]")); ERR_P(LscCmd(ser, "CSET 1:[chan],1,1,0"));
ERR_P(LscCmd(ser, "RANGE:[iRange]"));
ERR_P(LscCmd(ser, "CMODE 1:[cmode]"));
if (cmode>=4) {
ERR_P(LscCmd(ser, "PID?1>prop,integ,deriv"));
logfileOut(LOG_MAIN, "PID %f,%f,%f\n", prop, integ, deriv);
tuning=2;
}
} else { } else {
ERR_P(LscCmd(ser, "CSET 1:[chan],1;SETP 1:[tempH]")); ERR_P(LscCmd(ser, "CSET 1:[chan],1"));
}
ERR_P(LscCmd(ser, "SETP?1>fbuf"));
if (tempH==0 || fbuf/tempH<0.9999 || fbuf/tempH>1.0001) {
ERR_P(LscCmd(ser, "SETP 1:[tempH]"));
if (controlMode!=2 && !switchOn) {
logfileOut(LOG_MAIN, "set %f (on %s) (was changed)\n", tempC, ch);
}
} }
if (0!=strcmp(ch, controlChannel) || switchOn) { if (0!=strcmp(ch, controlChannel) || switchOn) {
str_copy(controlChannel, ch); str_copy(controlChannel, ch);
@ -747,12 +776,17 @@ int PeriodicTask(void) {
time_t putTim; time_t putTim;
float t3[3], p, d, w, t; float t3[3], p, d, w, t;
ERR_P(LscCmd(ser, "DIOST?>cod1,out1;DOUT 3,29;HTR?>htr;HTRST?>htrst;RELAYST?1>relay;BUSY?>busy")); ERR_P(LscCmd(ser, "DIOST?>cod1,out1"));
if (cryo.codDefined && samp.codDefined) { if (cryo.codDefined && samp.codDefined) {
per=period; /* no timeout on above command and codes are defined: normal period */ per=period; /* no timeout on above command and codes are defined: normal period */
if (per>logPeriod*1000) per=logPeriod*1000; if (per>logPeriod*1000) per=logPeriod*1000;
} }
ERR_P(LscCmd(ser, "DOUT 3,29"));
ERR_P(LscCmd(ser, "HTR?>htr"));
ERR_P(LscCmd(ser, "HTRST?>htrst"));
ERR_P(LscCmd(ser, "RELAYST?1>relay;BUSY?>busy"));
if (noResp) { /* there was no response on an earlier command, or we are initializing */ if (noResp) { /* there was no response on an earlier command, or we are initializing */
if (!configuring) remoteMode=2; if (!configuring) remoteMode=2;
LscCmd(ser, "MODE:[remoteMode]"); LscCmd(ser, "MODE:[remoteMode]");
@ -798,7 +832,7 @@ int PeriodicTask(void) {
if (cryo.code!=0) str_copy(cryo.device, buf1); if (cryo.code!=0) str_copy(cryo.device, buf1);
cryo.manual=0; cryo.manual=0;
} }
if (buf2[0]=='*') { if (buf2[0]=='*' && buf2[1]!='\0') {
str_copy(samp.device, buf2+1); str_copy(samp.device, buf2+1);
samp.manual=1; samp.manual=1;
} else { } else {
@ -860,6 +894,11 @@ int PeriodicTask(void) {
i=0; i=0;
if (sens1.present) { if (sens1.present) {
t3[0]=cryo.temp; t3[0]=cryo.temp;
/*
if (cryo.temp==0) {
logfileOut(LOG_MAIN, "zero??\n");
}
*/
i=1; i=1;
} else { } else {
t3[0]=undef; t3[0]=undef;
@ -907,7 +946,9 @@ int PeriodicTask(void) {
} }
} }
ERR_P(LscCmd(ser, "KEYST?>key;DIOST?>cod2,out2;DOUT 3,30")); ERR_P(LscCmd(ser, "KEYST?>key"));
ERR_P(LscCmd(ser, "DIOST?>cod2,out2"));
ERR_P(LscCmd(ser, "DOUT 3,30"));
if (busy==0) { if (busy==0) {
if (out1!=30) { if (out1!=30) {
@ -916,7 +957,8 @@ int PeriodicTask(void) {
} }
if (out2!=29) { if (out2!=29) {
ERR_P(LscCmd(ser, "DOUT:3,29")); ERR_P(LscCmd(ser, "DOUT:3,29"));
ERR_P(LscCmd(ser, "DIOST?>cod2,out2;DOUT 3,30")); ERR_P(LscCmd(ser, "DIOST?>cod2,out2"));
ERR_P(LscCmd(ser, "DOUT 3,30"));
} }
if (out1==30 && out2==29) { if (out1==30 && out2==29) {
@ -926,15 +968,24 @@ int PeriodicTask(void) {
for (i=0; i<2; i++) { for (i=0; i<2; i++) {
tpoint=tpoints[i]; tpoint=tpoints[i];
if (tpoint->code1!=tpoint->code) { /* code has changed -> wait for a confirmation */ if (tpoint->code1!=tpoint->code) { /* code has changed -> wait for a confirmation */
tpoint->code=tpoint->code1; logfileOut(LOG_MAIN, "%s codes: %d,%d,%d\n", tpoint->tname, tpoint->code, tpoint->code1, tpoint->code2);
tpoint->codChanged=1; if (tpoint->code1==tpoint->code2) {
tpoint->code=tpoint->code1;
tpoint->codChanged=1;
} else {
tpoint->code2=tpoint->code1;
}
} else { } else {
tpoint->code2=tpoint->code;
if (tpoint->codChanged) { /* code change confirmed */ if (tpoint->codChanged) { /* code change confirmed */
tpoint->codChanged=0; tpoint->codChanged=0;
Progress(1); Progress(1);
tpoint->manual=0; tpoint->manual=0;
if (tpoint->code1==0) { if (tpoint->code1==0) {
logfileOut(LOG_MAIN, "%s unplugged\n", tpoint->tname); logfileOut(LOG_MAIN, "%s unplugged\n", tpoint->tname);
if (tpoint==&cryo && samp.sensor1->ch[0]<='B') {
samp.manual=0; samp.dirty=1;
}
} else { } else {
logfileOut(LOG_MAIN, "plugged %d on %s\n", tpoint->code1, tpoint->tname); logfileOut(LOG_MAIN, "plugged %d on %s\n", tpoint->code1, tpoint->tname);
} }
@ -964,7 +1015,9 @@ int PeriodicTask(void) {
ERR_P(LscCmd(ser, "RANGE?>iRange")); ERR_P(LscCmd(ser, "RANGE?>iRange"));
if (iRange==0) tempC=0; if (iRange==0) tempC=0;
} else { } else {
ERR_P(LscCmd(ser, "RANGE?>iRange;CSET?1>,cod1,;SETP?1>tempC")); ERR_P(LscCmd(ser, "RANGE?>iRange"));
ERR_P(LscCmd(ser, "CSET?1>,cod1,"));
ERR_P(LscCmd(ser, "SETP?1>tempC"));
if (cod1!=1) { if (cod1!=1) {
tempC=0; tempC=0;
logfileOut(LOG_MAIN, "set point was not in K, set to 0\n"); logfileOut(LOG_MAIN, "set point was not in K, set to 0\n");
@ -974,6 +1027,16 @@ int PeriodicTask(void) {
} }
} }
if (tuning==2) {
ERR_P(LscCmd(ser, "TUNEST?>tuning"));
if (tuning==0) tuning=2;
} else if (tuning==1) {
ERR_P(LscCmd(ser, "TUNEST?>tuning"));
if (tuning==0) {
ERR_P(LscCmd(ser, "PID?1>prop,integ,deriv"));
logfileOut(LOG_MAIN, "@tuned PID %f,%f,%f\n", prop, integ, deriv);
}
}
if (saveTime!=0 && tim>saveTime) { if (saveTime!=0 && tim>saveTime) {
ERR_P(LscCmd(ser, "CRVSAV;BUSY?>busy")); ERR_P(LscCmd(ser, "CRVSAV;BUSY?>busy"));
while (!busy) { while (!busy) {
@ -996,7 +1059,7 @@ int inputSettings(Testpoint *this) {
} else { } else {
if (tpoint->code==0) { if (tpoint->code==0) {
logfileOut(LOG_MAIN ,"reset %s inputs\n", tpoint->tname); logfileOut(LOG_MAIN ,"reset %s inputs\n", tpoint->tname);
if (cryo.code==0 && samp.code==0) { if (cryo.code==0 && samp.code==0 && cryo.manual==0 && samp.manual==0) {
logfileOut(LOG_MAIN, "no more sensor connected\n"); logfileOut(LOG_MAIN, "no more sensor connected\n");
} }
} else { } else {
@ -1046,7 +1109,7 @@ int SetMaxPower(void) {
} }
maxPower=pw; maxPower=pw;
logfileOut(LOG_MAIN, "maxPower %f\n", maxPower, iAmp, iRange); logfileOut(LOG_MAIN, "maxPower %f\n", maxPower, iAmp, iRange);
ERR_P(LscCmd(ser, "CDISP 1:1,[resist],1;MOUT 1:0;CMODE 1:1")); ERR_P(LscCmd(ser, "CDISP 1:1,[resist],1;MOUT 1:0"));
ERR_P(LscCmd(ser, "CLIMIT 1:[tLimit],0,0,[iAmp],[iRange]")); ERR_P(LscCmd(ser, "CLIMIT 1:[tLimit],0,0,[iAmp],[iRange]"));
ERR_I(SetTemp(1)); ERR_I(SetTemp(1));
return(0); return(0);
@ -1253,7 +1316,9 @@ int mainBody(void)
ERR_I(iret=CocHandleRequests(tdif, 0)); ERR_I(iret=CocHandleRequests(tdif, 0));
if (iret==0) { time(&tim); break; } /* timeout */ if (iret==0) { time(&tim); break; } /* timeout */
tim=tim1.time; tim=tim1.time;
ERR_I(ExecuteRequest()); if (ser!=NULL) {
ERR_I(ExecuteRequest());
}
logfileWrite(logMask); logfileWrite(logMask);
} }
ftime(&tim1); ftime(&tim1);
@ -1265,7 +1330,9 @@ int mainBody(void)
logfileOut(LOG_MAIN ,"%d cycles lost\n", tdif-1); logfileOut(LOG_MAIN ,"%d cycles lost\n", tdif-1);
} }
ERR_I(PeriodicTask()); if (ser!=NULL) {
ERR_I(PeriodicTask());
}
if (remoteMode==2) ERR_I(Settings()); if (remoteMode==2) ERR_I(Settings());
return(0); return(0);
@ -1278,6 +1345,7 @@ int mainBody(void)
remoteMode=1; remoteMode=1;
configuring=0; configuring=0;
} else { } else {
/* logfileShowErr("error"); */
logfileOut(LOG_ALL ,"no response\n"); logfileOut(LOG_ALL ,"no response\n");
noResp=1; noResp=1;
per=100; /* try again soon */ per=100; /* try again soon */
@ -1356,7 +1424,7 @@ int main(int argc, char *argv[])
} }
} }
if (port==0) port=9753; if (port==0) port=9753;
if (msecTmo==0) msecTmo=1000; if (msecTmo==0) msecTmo=2000;
if (logPeriod==0) logPeriod=5; if (logPeriod==0) logPeriod=5;
str_copy(buf, logDir); str_copy(buf, logDir);
@ -1406,6 +1474,7 @@ int main(int argc, char *argv[])
CocDefFlt(tLow, CocRD); CocDefFlt(tLow, CocRD);
CocDefFlt(tHigh, CocRD); CocDefFlt(tHigh, CocRD);
CocDefFlt(maxShift, CocWR); CocDefFlt(maxShift, CocWR);
CocDefFlt(fbuf, CocRD);
CocDefStr(device, deviceFlag); CocDefStr(device, deviceFlag);
@ -1437,10 +1506,12 @@ int main(int argc, char *argv[])
CocDefInt(remoteMode, CocRD); CocDefInt(remoteMode, CocRD);
CocDefInt(heliumMode, CocRD); CocDefInt(heliumMode, CocRD);
CocDefInt(htrst, CocRD); CocDefInt(htrst, CocRD);
CocDefInt(tuning, CocRD);
CocDefInt(logPeriod, CocWR); CocDefInt(logPeriod, CocWR);
CocDefInt(readTemp, CocWR); CocDefInt(readTemp, CocWR);
CocDefInt(controlMode, CocWR); CocDefInt(controlMode, CocWR);
CocDefInt(cmode, CocWR);
CocDefInt(int2, CocWR); CocDefInt(int2, CocWR);
CocDefInt(busy, CocRD); CocDefInt(busy, CocRD);
CocDefInt(relay, CocRD); CocDefInt(relay, CocRD);
@ -1459,7 +1530,10 @@ int main(int argc, char *argv[])
CocAlias(set,tempC); CocAlias(set,tempC);
CocAlias(int,integ); CocAlias(int,integ);
ERR_P(ser=SerOpen(host, msecTmo, idleHdl)); ser=SerOpen(host, msecTmo, idleHdl);
if (ser==NULL) {
logfileShowErr("error in SerOpen");
}
ERR_I(iret=CocHandleRequests(100, 0)); ERR_I(iret=CocHandleRequests(100, 0));
ftime(&tim0); ftime(&tim0);
tim=tim0.time; tim=tim0.time;
@ -1476,22 +1550,44 @@ int main(int argc, char *argv[])
logfileWrite(logMask); logfileWrite(logMask);
remoteMode=2; remoteMode=2;
LscCmd(ser, "MODE?>remoteMode");
prop=50; prop=50;
integ=20; integ=20;
deriv=0; deriv=0;
LscCmd(ser, "PID?1>prop,integ,deriv"); if (ser!=NULL) {
LscCmd(ser, "MODE?>remoteMode");
LscCmd(ser, "PID?1>prop,integ,deriv");
}
if (remoteMode!=2) configuring=0; if (remoteMode!=2) configuring=0;
per=1; /* advance fast when initializing */ per=1; /* advance fast when initializing */
cntError=0; cntError=0;
while (!quit) { while (!quit) {
iret=mainBody(); iret=mainBody();
if (iret<0) { if (iret<0 || ser==NULL) {
cntError++; cntError++;
if (cntError>10) ERR_MSG("too many errors - quit"); if (0==strcmp(ErrMessage, "asynsrv error")) {
logfileShowErr("error in TecsServer/mainBody"); if (ser!=NULL) SerClose(ser);
ser=NULL;
}
if (cntError<4) {
logfileShowErr("error in TecsServer/mainBody");
} else if (cntError==4) {
logfileOut(LOG_MAIN, "--- too many errors: skip messages ---\n");
}
if (ser==NULL) {
CocHandleRequests(msecTmo, 0);
ser=SerOpen(host, msecTmo, idleHdl);
if (ser!=NULL) {
LscCmd(ser, "MODE?>remoteMode");
LscCmd(ser, "PID?1>prop,integ,deriv");
}
}
} else { } else {
if (cntError>0) cntError--; if (cntError>0) {
if (cntError>4) {
cntError=4;
}
cntError--;
}
} }
} }
LogMinMax(0); LogMinMax(0);

View File

@ -96,7 +96,6 @@
l=0 l=0
goto 11 goto 11
elseif (cmd .eq. 'plot') then elseif (cmd .eq. 'plot') then
call cho_choose('G')
iret=tecs_get_par('dlogfile', file) iret=tecs_get_par('dlogfile', file)
if (iret .lt. 0) goto 19 if (iret .lt. 0) goto 19
call tecs_plot(file) call tecs_plot(file)
@ -139,7 +138,8 @@
print *,'cti1, cti2, cti3, cti4, cti5 (maxi), cti6 (focus), apd' print *,'cti1, cti2, cti3, cti4, cti5 (maxi), cti6 (focus), apd'
print *,'ccr4k (4K closed cycle), hef4c (TriCS 4circle cryo)' print *,'ccr4k (4K closed cycle), hef4c (TriCS 4circle cryo)'
print *,'sup4t (supra.magnet 4T)' print *,'sup4t (supra.magnet 4T)'
print *,'rdrn (LTF dilution, 20kOhm), rdrn2 (2kOhm)' print *,'rdr11, rdr12 (LTF dilution 1 & 2, 20kOhm)'
1 ,', rdrn11_2, rdr12_2 (2kOhm)'
print * print *
elseif (cmd .eq. 'log') then elseif (cmd .eq. 'log') then
iret=tecs_get_par('logfile', file) iret=tecs_get_par('logfile', file)

View File

@ -3,7 +3,7 @@
#include <time.h> #include <time.h>
/* implemented in fortran TECS_DLOG.FOR */ /* implemented in fortran TECS_DLOG.F */
int dlog_open_write_(char *file); int dlog_open_write_(char *file);
/* open dlog file */ /* open dlog file */

View File

@ -2,7 +2,7 @@ subroutine tecs_plot(file)
character(len=*) file character(len=*) file
integer, parameter :: dmax=500, nset=3, nmenu=9, chartfreq=2 integer, parameter :: dmax=500, nset=3, nmenu=10, chartfreq=2
real, parameter :: winmin=60., undef=-65535.0 real, parameter :: winmin=60., undef=-65535.0
real*4 x1,x2,xmin,xmax,ymin(2),ymax(2),window real*4 x1,x2,xmin,xmax,ymin(2),ymax(2),window
@ -15,28 +15,28 @@ subroutine tecs_plot(file)
integer color(3)/2,4,3/ integer color(3)/2,4,3/
character key*1 character key*1
character text(nmenu)*12/ & character text(nmenu)*12/ &
'live off','sel. zoom','zoom in','zoom out','show all','n days','n hours','n min','quit'/ 'live off','sel. zoom','zoom in','zoom out','show all','n days','n hours','n min','file','quit'/
character keys*(nmenu)/'LZ+-XDHMQ'/ character keys*(nmenu)/'LZ+-XDHMFQ'/
character weekdays(7)*3/'Mon','Tue','Wed','Thu','Fri','Sat','Sun'/ character weekdays(7)*3/'Mon','Tue','Wed','Thu','Fri','Sat','Sun'/
character buf*8 character buf*8, device*8, line*40, filnam*128
external tplot_close external tplot_close
logical live, xwin, zoom, right logical live, xwin, zoom, right, saveit
integer iret, numb integer iret, numb, lund
integer dlog_open_r, dlog_get, dlog_close_r integer dlog_open_r, dlog_get, dlog_close_r
data window/1800./ data window/1800./
saveit=.false.
zoom=.false. zoom=.false.
right=.true. right=.true.
call pgopen(" ") call pgopen(" ")
call pgqinf('TYPE', buf, l) call pgqinf('TYPE', device, l)
if (buf=='NULL') then if (device=='NULL') then
print *,'No PGPLOT-Device defined' print *,'No PGPLOT-Device defined'
goto 9 goto 9
endif endif
xwin=(buf(1:1)=='X') live=device(1:1)/='X' ! live switched off by default on X-Windows
live=.not. xwin ! live switched off by default on X-Windows
call pgask(.false.) call pgask(.false.)
l=0 l=0
@ -83,6 +83,7 @@ subroutine tecs_plot(file)
call err_txt('dlog_get') call err_txt('dlog_get')
goto 99 goto 99
endif endif
if (saveit) goto 9
if (ntot>0) then if (ntot>0) then
xmin=minval(xd(1:ntot)) xmin=minval(xd(1:ntot))
xmax=maxval(xd(1:ntot)) xmax=maxval(xd(1:ntot))
@ -153,6 +154,11 @@ subroutine tecs_plot(file)
zoom=.false. zoom=.false.
call pgswin(x1,x2,ymin(rl),ymax(rl)) call pgswin(x1,x2,ymin(rl),ymax(rl))
call pgscr(0, 1.0, 1.0, 1.0)
call pgscr(1, 0.0, 0.0, 0.0)
call pgscr(2, 1.0, 0.0, 0.0)
call pgscr(3, 0.0, 0.7, 0.0)
call pgscr(4, 0.0, 0.0, 1.0)
do i=i1,i2 do i=i1,i2
call pgsci(color(i)) call pgsci(color(i))
@ -252,7 +258,7 @@ subroutine tecs_plot(file)
numb=0 numb=0
7 if (live) then 7 if (live) then
if (xwin) then if (device(1:1)=='X') then
call pgmtxt('T', 1.0, 1.0, 1.0, 'LIVE MODE (click on text window before pressing any further key)') call pgmtxt('T', 1.0, 1.0, 1.0, 'LIVE MODE (click on text window before pressing any further key)')
endif endif
call get_key(key, 0, chartfreq) call get_key(key, 0, chartfreq)
@ -354,7 +360,7 @@ subroutine tecs_plot(file)
call pgsci(1) call pgsci(1)
call pgmtxt('T', 2.0, 0.9, 0.0, buf(l:)) call pgmtxt('T', 2.0, 0.9, 0.0, buf(l:))
endif endif
if (xwin .and. .not. live) then if (device(1:1)=='X' .and. .not. live) then
call pgcurs(ex, ey, key) call pgcurs(ex, ey, key)
call must_purge call must_purge
else else
@ -380,6 +386,8 @@ subroutine tecs_plot(file)
right=.true. right=.true.
x2=xmax x2=xmax
endif endif
elseif (key .eq. 'F') then
saveit=.true.
elseif (key=='Q' .or. key==char(13)) then elseif (key=='Q' .or. key==char(13)) then
goto 9 goto 9
elseif (live) then elseif (live) then
@ -393,6 +401,24 @@ subroutine tecs_plot(file)
call tplot_close call tplot_close
call get_key(key, 0, 0) ! purge type-ahead-buffer call get_key(key, 0, 0) ! purge type-ahead-buffer
print * print *
if (saveit) then
lund=41
print '(x,a,$)', 'Filename: '
read(*,'(a)') filnam
open(lund, file=filnam, status='unknown', carriagecontrol='list')
write(lund, *) ' time [h]',char(9),' T1 [K]',char(9),' T2 [K]',char(9),'power [W]'
do i=1,ntot
write(line, '(4(f9.4,a))') xd(i)/3600., (char(9), max(-999.,min(9999.,yd(i,j))), j=1,3)
do j=1,3
if (yd(i,j)==undef) then
line(10*j+1:10*j+9)=' '
endif
enddo
write(lund, *) line(1:39)
enddo
close(lund)
print *, ntot+1, ' lines written to ',filnam(1:48)
endif
end subroutine end subroutine
subroutine get_key(key, tmo1, tmo2) subroutine get_key(key, tmo1, tmo2)

View File

@ -1,6 +1,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/timeb.h>
#include "rs232c_def.h" #include "rs232c_def.h"
#include "asynsrv_def.h" #include "asynsrv_def.h"
#include "sinq_prototypes.h" #include "sinq_prototypes.h"
@ -12,6 +12,8 @@
#define A_CHK(R) if (1!=(R)) { SerA_error(); ErrTxt(#R,0); goto OnError; } #define A_CHK(R) if (1!=(R)) { SerA_error(); ErrTxt(#R,0); goto OnError; }
int ftime (struct timeb *__timeptr); /* for some reason not defined in timeb.h with flag -std1 */
void (*idleHandler)(int,int); void (*idleHandler)(int,int);
struct SerChan { struct SerChan {
@ -33,7 +35,7 @@ SerChannel *SerOpen(const char *host, int msecTmo, void (*idleHdl)(int,int)) {
struct SerChan *ser; struct SerChan *ser;
char hbuf[64], cport[16]; char hbuf[64], cport[16];
char *p, *c; char *p, *c;
int port, chan; int port, chan, iRet;
idleHandler=idleHdl; idleHandler=idleHdl;
NEW(ser); NEW(ser);
@ -48,12 +50,13 @@ SerChannel *SerOpen(const char *host, int msecTmo, void (*idleHdl)(int,int)) {
} }
ser->asyn_info.port=port; ser->asyn_info.port=port;
ser->asyn_info.chan=chan; ser->asyn_info.chan=chan;
logfileOut(LOG_MAIN, "open connection to %s:%d/%d\n", ser->asyn_info.host, ser->asyn_info.port, ser->asyn_info.chan);
A_CHK(AsynSrv_Open(&ser->asyn_info)); A_CHK(AsynSrv_Open(&ser->asyn_info));
if (msecTmo==0) msecTmo=5000; if (msecTmo==0) msecTmo=5000;
A_CHK(AsynSrv_Config(&ser->asyn_info, "msecTmo", msecTmo, "idleHdl", idleHdl, NULL)); A_CHK(AsynSrv_Config(&ser->asyn_info, "msecTmo", msecTmo, "idleHdl", idleHdl, NULL));
logfileOut(LOG_MAIN, "connection to %s:%d/%d opened\n", ser->asyn_info.host, ser->asyn_info.port, ser->asyn_info.chan);
return((SerChannel *)ser); return((SerChannel *)ser);
OnError: return(NULL); OnError:
return(NULL);
} }
int SerClose(SerChannel *serch) { int SerClose(SerChannel *serch) {
@ -80,6 +83,8 @@ char *SerCmd(SerChannel *serch, char *cmnd) {
int l; int l;
struct SerChan *ser; struct SerChan *ser;
char *result; char *result;
struct timeb tim0, tim1;
int tdif;
l=strlen(cmnd); l=strlen(cmnd);
if (l>=SER_BUF_LEN-1) ERR_COD(ENOBUFS); if (l>=SER_BUF_LEN-1) ERR_COD(ENOBUFS);
@ -88,11 +93,18 @@ char *SerCmd(SerChannel *serch, char *cmnd) {
logfileOut(LOG_SER, ">%s\n", cmnd); logfileOut(LOG_SER, ">%s\n", cmnd);
cmnd[l]=ser->asyn_info.eot[1]; cmnd[l]=ser->asyn_info.eot[1];
cmnd[l+1]='\0'; cmnd[l+1]='\0';
ftime(&tim0);
A_CHK(AsynSrv_SendCmnds(&ser->asyn_info, &ser->to_host, &ser->from_host, cmnd, NULL)); A_CHK(AsynSrv_SendCmnds(&ser->asyn_info, &ser->to_host, &ser->from_host, cmnd, NULL));
result=AsynSrv_GetReply(&ser->asyn_info, &ser->from_host, NULL); result=AsynSrv_GetReply(&ser->asyn_info, &ser->from_host, NULL);
ftime(&tim1);
tdif=(tim1.time-tim0.time)*1000+tim1.millitm-tim0.millitm;
if (result==NULL) ERR_MSG("empty result"); if (result==NULL) ERR_MSG("empty result");
/* if (idleHandler!=NULL) idleHandler(50,0); */ /* if (idleHandler!=NULL) idleHandler(50,0); */
logfileOut(LOG_SER, "<%s\n", result); logfileOut(LOG_SER, "<%s\n", result);
if (tdif>1000) {
logfileOut(LOG_SER, "%d msec:\n >%s\n", tdif, cmnd);
logfileOut(LOG_SER, " <%s\n", result);
}
return(result); return(result);
OnError: return(NULL); OnError: return(NULL);
} }