revision of TecsServer / treat "interest" correctly
This commit is contained in:
@ -1,11 +1,12 @@
|
||||
#---------------------------------------------------------------------------
|
||||
# Makefile for the TECS Client library
|
||||
# Makefile for the TECS Client library and TecsServer
|
||||
#
|
||||
# Markus Zolliker, March 2000
|
||||
#--------------------------------------------------------------------------
|
||||
OBJ= tecs_cli.o coc_client.o coc_util.o err_handling.o \
|
||||
str_util.o str_buf.o coc_server.o tecs_lsc.o tecs_serial.o \
|
||||
coc_logfile.o tecs_dlog.o sys_util.o
|
||||
LIBR_OBJ= coc_util.o err_handling.o str_util.o str_buf.o sys_util.o tecs_dlog.o
|
||||
CLI_OBJ= tecs_cli.o coc_client.o
|
||||
SERV_OBJ= tecs.o coc_server.o tecs_lsc.o tecs_serial.o coc_logfile.o
|
||||
TCLI_OBJ= tecs_client.o tecs_plot.o tecs_for.o sys_aunix.o sys_aunix_c.o
|
||||
|
||||
#------------ for DigitalUnix (add -DFORTIFY to CFLAGS for fortified version)
|
||||
CC=cc
|
||||
@ -19,12 +20,27 @@ CFLAGS= -std1 -g -warnprotos -I../ -I. -I../hardsup
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) -c $*.c
|
||||
|
||||
tecs: $(OBJ)
|
||||
libtecsl.a: $(LIBR_OBJ) $(CLI_OBJ)
|
||||
- rm libtecsl.a
|
||||
ar cr libtecsl.a $(OBJ)
|
||||
ar cr libtecsl.a $(LIBR_OBJ) $(CLI_OBJ)
|
||||
ranlib libtecsl.a
|
||||
- rm TecsServer
|
||||
$(CC) $(CFLAGS) -o TecsServer -g tecs.c fortify1.c -lm -L. -ltecsl -L../hardsup -lhlib -lfor
|
||||
|
||||
all: libtecsl.a bin/TecsServer tecs
|
||||
|
||||
tecs_plot.o: tecs_plot.f90
|
||||
f90 -c -g tecs_plot.f90
|
||||
|
||||
bin/TecsServer: $(LIBR_OBJ) $(SERV_OBJ)
|
||||
- rm bin/TecsServer
|
||||
$(CC) $(CFLAGS) -o bin/TecsServer -g $(LIBR_OBJ) $(SERV_OBJ) fortify1.c \
|
||||
-lm -L../hardsup -lhlib -lfor
|
||||
|
||||
tecs: $(TCLI_OBJ) $(CLI_OBJ) $(LIBR_OBJ)
|
||||
f77 -o tecs -g $(TCLI_OBJ) $(CLI_OBJ) $(LIBR_OBJ) \
|
||||
-L/data/lnslib/lib -lpgplot -so_archive -lreadline -ltermcap -lX11 -lXm
|
||||
|
||||
clean:
|
||||
rm *.o
|
||||
rm *.a
|
||||
- rm *.o
|
||||
- rm *.a
|
||||
- rm bin/TecsServer
|
||||
- rm tecs
|
||||
|
@ -137,7 +137,7 @@ int CocCmdWithRetry(CocConn *conn) {
|
||||
ErrShow("try again, error was");
|
||||
}
|
||||
ERR_P(err=str_get_str(conn->resbuf, NULL));
|
||||
if (*err!='\0') { ErrMsg(err); ErrTxt(": (response from server)",0 ); goto OnError; }
|
||||
if (*err!='\0') { ErrMsg(err); ErrTxt(": (response from server)",0 ); return(-2); }
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
}
|
||||
@ -145,6 +145,7 @@ int CocCmdWithRetry(CocConn *conn) {
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
||||
int CocSet(CocConn *conn, const char *name, const char *value) {
|
||||
int iret=-1;
|
||||
|
||||
assert(conn!=NULL);
|
||||
str_put_start(conn->cmdbuf);
|
||||
@ -153,35 +154,36 @@ int CocSet(CocConn *conn, const char *name, const char *value) {
|
||||
ERR_I(str_put_str(conn->cmdbuf, value));
|
||||
ERR_I(str_put_str(conn->cmdbuf, "]"));
|
||||
|
||||
ERR_I(CocCmdWithRetry(conn));
|
||||
ERR_I(iret=CocCmdWithRetry(conn));
|
||||
|
||||
ERR_I(str_get_end(conn->resbuf));
|
||||
return(0);
|
||||
|
||||
OnError: return(-1);
|
||||
OnError: return(iret);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
||||
int CocGetN(CocConn *conn, const char *name, char *value, int reslen) {
|
||||
int iret=-1;
|
||||
|
||||
assert(conn!=NULL);
|
||||
str_put_start(conn->cmdbuf);
|
||||
ERR_I(str_put_str(conn->cmdbuf, name));
|
||||
|
||||
ERR_I(CocCmdWithRetry(conn));
|
||||
ERR_I(iret=CocCmdWithRetry(conn));
|
||||
|
||||
ERR_P(str_nget_str(conn->resbuf, value, reslen));
|
||||
ERR_I(str_get_end(conn->resbuf));
|
||||
return(0);
|
||||
|
||||
OnError: return(-1);
|
||||
OnError: return(iret);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
||||
int CocCmd(CocConn *conn, const char *rwList)
|
||||
{ int setmode, i;
|
||||
{ int setmode, i, iret=-1;
|
||||
const char *t, *s;
|
||||
char nam[32];
|
||||
CocVar *var;
|
||||
@ -215,7 +217,7 @@ int CocCmd(CocConn *conn, const char *rwList)
|
||||
s=t+1;
|
||||
} while (*t!='\0');
|
||||
|
||||
ERR_I(CocCmdWithRetry(conn));
|
||||
ERR_I(iret=CocCmdWithRetry(conn));
|
||||
|
||||
/* read values */
|
||||
s=rwList;
|
||||
@ -239,7 +241,7 @@ int CocCmd(CocConn *conn, const char *rwList)
|
||||
ERR_I(str_get_end(conn->resbuf));
|
||||
return(0);
|
||||
|
||||
OnError: return(-1);
|
||||
OnError: return(iret);
|
||||
}
|
||||
|
||||
void CocCloseClient(CocConn *conn) {
|
||||
|
@ -169,7 +169,7 @@ int CocHandle1Request(int tmo_msec, int fd) {
|
||||
str_put_start(bufo); /* reset output */
|
||||
str_put_str(bufo, err); /* put error message */
|
||||
logfileOut(LOG_NET, " (%s)\n", err);
|
||||
logfileMask(LOG_NET);
|
||||
/* logfileMask(LOG_NET); */
|
||||
}
|
||||
ERR_SI(send(cl->fd, bufo->buf, bufo->wrpos, 0));
|
||||
}
|
||||
|
@ -85,9 +85,10 @@ void CocList() {
|
||||
|
||||
p=*varListHdl;
|
||||
while (p!=NULL) {
|
||||
printf("%s %d\n", p->name, p->type);
|
||||
printf("%s %d ", p->name, p->type);
|
||||
p=p->next;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
CocVar *CocFindVar1(CocVar *varList, const char *name) {
|
||||
@ -216,7 +217,7 @@ int CocPutVar(CocVar *varList, Str_Buf *buf, const char *name, int secure) {
|
||||
} else {
|
||||
adr=(char *)adr + (int)var->var;
|
||||
}
|
||||
if (secure) { /* check acces */
|
||||
if (secure) { /* check access */
|
||||
if (var->flag==&CocRD) ERR_MSG("variable is read only");
|
||||
}
|
||||
/* printf("put %s %d\n", name, (int)adr); */
|
||||
|
@ -69,6 +69,14 @@ void ErrShow(char *text)
|
||||
outrtn(outarg, "");
|
||||
}
|
||||
|
||||
void ErrShort(void) {
|
||||
if (outrtn==NULL) {
|
||||
outrtn=ErrOutFil;
|
||||
outarg=stdout;
|
||||
}
|
||||
outrtn(outarg, ErrMessage);
|
||||
}
|
||||
|
||||
void ErrSetOutRtn(void (*rtn)(), void *arg) {
|
||||
outrtn=rtn;
|
||||
outarg=arg;
|
||||
@ -89,6 +97,8 @@ void ERR_EXIT(char *text) {
|
||||
#define err_show_ err_show
|
||||
#define err_txt_ err_txt
|
||||
#define err_msg_ err_msg
|
||||
#define err_set_outrtn_ err_set_outrtn
|
||||
#define err_short_ err_short
|
||||
#endif
|
||||
|
||||
void err_show_(F_CHAR(text), int text_len) {
|
||||
@ -112,6 +122,9 @@ void err_msg_(F_CHAR(text), int text_len) {
|
||||
ErrMsg(buf);
|
||||
}
|
||||
|
||||
void errsetoutrtn_(void (*rtn)(), void *arg) {
|
||||
void err_set_outrtn_(void (*rtn)(), void *arg) {
|
||||
ErrSetOutRtn(rtn, arg);
|
||||
}
|
||||
void err_short_(void) {
|
||||
ErrShort();
|
||||
}
|
||||
|
@ -73,7 +73,8 @@ Global Variables (read only)
|
||||
void ErrTxt(char *text, int systemError);
|
||||
void ErrMsg(char *msg);
|
||||
void ErrCod(int code);
|
||||
void ErrShow(char *text);
|
||||
void ErrShow(char *text); /* write out error message with stack info */
|
||||
void ErrShort(void); /* write out short error message */
|
||||
void ERR_EXIT(char *text);
|
||||
void ErrLog(char *text);
|
||||
void ErrSetOutRtn(void (*rtn)(), void *arg);
|
||||
|
@ -11,7 +11,10 @@
|
||||
|
||||
static char *last_line = NULL;
|
||||
|
||||
char *readline (char *prompt);
|
||||
int lnblnk_(char *c, int c_len);
|
||||
char *readline(char *prompt);
|
||||
void add_history(char *line_read);
|
||||
int usleep(time_t delay);
|
||||
|
||||
void sys_rd_line_(char *cmd, int *retlen, char *prompt, int clen, int plen)
|
||||
{
|
||||
@ -42,7 +45,7 @@ void sys_rd_line_(char *cmd, int *retlen, char *prompt, int clen, int plen)
|
||||
|
||||
|
||||
void intcatch(int sig)
|
||||
{ printf("\nuse quit (normally ctrl-\) to interrupt\n");
|
||||
{ printf("\nuse quit (normally ctrl-\\) to interrupt\n");
|
||||
}
|
||||
|
||||
int called=0; /* env is valid only if called==1 */
|
||||
@ -56,10 +59,10 @@ void sighdl(int sig)
|
||||
}
|
||||
|
||||
void sys_err_hdl_(void errhdl0())
|
||||
{ errhdl=errhdl0; };
|
||||
{ errhdl=errhdl0; }
|
||||
|
||||
void sys_int_hdl_(void inthdl0(int sig))
|
||||
{ inthdl=inthdl0; };
|
||||
{ inthdl=inthdl0; }
|
||||
|
||||
void sys_try_(void proc())
|
||||
{ int sig, status;
|
||||
|
326
tecs/tecs.c
326
tecs/tecs.c
@ -25,8 +25,8 @@ static char *binDir=NULL;
|
||||
static char *logDir=NULL;
|
||||
|
||||
typedef struct {
|
||||
float t, min, max; /* temperatures */
|
||||
int sMin, sMax; /* reading status summary */
|
||||
float t, t1, t2, min, max; /* temperatures */
|
||||
int stat1, stat2; /* reading status summary */
|
||||
int present; /* sensor is present */
|
||||
int readStat; /* reading status */
|
||||
char ch[2]; /* channels */
|
||||
@ -61,8 +61,8 @@ Testpoint /* C standard guarantees initialization to zero */
|
||||
static float
|
||||
tempC, /* set T (for sample) */
|
||||
tempH, /* set T on heat exchanger */
|
||||
htr, /* heat power percentage */
|
||||
tLimit, power, /* heater parameters */
|
||||
htr, /* heater current percentage */
|
||||
tLimit, maxPower, /* 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 */
|
||||
@ -74,7 +74,7 @@ static int
|
||||
period=5000, /* default read interval (msec.) */
|
||||
logTime, /* next logging time */
|
||||
setFlag, /* temperature to be set */
|
||||
powerFlag, /* power to be set */
|
||||
maxPowerFlag, /* maxPower to be set */
|
||||
pidFlag, /* pid's to be set */
|
||||
saveTime, /* time for a CRVSAV command */
|
||||
noResp=2, /* no response */
|
||||
@ -84,6 +84,7 @@ static int
|
||||
remoteMode, /* 1: local, 2: remote */
|
||||
maxfld, /* last used display field */
|
||||
busy, /* busy after CRVSAV */
|
||||
relay, relay0, /* relay status */
|
||||
deviceFlag, /* device given via net */
|
||||
num, /* curve number */
|
||||
fld, /* field number */
|
||||
@ -112,6 +113,8 @@ static char
|
||||
head[64], /* curve header */
|
||||
intype[64], /* input configuration */
|
||||
chan[2], /* actual channel */
|
||||
alarms[20], /* alarm status */
|
||||
alarmList[4], /* alarm list */
|
||||
dlogfile[128];
|
||||
|
||||
static char
|
||||
@ -364,7 +367,7 @@ int instCurve(char *nam, char *channel, int dispFld) {
|
||||
|
||||
int configInput(void) {
|
||||
char *t;
|
||||
char buf[80], nam[16], nbuf[256];
|
||||
char buf[80], nam[16], nbuf[256], ch0[4], ch[4];
|
||||
int i, n, nn, dispFld;
|
||||
int retstat;
|
||||
char *ext;
|
||||
@ -390,12 +393,13 @@ int configInput(void) {
|
||||
t=strchr(buf, '\'');
|
||||
if (t==NULL) ERR_MSG("missing ' in table file");
|
||||
t++;
|
||||
n=1;
|
||||
if (tpoint==&samp) {
|
||||
sens3.present=0;
|
||||
sens4.present=0;
|
||||
i=sscanf(t, "%12s%d%d", nam, &nn, &n);
|
||||
str_copy(ch, "C");
|
||||
i=sscanf(t, "%12s %7s %7s", nam, ch0, ch);
|
||||
if (i<1) ERR_MSG("missing sensor name");
|
||||
str_copy(ch0, "CD");
|
||||
ext=".s";
|
||||
dispFld=2;
|
||||
} else {
|
||||
@ -403,23 +407,46 @@ int configInput(void) {
|
||||
sens2.present=0;
|
||||
tLow=0; tHigh=0;
|
||||
controlMode=0;
|
||||
i=sscanf(t, "%12s%d%d%d%f%d%f%f%f", nam, &n, &nn, &controlMode, &tLimit, &resist, &power, &tLow, &tHigh);
|
||||
str_copy(ch, "A");
|
||||
i=sscanf(t, "%12s %s %s %d %f %d %f %f %f", nam, ch, ch0, &controlMode, &tLimit, &resist, &maxPower, &tLow, &tHigh);
|
||||
if (i<7) ERR_MSG("missing some sensor parameters");
|
||||
if (!samp.manual && (NULL!=strchr(ch0,'A') || NULL!=strchr(ch0,'B'))) {
|
||||
samp.dirty=1; /* sample and heat exchanger are on main plug */
|
||||
samp.code=cryo.code;
|
||||
}
|
||||
str_copy(ch0, "AB");
|
||||
ext=".x";
|
||||
dispFld=1;
|
||||
}
|
||||
if (n<0 || n>2) ERR_MSG("illegal value for nsensor");
|
||||
n=strlen(ch);
|
||||
if (n==1) {
|
||||
if (ch[0]=='0') {
|
||||
n=0;
|
||||
} else if (ch[0]=='1') {
|
||||
ch[0]=ch0[0];
|
||||
} else if (ch[0]=='2') {
|
||||
str_copy(ch, ch0); n=2;
|
||||
}
|
||||
} else if (n>2) {
|
||||
ERR_MSG("no more than 2 channels per plug allowed");
|
||||
}
|
||||
if (n==0) return(0);
|
||||
|
||||
nam[strlen(nam)-1]='\0'; /* strip off quote */
|
||||
if (!tpoint->manual) { /* set device name */
|
||||
str_copy(tpoint->device, nam);
|
||||
concatDevice();
|
||||
}
|
||||
str_append(nam, ext);
|
||||
|
||||
if (ch[0]<'A' || ch[0]>'D') ERR_MSG("illegal channel");
|
||||
tpoint->sensor1->ch[0]=ch[0];
|
||||
tpoint->sensor1->ch[1]='\0';
|
||||
ERR_I(retstat=instCurve(nam, tpoint->sensor1->ch, dispFld));
|
||||
tpoint->sensor1->present=1;
|
||||
if (n==2) {
|
||||
if (ch[1]<'A' || ch[1]>'D') ERR_MSG("illegal channel");
|
||||
tpoint->sensor2->ch[0]=ch[1];
|
||||
tpoint->sensor2->ch[1]='\0';
|
||||
str_append(nam, "l");
|
||||
ERR_I(retstat=instCurve(nam, tpoint->sensor2->ch, dispFld+2));
|
||||
tpoint->sensor2->present=1;
|
||||
@ -468,11 +495,11 @@ int loadCache(void) {
|
||||
return(-1);
|
||||
}
|
||||
|
||||
float WeightedAverage(int presentH, int presentL, float tH, float tL) {
|
||||
float WeightedAverage(float tH, float tL) {
|
||||
float p,q;
|
||||
|
||||
if (presentH) {
|
||||
if (presentL) {
|
||||
if (tH!=0.0) {
|
||||
if (tL!=0.0) {
|
||||
if (tL<tLow) {
|
||||
return(tL);
|
||||
} else if (tH<tHigh) {
|
||||
@ -483,32 +510,60 @@ float WeightedAverage(int presentH, int presentL, float tH, float tL) {
|
||||
}
|
||||
}
|
||||
return(tH);
|
||||
} else if (presentL) {
|
||||
} else if (tL!=0.0) {
|
||||
return(tL);
|
||||
}
|
||||
return(0.0);
|
||||
}
|
||||
|
||||
int LogMinMax(int new) {
|
||||
char buf[256], bufs[256];
|
||||
int i, j, l, ls, logIt, stat;
|
||||
float tol, tmin[2], tmax[2];
|
||||
void LogMinMax(int new) {
|
||||
char buf[256];
|
||||
int i;
|
||||
SensorT *s1, *s2;
|
||||
|
||||
buf[0]='\0';
|
||||
for (i=0; i<2; i++) {
|
||||
tpoint=tpoints[i];
|
||||
s1=tpoint->sensor1;
|
||||
s2=tpoint->sensor2;
|
||||
tpoint->tMin = WeightedAverage(s1->min, s2->min) * tpoint->scale;
|
||||
tpoint->tMax = WeightedAverage(s1->max, s2->max) * tpoint->scale;
|
||||
s1->min=0;
|
||||
s1->max=0;
|
||||
s2->min=0;
|
||||
s2->max=0;
|
||||
}
|
||||
sprintf(buf, "@%.3f < T < %.3f K", cryo.tMin, cryo.tMax);
|
||||
if (samp.tMax>0.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;
|
||||
}
|
||||
|
||||
int ReadTemp(void) {
|
||||
char buf[256], bufs[256];
|
||||
int i, l, ls, stat;
|
||||
|
||||
readTemp=0;
|
||||
|
||||
l=0;
|
||||
ls=0;
|
||||
for (i=1; i<=4; i++) {
|
||||
sensor=sensors[i];
|
||||
sensor->sMin=0;
|
||||
sensor->sMax=0;
|
||||
sensor->stat1=0;
|
||||
sensor->stat2=0;
|
||||
if (sensor->present) {
|
||||
assert(l<128);
|
||||
sprintf(buf+l, "MDAT?[sens%d.ch]>sens%d.min,sens%d.max;", i, i, i);
|
||||
sprintf(buf+l, "MDAT?[sens%d.ch]>sens%d.t1,sens%d.t2;", i, i, i);
|
||||
l=strlen(buf);
|
||||
assert(ls<128);
|
||||
sprintf(bufs+ls, "MDATST?[sens%d.ch]>sens%d.sMin,sens%d.sMax;", i, i, i);
|
||||
sprintf(bufs+ls, "MDATST?[sens%d.ch]>sens%d.stat1,sens%d.stat2;", i, i, i);
|
||||
ls=strlen(bufs);
|
||||
}
|
||||
}
|
||||
@ -522,40 +577,42 @@ int LogMinMax(int new) {
|
||||
/* check for reading errors */
|
||||
for (i=1; i<=4; i++) {
|
||||
sensor=sensors[i];
|
||||
stat=sensor->sMin | sensor->sMax;
|
||||
if (stat != sensor->readStat) {
|
||||
sensor->readStat=stat;
|
||||
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 & 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 & 32) logfileOut(LOG_MAIN, "temp overrange %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==0) logfileOut(LOG_MAIN, "reading o.k. %s\n", sensor->ch);
|
||||
if (sensor->present) {
|
||||
stat=sensor->stat1 | sensor->stat2;
|
||||
if (stat != sensor->readStat) {
|
||||
sensor->readStat=stat;
|
||||
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 & 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 & 32) logfileOut(LOG_MAIN, "temp overrange %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==0) logfileOut(LOG_MAIN, "reading o.k. %s\n", sensor->ch);
|
||||
}
|
||||
if (stat==0) {
|
||||
sensor->t = (sensor->t1 + sensor->t2) * 0.5; /* mean of min and max */
|
||||
if (sensor->t1 < sensor->min || sensor->min==0.0) sensor->min = sensor->t1;
|
||||
if (sensor->t2 > sensor->max) sensor->max = sensor->t2;
|
||||
} else {
|
||||
sensor->t=0;
|
||||
}
|
||||
} else {
|
||||
sensor->t=0;
|
||||
}
|
||||
}
|
||||
|
||||
logIt=0;
|
||||
for (i=0; i<2; i++) {
|
||||
tpoint=tpoints[i];
|
||||
s1=tpoint->sensor1;
|
||||
s2=tpoint->sensor2;
|
||||
tpoint->tMin = WeightedAverage(s1->present, s2->present, s1->min, s2->min) * tpoint->scale;
|
||||
tpoint->tMax = WeightedAverage(s1->present, s2->present, s1->max, s2->max) * tpoint->scale;
|
||||
|
||||
cryo.temp=WeightedAverage(sens1.t, sens2.t)*cryo.scale;
|
||||
samp.temp=WeightedAverage(sens3.t, sens4.t)*samp.scale;
|
||||
if (samp.temp==0.0) samp.temp=cryo.temp;
|
||||
if (!deviceFlag
|
||||
&& !samp.dirty && samp.codDefined && !samp.codChanged
|
||||
&& !cryo.dirty && cryo.codDefined && !cryo.codChanged) {
|
||||
configuring=0;
|
||||
} else if (configuring==0 && remoteMode==2) {
|
||||
str_copy(status, "configuring");
|
||||
configuring=1;
|
||||
}
|
||||
sprintf(buf, "@%.3f < T < %.3f K", cryo.tMin, cryo.tMax);
|
||||
if (samp.tMax>0.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);
|
||||
}
|
||||
@ -565,7 +622,8 @@ int SetTemp(int switchOn) {
|
||||
float scale;
|
||||
|
||||
if (switchOn) {
|
||||
ERR_I(LogMinMax(1));
|
||||
ERR_I(ReadTemp());
|
||||
LogMinMax(1);
|
||||
logfileOut(LOG_MAIN, "set %.3f\n", tempC);
|
||||
}
|
||||
scale=cryo.scale;
|
||||
@ -606,67 +664,19 @@ int SetTemp(int switchOn) {
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
int ReadTemp(void) {
|
||||
char buf[256];
|
||||
int i, l;
|
||||
SensorT *sensor;
|
||||
|
||||
readTemp=0;
|
||||
|
||||
l=0;
|
||||
for (i=1; i<=4; i++) {
|
||||
sensor=sensors[i];
|
||||
if (sensor->present) {
|
||||
assert(l<128);
|
||||
sprintf(buf+l, "KRDG?[sens%d.ch]>sens%d.t;", i, i);
|
||||
l=strlen(buf);
|
||||
} else {
|
||||
sensor->t=0.0;
|
||||
}
|
||||
}
|
||||
if (l>0) {
|
||||
buf[l-1]='\0'; /* strip off ';' */
|
||||
ERR_P(LscCmd(ser, buf));
|
||||
}
|
||||
|
||||
cryo.temp=WeightedAverage(sens1.present, sens2.present, sens1.t, sens2.t)*cryo.scale;
|
||||
samp.temp=WeightedAverage(sens3.present, sens4.present, sens3.t, sens4.t)*samp.scale;
|
||||
if (samp.temp==0.0) samp.temp=cryo.temp;
|
||||
if (!deviceFlag
|
||||
&& !samp.dirty && samp.codDefined && !samp.codChanged
|
||||
&& !cryo.dirty && cryo.codDefined && !cryo.codChanged) {
|
||||
configuring=0;
|
||||
} else if (configuring==0 && remoteMode==2) {
|
||||
str_copy(status, "configuring");
|
||||
configuring=1;
|
||||
}
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
int PeriodicTask(void) {
|
||||
char buf[256], lbuf[16];
|
||||
char *next;
|
||||
char *next, *alms;
|
||||
int i, k;
|
||||
time_t putTim;
|
||||
float t3[3], p, d, w, t;
|
||||
|
||||
ERR_P(LscCmd(ser, "DIOST?>cod1,out1;DOUT 3,29;HTR?>htr;HTRST?>htrst;BUSY?>busy"));
|
||||
ERR_P(LscCmd(ser, "DIOST?>cod1,out1;DOUT 3,29;HTR?>htr;HTRST?>htrst;RELAYST?1>relay;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) {
|
||||
ERR_I(LogMinMax(0));
|
||||
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]");
|
||||
@ -726,8 +736,50 @@ int PeriodicTask(void) {
|
||||
noResp=0;
|
||||
}
|
||||
|
||||
if (relay) {
|
||||
if (alarmList[0]!='\0') {
|
||||
str_copy(buf, "ALARMST?*");
|
||||
buf[8]=alarmList[0];
|
||||
if (alarmList[1]!='\0') {
|
||||
str_append(buf,";ALARMST?*");
|
||||
buf[18]=alarmList[1];
|
||||
}
|
||||
str_append(buf, ";ALMRST");
|
||||
ERR_P(alms=LscCmd(ser, buf));
|
||||
if (0!=strcmp(alarms, alms)) {
|
||||
str_copy(buf, " ");
|
||||
if (alms[ 0]!='0' || alms[ 2]!='0') buf[0]=alarmList[0];
|
||||
if (alms[ 4]!='0' || alms[ 6]!='0') buf[1]=alarmList[1];
|
||||
if (0==strcmp(buf," ")) {
|
||||
logfileOut(LOG_MAIN, "No more alarms, but relay is on!\n");
|
||||
} else {
|
||||
logfileOut(LOG_MAIN, "Alarm on channel %s\n", buf);
|
||||
}
|
||||
str_copy(alarms, alms);
|
||||
}
|
||||
} else {
|
||||
if (!relay0) logfileOut(LOG_MAIN, "Relay is on!\n");
|
||||
alarms[0]='\0';
|
||||
}
|
||||
} else {
|
||||
if (relay0) logfileOut(LOG_MAIN, "No more alarms, relay is off\n");
|
||||
alarms[0]='\0';
|
||||
}
|
||||
relay0=relay;
|
||||
|
||||
ERR_I(ReadTemp());
|
||||
|
||||
if (htrst!=htrst0) {
|
||||
LogMinMax(0);
|
||||
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 (tim>=logTime) {
|
||||
i=0;
|
||||
if (sens1.present) {
|
||||
@ -748,7 +800,7 @@ int PeriodicTask(void) {
|
||||
}
|
||||
}
|
||||
if (tempC!=0 || htr!=0) {
|
||||
t3[2]=htr*htr*power*1e-4;
|
||||
t3[2]=htr*htr*maxPower*1e-4;
|
||||
i=3;
|
||||
} else {
|
||||
t3[2]=undef;
|
||||
@ -756,7 +808,7 @@ int PeriodicTask(void) {
|
||||
time(&putTim);
|
||||
if (i>0) ERR_I(dlog_put_(&putTim, &i, t3));
|
||||
logTime=(putTim/logPeriod+1)*logPeriod;
|
||||
if (tim>mmTime) ERR_I(LogMinMax(0));
|
||||
if (tim>mmTime) LogMinMax(0);
|
||||
}
|
||||
if (sens1.present && sens3.present && controlMode==2 && tempC!=0) {
|
||||
t=sens1.t;
|
||||
@ -884,29 +936,29 @@ int inputSettings(Testpoint *this) {
|
||||
OnError: return(-1);
|
||||
}
|
||||
|
||||
int SetPower(void) {
|
||||
int SetMaxPower(void) {
|
||||
int i, j;
|
||||
float pa, pr, pw, dif;
|
||||
|
||||
iAmp=1; iRange=0;
|
||||
if (power>0) {
|
||||
pa=resist*4; /* max. power */
|
||||
if (maxPower>0) {
|
||||
pa=resist*4; /* max. maxPower */
|
||||
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; }
|
||||
if (pr>maxPower) {
|
||||
if (pr/maxPower<dif) { dif=pr/maxPower; pw=pr; iAmp=i; iRange=j; }
|
||||
} else {
|
||||
if (power/pr<dif) { dif=power/pr; pw=pr; iAmp=i; iRange=j; }
|
||||
if (maxPower/pr<dif) { dif=maxPower/pr; pw=pr; iAmp=i; iRange=j; }
|
||||
}
|
||||
pr=pr/10;
|
||||
}
|
||||
pa=pa/4;
|
||||
}
|
||||
}
|
||||
power=pw;
|
||||
logfileOut(LOG_MAIN, "power %f\n", power, iAmp, iRange);
|
||||
maxPower=pw;
|
||||
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, "CLIMIT 1:[tLimit],0,0,[iAmp],[iRange]"));
|
||||
ERR_I(SetTemp(1));
|
||||
@ -969,7 +1021,6 @@ int Display(void) {
|
||||
|
||||
int Settings(void) {
|
||||
char nbuf[256], buf[256], *cfg, *p;
|
||||
char alarms[3];
|
||||
|
||||
cfg=NULL;
|
||||
if (cryo.dirty && cryo.codDefined || samp.dirty && samp.codDefined) {
|
||||
@ -979,26 +1030,26 @@ int Settings(void) {
|
||||
|
||||
ERR_P(LscCmd(ser, "ALARM A:0;ALARM B:0;ALARM C:0;ALARM D:0"));
|
||||
|
||||
alarms[0]='\0';
|
||||
alarms[1]='\0';
|
||||
alarms[2]='\0';
|
||||
alarmList[0]='\0';
|
||||
alarmList[1]='\0';
|
||||
alarmList[2]='\0';
|
||||
if (sens1.present) {
|
||||
ERR_I(SetPower());
|
||||
str_copy(buf, "ALARM [sens1.ch]:1,1,[tLimit],0,0,1;RELAY 1:1;BEEP:0");
|
||||
alarms[0]=sens1.ch[0];
|
||||
ERR_I(SetMaxPower());
|
||||
str_copy(buf, "ALARM [sens1.ch]:1,1,[tLimit],0,1,1;RELAY 1:1;BEEP:0");
|
||||
alarmList[0]=sens1.ch[0];
|
||||
if (sens3.present) {
|
||||
str_append(buf, ";ALARM [sens3.ch]:1,1,[tLimit],0,0,1");
|
||||
alarms[1]=sens3.ch[0];
|
||||
str_append(buf, ";ALARM [sens3.ch]:1,1,[tLimit],0,1,1");
|
||||
alarmList[1]=sens3.ch[0];
|
||||
}
|
||||
ERR_P(LscCmd(ser, buf));
|
||||
}
|
||||
|
||||
/* switch of unused channels */
|
||||
buf[0]='\0';
|
||||
if (NULL==strchr(alarms, 'A')) str_append(buf, ";ALARM A:0");
|
||||
if (NULL==strchr(alarms, 'B')) str_append(buf, ";ALARM B:0");
|
||||
if (NULL==strchr(alarms, 'C')) str_append(buf, ";ALARM C:0");
|
||||
if (NULL==strchr(alarms, 'D')) str_append(buf, ";ALARM D:0");
|
||||
if (NULL==strchr(alarmList, 'A')) str_append(buf, ";ALARM A:0");
|
||||
if (NULL==strchr(alarmList, 'B')) str_append(buf, ";ALARM B:0");
|
||||
if (NULL==strchr(alarmList, 'C')) str_append(buf, ";ALARM C:0");
|
||||
if (NULL==strchr(alarmList, 'D')) str_append(buf, ";ALARM D:0");
|
||||
if (buf[0]!='\0') ERR_P(LscCmd(ser, buf+1)); /* send without leading semicolon */
|
||||
|
||||
ERR_I(Display());
|
||||
@ -1033,9 +1084,9 @@ int ExecuteRequest(void) {
|
||||
|
||||
if (readTemp) ERR_I(ReadTemp());
|
||||
if (remoteMode==2) ERR_I(Settings());
|
||||
if (powerFlag) {
|
||||
powerFlag=0;
|
||||
ERR_I(SetPower());
|
||||
if (maxPowerFlag) {
|
||||
maxPowerFlag=0;
|
||||
ERR_I(SetMaxPower());
|
||||
}
|
||||
if (pidFlag) {
|
||||
pidFlag=0;
|
||||
@ -1245,15 +1296,15 @@ int main(int argc, char *argv[])
|
||||
CocDefPtr(sensor, SensorT);
|
||||
|
||||
CocFltFld(SensorT, t, CocRD);
|
||||
CocFltFld(SensorT, min, CocRD);
|
||||
CocFltFld(SensorT, max, CocRD);
|
||||
CocFltFld(SensorT, t1, CocRD);
|
||||
CocFltFld(SensorT, t2, CocRD);
|
||||
CocIntFld(SensorT, readStat, CocRD);
|
||||
CocIntFld(SensorT, sMin, CocRD);
|
||||
CocIntFld(SensorT, sMax, CocRD);
|
||||
CocIntFld(SensorT, stat1, CocRD);
|
||||
CocIntFld(SensorT, stat2, CocRD);
|
||||
CocStrFld(SensorT, ch, CocRD);
|
||||
|
||||
CocDefFlt(htr, CocRD);
|
||||
CocDefFlt(power, powerFlag);
|
||||
CocDefFlt(maxPower, maxPowerFlag);
|
||||
CocDefFlt(prop, pidFlag);
|
||||
CocDefFlt(integ, pidFlag);
|
||||
CocDefFlt(deriv, pidFlag);
|
||||
@ -1294,6 +1345,7 @@ int main(int argc, char *argv[])
|
||||
CocDefInt(controlMode, CocWR);
|
||||
CocDefInt(int2, CocWR);
|
||||
CocDefInt(busy, CocRD);
|
||||
CocDefInt(relay, CocRD);
|
||||
CocDefInt(serialNo, CocRD);
|
||||
CocDefInt(configuring, CocRD);
|
||||
CocDefInt(quit, CocWR);
|
||||
|
@ -46,6 +46,7 @@ int TeccGet(pTecsClient conn, float *temp) {
|
||||
|
||||
int TeccWait(pTecsClient conn) {
|
||||
int last, cnt;
|
||||
|
||||
last=0;
|
||||
cnt=0;
|
||||
do {
|
||||
@ -142,23 +143,25 @@ static pTecsClient conn=NULL;
|
||||
|
||||
int tecs_set_par_(F_CHAR(name), F_CHAR(par), int name_len, int par_len) {
|
||||
char nbuf[64], pbuf[256];
|
||||
int iret=-1;
|
||||
|
||||
STR_TO_C(nbuf, name);
|
||||
STR_TO_C(pbuf, par);
|
||||
|
||||
ERR_I(CocSet(conn, nbuf, pbuf));
|
||||
ERR_I(iret=CocSet(conn, nbuf, pbuf));
|
||||
|
||||
return(0);
|
||||
OnError: return(-1);
|
||||
OnError: return(iret);
|
||||
}
|
||||
|
||||
int tecs_get_par_(F_CHAR(name), F_CHAR(par), int name_len, int par_len) {
|
||||
char nbuf[64], pbuf[256];
|
||||
int iret=-1;
|
||||
|
||||
STR_TO_C(nbuf, name);
|
||||
ERR_I(CocGet(conn, nbuf, pbuf));
|
||||
ERR_I(iret=CocGet(conn, nbuf, pbuf));
|
||||
return(STR_TO_F(par, pbuf));
|
||||
OnError: return(-1);
|
||||
OnError: return(iret);
|
||||
}
|
||||
|
||||
int tecs_send_(F_CHAR(cmd), F_CHAR(reply), int cmd_len, int reply_len) {
|
||||
|
@ -106,7 +106,7 @@
|
||||
print *,'device temperature device'
|
||||
print *,'controlMode control on: 0: heat exchanger, '
|
||||
1 ,'1: sample, 2: second loop'
|
||||
print *,'power heater max. power'
|
||||
print *,'maxPower heater max. power'
|
||||
print *,'prop PID gain'
|
||||
print *,'int PID integration time: 1000/int sec'
|
||||
print *,'deriv PID derivation term'
|
||||
@ -116,7 +116,7 @@
|
||||
print *,'Read only parameters:'
|
||||
print *
|
||||
print *,'tX heat exchanger temperature'
|
||||
print *,'tP sample temperature'
|
||||
print *,'tS sample temperature'
|
||||
print *,'tempH set-point on regulation'
|
||||
print *,'tLimit temperature limit'
|
||||
print *,'htr heater current percentage'
|
||||
@ -167,7 +167,11 @@
|
||||
endif
|
||||
goto 1
|
||||
|
||||
19 call tecs_write_error(6)
|
||||
19 if (iret .eq. -2) then
|
||||
call tecs_write_msg(6)
|
||||
else
|
||||
call tecs_write_error(6)
|
||||
endif
|
||||
goto 1
|
||||
|
||||
91 if (iret .lt. 0) then
|
||||
|
@ -179,11 +179,27 @@ c------------------------------------------------------------------------------
|
||||
|
||||
external tecs_err_routine
|
||||
|
||||
call ErrSetOutRtn(tecs_err_routine, iolun)
|
||||
call err_set_outrtn(tecs_err_routine, iolun)
|
||||
call err_show('Error in TECS')
|
||||
end
|
||||
|
||||
|
||||
subroutine TECS_WRITE_MSG(IOLUN) !!
|
||||
!! ================================
|
||||
!!
|
||||
!! write out error message of last error and stack info
|
||||
!!
|
||||
implicit none
|
||||
|
||||
integer IOLUN !! logical unit for output
|
||||
|
||||
external tecs_err_routine
|
||||
|
||||
call err_set_outrtn(tecs_err_routine, iolun)
|
||||
call err_short
|
||||
end
|
||||
|
||||
|
||||
SUBROUTINE TECS_ERR_ROUTINE (LUN, TEXT)
|
||||
! =======================================
|
||||
!
|
||||
|
@ -42,6 +42,7 @@ subroutine tecs_plot(file)
|
||||
goto 99
|
||||
endif
|
||||
xmax=0
|
||||
x1=0
|
||||
|
||||
1 if (right .or. window==0 .or. live) then
|
||||
ntot=dlog_get(dmax, nset, tbase, -window*1.1, 0.0, undef, xd, yd)
|
||||
@ -55,7 +56,11 @@ subroutine tecs_plot(file)
|
||||
x2=maxval(xd(1:ntot))
|
||||
endif
|
||||
if (live) then
|
||||
x1=max(x2-window,xd(1))
|
||||
if (x1 .eq. 0) then
|
||||
x1=max(x2-window,xd(1))
|
||||
else
|
||||
window=x2-x1
|
||||
endif
|
||||
x2=max(x1+window,x2+min(window*0.2,max(window*0.01,300.)))
|
||||
elseif (window==0) then
|
||||
x1=minval(xd(1:ntot))
|
||||
@ -65,10 +70,12 @@ subroutine tecs_plot(file)
|
||||
endif
|
||||
else
|
||||
if (.not. zoom) then
|
||||
x1=x2-window
|
||||
if (window==0) then ! maximal
|
||||
x1=0
|
||||
x2=1e20
|
||||
else
|
||||
x2=(x1+x2+window)/2
|
||||
x1=x2-window
|
||||
endif
|
||||
endif
|
||||
ntot=dlog_get(dmax, nset, tbase, x1-window*0.1, x2+window*0.1, undef, xd, yd)
|
||||
@ -122,12 +129,13 @@ subroutine tecs_plot(file)
|
||||
enddo
|
||||
|
||||
ey=(ymax(rl)-ymin(rl))
|
||||
fy=abs(ymax(rl))
|
||||
if (rl==1) then
|
||||
ymax(rl)=ymax(rl)+ey*0.25
|
||||
ymin(rl)=ymin(rl)-ey*0.01
|
||||
ymax(rl)=ymax(rl)+max(fy*0.0075,ey*0.25)
|
||||
ymin(rl)=ymin(rl)-max(fy*0.005,ey*0.01)
|
||||
else
|
||||
ymax(rl)=ymax(rl)+ey*0.01
|
||||
ymin(rl)=ymin(rl)-ey*4
|
||||
ymax(rl)=ymax(rl)+max(fy*0.1,ey*0.01)
|
||||
ymin(rl)=ymin(rl)-max(fy,ey*4)
|
||||
endif
|
||||
if (live) then
|
||||
ymin(rl)=min(ymin(rl),max(0.0,ylast1-ey*0.4))
|
||||
@ -346,18 +354,26 @@ subroutine tecs_plot(file)
|
||||
call pgsci(1)
|
||||
call pgmtxt('T', 2.0, 0.9, 0.0, buf(l:))
|
||||
endif
|
||||
call get_key(key, 2, 10)
|
||||
if (xwin .and. .not. live) then
|
||||
call pgcurs(ex, ey, key)
|
||||
call must_purge
|
||||
else
|
||||
call get_key(key, 2, 10)
|
||||
endif
|
||||
if (key/=char(0)) goto 8
|
||||
goto 7
|
||||
elseif (key .eq. 'D') then
|
||||
window=min(7*24*3600,24*3600*max(1,numb))
|
||||
right=.true.
|
||||
x1=0
|
||||
elseif (key .eq. 'H') then
|
||||
window=min(7*24*3600,3600*max(1,numb))
|
||||
right=.true.
|
||||
x1=0
|
||||
elseif (key .eq. 'M') then
|
||||
window=min(7*24*3600,60*max(1,numb))
|
||||
right=.true.
|
||||
x1=0
|
||||
elseif (key .eq. 'L') then
|
||||
live=.not. live
|
||||
if (live) then
|
||||
|
@ -102,7 +102,7 @@
|
||||
strcat(pBueffel, argv[1]);
|
||||
strcat(pBueffel, " ");
|
||||
strtolower(pBueffel);
|
||||
if ( NULL==strstr(" log send list tolerance access errorhandler interrupt ", pBueffel)
|
||||
if ( NULL==strstr(" log send list tolerance access errorhandler interrupt interest ", pBueffel)
|
||||
&& NULL==strstr(" upperlimit lowerlimit safevalue currentvalue targetvalue ", pBueffel)
|
||||
) {
|
||||
|
||||
@ -116,7 +116,7 @@
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
} else { /* get case or command without parameter */
|
||||
} else { /* get case (or command without parameter) */
|
||||
if (0==strcasecmp(argv[1], "kill")) {
|
||||
iRet=CocSet(pMe->pData,"quit","1"); /* send quit flag */
|
||||
strcpy(result, "1");
|
||||
@ -334,7 +334,7 @@
|
||||
pMe->port=atoi(pPort);
|
||||
}
|
||||
if (pMe->port==0) {
|
||||
pPort="9750";
|
||||
pPort="9753";
|
||||
pMe->port=atoi(pPort);
|
||||
}
|
||||
str_append(pMe->server, " -p ");
|
||||
|
Reference in New Issue
Block a user