diff --git a/site_ansto/hmcontrol_ansto.c b/site_ansto/hmcontrol_ansto.c new file mode 100644 index 00000000..6684dc1c --- /dev/null +++ b/site_ansto/hmcontrol_ansto.c @@ -0,0 +1,104 @@ +/*------------------------------------------------------------------------ + H M C O N T R O L _ A N S T O + + A module creating a slightly modified HMControl object suitable for the + ANSTO HM. This works exactly the same as the existing HMControl, but + has extra options (e.g. pausing HM's at the end of a count instead of + stopping them). + + copyright: see copyright.h + + Mark Lesha, October 2006 +-------------------------------------------------------------------------*/ + +#include +#include +#include +#include "fortify.h" +#include "hmcontrol.h" +#include "hmcontrol_ansto.h" // extends hmcontrol.h +#include "HistMem.h" +#include "devexec.h" + +/*----------------------------------------------------------------------*/ +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. +{ + int status,i; + pHMcontrol self = NULL; + + self = (pHMcontrol)pData; + assert(self); + + status = self->slaves[0]->CheckCountStatus(self->slaveData[0],pCon); + if(status == HWIdle || status == HWFault) + { + /* + stop counting on slaves when finished or when an error + occurred. + */ + InvokeCallBack(self->pCall,COUNTEND,pCon); + // If required, pause hm objects when count finishes + // instead of stopping them. Use the existing interface + // functions to do this. + if (((pHMcontrol_ANSTO)pData)->Pause_HM_After_Count) + self->pCount->Pause(self,pCon); + else + self->pCount->Halt(self); + } + /* + Warning: this assumes that slaves 1 - MAXSLAVE are histogram memories. + If this assumption does not hold, change this code to check if this + is really a histogram memory. + */ + for(i = 1; i < MAXSLAVE; i++) + { + if(self->slaves[i] != NULL) + { + HistDirty((pHistMem)self->slaveData[i]); + } + } + return status; +} + +/*----------------------------------------------------------------------*/ +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. +// 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); + return HMControlAction(pCon, pSics, pData, argc, argv); +} + +/*----------------------------------------------------------------------*/ +int MakeHMControl_ANSTO(SConnection *pCon, SicsInterp *pSics, + void *pData, int argc, char *argv[]) +{ + /* Start by making a plain vanilla HMControl object, */ + /* which gets installed in the command list. */ + if (!MakeHMControl(pCon, pSics, pData, argc, argv)) + return 0; + /* Find the new object in the command list. */ + CommandList *pCommand; + if (!(pCommand=FindCommand(pSics,argv[1]))) + return 0; + /* Get the original command's data, and add the extended command's data */ + /* to it. The altered size of the object does not make any side effects. */ + HMcontrol_ANSTO *newpData; + if (!(newpData=(HMcontrol_ANSTO *)malloc(sizeof(HMcontrol_ANSTO)))) + return 0; + memcpy(newpData,pCommand->pData,sizeof(HMcontrol)); + memset(((char *)newpData)+sizeof(HMcontrol),0,sizeof(HMcontrol_ANSTO)-sizeof(HMcontrol)); + free(pCommand->pData); + pCommand->pData=(void *)newpData; + /* Customize the command handler and status reporting routine. */ + pCommand->OFunc = HMControlAction_ANSTO; + newpData->hmc.pCount->CheckCountStatus = HMCStatus_ANSTO; + /* All done, return success. */ + return 1; +} diff --git a/site_ansto/hmcontrol_ansto.h b/site_ansto/hmcontrol_ansto.h new file mode 100644 index 00000000..72d50de1 --- /dev/null +++ b/site_ansto/hmcontrol_ansto.h @@ -0,0 +1,28 @@ +/*------------------------------------------------------------------------ + H M C O N T R O L _ A N S T O + + A module creating a slightly modified HMControl object suitable for the + ANSTO HM. This works exactly the same as the existing HMControl, but + has extra options (e.g. pausing HM's at the end of a count instead of + stopping them). + + copyright: see copyright.h + + Mark Lesha, October 2006 +-------------------------------------------------------------------------*/ + +#ifndef HMCONTROL_ANSTO_H_ +#define HMCONTROL_ANSTO_H_ + +typedef struct +{ + /* Data of the original HMControl object */ + HMcontrol hmc; + /* Extra data for HMControl_ANSTO for extra functionality */ + int Pause_HM_After_Count; +} HMcontrol_ANSTO, *pHMcontrol_ANSTO; + +int MakeHMControl_ANSTO(SConnection *pCon, SicsInterp *pSics, + void *pData, int argc, char *argv[]); + +#endif /*HMCONTROL_ANSTO_H_*/