From 3f7998eb9ad57a4474e36a0cde7227ab30a0cb60 Mon Sep 17 00:00:00 2001 From: smathis Date: Thu, 24 Jul 2025 08:51:38 +0200 Subject: [PATCH] Added sleep after write commands See comment in writeRead for explanation. --- src/turboPmacController.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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__);