/*--------------------------------------------------------------------------- L A K E S H O R E 3 4 0 This is the implementation for a LAKESHORE340 object derived from a more general environment controller. Mark Koennecke, August 1997 Mark Lesha, January 2006 (based on ITC4 code) Copyright: Labor fuer Neutronenstreuung Paul Scherrer Institut CH-5423 Villigen-PSI The authors hereby grant permission to use, copy, modify, distribute, and license this software and its documentation for any purpose, provided that existing copyright notices are retained in all copies and that this notice is included verbatim in any distributions. No written agreement, license, or royalty fee is required for any of the authorized uses. Modifications to this software may be copyrighted by their authors and need not follow the licensing terms described here, provided that the new terms are clearly indicated on the first page of each file where they apply. IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. ----------------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "lakeshore340.h" /*---------------------------------------------------------------------------*/ int LAKESHORE340SetPar(pEVControl self, char *name, float fNew, SConnection *pCon) { int iRet; /* check authorisation */ if(!SCMatchRights(pCon,usUser)) { SCWrite(pCon,"ERROR: you are not authorised to change this parameter", eError); return 0; } /* just catch those three names which we understand */ if(strcmp(name,"sensor") == 0) { iRet = SetSensorLAKESHORE340(self->pDriv,(int)fNew); if(!iRet) { SCWrite(pCon,"ERROR: value out of range",eError); return 0; } iRet = ConfigLAKESHORE340(self->pDriv); if(iRet != 1) { SCWrite(pCon,"ERROR: LAKESHORE340 configuration failed! ",eError); SCWrite(pCon,"INFO: Probably comm problem, Retry!",eError); return 0; } SCSendOK(pCon); return 1; } else if(strcmp(name,"control") == 0) { iRet = SetControlLAKESHORE340(self->pDriv,(int)fNew); if(!iRet) { SCWrite(pCon,"ERROR: value out of range",eError); return 0; } iRet = ConfigLAKESHORE340(self->pDriv); if(iRet != 1) { SCWrite(pCon,"ERROR: LAKESHORE340 configuration failed! ",eError); SCWrite(pCon,"INFO: Probably comm problem, Retry!",eError); return 0; } SCSendOK(pCon); return 1; } else if(strcmp(name,"timeout") == 0) { iRet = SetTMOLAKESHORE340(self->pDriv,(int)fNew); if(!iRet) { SCWrite(pCon,"ERROR: value out of range",eError); return 0; } iRet = ConfigLAKESHORE340(self->pDriv); if(iRet != 1) { SCWrite(pCon,"ERROR: LAKESHORE340 configuration failed! ",eError); SCWrite(pCon,"INFO: Probably comm problem, Retry!",eError); return 0; } SCSendOK(pCon); return 1; } /* Note divisors and multipliers will not be used with the LAKESHORE340 but leave in for back compatibility */ else if(strcmp(name,"divisor") == 0) { iRet = SetDivisorLAKESHORE340(self->pDriv,fNew); if(!iRet) { SCWrite(pCon,"ERROR: value out of range",eError); return 0; } iRet = ConfigLAKESHORE340(self->pDriv); if(iRet != 1) { SCWrite(pCon,"ERROR: LAKESHORE340 configuration failed! ",eError); SCWrite(pCon,"INFO: Probably comm problem, Retry!",eError); return 0; } SCSendOK(pCon); return 1; } else if(strcmp(name,"multiplicator") == 0) { iRet = SetMultLAKESHORE340(self->pDriv,fNew); if(!iRet) { SCWrite(pCon,"ERROR: value out of range",eError); return 0; } iRet = ConfigLAKESHORE340(self->pDriv); if(iRet != 1) { SCWrite(pCon,"ERROR: LAKESHORE340 configuration failed! ",eError); SCWrite(pCon,"INFO: Probably comm problem, Retry!",eError); return 0; } SCSendOK(pCon); return 1; } else return EVCSetPar(self,name,fNew,pCon); } /*--------------------------------------------------------------------------*/ int LAKESHORE340GetPar(pEVControl self, char *name, float *fNew) { int iRet; float fDiv; /* just catch those two names which we understand */ if(strcmp(name,"sensor") == 0) { iRet = GetSensorLAKESHORE340(self->pDriv); *fNew = (float)iRet; return 1; } else if(strcmp(name,"control") == 0) { iRet = GetControlLAKESHORE340(self->pDriv); *fNew = (float)iRet; return 1; } else if(strcmp(name,"timeout") == 0) { iRet = GetTMOLAKESHORE340(self->pDriv); *fNew = (float)iRet; return 1; } else if(strcmp(name,"divisor") == 0) { fDiv = GetDivisorLAKESHORE340(self->pDriv); *fNew = fDiv; return 1; } else if(strcmp(name,"multiplicator") == 0) { fDiv = GetMultLAKESHORE340(self->pDriv); *fNew = fDiv; return 1; } else return EVCGetPar(self,name,fNew); } /*---------------------------------------------------------------------------*/ int LAKESHORE340List(pEVControl self, SConnection *pCon) { char pBueffel[132]; int iRet; iRet = EVCList(self,pCon); sprintf(pBueffel,"%s.sensor = %d\n",self->pName, GetSensorLAKESHORE340(self->pDriv)); SCWrite(pCon,pBueffel,eValue); sprintf(pBueffel,"%s.control = %d\n",self->pName, GetControlLAKESHORE340(self->pDriv)); SCWrite(pCon,pBueffel,eValue); sprintf(pBueffel,"%s.timeout = %d\n",self->pName, GetTMOLAKESHORE340(self->pDriv)); SCWrite(pCon,pBueffel,eValue); sprintf(pBueffel,"%s.divisor = %f\n",self->pName, GetDivisorLAKESHORE340(self->pDriv)); SCWrite(pCon,pBueffel,eValue); sprintf(pBueffel,"%s.multiplicator = %f\n",self->pName, GetMultLAKESHORE340(self->pDriv)); SCWrite(pCon,pBueffel,eValue); return iRet; } /*-------------------------------------------------------------------------*/ int LAKESHORE340Wrapper(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]) { pEVControl self = NULL; char pBueffel[256]; int iRet; double fNum; float fVal; self = (pEVControl)pData; assert(self); assert(pCon); assert(pSics); if(argc < 2) { return EVControlWrapper(pCon,pSics,pData,argc,argv); } strtolower(argv[1]); if((strcmp(argv[1],"sensor") == 0) || (strcmp(argv[1],"control") == 0) || (strcmp(argv[1],"timeout") == 0) || (strcmp(argv[1],"divisor") == 0) || (strcmp(argv[1],"multiplicator") == 0) ) { if(argc > 2) /* set case */ { iRet = Tcl_GetDouble(pSics->pTcl,argv[2],&fNum); if(iRet != TCL_OK) { sprintf(pBueffel,"ERROR: expected number, got %s",argv[2]); SCWrite(pCon,pBueffel,eError); return 0; } return LAKESHORE340SetPar(self,argv[1],(float)fNum,pCon); } else /* get case */ { iRet = LAKESHORE340GetPar(self,argv[1],&fVal); sprintf(pBueffel,"%s.%s = %f\n",self->pName, argv[1],fVal); SCWrite(pCon,pBueffel,eValue); return 1; } } else if(strcmp(argv[1],"list") == 0) { return LAKESHORE340List(self,pCon); } else { return EVControlWrapper(pCon,pSics,pData,argc,argv); } /* not reached */ return 0; }