Improved error reporting to the MsgTxt additional field

This commit is contained in:
2017-08-08 17:32:32 +02:00
parent 0eed0c9357
commit 9a3b0f7666
3 changed files with 47 additions and 32 deletions

View File

@ -5,6 +5,10 @@ USAGE... Motor driver support for the PSI EL734 controller.
Mark Koennecke Mark Koennecke
February 2013 February 2013
Updated to have an MsgTxt field through SINQAxis, error handling
Mark Koennecke, May, August 2017
*/ */
@ -134,18 +138,22 @@ void EL734Controller::switchRemote()
* \param[out] reply The controllers reply * \param[out] reply The controllers reply
*/ */
asynStatus EL734Controller::transactController(char command[COMLEN], char reply[COMLEN]) asynStatus EL734Controller::transactController(int axisNo,char command[COMLEN], char reply[COMLEN])
{ {
asynStatus status; asynStatus status;
size_t in, out, i; size_t in, out, i;
int reason; int reason;
char myReply[COMLEN]; char myReply[COMLEN], errTxt[256];
SINQAxis *axis = getAxis(axisNo);
pasynOctetSyncIO->flush(pasynUserController_); pasynOctetSyncIO->flush(pasynUserController_);
status = pasynOctetSyncIO->writeRead(pasynUserController_, command, strlen(command), status = pasynOctetSyncIO->writeRead(pasynUserController_, command, strlen(command),
reply,COMLEN, 1.,&out,&in,&reason); reply,COMLEN, 1.,&out,&in,&reason);
if(status != asynSuccess){ if(status != asynSuccess){
if(axis!= NULL){
axis->updateMsgTxtFromDriver("Lost connection to motor controller");
}
return status; return status;
} }
@ -174,13 +182,25 @@ asynStatus EL734Controller::transactController(char command[COMLEN], char reply[
myReply[i] = (char)tolower((int)reply[i]); myReply[i] = (char)tolower((int)reply[i]);
} }
if(strstr(myReply,"?cmd") != NULL){ if(strstr(myReply,"?cmd") != NULL){
errlogSevPrintf(errlogMajor, "Bad command %s", command); snprintf(errTxt,sizeof(errTxt), "Bad command %s at axis %d", command, axisNo);
errlogSevPrintf(errlogMajor, errTxt);
if(axis!= NULL){
axis->updateMsgTxtFromDriver(errTxt);
}
return asynError; return asynError;
} else if(strstr(myReply,"?par") != NULL){ } else if(strstr(myReply,"?par") != NULL){
errlogSevPrintf(errlogMajor, "Bad parameter in command %s", command); snprintf(errTxt,sizeof(errTxt), "Bad parameter in command %s", command);
errlogSevPrintf(errlogMajor, errTxt);
if(axis!= NULL){
axis->updateMsgTxtFromDriver(errTxt);
}
return asynError; return asynError;
} else if(strstr(myReply,"?rng") != NULL){ } else if(strstr(myReply,"?rng") != NULL){
errlogSevPrintf(errlogMajor, "Parameter out of range in command %s", command); snprintf(errTxt,sizeof(errTxt), "Parameter out of range in command %s", command);
errlogSevPrintf(errlogMajor, errTxt);
if(axis!= NULL){
axis->updateMsgTxtFromDriver(errTxt);
}
return asynError; return asynError;
} }
@ -234,10 +254,7 @@ asynStatus EL734Axis::move(double position, int relative, double minVelocity, do
oredMSR = 0; oredMSR = 0;
homing = 0; homing = 0;
sprintf(command, "p %d %.3f", axisNo_, position/1000.); sprintf(command, "p %d %.3f", axisNo_, position/1000.);
status = pC_->transactController(command,reply); status = pC_->transactController(axisNo_,command,reply);
if(status == asynError){
updateMsgTxtFromDriver(reply);
}
next_poll = -1; next_poll = -1;
return status; return status;
} }
@ -253,11 +270,8 @@ asynStatus EL734Axis::home(double minVelocity, double maxVelocity, double accele
sprintf(command, "R %d", axisNo_); sprintf(command, "R %d", axisNo_);
homing = 1; homing = 1;
next_poll= -1; next_poll= -1;
status = pC_->transactController(command,reply); status = pC_->transactController(axisNo_,command,reply);
if(status == asynError){ return status;
updateMsgTxtFromDriver(reply);
}
return status;
} }
asynStatus EL734Axis::moveVelocity(double minVelocity, double maxVelocity, double acceleration) asynStatus EL734Axis::moveVelocity(double minVelocity, double maxVelocity, double acceleration)
@ -278,10 +292,7 @@ asynStatus EL734Axis::moveVelocity(double minVelocity, double maxVelocity, doubl
/* This is a negative move */ /* This is a negative move */
sprintf(command, "FB %d", axisNo_); sprintf(command, "FB %d", axisNo_);
} }
status = pC_->transactController(command,reply); status = pC_->transactController(axisNo_,command,reply);
if(status == asynError){
updateMsgTxtFromDriver(reply);
}
next_poll = -1; next_poll = -1;
return status; return status;
} }
@ -293,7 +304,7 @@ asynStatus EL734Axis::stop(double acceleration )
char command[COMLEN], reply[COMLEN]; char command[COMLEN], reply[COMLEN];
sprintf(command, "S %d", axisNo_); sprintf(command, "S %d", axisNo_);
status = pC_->transactController(command,reply); status = pC_->transactController(axisNo_,command,reply);
errlogPrintf("Sent STOP on Axis %d\n", axisNo_); errlogPrintf("Sent STOP on Axis %d\n", axisNo_);
updateMsgTxtFromDriver("Axis interrupted"); updateMsgTxtFromDriver("Axis interrupted");
@ -307,10 +318,7 @@ asynStatus EL734Axis::setPosition(double position)
char command[COMLEN], reply[COMLEN]; char command[COMLEN], reply[COMLEN];
sprintf(command, "P %d %f", axisNo_, position/1000.); sprintf(command, "P %d %f", axisNo_, position/1000.);
status = pC_->transactController(command,reply); status = pC_->transactController(axisNo_,command,reply);
if(status == asynError){
updateMsgTxtFromDriver(reply);
}
next_poll = -1; next_poll = -1;
return status; return status;
@ -336,9 +344,9 @@ asynStatus EL734Axis::setClosedLoop(bool closedLoop)
* \param[out] moving A flag that is set indicating that the axis is moving (true) or done (false). */ * \param[out] moving A flag that is set indicating that the axis is moving (true) or done (false). */
asynStatus EL734Axis::poll(bool *moving) asynStatus EL734Axis::poll(bool *moving)
{ {
int msr; int msr, count;
asynStatus comStatus; asynStatus comStatus;
char command[COMLEN], reply[COMLEN]; char command[COMLEN], reply[COMLEN], errTxt[256];
int driverError = 0; int driverError = 0;
@ -350,10 +358,9 @@ asynStatus EL734Axis::poll(bool *moving)
// Read the current motor position // Read the current motor position
sprintf(command,"u %d", axisNo_); sprintf(command,"u %d", axisNo_);
comStatus = pC_->transactController(command,reply); comStatus = pC_->transactController(axisNo_,command,reply);
if(comStatus == asynError){ if(comStatus == asynError){
updateMsgTxtFromDriver(reply); driverError = 1;
driverError = 1;
} }
if(comStatus) goto skip; if(comStatus) goto skip;
if(strstr(reply,"*ES") != NULL){ if(strstr(reply,"*ES") != NULL){
@ -369,7 +376,14 @@ asynStatus EL734Axis::poll(bool *moving)
updateMsgTxtFromDriver(NULL); updateMsgTxtFromDriver(NULL);
goto skip; goto skip;
} }
sscanf(reply,"%lf", &position); count = sscanf(reply,"%lf", &position);
if(count != 1) {
snprintf(errTxt,sizeof(errTxt),"Bad reply %s when reading position for %d", reply, axisNo_);
updateMsgTxtFromDriver(errTxt);
comStatus = asynError;
driverError =1;
goto skip;
}
//errlogPrintf("Axis %d, reply %s, position %lf\n", axisNo_, reply, position); //errlogPrintf("Axis %d, reply %s, position %lf\n", axisNo_, reply, position);
setDoubleParam(pC_->motorPosition_, position*1000); setDoubleParam(pC_->motorPosition_, position*1000);
//setDoubleParam(pC_->motorEncoderPosition_, position); //setDoubleParam(pC_->motorEncoderPosition_, position);
@ -377,7 +391,7 @@ asynStatus EL734Axis::poll(bool *moving)
// Read the moving status of this motor // Read the moving status of this motor
sprintf(command,"msr %d",axisNo_); sprintf(command,"msr %d",axisNo_);
comStatus = pC_->transactController(command,reply); comStatus = pC_->transactController(axisNo_,command,reply);
if(comStatus) goto skip; if(comStatus) goto skip;
sscanf(reply,"%x",&msr); sscanf(reply,"%x",&msr);
// errlogPrintf("Axis %d, reply %s, msr %d, position = %lf\n", // errlogPrintf("Axis %d, reply %s, msr %d, position = %lf\n",

View File

@ -53,7 +53,7 @@ friend class EL734Axis;
private: private:
asynUser *pasynUserController_; asynUser *pasynUserController_;
asynStatus transactController(char command[COMLEN], char reply[COMLEN]); asynStatus transactController(int axis, char command[COMLEN], char reply[COMLEN]);
void switchRemote(); void switchRemote();

View File

@ -16,8 +16,9 @@ class epicsShareClass SINQAxis : public asynMotorAxis
asynStatus setStringParam(int function, const char *value); asynStatus setStringParam(int function, const char *value);
friend class SINQController; friend class SINQController;
protected:
void updateMsgTxtFromDriver(const char *value); void updateMsgTxtFromDriver(const char *value);
protected:
private: private:
SINQController *pC_; SINQController *pC_;