diff --git a/motorApp/AMCISrc/ANF2Driver.cpp b/motorApp/AMCISrc/ANF2Driver.cpp index 8b071fe2..817fc9f1 100644 --- a/motorApp/AMCISrc/ANF2Driver.cpp +++ b/motorApp/AMCISrc/ANF2Driver.cpp @@ -32,13 +32,12 @@ static const char *driverName = "ANF2MotorDriver"; * \param[in] portName The name of the asyn port that will be created for this driver * \param[in] ANF2InPortName The name of the drvAsynSerialPort that was created previously to connect to the ANF2 controller * \param[in] ANF2OutPortName The name of the drvAsynSerialPort that was created previously to connect to the ANF2 controller - * \param[in] numAxes The number of axes that this controller supports - * \param[in] movingPollPeriod The time between polls when any axis is moving - * \param[in] idlePollPeriod The time between polls when no axis is moving + * \param[in] numModules The number of modules on the controller stack + * \param[in] axesPerModule The number of axes per module (ANF1=1, ANF2=2) */ -ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, const char *ANF2OutPortName, int numAxes, - double movingPollPeriod, double idlePollPeriod) - : asynMotorController(portName, numAxes, NUM_ANF2_PARAMS, +ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, const char *ANF2OutPortName, + int numModules, int axesPerModule) + : asynMotorController(portName, (numModules*axesPerModule), NUM_ANF2_PARAMS, asynInt32ArrayMask, // One additional interface beyond those in base class asynInt32ArrayMask, // One additional callback interface beyond those in base class ASYN_CANBLOCK | ASYN_MULTIDEVICE, @@ -52,20 +51,17 @@ ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, // Keep track of the number of axes created, so the poller can wait for all the axes to be created before starting axesCreated_ = 0; - movingPollPeriod_ = movingPollPeriod; - idlePollPeriod_ = idlePollPeriod; - inputDriver_ = epicsStrDup(ANF2InPortName); // Set this before calls to create Axis objects // Create controller-specific parameters createParam(ANF2GetInfoString, asynParamInt32, &ANF2GetInfo_); createParam(ANF2ReconfigString, asynParamInt32, &ANF2Reconfig_); - if (numAxes > MAX_AXES) { - numAxes = MAX_AXES; - } + numModules_ = numModules; + axesPerModule_ = axesPerModule; + numAxes_ = numModules * axesPerModule; - for (j=0; jconnect(ANF2InPortName, i+j*AXIS_REG_OFFSET, &pasynUserInReg_[j][i], NULL); @@ -93,23 +89,35 @@ ANF2Controller::ANF2Controller(const char *portName, const char *ANF2InPortName, * \param[in] portName The name of the asyn port that will be created for this driver * \param[in] ANF2InPortName The name of the drvAsynIPPPort that was created previously to connect to the ANF2 controller * \param[in] ANF2OutPortName The name of the drvAsynIPPPort that was created previously to connect to the ANF2 controller - * \param[in] numAxes The number of axes that this controller supports - * \param[in] movingPollPeriod The time in ms between polls when any axis is moving - * \param[in] idlePollPeriod The time in ms between polls when no axis is moving + * \param[in] numModules The number of modules on the controller stack + * \param[in] axesPerModule The number of axes per module (ANF1=1, ANF2=2) */ -extern "C" int ANF2CreateController(const char *portName, const char *ANF2InPortName, const char *ANF2OutPortName, int numAxes, - int movingPollPeriod, int idlePollPeriod) +extern "C" int ANF2CreateController(const char *portName, const char *ANF2InPortName, const char *ANF2OutPortName, + int numModules, int axesPerModule) { + // Enforce max values + if (numModules > MAX_MODULES) { + numModules = MAX_MODULES; + } + if (axesPerModule > MAX_AXES_PER_MODULE) { + axesPerModule = MAX_AXES_PER_MODULE; + } + /* ANF2Controller *pANF2Controller - = new ANF2Controller(portName, ANF2InPortName, ANF2OutPortName, numAxes, movingPollPeriod/1000., idlePollPeriod/1000.); + = new ANF2Controller(portName, ANF2InPortName, ANF2OutPortName, numModules, axesPerModule); pANF2Controller = NULL; */ - new ANF2Controller(portName, ANF2InPortName, ANF2OutPortName, numAxes, movingPollPeriod/1000., idlePollPeriod/1000.); + new ANF2Controller(portName, ANF2InPortName, ANF2OutPortName, numModules, axesPerModule); return(asynSuccess); } -extern "C" asynStatus ANF2StartPoller(const char *ANF2Name) /* specify which controller by port name */ +/** Starts the poller for a given controller + * \param[in] ANF2Name The name of the asyn port that for the controller + * \param[in] movingPollPeriod The time in ms between polls when any axis is moving + * \param[in] idlePollPeriod The time in ms between polls when no axis is moving + */ +extern "C" asynStatus ANF2StartPoller(const char *ANF2Name, int movingPollPeriod, int idlePollPeriod) { ANF2Controller *pC; static const char *functionName = "ANF2StartPoller"; @@ -122,13 +130,17 @@ extern "C" asynStatus ANF2StartPoller(const char *ANF2Name) /* specify which co } pC->lock(); - pC->doStartPoller(); + pC->doStartPoller(movingPollPeriod/1000.0, idlePollPeriod/1000.0); pC->unlock(); return asynSuccess; } -void ANF2Controller::doStartPoller() +void ANF2Controller::doStartPoller(double movingPollPeriod, double idlePollPeriod) { + // + movingPollPeriod_ = movingPollPeriod; + idlePollPeriod_ = idlePollPeriod; + // startPoller(movingPollPeriod_, idlePollPeriod_, 2); } @@ -149,7 +161,7 @@ void ANF2Controller::report(FILE *fp, int level) this->portName, numAxes_, movingPollPeriod_, idlePollPeriod_); fprintf(fp, " axesCreated=%i\n", axesCreated_); - for (j=0; j #include -#define MAX_AXES 2 +#define MAX_MODULES 6 +#define MAX_AXES_PER_MODULE 2 #define MAX_INPUT_REGS 10 #define MAX_OUTPUT_REGS 10 @@ -94,15 +95,15 @@ friend class ANF2Controller; class ANF2Controller : public asynMotorController { public: - ANF2Controller(const char *portName, const char *ANF2InPortName, const char *ANF2OutPortName, int numAxes, double movingPollPeriod, double idlePollPeriod); - void doStartPoller(); + ANF2Controller(const char *portName, const char *ANF2InPortName, const char *ANF2OutPortName, int numModules, int axesPerModule); + void doStartPoller(double movingPollPeriod, double idlePollPeriod); void report(FILE *fp, int level); ANF2Axis* getAxis(asynUser *pasynUser); ANF2Axis* getAxis(int axisNo); - asynUser *pasynUserInReg_[MAX_AXES][MAX_INPUT_REGS]; - asynUser *pasynUserOutReg_[MAX_AXES][MAX_OUTPUT_REGS]; - //asynUser *pasynUserOutArrayReg_[MAX_AXES][MAX_OUTPUT_REGS]; + asynUser *pasynUserInReg_[MAX_MODULES*MAX_AXES_PER_MODULE][MAX_INPUT_REGS]; + asynUser *pasynUserOutReg_[MAX_MODULES*MAX_AXES_PER_MODULE][MAX_OUTPUT_REGS]; + //asynUser *pasynUserOutArrayReg_[MAX_MODULES*MAX_AXES_PER_MODULE][MAX_OUTPUT_REGS]; /* These are the methods that we override from asynMotorDriver */ asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value); @@ -123,6 +124,9 @@ private: asynStatus readReg16(int, int, epicsInt32*, double); asynStatus readReg32(int, int, epicsInt32*, double); char *inputDriver_; + int numAxes_; + int numModules_; + int axesPerModule_; double movingPollPeriod_; double idlePollPeriod_; int axesCreated_;