Cleaned up ANSTO code to merge with sinqdev.sics
This is our new RELEASE-4_0 branch which was taken from ansto/93d9a7c Conflicts: .gitignore SICSmain.c asynnet.c confvirtualmot.c counter.c devexec.c drive.c event.h exebuf.c exeman.c histmem.c interface.h motor.c motorlist.c motorsec.c multicounter.c napi.c napi.h napi4.c network.c nwatch.c nxscript.c nxxml.c nxxml.h ofac.c reflist.c scan.c sicshipadaba.c sicsobj.c site_ansto/docs/Copyright.txt site_ansto/instrument/lyrebird/config/tasmad/sicscommon/nxsupport.tcl site_ansto/instrument/lyrebird/config/tasmad/taspub_sics/tasscript.tcl statusfile.c tasdrive.c tasub.c tasub.h tasublib.c tasublib.h
This commit is contained in:
66
motor.c
66
motor.c
@@ -82,7 +82,13 @@
|
||||
#define MOVECOUNT 11
|
||||
|
||||
extern double DoubleTime(void);
|
||||
|
||||
static void SetMotorError(pMotor self, char *text)
|
||||
{
|
||||
if(self->error != NULL){
|
||||
free(self->error);
|
||||
}
|
||||
self->error = strdup(text);
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
static void *MotorGetInterface(void *pData, int iID)
|
||||
{
|
||||
@@ -383,17 +389,18 @@ static int reportAndFixError(pMotor self, SConnection * pCon)
|
||||
switch (iRet) {
|
||||
case MOTFAIL:
|
||||
snprintf(pBueffel, 255, "ERROR: %s on %s", pError, self->name);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
SCWrite(pCon, pBueffel, eLogError);
|
||||
newStatus = HWFault;
|
||||
SetMotorError(self,pError);
|
||||
break;
|
||||
case MOTREDO:
|
||||
snprintf(pBueffel, 255, "WARNING: %s on %s", pError, self->name);
|
||||
SCWrite(pCon, pBueffel, eWarning);
|
||||
SCWrite(pCon, pBueffel, eLog);
|
||||
newStatus = statusRunTo(self, pCon);
|
||||
break;
|
||||
case MOTOK:
|
||||
snprintf(pBueffel, 255, "WARNING: %s on %s", pError, self->name);
|
||||
SCWrite(pCon, pBueffel, eWarning);
|
||||
SCWrite(pCon, pBueffel, eLog);
|
||||
newStatus = HWIdle;
|
||||
break;
|
||||
default:
|
||||
@@ -541,7 +548,7 @@ static int MotorGetParImpl(pMotor self, char *name, float *fVal)
|
||||
*fVal = self->pDriver->fLower;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
pPar = ObParFind(self->ParArray, name);
|
||||
if (pPar) {
|
||||
*fVal = pPar->fVal;
|
||||
@@ -689,8 +696,8 @@ static int MotorGetHardPositionImpl(pMotor self, SConnection * pCon,
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static long MotorRunImpl(void *sulf, SConnection * pCon, float fNew)
|
||||
{
|
||||
float fHard, fCurrHard, fNewHard, fZero;
|
||||
int i, iRet, iCode, iSign;
|
||||
float fHard;
|
||||
int i, iRet, iCode;
|
||||
char pBueffel[512];
|
||||
char pError[132];
|
||||
pMotor self;
|
||||
@@ -709,13 +716,7 @@ static long MotorRunImpl(void *sulf, SConnection * pCon, float fNew)
|
||||
SCSetInterrupt(pCon, eAbortBatch);
|
||||
return 0;
|
||||
}
|
||||
self->pDriver->GetPosition(self->pDriver, &fCurrHard);
|
||||
iSign = ObVal(self->ParArray, SIGN);
|
||||
fZero = ObVal(self->ParArray, SZERO);
|
||||
fNewHard = iSign * (fNew + fZero);
|
||||
if (absf(fCurrHard - fNewHard) <= ObVal(self->ParArray, PREC)) {
|
||||
return OKOK;
|
||||
}
|
||||
SetMotorError(self,"None");
|
||||
|
||||
/* check boundaries first */
|
||||
iRet = MotorCheckBoundaryImpl(self, fNew, &fHard, pError, 131);
|
||||
@@ -723,6 +724,7 @@ static long MotorRunImpl(void *sulf, SConnection * pCon, float fNew)
|
||||
snprintf(pBueffel, 511, "ERROR: %s", pError);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
SCSetInterrupt(pCon, eAbortOperation);
|
||||
SetMotorError(self,pError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -745,6 +747,7 @@ static long MotorRunImpl(void *sulf, SConnection * pCon, float fNew)
|
||||
ServerWriteGlobal(pBueffel, eError);
|
||||
SCSetInterrupt(pCon, eAbortBatch);
|
||||
self->pDrivInt->iErrorCount = 0;
|
||||
SetMotorError(self,"Motor ALARM!!!!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -769,6 +772,7 @@ static long MotorRunImpl(void *sulf, SConnection * pCon, float fNew)
|
||||
SCWrite(pCon, pError, eError);
|
||||
SCWrite(pCon, "\n", eError);
|
||||
SCSetInterrupt(pCon, (int) ObVal(self->ParArray, INT));
|
||||
SetMotorError(self,pError);
|
||||
return HWFault;
|
||||
case MOTREDO:
|
||||
iRet = self->pDriver->RunTo(self->pDriver, fHard);
|
||||
@@ -837,6 +841,7 @@ pMotor MotorInit(char *drivername, char *name, MotorDriver * pDriv)
|
||||
pM->pDriver = pDriv;
|
||||
pM->drivername = strdup(drivername);
|
||||
pM->name = strdup(name);
|
||||
pM->error = strdup("None");
|
||||
|
||||
|
||||
/* initialise object descriptor */
|
||||
@@ -1008,6 +1013,7 @@ int MotorCheckPosition(void *sulf, SConnection * pCon)
|
||||
*/
|
||||
|
||||
extern MotorDriver *MakePiPiezo(Tcl_Interp * pTcl, char *pArray);
|
||||
extern MotorDriver *epicsMakeMotorDriver(char *baseName);
|
||||
|
||||
int MotorCreate(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
int argc, char *argv[])
|
||||
@@ -1068,6 +1074,22 @@ int MotorCreate(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
SCWrite(pCon, pBueffel, eLogError);
|
||||
return 0;
|
||||
}
|
||||
} else if (strcmp(argv[2], "epics") == 0) {
|
||||
if(argc > 3){
|
||||
pDriver = epicsMakeMotorDriver(argv[3]);
|
||||
if (!pDriver) {
|
||||
return 0;
|
||||
}
|
||||
pNew = MotorInit("epics", argv[1], pDriver);
|
||||
if (!pNew) {
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "Failure to create motor %s", argv[1]);
|
||||
SCWrite(pCon, pBueffel, eLogError);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
SCWrite(pCon,"ERROR: missing basename argument to create EPICS motor",eError);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
site = getSite();
|
||||
if (site != NULL) {
|
||||
@@ -1082,10 +1104,7 @@ int MotorCreate(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
}
|
||||
|
||||
/* create the interpreter command */
|
||||
if (pNew->pActionRoutine)
|
||||
iRet = AddCommand(pSics, argv[1], pNew->pActionRoutine, MotorKill, pNew);
|
||||
else
|
||||
iRet = AddCommand(pSics, argv[1], MotorAction, MotorKill, pNew);
|
||||
iRet = AddCommand(pSics, argv[1], MotorAction, MotorKill, pNew);
|
||||
if (!iRet) {
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "ERROR: duplicate command %s not created", argv[1]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
@@ -1301,6 +1320,10 @@ int MotorAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
DeleteTokenList(pList);
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
} /* check for error */
|
||||
else if (strcmp(pCurrent->text, "error") == 0) {
|
||||
SCPrintf(pCon,eValue,"%s.error = %s", argv[0], self->error);
|
||||
return 1;
|
||||
} else if (strcmp(pCurrent->text, "interest") == 0) { /* interest */
|
||||
pMoti = (pMotInfo) malloc(sizeof(MotInfo));
|
||||
if (!pMoti) {
|
||||
@@ -1380,6 +1403,13 @@ int MotorAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
SCWrite(pCon, pBueffel, eValue);
|
||||
DeleteTokenList(pList);
|
||||
return 1;
|
||||
} else if(strcmp(pName->text,"status") == 0){
|
||||
if(self->running){
|
||||
SCPrintf(pCon,eValue,"%s.status = run",argv[0]);
|
||||
} else {
|
||||
SCPrintf(pCon,eValue,"%s.status = idle",argv[0]);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
iRet = MotorGetPar(self, pName->text, &fValue);
|
||||
if (!iRet) {
|
||||
|
||||
Reference in New Issue
Block a user