Skip to content

Commit

Permalink
Merge pull request #167 from EuropeanSpallationSource/asynMotor-remov…
Browse files Browse the repository at this point in the history
…e-initEvent

devMotorAsyn: remove initEvent in init_record()

Fixes #164 (problem 2)
  • Loading branch information
kmpeters authored May 15, 2023
2 parents cd09677 + 9064380 commit 891a66e
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions motorApp/MotorSrc/devMotorAsyn.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

#include <asynDriver.h>
#include <asynInt32.h>
#include <asynFloat64SyncIO.h>
#include <asynFloat64.h>
#include <asynDrvUser.h>
#include <asynFloat64Array.h>
Expand Down Expand Up @@ -137,6 +138,7 @@ typedef struct
double param;
int needUpdate;
asynUser *pasynUser;
asynUser *pasynUserSync;
asynInt32 *pasynInt32;
void *asynInt32Pvt;
asynFloat64 *pasynFloat64;
Expand All @@ -148,7 +150,6 @@ typedef struct
asynGenericPointer *pasynGenericPointer;
void *asynGenericPointerPvt;
void *registrarPvt;
epicsEventId initEvent;
int driverReasons[NUM_MOTOR_COMMANDS];
} motorAsynPvt;

Expand All @@ -170,16 +171,23 @@ static void init_controller(struct motorRecord *pmr, asynUser *pasynUser )
motorAsynPvt *pPvt = (motorAsynPvt *)pmr->dpvt;
double position = pPvt->status.position;
double rdbd = (fabs(pmr->rdbd) < fabs(pmr->mres) ? fabs(pmr->mres) : fabs(pmr->rdbd) );
double encRatio[2] = {pmr->mres, pmr->eres};
int use_rel = (pmr->rtry != 0 && pmr->rmod != motorRMOD_I && (pmr->ueip || pmr->urip));
int dval_non_zero_pos_near_zero = (fabs(pmr->dval) > rdbd) &&
(pmr->mres != 0) && (fabs(position * pmr->mres) < rdbd);
epicsFloat64 eratio = pmr->mres / pmr->eres;
int initPos = 0;
int status;

/*Before setting position, set the correct encoder ratio.*/
start_trans(pmr);
build_trans(SET_ENC_RATIO, encRatio, pmr);
end_trans(pmr);
/* Write encoder ratio to the driver.*/
pPvt->pasynUserSync->reason = pPvt->driverReasons[motorEncRatio];
status = pasynFloat64SyncIO->write(pPvt->pasynUserSync, eratio, pasynUser->timeout);
if (status) {
asynPrint(pasynUser, ASYN_TRACE_ERROR,
"devMotorAsyn::init_controller, %s failed to set encoder ratio to %f\n", pmr->name, eratio );
} else {
asynPrint(pasynUser, ASYN_TRACE_FLOW,
"devMotorAsyn::init_controller, %s set encoder ratio to %f\n", pmr->name, eratio );
}

switch (pmr->rstm) {
case motorRSTM_NearZero:
Expand All @@ -202,15 +210,11 @@ static void init_controller(struct motorRecord *pmr, asynUser *pasynUser )
if (initPos)
{
double setPos = pmr->dval / pmr->mres;
epicsEventId initEvent = epicsEventCreate( epicsEventEmpty );
RTN_STATUS rtnval;

pPvt->initEvent = initEvent;

start_trans(pmr);
rtnval = build_trans(LOAD_POS, &setPos, pmr);
end_trans(pmr);
if (rtnval != OK) {
/* Write setPos to the driver */
pPvt->pasynUserSync->reason = pPvt->driverReasons[motorPosition];
status = pasynFloat64SyncIO->write(pPvt->pasynUserSync, setPos, pasynUser->timeout);
if (status) {
asynPrint(pasynUser, ASYN_TRACE_ERROR,
"devMotorAsyn::init_controller, %s failed to set position to %f\n",
pmr->name, setPos );
Expand All @@ -219,13 +223,6 @@ static void init_controller(struct motorRecord *pmr, asynUser *pasynUser )
"devMotorAsyn::init_controller, %s set position to %f\n",
pmr->name, setPos );
}

if ( initEvent )
{
epicsEventMustWait(initEvent);
epicsEventDestroy(initEvent);
pPvt->initEvent = 0;
}
}
else
asynPrint(pasynUser, ASYN_TRACE_FLOW,
Expand Down Expand Up @@ -307,6 +304,14 @@ static long init_record(struct motorRecord * pmr )
pPvt->pasynFloat64 = (asynFloat64 *)pasynInterface->pinterface;
pPvt->asynFloat64Pvt = pasynInterface->drvPvt;

/* Initialize Float64 synchronous interface */
status = pasynFloat64SyncIO->connect(port, signal, &pPvt->pasynUserSync, userParam);
if (status != asynSuccess) {
asynPrint(pasynUser, ASYN_TRACE_ERROR,
"devMotorAsyn::init_record, %s connect Float64SyncIO interface failed\n", pmr->name);
goto bad;
}

/* Get the asynDrvUser interface */
pasynInterface = pasynManager->findInterface(pasynUser, asynDrvUserType, 1); if (!pasynInterface) {
asynPrint(pasynUser, ASYN_TRACE_ERROR,
Expand Down Expand Up @@ -408,6 +413,9 @@ static long init_record(struct motorRecord * pmr )
* set, a callback will be generated
*/

/* Finished using the Float64 SyncIO interface */
pasynFloat64SyncIO->disconnect(pPvt->pasynUserSync);

/* Finally, indicate to the motor record that these values can be used. */
pasynManager->freeAsynUser(pasynUser);
pPvt->needUpdate = 1;
Expand Down Expand Up @@ -720,10 +728,6 @@ static void asynCallback(asynUser *pasynUser)
"devMotorAsyn::asynCallback: %s error in freeAsynUser, %s\n",
pmr->name, pasynUser->errorMessage);
}

if ( pPvt->initEvent && pmsg->command == motorPosition) {
epicsEventSignal( pPvt->initEvent );
}
}

/**
Expand Down

0 comments on commit 891a66e

Please sign in to comment.