diff --git a/src/turboPmacController.cpp b/src/turboPmacController.cpp index 2122d1d..f4426b0 100644 --- a/src/turboPmacController.cpp +++ b/src/turboPmacController.cpp @@ -207,7 +207,6 @@ asynStatus turboPmacController::writeRead(int axisNo, const char *command, // Definition of local variables. asynStatus status = asynSuccess; asynStatus timeoutStatus = asynSuccess; - // char fullCommand[MAXBUF_] = {0}; char drvMessageText[MAXBUF_] = {0}; char modResponse[MAXBUF_] = {0}; int motorStatusProblem = 0; @@ -255,6 +254,22 @@ asynStatus turboPmacController::writeRead(int axisNo, const char *command, pasynOctetSyncIOipPort(), command, commandLength, response, MAXBUF_, pTurboPmacC_->comTimeout, &nbytesOut, &nbytesIn, &eomReason); + /* + If sth. is written to the controller, it needs some time to process the + command. However, the controller returns the acknowledgment via + pasynOctetSyncIO->writeRead immediately, signalling to the driver that it is + ready to receive the next command. In practice, this can result in commands + getting discarded on the driver side or in bringing the driver in undefined + states (e.g. stuck in status 1). + + To prevent this, we wait for 20 ms after a write command to give the + controller enough time to process everything. A write command can be + identified by looking for the equal sign. + */ + if (strchr(command, '=')) { + usleep(20000); + } + msgPrintControlKey comKey = msgPrintControlKey(portName, axisNo, __PRETTY_FUNCTION__, __LINE__);