From 1477975057d8e98f7ef0a81ef78e30d30e4c0f0e Mon Sep 17 00:00:00 2001 From: kpetersn Date: Fri, 10 Aug 2018 10:47:02 -0500 Subject: [PATCH] Patch from Takashi Nakamoto of the National Astronomical Observatory of Japan: "While I was developing an EPICS application on the top of the motor module, my application died for segmentation fault. The reason was my mistake: I forgot to call XPSConfigAxis before I start to use that axis, but it took time for me to find it out (e.g. compiled the motor module and my application with debug option, running gdb, ...). So, I thought it would be nice if an error message is shown in the console instead of sudden death only with segmentation fault message, and the attached patch does it." --- motorApp/NewportSrc/drvXPSAsyn.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/motorApp/NewportSrc/drvXPSAsyn.c b/motorApp/NewportSrc/drvXPSAsyn.c index 72b191f9..eb1e8654 100644 --- a/motorApp/NewportSrc/drvXPSAsyn.c +++ b/motorApp/NewportSrc/drvXPSAsyn.c @@ -612,6 +612,10 @@ static int motorAxisSetDouble(AXIS_HDL pAxis, motorAxisParam_t function, double double positions[XPS_MAX_AXES] = {0.0}; if (pAxis == NULL) return MOTOR_AXIS_ERROR; + if (!pAxis->mutexId) { + PRINT(pAxis->logParam, MOTOR_ERROR, "motorAxisSetDouble[%d,%d]: invalid mutex ID. Call XPSConfigAxis first for initialization.\n", pAxis->card, pAxis->axis); + return MOTOR_AXIS_ERROR; + } else { if (epicsMutexLock( pAxis->mutexId ) == epicsMutexLockOK) @@ -937,6 +941,11 @@ static int motorAxisMove(AXIS_HDL pAxis, double position, int relative, if (pAxis == NULL) return MOTOR_AXIS_ERROR; + if (!pAxis->mutexId) { + PRINT(pAxis->logParam, MOTOR_ERROR, "motorAxisMove[%d,%d]: invalid mutex ID. Call XPSConfigAxis first for initialization.\n", pAxis->card, pAxis->axis); + return MOTOR_AXIS_ERROR; + } + PRINT(pAxis->logParam, FLOW, "Set card %d, axis %d move to %f, min vel=%f, max_vel=%f, accel=%f\n", pAxis->card, pAxis->axis, position, min_velocity, max_velocity, acceleration);