From c7936191d97c2a66b2bf2d3de92bbaefb32fdf9d Mon Sep 17 00:00:00 2001 From: smathis Date: Fri, 25 Apr 2025 13:17:41 +0200 Subject: [PATCH] Added Connected PV --- db/sinqMotor.db | 12 ++++++++++++ src/sinqAxis.cpp | 13 +++++++++++++ src/sinqAxis.h | 2 +- src/sinqController.cpp | 10 ++++++++++ src/sinqController.h | 5 +++++ 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/db/sinqMotor.db b/db/sinqMotor.db index 89c5f12..dc5b7dc 100755 --- a/db/sinqMotor.db +++ b/db/sinqMotor.db @@ -54,6 +54,18 @@ record(calc, "$(INSTR)$(M):StatusProblem") field(CALC, "A >> 9") } +# If the value of this PV is 0, the according axis is currently disconnected from the controller. +# Trying to give commands to a disconnected axis will result in an error message in the IOC shell +# This record is coupled to the parameter library via motorConnected_ -> MOTOR_CONNECTED. +record(longin, "$(INSTR)$(M):Connected") +{ + field(DTYP, "asynInt32") + field(INP, "@asyn($(CONTROLLER),$(AXIS)) MOTOR_CONNECTED") + field(SCAN, "I/O Intr") + field(PINI, "NO") + field(INIT, "1") +} + # Call the reset function of the corresponding sinqAxis # This record is coupled to the parameter library via motorReset_ -> MOTOR_RESET. record(longout, "$(INSTR)$(M):Reset") { diff --git a/src/sinqAxis.cpp b/src/sinqAxis.cpp index b7b2be3..1aeb54f 100644 --- a/src/sinqAxis.cpp +++ b/src/sinqAxis.cpp @@ -67,6 +67,18 @@ sinqAxis::sinqAxis(class sinqController *pC, int axisNo) exit(-1); } + // Assume that the motor is connected initially + status = setIntegerParam(pC_->motorConnected(), 1); + if (status != asynSuccess) { + asynPrint(pC_->pasynUser(), ASYN_TRACE_ERROR, + "Controller \"%s\", axis %d => %s, line %d:\nFATAL ERROR " + "(setting a parameter value failed " + "with %s)\n. Terminating IOC", + pC->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__, + pC_->stringifyAsynStatus(status)); + exit(-1); + } + // We assume that the motor has no status problems initially status = setIntegerParam(pC_->motorStatusProblem(), 0); if (status != asynSuccess) { @@ -113,6 +125,7 @@ sinqAxis::sinqAxis(class sinqController *pC, int axisNo) } asynStatus sinqAxis::poll(bool *moving) { + // Local variable declaration asynStatus pl_status = asynSuccess; asynStatus poll_status = asynSuccess; diff --git a/src/sinqAxis.h b/src/sinqAxis.h index 56f141e..8842a8d 100644 --- a/src/sinqAxis.h +++ b/src/sinqAxis.h @@ -357,7 +357,7 @@ class epicsShareClass sinqAxis : public asynMotorAxis { bool watchdogMovActive_; // Store the motor target position for the movement time calculation double targetPosition_; - + bool wasMoving_; /* diff --git a/src/sinqController.cpp b/src/sinqController.cpp index b0fc7a1..767ed3c 100644 --- a/src/sinqController.cpp +++ b/src/sinqController.cpp @@ -170,6 +170,16 @@ sinqController::sinqController(const char *portName, exit(-1); } + status = createParam("MOTOR_CONNECTED", asynParamInt32, &motorConnected_); + if (status != asynSuccess) { + asynPrint(this->pasynUserSelf, 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); + } + /* We need to introduce 2 new parameters in order to write the limits from the driver to the EPICS record. See the comment in sinqController.h next to diff --git a/src/sinqController.h b/src/sinqController.h index ef88351..9112844 100644 --- a/src/sinqController.h +++ b/src/sinqController.h @@ -285,6 +285,7 @@ class epicsShareClass sinqController : public asynMotorController { int motorCanSetSpeed() { return motorCanSetSpeed_; } int motorLimitsOffset() { return motorLimitsOffset_; } int motorForceStop() { return motorForceStop_; } + int motorConnected() { return motorConnected_; } int motorVeloFromDriver() { return motorVeloFromDriver_; } int motorVbasFromDriver() { return motorVbasFromDriver_; } int motorVmaxFromDriver() { return motorVmaxFromDriver_; } @@ -335,6 +336,9 @@ class epicsShareClass sinqController : public asynMotorController { int maxSubsequentTimeouts_; bool maxSubsequentTimeoutsExceeded_; + /* + See the documentation in db/sinqMotor.db for the following integers + */ #define FIRST_SINQMOTOR_PARAM motorMessageText_ int motorMessageText_; int motorReset_; @@ -345,6 +349,7 @@ class epicsShareClass sinqController : public asynMotorController { int motorCanSetSpeed_; int motorLimitsOffset_; int motorForceStop_; + int motorConnected_; /* These parameters are here to write values from the hardware to the EPICS motor record. Using motorHighLimit_ / motorLowLimit_ does not work: