diff --git a/slsmagnet.c b/slsmagnet.c index 47764bc..400797d 100644 --- a/slsmagnet.c +++ b/slsmagnet.c @@ -139,6 +139,7 @@ static int communicateSLS(mkChannel *pSock, char msg[6], char reply[6]) if(!pSock) return NOTCONNECTED; + memset(reply,0,6); address = (int)msg[1]; iRet = NETWrite(pSock,msg,6); if(iRet < 0) @@ -924,11 +925,34 @@ static void slsdspCodeToText(int code, char *text, int textlen){ return DEVFAULT; } ival = (int)reply[5]; - if(ival != 0){ - return DEVFAULT; - } else { + if(ival == 0){ return DEVREDO; - } + } + /* + * OK, clearing the error did not work, I try to reinitialize the + * socket because this helps sometimes. + */ + NETClosePort(pMe->pSock); + pMe->pSock = NULL; + pMe->pSock = NETConnect(pMe->pHost,pMe->iPort); + if(!pMe->pSock) + { + return DEVFAULT; + } + sleep(1); + msg[0] = DSPREAD; + msg[1] = 0x29; + iRet = communicateSLS(pMe->pSock,msg,reply); + if(iRet < 0) + { + return DEVFAULT; + } + ival = (int)reply[5]; + if(ival == 0){ + return DEVREDO; + } else { + return DEVFAULT; + } } switch(iError) diff --git a/tabledrive.c b/tabledrive.c index 9ebbbd7..a4196c6 100644 --- a/tabledrive.c +++ b/tabledrive.c @@ -57,7 +57,7 @@ static int TableDriveCheckLimits(void *pData, float fVal, char *error, strncpy(error,"Path Table Not Defined!",25); return 0; } - if(fVal < 1. || fVal >= self->tableLength){ + if(fVal < 1. || fVal > self->tableLength){ strncpy(error,"Out of Range",25); return 0; } @@ -267,7 +267,7 @@ static void tableInfo(pTableDrive self, SConnection *pCon){ MotorGetPar(moti.pMot,"precision",&tolerance); targetPosition = findTarget(moti,value); snprintf(pBueffel,256,"Motor %10s, should: %8.2f, is %8.2f, diff = %8.2f", - moti.motorName, motorPosition, targetPosition, + moti.motorName, targetPosition, motorPosition, ABS(targetPosition - motorPosition)); SCWrite(pCon,pBueffel,eValue); }