- Added makefile_slinux
- Changed mesure to be a silver bullet
This commit is contained in:
@ -580,6 +580,7 @@ pCounterDriver MakeECBCounter(char *ecb){
|
||||
self->Get = ECBGet;
|
||||
self->Send = ECBSend;
|
||||
self->KillPrivate = NULL;
|
||||
self->iNoOfMonitors = 8;
|
||||
|
||||
self->pData = pPriv;
|
||||
return self;
|
||||
|
@ -910,6 +910,11 @@ static int ECBGetDriverPar(void *pData,char *name, float *value){
|
||||
|
||||
assert(self);
|
||||
|
||||
if(strcmp(name,"ecbindex") == 0){
|
||||
*value = self->ecbIndex;
|
||||
return 1;
|
||||
}
|
||||
|
||||
par = ObParFind(self->driverPar,name);
|
||||
if(par != NULL){
|
||||
*value = par->fVal;
|
||||
|
98
el734hp.c
98
el734hp.c
@ -18,6 +18,7 @@
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <fortify.h>
|
||||
#include <time.h>
|
||||
#include <sics.h>
|
||||
#include <modriv.h>
|
||||
#include <rs232controller.h>
|
||||
@ -58,6 +59,7 @@
|
||||
int posCount;
|
||||
int runCount;
|
||||
char errorReply[80];
|
||||
time_t valueExpiry;
|
||||
} EL734Driv, *pEL734Driv;
|
||||
/*------------------- error codes ----------------------------------*/
|
||||
#define BADADR -1
|
||||
@ -115,6 +117,11 @@ static int EL734GetPos(void *pData, float *fPos){
|
||||
self = (pEL734Driv)pData;
|
||||
assert(self);
|
||||
|
||||
if(time(NULL) < self->valueExpiry){
|
||||
*fPos = self->lastValue;
|
||||
return OKOK;
|
||||
}
|
||||
|
||||
snprintf(pCommand,79,"u %d\r",self->iMotor);
|
||||
status = transactRS232(self->controller,pCommand,strlen(pCommand),
|
||||
pReply,79);
|
||||
@ -127,6 +134,7 @@ static int EL734GetPos(void *pData, float *fPos){
|
||||
}
|
||||
sscanf(pReply,"%f",fPos);
|
||||
self->lastValue = *fPos;
|
||||
self->valueExpiry = time(NULL) + 3;
|
||||
return OKOK;
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
@ -212,39 +220,6 @@ static int decodeMSR(pEL734Driv self, int msr){
|
||||
}
|
||||
|
||||
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);
|
||||
self->oredMsr |= msr;
|
||||
self->valueExpiry = -1;
|
||||
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){
|
||||
pEL734Driv self = NULL;
|
||||
int status, msr;
|
||||
int status, msr, i, len = 49;
|
||||
char pCommand[50],pReply[80];
|
||||
|
||||
self = (pEL734Driv)pData;
|
||||
@ -345,10 +321,30 @@ static int EL734Fix(void *pData, int iCode, float fValue){
|
||||
switch(iCode){
|
||||
case BADADR:
|
||||
case BADCMD:
|
||||
case TIMEOUT:
|
||||
case BADPAR:
|
||||
case BADBSY:
|
||||
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:
|
||||
snprintf(pCommand,49,"RMT 1\r");
|
||||
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->posCount = 0;
|
||||
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;
|
||||
}
|
||||
@ -457,7 +465,7 @@ static void KillEL734(void *pData){
|
||||
/*------------------------------------------------------------------*/
|
||||
MotorDriver *CreateEL734HP(SConnection *pCon, int argc, char *argv[]){
|
||||
pEL734Driv pNew = NULL;
|
||||
int motor, status;
|
||||
int motor, status, i, success;
|
||||
prs232 controller = NULL;
|
||||
char pCommand[50],pReply[80], pError[255];
|
||||
|
||||
@ -509,15 +517,17 @@ MotorDriver *CreateEL734HP(SConnection *pCon, int argc, char *argv[]){
|
||||
connection will already have been set up, read limits
|
||||
*/
|
||||
snprintf(pCommand,49,"h %d\r",pNew->iMotor);
|
||||
success = 0;
|
||||
for(i = 0; i < 3; i++){
|
||||
status = transactRS232(pNew->controller, pCommand,strlen(pCommand),
|
||||
pReply,79);
|
||||
if(status != 1){
|
||||
SCWrite(pCon,"ERROR: failed to read HW limits, defaulting..",eError);
|
||||
getRS232Error(status,pReply,79);
|
||||
snprintf(pError,255,"ERROR: %s",pReply);
|
||||
SCWrite(pCon,pError,eError);
|
||||
pNew->fLower = -180.;
|
||||
pNew->fUpper = 180.;
|
||||
closeRS232(pNew->controller);
|
||||
SicsWait(60);
|
||||
initRS232(pNew->controller);
|
||||
} else {
|
||||
if(checkResponse(pNew,pReply)){
|
||||
if(sscanf(pReply,"%f %f",&pNew->fLower,&pNew->fUpper)!= 2){
|
||||
@ -525,15 +535,21 @@ MotorDriver *CreateEL734HP(SConnection *pCon, int argc, char *argv[]){
|
||||
"ERROR: received shitty HW limit response from SICS: %s",
|
||||
pReply);
|
||||
SCWrite(pCon,pError,eError);
|
||||
} else{
|
||||
success = 1;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
if(success == 0){
|
||||
SCWrite(pCon,
|
||||
"ERROR: invalid response when reading HW limits, defaulting..",
|
||||
eError);
|
||||
pNew->fLower = -180.;
|
||||
pNew->fUpper = 180.;
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(pError,255,"EL734 returned HW-limits of: %s", pReply);
|
||||
SCWrite(pCon,pError,eError);
|
||||
return (MotorDriver *)pNew;
|
||||
|
@ -37,6 +37,10 @@ typedef struct {
|
||||
NoBeam and Counting status if the beam goes off
|
||||
*/
|
||||
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;
|
||||
/*--------------------- ERROR CODES -------------------------------------*/
|
||||
#define OFFLINE -1
|
||||
@ -49,6 +53,7 @@ typedef struct {
|
||||
#define BADREPLY -10
|
||||
#define SELECTFAIL -11
|
||||
#define TIMEOUT737 -12
|
||||
#define TOMANYREADERRORS -23
|
||||
/*---------------------------------------------------------------------*/
|
||||
static void setBadReply(pEL737hp self, char *reply){
|
||||
if(self->badReply != NULL){
|
||||
@ -133,20 +138,24 @@ static int readRS(pEL737hp pPriv, int *RS){
|
||||
status = readRS232TillTerm(pPriv->controller,
|
||||
reply,&len);
|
||||
if(status < 0) {
|
||||
pPriv->readErrorCount++;
|
||||
pPriv->errorCode = status;
|
||||
return 0;
|
||||
}
|
||||
status = checkEL737Error(reply);
|
||||
if(status < 0){
|
||||
pPriv->readErrorCount++;
|
||||
pPriv->errorCode = status;
|
||||
return 0;
|
||||
}
|
||||
status = sscanf(reply,"%d",RS);
|
||||
if(status < 1){
|
||||
pPriv->readErrorCount++;
|
||||
pPriv->errorCode = BADREPLY;
|
||||
setBadReply(pPriv,reply);
|
||||
return 0;
|
||||
}
|
||||
pPriv->readErrorCount = 0;
|
||||
return 1;
|
||||
}
|
||||
/*-----------------------------------------------------------------*/
|
||||
@ -239,7 +248,11 @@ static int EL737Status(struct __COUNTER *self, float *fControl){
|
||||
handle STATSEND mode
|
||||
*/
|
||||
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->startRequest = time(NULL);
|
||||
*fControl = pPriv->cachedControl;
|
||||
@ -253,6 +266,7 @@ static int EL737Status(struct __COUNTER *self, float *fControl){
|
||||
if(time(NULL) > pPriv->startRequest + 10){
|
||||
pPriv->statusMode = STATSEND;
|
||||
pPriv->errorCode = TIMEOUT737;
|
||||
pPriv->readErrorCount++;
|
||||
return HWFault;
|
||||
}
|
||||
|
||||
@ -285,6 +299,14 @@ static int EL737Status(struct __COUNTER *self, float *fControl){
|
||||
returnValue = decodeRS(pPriv,RS);
|
||||
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
|
||||
*/
|
||||
@ -310,6 +332,7 @@ static int EL737Start(struct __COUNTER *self){
|
||||
pPriv = (pEL737hp)self->pData;
|
||||
|
||||
fixMode(pPriv);
|
||||
pPriv->readErrorCount = 0;
|
||||
if(self->eMode == ePreset){
|
||||
snprintf(pCommand,49,"MP %d\r",(int)self->fPreset);
|
||||
} else {
|
||||
@ -414,8 +437,13 @@ static int EL737GetError(struct __COUNTER *self, int *iCode,
|
||||
break;
|
||||
case SELECTFAIL:
|
||||
strncpy(pError,"select system call failed, network trouble",errLen);
|
||||
break;
|
||||
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:
|
||||
getRS232Error(pPriv->errorCode,pError,errLen);
|
||||
}
|
||||
@ -428,29 +456,39 @@ static int EL737FixIt(struct __COUNTER *self, int iCode){
|
||||
char pReply[50];
|
||||
char buffer[256];
|
||||
int dataLen = 255;
|
||||
int i;
|
||||
|
||||
assert(self);
|
||||
pPriv = (pEL737hp)self->pData;
|
||||
|
||||
switch(iCode){
|
||||
case TIMEOUT:
|
||||
case BADPARAM:
|
||||
case NOPARAM:
|
||||
case BADRANGE:
|
||||
case BADTRANGE:
|
||||
case TIMEOUT737:
|
||||
return COREDO;
|
||||
break;
|
||||
case BADREPLY:
|
||||
/*
|
||||
try to read away all the garbage which may still be in the line
|
||||
*/
|
||||
if(availableRS232(pPriv->controller) > 0){
|
||||
memset(buffer,0,256);
|
||||
readRS232(pPriv->controller,buffer,&dataLen);
|
||||
printf("EL737hpdriv dumped %s after bad reply\n", buffer);
|
||||
}
|
||||
case TIMEOUT737:
|
||||
case TIMEOUT:
|
||||
for(i = 0; i < 3; i++){
|
||||
status = readRS232TillTerm(pPriv->controller,buffer,&dataLen);
|
||||
if(status == 1){
|
||||
return COREDO;
|
||||
}
|
||||
}
|
||||
/*
|
||||
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;
|
||||
}
|
||||
break;
|
||||
case OFFLINE:
|
||||
EL737Command(pPriv,"RMT 1\r",pReply,49);
|
||||
@ -463,12 +501,13 @@ static int EL737FixIt(struct __COUNTER *self, int iCode){
|
||||
break;
|
||||
case TOMANYCOUNTS:
|
||||
case SYSERROR:
|
||||
return COTERM;
|
||||
break;
|
||||
default:
|
||||
/*
|
||||
network problem; try to reopen
|
||||
*/
|
||||
closeRS232(pPriv->controller);
|
||||
SicsWait(60);
|
||||
status = initRS232(pPriv->controller);
|
||||
if(status != 1){
|
||||
return COTERM;
|
||||
|
@ -538,7 +538,7 @@
|
||||
} else {
|
||||
SCWrite(pCon,"ERROR: lbank value not found!",eError);
|
||||
}
|
||||
if (var1)
|
||||
if (lbank == 1)
|
||||
{
|
||||
lData = GetHistogramPointer(self->pHistogram1,pCon);
|
||||
if(!lData)
|
||||
@ -549,7 +549,7 @@
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (var2)
|
||||
if (mbank == 1)
|
||||
{
|
||||
mData = GetHistogramPointer(self->pHistogram2,pCon);
|
||||
if(!mData)
|
||||
@ -567,7 +567,7 @@
|
||||
} else {
|
||||
SCWrite(pCon,"ERROR: ubank value not found!",eError);
|
||||
}
|
||||
if (var3)
|
||||
if (ubank == 1)
|
||||
{
|
||||
uData = GetHistogramPointer(self->pHistogram3,pCon);
|
||||
if(!uData)
|
||||
@ -725,6 +725,7 @@
|
||||
/* calculate elastic peak position */
|
||||
NXDupdate(pDict,"bank","bank1");
|
||||
mData = getFMBankPointer(MIDDLE);
|
||||
iDet = getFMdim(MIDDLE);
|
||||
if(mData)
|
||||
{
|
||||
lSum = (long *)malloc(iTime *sizeof(long));
|
||||
|
@ -1243,6 +1243,10 @@ name of hkl object holding crystallographic information
|
||||
free(self->pCurrentFile);
|
||||
|
||||
pText = makeFilename(pServ->pSics,pCon);
|
||||
if(pText == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
self->pCurrentFile = strdup(pText);
|
||||
if(self->iHDF5)
|
||||
{
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <motor.h>
|
||||
#include <scan.h>
|
||||
#include <scan.i>
|
||||
#include <lld.h>
|
||||
#include "tas.h"
|
||||
#include "tasu.h"
|
||||
#include "../scanvar.h"
|
||||
@ -930,6 +931,8 @@ static int AddTASScanVar(pScanData self, SicsInterp *pSics, SConnection *pCon,
|
||||
pVar.pObject = pData;
|
||||
pVar.fStart = fStart;
|
||||
pVar.fStep = fStep;
|
||||
pVar.fData = NULL;
|
||||
pVar.dataList = LLDcreate(sizeof(float));
|
||||
|
||||
/* put it away */
|
||||
DynarPutCopy(self->pScanVar,self->iScanVar,&pVar,sizeof(VarEntry));
|
||||
@ -1494,7 +1497,7 @@ int TASScan(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
psTime = localtime(&iDate);
|
||||
memset(pWork,0,69);
|
||||
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->pScan->iNP, pTAS->pScan->iScanVar,
|
||||
pWork);
|
||||
|
Reference in New Issue
Block a user