diff --git a/amor2t.c b/amor2t.c index 96bf3b7..41bbb61 100644 --- a/amor2t.c +++ b/amor2t.c @@ -19,6 +19,10 @@ structures this extra was added into this module. Mark Koennecke, May-June 2000 + + Introduced DIAFLAG to switch off diaphragm calculation. + + Mark Koennecke, July 2005 ---------------------------------------------------------------------------*/ #include #include @@ -32,7 +36,7 @@ #define DEBUG 1 #define MAXMOT 13 -#define MAXPAR 13 +#define MAXPAR 14 #include "amor2t.i" #include "amor2t.h" @@ -72,6 +76,16 @@ The core of it all: The calculation of the settings for the various motors. ========================================================================*/ + static void clearRunFlags(pAmor2T self) + { + int i; + + for(i = 0; i < MAXMOT; i++) + { + self->toStart[i].pMot = NULL; + } + } + /*---------------------------------------------------------------------*/ static int CalculateAMORE(pAmor2T self, SConnection *pCon, float fNew) { float fMOM, fSOM, fSTZ, fSOZ, fAOM, fAOZ, fC3Z, fconstAOM; @@ -107,7 +121,9 @@ /* calculate base height of sample table */ fBase = fSOZ + ObVal(self->aParameter,PARDH); fPIR = 180. / 3.1415926; - + + clearRunFlags(self); + /* calculation for detector */ fAngle = fNew - 2*fMOM; if(fAngle < 0) @@ -127,32 +143,32 @@ self->toStart[2].pMot = self->aEngine[MOTCOM]; strcpy(self->toStart[2].pName,self->aEngine[MOTCOM]->name); self->toStart[2].fTarget = fNew - 2*fMOM; - self->iStart = 3; - /* calculation for diaphragm 4 */ - fZ = ObVal(self->aParameter,PARDD4) * sin(fAngle); - self->toStart[3].pMot = self->aEngine[MOTD4B]; - strcpy(self->toStart[3].pName,self->aEngine[MOTD4B]->name); - self->toStart[3].fTarget = fBase + fZ - - ObVal(self->aParameter,PARD4H); - self->iStart = 4; + if(ObVal(self->aParameter,DIAFLAG) > .0) + { + /* calculation for diaphragm 4 */ + fZ = ObVal(self->aParameter,PARDD4) * sin(fAngle); + self->toStart[3].pMot = self->aEngine[MOTD4B]; + strcpy(self->toStart[3].pName,self->aEngine[MOTD4B]->name); + self->toStart[3].fTarget = fBase + fZ - + ObVal(self->aParameter,PARD4H); - /* calculation for diaphragm 5 */ - fZ = ObVal(self->aParameter,PARDD5) * sin(fAngle); - self->toStart[4].pMot = self->aEngine[MOTD5B]; - strcpy(self->toStart[4].pName,self->aEngine[MOTD5B]->name); - self->toStart[4].fTarget = fBase + fZ - - ObVal(self->aParameter,PARD5H); - self->iStart = 5; + /* calculation for diaphragm 5 */ + fZ = ObVal(self->aParameter,PARDD5) * sin(fAngle); + self->toStart[4].pMot = self->aEngine[MOTD5B]; + strcpy(self->toStart[4].pName,self->aEngine[MOTD5B]->name); + self->toStart[4].fTarget = fBase + fZ - + ObVal(self->aParameter,PARD5H); #ifdef DEBUG - sprintf(pBueffel,"2T COZ COX COM D4B D5B "); - SCWrite(pCon,pBueffel,eValue); - sprintf(pBueffel,"%6.2f %6.2f %6.2f %6.2f %6.2f %6.2f", + sprintf(pBueffel,"2T COZ COX COM D4B D5B "); + SCWrite(pCon,pBueffel,eValue); + sprintf(pBueffel,"%6.2f %6.2f %6.2f %6.2f %6.2f %6.2f", fNew, self->toStart[1].fTarget, self->toStart[0].fTarget, self->toStart[2].fTarget, self->toStart[3].fTarget, self->toStart[4].fTarget); - SCWrite(pCon,pBueffel,eValue); + SCWrite(pCon,pBueffel,eValue); #endif + } if(ObVal(self->aParameter,ANAFLAG) > 0) { @@ -162,14 +178,12 @@ self->toStart[5].pMot = self->aEngine[MOTAOZ]; strcpy(self->toStart[5].pName,self->aEngine[MOTAOZ]->name); self->toStart[5].fTarget = fAOZ; - self->iStart = 6; /* analyzer omega */ self->toStart[6].pMot = self->aEngine[MOTAOM]; strcpy(self->toStart[6].pName,self->aEngine[MOTAOM]->name); self->toStart[6].fTarget = fNew/2. + ObVal(self->aParameter,PARAOM); - self->iStart = 7; /* C3Z */ fZ2 = (ObVal(self->aParameter,PARDS) - ObVal(self->aParameter, @@ -180,7 +194,6 @@ self->toStart[7].fTarget = fBase + fZ + fZ2 - ObVal(self->aParameter,PARDDD) - self->toStart[1].fTarget; - self->iStart = 8; #ifdef DEBUG sprintf(pBueffel,"2T AOZ AOM C3Z"); SCWrite(pCon,pBueffel,eValue); @@ -238,6 +251,7 @@ */ fDiffracted = fIncident - fNew; + clearRunFlags(self); /* calculation for detector */ fDiffracted /= fPIR; @@ -257,16 +271,16 @@ self->toStart[2].pMot = self->aEngine[MOTCOM]; strcpy(self->toStart[2].pName,self->aEngine[MOTCOM]->name); self->toStart[2].fTarget = -fDiffracted*fPIR; - self->iStart = 3; /* calculation for diaphragm 5 */ - fZ = ObVal(self->aParameter,PARDD5) * sin(fDiffracted); - self->toStart[3].pMot = self->aEngine[MOTD5B]; - strcpy(self->toStart[3].pName,self->aEngine[MOTD5B]->name); - self->toStart[3].fTarget = fBase + fZ - - ObVal(self->aParameter,PARD5H); - self->iStart = 4; - + if(ObVal(self->aParameter,DIAFLAG) > .0) + { + fZ = ObVal(self->aParameter,PARDD5) * sin(fDiffracted); + self->toStart[3].pMot = self->aEngine[MOTD5B]; + strcpy(self->toStart[3].pName,self->aEngine[MOTD5B]->name); + self->toStart[3].fTarget = fBase + fZ - + ObVal(self->aParameter,PARD5H); + } #ifdef DEBUG sprintf(pBueffel,"2T COX COZ COM D5B "); SCWrite(pCon,pBueffel,eValue); @@ -297,8 +311,12 @@ } /* start them all */ - for(i = 0; i < self->iStart; i++) + for(i = 0; i < MAXMOT; i++) { + if(self->toStart[i].pMot == NULL) + { + continue; + } pDriv = self->toStart[i].pMot->pDescriptor->GetInterface( self->toStart[i].pMot,DRIVEID); if(pDriv != NULL) @@ -330,8 +348,12 @@ } /* start them all */ - for(i = 0; i < self->iStart; i++) + for(i = 0; i < MAXMOT; i++) { + if(self->toStart[i].pMot == NULL) + { + continue; + } pDriv = self->toStart[i].pMot->pDescriptor->GetInterface( self->toStart[i].pMot,DRIVEID); if(pDriv != NULL) @@ -356,8 +378,12 @@ assert(self); /* stop them all */ - for(i = 0; i < self->iStart; i++) + for(i = 0; i < MAXMOT; i++) { + if(self->toStart[i].pMot == NULL) + { + continue; + } pDriv = self->toStart[i].pMot->pDescriptor->GetInterface( self->toStart[i].pMot,DRIVEID); if(pDriv != NULL) @@ -389,8 +415,12 @@ } /* check them all */ - for(i = 0; i < self->iStart; i++) + for(i = 0; i < MAXMOT; i++) { + if(self->toStart[i].pMot == NULL) + { + continue; + } pDriv = self->toStart[i].pMot->pDescriptor->GetInterface( self->toStart[i].pMot,DRIVEID); if(pDriv != NULL) @@ -428,8 +458,12 @@ } /* check them all */ - for(i = 0; i < self->iStart; i++) + for(i = 0; i < MAXMOT; i++) { + if(self->toStart[i].pMot == NULL) + { + continue; + } pDriv = self->toStart[i].pMot->pDescriptor->GetInterface( self->toStart[i].pMot,DRIVEID); if(pDriv != NULL) @@ -455,8 +489,12 @@ assert(self); /* check them all */ - for(i = 0; i < self->iStart; i++) + for(i = 0; i < MAXMOT; i++) { + if(self->toStart[i].pMot == NULL) + { + continue; + } pDriv = self->toStart[i].pMot->pDescriptor->GetInterface( self->toStart[i].pMot,DRIVEID); if(pDriv != NULL) @@ -548,6 +586,7 @@ fprintf(fd,"%s anaflag %f \n", name, ObVal(self->aParameter,ANAFLAG)); fprintf(fd,"%s c2h %f \n", name, ObVal(self->aParameter,PARDDD)); fprintf(fd,"%s aomconst %f \n", name, ObVal(self->aParameter,PARAOM)); + fprintf(fd,"%s diaflag %f \n", name, ObVal(self->aParameter,DIAFLAG)); return 1; } /*------------------------------------------------------------------------*/ @@ -599,6 +638,9 @@ sprintf(pBueffel, "%s.aomconst %f \n", name, ObVal(self->aParameter,PARAOM)); Tcl_DStringAppend(&tString,pBueffel,-1); + sprintf(pBueffel, + "%s.diaflag %f \n", name, ObVal(self->aParameter,DIAFLAG)); + Tcl_DStringAppend(&tString,pBueffel,-1); SCWrite(pCon,Tcl_DStringValue(&tString),eValue); Tcl_DStringFree(&tString); } @@ -868,6 +910,7 @@ ObParInit(pNew->aParameter,ANAFLAG,"anaflag",-1.,usMugger); ObParInit(pNew->aParameter,PARDDD,"c2h",100.,usMugger); ObParInit(pNew->aParameter,PARAOM,"aomconst",3.,usMugger); + ObParInit(pNew->aParameter,DIAFLAG,"diaflag",1.,usMugger); /* initialize interfaces */ diff --git a/amor2t.h b/amor2t.h index 6e243cb..3890c70 100644 --- a/amor2t.h +++ b/amor2t.h @@ -17,6 +17,5 @@ int argc, char *argv[]); int Amor2TAction(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]); - void Amor2TKill(void *pData); #endif diff --git a/amor2t.i b/amor2t.i index 2bcf2ae..7e98ca2 100644 --- a/amor2t.i +++ b/amor2t.i @@ -33,6 +33,8 @@ #define PARDDD 11 /* constant part of AOM */ #define PARAOM 12 +/* flag for diaphragms */ +#define DIAFLAG 13 typedef struct { @@ -48,7 +50,6 @@ pIDrivable pDriv; pMotor aEngine[MAXMOT]; MotEntry toStart[MAXMOT]; - int iStart; ObPar *aParameter; }Amor2T; diff --git a/amor2t.tex b/amor2t.tex index c458706..08e0896 100644 --- a/amor2t.tex +++ b/amor2t.tex @@ -62,6 +62,7 @@ $\langle$putput {\footnotesize ?}$\rangle\equiv$ \item[pMot] is a pointer to the motors data structure. \item[pName] is the name of the motor to start. \item[fTarget] is the target value for the motor. +\item[run] A flag which determines if this motor is to be run. \end{description} The next data structure is the class data structure for amor2t: @@ -76,7 +77,6 @@ $\langle$amoredata {\footnotesize ?}$\rangle\equiv$ \mbox{}\verb@ pIDrivable pDriv;@\\ \mbox{}\verb@ pMotor aEngine[MAXMOT];@\\ \mbox{}\verb@ MotEntry toStart[MAXMOT];@\\ -\mbox{}\verb@ int iStart;@\\ \mbox{}\verb@ ObPar *aParameter;@\\ \mbox{}\verb@ }Amor2T;@\\ \mbox{}\verb@@$\diamond$ @@ -118,7 +118,6 @@ $\langle$amorinterface {\footnotesize ?}$\rangle\equiv$ \mbox{}\verb@ int argc, char *argv[]);@\\ \mbox{}\verb@ int Amor2TAction(SConnection *pCon, SicsInterp *pSics, void *pData,@\\ \mbox{}\verb@ int argc, char *argv[]);@\\ -\mbox{}\verb@ void Amor2TKill(void *pData); @\\ \mbox{}\verb@@$\diamond$ \end{list} \vspace{-1ex} @@ -168,6 +167,8 @@ $\langle$amorinterface {\footnotesize ?}$\rangle\equiv$ \mbox{}\verb@#define PARDDD 11@\\ \mbox{}\verb@/* constant part of AOM */@\\ \mbox{}\verb@#define PARAOM 12@\\ +\mbox{}\verb@/* flag for diaphragms */@\\ +\mbox{}\verb@#define DIAFLAG 13@\\ \mbox{}\verb@@\\ \mbox{}\verb@@$\langle$putput {\footnotesize ?}$\rangle$\verb@@\\ \mbox{}\verb@@\\ diff --git a/amor2t.w b/amor2t.w index 75357cf..cb559e3 100644 --- a/amor2t.w +++ b/amor2t.w @@ -49,6 +49,7 @@ used is an entry in an array of motors to start: \item[pMot] is a pointer to the motors data structure. \item[pName] is the name of the motor to start. \item[fTarget] is the target value for the motor. +\item[run] A flag which determines if this motor is to be run. \end{description} The next data structure is the class data structure for amor2t: @@ -58,7 +59,6 @@ The next data structure is the class data structure for amor2t: pIDrivable pDriv; pMotor aEngine[MAXMOT]; MotEntry toStart[MAXMOT]; - int iStart; ObPar *aParameter; }Amor2T; @} @@ -124,6 +124,8 @@ functions for interacting with the interpreter. #define PARDDD 11 /* constant part of AOM */ #define PARAOM 12 +/* flag for diaphragms */ +#define DIAFLAG 13 @ diff --git a/dornier2.c b/dornier2.c index 741a02d..9e3293c 100644 --- a/dornier2.c +++ b/dornier2.c @@ -159,7 +159,7 @@ static int takeControl(pDornier pDorn){ snprintf(pCom,49,"SDR %d\n",pDorn->minRPM); iRet = transactRS232(pDorn->controller,pCom,strlen(pCom), pAnswer,79); - if(iRet != 1) + if(iRet < 1) { pDorn->iLastError = iRet; return 0; @@ -278,7 +278,7 @@ static int takeControl(pDornier pDorn){ pAnswer,49); setRS232ReplyTerminator(pDorn->controller,"\n"); pDorn->firstStatus = 1; - if(iRet != 1) + if(iRet < 1) { if(iRet != INCOMPLETE){ @@ -359,7 +359,7 @@ static int DornierFixIt(pVelSelDriv self, int iCode){ } oldReject = pDorn->rejectCount; status = takeControl(pDorn); - if(status == 1){ + if(status >= 1){ DornierRun(self,pDorn->fTarget); pDorn->rejectCount = oldReject + 1; return VELOREDO; @@ -500,7 +500,7 @@ static int DornierStatNew(pVelSelDriv self, int *iCode, float *fCur){ /* send a command */ iRet = transactRS232(pDorn->controller,pCommand,strlen(pCommand), pAnswer,79); - if(iRet != 1) + if(iRet < 1) { pDorn->iLastError = iRet; return 0; @@ -577,7 +577,7 @@ static int DornierStatNew(pVelSelDriv self, int *iCode, float *fCur){ Funny enough no or is sent in the reply to this. */ iRet = takeControl(pDorn); - if(iRet != 1) + if(iRet <= 1) { sprintf(pBueffel, "ERROR: %s while switching velocity selector to remote", diff --git a/el734hp.c b/el734hp.c index 9f46999..f8b87af 100644 --- a/el734hp.c +++ b/el734hp.c @@ -105,20 +105,24 @@ static int transactEL734(prs232 self, void *send, int sendLen, message only at the second try. This is the logic below. */ status = transactRS232(self,send,sendLen,reply,replylen); - if(status == 1){ + if(status >= 1){ pReply = (char *)reply; if(strstr(pReply,"*ES") != NULL){ if(availableRS232(self)){ len = replylen; readRS232TillTerm(self,reply,&len); } - return transactRS232(self,send,sendLen,reply,replylen); + status = transactRS232(self,send,sendLen,reply,replylen); + if(status >= 1){ + return 1; + } } else { - return status; + return 1; } } else { return status; } + return 0; /* not reached */ } /*------------------------------------------------------------------- If we get an empty reply when we expect some response data, then, maybe, @@ -272,12 +276,26 @@ static int decodeMSR(pEL734Driv self, int msr){ */ if(msr & 0x80){ self->runCount++; + }else if(msr & 0x20){ + self->errorCode = HILIM; + return HWFault; + }else if(msr & 0x10){ + self->errorCode = LOWLIM; + return HWFault; + }else if(msr & 0x1000){ + self->errorCode = BADCUSHION; + return HWFault; + }else if(msr & 0x40){ + self->errorCode = BADSTP; + return HWFault; } else if(msr & 0x200) { self->posCount++; } else if(msr & 0x100) { - self->posCount++; + self->errorCode = POSFAULT; + return HWFault; } else if(msr & 0x400) { - self->posCount++; + self->errorCode = POSFAULT; + return HWFault; } return HWBusy; @@ -521,6 +539,11 @@ static int EL734SetPar(void *pData, SConnection *pCon, } self->fLower = newValue; snprintf(pCommand,79,"H %d %8.3f %8.3f\r",self->iMotor,self->fLower, self->fUpper); + } else if(strcmp(name,"forcepos") == 0){ + if(!SCMatchRights(pCon,usMugger)){ + return 0; + } + snprintf(pCommand,79,"U %d %8.3f\r",self->iMotor,newValue); } if(strlen(pCommand) > 1){ status = transactEL734(self->controller,pCommand,strlen(pCommand), diff --git a/nxamor.c b/nxamor.c index 851e716..1fb7a46 100644 --- a/nxamor.c +++ b/nxamor.c @@ -32,7 +32,7 @@ #include "amor2t.h" /* some defines for some names */ -#define AMORDICT "/home/amor/amor_sics/amor.dic" +static char AMORDICT[1024] = "/home/amor/amor_sics/amor.dic"; #define INSTNAME "AMOR at SINQ, PSI" #define SOURCENAME "Spallation source SINQ" #define SOURCETYPE "Continous flux spallation source" @@ -809,6 +809,9 @@ static int WriteTOFDetector(char *name, pHistMem pHM, int *iDim, return 0; } pAmor = (pAmor2T)pCom->pData; + if(argc > 3) { + strncpy(AMORDICT,argv[3],1023); + } /* install command */ diff --git a/slsmagnet.c b/slsmagnet.c index b42d1fe..53dd945 100644 --- a/slsmagnet.c +++ b/slsmagnet.c @@ -11,6 +11,8 @@ 115KB when using this device. Mark Koennecke, October 2001 + + Adaptiert auf neue DSP Software version, Mark Koennecke, August 2005 Copyright: see copyright.h ----------------------------------------------------------------------------*/ @@ -161,7 +163,10 @@ static int communicateSLS(mkChannel *pSock, char msg[6], char reply[6]) assert(pMe); msg[0] = DSPREAD; /* read request */ - msg[1] = 0x92; /* address of mag current */ + /* old address of mag current + msg[1] = 0x92; + */ + msg[1] = 0x9c; /* address of mag current */ iRet = communicateSLS(pMe->pSock,msg,reply); if(iRet < 0) { @@ -267,7 +272,10 @@ static int communicateSLS(mkChannel *pSock, char msg[6], char reply[6]) try to switch device on */ msg[0] = DSPWRITE; + /* old device on msg[1] = 0x31; + */ + msg[1] = 0x3c; ival = 1; memcpy(msg+2, &ival,4); iRet = communicateSLS(pMe->pSock,msg,reply); diff --git a/sps.c b/sps.c index 2859a40..9ae2652 100644 --- a/sps.c +++ b/sps.c @@ -62,6 +62,7 @@ /* configure terminators */ SerialATerm(&self->pData, "1\r\n"); SerialSendTerm(&self->pData,"\r\n"); + SerialConfig(&self->pData,5000); return 1; } @@ -207,8 +208,8 @@ } /* decode the reply into the Byte array */ - pPtr = pBueffel; - if(*pPtr != 'R') + pPtr = strchr(pBueffel,'R'); + if(pPtr == NULL) { return -2; } @@ -300,8 +301,8 @@ } /* decode the reply into the Byte array */ - pPtr = pBueffel; - if(*pPtr != 'R') + pPtr = strchr(pBueffel,'R'); + if(pPtr == NULL) { return -2; } @@ -402,8 +403,8 @@ } /* decode the result */ - pPtr = pBueffel; - if(*pPtr != 'A') /* a silly answer was returned */ + pPtr = strchr(pBueffel,'A'); + if(pPtr == NULL) /* a silly answer was returned */ { SICSLogWrite("SPS: Silly answer in SPSGetADC",eError); return 0;