diff --git a/db/turboPmac.db b/db/turboPmac.db index 49c2ff9..d2f51a1 100644 --- a/db/turboPmac.db +++ b/db/turboPmac.db @@ -31,3 +31,14 @@ record(longout, "$(INSTR)FlushHardware") { field(PINI, "NO") field(VAL, "1") } + +# If this PV is set to 1 (default), the position limits are read out from the +# controller. Otherwise, the limits given in the substitution file (DHLM and +# DLLM) are used. +# This record is coupled to the parameter library via limFromHardware -> LIM_FROM_HARDWARE. +record(longout, "$(INSTR)$(M):LimFromHardware") { + field(DTYP, "asynInt32") + field(OUT, "@asyn($(CONTROLLER),$(AXIS),1) LIM_FROM_HARDWARE") + field(PINI, "YES") + field(VAL, "$(LIMFROMHARDWARE=1)") +} \ No newline at end of file diff --git a/src/turboPmacAxis.cpp b/src/turboPmacAxis.cpp index 586090d..155b9dd 100644 --- a/src/turboPmacAxis.cpp +++ b/src/turboPmacAxis.cpp @@ -609,19 +609,30 @@ asynStatus turboPmacAxis::doPoll(bool *moving) { __LINE__); } - pl_status = pC_->setDoubleParam(axisNo_, pC_->motorHighLimitFromDriver(), - highLimit); + int limFromHardware = 0; + pl_status = + pC_->getIntegerParam(axisNo_, pC_->limFromHardware(), &limFromHardware); if (pl_status != asynSuccess) { - return pC_->paramLibAccessFailed(pl_status, "motorHighLimitFromDriver_", - axisNo_, __PRETTY_FUNCTION__, - __LINE__); + return pC_->paramLibAccessFailed(pl_status, "limFromHardware", axisNo_, + __PRETTY_FUNCTION__, __LINE__); } - pl_status = - pC_->setDoubleParam(axisNo_, pC_->motorLowLimitFromDriver(), lowLimit); - if (pl_status != asynSuccess) { - return pC_->paramLibAccessFailed(pl_status, "motorLowLimit_", axisNo_, - __PRETTY_FUNCTION__, __LINE__); + if (limFromHardware != 0) { + pl_status = pC_->setDoubleParam( + axisNo_, pC_->motorHighLimitFromDriver(), highLimit); + if (pl_status != asynSuccess) { + return pC_->paramLibAccessFailed( + pl_status, "motorHighLimitFromDriver_", axisNo_, + __PRETTY_FUNCTION__, __LINE__); + } + + pl_status = pC_->setDoubleParam(axisNo_, pC_->motorLowLimitFromDriver(), + lowLimit); + if (pl_status != asynSuccess) { + return pC_->paramLibAccessFailed(pl_status, "motorLowLimit_", + axisNo_, __PRETTY_FUNCTION__, + __LINE__); + } } pl_status = setMotorPosition(currentPosition); diff --git a/src/turboPmacController.cpp b/src/turboPmacController.cpp index 81f0b5a..bd0682f 100644 --- a/src/turboPmacController.cpp +++ b/src/turboPmacController.cpp @@ -45,6 +45,7 @@ struct turboPmacControllerImpl { int rereadEncoderPosition; int readConfig; int flushHardware; + int limFromHardware; }; #define NUM_turboPmac_DRIVER_PARAMS 3 @@ -114,6 +115,17 @@ turboPmacController::turboPmacController(const char *portName, exit(-1); } + status = createParam("LIM_FROM_HARDWARE", asynParamInt32, + &pTurboPmacC_->limFromHardware); + if (status != asynSuccess) { + asynPrint(this->pasynUser(), ASYN_TRACE_ERROR, + "Controller \"%s\" => %s, line %d\nFATAL ERROR (creating a " + "parameter failed with %s).\nTerminating IOC", + portName, __PRETTY_FUNCTION__, __LINE__, + stringifyAsynStatus(status)); + exit(-1); + } + /* Define the end-of-string of a message coming from the device to EPICS. It is not necessary to append a terminator to outgoing messages, since @@ -506,6 +518,9 @@ int turboPmacController::rereadEncoderPosition() { } int turboPmacController::readConfig() { return pTurboPmacC_->readConfig; } int turboPmacController::flushHardware() { return pTurboPmacC_->flushHardware; } +int turboPmacController::limFromHardware() { + return pTurboPmacC_->limFromHardware; +} asynUser *turboPmacController::pasynInt32SyncIOipPort() { return pTurboPmacC_->pasynInt32SyncIOipPort; diff --git a/src/turboPmacController.h b/src/turboPmacController.h index 9d43e5d..7a1a929 100644 --- a/src/turboPmacController.h +++ b/src/turboPmacController.h @@ -122,6 +122,7 @@ class turboPmacController : public sinqController { int rereadEncoderPosition(); int readConfig(); int flushHardware(); + int limFromHardware(); asynUser *pasynInt32SyncIOipPort();