diff --git a/sinqMotor b/sinqMotor index 6f639d7..2578081 160000 --- a/sinqMotor +++ b/sinqMotor @@ -1 +1 @@ -Subproject commit 6f639d7233823ad1dcdf00cf98cf76f9cd14aea0 +Subproject commit 2578081814943129175fbb6ec329ec7531f59b8b diff --git a/src/masterMacsAxis.cpp b/src/masterMacsAxis.cpp index d54dcfb..f23115a 100644 --- a/src/masterMacsAxis.cpp +++ b/src/masterMacsAxis.cpp @@ -190,8 +190,9 @@ asynStatus masterMacsAxis::init() { double motVelocity = 0.0; double motVmax = 0.0; double motAccel = 0.0; - double motMode = 0; - double motCanSetMode = 0; + int motMode = 0; + int dynamicLimits = 0; + int motCanSetMode = 0; // ========================================================================= @@ -298,11 +299,12 @@ asynStatus masterMacsAxis::init() { if (status != asynSuccess) { return status; } - nvals = sscanf(response, "%d", &pMasterMacsA_->dynamicLimits); + nvals = sscanf(response, "%d", &dynamicLimits); if (nvals != 1) { return pC_->couldNotParseResponse("R32", response, axisNo_, __PRETTY_FUNCTION__, __LINE__); } + pMasterMacsA_->dynamicLimits = bool(dynamicLimits); // Check the current motor mode status = pC_->read(axisNo_, 07, response); @@ -1176,6 +1178,43 @@ asynStatus masterMacsAxis::enable(bool on) { return asynError; } +asynStatus masterMacsAxis::setMode(int mode) { + // masterMacs can be disabled + if (pasynUser->reason == motorSetMode()) { + + // First call to the sinqController function. It checks whether it is + // possible to set the mode and whether the given value is valid. + asynStatus status = sinqController::writeInt32(pasynUser, value); + if (status == asynSuccess) { + + // Now write to the hardware + char command[MAXBUF_]; + int axisNo; + getAddress(pasynUser, &axisNo); + + // Map the EPICS value to MasterMACS values (see + // MasterMACS_manual.pdf). + int adjustedValue = 0; + if (value == 0) { + adjustedValue = 1; + } else if (value == 1) { + adjustedValue = 3; + } else { + // This branch is unreachable, as it is is already checked + // within sinqController::writeInt32 that value is either 0 + // or 1. + return asynError; + } + + snprintf(command, sizeof(value), "%d", adjustedValue); + return write(axisNo, 07, command); + } + return status; + } else { + return sinqController::writeInt32(pasynUser, value); + } +} + bool masterMacsAxis::needInit() { return pMasterMacsA_->needInit; } /** diff --git a/src/masterMacsAxis.h b/src/masterMacsAxis.h index 695a8f3..5759479 100644 --- a/src/masterMacsAxis.h +++ b/src/masterMacsAxis.h @@ -130,6 +130,15 @@ class HIDDEN masterMacsAxis : public sinqAxis { */ asynStatus enable(bool on); + /** + * @brief Write the new operation mode (position or velocity) to the + * MasterMACS controller. + * + * @param mode + * @return asynStatus + */ + asynStatus masterMacsAxis::setMode(int mode); + /** * @brief Read the encoder type (incremental or absolute) for this axis * from the MCU and store the information in the PV ENCODER_TYPE. diff --git a/src/masterMacsController.cpp b/src/masterMacsController.cpp index d9cc639..dc24442 100644 --- a/src/masterMacsController.cpp +++ b/src/masterMacsController.cpp @@ -574,44 +574,6 @@ asynStatus masterMacsController::readInt32(asynUser *pasynUser, } } -asynStatus masterMacsController::writeInt32(asynUser *pasynUser, - epicsInt32 value) { - // masterMacs can be disabled - if (pasynUser->reason == motorSetMode()) { - - // First call to the sinqController function. It checks whether it is - // possible to set the mode and whether the given value is valid. - asynStatus status = sinqController::writeInt32(pasynUser, value); - if (status == asynSuccess) { - - // Now write to the hardware - char command[MAXBUF_]; - int axisNo; - getAddress(pasynUser, &axisNo); - - // Map the EPICS value to MasterMACS values (see - // MasterMACS_manual.pdf). - int adjustedValue = 0; - if (value == 0) { - adjustedValue = 1; - } else if (value == 1) { - adjustedValue = 3; - } else { - // This branch is unreachable, as it is is already checked - // within sinqController::writeInt32 that value is either 0 - // or 1. - return asynError; - } - - snprintf(command, sizeof(value), "%d", adjustedValue); - return write(axisNo, 07, command); - } - return status; - } else { - return sinqController::writeInt32(pasynUser, value); - } -} - double masterMacsController::comTimeout() { return pMasterMacsC_->comTimeout; } int masterMacsController::nodeReset() { return pMasterMacsC_->nodeReset; } diff --git a/src/masterMacsController.h b/src/masterMacsController.h index 271e668..ca09e64 100644 --- a/src/masterMacsController.h +++ b/src/masterMacsController.h @@ -54,15 +54,6 @@ class HIDDEN masterMacsController : public sinqController { */ asynStatus readInt32(asynUser *pasynUser, epicsInt32 *value); - /** - * @brief Overloaded version of the sinqController version - * - * @param pasynUser - * @param value - * @return asynStatus - */ - asynStatus writeInt32(asynUser *pasynUser, epicsInt32 *value); - /** * @brief Get the axis object * @@ -84,7 +75,8 @@ class HIDDEN masterMacsController : public sinqController { /** * @brief Overloaded function of sinqController * - * The function is overloaded to allow resetting the node + * The function is overloaded to allow resetting the node and changing the + * operation mode. * * @param pasynUser Specify the axis via the asynUser * @param value New value