diff --git a/tecs/instr_hosts.c b/tecs/instr_hosts.c index 37be5f3d..66a457af 100644 --- a/tecs/instr_hosts.c +++ b/tecs/instr_hosts.c @@ -9,12 +9,13 @@ typedef struct { char *instr; char *host; char *user; int cod; } Instrument; static Instrument list[]={ { "DMC", "lnsa05.psi.ch", "DMC" , 1}, { "TOPSI", "lnsa07.psi.ch", "TOPSI" , 1}, - { "SANS", "lnsa10.psi.ch", "SANS" , 3}, + { "SANS", "lnsa10.psi.ch", "SANS" , 1}, { "HRPT", "lnsa11.psi.ch", "HRPT" , 1}, - { "TRICS", "lnsa13.psi.ch", "TRICS" , 1}, + { "TASP", "lnsa12.psi.ch", "TASP" , 1}, + { "TRICS", "lnsa18.psi.ch", "TRICS" , 1}, { "AMOR", "lnsa14.psi.ch", "AMOR" , 1}, { "FOCUS", "lnsa16.psi.ch", "FOCUS" , 1}, - { "TASP", "lnsa08.psi.ch", NULL , 0}, + { "RITA", "lnsa08.psi.ch", NULL , 0}, { "PREP", "lnsa01.psi.ch", NULL , 0}, { "TEST", "lnsa15.psi.ch", "lnslib", 2} }; @@ -54,9 +55,6 @@ int InstrHost(char *input, char *instr, char *host, char *user, char *pcod time(&t); tim=*localtime(&t); sprintf(pcod, "%02dlns%d", tim.tm_year % 100, tim.tm_mon/6+1); - } else if (list[j].cod == 3) { - str_ncpy(pcod, instr, pcod_len); - str_ncat(pcod, "ASQ", pcod_len); } else { str_ncpy(pcod, " ", pcod_len); } diff --git a/tecs/tecs.c b/tecs/tecs.c index f0bd3f83..853f9c2b 100644 --- a/tecs/tecs.c +++ b/tecs/tecs.c @@ -33,6 +33,7 @@ typedef struct { float t, t0, t1, t2, min, max, band; /* temperatures */ float scale; /* scale for extreme ranges */ float lim; /* range limit (used when two sensors present) */ + float alarm; int stat1, stat2; /* reading status summary */ int present; /* 0: sensor inactive, 1: sensor configured, -1: sensor parameters read */ int readStat; /* reading status */ @@ -82,7 +83,9 @@ static float set, /* set T */ setH, /* set T on heat exchanger */ htr, power=DATA_UNDEF, /* heater current percentage, heater power */ - tLimit, maxPower, /* heater parameters */ + tLimit, /* temperature limit */ + maxPower, /* max. Power */ + powFact=1, /* power factor (for external power supplies) */ tShift=0, /* setpoint shift */ full, /* full value for helium level */ prop, integ, deriv, /* pid */ @@ -95,6 +98,7 @@ static float aux=DATA_UNDEF, /* auxiliary value */ ramp=0, slope=0, + smooth=0, fbuf, /* float buffer */ r1, r2, /* temporary values */ tInt=0; /* integral time (sec.) for setpoint shift */ @@ -127,6 +131,7 @@ static int tim0, /* msec Time */ per, /* effective period */ mmInt, mmTime, /* interval and time for next min-max logging */ + lockAlarm, cntError, tableTime; /* last time when table was read */ @@ -142,9 +147,10 @@ static char head[64], /* curve header */ intype[64], /* input configuration */ chan[2], /* actual channel */ - alarms[20], /* alarm status */ - alarmChannels[4]=" ", - alarmList[4], /* alarm list */ + alarmStatus[20], /* alarm status */ + alarmChannels[8]="", + alarmList[8], /* enabled alarms */ + alarmHistory[8]="", config[256], /* special configuration commands */ helium[80], /* helium level status */ heUnits[4], /* helium level units */ @@ -253,13 +259,17 @@ int InstalCurve(SensorT *sensor, char *dev) { sens=sensor; str_copy(chan, sens->ch); sens->present=0; - if (sens->type=='x' || sens->type=='h') { + if (sens->type=='x' || sens->type=='h' || sens->type=='f') { if (chan[0]>='C') { - ERR_P(LscCmd(ser, "INTYPE [chan]:0,1,2,1,13;MNMX [chan]:1,3")); /* 7.5 V Range */ + ERR_P(LscCmd(ser, "INTYPE [chan]:0,1,2,1,13")); /* 7.5 V Range */ } else { - ERR_P(LscCmd(ser, "INTYPE [chan]:0,1,2,1,12;MNMX [chan]:1,3")); /* 5 V Range */ + ERR_P(LscCmd(ser, "INTYPE [chan]:0,1,2,1,12")); /* 5 V Range */ + } + if (sens->type=='f') { + ERR_P(LscCmd(ser, "MNMX [chan]:1,4;INCRV [chan]:0")); + } else { + ERR_P(LscCmd(ser, "MNMX [chan]:1,3;INCRV [chan]:0")); } - ERR_P(LscCmd(ser, "INCRV [chan]:0")); if (settingsFlag==0) sens->present=1; return 0; } @@ -356,6 +366,7 @@ int InstalCurve(SensorT *sensor, char *dev) { } else { /* header does not match -> download */ + logfileOut(LOG_MAIN, "%s\n%s\n", head, chead); if (num<=20) ERR_MSG("standard curve does not match"); if (busy) ERR_MSG("busy"); logfileOut(LOG_MAIN+LOG_STAT, "download curve %d\n", num); @@ -479,8 +490,14 @@ int PrepInput(char *label) { sensB.scale=1; sensA.lim=0; sensB.lim=0; + sensA.alarm=0; + sensB.alarm=0; + slope=0; + ramp=0; controlMode=0; + powFact=1; config[0]='\0'; + tLimit=310; } else { sensC.present=0; sensD.present=0; @@ -488,6 +505,8 @@ int PrepInput(char *label) { sensD.scale=1; sensC.lim=0; sensD.lim=0; + sensC.alarm=0; + sensD.alarm=0; } loop=1; resist=10; @@ -524,13 +543,14 @@ int PrepInput(char *label) { s=sensors[i]; typ=chans[i]; if (typ=='_') typ='\0'; - if (NULL==strchr("mnslhxt", typ)) ERR_MSG("unknown channel type code"); + if (NULL==strchr("mnslhxft", typ)) ERR_MSG("unknown channel type code"); if (typ!='\0') { s->present=-1; } s->type=typ; s->band=10; if (s->scale==0.0) s->scale=1.0; + if (s->alarm==0.0 && typ=='m' || typ=='s') s->alarm=tLimit; } if (!plug->manual) { /* set device name */ @@ -728,28 +748,33 @@ int ReadTemp(void) { s->stat1=0; s->stat2=0; if (s->present) { - if (s->type=='h' || s->type=='x') { - typ='S'; - } else { - typ='K'; - } if (doit) ERR_P(LscCmd(ser, buf)); str_substitute(buf , "KRDG?#>sens#.t0;MDAT?#>sens#.t1,sens#.t2;MDATST?#>sens#.stat1,sens#.stat2" , "#", s->ch); - buf[0]=typ; /* change KRDG to SRDG */ + if (s->type=='h' || s->type=='x') { + buf[0]='S'; /* change KRDG to SRDG */ + typ='S'; + } else if (s->type=='f') { + buf[0]='L'; /* change KRDG to LDAT */ + buf[1]='D'; + buf[2]='A'; + buf[3]='T'; + } doit=1; } } if (doit) { if (ramp!=0) { - str_append(buf, ";SETP?[loop]>tr"); - tr=tr*CtlScale(); - } else { - tr=set; + str_append(buf, ";SETP?[loop]>fbuf"); } str_append(buf, ";MNMXRST"); ERR_P(LscCmd(ser, buf)); + if (ramp!=0) { + tr=fbuf*CtlScale(); + } else { + tr=setH; + } if (tr==0) tr=DATA_UNDEF; } @@ -763,7 +788,7 @@ int ReadTemp(void) { logfileOut(LOG_MAIN, "magic %s: %g %g %g\n", s->ch, s->t1, s->t2, s->t0); } - stat=(s->stat1 | s->stat2) & (255-2); /* ignore "old reading" */ + stat=(s->stat1 | s->stat2) & (255-3); /* ignore "old reading" and "invalid reading" */ if (stat != s->readStat) { s->readStat=stat; err=LscReadStat(stat); @@ -849,7 +874,12 @@ int ReadTemp(void) { int ReadHeater(void) { if (loop==1) { - ERR_P(LscCmd(ser, "HTR?>htr;HTRST?>htrst;RELAYST?1>relay")); + if (relay) { + ERR_P(LscCmd(ser, "HTRST?>htrst")); + htr=0; + } else { + ERR_P(LscCmd(ser, "HTR?>htr;HTRST?>htrst;RELAYST?1>relay")); + } } else { ERR_P(LscCmd(ser, "AOUT?2>htr")); htrst=0; @@ -923,9 +953,9 @@ int SetTemp(int switchOn) { } if (ramp > 0 && set != 0) { /* take ramp from actual temperature if more than 1 % deviation */ - ERR_P(LscCmd(ser, "CSET?[loop]>,,cod1;SETP?[loop]>tr")); - tr=tr*scale; - if (cod1 == 0 || fabsf(ctlSens->t - tr) >= 0.01 * ctlSens->t) { + ERR_P(LscCmd(ser, "CSET?[loop]>,,cod1;SETP?[loop]>fbuf")); + tr=fbuf*scale; + if (cod1 == 0 || fabsf(ctlSens->t - tr) >= 0.1 * ctlSens->t) { fbuf = ctlSens->t; tr = fbuf * scale; ERR_P(LscCmd(ser, "SETP [loop],[fbuf];RAMP [loop],0,0;SETP [loop],[fbuf]")); @@ -940,7 +970,7 @@ int SetTemp(int switchOn) { ERR_P(LscCmd(ser, "ANALOG 2:0,0")); } setH=0; - } else if (switchOn) { /* switch on also when bad heater message and no alarms: || (htrst>=5 && relay==0)) */ + } else if (switchOn) { /* switch on also when bad heater message and no alarms: || (htrst>=5 && !relay)) */ ERR_P(LscCmd(ser, "CSET [loop]:[chan],1,1,0")); if (loop==1) { ERR_P(LscCmd(ser, "RANGE:[iRange]")); @@ -948,16 +978,23 @@ int SetTemp(int switchOn) { ERR_P(LscCmd(ser, "ANALOG 2:0,3")); } } else { - ERR_P(LscCmd(ser, "CSET [loop]:[chan],1")); + ERR_P(LscCmd(ser, "CSET?[loop]>,buf1,")); + if (buf1[0] != '1') { + ERR_P(LscCmd(ser, "CSET [loop]:[chan],1")); + } } showSet=(0!=strcmp(ctlSens->ch, controlChannel) || switchOn); str_copy(controlChannel, ctlSens->ch); if (ramp==0 || set==0) { - ERR_P(LscCmd(ser, "RAMP [loop],0,[ramp];SETP?[loop]>fbuf")); + ERR_P(LscCmd(ser, "RAMP?[loop]>buf1,")); + if (buf1[0] != '0') { + ERR_P(LscCmd(ser, "RAMP [loop]:0,[ramp]")); + } + ERR_P(LscCmd(ser, "SETP?[loop]>fbuf")); if (fabsf(setH-fbuf) >= (fbuf+setH)*1.0e-5) { ERR_P(LscCmd(ser, "SETP [loop]:[setH]")); if (controlMode!=2 && !showSet) { - logfileOut(LOG_MAIN, "set %g (on %s) (was changed)\n", set, ctlSens->ch); + logfileOut(LOG_MAIN, "set %g (on %s) (was changed %g -> %g)\n", set, ctlSens->ch, fbuf, setH); } } else { setH=fbuf; @@ -969,15 +1006,27 @@ int SetTemp(int switchOn) { } else { if (ramp < 0) ramp=-ramp; if (ramp < 0.1) ramp=0.1; - ERR_P(LscCmd(ser, "RAMP [loop]:1,[ramp];SETP [loop],[setH];SETP?[loop]>tr")); - tr=tr*scale; + if (showSet) { + ERR_P(LscCmd(ser, "RAMP [loop]:1,[ramp];SETP [loop],[setH];SETP?[loop]>fbuf")); + } else { + ERR_P(LscCmd(ser, "SETP?[loop]>fbuf")); + if (fabs(fbuf-setH) >= ramp*smooth) { + fbuf=ramp; + } else { + fbuf=sqrt(fabs(fbuf-setH)*ramp/smooth); + if (fbuf<0.1) fbuf=0.1; + } + ERR_P(LscCmd(ser, "RAMP [loop]:1,[fbuf];SETP [loop],[setH]")); + ERR_P(LscCmd(ser, "SETP?[loop]>fbuf")); + } + tr=fbuf*scale; if (showSet) { logfileOut(LOG_MAIN, "set %g (on %s) %g K/min, starting from %g\n", set, ctlSens->ch, ramp, tr); } } if (tr==0) tr=DATA_UNDEF; if (showSet) { - relay=0; + /* relay=0; */ ERR_I(ReadHeater()); } return 0; @@ -986,27 +1035,28 @@ int SetTemp(int switchOn) { int SetMaxPower(void) { int i, j; - float pa, pr, pw, dif; + float pa, pr, pw, dif, p; if (loop == 1) { iAmp=1; iRange=0; if (maxPower>0) { + p=maxPower/powFact; 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>maxPower) { - if (pr/maxPowerp) { + if (pr/ppresent<=0 || s->type=='h') return '\0'; if (s->type=='x') { return '3'; + } else if (s->type=='f') { + return '4'; } else { if (s->scale==1.0) { return '1'; @@ -1035,6 +1087,30 @@ char DisplayFmt(SensorT *s) { } } +int ConfigAlarms(void) { + int i, k; + SensorT *s; + + ERR_P(LscCmd(ser, "RELAY 1:1;BEEP:0")); + relay=0; + k=0; + for (i=0;i<4;i++) { + s=sensors[i]; + str_copy(buf1, s->ch); + if (s->present==1 && s->alarm>0) { + r1=s->alarm/s->scale; + ERR_P(LscCmd(ser, "ALARM [buf1]:1,1,[r1],0,1,1")); + alarmList[k]=s->ch[0]; + k++; + } else { + ERR_P(LscCmd(ser, "ALARM [buf1]:0")); /* switch off unused alarms */ + } + } + alarmList[k]='\0'; + return 0; + OnError: return -1; +} + int Settings(void) { char buf[256], typ; char flds[6], fmt[6]; @@ -1042,10 +1118,14 @@ int Settings(void) { int i,k,l; SensorT *s; - remoteMode=2; /* set to remote mode */ - ERR_P(LscCmd(ser, "MODE:[remoteMode]")); - ERR_P(LscCmd(ser, "PID?[loop]>prop,integ,deriv")); - ERR_P(LscCmd(ser, "RAMP?[loop]>,ramp")); + if (remoteMode!=2) { + remoteMode=2; /* set to remote mode */ + ERR_P(LscCmd(ser, "PID?[loop]>prop,integ,deriv")); + ERR_P(LscCmd(ser, "RAMP?[loop]>,ramp")); + ERR_P(LscCmd(ser, "MODE:[remoteMode]")); + } else { + ERR_P(LscCmd(ser, "PID [loop],[prop],[integ],[deriv]")); + } for (i=0; i<4; i++) { s=sensors[i]; plug=plugs[i/2]; @@ -1080,7 +1160,7 @@ int Settings(void) { samp.sensor2=s; } else if ('h'==typ) { heliumSens=s; - } else if ('x'==typ) { + } else if ('x'==typ || 'f'==typ) { auxSens=s; } else if ('t'==typ) { testSens=s; @@ -1097,38 +1177,19 @@ int Settings(void) { } if (settingsFlag) return 0; - str_copy(statusBuf, "alarms"); - /* alarms */ - alarmList[0]='\0'; - alarmList[1]='\0'; - alarmList[2]='\0'; s=cryo.sensor1; if (s!=NULL) { ERR_I(SetMaxPower()); - r1=tLimit/s->scale; - str_copy(buf1, s->ch); - str_copy(buf, "ALARM [buf1]:1,1,[r1],0,1,1;RELAY 1:1;BEEP:0"); - alarmList[0]=s->ch[0]; - if (samp.sensor1!=cryo.sensor1) { - s=samp.sensor1; - r2=tLimit/s->scale; - str_copy(buf2, s->ch); - str_append(buf, ";ALARM [buf2]:1,1,[r2],0,1,1"); - alarmList[1]=s->ch[0]; - } - ERR_P(LscCmd(ser, buf)); } - /* switch off alarm of unused channels */ - buf[0]='\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 */ + if (settingsFlag) return 0; + + str_copy(statusBuf, "alarms"); + ERR_I(ConfigAlarms()); if (settingsFlag) return 0; + str_copy(statusBuf, "display"); /* display */ @@ -1194,7 +1255,7 @@ int Settings(void) { logfileOut(LOG_MAIN, "load %s\n", config); p=cfg; while (p!=NULL) { - str_split(buf, p, '\n'); + p=str_split(buf, p, '\n'); ERR_P(LscCmd(ser, buf)); } FREE(cfg); @@ -1331,45 +1392,62 @@ int PeriodicTask(void) { if (relay || loop !=1) { if (alarmList[0]!='\0') { - str_copy(buf, "ALARMST?*"); - buf[8]=alarmList[0]; - if (alarmList[1]!='\0') { - str_append(buf,";ALARMST?*"); - buf[18]=alarmList[1]; + buf[0]='\0'; + for (k=0;(k<4) && alarmList[k]!='\0';k++) { + str_copy(buf1,";ALARMST?*"); + buf1[9]=alarmList[k]; + str_append(buf, buf1); } - str_append(buf, ";ALMRST"); - ERR_P(alms=LscCmd(ser, buf)); - if (0!=strcmp(alarms, alms)) { - str_copy(alarmChannels, " "); - if (alms[ 0]!='0' || alms[ 2]!='0') alarmChannels[0]=alarmList[0]; - if (alms[ 4]!='0' || alms[ 6]!='0') alarmChannels[1]=alarmList[1]; - if (0==strcmp(alarmChannels," ")) { - if (loop == 1) { - logfileOut(LOG_MAIN, "No more alarms, but relay is on!\n"); + ERR_P(alms=LscCmd(ser, buf+1)); /* send without leading semicolon */ + if (0!=strcmp(alarmStatus, alms)) { + str_copy(alarmStatus, alms); + alarmChannels[0]='\0'; + i=0; + for (k=0;(k<4) && alarmList[k]!='\0';k++) { + if (alms[k*4] != '0' || alms[k*4+2] != '0') { + alarmChannels[i]=alarmList[k]; + i++; + alarmChannels[i]='\0'; + if (NULL==strchr(alarmHistory, alarmList[k])) { /* if not yet in history */ + str_append(alarmHistory, alarmChannels+i-1); /* add to history */ + } + } + } + if (i==0) { + if (lockAlarm) { + logfileOut(LOG_MAIN, "No more active alarms, latching alarms: %s!\n", alarmHistory); } else { - logfileOut(LOG_MAIN, "No more alarms\n"); + alarmHistory[0]='\0'; + alarmChannels[0]='\0'; + logfileOut(LOG_MAIN, "No more active alarms\n"); + ERR_P(LscCmd(ser, "ALMRST")); relay=0; } } else { logfileOut(LOG_MAIN, "Alarm on channel %s\n", alarmChannels); - if (loop != 1) { - ERR_P(LscCmd(ser, "CSET 2:[chan],1,0,0")); - if (!relay) { - logfileOut(LOG_MAIN, "Switch off heater\n"); + if (!relay0 && set!=0) { + lockAlarm=1; + logfileOut(LOG_MAIN, "Switch off heater\n"); + if (loop==1) { /* turn on high relay manually, switch off heater and reset alarms */ + ERR_P(LscCmd(ser, "RELAY 1:2,1;RANGE:0;ALMRST")); + } else { + ERR_P(LscCmd(ser, "RELAY 1:2,1;ANALOG 2:0,0;ALMRST")); relay=1; } + } else { + ERR_P(LscCmd(ser, "ALMRST")); } } - str_copy(alarms, alms); + } else { + ERR_P(LscCmd(ser, "ALMRST")); } } else if (loop == 1) { if (!relay0) logfileOut(LOG_MAIN, "Relay is on!\n"); - alarms[0]='\0'; + alarmStatus[0]='\0'; } } else if (loop == 1) { - str_copy(alarmChannels, " "); - if (relay0) logfileOut(LOG_MAIN, "No more alarms, relay is off\n"); - alarms[0]='\0'; + alarmChannels[0]='\0'; + alarmStatus[0]='\0'; } relay0=relay; @@ -1393,11 +1471,11 @@ int PeriodicTask(void) { if (set!=0 && remoteMode==2) { if (cryo.sensor1!=samp.sensor1 && controlMode==2) { t=ctlSens->t; - d=(setH-t)/t-1.0; /* relative difference */ + d=(setH-t)/t; /* relative difference */ w=exp(-d*d*230); /* gaussian */ - if (w<0.1) tInt=0; /* reset when far from setpoint (more than 10 %) */ + /* if (w<0.1) tInt=0; reset when far from setpoint (more than 10 %) */ if (int2<1) int2=1; - if (tIntw) { p=w/tInt; } else { @@ -1533,7 +1611,13 @@ int DeviceHdl(int mode, void *base) { int SetHdl(int mode, void *base) { if (mode==COC_WR) { if (remoteMode!=2) { - ERR_MSG("controller is in local mode, set to remote first"); + ERR_MSG("controller is in local mode, enter 'remote' first"); + } else if (relay && set!=0) { + if (alarmChannels[0]!='\0') { + ERR_MSG("alarm is active, set prohibited"); + } else { + ERR_MSG("alarm was active, enter 'reset' first"); + } } else if (set<0) { set=0; } else if (set>tLimit) { @@ -1561,14 +1645,29 @@ int PidHdl(int mode, void *base) { OnError: return -1; } +int AlarmHdl(int mode, void *base) { + if (mode==COC_WR) { + return COC_DWR; + } else if (mode==COC_DWR) { + ERR_I(ConfigAlarms()); + } + return 0; + OnError: return -1; +} + int MaxPowerHdl(int mode, void *base) { if (mode==COC_WR) { - if (remoteMode==2) { - return COC_DWR; + if (remoteMode!=2) { + ERR_MSG("controller is in local mode, enter 'remote' first"); + } else if (relay) { + if (alarmChannels[0]!='\0') { + ERR_MSG("alarm is active, maxPower prohibited"); + } else { + ERR_MSG("alarm was active, enter 'reset' first"); + } } - ERR_MSG("controller is in local mode, set to remote first"); - return 0; - } else if (mode==COC_DWR && remoteMode!=2) { + return COC_DWR; + } else if (mode==COC_DWR && remoteMode==2) { ERR_I(SetMaxPower()); ERR_I(SetTemp(1)); } @@ -1655,9 +1754,13 @@ int ShowSensor(StrBuf *buf, SensorT *s, char *name, char *units, char lim) { } else { ERR_I(StrPut(buf, LscReadStat(s->readStat), StrNONE)); } - if (s==ctlSens && tr!=DATA_UNDEF) { + if (s==ctlSens) { ERR_I(StrPut(buf, ", setpoint", '=')); - ERR_I(PutFloat(buf, 5, tr)); + if (tr==DATA_UNDEF) { + ERR_I(PutFloat(buf, 5, 0.0)); + } else { + ERR_I(PutFloat(buf, 5, tr)); + } ERR_I(StrPut(buf, " ", StrNONE)); ERR_I(StrPut(buf, units, StrNONE)); } @@ -1704,45 +1807,51 @@ int StatusHdl(int mode, void *base) { goto EndStatus; } if (remoteMode==1) { - ERR_I(StrPut(&buf, "LOCAL mode, use command 'remote' to enable remote control", '\n')); + ERR_I(StrPut(&buf, "LOCAL mode, enter 'remote' to enable remote control", '\n')); } ERR_I(StrPut(&buf, "device:", ' ')); ERR_I(StrPut(&buf, device, StrNONE)); if (set==0) { - ERR_I(StrPut(&buf, "\nheater off (set=0)", StrNONE)); + ERR_I(StrPut(&buf, "\nheater off,",' ')); } else { ERR_I(StrPut(&buf, "\ntarget", '=')); ERR_I(PutFloat(&buf, 5, set)); if (ramp==0 || tr==setH) { - ERR_I(StrPut(&buf, " K", StrNONE)); + ERR_I(StrPut(&buf, " K,", ' ')); } else { ERR_I(StrPut(&buf, " K ramping at", ' ')); ERR_I(PutFloat(&buf, 4, ramp)); - ERR_I(StrPut(&buf, " K/min", StrNONE)); - } - if (relay) { - ERR_I(StrPut(&buf, ", heater off (alarm)", StrNONE)); - } else if (htrst!=0) { - ERR_I(StrPut(&buf, ",", ' ')); - ERR_I(StrPut(&buf, LscHtrStat(htrst), StrNONE)); - } else { - if (power!=DATA_UNDEF) { - ERR_I(StrPut(&buf, ", htr power", '=')); - if (power>=0.5) { - ERR_I(PutFloat(&buf, 3, power)); - ERR_I(StrPut(&buf, " W, htr current", '=')); - } else { - ERR_I(PutFloat(&buf, 3, power*1000)); - ERR_I(StrPut(&buf, " mW, htr current", '=')); - } - ERR_I(PutFloat(&buf, 4, htr)); - ERR_I(StrPut(&buf, " ", '%')); - } + ERR_I(StrPut(&buf, " K/min,", ' ')); } } - if (0!=strcmp(alarmChannels," ")) { - ERR_I(StrPut(&buf, "\nalarm on channel",' ')); - ERR_I(StrPut(&buf, alarmChannels, StrNONE)); + if (relay) { + if (alarmChannels[0]!='\0') { + ERR_I(StrPut(&buf, "alarm on channel",' ')); + ERR_I(StrPut(&buf, alarmChannels, StrNONE)); + } else if (alarmHistory[0]!='\0') { + ERR_I(StrPut(&buf, "alarm was on channel", ' ')); + ERR_I(StrPut(&buf, alarmHistory, ',')); + ERR_I(StrPut(&buf, " (enter 'reset' to confirm)", StrNONE)); + } else { + ERR_I(StrPut(&buf, "alarm",' ')); + } + } else if (htrst!=0) { + ERR_I(StrPut(&buf, LscHtrStat(htrst), StrNONE)); + } else { + if (power!=DATA_UNDEF) { + ERR_I(StrPut(&buf, "htr power", '=')); + if (power>=0.5) { + ERR_I(PutFloat(&buf, 3, power)); + ERR_I(StrPut(&buf, " W, htr current", '=')); + } else { + ERR_I(PutFloat(&buf, 3, power*1000)); + ERR_I(StrPut(&buf, " mW, htr current", '=')); + } + ERR_I(PutFloat(&buf, 4, htr)); + ERR_I(StrPut(&buf, " ", '%')); + } else { + ERR_I(StrPut(&buf, "set=0", StrNONE)); + } } tM=0; tS=0; if (cryo.sensor1!=NULL) { @@ -1786,16 +1895,39 @@ EndStatus: int RemoteHdl(int mode, void *base) { if (mode==COC_WR) { - return COC_DRD; - } else if (mode==COC_DRD) { + return COC_DWR; + } else if (mode==COC_DWR) { ERR_P(LscCmd(ser, "MODE:[remoteMode]")); } return 0; OnError: return -1; } -int ExecuteRequest(void) { +int RelayHdl(int mode, void *base) { + if (mode==COC_WR) { + if (alarmChannels[0]!='\0') ERR_MSG("alarm is still active"); + return COC_DWR; + } else if (mode==COC_DWR) { + if (relay) { + ERR_P(LscCmd(ser, "RELAY 1:2,1")); + if (alarmHistory[0]=='\0') { + str_copy(alarmHistory, "X"); + } + } else { + alarmHistory[0]='\0'; + alarmStatus[0]='\0'; + ERR_P(LscCmd(ser, "ALMRST;RELAY 1:1")); + logfileOut(LOG_MAIN, "reset alarms\n"); + relay0=0; + lockAlarm=0; + set=0; + } + } + return 0; + OnError: return -1; +} +int ExecuteRequest(void) { if (readTemp) ERR_I(ReadTemp()); ERR_I(CocCallHandlers()); while (settingsFlag==1) { @@ -1844,7 +1976,7 @@ int MainBody(void) { per=1000; /* 1 sec */ cryo.temp=0; samp.temp=0; - remoteMode=1; + /* remoteMode=1; */ noResp=3; } else if (noResp < 2) { logfileOut(LOG_ALL ,"no response\n"); @@ -1953,6 +2085,7 @@ int main(int argc, char *argv[]) { CocFltFld(SensorT, t2, RD); CocFltFld(SensorT, lim, RD); CocFltFld(SensorT, scale, RD); + CocFltFld(SensorT, alarm, RW); CocHdl(AlarmHdl); CocIntFld(SensorT, readStat, RD); CocIntFld(SensorT, stat1, RD); CocIntFld(SensorT, stat2, RD); @@ -1965,6 +2098,8 @@ int main(int argc, char *argv[]) { CocDefFlt(deriv, RW); CocHdl(PidHdl); CocDefFlt(set, RW); CocHdl(SetHdl); CocDefFlt(ramp, RW); CocHdl(SetHdl); + CocDefFlt(smooth, RW); + CocDefFlt(powFact, RW); CocDefFlt(htr, RD); CocDefFlt(power, RD); CocDefFlt(setH, RD); @@ -1980,6 +2115,8 @@ int main(int argc, char *argv[]) { CocDefFlt(fbuf, RD); CocDefFlt(r1, RD); CocDefFlt(r2, RD); + CocDefFlt(tShift, RW); + CocDefFlt(tInt, RW); CocDefPtr(clData, ClientData); CocStrFld(ClientData, cmd, RW); CocHdl(SendHdl); @@ -2017,6 +2154,7 @@ int main(int argc, char *argv[]) { CocDefInt(iAmp, RD); CocDefInt(iRange, RD); CocDefInt(remoteMode, RW); CocHdl(RemoteHdl); + CocDefInt(relay, RW); CocHdl(RelayHdl); CocDefInt(htrst, RD); CocDefInt(loop, RD); CocDefInt(rdTim, RD); @@ -2027,7 +2165,6 @@ int main(int argc, char *argv[]) { CocDefInt(controlMode, RW); CocDefInt(int2, RW); CocDefInt(busy, RD); - CocDefInt(relay, RD); CocDefInt(serialNo, RD); CocDefInt(quit, RW); diff --git a/tecs/tecs_client.f b/tecs/tecs_client.f index d8a11779..35bd6e31 100644 --- a/tecs/tecs_client.f +++ b/tecs/tecs_client.f @@ -58,16 +58,18 @@ print *,'Tecs Client' print *,'-----------' print * - print *,' show temperature and device' print *,'set set temperature' print *,'send direct command to LSC340' print *,'device set cryo device' print *,' show parameter' print *,' set parameter' + print * + print *,' show summary' print *,'plot chart for temperature and ' 1 ,' var = P (default), He, Aux' print *,'log show last n lines of logfile' print *,'remote set to remote mode' + print *,'reset reset alarms' print *,'kill shut down TecsServer' print *,'restart restart TecsServer' print *,'exit,quit exit tecs client' @@ -83,6 +85,7 @@ cmd=' ' k=0 do j=1,l + if (k .gt. 0 .and. line(j:j) .eq. '=') line(j:j)=' ' if (line(j:j) .gt. ' ') then k=k+1 cmd(k:k)=line(j:j) @@ -136,6 +139,9 @@ else if (cmd .eq. 'remote') then iret=tecs_set_par('remoteMode', '2', 2) if (iret .lt. 0) goto 19 + else if (cmd .eq. 'reset') then + iret=tecs_set_par('relay', '0', 2) + if (iret .lt. 0) goto 19 elseif (cmd .eq. 'rwacs') then iret=tecs_rights(1) if (iret .lt. 0) goto 19 @@ -158,12 +164,13 @@ print *,'controlMode control on: 0: heat exchanger, ' 1 ,'1: sample, 2: second loop' print *,'maxPower heater max. power' + print *,'ramp ramp in K/min. (0: no ramp)' print *,'prop PID gain' print *,'int PID integration time: 1000/int sec' print *,'deriv PID derivation term' print *,'maxShift maximum (set-tempH) for controlMode=2' print *,'int2 integration time (sec) for controlMode=2' - print *,'remoteMode 1: local, 2: remote' +! print *,'remoteMode 1: local, 2: remote' print * print *,'Read only parameters:' print * diff --git a/tecs/tecs_plot.f90 b/tecs/tecs_plot.f90 index 4928ce99..68ac8c76 100644 --- a/tecs/tecs_plot.f90 +++ b/tecs/tecs_plot.f90 @@ -171,7 +171,7 @@ subroutine tecs_plot(auxpar) sel2=sel endif do rl=1,2 - if (mode==zoom) then + if (mode==zoom .and. rl==1) then ymin(1)=y1 ymax(1)=y2 else @@ -361,7 +361,8 @@ subroutine tecs_plot(auxpar) numl=0 numb=' ' -7 if (mode==live) then +7 ex=undef + if (mode==live) then ! if (device(1:1)=='X') then ! call pgmtxt('T', 0.5, 0.0, 0.0, 'LIVE MODE (click on text window before pressing any further key)') ! endif @@ -369,7 +370,7 @@ subroutine tecs_plot(auxpar) i=chartperiod-mod(myc_now(), chartperiod) call get_cursor(ex, ey, key, -i) - do while (key == char(0)) ! no key pressed + do while (key == char(0) .or. key == ' ') ! no key or space key pressed iret=tecs_get_mult(pars, t, nset, yy1) if (iret<0) goto 99 tim1=t-tbase @@ -428,7 +429,7 @@ subroutine tecs_plot(auxpar) if (mode==zoom) then if (ex==undef) then ex=(x1+x2)/2 - ey=(min(y1,ymax(1))+max(y1,ymin(1)))/2 + ey=(min(y2,ymax(1))+max(y1,ymin(1)))/2 end if fx=max(winmin,x2-x1) fy=max(y2-y1,1e-3,y2*1e-5) @@ -532,6 +533,7 @@ subroutine tecs_plot(auxpar) elseif (key == 'S') then sel=sel+1 if (sel > tmax) sel=0 + if (mode==zoom) mode=0 elseif (key == 'C') then auxsel=auxsel+1 if (auxsel > amax) auxsel=1 @@ -553,18 +555,16 @@ subroutine tecs_plot(auxpar) read(*,'(a)') filnam open(lund, file=filnam, status='unknown', carriagecontrol='list') - gap=.false. - do j=1,nset - if (j == 1) then - write(lund, *) ' time [h]',char(9),' Tm [K]' - elseif (j == 2) then - write(lund,*) - write(lund, *) ' time [h]',char(9),' Ts [K]' + l=0 + i2=0 + do i1=1,nset + if (i1 > nset-naux) then + j=i1 else - write(lund,*) - write(lund, *) ' time [h]',char(9), ' ',trim(parnam(j)) + j=nset-i1+(1-naux) endif + gap=.false. do i=1,retLen(j) if (yd(i,j)==undef) then if (gap) then @@ -572,13 +572,20 @@ subroutine tecs_plot(auxpar) gap=.false. endif else + if (i2/=i1) then + if (l > 0) write(lund, *) + write(lund, *) ' time [h]',char(9), ' ',trim(parnam(j)) + l=l+1 + i2=i1 + endif write(lund, '(f9.4,a,f9.4)') xd(i,j)/3600., char(9), max(-999.,min(9999.,yd(i,j))) + l=l+1 gap=.true. endif enddo enddo close(lund) - print *, retLen(1)+1, ' lines written to ',filnam(1:48) + print *, l, ' lines written to ',filnam(1:48) endif end subroutine