From 82fe312c4cb62a005301774ca0c6842e45d1755f Mon Sep 17 00:00:00 2001 From: Jens Eden Date: Wed, 7 Jan 2015 10:21:35 +0000 Subject: [PATCH] split init string into individual commands; read status before position --- motorApp/OmsAsynSrc/omsBaseController.cpp | 33 ++++++++++++++--------- motorApp/OmsAsynSrc/omsBaseController.h | 1 + 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/motorApp/OmsAsynSrc/omsBaseController.cpp b/motorApp/OmsAsynSrc/omsBaseController.cpp index 46b0feb7..dfa096dc 100644 --- a/motorApp/OmsAsynSrc/omsBaseController.cpp +++ b/motorApp/OmsAsynSrc/omsBaseController.cpp @@ -471,12 +471,18 @@ asynStatus omsBaseController::Init(const char* initString, int multiple){ /* send InitString */ if ((initString != NULL) && (strlen(initString) > 0)) { if (multiple){ + /* send each commmand in initstring individually */ + char* tmpout = new char[strlen(initString)+2]; char* inittmp = epicsStrDup(initString); for (tokSave = NULL, p = epicsStrtok_r(inittmp, ";", &tokSave); p != NULL; p = epicsStrtok_r(NULL, ";", &tokSave)) { - sendOnlyLock(p); + strcpy(tmpout, p); + strcat(tmpout, ";"); + sendOnlyLock(tmpout); + epicsThreadSleep(0.1); } free(inittmp); + delete[] tmpout; } else { sendOnlyLock(initString); @@ -626,28 +632,31 @@ void omsBaseController::omsPoller() epicsTimeGetCurrent(&loopStart); + /* read all axis status values and reset done-field + * MDNN,MDNN,PNLN,PNNN,PNLN,PNNN,PNNN,PNNN */ retry_count = 0; - while ((getAxesPositions(axisPosArr) != asynSuccess) && (retry_count < 5)){ + while ((getAxesStatus(statusBuffer, sizeof(statusBuffer), &moveDone) != asynSuccess) && (retry_count < 5)){ + Debug(1, "%s:%s:%s: error reading axes status\n", driverName, functionName, this->portName); epicsThreadSleep(0.1); ++retry_count; } + if (retry_count > 4){ - errlogPrintf("%s:%s:%s: error reading axis position after %d attempts\n", + errlogPrintf("%s:%s:%s: error reading axis status (%d attempts)\n", driverName, functionName, this->portName, retry_count); ++loopBreakCount; + resetConnection(); + continue; + } + + if (getAxesPositions(axisPosArr) != asynSuccess){ + Debug(1, "%s:%s:%s: error reading axis positions\n", driverName, functionName, this->portName); + ++loopBreakCount; continue; } if (useEncoder && (getEncoderPositions(encPosArr) != asynSuccess)){ - Debug(1, "%s:%s:%s: error executing get Encoder Positions\n", driverName, functionName, this->portName); - ++loopBreakCount; - continue; - } - - /* read all axis status values and reset done-field - * MDNN,MDNN,PNLN,PNNN,PNLN,PNNN,PNNN,PNNN */ - if (getAxesStatus(statusBuffer, sizeof(statusBuffer), &moveDone) != asynSuccess){ - Debug(1, "%s:%s:%s: error reading axes status\n", driverName, functionName, this->portName); + Debug(1, "%s:%s:%s: error reading encoder positions\n", driverName, functionName, this->portName); ++loopBreakCount; continue; } diff --git a/motorApp/OmsAsynSrc/omsBaseController.h b/motorApp/OmsAsynSrc/omsBaseController.h index 79a7c08d..d3290c0d 100644 --- a/motorApp/OmsAsynSrc/omsBaseController.h +++ b/motorApp/OmsAsynSrc/omsBaseController.h @@ -62,6 +62,7 @@ protected: virtual asynStatus getClosedLoopStatus(int clstatus[OMS_MAX_AXES]); virtual epicsEventWaitStatus waitInterruptible(double timeout); virtual bool watchdogOK(); + virtual bool resetConnection(){return false;}; char* getPortName(){return portName;}; bool firmwareMin(int, int, int); static omsBaseController* findController(const char*);