From 3e6df0a28f1dc81643c9da5fec7f9694b195e1a3 Mon Sep 17 00:00:00 2001 From: smathis Date: Tue, 20 Oct 2026 13:14:25 +0200 Subject: [PATCH] Graceful handling of short-lived communication errors. If a communication error between the MACS controller and a slave controller is short-lived, it shouldn't be reported to the user. --- src/masterMacsAxis.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/masterMacsAxis.cpp b/src/masterMacsAxis.cpp index 0777ab6..34594de 100644 --- a/src/masterMacsAxis.cpp +++ b/src/masterMacsAxis.cpp @@ -573,9 +573,21 @@ asynStatus masterMacsAxis::doPoll(bool *moving) { rwStatus = readAxisError(); } + // Calculate the number of minimum repetitions from the currently active + // poll period and the minGraceTime before reporting a communication error. + double pollInterval = pC_->idlePollPeriod(); + if (*moving) { + pollInterval = pC_->movingPollPeriod(); + } + double minGraceTime = 30.0; + int minRepetitions = + static_cast(std::ceil(minGraceTime / pollInterval)); + + // Repeat the communication error twice. msgPrintControlKey commError = msgPrintControlKey( pC_->portName, axisNo_, __PRETTY_FUNCTION__, __LINE__, - {.maxRepetitions = 5, .minRepetitions = 1}); + {.maxRepetitions = minRepetitions + 1, + .minRepetitions = minRepetitions}); /* A communication error is a special case. If a communication between @@ -583,7 +595,14 @@ asynStatus masterMacsAxis::doPoll(bool *moving) { since this information is not reliable. */ if (communicationError()) { - + /* + Only emit an error message if the communication error was set at least + minRepetitions times. This is to avoid reporting communication errors + which only occur very temporarily and are not relevant. As a concrete + example, if an axis is connected to the controller, the MACS might + detect that it is connected, but establishing the communication might + take a short time. This is not an error which should be reported. + */ if (pC_->getMsgPrintControl().repetitionCount(commError) >= commError.options_.minRepetitions) { if (pC_->getMsgPrintControl().shouldBePrinted(commError, true, @@ -604,6 +623,16 @@ asynStatus masterMacsAxis::doPoll(bool *moving) { poll_status = asynError; } else { pC_->getMsgPrintControl().incrementRepetitionCount(commError); + + /* + If the error shouldn't be reported yet (see text above), reset the + error message on the controller, as it will otherwise persist even + though the communication has been established. + */ + rwStatus = pC_->write(axisNo_, 17, ""); + if (rwStatus != asynSuccess) { + setAxisParamChecked(this, motorStatusProblem, true); + } } } else {