- Added makefile_slinux

- Changed mesure to be a silver bullet
This commit is contained in:
koennecke
2005-03-03 13:54:22 +00:00
parent 000bb7b4a8
commit 835177dc0a
7 changed files with 137 additions and 68 deletions

View File

@ -580,6 +580,7 @@ pCounterDriver MakeECBCounter(char *ecb){
self->Get = ECBGet; self->Get = ECBGet;
self->Send = ECBSend; self->Send = ECBSend;
self->KillPrivate = NULL; self->KillPrivate = NULL;
self->iNoOfMonitors = 8;
self->pData = pPriv; self->pData = pPriv;
return self; return self;

View File

@ -910,6 +910,11 @@ static int ECBGetDriverPar(void *pData,char *name, float *value){
assert(self); assert(self);
if(strcmp(name,"ecbindex") == 0){
*value = self->ecbIndex;
return 1;
}
par = ObParFind(self->driverPar,name); par = ObParFind(self->driverPar,name);
if(par != NULL){ if(par != NULL){
*value = par->fVal; *value = par->fVal;

118
el734hp.c
View File

@ -18,6 +18,7 @@
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <fortify.h> #include <fortify.h>
#include <time.h>
#include <sics.h> #include <sics.h>
#include <modriv.h> #include <modriv.h>
#include <rs232controller.h> #include <rs232controller.h>
@ -58,6 +59,7 @@
int posCount; int posCount;
int runCount; int runCount;
char errorReply[80]; char errorReply[80];
time_t valueExpiry;
} EL734Driv, *pEL734Driv; } EL734Driv, *pEL734Driv;
/*------------------- error codes ----------------------------------*/ /*------------------- error codes ----------------------------------*/
#define BADADR -1 #define BADADR -1
@ -115,6 +117,11 @@ static int EL734GetPos(void *pData, float *fPos){
self = (pEL734Driv)pData; self = (pEL734Driv)pData;
assert(self); assert(self);
if(time(NULL) < self->valueExpiry){
*fPos = self->lastValue;
return OKOK;
}
snprintf(pCommand,79,"u %d\r",self->iMotor); snprintf(pCommand,79,"u %d\r",self->iMotor);
status = transactRS232(self->controller,pCommand,strlen(pCommand), status = transactRS232(self->controller,pCommand,strlen(pCommand),
pReply,79); pReply,79);
@ -127,6 +134,7 @@ static int EL734GetPos(void *pData, float *fPos){
} }
sscanf(pReply,"%f",fPos); sscanf(pReply,"%f",fPos);
self->lastValue = *fPos; self->lastValue = *fPos;
self->valueExpiry = time(NULL) + 3;
return OKOK; return OKOK;
} }
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
@ -212,39 +220,6 @@ static int decodeMSR(pEL734Driv self, int msr){
} }
return HWBusy; return HWBusy;
/* inserted above line and commented out lines below M.Zolliker Sep 2004
we do not stop when a minor error message occurs, but treat these with oredMsr
if(msr & 0x10){
self->errorCode = LOWLIM;
return HWFault;
} else if(msr & 0x20){
self->errorCode = HILIM;
return HWFault;
} else if(msr & 0x80){
self->errorCode = RUNFAULT;
return HWPosFault;
} else if(msr & 0x200){
self->errorCode = POSFAULT;
return HWPosFault;
} else if(msr & 0x1000){
self->errorCode = BADCUSHION;
return HWFault;
} else if(msr & 0x8){
self->errorCode = BADSTP;
return HWFault;
} else if(msr & 0x40) {
self->errorCode = BADSTP;
return HWFault;
} else if(msr & 0x100){
self->errorCode = POSFAULT;
return HWFault;
} else if(msr & 0x400){
self->errorCode = POSFAULT;
return HWFault;
} else {
return HWBusy;
}
*/
} }
} }
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
@ -268,6 +243,7 @@ static int EL734Status(void *pData){
} }
sscanf(pReply,"%x",&msr); sscanf(pReply,"%x",&msr);
self->oredMsr |= msr; self->oredMsr |= msr;
self->valueExpiry = -1;
return decodeMSR(self,msr); return decodeMSR(self,msr);
} }
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
@ -336,7 +312,7 @@ static void EL734Error(void *pData, int *iCode, char *error, int errLen){
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
static int EL734Fix(void *pData, int iCode, float fValue){ static int EL734Fix(void *pData, int iCode, float fValue){
pEL734Driv self = NULL; pEL734Driv self = NULL;
int status, msr; int status, msr, i, len = 49;
char pCommand[50],pReply[80]; char pCommand[50],pReply[80];
self = (pEL734Driv)pData; self = (pEL734Driv)pData;
@ -345,10 +321,30 @@ static int EL734Fix(void *pData, int iCode, float fValue){
switch(iCode){ switch(iCode){
case BADADR: case BADADR:
case BADCMD: case BADCMD:
case TIMEOUT:
case BADPAR: case BADPAR:
case BADBSY: case BADBSY:
return MOTREDO; return MOTREDO;
case TIMEOUT:
for(i = 0; i < 3; i++){
len = 49;
status = readRS232TillTerm(self->controller,pReply,&len);
if(status == 1){
return MOTREDO;
}
}
/*
If nothing can be read, the only fixable cause is a network breakdown
Try to fix this. If this does not work: give up
*/
closeRS232(self->controller);
SicsWait(60);
status = initRS232(self->controller);
if(status != 1){
return MOTFAIL;
} else {
return MOTREDO;
}
break;
case BADLOC: case BADLOC:
snprintf(pCommand,49,"RMT 1\r"); snprintf(pCommand,49,"RMT 1\r");
transactRS232(self->controller,pCommand,strlen(pCommand),pReply,79); transactRS232(self->controller,pCommand,strlen(pCommand),pReply,79);
@ -363,6 +359,18 @@ static int EL734Fix(void *pData, int iCode, float fValue){
self->runCount = 0; self->runCount = 0;
self->posCount = 0; self->posCount = 0;
return MOTOK; return MOTOK;
case BADSEND:
/*
network problem: try to reopen connection
*/
closeRS232(self->controller);
SicsWait(60);
status = initRS232(self->controller);
if(status != 1){
return MOTFAIL;
} else {
return MOTREDO;
}
} }
return MOTFAIL; return MOTFAIL;
} }
@ -457,7 +465,7 @@ static void KillEL734(void *pData){
/*------------------------------------------------------------------*/ /*------------------------------------------------------------------*/
MotorDriver *CreateEL734HP(SConnection *pCon, int argc, char *argv[]){ MotorDriver *CreateEL734HP(SConnection *pCon, int argc, char *argv[]){
pEL734Driv pNew = NULL; pEL734Driv pNew = NULL;
int motor, status; int motor, status, i, success;
prs232 controller = NULL; prs232 controller = NULL;
char pCommand[50],pReply[80], pError[255]; char pCommand[50],pReply[80], pError[255];
@ -509,31 +517,39 @@ MotorDriver *CreateEL734HP(SConnection *pCon, int argc, char *argv[]){
connection will already have been set up, read limits connection will already have been set up, read limits
*/ */
snprintf(pCommand,49,"h %d\r",pNew->iMotor); snprintf(pCommand,49,"h %d\r",pNew->iMotor);
status = transactRS232(pNew->controller, pCommand,strlen(pCommand), success = 0;
for(i = 0; i < 3; i++){
status = transactRS232(pNew->controller, pCommand,strlen(pCommand),
pReply,79); pReply,79);
if(status != 1){ if(status != 1){
SCWrite(pCon,"ERROR: failed to read HW limits, defaulting..",eError); getRS232Error(status,pReply,79);
getRS232Error(status,pReply,79); snprintf(pError,255,"ERROR: %s",pReply);
snprintf(pError,255,"ERROR: %s",pReply); SCWrite(pCon,pError,eError);
SCWrite(pCon,pError,eError); closeRS232(pNew->controller);
pNew->fLower = -180.; SicsWait(60);
pNew->fUpper = 180.; initRS232(pNew->controller);
} else { } else {
if(checkResponse(pNew,pReply)){ if(checkResponse(pNew,pReply)){
if(sscanf(pReply,"%f %f",&pNew->fLower,&pNew->fUpper)!= 2){ if(sscanf(pReply,"%f %f",&pNew->fLower,&pNew->fUpper)!= 2){
snprintf(pError,255, snprintf(pError,255,
"ERROR: received shitty HW limit response from SICS: %s", "ERROR: received shitty HW limit response from SICS: %s",
pReply); pReply);
SCWrite(pCon,pError,eError); SCWrite(pCon,pError,eError);
} else{
success = 1;
break;
}
} }
} else { }
}
if(success == 0){
SCWrite(pCon, SCWrite(pCon,
"ERROR: invalid response when reading HW limits, defaulting..", "ERROR: invalid response when reading HW limits, defaulting..",
eError); eError);
pNew->fLower = -180.; pNew->fLower = -180.;
pNew->fUpper = 180.; pNew->fUpper = 180.;
}
} }
snprintf(pError,255,"EL734 returned HW-limits of: %s", pReply); snprintf(pError,255,"EL734 returned HW-limits of: %s", pReply);
SCWrite(pCon,pError,eError); SCWrite(pCon,pError,eError);
return (MotorDriver *)pNew; return (MotorDriver *)pNew;

View File

@ -37,6 +37,10 @@ typedef struct {
NoBeam and Counting status if the beam goes off NoBeam and Counting status if the beam goes off
*/ */
char *badReply; char *badReply;
int readErrorCount; /* need to remember failed reads: on RDOE, upper level
code will see busy's and thus not catch the case of
multiple failures
*/
} EL737hp, *pEL737hp; } EL737hp, *pEL737hp;
/*--------------------- ERROR CODES -------------------------------------*/ /*--------------------- ERROR CODES -------------------------------------*/
#define OFFLINE -1 #define OFFLINE -1
@ -49,6 +53,7 @@ typedef struct {
#define BADREPLY -10 #define BADREPLY -10
#define SELECTFAIL -11 #define SELECTFAIL -11
#define TIMEOUT737 -12 #define TIMEOUT737 -12
#define TOMANYREADERRORS -23
/*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/
static void setBadReply(pEL737hp self, char *reply){ static void setBadReply(pEL737hp self, char *reply){
if(self->badReply != NULL){ if(self->badReply != NULL){
@ -133,20 +138,24 @@ static int readRS(pEL737hp pPriv, int *RS){
status = readRS232TillTerm(pPriv->controller, status = readRS232TillTerm(pPriv->controller,
reply,&len); reply,&len);
if(status < 0) { if(status < 0) {
pPriv->readErrorCount++;
pPriv->errorCode = status; pPriv->errorCode = status;
return 0; return 0;
} }
status = checkEL737Error(reply); status = checkEL737Error(reply);
if(status < 0){ if(status < 0){
pPriv->readErrorCount++;
pPriv->errorCode = status; pPriv->errorCode = status;
return 0; return 0;
} }
status = sscanf(reply,"%d",RS); status = sscanf(reply,"%d",RS);
if(status < 1){ if(status < 1){
pPriv->readErrorCount++;
pPriv->errorCode = BADREPLY; pPriv->errorCode = BADREPLY;
setBadReply(pPriv,reply); setBadReply(pPriv,reply);
return 0; return 0;
} }
pPriv->readErrorCount = 0;
return 1; return 1;
} }
/*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/
@ -239,7 +248,11 @@ static int EL737Status(struct __COUNTER *self, float *fControl){
handle STATSEND mode handle STATSEND mode
*/ */
if(pPriv->statusMode == STATSEND){ if(pPriv->statusMode == STATSEND){
writeRS232(pPriv->controller,"RS\r",3); status = writeRS232(pPriv->controller,"RS\r",3);
if(status < 0){
pPriv->errorCode = status;
return HWFault;
}
pPriv->statusMode = STATRECEIVE; pPriv->statusMode = STATRECEIVE;
pPriv->startRequest = time(NULL); pPriv->startRequest = time(NULL);
*fControl = pPriv->cachedControl; *fControl = pPriv->cachedControl;
@ -253,6 +266,7 @@ static int EL737Status(struct __COUNTER *self, float *fControl){
if(time(NULL) > pPriv->startRequest + 10){ if(time(NULL) > pPriv->startRequest + 10){
pPriv->statusMode = STATSEND; pPriv->statusMode = STATSEND;
pPriv->errorCode = TIMEOUT737; pPriv->errorCode = TIMEOUT737;
pPriv->readErrorCount++;
return HWFault; return HWFault;
} }
@ -285,6 +299,14 @@ static int EL737Status(struct __COUNTER *self, float *fControl){
returnValue = decodeRS(pPriv,RS); returnValue = decodeRS(pPriv,RS);
pPriv->lastStatus = returnValue; pPriv->lastStatus = returnValue;
/*
check for excessive failed reads
*/
if(pPriv->readErrorCount > 3){
pPriv->errorCode = TOMANYREADERRORS;
return HWFault;
}
/* /*
check if we update the monitors and do it check if we update the monitors and do it
*/ */
@ -310,6 +332,7 @@ static int EL737Start(struct __COUNTER *self){
pPriv = (pEL737hp)self->pData; pPriv = (pEL737hp)self->pData;
fixMode(pPriv); fixMode(pPriv);
pPriv->readErrorCount = 0;
if(self->eMode == ePreset){ if(self->eMode == ePreset){
snprintf(pCommand,49,"MP %d\r",(int)self->fPreset); snprintf(pCommand,49,"MP %d\r",(int)self->fPreset);
} else { } else {
@ -414,8 +437,13 @@ static int EL737GetError(struct __COUNTER *self, int *iCode,
break; break;
case SELECTFAIL: case SELECTFAIL:
strncpy(pError,"select system call failed, network trouble",errLen); strncpy(pError,"select system call failed, network trouble",errLen);
break;
case TIMEOUT737: case TIMEOUT737:
strncpy(pError,"timeout waiting for status repsonse",errLen); strncpy(pError,"timeout or network problem while waiting for status repsonse",errLen);
break;
case TOMANYREADERRORS:
strncpy(pError,"Failed more then three times to read counter box",errLen);
break;
default: default:
getRS232Error(pPriv->errorCode,pError,errLen); getRS232Error(pPriv->errorCode,pError,errLen);
} }
@ -428,29 +456,39 @@ static int EL737FixIt(struct __COUNTER *self, int iCode){
char pReply[50]; char pReply[50];
char buffer[256]; char buffer[256];
int dataLen = 255; int dataLen = 255;
int i;
assert(self); assert(self);
pPriv = (pEL737hp)self->pData; pPriv = (pEL737hp)self->pData;
switch(iCode){ switch(iCode){
case TIMEOUT:
case BADPARAM: case BADPARAM:
case NOPARAM: case NOPARAM:
case BADRANGE: case BADRANGE:
case BADTRANGE: case BADTRANGE:
case TIMEOUT737:
return COREDO; return COREDO;
break; break;
case BADREPLY: case BADREPLY:
/* case TIMEOUT737:
try to read away all the garbage which may still be in the line case TIMEOUT:
*/ for(i = 0; i < 3; i++){
if(availableRS232(pPriv->controller) > 0){ status = readRS232TillTerm(pPriv->controller,buffer,&dataLen);
memset(buffer,0,256); if(status == 1){
readRS232(pPriv->controller,buffer,&dataLen); return COREDO;
printf("EL737hpdriv dumped %s after bad reply\n", buffer); }
}
/*
If nothing can be read, the only fixable cause is a network breakdown
Try to fix this. If this does not work: give up
*/
closeRS232(pPriv->controller);
SicsWait(60);
status = initRS232(pPriv->controller);
if(status != 1){
return COTERM;
} else {
return COREDO;
} }
return COREDO;
break; break;
case OFFLINE: case OFFLINE:
EL737Command(pPriv,"RMT 1\r",pReply,49); EL737Command(pPriv,"RMT 1\r",pReply,49);
@ -463,12 +501,13 @@ static int EL737FixIt(struct __COUNTER *self, int iCode){
break; break;
case TOMANYCOUNTS: case TOMANYCOUNTS:
case SYSERROR: case SYSERROR:
return COTERM;
break; break;
default: default:
/* /*
network problem; try to reopen network problem; try to reopen
*/ */
closeRS232(pPriv->controller);
SicsWait(60);
status = initRS232(pPriv->controller); status = initRS232(pPriv->controller);
if(status != 1){ if(status != 1){
return COTERM; return COTERM;

View File

@ -538,7 +538,7 @@
} else { } else {
SCWrite(pCon,"ERROR: lbank value not found!",eError); SCWrite(pCon,"ERROR: lbank value not found!",eError);
} }
if (var1) if (lbank == 1)
{ {
lData = GetHistogramPointer(self->pHistogram1,pCon); lData = GetHistogramPointer(self->pHistogram1,pCon);
if(!lData) if(!lData)
@ -549,7 +549,7 @@
return; return;
} }
} }
if (var2) if (mbank == 1)
{ {
mData = GetHistogramPointer(self->pHistogram2,pCon); mData = GetHistogramPointer(self->pHistogram2,pCon);
if(!mData) if(!mData)
@ -567,7 +567,7 @@
} else { } else {
SCWrite(pCon,"ERROR: ubank value not found!",eError); SCWrite(pCon,"ERROR: ubank value not found!",eError);
} }
if (var3) if (ubank == 1)
{ {
uData = GetHistogramPointer(self->pHistogram3,pCon); uData = GetHistogramPointer(self->pHistogram3,pCon);
if(!uData) if(!uData)
@ -725,6 +725,7 @@
/* calculate elastic peak position */ /* calculate elastic peak position */
NXDupdate(pDict,"bank","bank1"); NXDupdate(pDict,"bank","bank1");
mData = getFMBankPointer(MIDDLE); mData = getFMBankPointer(MIDDLE);
iDet = getFMdim(MIDDLE);
if(mData) if(mData)
{ {
lSum = (long *)malloc(iTime *sizeof(long)); lSum = (long *)malloc(iTime *sizeof(long));

View File

@ -1243,6 +1243,10 @@ name of hkl object holding crystallographic information
free(self->pCurrentFile); free(self->pCurrentFile);
pText = makeFilename(pServ->pSics,pCon); pText = makeFilename(pServ->pSics,pCon);
if(pText == NULL)
{
return 0;
}
self->pCurrentFile = strdup(pText); self->pCurrentFile = strdup(pText);
if(self->iHDF5) if(self->iHDF5)
{ {

View File

@ -28,6 +28,7 @@
#include <motor.h> #include <motor.h>
#include <scan.h> #include <scan.h>
#include <scan.i> #include <scan.i>
#include <lld.h>
#include "tas.h" #include "tas.h"
#include "tasu.h" #include "tasu.h"
#include "../scanvar.h" #include "../scanvar.h"
@ -930,6 +931,8 @@ static int AddTASScanVar(pScanData self, SicsInterp *pSics, SConnection *pCon,
pVar.pObject = pData; pVar.pObject = pData;
pVar.fStart = fStart; pVar.fStart = fStart;
pVar.fStep = fStep; pVar.fStep = fStep;
pVar.fData = NULL;
pVar.dataList = LLDcreate(sizeof(float));
/* put it away */ /* put it away */
DynarPutCopy(self->pScanVar,self->iScanVar,&pVar,sizeof(VarEntry)); DynarPutCopy(self->pScanVar,self->iScanVar,&pVar,sizeof(VarEntry));
@ -1494,7 +1497,7 @@ int TASScan(SConnection *pCon, SicsInterp *pSics, void *pData,
psTime = localtime(&iDate); psTime = localtime(&iDate);
memset(pWork,0,69); memset(pWork,0,69);
strftime(pWork,69,"%d-%b-%Y %H:%M:%S",psTime); strftime(pWork,69,"%d-%b-%Y %H:%M:%S",psTime);
sprintf(pLine,"%8s %3d Points Scan %3d Scanned Variable(s) %s", snprintf(pLine,1023,"%8s %3d Points Scan %3d Scanned Variable(s) %s",
pTAS->tasPar[INST]->text, pTAS->tasPar[INST]->text,
pTAS->pScan->iNP, pTAS->pScan->iScanVar, pTAS->pScan->iNP, pTAS->pScan->iScanVar,
pWork); pWork);