diff --git a/site_ansto/hmcontrol_ansto.c b/site_ansto/hmcontrol_ansto.c index 6684dc1c..b0d6a942 100644 --- a/site_ansto/hmcontrol_ansto.c +++ b/site_ansto/hmcontrol_ansto.c @@ -22,8 +22,9 @@ /*----------------------------------------------------------------------*/ static int HMCStatus_ANSTO(void *pData, SConnection *pCon) -// A very slightly modified version of the original HMCStatus(), -// to support pause-on-count-terminate option for ANSTO HM. +// A slightly modified version of the original HMCStatus(), +// to support pause-on-count-terminate option for ANSTO HM, +// and termination either by counter or by HM. { int status,i; pHMcontrol self = NULL; @@ -31,7 +32,9 @@ static int HMCStatus_ANSTO(void *pData, SConnection *pCon) self = (pHMcontrol)pData; assert(self); - status = self->slaves[0]->CheckCountStatus(self->slaveData[0],pCon); + // Termination happens when the selected device (counter or HM) terminates. + status = self->slaves[((pHMcontrol_ANSTO)pData)->Termination_Object] + ->CheckCountStatus(self->slaveData[((pHMcontrol_ANSTO)pData)->Termination_Object],pCon); if(status == HWIdle || status == HWFault) { /* @@ -39,10 +42,10 @@ static int HMCStatus_ANSTO(void *pData, SConnection *pCon) occurred. */ InvokeCallBack(self->pCall,COUNTEND,pCon); - // If required, pause hm objects when count finishes + // If required, pause all objects when hm/count terminates // instead of stopping them. Use the existing interface // functions to do this. - if (((pHMcontrol_ANSTO)pData)->Pause_HM_After_Count) + if (((pHMcontrol_ANSTO)pData)->Pause_HM_After_Count==1) self->pCount->Pause(self,pCon); else self->pCount->Halt(self); @@ -65,13 +68,40 @@ static int HMCStatus_ANSTO(void *pData, SConnection *pCon) /*----------------------------------------------------------------------*/ int HMControlAction_ANSTO(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]) -// This function extends HMControlAction by looking for an optional -// fifth command argument, which is stored to the expanded command data. +// This function extends HMControlAction by looking for an optional fifth +// and sixth command argument, which are stored to the expanded command data. // Thereafter the rest of the arguments are simply passed to the standard // HMControlAction function. { - ((pHMcontrol_ANSTO)pData)->Pause_HM_After_Count - =(argc>=5&&strcmp(argv[4],"pause")==0); + ((pHMcontrol_ANSTO)pData)->Pause_HM_After_Count=0; + ((pHMcontrol_ANSTO)pData)->Termination_Object=0; + if (argc>=5) + { + if (strcmp(argv[4],"pause")==0) + ((pHMcontrol_ANSTO)pData)->Pause_HM_After_Count=1; + else if (strcmp(argv[4],"stop")!=0) // default + { + SCWrite(pCon,"ERROR: Optional argument 5 must be 'stop' or 'pause'",eError); + return 0; + } + } + if (argc>=6) + { + if (sscanf(argv[5],"%d",&(((pHMcontrol_ANSTO)pData)->Termination_Object))!=1 + || ((pHMcontrol_ANSTO)pData)->Termination_Object>=((pHMcontrol_ANSTO)pData)->hmc.nSlaves) + { + char errstr[256]; + sprintf(errstr,"ERROR: Optional argument 6 must be integer 0 to %d, specifies termination object.", + ((pHMcontrol_ANSTO)pData)->hmc.nSlaves - 1); + SCWrite(pCon,errstr,eError); + return 0; + } + } + if (argc>=7) // too many args + { + SCWrite(pCon,"ERROR: Usage %s start preset mode",eError); + return 0; + } return HMControlAction(pCon, pSics, pData, argc, argv); } diff --git a/site_ansto/hmcontrol_ansto.h b/site_ansto/hmcontrol_ansto.h index 72d50de1..8828c454 100644 --- a/site_ansto/hmcontrol_ansto.h +++ b/site_ansto/hmcontrol_ansto.h @@ -20,6 +20,7 @@ typedef struct HMcontrol hmc; /* Extra data for HMControl_ANSTO for extra functionality */ int Pause_HM_After_Count; + int Termination_Object; } HMcontrol_ANSTO, *pHMcontrol_ANSTO; int MakeHMControl_ANSTO(SConnection *pCon, SicsInterp *pSics,