diff --git a/SCinter.c b/SCinter.c index bca74aac..f8fb2140 100644 --- a/SCinter.c +++ b/SCinter.c @@ -252,6 +252,7 @@ extern char *SkipSpace(char *pPtr); char pBrk[] = {" \r\n\0"}; char *pPtr; char **argv = NULL; + commandContext comCon; assert(self); @@ -306,13 +307,7 @@ extern char *SkipSpace(char *pPtr); self->eOut = eStatus; Tcl_ResetResult((Tcl_Interp *)self->pTcl); MacroPush(pCon); - SCWrite(pCon, "", eStart); - pCon->conStatus = 0; iRet = pCommand->OFunc(pCon, self, pCommand->pData, argc, argv); - /* If a task is registered with the dev exec then conStatus is HWBusy*/ - if (pCon->conStatus != HWBusy) { - SCWrite(pCon,"",eFinish); - } MacroPop(); deleteArgv: diff --git a/drive.c b/drive.c index dd04e9e6..06298e6f 100644 --- a/drive.c +++ b/drive.c @@ -453,14 +453,24 @@ assert(pCon); assert(pSics); - iRet = AddCommand(pSics,"drive", DriveWrapper,NULL,NULL); + if(argc > 1) + { + iRet = AddCommand(pSics,argv[1], DriveWrapper,NULL,NULL); + } else { + iRet = AddCommand(pSics,"drive", DriveWrapper,NULL,NULL); + } if(!iRet) { sprintf(pBueffel,"ERROR: duplicate command drive not created"); SCWrite(pCon,pBueffel,eError); return 0; } - iRet = AddCommand(pSics,"run", RunWrapper,NULL,NULL); + if(argc < 2) + { + iRet = AddCommand(pSics,argv[2], RunWrapper,NULL,NULL); + } else { + iRet = AddCommand(pSics,"run", RunWrapper,NULL,NULL); + } if(!iRet) { sprintf(pBueffel,"ERROR: duplicate command run not created"); diff --git a/fourlib.c b/fourlib.c index a1a916ef..81551a9f 100644 --- a/fourlib.c +++ b/fourlib.c @@ -489,11 +489,12 @@ int z1mToNormalBeam(double lambda, MATRIX z1m, double *gamma, double *om, double phimat(dum,omdeg); znew = mat_mul(dum,z1m); if(znew[0][0] < 0) { - *om = *om -2.*atan2(-znew[0][0], -znew[2][0]); + *om = *om -2.*atan2(-znew[0][0], -znew[1][0]); omdeg = *om * RD; } b = (sign(180.,omdeg)+ omdeg)/360.; - /* omdeg = omdeg - 360. * floor(b); */ + b = sign(1,b)* floor(ABS(b)); + omdeg = omdeg - 360. * b ; *nu = asin(lambda*z1m[2][0]); *gamma = acos(cos(2.*(theta/RD)))/cos(*nu); *om = omdeg; diff --git a/hkl.c b/hkl.c index 44d1f52d..b139a04f 100644 --- a/hkl.c +++ b/hkl.c @@ -474,15 +474,16 @@ static int checkNormalBeam(double om, double *gamma, double nu, char pError[132]; float fHard; + fSet[0] = (float)*gamma; + fSet[1] = (float)om; + fSet[2] = (float)nu; + /* check omega, gamma and nu */ iTest = MotorCheckBoundary(self->pOmega,(float)om, &fHard,pError,131); iTest += checkTheta(self,gamma); iTest += MotorCheckBoundary(self->pNu,(float)nu, &fHard,pError,131); if(iTest == 3) /* none of them burns */ { - fSet[0] = (float)*gamma; - fSet[1] = (float)om; - fSet[2] = (float)nu; return 1; } return 0; @@ -677,7 +678,7 @@ static int calculateBisecting(MATRIX z1, pHKL self, SConnection *pCon, static int calculateNormalBeam(MATRIX z1, pHKL self, SConnection *pCon, float fSet[4], double myPsi, int iRetry) { - int i, iTest; + int i, iTest, status; double stt, om, chi, phi, gamma, nu, psi, omnb; float currentPhi, currentChi; double ompsi, chipsi, phipsi; @@ -699,7 +700,6 @@ static int calculateNormalBeam(MATRIX z1, pHKL self, SConnection *pCon, { return 0; } - /* phim = mat_creat(3,3,ZERO_MATRIX); phimat(phim,(double)currentPhi); z4 = mat_mul(phim,z1); @@ -709,9 +709,13 @@ static int calculateNormalBeam(MATRIX z1, pHKL self, SConnection *pCon, mat_free(phim); mat_free(chim); mat_free(z4); - */ - if(!z1mToNormalBeam(self->fLambda, z1, &gamma, &omnb, &nu)){ + + status = z1mToNormalBeam(self->fLambda, z3, &gamma, &omnb, &nu); + omnb += 180.; + mat_free(z3); + if(status != 1) + { return 0; } if(checkNormalBeam(omnb, &gamma, nu,fSet,pCon,self)){ @@ -719,61 +723,6 @@ static int calculateNormalBeam(MATRIX z1, pHKL self, SConnection *pCon, } else { return 0; } - - if(!z1mToBisecting(self->fLambda,z1,&stt,&om,&chi,&phi)) - { - return 0; - } - if(bisToNormalBeam(stt,om,chi,phi, - &omnb, &gamma, &nu)) - { - /* om = -om + 180.; */ - if(checkNormalBeam(omnb, &gamma, nu,fSet,pCon,self)) - { - return 1; - } - } - return 0; - - /* - do the bisecting angles first - */ - if(!z1mToBisecting(self->fLambda,z3,&stt,&om,&chi,&phi)) - { - return 0; - } - - if(ABS(chi -90.) < .001 && ABS(phi-180.) < .001) - { - chi = .0; - phi = .0; - } - - /* - in order to cope with all those limitations: rotate through psi - */ - for(i = 0; i < iRetry; i++) - { - if(iRetry > 1) - { - psi = i*.5; - } - else - { - psi = myPsi; - } - rotatePsi(om,chi,phi,psi,&ompsi,&chipsi,&phipsi); - if(bisToNormalBeam(stt,ompsi,chipsi,phipsi, - &om, &gamma, &nu)) - { - if(checkNormalBeam(om, &gamma, nu,fSet,pCon,self)) - { - return 1; - } - } - } - - return 0; } /*---------------------------------------------------------------------*/ static int calculateNormalBeamOmega(MATRIX z1, pHKL self, diff --git a/hklmot.c b/hklmot.c index 6f7c66cb..2d897360 100644 --- a/hklmot.c +++ b/hklmot.c @@ -109,6 +109,7 @@ static int HKLCheckStatus(void *pData, SConnection *pCon){ status = RunHKL(self->pHkl,self->pHkl->targetHKL,.0,0,pCon); self->pHkl->targetDirty = 0; if(status != 1){ + SCSetInterrupt(pCon,eAbortOperation); return HWFault; } return HWBusy; diff --git a/hklscan.c b/hklscan.c index de9bf0c9..6ed90cdd 100644 --- a/hklscan.c +++ b/hklscan.c @@ -7,6 +7,14 @@ copyright: see copyright.h Mark Koennecke, June 1999 + + This is obsolete: h,k,l are now drivable. Logged variables have been added + to the scan module. The command is now implemented through scripts. + This module is left in the source tree in order to allow for a quick + reinstallation in case of problems but should be retired from the + source tree in the shutdown 2007 + + Mark Koennecke, January 2006 --------------------------------------------------------------------------*/ #include #include @@ -86,7 +94,7 @@ } /* alright. Install command */ - iRet = AddCommand(pSics, "hklscan", + iRet = AddCommand(pSics, "__hklscan", HklscanAction,KillHklscan,pNew); if(!iRet) { @@ -232,7 +240,7 @@ self->fd = NULL; return 1; } -/*------------------------------------------------------------------------*/ +/*-------------------------------------------------------------------*/ int Hklscan(pHklscan self, SConnection *pCon, int iNP, int iMode, float fPreset) { @@ -279,10 +287,11 @@ int argc, char *argv[]) { char pBueffel[512]; - int iRet, iMode, iNP; + int iRet, iMode, iNP, iPoint; pHklscan self = NULL; double dVal; float fPreset; + void *pPtr; assert(pCon); assert(pSics); @@ -438,7 +447,7 @@ SCSendOK(pCon); } return iRet; - } + } sprintf(pBueffel, "ERROR: %s not recognized as command word to hklscan",argv[1]); SCWrite(pCon,pBueffel,eError); diff --git a/mesure.c b/mesure.c index 8ef861f8..771864fd 100644 --- a/mesure.c +++ b/mesure.c @@ -24,6 +24,8 @@ #include "danu.h" #include "integrate.h" #include "hkl.h" +#include "matrix/matrix.h" +#include "hkl.i" #include "sicsvar.h" #include "evcontroller.h" #include "mesure.h" @@ -755,6 +757,8 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon) float fVal, fUB[9]; pSicsVariable pVar = NULL; char *pFile = NULL, *pPtr; + float zero, pos; + pMotor pMot = NULL; assert(self); @@ -830,11 +834,11 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon) fprintf(self->fHKL,"filetime = %s\n",pBueffel); GetLambda(self->pCryst,&fVal); fprintf(self->fHKL,"lambda = %f Angstroem\n",fVal); - GetUB(self->pCryst,fUB); + GetUB(self->pCryst,fUB); fprintf(self->fHKL, "UB = %7.6f %7.6f %7.6f %7.6f %7.6f %7.6f %7.6f %7.6f %7.6f\n", fUB[0], fUB[1],fUB[2],fUB[3],fUB[4],fUB[5],fUB[6],fUB[7],fUB[8]); - + /* write sample & user info */ strcpy(pBueffel,"CCL, Instr=TRICS, "); pVar = FindVariable(pServ->pSics,"sample"); @@ -852,8 +856,58 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon) strcat(pBueffel,pBuff); } fprintf(self->fRefl,"%s\n",pBueffel); + fprintf(self->fRefl,"lambda = %f Angstroem\n",fVal); + fprintf(self->fRefl, + "UB = %7.6f %7.6f %7.6f %7.6f %7.6f %7.6f %7.6f %7.6f %7.6f\n", + fUB[0], fUB[1],fUB[2],fUB[3],fUB[4],fUB[5],fUB[6],fUB[7],fUB[8]); + /* + * zero points for Juerg + */ + pBueffel[0] = '\0'; + if(self->pCryst->pTheta != NULL){ + MotorGetPar(self->pCryst->pTheta,"softzero",&zero); + snprintf(pBuff,131,"stt.zero = %f ", zero); + strcat(pBueffel,pBuff); + } + if(self->pCryst->pOmega != NULL){ + MotorGetPar(self->pCryst->pOmega,"softzero",&zero); + snprintf(pBuff,131,"om.zero = %f ", zero); + strcat(pBueffel,pBuff); + } + if(self->pCryst->pChi != NULL){ + MotorGetPar(self->pCryst->pChi,"softzero",&zero); + snprintf(pBuff,131,"chi.zero = %f ", zero); + strcat(pBueffel,pBuff); + } + if(self->pCryst->pPhi != NULL){ + MotorGetPar(self->pCryst->pPhi,"softzero",&zero); + snprintf(pBuff,131,"phi.zero = %f ", zero); + strcat(pBueffel,pBuff); + } + fprintf(self->fRefl,"%s\n",pBueffel); + + /* + * CEX motors .... + */ + pBueffel[0] = '\0'; + pMot = FindCommandData(pServ->pSics,"cex1","Motor"); + if(pMot != NULL){ + MotorGetSoftPosition(pMot,pCon,&pos); + snprintf(pBuff,131,"cex1 = %f ",pos); + strcat(pBueffel,pBuff); + } + pMot = FindCommandData(pServ->pSics,"cex2","Motor"); + if(pMot != NULL){ + MotorGetSoftPosition(pMot,pCon,&pos); + snprintf(pBuff,131,"cex2 = %f ",pos); + strcat(pBueffel,pBuff); + } + if(strlen(pBueffel) > 1) { + fprintf(self->fRefl,"%s\n",pBueffel); + } + return 1; } /*---------------------------------------------------------------------------*/ @@ -1536,7 +1590,7 @@ static int ScanReflection(pMesure self, float twoTheta, SConnection *pCon) strtolower(argv[1]); /*------ start */ - if(strcmp(argv[1],"start") == 0) + if(strcmp(argv[1],"open") == 0) { if(!SCMatchRights(pCon,usUser)) { diff --git a/motor.c b/motor.c index 84286166..08c2d105 100644 --- a/motor.c +++ b/motor.c @@ -1058,22 +1058,23 @@ extern MotorDriver *MakePiPiezo(Tcl_Interp *pTcl, char *pArray); iLen = ObParLength(self->ParArray); sprintf(pBueffel,"Parameter Listing for motor %s",self->name); SCWrite(pCon,pBueffel,eValue); + sprintf(pBueffel,"%s.Position = %f\n", self->name,self->fPosition); + SCWrite(pCon,pBueffel,eStatus); + sprintf(pBueffel,"%s.TargetPosition = %f\n", self->name,self->fTarget); + SCWrite(pCon,pBueffel,eStatus); + + snprintf(pBueffel,511,"%s.hardlowerlim = %f",self->name, + self->pDriver->fLower); + SCWrite(pCon,pBueffel,eValue); snprintf(pBueffel,511,"%s.hardupperlim = %f",self->name, self->pDriver->fUpper); SCWrite(pCon,pBueffel,eValue); - snprintf(pBueffel,511,"%s.hardlowerlim = %f",self->name, - self->pDriver->fLower); - SCWrite(pCon,pBueffel,eValue); for(i = 0; i < iLen; i++) { sprintf(pBueffel,"%s.%s = %f\n",self->name, self->ParArray[i].name,self->ParArray[i].fVal); SCWrite(pCon,pBueffel,eStatus); } - sprintf(pBueffel,"%s.Position = %f\n", self->name,self->fPosition); - SCWrite(pCon,pBueffel,eStatus); - sprintf(pBueffel,"%s.TargetPosition = %f\n", self->name,self->fTarget); - SCWrite(pCon,pBueffel,eStatus); /* list driver parameters when appropriate diff --git a/protocol.c b/protocol.c index cc790d5d..a099183b 100644 --- a/protocol.c +++ b/protocol.c @@ -191,6 +191,7 @@ static int ContextDo(SConnection *pCon, SicsInterp *pSics, void *pData, SCPushContext2(pCon,comCon); status = InterpExecute(pSics,pCon,command); + SCWrite(pCon,"",eFinish); SCPopContext(pCon); return status; } @@ -442,26 +443,18 @@ int SCWriteSycamore(SConnection *pCon, char *pBuffer, int iOut) char **argv = NULL; int argc; char *parser = "sycformat "; - char batchName[50]; - strcpy(batchName,"::ansto::batch::next"); CommandList *pCommand = NULL; if(!SCVerifyConnection(pCon)) { - DeleteDynString(parseCmd); return 0; } comCon = SCGetContext(pCon); - if (strcmp(comCon.deviceID, batchName) == 0) { - DeleteDynString(parseCmd); - return 1; - } /* Return 0 without dying if no message data */ if(pBuffer == NULL) { - DeleteDynString(parseCmd); return 0; } diff --git a/scan.c b/scan.c index 911649af..4911cef9 100644 --- a/scan.c +++ b/scan.c @@ -217,11 +217,7 @@ static void ConfigureScanDict(pStringDict dict) int AddScanVar(pScanData self, SicsInterp *pSics, SConnection *pCon, char *name, float fStart, float fStep) { - CommandList *pCom = NULL; - pIDrivable pDriv = NULL; - pDummy pData = NULL; pVarEntry pVar = NULL; - char pBueffel[512]; if(self->iActive) { @@ -240,6 +236,31 @@ static void ConfigureScanDict(pStringDict dict) DynarPut(self->pScanVar,self->iScanVar,pVar); self->iScanVar++; + return 1; + } +/*-------------------------------------------------------------------------*/ + int AddLogVar(pScanData self, SicsInterp *pSics, SConnection *pCon, + char *name) + { + pVarEntry pVar = NULL; + + if(self->iActive) + { + SCWrite(pCon,"ERROR: cannot change parameters while scan is running", + eError); + return 0; + } + + pVar = MakeLogVar(pSics,pCon,name); + if(pVar == NULL) + { + return 0; + } + + /* put it away */ + DynarPut(self->pScanVar,self->iScanVar,pVar); + self->iScanVar++; + return 1; } /*--------------------------------------------------------------------------*/ @@ -277,8 +298,15 @@ static void ConfigureScanDict(pStringDict dict) pVar = (pVarEntry)pData; if(pVar) { - fprintf(fd,"%s add %s %f %f\n", self->objectName, ScanVarName(pVar), - ScanVarStart(pVar), ScanVarStep(pVar)); + if(isLogVar(pVar)) + { + fprintf(fd,"%s log %s\n", self->objectName, ScanVarName(pVar)); + } + else + { + fprintf(fd,"%s add %s %f %f\n", self->objectName, ScanVarName(pVar), + ScanVarStart(pVar), ScanVarStep(pVar)); + } } pData = NULL; } @@ -1961,7 +1989,7 @@ static int DumpScan(pScanData self, SConnection *pCon) return 0; } /*---------- add command */ - if(strcmp(argv[1],"add") == 0) + if(strcmp(argv[1],"add") == 0) { if(argc < 5) { @@ -1994,6 +2022,23 @@ static int DumpScan(pScanData self, SConnection *pCon) } return iRet; } + else if(strcmp(argv[1],"log") == 0) + { + if(argc < 3) + { + sprintf(pBueffel, + "ERROR: Insufficient number of arguments given for %s log", + argv[0]); + SCWrite(pCon,pBueffel,eError); + return 0; + } + iRet = AddLogVar(self,pSics,pCon,argv[2]); + if(iRet) + { + SCSendOK(pCon); + } + return iRet; + } /* --------clear */ else if(strcmp(argv[1],"clear") == 0) { diff --git a/scanvar.c b/scanvar.c index 6f49bf36..800c2a6a 100644 --- a/scanvar.c +++ b/scanvar.c @@ -65,6 +65,55 @@ pVarEntry MakeScanVar(SicsInterp *pSics, SConnection *pCon, char return pVar; } +/*----------------------------------------------------------------------*/ +pVarEntry MakeLogVar(SicsInterp *pSics, SConnection *pCon, char *name){ + CommandList *pCom = NULL; + pIDrivable pDriv = NULL; + pDummy pData = NULL; + pVarEntry pVar = NULL; + char pBueffel[512]; + + /* + allocate space + */ + pVar = (pVarEntry)malloc(sizeof(VarEntry)); + if(pVar == NULL){ + SCWrite(pCon,"ERROR: out of memory allocating scan variable",eError); + return NULL; + } + memset(pVar,0,sizeof(VarEntry)); + + /* find the thing */ + pCom = FindCommand(pSics,name); + if(!pCom){ + snprintf(pBueffel,511,"ERROR: Cannot find variable %s to log",name); + SCWrite(pCon,pBueffel,eError); + return NULL; + } + pData = (pDummy)pCom->pData; + if(!pData){ + snprintf(pBueffel,511,"ERROR: Cannot find data for variable %s",name); + SCWrite(pCon,pBueffel,eError); + return NULL; + } + pDriv = pData->pDescriptor->GetInterface(pData,DRIVEID); + if(!pDriv){ + snprintf(pBueffel,511, + "ERROR: variable %s is NOT driveable and cannot be logged",name); + SCWrite(pCon,pBueffel,eError); + return NULL; + } + + /* got everything, fill in the VarEntry structure */ + strcpy(pVar->Name,name); + pVar->pInter = pDriv; + pVar->pObject = pData; + pVar->logVar = 1; + pVar->dataList = LLDcreate(sizeof(float)); + + return pVar; +} + /*------------------------------------------------------------------*/ void InitScanVar(pVarEntry pVar){ LLDdelete(pVar->dataList); @@ -105,6 +154,13 @@ int StartScanVar(pVarEntry pVar, SConnection *pCon, int i){ char pBueffel[512]; int status; + /** + * logged variables are not started + */ + if(pVar->logVar == 1){ + return 1; + } + pDum = (pDummy)pVar->pObject; fVal = pVar->fStart + i * pVar->fStep; status = StartDevice(pServ->pExecutor, @@ -122,6 +178,32 @@ int StartScanVar(pVarEntry pVar, SConnection *pCon, int i){ return 1; } /*-------------------------------------------------------------------------*/ +int CheckScanVar(pVarEntry pVar, SConnection *pCon, int np){ + int status; + char pError[132], pBueffel[512]; + + if(pVar->logVar == 1){ + return 1; + } + + status = pVar->pInter->CheckLimits(pVar->pObject, + pVar->fStart,pError,131); + if(status != 1){ + snprintf(pBueffel,511,"ERROR: %s, scan aborted",pError); + SCWrite(pCon,pBueffel,eError); + return 0; + } + status = pVar->pInter->CheckLimits(pVar->pObject, + pVar->fStart + np * pVar->fStep, + pError,131); + if(status != 1){ + snprintf(pBueffel,511,"ERROR: %s, scan aborted",pError); + SCWrite(pCon,pBueffel,eError); + return 0; + } + return 1; +} +/*-------------------------------------------------------------------------*/ void AppendScanVar(pVarEntry pVar, float pos){ float fVal = pos; LLDnodeAppendFrom(pVar->dataList,&fVal); @@ -151,4 +233,8 @@ void CopyScanVar(pVarEntry pVar, float *fData, int np){ status = LLDnodePtr2Next(pVar->dataList); } } +/*-------------------------------------------------------------------------*/ +int isLogVar(pVarEntry pVar){ + return pVar->logVar; +} diff --git a/scanvar.h b/scanvar.h index 93303639..7bb1dbfb 100644 --- a/scanvar.h +++ b/scanvar.h @@ -21,6 +21,7 @@ float fStep; float *fData; int dataList; + int logVar; }VarEntry, *pVarEntry; /*---------------------------------------------------------------------*/ @@ -34,13 +35,22 @@ * @param start The start position from which to scan * @param step The step width with which to scan. * @return A pointer to a new scan variable object on success, NULL - * else + * else NULL */ pVarEntry MakeScanVar(SicsInterp *pSics, SConnection *pCon, char *name, float start, float step); + /* + * Make a variable which is logged during the scan + * @param pSics The SICS interpreter to search for the variable + * @param pCon A connection to report problems to + * @param name The name of the variable to log + * @return A pointer to a new scan variable object on success, NULL + * else NULL + */ + pVarEntry MakeLogVar(SicsInterp *pSics, SConnection *pCon, char *name); /** * InitScanVar clears the list of scan points - * @param pvar The scna variable to clear + * @param pvar The scan variable to clear */ void InitScanVar(pVarEntry pVar); /** @@ -66,6 +76,14 @@ * @return The step width for the scan. */ float ScanVarStep(pVarEntry pVar); + /** + * check if the scan is possible, i.e the scan variable does + * not violate the limits in the scan + * @param pVar The scan variable to check + * @param pCon The connection to report errors to + * @return 1 when OK, 0 when the limits are violated. + */ + int CheckScanVar(pVarEntry pVar, SConnection *pCon, int np); /** * StartScanVar starts the scan variable to drive to the next * position. @@ -96,5 +114,8 @@ * @param np The number of slots in fData. */ void CopyScanVar(pVarEntry pVar, float *fData, int np); - + /** + * enquires if a variable is a logged variable or a proper scan variable + */ + int isLogVar(pVarEntry pVar); #endif diff --git a/sicslist.c b/sicslist.c index 60bfc496..0985e17f 100644 --- a/sicslist.c +++ b/sicslist.c @@ -22,10 +22,11 @@ static void listAllObjects(SConnection *pCon, SicsInterp *pSics){ pCom = pSics->pCList; while(pCom != NULL){ - Tcl_DStringAppendElement(&lst,pCom->pName); + Tcl_DStringAppend(&lst,pCom->pName,-1); pCom = pCom->pNext; + Tcl_DStringAppend(&lst, ", ",-1); } - Tcl_DStringAppendElement(&lst,"ENDLIST"); + Tcl_DStringAppend(&lst,"ENDLIST",-1); SCWrite(pCon,Tcl_DStringValue(&lst), eValue); Tcl_DStringFree(&lst); } @@ -37,45 +38,45 @@ static void listAllObjectData(SConnection *pCon, char *name, pDummy data){ Tcl_DStringInit(&lst); if(data == NULL){ - snprintf(buffer,255,"%s = command", name); - Tcl_DStringAppendElement(&lst,buffer); + snprintf(buffer,255,"%s = command, ", name); + Tcl_DStringAppend(&lst,buffer,-1); } else { - snprintf(buffer,255,"%s=obj", name); - Tcl_DStringAppendElement(&lst,buffer); - snprintf(buffer,255,"type=%s",data->pDescriptor->name); - Tcl_DStringAppendElement(&lst,buffer); + snprintf(buffer,255,"%s=obj, ", name); + Tcl_DStringAppend(&lst,buffer,-1); + snprintf(buffer,255,"type=%s, ",data->pDescriptor->name); + Tcl_DStringAppend(&lst,buffer,-1); if(data->pDescriptor->GetInterface(data,DRIVEID) != NULL){ - snprintf(buffer,255,"drivable=true"); + snprintf(buffer,255,"drivable=true, "); } else { - snprintf(buffer,255,"drivable=false"); + snprintf(buffer,255,"drivable=false, "); } - Tcl_DStringAppendElement(&lst,buffer); + Tcl_DStringAppend(&lst,buffer,-1); if(data->pDescriptor->GetInterface(data,COUNTID) != NULL){ - snprintf(buffer,255,"countable=true"); + snprintf(buffer,255,"countable=true, "); } else { - snprintf(buffer,255,"countable=false"); + snprintf(buffer,255,"countable=false, "); } - Tcl_DStringAppendElement(&lst,buffer); + Tcl_DStringAppend(&lst,buffer,-1); if(data->pDescriptor->GetInterface(data,CALLBACKINTERFACE) != NULL){ - snprintf(buffer,255,"callback=true"); + snprintf(buffer,255,"callback=true, "); } else { - snprintf(buffer,255,"callback=false"); + snprintf(buffer,255,"callback=false, "); } - Tcl_DStringAppendElement(&lst,buffer); + Tcl_DStringAppend(&lst,buffer,-1); if(data->pDescriptor->GetInterface(data,ENVIRINTERFACE) != NULL){ - snprintf(buffer,255,"environment=true"); + snprintf(buffer,255,"environment=true, "); } else { - snprintf(buffer,255,"environment=false"); + snprintf(buffer,255,"environment=false, "); } - Tcl_DStringAppendElement(&lst,buffer); + Tcl_DStringAppend(&lst,buffer,-1); prop = data->pDescriptor->pKeys; while(prop != NULL){ - snprintf(buffer,255,"%s=%s",prop->name,prop->value); - Tcl_DStringAppendElement(&lst,buffer); + snprintf(buffer,255,"%s=%s, ",prop->name,prop->value); + Tcl_DStringAppend(&lst,buffer,-1); prop = prop->pNext; } } - Tcl_DStringAppendElement(&lst,"ENDLIST"); + Tcl_DStringAppend(&lst,"ENDLIST",-1); SCWrite(pCon,Tcl_DStringValue(&lst),eValue); Tcl_DStringFree(&lst); } @@ -190,7 +191,8 @@ static void listToString(int list,Tcl_DString *txt){ while(status != 0){ pPtr = (char *)LLDnodePtr(list); if(pPtr != NULL){ - Tcl_DStringAppendElement(txt,pPtr); + Tcl_DStringAppend(txt,pPtr,-1); + Tcl_DStringAppend(txt, ", ",-1); } status = LLDnodePtr2Next(list); } @@ -205,7 +207,7 @@ static void printKeyTypes(SicsInterp *pSics, SConnection *pCon, Tcl_DString result; if(strcmp(key,"interface") == 0){ - SCWrite(pCon,"drivable countable callback environment",eValue); + SCWrite(pCon,"drivable, countable, callback, environment",eValue); return; } @@ -254,11 +256,12 @@ static void printObjectsMatchingKeyVal(SicsInterp *pSics, } } if(status == 1){ - Tcl_DStringAppendElement(&result,pCom->pName); + Tcl_DStringAppend(&result,pCom->pName,-1); + Tcl_DStringAppend(&result, ", ",-1); } pCom = pCom->pNext; } - Tcl_DStringAppendElement(&result,"ENDLIST"); + Tcl_DStringAppend(&result,"ENDLIST",-1); SCWrite(pCon,Tcl_DStringValue(&result),eValue); Tcl_DStringFree(&result); } @@ -368,11 +371,11 @@ static int printServer(SConnection *pCon){ Tcl_DStringInit(&txt); current = pSICSOptions; while(current != NULL){ - snprintf(buffer,511,"%s=%s",current->name,current->value); - Tcl_DStringAppendElement(&txt,buffer); + snprintf(buffer,511,"%s=%s, ",current->name,current->value); + Tcl_DStringAppend(&txt,buffer,-1); current = current->pNext; } - Tcl_DStringAppendElement(&txt,"ENDLIST"); + Tcl_DStringAppend(&txt,"ENDLIST",-1); SCWrite(pCon,Tcl_DStringValue(&txt),eValue); Tcl_DStringFree(&txt); return 1; @@ -437,11 +440,12 @@ static void printMatch(SConnection *pCon, SicsInterp *pSics, current = pSics->pCList; while(current != NULL){ if(!match(mask,current->pName)){ - Tcl_DStringAppendElement(&txt, current->pName); + Tcl_DStringAppend(&txt, current->pName,-1); + Tcl_DStringAppend(&txt, ", ",-1); } current = current->pNext; } - Tcl_DStringAppendElement(&txt,"ENDLIST"); + Tcl_DStringAppend(&txt,"ENDLIST",-1); SCWrite(pCon,Tcl_DStringValue(&txt), eValue); Tcl_DStringFree(&txt); } diff --git a/sicsstat.tcl b/sicsstat.tcl index e69de29b..552344a7 100644 --- a/sicsstat.tcl +++ b/sicsstat.tcl @@ -0,0 +1,7 @@ +# Counter counter +counter SetPreset 500.000000 +counter SetMode Timer +hm CountMode timer +hm preset 600.000000 +hm genbin 1000.000000 1000.000000 1000 +hm init diff --git a/stdscan.c b/stdscan.c index 2da901bf..8a25f6ff 100644 --- a/stdscan.c +++ b/stdscan.c @@ -415,27 +415,12 @@ int prepareDataFile(pScanData self){ pVar = (pVarEntry)pDings; if(pVar) { - /* start value */ - fVal = ScanVarStart(pVar); - iRet = pVar->pInter->CheckLimits(pVar->pObject, - fVal,pBueffel,511); + iRet = CheckScanVar(pVar,self->pCon,self->iNP - 1); if(!iRet) { - sprintf(pMessage,"ERROR: %s, scan aborted",pBueffel); - SCWrite(self->pCon,pBueffel,eError); return 0; } - /* end value */ - fVal = pVar->fStart + (self->iNP - 1) * ScanVarStep(pVar); - iRet = pVar->pInter->CheckLimits(pVar->pObject, - fVal,pBueffel,511); - if(!iRet) - { - sprintf(pMessage,"ERROR: %s, scan aborted",pBueffel); - SCWrite(self->pCon,pBueffel,eError); - return 0; - } - InitScanVar(pVar); + InitScanVar(pVar); } else { @@ -478,27 +463,12 @@ int prepareDataFile(pScanData self){ pVar = (pVarEntry)pDings; if(pVar) { - /* start value */ - fVal = ScanVarStart(pVar); - iRet = pVar->pInter->CheckLimits(pVar->pObject, - fVal,pBueffel,511); + iRet = CheckScanVar(pVar,self->pCon,self->iNP); if(!iRet) { - sprintf(pMessage,"ERROR: %s, scan aborted",pBueffel); - SCWrite(self->pCon,pBueffel,eError); return 0; } - /* end value */ - fVal = pVar->fStart + (self->iNP - 1) * ScanVarStep(pVar); - iRet = pVar->pInter->CheckLimits(pVar->pObject, - fVal,pBueffel,511); - if(!iRet) - { - sprintf(pMessage,"ERROR: %s, scan aborted",pBueffel); - SCWrite(self->pCon,pBueffel,eError); - return 0; - } - InitScanVar(pVar); + InitScanVar(pVar); } else { @@ -522,7 +492,6 @@ int prepareDataFile(pScanData self){ pVarEntry pVar = NULL; void *pDings; int i, iRet; - float fVal; char pBueffel[512]; char pMessage[1024]; @@ -537,9 +506,7 @@ int prepareDataFile(pScanData self){ pVar = (pVarEntry)pDings; if(pVar) { - /* start value */ - fVal = ScanVarStart(pVar); - InitScanVar(pVar); + InitScanVar(pVar); } else { @@ -647,6 +614,45 @@ int prepareDataFile(pScanData self){ { return CollectScanDataIntern(self,iPoint,1); } +/*------------------------------------------------------------------------*/ + static int CollectSilent(pScanData self, int iPoint) + { + pVarEntry pVar = NULL; + void *pDings; + int i, iRet, status, jochenFlag = 1; + float fVal; + CountEntry sCount; + + assert(self); + assert(self->pCon); + InitCountEntry(&sCount); + + /* loop over all scan variables */ + status = 1; + for(i = 0; i < self->iScanVar; i++) + { + DynarGet(self->pScanVar,i,&pDings); + pVar = (pVarEntry)pDings; + if(pVar) + { + if(jochenFlag == 1 && + strcmp(pVar->pObject->pDescriptor->name, "Motor") == 0) + { + MotorGetSoftPosition((pMotor)pVar->pObject,self->pCon,&fVal); + } + else + { + fVal = pVar->pInter->GetValue(pVar->pObject,self->pCon); + } + AppendScanVar(pVar,fVal); + } + } + + /* store counter data */ + sCount = CollectCounterData(self); + + return 1; + } /*--------------------------------------------------------------------------*/ static int StartToDrive(pScanData self, int iPoint) { @@ -927,6 +933,8 @@ int StandardScanWrapper(SConnection *pCon, SicsInterp *pSics, void *pData, return ScanCount(self,iPoint); } else if(strcmp(argv[1],"collect") == 0){ return CollectScanData(self,iPoint); + } else if(strcmp(argv[1],"silentcollect") == 0){ + return CollectSilent(self,iPoint); } else if(strcmp(argv[1],"writepoint") == 0){ return WriteScanPoints(self,iPoint); } else { diff --git a/sycFormat.tcl b/sycFormat.tcl index 78c21694..7a92daef 100644 --- a/sycFormat.tcl +++ b/sycFormat.tcl @@ -28,16 +28,17 @@ if { [info exists sycinit] == 0 } { # 'tag' and 'msgString' parameters must be passed within braces # eg sycFormat con0004 t000005 s1 event {s1} {type.position status.HWBusy} proc sycformat {connID transID devID msgFlag tag msgString} { - global statusMap cache + global statusMap set fullmatch ""; set msg ""; set eventType ""; set status "" set position "" proc _prefix {flag} { - upvar connID cID transID tID devID dID - return "\[$cID:$tID:$dID:$flag\]" + upvar connID cID transID tID devID dID + return "\[$cID:$tID:$dID:$flag\]" } + set msgString [string trim $msgString] regexp {<(.*)>} $msgString match msg regexp {type\.(\w*)} $msgString match eventType regexp {status\.(\w*)} $msgString match status @@ -48,16 +49,15 @@ if { [info exists sycinit] == 0 } { } switch $msgFlag { - "start" { - set output "[_prefix start] $msgString" - - } "event" { switch $eventType { "POSITION" { regexp {(\w+)\.position *= *(\d+(?:\.\d+)?)} $msgString match device position set output "[_prefix event] $tag={type=$eventType,$devID.position=$position}" } + "STATUS" { + set output "[_prefix event] $tag={type=$eventType,$devID.status=$statusMap($status)}" + } default { # Error } @@ -83,7 +83,7 @@ if { [info exists sycinit] == 0 } { } } default { - set output "[_prefix $msgFlag] $msgString" + set output "[_prefix $msgFlag] $tag=\{$msgString\}" } } return $output diff --git a/tcldrivable.c b/tcldrivable.c index eb0bbaff..0b91c1f2 100644 --- a/tcldrivable.c +++ b/tcldrivable.c @@ -565,6 +565,7 @@ int TclDrivableInvoke(SConnection *pCon, SicsInterp *pSics, /* invoke and report */ + memset(pError,0,132*sizeof(char)); switch(functionIndex){ case TCLHALT: if(!pDriv->Halt){