changed max axes to 10, changed debug output, always check limits, (MAXnet) fixed reading of long strings

This commit is contained in:
Jens Eden
2014-01-20 12:58:11 +00:00
parent f407631e15
commit 519fdd266b
5 changed files with 110 additions and 99 deletions
+1 -1
View File
@@ -167,7 +167,7 @@ asynStatus omsBaseAxis::stop(double acceleration )
asynPrint(pasynUser_, ASYN_TRACE_FLOW,
"%s:%s: port %s, set axis %d to stop with accel=%f\n",
driverName, functionName, pC_->portName, axisNo_, axisNo_, acceleration );
driverName, functionName, pC_->portName, axisNo_, acceleration );
return status;
}
+47 -42
View File
@@ -37,7 +37,7 @@ static const char *driverName = "omsBaseDriver";
#ifdef __GNUG__
#ifdef DEBUG
#define Debug(l, f, args...) {if (l <= motorOMSBASEdebug) \
#define Debug(l, f, args...) {if (l & motorOMSBASEdebug) \
errlogPrintf(f, ## args);}
#else
#define Debug(l, f, args...)
@@ -231,7 +231,7 @@ asynStatus omsBaseController::readInt32(asynUser *pasynUser, epicsInt32 *value)
int function = pasynUser->reason;
asynStatus status = asynSuccess;
omsBaseAxis *pAxis = getAxis(pasynUser);
static const char *functionName = "readInt32";
// static const char *functionName = "readInt32";
static char outputBuffer[8];
if (!pAxis) return asynError;
@@ -271,7 +271,7 @@ asynStatus omsBaseController::writeInt32(asynUser *pasynUser, epicsInt32 value)
if (function == motorDeferMoves_)
{
asynPrint(pasynUser, ASYN_TRACE_ERROR,
"%s:%s:%s Deferred Move: not yet implemented %s\n",
"%s:%s:%s Deferred Move: not yet implemented\n",
driverName, functionName, portName);
}
else if (function == motorClosedLoop_)
@@ -452,7 +452,7 @@ asynStatus omsBaseController::Init(const char* initString, int multiple){
char *p, *tokSave;
int totalAxes;
char axisChrArr[OMS_MAX_AXES] = {'X','Y','Z','T','U','V','R','S'};
char axisChrArr[OMS_MAX_AXES] = {'X','Y','Z','T','U','V','R','S','W','K'};
char outputBuffer[10];
epicsInt32 axisPosArr[OMS_MAX_AXES];
@@ -615,7 +615,7 @@ void omsBaseController::omsPoller()
if (loopBreakCount > 10){
errlogPrintf("%s:%s:%s: Error: %d consecutive unsuccessful attempts to read from motor card\n"
, driverName, functionName, this->portName, loopBreakCount);
loopBreakCount = 0;
break;
}
epicsTimeGetCurrent(&loopStart);
@@ -639,9 +639,9 @@ void omsBaseController::omsPoller()
}
/* read all axis status values and reset done-field
* MDNN,MDNN,PNLN,PNNN,PNLN,PNNN,PNNN,PNNN*/
* 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 axes status\n", driverName, functionName, this->portName);
++loopBreakCount;
continue;
}
@@ -672,24 +672,18 @@ void omsBaseController::omsPoller()
Debug(1,"%s:%s:%s: Error reading encoder status buffer >%s<\n", driverName, functionName, this->portName, encStatusBuffer);
}
/* read all limits */
if (moveDone || (anyMoving == 0))
haveLimits = true;
else
haveLimits = false;
haveLimits = true;
limitFlags =0;
if (haveLimits){
if ((sendReceiveLock((char*) "AM;QL;", pollInputBuffer, sizeof(pollInputBuffer)) == asynSuccess)){
if (1 != sscanf(pollInputBuffer, "%x", &limitFlags)){
Debug(1,"%s:%s:%s: error converting limits: %s\n", driverName, functionName, this->portName, pollInputBuffer);
haveLimits = false;
}
}
else {
haveLimits = false;
Debug(1,"%s:%s:%s: error reading limits %s\n", driverName, functionName, this->portName, pollInputBuffer);
}
}
if ((sendReceiveLock((char*) "AM;QL;", pollInputBuffer, sizeof(pollInputBuffer)) == asynSuccess)){
if (1 != sscanf(pollInputBuffer, "%x", &limitFlags)){
Debug(1,"%s:%s:%s: error converting limits: %s\n", driverName, functionName, this->portName, pollInputBuffer);
haveLimits = false;
}
}
else {
haveLimits = false;
Debug(1,"%s:%s:%s: error reading limits %s\n", driverName, functionName, this->portName, pollInputBuffer);
}
if (enabled) watchdogOK();
anyMoving = 0;
@@ -719,33 +713,42 @@ void omsBaseController::omsPoller()
/* check the done flag or current velocity */
if (statusBuffer[i*STATUSSTRINGLEN + 1] == 'D'){
Debug(3, "%s:%s:%s: found Done Flag axis %d\n", driverName, functionName, portName, i);
Debug(8, "%s:%s:%s: found Done Flag axis %d\n", driverName, functionName, portName, i);
pAxis->setIntegerParam(motorStatusProblem_, 0);
pAxis->moveDelay=0;
pAxis->setIntegerParam(motorStatusDone_, 1);
pAxis->setIntegerParam(motorStatusMoving_, 0);
if (pAxis->homing) pAxis->homing = 0;
Debug(1, "%s:%s:%s: done axis %d \n", driverName, functionName,
this->portName, i );
}
else if (haveVeloArray && (veloArr[i] == 0)){
/* keep a small delay here, to make sure that a motorAxisDone cycle is performed
even if the motor is on hard limits */
getIntegerParam(pAxis->axisNo_, motorStatusMoving_, &axisMoving);
if (axisMoving){
pAxis->moveDelay++ ;
if (pAxis->moveDelay >= 5) {
Debug(4, "%s:%s:%s: setting Problem Flag axis %d\n", driverName, functionName, portName, i);
if (statusBuffer[i*STATUSSTRINGLEN + 2] == 'L'){
pAxis->setIntegerParam(motorStatusProblem_, 0);
pAxis->moveDelay=0;
pAxis->setIntegerParam(motorStatusDone_, 1);
pAxis->setIntegerParam(motorStatusMoving_, 0);
pAxis->setIntegerParam(motorStatusProblem_, 1);
pAxis->moveDelay = 0;
if (pAxis->homing) pAxis->homing = 0;
Debug(1, "%s:%s:%s: stop axis %d, moveDelay count %d\n", driverName, functionName,
this->portName, i, pAxis->moveDelay );
if (statusBuffer[i*STATUSSTRINGLEN + 2] == 'P')
pAxis->setIntegerParam(motorStatusHighLimit_, 1);
else
pAxis->setIntegerParam(motorStatusLowLimit_, 1);
}
else {
pAxis->moveDelay++ ;
if (pAxis->moveDelay >= 5) {
Debug(4, "%s:%s:%s: setting Problem Flag axis %d\n", driverName, functionName, portName, i);
pAxis->setIntegerParam(motorStatusDone_, 1);
pAxis->setIntegerParam(motorStatusMoving_, 0);
pAxis->setIntegerParam(motorStatusProblem_, 1);
pAxis->moveDelay = 0;
if (pAxis->homing) pAxis->homing = 0;
Debug(1, "%s:%s:%s: stop axis %d, moveDelay count %d\n", driverName, functionName,
this->portName, i, pAxis->moveDelay );
}
Debug(2, "%s:%s:%s: moveDelay axis %d, count %d\n", driverName, functionName,
this->portName, i, pAxis->moveDelay );
}
Debug(2, "%s:%s:%s: moveDelay axis %d, count %d\n", driverName, functionName,
this->portName, i, pAxis->moveDelay );
}
}
else {
@@ -760,11 +763,13 @@ void omsBaseController::omsPoller()
/* check limits */
if (haveLimits){
if (((limitFlags & (1 << i)) > 0) ^ (pAxis->getLimitInvert()))
pAxis->setIntegerParam(motorStatusLowLimit_, 1);
int limitOffset = 0;
if (i > 7) limitOffset = 8; // same as limitOffset = 16 ; i -= 8
if (((limitFlags & (1 << (i+limitOffset))) > 0) ^ (pAxis->getLimitInvert()))
pAxis->setIntegerParam(motorStatusLowLimit_, 1);
else
pAxis->setIntegerParam(motorStatusLowLimit_, 0);
if (((limitFlags & (1 << (i+8))) > 0) ^ (pAxis->getLimitInvert()))
if (((limitFlags & (1 << (i+limitOffset+8))) > 0) ^ (pAxis->getLimitInvert()))
pAxis->setIntegerParam(motorStatusHighLimit_, 1);
else
pAxis->setIntegerParam(motorStatusHighLimit_, 0);
@@ -814,7 +819,7 @@ void omsBaseController::omsPoller()
waiting may be interrupted by pollEvent or interrupt messages*/
epicsTimeGetCurrent(&now);
timeToWait = timeout - epicsTimeDiffInSeconds(&now, &loopStart);
Debug(5, "%s:%s:%s: poller loop: waiting %f s\n", driverName, functionName, this->portName, timeToWait);
Debug(16, "%s:%s:%s: poller loop: waiting %f s\n", driverName, functionName, this->portName, timeToWait);
if (waitInterruptible(timeToWait) == epicsEventWaitOK) {
fastPolls = forcedFastPolls;
}
+1 -1
View File
@@ -27,7 +27,7 @@ HeadURL: $URL$
#include "omsBaseAxis.h"
#include <epicsExport.h>
#define OMS_MAX_AXES 8
#define OMS_MAX_AXES 10
#define OMSBASE_MAXNUMBERLEN 12
#define OMSINPUTBUFFERLEN OMSBASE_MAXNUMBERLEN * OMS_MAX_AXES + 2
+53 -50
View File
@@ -20,7 +20,7 @@ HeadURL: $URL$
#ifdef __GNUG__
#ifdef DEBUG
#define Debug(l, f, args...) {if (l <= motorMAXnetdebug) \
#define Debug(l, f, args...) {if (l & motorMAXnetdebug) \
errlogPrintf(f, ## args);}
#else
#define Debug(l, f, args...)
@@ -28,11 +28,12 @@ HeadURL: $URL$
#else
#define Debug
#endif
static const char *driverName = "omsMAXnetDriver";
volatile int motorMAXnetdebug = 0;
extern "C" {epicsExportAddress(int, motorMAXnetdebug);}
#define MAXnet_MAX_BUFFERLENGTH 80
#define MAXnet_MAX_BUFFERLENGTH 250
static void connectCallback(asynUser *pasynUser, asynException exception)
{
@@ -43,12 +44,12 @@ static void connectCallback(asynUser *pasynUser, asynException exception)
if (exception == asynExceptionConnect) {
status = pasynManager->isConnected(pasynUser, &connected);
if (connected){
if (motorMAXnetdebug > 4) asynPrint(pasynUser, ASYN_TRACE_FLOW,
if (motorMAXnetdebug & 8) asynPrint(pasynUser, ASYN_TRACE_FLOW,
"MAXnet connectCallback: TCP-Port connected\n");
pController->portConnected = 1;
}
else {
if (motorMAXnetdebug > 3) asynPrint(pasynUser, ASYN_TRACE_FLOW,
if (motorMAXnetdebug & 4) asynPrint(pasynUser, ASYN_TRACE_FLOW,
"MAXnet connectCallback: TCP-Port disconnected\n");
pController->portConnected = 0;
}
@@ -93,14 +94,12 @@ omsMAXnet::omsMAXnet(const char* portName, int numAxes, const char* serialPortNa
pasynUserSerial = pasynManager->createAsynUser(0,0);
pasynUserSerial->userPvt = this;
Debug(9, "omsMAXnet connect to %s \n", serialPortName);
status = pasynManager->connectDevice(pasynUserSerial,serialPortName,0);
if(status != asynSuccess){
printf("MAXnetConfig: can't connect to port %s: %s\n",serialPortName,pasynUserSerial->errorMessage);
return;
}
Debug(9, "omsMAXnet add Callback \n");
status = pasynManager->exceptionCallbackAdd(pasynUserSerial, connectCallback);
if(status != asynSuccess){
printf("MAXnetConfig: can't set exceptionCallback for %s: %s\n",serialPortName,pasynUserSerial->errorMessage);
@@ -109,7 +108,6 @@ omsMAXnet::omsMAXnet(const char* portName, int numAxes, const char* serialPortNa
/* set the connect flag */
pasynManager->isConnected(pasynUserSerial, &portConnected);
Debug(9, "omsMAXnet findInterface \n");
pasynInterface = pasynManager->findInterface(pasynUserSerial,asynOctetType,1);
if( pasynInterface == NULL) {
printf("MAXnetConfig: %s driver not supported\n", asynOctetType);
@@ -118,7 +116,6 @@ omsMAXnet::omsMAXnet(const char* portName, int numAxes, const char* serialPortNa
pasynOctetSerial = (asynOctet*)pasynInterface->pinterface;
octetPvtSerial = pasynInterface->drvPvt;
Debug(9, "omsMAXnet SyncIO->connect \n");
status = pasynOctetSyncIO->connect(serialPortName, 0, &pasynUserSyncIOSerial, NULL);
if(status != asynSuccess){
printf("MAXnetConfig: can't connect pasynOctetSyncIO %s: %s\n",serialPortName,pasynUserSyncIOSerial->errorMessage);
@@ -126,13 +123,11 @@ omsMAXnet::omsMAXnet(const char* portName, int numAxes, const char* serialPortNa
}
/* flush any junk at input port - should be no data available */
Debug(9, "omsMAXnet flush \n");
pasynOctetSyncIO->flush(pasynUserSyncIOSerial);
timeout = 2.0;
pasynUserSerial->timeout = 0.0;
Debug(9, "omsMAXnet setInputEos \n");
// CAUTION firmware versions before 1.33.4 use '\n' for serial port and '\n\r' for IP port as InputEOS
// Set inputEOS in st.cmd for old firmware versions
status = pasynOctetSyncIO->setInputEos(pasynUserSyncIOSerial, "\n\r", 2);
@@ -141,14 +136,12 @@ omsMAXnet::omsMAXnet(const char* portName, int numAxes, const char* serialPortNa
return ;
}
Debug(9, "omsMAXnet setOutputEos \n");
status = pasynOctetSyncIO->setOutputEos(pasynUserSyncIOSerial, "\n", 1);
if(status != asynSuccess){
printf("MAXnetConfig: unable to set OutputEOS %s: %s\n",serialPortName,pasynUserSyncIOSerial->errorMessage);
return ;
}
Debug(9, "omsMAXnet registerInterruptUser \n");
void* registrarPvt= NULL;
status = pasynOctetSerial->registerInterruptUser(octetPvtSerial, pasynUserSerial, omsMAXnet::asynCallback, this, &registrarPvt);
if(status != asynSuccess) {
@@ -156,7 +149,6 @@ omsMAXnet::omsMAXnet(const char* portName, int numAxes, const char* serialPortNa
return;
}
Debug(9, "omsMAXnet get FirmwareVersion \n");
/* get FirmwareVersion */
if(getFirmwareVersion() != asynSuccess) {
printf("MAXnetConfig: unable to talk to controller at %s: %s\n",serialPortName,pasynUserSyncIOSerial->errorMessage);
@@ -184,7 +176,6 @@ epicsEventWaitStatus omsMAXnet::waitInterruptible(double timeout)
epicsEventWaitStatus waitStatus = epicsEventWaitTimeout;
epicsTimeGetCurrent(&starttime);
// TODO use local poll Periods or lock()
if (timeout == idlePollPeriod_)
pollWait = idlePollPeriod_ / 5.0;
else
@@ -195,7 +186,7 @@ epicsEventWaitStatus omsMAXnet::waitInterruptible(double timeout)
pasynManager->unlockPort(pasynUserSerial);
while ( timeToWait > 0){
/* reading with bufferlength 0 and timeout 0.0 triggers a callback and
* poll event, if a notification is outstanding */
* poll event, if a notification is outstanding. One character will be read. */
if (enabled) {
pasynManager->lockPort(pasynUserSerial);
status = pasynOctetSerial->read(octetPvtSerial, pasynUserSerial, inputBuff,
@@ -218,14 +209,13 @@ asynStatus omsMAXnet::sendOnly(const char *outputBuff)
asynStatus status;
if (!enabled) return asynError;
Debug(9, "omsMAXnet::sendOnly: write: %s \n", outputBuff);
status = pasynOctetSyncIO->write(pasynUserSyncIOSerial, outputBuff,
strlen(outputBuff), timeout, &nActual);
if (status != asynSuccess) {
asynPrint(pasynUserSyncIOSerial, ASYN_TRACE_ERROR,
"drvMAXnetAsyn:sendOnly: error sending command %d, sent=%d, status=%d\n",
"drvMAXnetAsyn:sendOnly: error sending command %s, sent=%d, status=%d\n",
outputBuff, nActual, status);
}
Debug(4, "omsMAXnet::sendOnly: wrote: %s \n", outputBuff);
@@ -235,28 +225,30 @@ asynStatus omsMAXnet::sendOnly(const char *outputBuff)
asynStatus omsMAXnet::sendReceive(const char *outputBuff, char *inputBuff, unsigned int inputSize)
{
char localBuffer[MAXnet_MAX_BUFFERLENGTH + 1] = "";
size_t nRead, nWrite, bufferSize = inputSize;
size_t nRead=0, nReadnext=0, nWrite=0;
size_t bufferSize = MAXnet_MAX_BUFFERLENGTH;
int eomReason = 0;
asynStatus status = asynSuccess;
char *outString;
char *outString = localBuffer;
int errorCount = 10;
if (!enabled) return asynError;
Debug(4, "omsMAXnet::sendReceive: write: %s \n", outputBuff);
if (bufferSize > MAXnet_MAX_BUFFERLENGTH) bufferSize = MAXnet_MAX_BUFFERLENGTH;
Debug(9, "omsMAXnet::sendReceive: read the notification \n");
/*
* read the notification from input buffer
*/
while ((notificationCounter > 0) && errorCount){
status = pasynOctetSyncIO->read(pasynUserSyncIOSerial, localBuffer, sizeof(localBuffer), 0.1, &nRead, &eomReason);
status = pasynOctetSyncIO->read(pasynUserSyncIOSerial, localBuffer, bufferSize, 0.001, &nRead, &eomReason);
while ((status == asynSuccess) && !(eomReason & ASYN_EOM_EOS)) {
status = pasynOctetSyncIO->read(pasynUserSyncIOSerial, localBuffer+nRead,
bufferSize-nRead, timeout, &nReadnext, &eomReason);
nRead += nReadnext;
}
localBuffer[nRead] = '\0';
outString = localBuffer;
while (*outString == 6) ++outString;
if (status == asynSuccess) {
localBuffer[nRead] = '\0';
if (isNotification(localBuffer) && (notificationCounter > 0)) {
Debug(2, "omsMAXnet::sendReceive: decrement notificationCounter: %s, len: %d, reason: %d\n", localBuffer, nRead, eomReason);
if (isNotification(outString) && (notificationCounter > 0)) {
--notificationCounter;
}
}
@@ -268,33 +260,43 @@ asynStatus omsMAXnet::sendReceive(const char *outputBuff, char *inputBuff, unsig
}
}
Debug(9, "omsMAXnet::sendReceive: write \n");
Debug(4, "omsMAXnet::sendReceive: write: %s \n", outputBuff);
nRead=0;
nReadnext=0;
status = pasynOctetSyncIO->writeRead(pasynUserSyncIOSerial, outputBuff, strlen(outputBuff), localBuffer,
bufferSize, timeout, &nWrite, &nRead, &eomReason);
if (status == asynSuccess) localBuffer[nRead] = '\0';
// if input data is a notification read until expected data arrived
while ((status == asynSuccess) && isNotification(localBuffer)) {
Debug(2, "omsMAXnet::sendReceive: notification while reading: %s\n", localBuffer);
while ((status == asynSuccess) && !(eomReason & ASYN_EOM_EOS)) {
status = pasynOctetSyncIO->read(pasynUserSyncIOSerial, localBuffer+nRead,
bufferSize-nRead, timeout, &nReadnext, &eomReason);
nRead += nReadnext;
}
localBuffer[nRead] = '\0';
// cut off a leading /006
outString = localBuffer;
while (*outString == 6) ++outString;
// if input data is a notification read until expected data arrived
while ((status == asynSuccess) && isNotification(outString)) {
nRead=0;
nReadnext=0;
status = pasynOctetSyncIO->read(pasynUserSyncIOSerial, localBuffer,
bufferSize, timeout, &nRead, &eomReason);
if (status == asynSuccess) localBuffer[nRead] = '\0';
while ((status == asynSuccess) && !(eomReason & ASYN_EOM_EOS)) {
status = pasynOctetSyncIO->read(pasynUserSyncIOSerial, localBuffer+nRead,
bufferSize-nRead, timeout, &nReadnext, &eomReason);
nRead += nReadnext;
}
localBuffer[nRead] = '\0';
// cut off a leading /006
outString = localBuffer;
while (*outString == 6) ++outString;
if (notificationCounter > 0) --notificationCounter;
}
if ((status == asynSuccess) && (eomReason == ASYN_EOM_EOS)) {
// cut off a leading /006
outString = strrchr(localBuffer, 6);
if (outString == NULL) {
outString = localBuffer;
}
else {
++outString;
}
// copy into inputBuffer
strncpy(inputBuff, outString, inputSize);
inputBuff[inputSize-1] = '\0';
}
// copy into inputBuffer
strncpy(inputBuff, outString, inputSize);
inputBuff[inputSize-1] = '\0';
Debug(4, "omsMAXnet::sendReceive: read: %s \n", inputBuff);
@@ -303,6 +305,7 @@ asynStatus omsMAXnet::sendReceive(const char *outputBuff, char *inputBuff, unsig
/*
* check if buffer is a notification messages with 13 chars ("%000 SSSSSSSS")
* (first character may miss
*/
int omsMAXnet::isNotification (char *buffer) {
@@ -313,8 +316,8 @@ int omsMAXnet::isNotification (char *buffer) {
printf("%s:%s:%s: CMD_ERR_FLAG received\n", driverName, functionName, portName);
}
else {
if (motorMAXnetdebug > 1) printf("%s:%s:%s: Interrupt notification: %s\n",
driverName, functionName, portName, buffer);
Debug(2,"%s:%s:%s: Interrupt notification: %s\n",
driverName, functionName, portName, buffer);
epicsEventSignal(pollEventId_);
}
return 1;
+8 -5
View File
@@ -23,7 +23,7 @@ HeadURL: $URL$
#include <epicsExit.h>
#include "omsMAXv.h"
static const char *driverName = "omsMAXvDriver";
static const char *driverName = "omsMAXvAsyn";
#define MIN(a,b) ((a)<(b)? (a): (b))
@@ -66,10 +66,11 @@ void omsMAXv::InterruptHandler( void * param )
epicsInterruptContextMessage(errmsg);
}
// not clearing this may corrupt the next read/write operation
/* unset this bit to not clear the text_response bit */
if (status1_flag.Bits.text_response != 0) status1_flag.Bits.text_response = 0;
pmotor->status1_flag.All = status1_flag.All; /* Release IRQ's. */
/* Release IRQ's. Clear bits by writing a 1 */
pmotor->status1_flag.All = status1_flag.All;
/* do a dummy read to ensure that all previous writes, which may
* have been queued in the VME bridge chip get processed
@@ -359,7 +360,9 @@ asynStatus omsMAXv::sendOnly(const char *outputBuff)
*/
asynStatus omsMAXv::sendReceive(const char *outputBuff, char *inputBuff, unsigned int inputSize)
{
#ifdef DEBUG
static const char* functionName = "sendReceive";
#endif
STATUS1 flag1;
epicsUInt16 getIndex, putIndex;
@@ -378,7 +381,6 @@ asynStatus omsMAXv::sendReceive(const char *outputBuff, char *inputBuff, unsigne
*inputBuff = '\0';
Debug(64, "omsMAXv::sendReceive: receiving\n");
itera = 0;
double time = 0.0;
double timeout = epicsThreadSleepQuantum() + 0.001;
@@ -395,7 +397,8 @@ asynStatus omsMAXv::sendReceive(const char *outputBuff, char *inputBuff, unsigne
if (pmotor->status1_flag.Bits.text_response == 0)
{
Debug(1, "Timeout occurred in recv_mess, %s\n", outputBuff);
Debug(1, "%s:%s:%s: Timeout occurred , %s\n",
driverName, functionName, portName, outputBuff);
return asynTimeout;
}