diff --git a/Makefile b/Makefile index 7dd9222..1602269 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ REQUIRED+=sinqMotor motorBase_VERSION=7.2.2 # Specify the version of sinqMotor we want to build against -sinqMotor_VERSION=mathis_s +sinqMotor_VERSION=0.10.0 # These headers allow to depend on this library for derived drivers. HEADERS += src/masterMacsAxis.h diff --git a/src/masterMacsAxis.cpp b/src/masterMacsAxis.cpp index b1adcf6..7fe800b 100644 --- a/src/masterMacsAxis.cpp +++ b/src/masterMacsAxis.cpp @@ -191,7 +191,7 @@ asynStatus masterMacsAxis::init() { nvals = sscanf(response, "%lf", &motorPosition); if (nvals != 1) { return pC_->couldNotParseResponse("R12", response, axisNo_, - __PRETTY_FUNCTION__, __LINE__); + __PRETTY_FUNCTION__, __LINE__); } // Read out the current velocity @@ -202,7 +202,7 @@ asynStatus masterMacsAxis::init() { nvals = sscanf(response, "%lf", &motorVelocity); if (nvals != 1) { return pC_->couldNotParseResponse("R05", response, axisNo_, - __PRETTY_FUNCTION__, __LINE__); + __PRETTY_FUNCTION__, __LINE__); } // Read out the maximum velocity @@ -213,7 +213,7 @@ asynStatus masterMacsAxis::init() { nvals = sscanf(response, "%lf", &motorVmax); if (nvals != 1) { return pC_->couldNotParseResponse("R26", response, axisNo_, - __PRETTY_FUNCTION__, __LINE__); + __PRETTY_FUNCTION__, __LINE__); } // Read out the acceleration @@ -224,7 +224,7 @@ asynStatus masterMacsAxis::init() { nvals = sscanf(response, "%lf", &motorAccel); if (nvals != 1) { return pC_->couldNotParseResponse("R06", response, axisNo_, - __PRETTY_FUNCTION__, __LINE__); + __PRETTY_FUNCTION__, __LINE__); } // Cache the motor speed. If this value differs from the one in the motor @@ -333,8 +333,8 @@ asynStatus masterMacsAxis::doPoll(bool *moving) { nvals = sscanf(response, "%lf", &handshakePerformed); if (nvals != 1) { - return pC_->couldNotParseResponse( - "R86", response, axisNo_, __PRETTY_FUNCTION__, __LINE__); + return pC_->couldNotParseResponse("R86", response, axisNo_, + __PRETTY_FUNCTION__, __LINE__); } if (handshakePerformed == 1.0) { @@ -401,7 +401,7 @@ asynStatus masterMacsAxis::doPoll(bool *moving) { nvals = sscanf(response, "%lf", ¤tPosition); if (nvals != 1) { return pC_->couldNotParseResponse("R12", response, axisNo_, - __PRETTY_FUNCTION__, __LINE__); + __PRETTY_FUNCTION__, __LINE__); } /* @@ -608,8 +608,8 @@ asynStatus masterMacsAxis::doPoll(bool *moving) { } nvals = sscanf(response, "%lf", &lowLimit); if (nvals != 1) { - return pC_->couldNotParseResponse( - "R34", response, axisNo_, __PRETTY_FUNCTION__, __LINE__); + return pC_->couldNotParseResponse("R34", response, axisNo_, + __PRETTY_FUNCTION__, __LINE__); } rw_status = pC_->read(axisNo_, 33, response); @@ -618,8 +618,8 @@ asynStatus masterMacsAxis::doPoll(bool *moving) { } nvals = sscanf(response, "%lf", &highLimit); if (nvals != 1) { - return pC_->couldNotParseResponse( - "R33", response, axisNo_, __PRETTY_FUNCTION__, __LINE__); + return pC_->couldNotParseResponse("R33", response, axisNo_, + __PRETTY_FUNCTION__, __LINE__); } /* @@ -979,7 +979,7 @@ asynStatus masterMacsAxis::readEncoderType() { nvals = sscanf(response, "%d", &encoder_id); if (nvals != 1) { return pC_->couldNotParseResponse(command, response, axisNo_, - __PRETTY_FUNCTION__, __LINE__); + __PRETTY_FUNCTION__, __LINE__); } /* @@ -1068,7 +1068,11 @@ asynStatus masterMacsAxis::enable(bool on) { axisNo_, __PRETTY_FUNCTION__, __LINE__); } - rw_status = pC_->write(axisNo_, 04, value); + + // The answer to the enable command on MasterMACS might take some time, + // hence we wait for a custom timespan in seconds instead of + // pC_->comTimeout_ + rw_status = pC_->write(axisNo_, 04, value, 1.0); if (rw_status != asynSuccess) { return rw_status; } @@ -1138,8 +1142,8 @@ asynStatus masterMacsAxis::readAxisStatus() { float axisStatus = 0; int nvals = sscanf(response, "%f", &axisStatus); if (nvals != 1) { - return pC_->couldNotParseResponse( - "R10", response, axisNo_, __PRETTY_FUNCTION__, __LINE__); + return pC_->couldNotParseResponse("R10", response, axisNo_, + __PRETTY_FUNCTION__, __LINE__); } axisStatus_ = toBitset(axisStatus); @@ -1159,8 +1163,8 @@ asynStatus masterMacsAxis::readAxisError() { float axisError = 0; int nvals = sscanf(response, "%f", &axisError); if (nvals != 1) { - return pC_->couldNotParseResponse( - "R11", response, axisNo_, __PRETTY_FUNCTION__, __LINE__); + return pC_->couldNotParseResponse("R11", response, axisNo_, + __PRETTY_FUNCTION__, __LINE__); } axisError_ = toBitset(axisError); } diff --git a/src/masterMacsController.cpp b/src/masterMacsController.cpp index 6d18652..b13043a 100644 --- a/src/masterMacsController.cpp +++ b/src/masterMacsController.cpp @@ -113,18 +113,19 @@ masterMacsAxis *masterMacsController::getMasterMacsAxis(int axisNo) { return dynamic_cast(asynAxis); } -asynStatus masterMacsController::read(int axisNo, int tcpCmd, char *response) { +asynStatus masterMacsController::read(int axisNo, int tcpCmd, char *response, + double comTimeout) { return writeRead(axisNo, tcpCmd, NULL, response); } asynStatus masterMacsController::write(int axisNo, int tcpCmd, - const char *payload) { - return writeRead(axisNo, tcpCmd, payload, NULL); + const char *payload, double comTimeout) { + return writeRead(axisNo, tcpCmd, payload, NULL, comTimeout); } asynStatus masterMacsController::writeRead(int axisNo, int tcpCmd, - const char *payload, - char *response) { + const char *payload, char *response, + double comTimeout) { // Definition of local variables. asynStatus status = asynSuccess; @@ -156,6 +157,11 @@ asynStatus masterMacsController::writeRead(int axisNo, int tcpCmd, // ========================================================================= + // Check if a timeout has been given + if (comTimeout < 0.0) { + comTimeout = comTimeout_; + } + masterMacsAxis *axis = getMasterMacsAxis(axisNo); if (axis == nullptr) { // We already did the error logging directly in getAxis @@ -179,8 +185,16 @@ asynStatus masterMacsController::writeRead(int axisNo, int tcpCmd, adjustForPrint(printableCommand, fullCommand, MAXBUF_); // Send out the command - status = pasynOctetSyncIO->write( - ipPortUser_, fullCommand, fullCommandLength, comTimeout_, &nbytesOut); + status = pasynOctetSyncIO->write(ipPortUser_, fullCommand, + fullCommandLength, comTimeout, &nbytesOut); + + if (status != asynSuccess) { + asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, + "Controller \"%s\", axis %d => %s, line %d:\nError " + "%s while writing to the controller\n", + portName, axisNo, __PRETTY_FUNCTION__, __LINE__, + stringifyAsynStatus(status)); + } msgPrintControlKey writeKey = msgPrintControlKey(portName, axisNo, __PRETTY_FUNCTION__, __LINE__); @@ -207,24 +221,28 @@ asynStatus masterMacsController::writeRead(int axisNo, int tcpCmd, https://www.slac.stanford.edu/grp/lcls/controls/global/doc/epics-modules/R3-14-12/asyn/asyn-R4-18-lcls2/asyn/interfaces/asynOctetBase.c) */ status = pasynOctetSyncIO->read(ipPortUser_, fullResponse, MAXBUF_, - comTimeout_, &nbytesIn, &eomReason); + comTimeout, &nbytesIn, &eomReason); pasynOctetSyncIO->flush(ipPortUser_); if (status == asynSuccess) { status = parseResponse(fullCommand, fullResponse, drvMessageText, &valueStart, &valueStop, axisNo, tcpCmd, isRead); + if (status == asynSuccess) { // Received the correct message break; } } else { - asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR, - "Controller \"%s\", axis %d => %s, line %d:\nError " - "%s while reading from the controller\n", - portName, axisNo, __PRETTY_FUNCTION__, __LINE__, - stringifyAsynStatus(status)); - break; + if (status != asynTimeout) { + asynPrint( + this->pasynUserSelf, ASYN_TRACE_ERROR, + "Controller \"%s\", axis %d => %s, line %d:\nError " + "%s while reading from the controller\n", + portName, axisNo, __PRETTY_FUNCTION__, __LINE__, + stringifyAsynStatus(status)); + break; + } } if (i + 1 == maxTrials && status == asynError) { diff --git a/src/masterMacsController.h b/src/masterMacsController.h index d7e78f7..d2cc06a 100644 --- a/src/masterMacsController.h +++ b/src/masterMacsController.h @@ -57,7 +57,8 @@ class masterMacsController : public sinqController { * @param payload Value send to MasterMACS. * @return asynStatus */ - asynStatus write(int axisNo, int tcpCmd, const char *payload); + asynStatus write(int axisNo, int tcpCmd, const char *payload, + double comTimeout = -1.0); /** * @brief Send a command to the hardware and receive a response (R mode) @@ -68,7 +69,8 @@ class masterMacsController : public sinqController { * expected to have the size MAXBUF_. * @return asynStatus */ - asynStatus read(int axisNo, int tcpCmd, char *response); + asynStatus read(int axisNo, int tcpCmd, char *response, + double comTimeout = -1.0); /** * @brief Send a command to the hardware (R or S mode) and receive a @@ -85,7 +87,7 @@ class masterMacsController : public sinqController { * @return asynStatus */ asynStatus writeRead(int axisNo, int tcpCmd, const char *payload, - char *response); + char *response, double comTimeout = -1.0); /** * @brief Parse "fullResponse" received upon sending "fullCommand".