Compare commits

...

5 Commits
0.7.0 ... 0.9.0

Author SHA1 Message Date
a990da4245 Added functions to get/set motorPosition.
Changed to functions motorPosition and setMotorPosition in order to
retrieve / set motor positions from / to the paramLib.
2025-03-31 10:53:39 +02:00
83a74ce8d0 Added new sinqMotor version as minimum requirement 2025-03-19 15:04:16 +01:00
445dd44c19 Removed a doubling of functionality
ipPortUser / lowLevelPortUser are already defined in the sinqMotor
library
2025-03-10 17:02:28 +01:00
d471041c59 Removed friend class declaration and replaced access to private
properties with accessors
2025-03-10 16:55:10 +01:00
967613447b Added error reset function. 2025-03-10 14:31:15 +01:00
6 changed files with 266 additions and 209 deletions

View File

@ -14,7 +14,7 @@ REQUIRED+=sinqMotor
motorBase_VERSION=7.2.2
# Specify the version of sinqMotor we want to build against
sinqMotor_VERSION=0.8.0
sinqMotor_VERSION=0.10.0
# These headers allow to depend on this library for derived drivers.
HEADERS += src/turboPmacAxis.h

View File

@ -1,5 +1,7 @@
# turboPmac
## <span style="color:red">Please read the documentation of sinqMotor first: https://git.psi.ch/sinq-epics-modules/sinqmotor</span>
## Overview
This is a driver for the Turbo PMAC motion controller with the SINQ communication protocol. It is based on the sinqMotor shared library (https://git.psi.ch/sinq-epics-modules/sinqmotor). The header files contain detailed documentation for all public functions. The headers themselves are exported when building the library to allow other drivers to depend on this one.
@ -21,11 +23,11 @@ turboPmac exports the following IOC shell functions:
- `turboPmacController`: Create a new controller object.
- `turboPmacAxis`: Create a new axis object.
The full mcu.cmd file looks like this:
The full turboPmacX.cmd file looks like this:
```
# Define the name of the controller and the corresponding port
epicsEnvSet("NAME","mcu")
epicsEnvSet("NAME","turboPmacX")
epicsEnvSet("ASYN_PORT","p$(NAME)")
# Create the TCP/IP socket used to talk with the controller. The socket can be adressed from within the IOC shell via the port name
@ -47,8 +49,8 @@ turboPmacAxis("$(NAME)",5);
# Set the number of subsequent timeouts
setMaxSubsequentTimeouts("$(NAME)", 20);
# Configure the timeout frequency watchdog:
setThresholdComTimeout("$(NAME)", 100, 1);
# Configure the timeout frequency watchdog: A maximum of 10 timeouts are allowed in 300 seconds before an alarm message is sent.
setThresholdComTimeout("$(NAME)", 300, 10);
# Parametrize the EPICS record database with the substitution file named after the MCU.
epicsEnvSet("SINQDBPATH","$(sinqMotor_DB)/sinqMotor.db")

View File

@ -54,13 +54,13 @@ turboPmacAxis::turboPmacAxis(turboPmacController *pC, int axisNo,
line 40). However, we want the IOC creation to stop completely, since this
is a configuration error.
*/
if (axisNo >= pC->numAxes_) {
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR,
if (axisNo >= pC->numAxes()) {
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d: FATAL ERROR: "
"Axis index %d must be smaller than the total number of axes "
"%d",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
axisNo_, pC->numAxes_);
axisNo_, pC->numAxes());
exit(-1);
}
@ -78,13 +78,14 @@ turboPmacAxis::turboPmacAxis(turboPmacController *pC, int axisNo,
// Initialize all member variables
waitForHandshake_ = false;
timeAtHandshake_ = 0;
axisStatus_ = 0;
// Provide initial values for some parameter library entries
status = pC_->setIntegerParam(axisNo_, pC_->rereadEncoderPosition_, 0);
status = pC_->setIntegerParam(axisNo_, pC_->rereadEncoderPosition(), 0);
if (status != asynSuccess) {
asynPrint(
pC_->pasynUserSelf, ASYN_TRACE_ERROR,
pC_->asynUserSelf(), 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__,
@ -93,10 +94,10 @@ turboPmacAxis::turboPmacAxis(turboPmacController *pC, int axisNo,
}
// turboPmac motors can always be disabled
status = pC_->setIntegerParam(axisNo_, pC_->motorCanDisable_, 1);
status = pC_->setIntegerParam(axisNo_, pC_->motorCanDisable(), 1);
if (status != asynSuccess) {
asynPrint(
pC_->pasynUserSelf, ASYN_TRACE_ERROR,
pC_->asynUserSelf(), 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__,
@ -121,7 +122,7 @@ asynStatus turboPmacAxis::init() {
char command[pC_->MAXBUF_], response[pC_->MAXBUF_];
int nvals = 0;
double motorRecResolution = 0.0;
double motorPosition = 0.0;
double motorPos = 0.0;
double motorVelocity = 0.0;
double motorVmax = 0.0;
double motorAccel = 0.0;
@ -134,11 +135,11 @@ asynStatus turboPmacAxis::init() {
time_t now = time(NULL);
time_t maxInitTime = 60;
while (1) {
status = pC_->getDoubleParam(axisNo_, pC_->motorRecResolution_,
status = pC_->getDoubleParam(axisNo_, pC_->motorRecResolution(),
&motorRecResolution);
if (status == asynParamUndefined) {
if (now + maxInitTime < time(NULL)) {
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR,
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line "
"%d\nInitializing the parameter library failed.\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__,
@ -165,7 +166,7 @@ asynStatus turboPmacAxis::init() {
if (status != asynSuccess) {
return status;
}
nvals = sscanf(response, "%d %lf %lf %lf %lf %d", &axStatus, &motorPosition,
nvals = sscanf(response, "%d %lf %lf %lf %lf %d", &axStatus, &motorPos,
&motorVmax, &motorVelocity, &motorAccel, &acoDelay);
// The acoDelay is given in milliseconds -> Convert to seconds, rounded up
@ -177,17 +178,20 @@ asynStatus turboPmacAxis::init() {
motorAccel = motorAccel * 1000;
if (nvals != 6) {
return pC_->errMsgCouldNotParseResponse(command, response, axisNo_,
__PRETTY_FUNCTION__, __LINE__);
return pC_->couldNotParseResponse(command, response, axisNo_,
__PRETTY_FUNCTION__, __LINE__);
}
// Transform from motor to parameter library coordinates
motorPosition = motorPosition / motorRecResolution;
// Store these values in the parameter library
status = pC_->setDoubleParam(axisNo_, pC_->motorPosition_, motorPosition);
status = setMotorPosition(motorPos);
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorPosition_", axisNo_,
return status;
}
// Initial motor status is idle
status = pC_->setIntegerParam(axisNo_, pC_->motorStatusDone(), 1);
if (status != asynSuccess) {
return pC_->paramLibAccessFailed(status, "motorStatusDone_", axisNo_,
__PRETTY_FUNCTION__, __LINE__);
}
@ -207,7 +211,7 @@ asynStatus turboPmacAxis::init() {
// If we can't communicate with the parameter library, it doesn't make
// sense to try and upstream this to the user -> Just log the error
asynPrint(
pC_->pasynUserSelf, ASYN_TRACE_ERROR,
pC_->asynUserSelf(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d\ncallParamCallbacks "
"failed with %s.\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
@ -245,11 +249,41 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
double lowLimit = 0.0;
double limitsOffset = 0.0;
// Was the axis idle during the previous poll?
int previousStatusDone = 1;
// =========================================================================
// Are we currently waiting for a handshake?
if (waitForHandshake_) {
// Check if the handshake takes too long and communicate an error in
// this case. A handshake should not take more than 5 seconds.
time_t currentTime = time(NULL);
bool timedOut = (currentTime > timeAtHandshake_ + 5);
if (pC_->getMsgPrintControl().shouldBePrinted(
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__, timedOut,
pC_->asynUserSelf())) {
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d\nAsked for a "
"handshake at %ld s and didn't get a positive reply yet "
"(current time is %ld s).\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
timeAtHandshake_, currentTime);
}
if (timedOut) {
pl_status =
setStringParam(pC_->motorMessageText(),
"Timed out while waiting for a handshake");
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMessageText_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
}
snprintf(command, sizeof(command), "P%2.2d23 P%2.2d01", axisNo_,
axisNo_);
rw_status = pC_->writeRead(axisNo_, command, response, 2);
@ -259,8 +293,8 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
nvals = sscanf(response, "%d %d", &handshakePerformed, &error);
if (nvals != 2) {
return pC_->errMsgCouldNotParseResponse(
command, response, axisNo_, __PRETTY_FUNCTION__, __LINE__);
return pC_->couldNotParseResponse(command, response, axisNo_,
__PRETTY_FUNCTION__, __LINE__);
}
if (error != 0) {
@ -277,14 +311,14 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
// poll. This is already part of the movement procedure.
*moving = true;
pl_status = setIntegerParam(pC_->motorStatusMoving_, *moving);
pl_status = setIntegerParam(pC_->motorStatusMoving(), *moving);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status,
"motorStatusMoving_", axisNo_,
__PRETTY_FUNCTION__, __LINE__);
}
pl_status = setIntegerParam(pC_->motorStatusDone_, !(*moving));
pl_status = setIntegerParam(pC_->motorStatusDone(), !(*moving));
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorStatusDone_",
axisNo_, __PRETTY_FUNCTION__,
@ -295,8 +329,7 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
}
}
// Motor resolution from parameter library
pl_status = pC_->getDoubleParam(axisNo_, pC_->motorRecResolution_,
pl_status = pC_->getDoubleParam(axisNo_, pC_->motorRecResolution(),
&motorRecResolution);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorRecResolution_",
@ -305,16 +338,17 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
}
// Read the previous motor position
pl_status =
pC_->getDoubleParam(axisNo_, pC_->motorPosition_, &previousPosition);
pl_status = motorPosition(&previousPosition);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorPosition_", axisNo_,
__PRETTY_FUNCTION__, __LINE__);
return pl_status;
}
// Transform from EPICS to motor coordinates (see comment in
// turboPmacAxis::atFirstPoll)
previousPosition = previousPosition * motorRecResolution;
pl_status = pC_->getIntegerParam(axisNo_, pC_->motorStatusDone(),
&previousStatusDone);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorStatusDone_", axisNo_,
__PRETTY_FUNCTION__, __LINE__);
}
// Query the axis status
snprintf(command, sizeof(command),
@ -328,8 +362,8 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
nvals = sscanf(response, "%d %lf %d %lf %lf", &axStatus, &currentPosition,
&error, &highLimit, &lowLimit);
if (nvals != 5) {
return pC_->errMsgCouldNotParseResponse(command, response, axisNo_,
__PRETTY_FUNCTION__, __LINE__);
return pC_->couldNotParseResponse(command, response, axisNo_,
__PRETTY_FUNCTION__, __LINE__);
}
/*
@ -345,7 +379,7 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
by limitsOffset on both sides.
*/
pl_status =
pC_->getDoubleParam(axisNo_, pC_->motorLimitsOffset_, &limitsOffset);
pC_->getDoubleParam(axisNo_, pC_->motorLimitsOffset(), &limitsOffset);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorLimitsOffset_",
axisNo_, __PRETTY_FUNCTION__,
@ -358,7 +392,7 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
axisStatus_ = axStatus;
// Update the enablement PV
pl_status = setIntegerParam(pC_->motorEnableRBV_,
pl_status = setIntegerParam(pC_->motorEnableRBV(),
(axStatus != -3 && axStatus != -5));
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorEnableRBV_", axisNo_,
@ -375,13 +409,19 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
switch (axStatus) {
case -6:
// Axis is stopping
*moving = true;
// If the axis was already idle during the last poll, it is not moving
if (previousStatusDone == 0) {
*moving = true;
} else {
*moving = false;
}
break;
case -5:
// Axis is deactivated
*moving = false;
pl_status = setStringParam(pC_->motorMessageText_, "Deactivated");
pl_status = setStringParam(pC_->motorMessageText(), "Deactivated");
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMessageText_",
axisNo_, __PRETTY_FUNCTION__,
@ -392,18 +432,18 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
// Emergency stop
*moving = false;
if (pC_->msgPrintControl_.shouldBePrinted(keyStatus, true,
pC_->pasynUserSelf)) {
if (pC_->getMsgPrintControl().shouldBePrinted(keyStatus, true,
pC_->asynUserSelf())) {
asynPrint(
pC_->pasynUserSelf, ASYN_TRACE_ERROR,
pC_->asynUserSelf(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d\nEmergency stop "
"activated.%s\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
pC_->msgPrintControl_.getSuffix());
pC_->getMsgPrintControl().getSuffix());
}
resetCountStatus = false;
pl_status = setStringParam(pC_->motorMessageText_, "Emergency stop");
pl_status = setStringParam(pC_->motorMessageText(), "Emergency stop");
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMessageText_",
axisNo_, __PRETTY_FUNCTION__,
@ -415,7 +455,7 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
// Disabled
*moving = false;
pl_status = setStringParam(pC_->motorMessageText_, "Disabled");
pl_status = setStringParam(pC_->motorMessageText(), "Disabled");
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMessageText_",
axisNo_, __PRETTY_FUNCTION__,
@ -447,7 +487,7 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
*moving = true;
asynPrint(
pC_->pasynUserSelf, ASYN_TRACE_FLOW,
pC_->asynUserSelf(), ASYN_TRACE_FLOW,
"Controller \"%s\", axis %d => %s, line %d\nAxis is moving\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__);
@ -455,14 +495,14 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
default:
*moving = false;
if (pC_->msgPrintControl_.shouldBePrinted(keyStatus, true,
pC_->pasynUserSelf)) {
if (pC_->getMsgPrintControl().shouldBePrinted(keyStatus, true,
pC_->asynUserSelf())) {
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR,
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d\nReached "
"unreachable state P%2.2d00 = %d.%s\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
axisNo_, axStatus, pC_->msgPrintControl_.getSuffix());
axisNo_, axStatus, pC_->getMsgPrintControl().getSuffix());
}
resetCountStatus = false;
@ -470,7 +510,7 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
"Unknown state P%2.2d00 = %d has been reached. Please call "
"the support.",
axisNo_, error);
pl_status = setStringParam(pC_->motorMessageText_, userMessage);
pl_status = setStringParam(pC_->motorMessageText(), userMessage);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMessageText_",
axisNo_, __PRETTY_FUNCTION__,
@ -479,7 +519,7 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
}
if (resetCountStatus) {
pC_->msgPrintControl_.resetCount(keyStatus);
pC_->getMsgPrintControl().resetCount(keyStatus, pC_->asynUserSelf());
}
if (*moving) {
@ -504,17 +544,17 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
case 1:
// EPICS should already prevent this issue in the first place,
// since it contains the user limits
if (pC_->msgPrintControl_.shouldBePrinted(keyError, true,
pC_->pasynUserSelf)) {
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR,
if (pC_->getMsgPrintControl().shouldBePrinted(keyError, true,
pC_->asynUserSelf())) {
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d\nTarget "
"position would exceed user limits.%s\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
pC_->msgPrintControl_.getSuffix());
pC_->getMsgPrintControl().getSuffix());
}
resetError = false;
pl_status = setStringParam(pC_->motorMessageText_,
pl_status = setStringParam(pC_->motorMessageText(),
"Target position would exceed software "
"limits. Please call the support.");
if (pl_status != asynSuccess) {
@ -527,19 +567,19 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
break;
case 5:
// Command not possible
if (pC_->msgPrintControl_.shouldBePrinted(keyStatus, true,
pC_->pasynUserSelf)) {
if (pC_->getMsgPrintControl().shouldBePrinted(keyStatus, true,
pC_->asynUserSelf())) {
asynPrint(
pC_->pasynUserSelf, ASYN_TRACE_ERROR,
pC_->asynUserSelf(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d\nAxis is "
"still moving, but received another move command. EPICS "
"should prevent this, check if *moving is set correctly.%s\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
pC_->msgPrintControl_.getSuffix());
pC_->getMsgPrintControl().getSuffix());
}
resetError = false;
pl_status = setStringParam(pC_->motorMessageText_,
pl_status = setStringParam(pC_->motorMessageText(),
"Axis received move command while it is "
"still moving. Please call the support.");
if (pl_status != asynSuccess) {
@ -551,13 +591,13 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
poll_status = asynError;
break;
case 8:
if (pC_->msgPrintControl_.shouldBePrinted(keyError, true,
pC_->pasynUserSelf)) {
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR,
if (pC_->getMsgPrintControl().shouldBePrinted(keyError, true,
pC_->asynUserSelf())) {
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d\nAir cushion "
"feedback stopped during movement (P%2.2d01 = %d).%s\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
axisNo_, error, pC_->msgPrintControl_.getSuffix());
axisNo_, error, pC_->getMsgPrintControl().getSuffix());
}
resetError = false;
@ -566,7 +606,7 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
"%d). Please call the support.",
axisNo_, error);
pl_status = setStringParam(pC_->motorMessageText_, userMessage);
pl_status = setStringParam(pC_->motorMessageText(), userMessage);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMessageText_",
axisNo_, __PRETTY_FUNCTION__,
@ -574,14 +614,14 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
}
break;
case 9:
if (pC_->msgPrintControl_.shouldBePrinted(keyError, true,
pC_->pasynUserSelf)) {
if (pC_->getMsgPrintControl().shouldBePrinted(keyError, true,
pC_->asynUserSelf())) {
asynPrint(
pC_->pasynUserSelf, ASYN_TRACE_ERROR,
pC_->asynUserSelf(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d\nNo air cushion "
"feedback before movement start (P%2.2d01 = %d).%s\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__, axisNo_,
error, pC_->msgPrintControl_.getSuffix());
error, pC_->getMsgPrintControl().getSuffix());
}
resetError = false;
@ -589,7 +629,7 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
"No air cushion feedback before movement start (P%2.2d01 = "
"%d). Please call the support.",
axisNo_, error);
pl_status = setStringParam(pC_->motorMessageText_, userMessage);
pl_status = setStringParam(pC_->motorMessageText(), userMessage);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMessageText_",
axisNo_, __PRETTY_FUNCTION__,
@ -604,14 +644,14 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
which is not properly homed or if a bug occured.
*/
if (pC_->msgPrintControl_.shouldBePrinted(keyError, true,
pC_->pasynUserSelf)) {
if (pC_->getMsgPrintControl().shouldBePrinted(keyError, true,
pC_->asynUserSelf())) {
asynPrint(
pC_->pasynUserSelf, ASYN_TRACE_ERROR,
pC_->asynUserSelf(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d\nAxis hit the "
"controller limits.%s\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
pC_->msgPrintControl_.getSuffix());
pC_->getMsgPrintControl().getSuffix());
}
resetError = false;
@ -622,7 +662,7 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
"Otherwise please call the support.",
axisNo_, error);
pl_status = setStringParam(pC_->motorMessageText_, userMessage);
pl_status = setStringParam(pC_->motorMessageText(), userMessage);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMessageText_",
axisNo_, __PRETTY_FUNCTION__,
@ -634,14 +674,14 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
case 11:
// Following error
if (pC_->msgPrintControl_.shouldBePrinted(keyError, true,
pC_->pasynUserSelf)) {
if (pC_->getMsgPrintControl().shouldBePrinted(keyError, true,
pC_->asynUserSelf())) {
asynPrint(
pC_->pasynUserSelf, ASYN_TRACE_ERROR,
pC_->asynUserSelf(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d\nMaximum allowed "
"following error exceeded.%s\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
pC_->msgPrintControl_.getSuffix());
pC_->getMsgPrintControl().getSuffix());
}
resetError = false;
@ -650,7 +690,7 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
"Check if movement range is blocked. "
"Otherwise please call the support.",
axisNo_, error);
pl_status = setStringParam(pC_->motorMessageText_, command);
pl_status = setStringParam(pC_->motorMessageText(), command);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMessageText_",
axisNo_, __PRETTY_FUNCTION__,
@ -661,13 +701,13 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
break;
case 12:
if (pC_->msgPrintControl_.shouldBePrinted(keyError, true,
pC_->pasynUserSelf)) {
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR,
if (pC_->getMsgPrintControl().shouldBePrinted(keyError, true,
pC_->asynUserSelf())) {
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d\nSecurity "
"input is triggered (P%2.2d01 = %d).%s\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
axisNo_, error, pC_->msgPrintControl_.getSuffix());
axisNo_, error, pC_->getMsgPrintControl().getSuffix());
}
resetError = false;
@ -676,7 +716,7 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
"for errors (if available). Otherwise please call "
"the support.",
axisNo_, error);
pl_status = setStringParam(pC_->motorMessageText_, command);
pl_status = setStringParam(pC_->motorMessageText(), command);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMessageText_",
axisNo_, __PRETTY_FUNCTION__,
@ -689,13 +729,13 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
case 13:
// Driver hardware error triggered
if (pC_->msgPrintControl_.shouldBePrinted(keyError, true,
pC_->pasynUserSelf)) {
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR,
if (pC_->getMsgPrintControl().shouldBePrinted(keyError, true,
pC_->asynUserSelf())) {
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d\nDriver "
"hardware error triggered.%s\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
pC_->msgPrintControl_.getSuffix());
pC_->getMsgPrintControl().getSuffix());
}
resetError = false;
@ -703,7 +743,7 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
"Driver hardware error (P%2.2d01 = 13). "
"Please call the support.",
axisNo_);
pl_status = setStringParam(pC_->motorMessageText_, command);
pl_status = setStringParam(pC_->motorMessageText(), command);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMessageText_",
axisNo_, __PRETTY_FUNCTION__,
@ -716,13 +756,13 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
// EPICS should already prevent this issue in the first place,
// since it contains the user limits
if (pC_->msgPrintControl_.shouldBePrinted(keyError, true,
pC_->pasynUserSelf)) {
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR,
if (pC_->getMsgPrintControl().shouldBePrinted(keyError, true,
pC_->asynUserSelf())) {
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d\nMove "
"command exceeds hardware limits (P%2.2d01 = %d).%s\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
axisNo_, error, pC_->msgPrintControl_.getSuffix());
axisNo_, error, pC_->getMsgPrintControl().getSuffix());
}
resetError = false;
@ -730,7 +770,7 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
"Move command exceeds hardware limits (P%2.2d01 = %d). Please "
"call the support.",
axisNo_, error);
pl_status = setStringParam(pC_->motorMessageText_, userMessage);
pl_status = setStringParam(pC_->motorMessageText(), userMessage);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMessageText_",
axisNo_, __PRETTY_FUNCTION__,
@ -741,21 +781,21 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
break;
default:
if (pC_->msgPrintControl_.shouldBePrinted(keyError, true,
pC_->pasynUserSelf)) {
if (pC_->getMsgPrintControl().shouldBePrinted(keyError, true,
pC_->asynUserSelf())) {
asynPrint(
pC_->pasynUserSelf, ASYN_TRACE_ERROR,
pC_->asynUserSelf(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d\nUnknown error "
"P%2.2d01 = %d.%s\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__, axisNo_,
error, pC_->msgPrintControl_.getSuffix());
error, pC_->getMsgPrintControl().getSuffix());
}
resetError = false;
snprintf(userMessage, sizeof(userMessage),
"Unknown error P%2.2d01 = %d. Please call the support.",
axisNo_, error);
pl_status = setStringParam(pC_->motorMessageText_, userMessage);
pl_status = setStringParam(pC_->motorMessageText(), userMessage);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMessageText_",
axisNo_, __PRETTY_FUNCTION__,
@ -767,12 +807,12 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
}
if (resetError) {
pC_->msgPrintControl_.resetCount(keyError);
pC_->getMsgPrintControl().resetCount(keyError, pC_->asynUserSelf());
}
// Update the parameter library
if (error != 0) {
pl_status = setIntegerParam(pC_->motorStatusProblem_, true);
pl_status = setIntegerParam(pC_->motorStatusProblem(), true);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorStatusProblem_",
axisNo_, __PRETTY_FUNCTION__,
@ -781,7 +821,7 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
}
if (*moving == false) {
pl_status = setIntegerParam(pC_->motorMoveToHome_, 0);
pl_status = setIntegerParam(pC_->motorMoveToHome(), 0);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMoveToHome_",
axisNo_, __PRETTY_FUNCTION__,
@ -789,28 +829,28 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
}
}
pl_status = setIntegerParam(pC_->motorStatusMoving_, *moving);
pl_status = setIntegerParam(pC_->motorStatusMoving(), *moving);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorStatusMoving_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
pl_status = setIntegerParam(pC_->motorStatusDone_, !(*moving));
pl_status = setIntegerParam(pC_->motorStatusDone(), !(*moving));
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorStatusDone_", axisNo_,
__PRETTY_FUNCTION__, __LINE__);
}
pl_status = setIntegerParam(pC_->motorStatusDirection_, direction);
pl_status = setIntegerParam(pC_->motorStatusDirection(), direction);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorStatusDirection_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
pl_status =
pC_->setDoubleParam(axisNo_, pC_->motorHighLimitFromDriver_, highLimit);
pl_status = pC_->setDoubleParam(axisNo_, pC_->motorHighLimitFromDriver(),
highLimit);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorHighLimitFromDriver_",
axisNo_, __PRETTY_FUNCTION__,
@ -818,22 +858,16 @@ asynStatus turboPmacAxis::doPoll(bool *moving) {
}
pl_status =
pC_->setDoubleParam(axisNo_, pC_->motorLowLimitFromDriver_, lowLimit);
pC_->setDoubleParam(axisNo_, pC_->motorLowLimitFromDriver(), lowLimit);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorLowLimit_", axisNo_,
__PRETTY_FUNCTION__, __LINE__);
}
// Transform from motor to EPICS coordinates (see comment in
// turboPmacAxis::init())
currentPosition = currentPosition / motorRecResolution;
pl_status = setDoubleParam(pC_->motorPosition_, currentPosition);
pl_status = setMotorPosition(currentPosition);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorPosition_", axisNo_,
__PRETTY_FUNCTION__, __LINE__);
return pl_status;
}
return poll_status;
}
@ -857,13 +891,13 @@ asynStatus turboPmacAxis::doMove(double position, int relative,
// =========================================================================
pl_status = pC_->getIntegerParam(axisNo_, pC_->motorEnableRBV_, &enabled);
pl_status = pC_->getIntegerParam(axisNo_, pC_->motorEnableRBV(), &enabled);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "enableMotorRBV_", axisNo_,
__PRETTY_FUNCTION__, __LINE__);
}
pl_status = pC_->getDoubleParam(axisNo_, pC_->motorRecResolution_,
pl_status = pC_->getDoubleParam(axisNo_, pC_->motorRecResolution(),
&motorRecResolution);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorRecResolution_",
@ -873,7 +907,7 @@ asynStatus turboPmacAxis::doMove(double position, int relative,
if (enabled == 0) {
asynPrint(
pC_->pasynUserSelf, ASYN_TRACE_ERROR,
pC_->asynUserSelf(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d\nAxis is disabled.\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__);
return asynSuccess;
@ -883,13 +917,13 @@ asynStatus turboPmacAxis::doMove(double position, int relative,
motorCoordinatesPosition = position * motorRecResolution;
motorVelocity = maxVelocity * motorRecResolution;
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_FLOW,
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_FLOW,
"Controller \"%s\", axis %d => %s, line %d\nStart of axis to "
"position %lf.\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__, position);
// Check if the speed is allowed to be changed
pl_status = pC_->getIntegerParam(axisNo_, pC_->motorCanSetSpeed_,
pl_status = pC_->getIntegerParam(axisNo_, pC_->motorCanSetSpeed(),
&motorCanSetSpeed);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorCanSetSpeed_",
@ -905,7 +939,7 @@ asynStatus turboPmacAxis::doMove(double position, int relative,
motorVelocity);
writeOffset = strlen(command);
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_FLOW,
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_FLOW,
"Controller \"%s\", axis %d => %s, line %d\nSetting speed "
"to %lf.\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
@ -929,12 +963,12 @@ asynStatus turboPmacAxis::doMove(double position, int relative,
if (rw_status != asynSuccess) {
asynPrint(
pC_->pasynUserSelf, ASYN_TRACE_ERROR,
pC_->asynUserSelf(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d\nStarting movement to "
"target position %lf failed.\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
motorCoordinatesPosition);
pl_status = setIntegerParam(pC_->motorStatusProblem_, true);
pl_status = setIntegerParam(pC_->motorStatusProblem(), true);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorStatusProblem_",
axisNo_, __PRETTY_FUNCTION__,
@ -974,12 +1008,45 @@ asynStatus turboPmacAxis::stop(double acceleration) {
if (rw_status != asynSuccess) {
asynPrint(
pC_->pasynUserSelf, ASYN_TRACE_ERROR,
pC_->asynUserSelf(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d\nStopping the movement "
"failed.\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__);
pl_status = setIntegerParam(pC_->motorStatusProblem_, true);
pl_status = setIntegerParam(pC_->motorStatusProblem(), true);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorStatusProblem_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
}
return rw_status;
}
asynStatus turboPmacAxis::doReset() {
// Status of read-write-operations of ASCII commands to the controller
asynStatus rw_status = asynSuccess;
// Status of parameter library operations
asynStatus pl_status = asynSuccess;
char command[pC_->MAXBUF_], response[pC_->MAXBUF_];
// =========================================================================
// Reset the error for this axis manually
snprintf(command, sizeof(command), "P%2.2d01=0", axisNo_);
rw_status = pC_->writeRead(axisNo_, command, response, 0);
if (rw_status != asynSuccess) {
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d\nResetting the "
"error failed\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__);
pl_status = setIntegerParam(pC_->motorStatusProblem(), true);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorStatusProblem_",
axisNo_, __PRETTY_FUNCTION__,
@ -1006,7 +1073,7 @@ asynStatus turboPmacAxis::doHome(double min_velocity, double max_velocity,
// =========================================================================
pl_status = pC_->getStringParam(axisNo_, pC_->encoderType_,
pl_status = pC_->getStringParam(axisNo_, pC_->encoderType(),
sizeof(response), response);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "encoderType_", axisNo_,
@ -1022,14 +1089,14 @@ asynStatus turboPmacAxis::doHome(double min_velocity, double max_velocity,
return rw_status;
}
pl_status = setIntegerParam(pC_->motorMoveToHome_, 1);
pl_status = setIntegerParam(pC_->motorMoveToHome(), 1);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMoveToHome_",
axisNo_, __PRETTY_FUNCTION__,
__LINE__);
}
pl_status = setStringParam(pC_->motorMessageText_, "Homing");
pl_status = setStringParam(pC_->motorMessageText(), "Homing");
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMessageText_",
axisNo_, __PRETTY_FUNCTION__,
@ -1037,7 +1104,7 @@ asynStatus turboPmacAxis::doHome(double min_velocity, double max_velocity,
}
return callParamCallbacks();
} else {
pl_status = setStringParam(pC_->motorMessageText_,
pl_status = setStringParam(pC_->motorMessageText(),
"Can't home a motor with absolute encoder");
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMessageText_",
@ -1075,16 +1142,16 @@ asynStatus turboPmacAxis::readEncoderType() {
int reponse_length = strlen(response);
if (reponse_length < 3) {
return pC_->errMsgCouldNotParseResponse(command, response, axisNo_,
__PRETTY_FUNCTION__, __LINE__);
return pC_->couldNotParseResponse(command, response, axisNo_,
__PRETTY_FUNCTION__, __LINE__);
}
// We are only interested in the last two digits and the last value in
// the string before the terminator is \r
nvals = sscanf(response + (reponse_length - 3), "%2X", &encoder_id);
if (nvals != 1) {
return pC_->errMsgCouldNotParseResponse(command, response, axisNo_,
__PRETTY_FUNCTION__, __LINE__);
return pC_->couldNotParseResponse(command, response, axisNo_,
__PRETTY_FUNCTION__, __LINE__);
}
snprintf(command, sizeof(command), "P46");
@ -1096,9 +1163,9 @@ asynStatus turboPmacAxis::readEncoderType() {
// If true, the encoder is incremental
if (encoder_id <= number_of_axes) {
pl_status = setStringParam(pC_->encoderType_, IncrementalEncoder);
pl_status = setStringParam(pC_->encoderType(), IncrementalEncoder);
} else {
pl_status = setStringParam(pC_->encoderType_, AbsoluteEncoder);
pl_status = setStringParam(pC_->encoderType(), AbsoluteEncoder);
}
if (pl_status != asynSuccess) {
@ -1135,7 +1202,7 @@ asynStatus turboPmacAxis::rereadEncoder() {
if (rw_status != asynSuccess) {
return rw_status;
}
pl_status = pC_->getStringParam(axisNo_, pC_->encoderType_,
pl_status = pC_->getStringParam(axisNo_, pC_->encoderType(),
sizeof(encoderType), encoderType);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "encoderType_", axisNo_,
@ -1144,7 +1211,7 @@ asynStatus turboPmacAxis::rereadEncoder() {
// Abort if the axis is incremental
if (strcmp(encoderType, IncrementalEncoder) == 0) {
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_FLOW,
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_FLOW,
"Controller \"%s\", axis %d => %s, line %d\nEncoder is "
"not reread because it is incremental.\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__);
@ -1154,19 +1221,19 @@ asynStatus turboPmacAxis::rereadEncoder() {
// Check if the axis is disabled. If not, inform the user that this
// is necessary
int enabled = 0;
pl_status = pC_->getIntegerParam(axisNo_, pC_->motorEnableRBV_, &enabled);
pl_status = pC_->getIntegerParam(axisNo_, pC_->motorEnableRBV(), &enabled);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "enableMotorRBV_", axisNo_,
__PRETTY_FUNCTION__, __LINE__);
}
if (enabled == 1) {
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_WARNING,
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_WARNING,
"Controller \"%s\", axis %d => %s, line %d\nAxis must be "
"disabled before rereading the encoder.\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__);
pl_status = setStringParam(
pC_->motorMessageText_,
pC_->motorMessageText(),
"Axis must be disabled before rereading the encoder.");
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMessageText_",
@ -1177,7 +1244,7 @@ asynStatus turboPmacAxis::rereadEncoder() {
} else {
snprintf(command, sizeof(command), "M%2.2d=15", axisNo_);
asynPrint(
pC_->pasynUserSelf, ASYN_TRACE_FLOW,
pC_->asynUserSelf(), ASYN_TRACE_FLOW,
"Controller \"%s\", axis %d => %s, line %d\nRereading absolute "
"encoder via command %s.\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__, command);
@ -1192,7 +1259,7 @@ asynStatus turboPmacAxis::rereadEncoder() {
// turn off parameter as finished rereading
// this will only be immediately noticed in the read back variable
// though
pl_status = pC_->setIntegerParam(pC_->rereadEncoderPosition_, 0);
pl_status = pC_->setIntegerParam(pC_->rereadEncoderPosition(), 0);
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "rereadEncoderPosition_",
axisNo_, __PRETTY_FUNCTION__,
@ -1224,13 +1291,13 @@ asynStatus turboPmacAxis::enable(bool on) {
// actually be disabled in this state!
if (axisStatus_ == 1 || axisStatus_ == 2 || axisStatus_ == 3 ||
axisStatus_ == 4 || axisStatus_ == 5) {
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_ERROR,
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line %d\nAxis is not "
"idle and can therefore not be enabled / disabled.\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__);
pl_status =
setStringParam(pC_->motorMessageText_,
setStringParam(pC_->motorMessageText(),
"Axis cannot be disabled while it is moving.");
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMessageText_",
@ -1245,7 +1312,7 @@ asynStatus turboPmacAxis::enable(bool on) {
// was sent => Do nothing
if ((axisStatus_ != -3) == on) {
asynPrint(
pC_->pasynUserSelf, ASYN_TRACE_WARNING,
pC_->asynUserSelf(), ASYN_TRACE_WARNING,
"Controller \"%s\", axis %d => %s, line %d\nAxis is already %s.\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
on ? "enabled" : "disabled");
@ -1262,14 +1329,14 @@ asynStatus turboPmacAxis::enable(bool on) {
// Enable / disable the axis if it is not moving
snprintf(command, sizeof(command), "M%2.2d14=%d", axisNo_, on);
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_FLOW,
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_FLOW,
"Controller \"%s\", axis %d => %s, line %d\n%s axis\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
on ? "Enable" : "Disable");
if (on == 0) {
pl_status = setStringParam(pC_->motorMessageText_, "Disabling ...");
pl_status = setStringParam(pC_->motorMessageText(), "Disabling ...");
} else {
pl_status = setStringParam(pC_->motorMessageText_, "Enabling ...");
pl_status = setStringParam(pC_->motorMessageText(), "Enabling ...");
}
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMessageText_",
@ -1295,8 +1362,8 @@ asynStatus turboPmacAxis::enable(bool on) {
}
nvals = sscanf(response, "%d", &axisStatus_);
if (nvals != 1) {
return pC_->errMsgCouldNotParseResponse(
command, response, axisNo_, __PRETTY_FUNCTION__, __LINE__);
return pC_->couldNotParseResponse(command, response, axisNo_,
__PRETTY_FUNCTION__, __LINE__);
}
if ((axisStatus_ != -3) == on) {
@ -1309,7 +1376,7 @@ asynStatus turboPmacAxis::enable(bool on) {
// Failed to change axis status within timeout_enable_disable => Send a
// corresponding message
asynPrint(pC_->pasynUserSelf, ASYN_TRACE_FLOW,
asynPrint(pC_->asynUserSelf(), ASYN_TRACE_FLOW,
"Controller \"%s\", axis %d => %s, line %d\nFailed to %s axis "
"within %d seconds\n",
pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__,
@ -1318,7 +1385,7 @@ asynStatus turboPmacAxis::enable(bool on) {
// Output message to user
snprintf(command, sizeof(command), "Failed to %s within %d seconds",
on ? "enable" : "disable", timeout_enable_disable);
pl_status = setStringParam(pC_->motorMessageText_, "Enabling ...");
pl_status = setStringParam(pC_->motorMessageText(), "Enabling ...");
if (pl_status != asynSuccess) {
return pC_->paramLibAccessFailed(pl_status, "motorMessageText_",
axisNo_, __PRETTY_FUNCTION__,
@ -1354,9 +1421,9 @@ asynStatus turboPmacCreateAxis(const char *portName, int axis) {
if (ptr == nullptr) {
/*
We can't use asynPrint here since this macro would require us
to get a lowLevelPortUser_ from a pointer to an asynPortDriver.
to get an asynUser from a pointer to an asynPortDriver.
However, the given pointer is a nullptr and therefore doesn't
have a lowLevelPortUser_! printf is an EPICS alternative which
have an asynUser! printf is an EPICS alternative which
works w/o that, but doesn't offer the comfort provided
by the asynTrace-facility
*/
@ -1421,4 +1488,4 @@ static void turboPmacAxisRegister(void) {
}
epicsExportRegistrar(turboPmacAxisRegister);
} // extern "C"
} // extern "C"

View File

@ -81,6 +81,14 @@ class turboPmacAxis : public sinqAxis {
*/
asynStatus init();
/**
* @brief Implementation of the `doReset` function from sinqAxis.
*
* @param on
* @return asynStatus
*/
asynStatus doReset();
/**
* @brief Enable / disable the axis.
*
@ -112,9 +120,6 @@ class turboPmacAxis : public sinqAxis {
// The axis status is used when enabling / disabling the motor
int axisStatus_;
private:
friend class turboPmacController;
};
#endif

View File

@ -49,27 +49,12 @@ turboPmacController::turboPmacController(const char *portName,
asynStatus status = asynSuccess;
// Initialization of all member variables
lowLevelPortUser_ = nullptr;
comTimeout_ = comTimeout;
// Maximum allowed number of subsequent timeouts before the user is
// informed.
maxSubsequentTimeouts_ = 10;
// =========================================================================;
/*
We try to connect to the port via the port name provided by the constructor.
If this fails, the function is terminated via exit
*/
pasynOctetSyncIO->connect(ipPortConfigName, 0, &lowLevelPortUser_, NULL);
if (status != asynSuccess || lowLevelPortUser_ == nullptr) {
errlogPrintf("Controller \"%s\" => %s, line %d\nFATAL ERROR "
"(cannot connect to MCU controller).\nTerminating IOC",
portName, __PRETTY_FUNCTION__, __LINE__);
exit(-1);
}
// =========================================================================
// Create additional parameter library entries
@ -103,15 +88,15 @@ turboPmacController::turboPmacController(const char *portName,
const char *message_from_device =
"\006"; // Hex-code for ACK (acknowledge) -> Each message from the MCU
// is terminated by this value
status = pasynOctetSyncIO->setInputEos(
lowLevelPortUser_, message_from_device, strlen(message_from_device));
status = pasynOctetSyncIO->setInputEos(ipPortUser_, message_from_device,
strlen(message_from_device));
if (status != asynSuccess) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\" => %s, line %d\nFATAL ERROR "
"(setting input EOS failed with %s).\nTerminating IOC",
portName, __PRETTY_FUNCTION__, __LINE__,
stringifyAsynStatus(status));
pasynOctetSyncIO->disconnect(lowLevelPortUser_);
pasynOctetSyncIO->disconnect(ipPortUser_);
exit(-1);
}
@ -123,7 +108,7 @@ turboPmacController::turboPmacController(const char *portName,
"with %s).\nTerminating IOC",
portName, __PRETTY_FUNCTION__, __LINE__,
stringifyAsynStatus(status));
pasynOctetSyncIO->disconnect(lowLevelPortUser_);
pasynOctetSyncIO->disconnect(ipPortUser_);
exit(-1);
}
}
@ -254,8 +239,8 @@ asynStatus turboPmacController::writeRead(int axisNo, const char *command,
trying to reconnect. If the problem persists, ask them to call the support
*/
status = pasynOctetSyncIO->write(lowLevelPortUser_, fullCommand,
fullComandLength, comTimeout_, &nbytesOut);
status = pasynOctetSyncIO->write(ipPortUser_, fullCommand, fullComandLength,
comTimeout_, &nbytesOut);
msgPrintControlKey writeKey =
msgPrintControlKey(portName, axisNo, __PRETTY_FUNCTION__, __LINE__);
@ -279,7 +264,7 @@ asynStatus turboPmacController::writeRead(int axisNo, const char *command,
checkMaxSubsequentTimeouts(timeoutCounter, axis);
timeoutCounter += 1;
status = pasynOctetSyncIO->write(lowLevelPortUser_, fullCommand,
status = pasynOctetSyncIO->write(ipPortUser_, fullCommand,
fullComandLength, comTimeout_,
&nbytesOut);
if (status != asynTimeout) {
@ -300,12 +285,12 @@ asynStatus turboPmacController::writeRead(int axisNo, const char *command,
stringifyAsynStatus(status), msgPrintControl_.getSuffix());
}
} else {
msgPrintControl_.resetCount(writeKey);
msgPrintControl_.resetCount(writeKey, pasynUserSelf);
}
// Read the response from the MCU buffer
status = pasynOctetSyncIO->read(lowLevelPortUser_, response, MAXBUF_,
comTimeout_, &nbytesIn, &eomReason);
status = pasynOctetSyncIO->read(ipPortUser_, response, MAXBUF_, comTimeout_,
&nbytesIn, &eomReason);
msgPrintControlKey readKey =
msgPrintControlKey(portName, axisNo, __PRETTY_FUNCTION__, __LINE__);
@ -330,9 +315,8 @@ asynStatus turboPmacController::writeRead(int axisNo, const char *command,
checkMaxSubsequentTimeouts(timeoutCounter, axis);
timeoutCounter += 1;
status =
pasynOctetSyncIO->read(lowLevelPortUser_, response, MAXBUF_,
comTimeout_, &nbytesIn, &eomReason);
status = pasynOctetSyncIO->read(ipPortUser_, response, MAXBUF_,
comTimeout_, &nbytesIn, &eomReason);
if (status != asynTimeout) {
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
"Controller \"%s\", axis %d => %s, line "
@ -351,7 +335,7 @@ asynStatus turboPmacController::writeRead(int axisNo, const char *command,
stringifyAsynStatus(status), msgPrintControl_.getSuffix());
}
} else {
msgPrintControl_.resetCount(readKey);
msgPrintControl_.resetCount(readKey, pasynUserSelf);
}
if (timeoutStatus == asynError) {
@ -377,7 +361,7 @@ asynStatus turboPmacController::writeRead(int axisNo, const char *command,
eomReason, msgPrintControl_.getSuffix());
}
} else {
msgPrintControl_.resetCount(terminateKey);
msgPrintControl_.resetCount(terminateKey, pasynUserSelf);
}
/*
@ -412,7 +396,7 @@ asynStatus turboPmacController::writeRead(int axisNo, const char *command,
modResponse, command);
status = asynError;
} else {
msgPrintControl_.resetCount(numResponsesKey);
msgPrintControl_.resetCount(numResponsesKey, pasynUserSelf);
}
// Create custom error messages for different failure modes, if no error
@ -511,12 +495,12 @@ asynStatus turboPmacController::readInt32(asynUser *pasynUser,
}
}
asynStatus turboPmacController::errMsgCouldNotParseResponse(
asynStatus turboPmacController::couldNotParseResponse(
const char *command, const char *response, int axisNo,
const char *functionName, int lineNumber) {
char modifiedResponse[MAXBUF_] = {0};
adjustResponseForPrint(modifiedResponse, response, MAXBUF_);
return sinqController::errMsgCouldNotParseResponse(
return sinqController::couldNotParseResponse(
command, modifiedResponse, axisNo, functionName, lineNumber);
}

View File

@ -73,9 +73,6 @@ class turboPmacController : public sinqController {
*/
virtual asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value);
protected:
asynUser *lowLevelPortUser_;
/**
* @brief Send a command to the hardware and receive a response
*
@ -96,13 +93,13 @@ class turboPmacController : public sinqController {
int numExpectedResponses);
/**
* @brief Specialized version of sinqController::errMsgCouldNotParseResponse
* @brief Specialized version of sinqController::couldNotParseResponse
* for turboPmac
*
* This is an overloaded version of
* sinqController::errMsgCouldNotParseResponse which calls
* sinqController::couldNotParseResponse which calls
* adjustResponseForLogging on response before handing it over to
* sinqController::errMsgCouldNotParseResponse.
* sinqController::couldNotParseResponse.
*
* @param command Command which led to the unparseable message
* @param response Response which wasn't parseable
@ -113,17 +110,21 @@ class turboPmacController : public sinqController {
called. It is recommended to use a macro, e.g. __LINE__.
* @return asynStatus Returns asynError.
*/
asynStatus errMsgCouldNotParseResponse(const char *command,
asynStatus couldNotParseResponse(const char *command,
const char *response, int axisNo_,
const char *functionName,
int lineNumber);
protected:
// Accessors for additional PVs
int rereadEncoderPosition() { return rereadEncoderPosition_; }
int readConfig() { return readConfig_; }
// Set the maximum buffer size. This is an empirical value which must be
// large enough to avoid overflows for all commands to the device /
// responses from it.
static const uint32_t MAXBUF_ = 200;
protected:
/*
Timeout for the communication process in seconds
*/
@ -136,8 +137,6 @@ class turboPmacController : public sinqController {
int rereadEncoderPosition_;
int readConfig_;
#define LAST_turboPmac_PARAM readConfig_
friend class turboPmacAxis;
};
#define NUM_turboPmac_DRIVER_PARAMS \
(&LAST_turboPmac_PARAM - &FIRST_turboPmac_PARAM + 1)