minor changes
This commit is contained in:
396
tecs/tecs.c
396
tecs/tecs.c
@@ -26,6 +26,7 @@ static char *logDir=NULL;
|
||||
|
||||
typedef struct {
|
||||
float temp, t1, t2; /* calc, high, low temperature */
|
||||
float tMin, tMax, min1, max1, min2, max2; /* minimum and maximum temperatures since ... */
|
||||
int dirty; /* input config to be reloaded */
|
||||
int try; /* trial count */
|
||||
int manual; /* manual device */
|
||||
@@ -52,6 +53,8 @@ static float
|
||||
tLimit, power, /* heater parameters */
|
||||
tLow=0, tHigh=0, /* lower limit of high-T sensor, upper limit of low-T sensor */
|
||||
tShift=0, /* setpoint shift */
|
||||
prop, integ, deriv, /* pid */
|
||||
maxShift=2, /* maximal shift in when controlMode=2 */
|
||||
tInt=0; /* integral time (sec.) for setpoint shift */
|
||||
|
||||
static int
|
||||
@@ -59,8 +62,10 @@ static int
|
||||
period=5000, /* default read interval (msec.) */
|
||||
logTime, /* next logging time */
|
||||
setFlag, /* temperature to be set */
|
||||
powerFlag, /* power to be set */
|
||||
pidFlag, /* pid's to be set */
|
||||
saveTime, /* time for a CRVSAV command */
|
||||
noResp=1, /* no response */
|
||||
noResp=2, /* no response */
|
||||
quit, /* quit server */
|
||||
controlMode=2, /* 0: control on heater, 1: control on sample, 3: 2nd loop for difference heater-sample */
|
||||
remoteMode, /* 1: local, 2: remote */
|
||||
@@ -72,14 +77,17 @@ static int
|
||||
key, /* key status */
|
||||
serialNo,
|
||||
configuring=1,
|
||||
stable, /* stable since 2 min. */
|
||||
resist, /* heater resistance */
|
||||
readTemp, /* client requested readTemp */
|
||||
cod1, cod2, out1, out2, /* codes read from digital input/output */
|
||||
iRange, iAmp, /* max. range and max. current code */
|
||||
htrst, htrst0, /* heater status */
|
||||
per; /* effective period */
|
||||
|
||||
static time_t
|
||||
tim, /* actual time */
|
||||
mmInt, mmTime, /* interval and time for next min-max logging */
|
||||
tableTime; /* last time when table was read */
|
||||
|
||||
static int decod[8]={21,20,17,16,5,4,1,0}; /* for code conversion */
|
||||
@@ -95,7 +103,19 @@ static char
|
||||
|
||||
static char
|
||||
*table=NULL, /* environment devices table */
|
||||
*cache=NULL; /* curve list cache */
|
||||
*cache=NULL, /* curve list cache */
|
||||
*logfile="<none>";
|
||||
|
||||
static char
|
||||
*heaterStatus[7]={
|
||||
"heater o.k.\n",
|
||||
"heater supply over V\n",
|
||||
"heater supply under V\n",
|
||||
"heater output DAC error\n",
|
||||
"heater Ilimit DAC error\n",
|
||||
"open heater load\n",
|
||||
"heater load < 10 Ohm\n",
|
||||
};
|
||||
|
||||
struct timeb tim0;
|
||||
int logMask;
|
||||
@@ -147,7 +167,7 @@ int putPermanentData(FILE *fil) {
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
int instCurve(char *nam, char *channel) {
|
||||
int instCurve(char *nam, char *channel, int dispFld) {
|
||||
/*
|
||||
install sensor nam on channel
|
||||
*/
|
||||
@@ -163,6 +183,7 @@ int instCurve(char *nam, char *channel) {
|
||||
|
||||
fil=NULL;
|
||||
crv=NULL;
|
||||
e=NULL;
|
||||
|
||||
str_copy(chan, channel);
|
||||
logfileOut(LOG_MAIN, "install curve %s\n", nam);
|
||||
@@ -180,6 +201,11 @@ int instCurve(char *nam, char *channel) {
|
||||
points=str_split(intype, t, '\n');
|
||||
}
|
||||
if (points==NULL) ERR_MSG("illegal curve file");
|
||||
if (cache==NULL) { ERR_SP(cache=my_malloc(1,"one")); *cache='\0'; } /* create empty cache if undefined */
|
||||
|
||||
start=strchr(cache, '\n'); /* skip permanent data */
|
||||
if (start==NULL) { start=cache; } else { start++; }
|
||||
|
||||
if (points[0]=='$') { /* standard curve */
|
||||
|
||||
points++; num=atoi(points);
|
||||
@@ -195,9 +221,6 @@ int instCurve(char *nam, char *channel) {
|
||||
str_append(buf, " ");
|
||||
str_upcase(buf, buf);
|
||||
|
||||
if (cache==NULL) { ERR_SP(cache=my_malloc(1,"one")); *cache='\0'; } /* create empty cache if undefined */
|
||||
start=strchr(cache, '\n'); /* skip device names */
|
||||
if (start==NULL) { start=cache; } else { start++; }
|
||||
entry=strstr(start, buf);
|
||||
if (entry==NULL) { /* sensor not found in cache */
|
||||
entry=start;
|
||||
@@ -235,14 +258,14 @@ int instCurve(char *nam, char *channel) {
|
||||
if (e!=NULL) { *e='\0'; e++; }
|
||||
}
|
||||
}
|
||||
fld=chan[0]-'A'+1;
|
||||
fld=dispFld;
|
||||
if (fld>maxfld) maxfld=fld;
|
||||
|
||||
if (head[0]!='\0' && LscEqPar(head, chead)) { /* header matches: select sensor type and curve */
|
||||
|
||||
retstat=-1; /* an error could be fixed */
|
||||
ERR_P(LscCmd(ser, "RANGE:0;INTYPE [chan]:[intype];INCRV [chan]:[num]"));
|
||||
ERR_P(LscCmd(ser, "DISPFLD [fld],[chan],1;DISPLAY:[maxfld]"));
|
||||
ERR_P(LscCmd(ser, "MNMX [chan]:1,1;DISPFLD [fld],[chan],1;DISPLAY [maxfld]"));
|
||||
logfileOut(LOG_MAIN, "curve %d on channel %s selected\n", num, chan);
|
||||
Progress(100);
|
||||
|
||||
@@ -254,8 +277,7 @@ int instCurve(char *nam, char *channel) {
|
||||
if (busy) ERR_MSG("busy");
|
||||
logfileOut(LOG_MAIN, "download curve %d\n", num);
|
||||
/* select sensor type first to display sensor units */
|
||||
ERR_P(LscCmd(ser, "RANGE:0;INTYPE [chan]:[intype]"));
|
||||
ERR_P(LscCmd(ser, "DISPFLD [fld],[chan],3;DISPLAY:[maxfld]"));
|
||||
ERR_P(LscCmd(ser, "RANGE:0;INTYPE [chan]:[intype];DISPLAY:[maxfld]"));
|
||||
Progress(1);
|
||||
|
||||
n=3;
|
||||
@@ -283,7 +305,8 @@ int instCurve(char *nam, char *channel) {
|
||||
|
||||
/* write header, select curve */
|
||||
str_upcase(head, chead);
|
||||
ERR_P(LscCmd(ser, "CRVHDR [num]:[head];INCRV [chan]:[num];DISPFLD [fld],[chan],1"));
|
||||
ERR_P(LscCmd(ser, "CRVHDR [num]:[head];INCRV [chan]:[num]"));
|
||||
ERR_P(LscCmd(ser, "MNMX [chan]:1,1;DISPFLD [fld],[chan],1;DISPLAY [maxfld]"));
|
||||
Progress(1);
|
||||
logfileOut(LOG_MAIN, "curve selected on channel %s\n", chan);
|
||||
saveTime=tim+30;
|
||||
@@ -300,8 +323,10 @@ int instCurve(char *nam, char *channel) {
|
||||
fil=fopen(nbuf, "r+");
|
||||
if (fil==NULL) ERR_SP(fil=fopen(nbuf, "w"));
|
||||
ERR_I(putPermanentData(fil));
|
||||
sprintf(buf, "%d:%s", num, head);
|
||||
ERR_SI(fputs(buf, fil)); /* write actual entry */
|
||||
if (num>20) { /* write actual entry */
|
||||
sprintf(buf, "%d:%s", num, head);
|
||||
ERR_SI(fputs(buf, fil));
|
||||
}
|
||||
if (start!=s) { /* write content before replaced entry */
|
||||
ERR_SI(fputs("\n", fil));
|
||||
ERR_SI(fputs(start, fil));
|
||||
@@ -327,7 +352,7 @@ int instCurve(char *nam, char *channel) {
|
||||
int configInput(void) {
|
||||
char *t;
|
||||
char buf[80], nam[16], nbuf[256];
|
||||
int i, n, nn;
|
||||
int i, n, nn, dispFld;
|
||||
int retstat;
|
||||
char *ext;
|
||||
|
||||
@@ -358,6 +383,7 @@ int configInput(void) {
|
||||
i=sscanf(t, "%12s%d%d", nam, &nn, &n);
|
||||
if (i<1) ERR_MSG("missing sensor name");
|
||||
ext=".s";
|
||||
dispFld=2;
|
||||
} else {
|
||||
cryo.nSens=0;
|
||||
tLow=0; tHigh=0;
|
||||
@@ -365,6 +391,7 @@ int configInput(void) {
|
||||
i=sscanf(t, "%12s%d%d%d%f%d%f%f%f", nam, &n, &nn, &controlMode, &tLimit, &resist, &power, &tLow, &tHigh);
|
||||
if (i<7) ERR_MSG("missing some sensor parameters");
|
||||
ext=".x";
|
||||
dispFld=1;
|
||||
}
|
||||
if (n<0 || n>2) ERR_MSG("illegal value for nsensor");
|
||||
if (n==0) return(0);
|
||||
@@ -375,10 +402,10 @@ int configInput(void) {
|
||||
}
|
||||
str_append(nam, ext);
|
||||
|
||||
ERR_I(retstat=instCurve(nam, tpoint->ch1));
|
||||
ERR_I(retstat=instCurve(nam, tpoint->ch1, dispFld));
|
||||
if (n==2) {
|
||||
str_append(nam, "l");
|
||||
ERR_I(retstat=instCurve(nam, tpoint->ch2));
|
||||
ERR_I(retstat=instCurve(nam, tpoint->ch2, dispFld+2));
|
||||
}
|
||||
tpoint->nSens=n;
|
||||
return(0);
|
||||
@@ -445,10 +472,75 @@ float WeightedAverage(int n, float tH, float tL) {
|
||||
}
|
||||
}
|
||||
|
||||
int LogMinMax(int new) {
|
||||
char buf[256];
|
||||
int i, j, logIt;
|
||||
float tol, tmin[2], tmax[2];
|
||||
|
||||
buf[0]='\0';
|
||||
|
||||
if (cryo.nSens>0) {
|
||||
str_append(buf, "MDAT?[cryo.ch1]>cryo.min1,cryo.max1;");
|
||||
if (cryo.nSens>1) {
|
||||
str_append(buf, "MDAT?[cryo.ch2]>cryo.min2,cryo.max2;");
|
||||
} else {
|
||||
cryo.t2=0;
|
||||
}
|
||||
} else {
|
||||
cryo.t1=0;
|
||||
cryo.t2=0;
|
||||
}
|
||||
|
||||
if (samp.nSens>0) {
|
||||
str_append(buf, "MDAT?[samp.ch1]>samp.min1,samp.max1;");
|
||||
if (samp.nSens>1) {
|
||||
str_append(buf, "MDAT?[samp.ch2]>samp.min2,samp.max2;");
|
||||
} else {
|
||||
samp.t2=0;
|
||||
}
|
||||
} else {
|
||||
samp.t1=0;
|
||||
samp.t2=0;
|
||||
}
|
||||
|
||||
i=strlen(buf);
|
||||
if (i>0) {
|
||||
str_append(buf, "MNMXRST");
|
||||
ERR_P(LscCmd(ser, buf));
|
||||
}
|
||||
|
||||
logIt=0;
|
||||
for (i=0; i<2; i++) {
|
||||
tpoint=tpoints[i];
|
||||
if (tpoint->nSens>0) {
|
||||
tpoint->tMin = WeightedAverage(tpoint->nSens, tpoint->min1, tpoint->min2) * tpoint->scale;
|
||||
tpoint->tMax = WeightedAverage(tpoint->nSens, tpoint->max1, tpoint->max2) * tpoint->scale;
|
||||
}
|
||||
}
|
||||
sprintf(buf, "@%.3f < T < %.3f K", cryo.tMin, cryo.tMax);
|
||||
if (samp.nSens>0) {
|
||||
sprintf(buf1, "(reg), %.3f < T < %.3f K (samp)", samp.tMin, samp.tMax);
|
||||
str_append(buf, buf1);
|
||||
}
|
||||
logfileOut(LOG_MAIN, "%s\n", buf);
|
||||
if (new) {
|
||||
mmInt=60;
|
||||
} else if (mmInt<600) {
|
||||
mmInt=mmInt+60;
|
||||
}
|
||||
mmTime=tim+mmInt;
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
int SetTemp(int switchOn) {
|
||||
char *ch;
|
||||
float scale;
|
||||
|
||||
if (switchOn) {
|
||||
ERR_I(LogMinMax(1));
|
||||
logfileOut(LOG_MAIN, "set %.3f\n", tempC);
|
||||
}
|
||||
scale=cryo.scale;
|
||||
ch=cryo.ch1;
|
||||
if (cryo.nSens>1 && tempC<(tLow+tHigh)/2) ch=cryo.ch2;
|
||||
@@ -468,6 +560,11 @@ int SetTemp(int switchOn) {
|
||||
if (scale!=1.0) { /* show set point on display (for rdrn) */
|
||||
ERR_P(LscCmd(ser, "LINEAR C,1,0,1,1,[tempC]"));
|
||||
}
|
||||
if (tShift>maxShift) {
|
||||
tShift=maxShift;
|
||||
} else if (tShift<-maxShift) {
|
||||
tShift=-maxShift;
|
||||
}
|
||||
tempH=(tempC+tShift)/scale;
|
||||
if (tempC==0) {
|
||||
ERR_P(LscCmd(ser, "CSET 1:[chan],1,1,0;RANGE:0;SETP 1:0"));
|
||||
@@ -540,13 +637,24 @@ int PeriodicTask(void) {
|
||||
time_t putTim;
|
||||
float t3[3], p, d, w;
|
||||
|
||||
ERR_P(LscCmd(ser, "DIOST?>cod1,out1;DOUT 3,29;HTR?>htr;BUSY?>busy"));
|
||||
ERR_P(LscCmd(ser, "DIOST?>cod1,out1;DOUT 3,29;HTR?>htr;HTRST?>htrst;BUSY?>busy"));
|
||||
if (cryo.codDefined && samp.codDefined) {
|
||||
per=period; /* no timeout on above command and codes are defined: normal period */
|
||||
if (per>logPeriod*1000) per=logPeriod*1000;
|
||||
}
|
||||
|
||||
if (htrst!=htrst0) {
|
||||
if (htrst<0 || htrst>6) {
|
||||
sprintf(buf, "heater status %d\n", htrst);
|
||||
logfileOut(LOG_MAIN, buf);
|
||||
} else {
|
||||
logfileOut(LOG_MAIN, heaterStatus[htrst]);
|
||||
}
|
||||
htrst0=htrst;
|
||||
}
|
||||
if (noResp) { /* there was no response on an earlier command, or we are initializing */
|
||||
if (!configuring) remoteMode=2;
|
||||
LscCmd(ser, "MODE:[remoteMode]");
|
||||
k=serialNo; /* check serial number */
|
||||
ERR_P(LscCmd(ser, "*IDN?>buf1,buf2,serialNo,"));
|
||||
if (0!=strcmp(buf1, "LSCI") || 0!=strcmp(buf2, "MODEL340") || serialNo==0) return(0);
|
||||
@@ -605,27 +713,35 @@ int PeriodicTask(void) {
|
||||
|
||||
ERR_I(ReadTemp());
|
||||
|
||||
if (cryo.dirty==0 && samp.dirty==0 && noResp==0 && tim>logTime) {
|
||||
if (tim>=logTime) {
|
||||
i=0;
|
||||
if (cryo.nSens>0) {
|
||||
t3[0]=cryo.temp;
|
||||
i=1;
|
||||
} else {
|
||||
t3[0]=undef;
|
||||
}
|
||||
if (samp.nSens>0) {
|
||||
t3[1]=samp.temp;
|
||||
i=2;
|
||||
} else {
|
||||
t3[1]=undef;
|
||||
if (cryo.nSens>1) {
|
||||
t3[1]=cryo.t2;
|
||||
i=2;
|
||||
} else {
|
||||
t3[1]=undef;
|
||||
}
|
||||
}
|
||||
if (tempC!=0 || htr!=0) {
|
||||
t3[2]=htr*htr*power*1e-4;
|
||||
i=3;
|
||||
} else {
|
||||
t3[2]=undef;
|
||||
}
|
||||
time(&putTim);
|
||||
i=3;
|
||||
dlog_put_(&putTim, &i, t3);
|
||||
|
||||
if (i>0) ERR_I(dlog_put_(&putTim, &i, t3));
|
||||
logTime=(putTim/logPeriod+1)*logPeriod;
|
||||
if (tim>mmTime) ERR_I(LogMinMax(0));
|
||||
}
|
||||
if (samp.nSens>0 && cryo.nSens>0 && controlMode==2 && tempC!=0) {
|
||||
d=(tempH-cryo.temp)/cryo.temp-1.0; /* relative difference */
|
||||
@@ -693,6 +809,7 @@ int PeriodicTask(void) {
|
||||
remoteMode=1;
|
||||
ERR_P(LscCmd(ser, "MODE?>remoteMode"));
|
||||
if (remoteMode==2) { /* user switched to remote mode */
|
||||
ERR_P(LscCmd(ser, "PID?1>prop,integ,deriv"));
|
||||
if (controlMode==2) {
|
||||
ERR_P(LscCmd(ser, "RANGE?>iRange"));
|
||||
if (iRange==0) tempC=0;
|
||||
@@ -741,8 +858,6 @@ int inputSettings(Testpoint *this) {
|
||||
} else {
|
||||
logfileShowErr("try again");
|
||||
}
|
||||
} else {
|
||||
ERR_P(LscCmd(ser, "ALARM [tpoint.ch1]:[tpoint.nSens],1,[tLimit],0,0,1;ALARM [tpoint.ch2]:0;RELAY 1:1;BEEP:0"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -750,59 +865,112 @@ int inputSettings(Testpoint *this) {
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
int Settings(void) {
|
||||
int i, j, k;
|
||||
int SetPower(void) {
|
||||
int i, j;
|
||||
float pa, pr, pw, dif;
|
||||
|
||||
iAmp=1; iRange=0;
|
||||
if (power>0) {
|
||||
pa=resist*4; /* max. power */
|
||||
pw=0; dif=1.0e6;
|
||||
for (i=4; i>0; i--) {
|
||||
pr=pa;
|
||||
for (j=5; j>0; j--) {
|
||||
if (pr>power) {
|
||||
if (pr/power<dif) { dif=pr/power; pw=pr; iAmp=i; iRange=j; }
|
||||
} else {
|
||||
if (power/pr<dif) { dif=power/pr; pw=pr; iAmp=i; iRange=j; }
|
||||
}
|
||||
pr=pr/10;
|
||||
}
|
||||
pa=pa/4;
|
||||
}
|
||||
}
|
||||
power=pw;
|
||||
logfileOut(LOG_MAIN, "power %f\n", power, iAmp, iRange);
|
||||
ERR_P(LscCmd(ser, "CDISP 1:1,[resist],1;MOUT 1:0;CMODE 1:1"));
|
||||
ERR_P(LscCmd(ser, "CLIMIT 1:[tLimit],0,0,[iAmp],[iRange]"));
|
||||
ERR_I(SetTemp(1));
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
int Display(void) {
|
||||
char flds[5], fmt[5], disp[32], buf[256];
|
||||
int i,j,k;
|
||||
|
||||
maxfld=0;
|
||||
for (i=1; i<=4; i++) { flds[i]=' '; fmt[i]=' '; }
|
||||
for (j=0; j<2; j++) { /* fill in kelvin display fields */
|
||||
tpoint=tpoints[j];
|
||||
if (tpoint->nSens>0) {
|
||||
k=1+j;
|
||||
flds[k]=tpoint->ch1[0]; fmt[k]='1'; if (k>maxfld) maxfld=k;
|
||||
if (tpoint->nSens>1) {
|
||||
k=3+j;
|
||||
flds[k]=tpoint->ch2[0]; fmt[k]='1'; if (k>maxfld) maxfld=k;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (j=0; j<2; j++) { /* fill raw display fields */
|
||||
tpoint=tpoints[j];
|
||||
if (tpoint->nSens>0) {
|
||||
k=2-j; /* try first right (or left) of the kelvin field */
|
||||
if (flds[k]!=' ') k=3+j; /* then the field below */
|
||||
if (flds[k]!=' ') k=4-j; /* then below right */
|
||||
if (flds[k]==' ') {
|
||||
if (k>maxfld) maxfld=k;
|
||||
flds[k]=tpoint->ch1[0]; fmt[k]='3';
|
||||
}
|
||||
if (tpoint->nSens>1) {
|
||||
k=4-j; /* try right (or left) of the kelvin field */
|
||||
if (flds[k]==' ') {
|
||||
if (k>maxfld) maxfld=k;
|
||||
flds[k]=tpoint->ch2[0]; fmt[k]='3';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* fields 5-8 standard raw data */
|
||||
ERR_P(LscCmd(ser, "DISPFLD 5,A,3;DISPFLD 6,C,3;DISPFLD 7,B,3;DISPFLD 8,D,3"));
|
||||
if (maxfld==0) { /* show raw data */
|
||||
ERR_P(LscCmd(ser, "DISPFLD 1,A,3;DISPFLD 2,C,3;DISPFLD 3,B,3;DISPFLD 4,D,3;DISPLAY:4"));
|
||||
} else {
|
||||
buf[0]='\0';
|
||||
for (i=1; i<=maxfld; i++) {
|
||||
if (flds[i]!=' ') {
|
||||
sprintf(disp, "DISPFLD %d,%c,%c;", i, flds[i], fmt[i]);
|
||||
}
|
||||
str_append(buf, disp);
|
||||
}
|
||||
str_append(buf, "DISPLAY:[maxfld]");
|
||||
ERR_P(LscCmd(ser, buf));
|
||||
}
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
int Settings(void) {
|
||||
char nbuf[256], buf[256], *cfg, *p;
|
||||
|
||||
cfg=NULL;
|
||||
if (cryo.dirty && cryo.codDefined || samp.dirty && samp.codDefined) {
|
||||
|
||||
for (i=0; i<2; i++) {
|
||||
tpoint=tpoints[i];
|
||||
if (tpoint->dirty) {
|
||||
ERR_P(LscCmd(ser, "DISPFLD 2,[tpoint.ch1],1;DISPFLD 4,[tpoint.ch2],1"));
|
||||
}
|
||||
}
|
||||
inputSettings(&cryo);
|
||||
inputSettings(&samp);
|
||||
ERR_I(inputSettings(&cryo));
|
||||
ERR_I(inputSettings(&samp));
|
||||
|
||||
if (cryo.nSens>0) {
|
||||
/* control settings */
|
||||
ERR_P(LscCmd(ser, "CDISP 1:1,[resist],1;MOUT 1:0;CMODE 1:1"));
|
||||
iAmp=1; iRange=0;
|
||||
if (power>0) {
|
||||
pa=resist*4; /* max. power */
|
||||
pw=0; dif=1.0e6;
|
||||
for (i=4; i>0; i--) {
|
||||
pr=pa;
|
||||
for (j=5; j>0; j--) {
|
||||
if (pr>power) {
|
||||
if (pr/power<dif) { dif=pr/power; pw=pr; iAmp=i; iRange=j; }
|
||||
} else {
|
||||
if (power/pr<dif) { dif=power/pr; pw=pr; iAmp=i; iRange=j; }
|
||||
}
|
||||
pr=pr/10;
|
||||
}
|
||||
pa=pa/4;
|
||||
}
|
||||
ERR_I(SetPower());
|
||||
ERR_P(LscCmd(ser, "ALARM [cryo.ch1]:1,1,[tLimit],0,0,1;ALARM [cryo.ch2]:0;RELAY 1:1;BEEP:0"));
|
||||
if (samp.nSens>0) {
|
||||
ERR_P(LscCmd(ser, "ALARM [samp.ch1]:1,1,[tLimit],0,0,1;ALARM [samp.ch2]:0"));
|
||||
} else {
|
||||
ERR_P(LscCmd(ser, "ALARM [samp.ch1]:0;ALARM [samp.ch2]:0"));
|
||||
}
|
||||
power=pw;
|
||||
logfileOut(LOG_INFO, "power %f\n", power, iAmp, iRange);
|
||||
ERR_P(LscCmd(ser, "CLIMIT 1:[tLimit],0,0,[iAmp],[iRange]"));
|
||||
ERR_I(SetTemp(1));
|
||||
}
|
||||
if (samp.nSens>=cryo.nSens) {
|
||||
maxfld=2*samp.nSens;
|
||||
} else {
|
||||
maxfld=2*cryo.nSens-1;
|
||||
}
|
||||
if (maxfld>0) {
|
||||
ERR_P(LscCmd(ser, "DISPLAY:[maxfld]"));
|
||||
} else {
|
||||
maxfld=1;
|
||||
ERR_P(LscCmd(ser, "DISPLAY:1;DISPFLD 1,A,3"));
|
||||
ERR_P(LscCmd(ser, "ALARM [cryo.ch1]:0;ALARM [cryo.ch2]:0;ALARM [samp.ch1]:0;ALARM [samp.ch2]:0"));
|
||||
}
|
||||
ERR_I(Display());
|
||||
|
||||
str_copy(nbuf, binDir);
|
||||
str_append(nbuf, cryo.device);
|
||||
@@ -830,15 +998,24 @@ int Settings(void) {
|
||||
int ExecuteRequest(void) {
|
||||
char *t, *res;
|
||||
struct CocClient *client;
|
||||
float p;
|
||||
|
||||
if (readTemp) ReadTemp();
|
||||
if (readTemp) ERR_I(ReadTemp());
|
||||
if (remoteMode==2) ERR_I(Settings());
|
||||
if (powerFlag) {
|
||||
powerFlag=0;
|
||||
ERR_I(SetPower());
|
||||
}
|
||||
if (pidFlag) {
|
||||
pidFlag=0;
|
||||
ERR_P(LscCmd(ser,"PID 1:[prop],[integ],[deriv]"));
|
||||
}
|
||||
if (setFlag) {
|
||||
setFlag=0;
|
||||
if (cryo.nSens>0) {
|
||||
tInt=0; /* reset integral time */
|
||||
ERR_I(SetTemp(1));
|
||||
}
|
||||
setFlag=0;
|
||||
}
|
||||
client=CocGetNextCmd();
|
||||
if (client!=NULL) {
|
||||
@@ -854,7 +1031,7 @@ int ExecuteRequest(void) {
|
||||
if (deviceFlag) {
|
||||
tempC=0;
|
||||
remoteMode=2; /* set to remote mode */
|
||||
LscCmd(ser, "MODE:[remoteMode]");
|
||||
ERR_P(LscCmd(ser, "MODE:[remoteMode]"));
|
||||
if (!configuring) {
|
||||
str_copy(status, "configuring");
|
||||
configuring=1;
|
||||
@@ -895,8 +1072,6 @@ int mainBody(void)
|
||||
int i, iret, tdif;
|
||||
struct timeb tim1;
|
||||
|
||||
ERR_I(PeriodicTask());
|
||||
if (remoteMode==2) ERR_I(Settings());
|
||||
logfileWrite(logMask);
|
||||
|
||||
while (!quit) {
|
||||
@@ -914,17 +1089,27 @@ int mainBody(void)
|
||||
i=period*tdif+tim0.millitm;
|
||||
tim0.time+=i / 1000;
|
||||
tim0.millitm=i % 1000;
|
||||
if (tdif>1) {
|
||||
logfileOut(LOG_INFO ,"%d cycles lost\n", tdif-1);
|
||||
if (tdif>4) {
|
||||
logfileOut(LOG_MAIN ,"%d cycles lost\n", tdif-1);
|
||||
}
|
||||
|
||||
ERR_I(PeriodicTask());
|
||||
if (remoteMode==2) ERR_I(Settings());
|
||||
|
||||
return(0);
|
||||
OnError:
|
||||
if (0==strcmp(ErrMessage, "timeout")) {
|
||||
if (!noResp) logfileOut(LOG_MAIN ,"no response\n");
|
||||
per=period+10000; /* long period if no response */
|
||||
noResp=1;
|
||||
cryo.temp=0;
|
||||
samp.temp=0;
|
||||
if (noResp==1) { /* this is the second time we have no response */
|
||||
per=period+15000; /* long period if no response */
|
||||
cryo.temp=0;
|
||||
samp.temp=0;
|
||||
remoteMode=1;
|
||||
configuring=0;
|
||||
} else {
|
||||
logfileOut(LOG_ALL ,"no response\n");
|
||||
noResp=1;
|
||||
per=100; /* try again soon */
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
return(-1);
|
||||
@@ -948,14 +1133,14 @@ int main(int argc, char *argv[])
|
||||
samp.codChanged=1;
|
||||
samp.scale=1.0;
|
||||
|
||||
logMask=LOG_MAIN+LOG_INFO;
|
||||
logMask=LOG_MAIN;
|
||||
binDir="bin/";
|
||||
logDir="log/";
|
||||
serverId="tecs";
|
||||
host="lnsp26:4000/0";
|
||||
port=0;
|
||||
msecTmo=0;
|
||||
logfileOut(LOG_INFO ,"%s ", argv[0]);
|
||||
logfileOut(LOG_MAIN ,"%s ", argv[0]);
|
||||
for (i=1;i<argc;i++) {
|
||||
if (argv[i]!=NULL) {
|
||||
if (argv[i][0]=='-') {
|
||||
@@ -992,23 +1177,23 @@ int main(int argc, char *argv[])
|
||||
i++;
|
||||
logPeriod=atoi(argv[i]);
|
||||
} else {
|
||||
logfileOut(LOG_INFO ,"?");
|
||||
logfileOut(LOG_MAIN ,"?");
|
||||
}
|
||||
if (opt!=' ') logfileOut(LOG_INFO ,"-%c ", opt);
|
||||
logfileOut(LOG_INFO ,"%s ", argv[i]);
|
||||
if (opt!=' ') logfileOut(LOG_MAIN ,"-%c ", opt);
|
||||
logfileOut(LOG_MAIN ,"%s ", argv[i]);
|
||||
}
|
||||
}
|
||||
if (port==0) port=9753;
|
||||
if (msecTmo==0) msecTmo=1000;
|
||||
if (logPeriod==0) logPeriod=10;
|
||||
if (logPeriod==0) logPeriod=5;
|
||||
|
||||
str_copy(buf, logDir);
|
||||
str_append(buf, serverId);
|
||||
|
||||
str_copy(status, "starting up");
|
||||
logfileStatusBuf(status);
|
||||
logfileInit(buf, logIt, use_stdout, logIt && use_stdout);
|
||||
logfileOut(LOG_INFO ,"\n");
|
||||
logfile=logfileInit(buf, logIt, use_stdout, logIt && use_stdout);
|
||||
logfileOut(LOG_MAIN ,"\n");
|
||||
logfileWrite(logMask);
|
||||
|
||||
ERR_I(CocInitServer(1024, port));
|
||||
@@ -1021,19 +1206,25 @@ int main(int argc, char *argv[])
|
||||
CocFltFld(Testpoint, t1, CocRD);
|
||||
CocFltFld(Testpoint, t2, CocRD);
|
||||
CocFltFld(Testpoint, scale, CocRD);
|
||||
CocFltFld(Testpoint, min1, CocRD);
|
||||
CocFltFld(Testpoint, min2, CocRD);
|
||||
CocFltFld(Testpoint, max1, CocRD);
|
||||
CocFltFld(Testpoint, max2, CocRD);
|
||||
CocFltFld(Testpoint, tMin, CocRD);
|
||||
CocFltFld(Testpoint, tMax, CocRD);
|
||||
|
||||
CocStrFld(Testpoint, ch1, CocRD);
|
||||
CocStrFld(Testpoint, ch2, CocRD);
|
||||
|
||||
CocDefFlt(htr, CocRD);
|
||||
CocDefFlt(power, CocRD);
|
||||
CocDefFlt(power, powerFlag);
|
||||
CocDefFlt(prop, pidFlag);
|
||||
CocDefFlt(integ, pidFlag);
|
||||
CocDefFlt(deriv, pidFlag);
|
||||
CocDefFlt(tempC, setFlag);
|
||||
CocDefFlt(tempH, CocRD);
|
||||
CocDefFlt(tLimit, CocRD);
|
||||
|
||||
CocAlias(tempX,cryo.temp);
|
||||
CocAlias(tempP,samp.temp);
|
||||
CocAlias(set,tempC);
|
||||
CocDefFlt(maxShift, CocWR);
|
||||
|
||||
CocDefStr(device, deviceFlag);
|
||||
|
||||
@@ -1046,6 +1237,7 @@ int main(int argc, char *argv[])
|
||||
CocDefStr(intype, CocRD);
|
||||
CocDefStr(status, CocRD);
|
||||
CocDefStr(dlogfile, CocRD);
|
||||
CocDefStr(logfile, CocRD);
|
||||
|
||||
CocDefInt(cod1, CocRD);
|
||||
CocDefInt(cod2, CocRD);
|
||||
@@ -1059,6 +1251,7 @@ int main(int argc, char *argv[])
|
||||
CocDefInt(iAmp, CocRD);
|
||||
CocDefInt(iRange, CocRD);
|
||||
CocDefInt(remoteMode, CocRD);
|
||||
CocDefInt(htrst, CocRD);
|
||||
|
||||
CocDefInt(logPeriod, CocWR);
|
||||
CocDefInt(readTemp, CocWR);
|
||||
@@ -1068,19 +1261,33 @@ int main(int argc, char *argv[])
|
||||
CocDefInt(configuring, CocRD);
|
||||
CocDefInt(quit, CocWR);
|
||||
|
||||
CocAlias(tempX,cryo.temp);
|
||||
CocAlias(tempP,samp.temp);
|
||||
CocAlias(set,tempC);
|
||||
CocAlias(int,integ);
|
||||
|
||||
ERR_P(ser=SerOpen(host, msecTmo, idleHdl));
|
||||
ERR_I(iret=CocHandleRequests(100, 0));
|
||||
ftime(&tim0);
|
||||
tim=tim0.time;
|
||||
|
||||
if (period>1000) { /* round time */
|
||||
tim0.time=tim0.time-(tim0.time % (period/1000));
|
||||
tim0.millitm=0;
|
||||
}
|
||||
str_copy(dlogfile, logDir);
|
||||
str_append(dlogfile, serverId);
|
||||
str_append(dlogfile, ".dlog");
|
||||
logfileOut(LOG_INFO, "open data log file: %s\n", dlogfile);
|
||||
dlog_open_write_(dlogfile);
|
||||
logfileOut(LOG_MAIN, "open data log file: %s\n", dlogfile);
|
||||
ERR_I(iret=dlog_open_write_(dlogfile));
|
||||
if (iret==1) logfileOut(LOG_MAIN, "created new data log file\n");
|
||||
logfileWrite(logMask);
|
||||
|
||||
remoteMode=2;
|
||||
LscCmd(ser, "MODE?>remoteMode");
|
||||
prop=50;
|
||||
integ=20;
|
||||
deriv=0;
|
||||
LscCmd(ser, "PID?1>prop,integ,deriv");
|
||||
if (remoteMode!=2) configuring=0;
|
||||
per=1; /* advance fast when initializing */
|
||||
cntError=0;
|
||||
@@ -1094,6 +1301,7 @@ int main(int argc, char *argv[])
|
||||
if (cntError>0) cntError--;
|
||||
}
|
||||
}
|
||||
LogMinMax(0);
|
||||
logfileWrite(logMask);
|
||||
ERR_MSG("got quit command");
|
||||
OnError:
|
||||
|
||||
Reference in New Issue
Block a user