Skip to content

Commit f969c82

Browse files
authored
Merge pull request #17 from epics-motor/issue16
Added a writeOnlyDelay argument to nf874xCreateController Fixes #16
2 parents 6143b86 + 285e582 commit f969c82

4 files changed

Lines changed: 40 additions & 9 deletions

File tree

iocs/newFocusIOC/iocBoot/iocNewFocus/newfocus8742.cmd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ asynSetTraceIOMask("$(PORT)_ETH",-1,0x1)
1717
# (3) Number of axes
1818
# (4) Moving poll period (ms)
1919
# (5) Idle poll period (ms)
20-
nf874xCreateController("$(PORT)", "$(PORT)_ETH", 3, 200, 1000)
20+
# (6) Write-only delay (ms)
21+
nf874xCreateController("$(PORT)", "$(PORT)_ETH", 3, 200, 1000, 10)
2122

2223
## Load record instances
2324
dbLoadTemplate("newfocus8742.substitutions", "P=$(PREFIX),PORT=$(PORT)")

iocs/newFocusIOC/newFocusApp/src/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ include $(TOP)/configure/CONFIG
55
# ADD MACRO DEFINITIONS AFTER THIS LINE
66
#=============================
77

8+
# EPICS base sorts libraries, which prevents motorAcsMotion from overriding
9+
# motor/modules/motorAcsMotion. The following lines fix this, in theory.
10+
#!PROD_DEPLIB_DIRS = $(foreach word, $(INSTALL_LIB)/ \
11+
#! $(dir $($*_DEPLIBS) $(PROD_DEPLIBS)), $(abspath $(word)))
12+
813
# The following are used for debugging messages.
914
#!USR_CXXFLAGS += -DDEBUG
1015

newFocusApp/src/874xMotorDriver.cpp

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static const char *driverName = "nf874xMotorDriver";
3939
* \param[in] idlePollPeriod The time between polls when no axis is moving
4040
*/
4141
nf874xController::nf874xController(const char *portName, const char *nf874xPortName, int numAxes,
42-
double movingPollPeriod, double idlePollPeriod)
42+
double movingPollPeriod, double idlePollPeriod, double writeOnlyDelay)
4343
//: asynMotorController(portName, numAxes, NUM_nf874x_PARAMS,
4444
: asynMotorController(portName, numAxes+1, NUM_nf874x_PARAMS,
4545
asynUInt32DigitalMask,
@@ -51,7 +51,12 @@ nf874xController::nf874xController(const char *portName, const char *nf874xPortN
5151
int axis;
5252
asynStatus status;
5353
static const char *functionName = "nf874xController";
54-
54+
55+
writeOnlyDelay_ = writeOnlyDelay;
56+
asynPrint(this->pasynUserSelf, ASYN_TRACE_ERROR,
57+
"%s:%s: nf874x write-only delay (ms): %lf\n",
58+
driverName, functionName, writeOnlyDelay_);
59+
5560
/* Connect to nf874x controller */
5661
status = pasynOctetSyncIO->connect(nf874xPortName, 0, &pasynUserController_, NULL);
5762
if (status) {
@@ -97,11 +102,12 @@ nf874xController::nf874xController(const char *portName, const char *nf874xPortN
97102
* \param[in] numAxes The number of axes that this controller supports.
98103
* \param[in] movingPollPeriod The time in ms between polls when any axis is moving
99104
* \param[in] idlePollPeriod The time in ms between polls when no axis is moving
105+
* \param[in] writeOnlyDelay The time in ms to sleep before sending a write-only command
100106
*/
101107
extern "C" int nf874xCreateController(const char *portName, const char *nf874xPortName, int numAxes,
102-
int movingPollPeriod, int idlePollPeriod)
108+
int movingPollPeriod, int idlePollPeriod, int writeOnlyDelay)
103109
{
104-
new nf874xController(portName, nf874xPortName, numAxes, movingPollPeriod/1000., idlePollPeriod/1000.);
110+
new nf874xController(portName, nf874xPortName, numAxes, movingPollPeriod/1000., idlePollPeriod/1000., writeOnlyDelay/1000.);
105111
return(asynSuccess);
106112
}
107113

@@ -137,6 +143,12 @@ nf874xAxis* nf874xController::getAxis(int axisNo)
137143
return static_cast<nf874xAxis*>(asynMotorController::getAxis(axisNo));
138144
}
139145

146+
/** Writes a string to the controller after a delay */
147+
asynStatus nf874xController::writeController()
148+
{
149+
epicsThreadSleep(writeOnlyDelay_);
150+
return asynMotorController::writeController();
151+
}
140152

141153
/** Called when asyn clients call pasynInt32->write().
142154
* Extracts the function and axis number from pasynUser.
@@ -461,6 +473,7 @@ asynStatus nf874xAxis::poll(bool *moving)
461473
{
462474
int done;
463475
asynStatus comStatus;
476+
static const char *functionName = "poll";
464477

465478
// Returned poll values will include the controller id in the response if it was
466479
// supplied as part of the axis name. Skip past the '>' before interpreting the result.
@@ -545,6 +558,13 @@ asynStatus nf874xAxis::poll(bool *moving)
545558
}
546559

547560
skip:
561+
562+
if (comStatus) {
563+
asynPrint(pasynUser_, ASYN_TRACE_ERROR,
564+
"%s:%s: error, comStatus=%d\n",
565+
driverName, functionName, comStatus);
566+
}
567+
548568
setIntegerParam(pC_->motorStatusProblem_, comStatus ? 1 : 0);
549569
callParamCallbacks();
550570
return comStatus ? asynError : asynSuccess;
@@ -598,15 +618,17 @@ static const iocshArg nf874xCreateControllerArg1 = {"nf874x port name", iocshArg
598618
static const iocshArg nf874xCreateControllerArg2 = {"Number of axes", iocshArgInt};
599619
static const iocshArg nf874xCreateControllerArg3 = {"Moving poll period (ms)", iocshArgInt};
600620
static const iocshArg nf874xCreateControllerArg4 = {"Idle poll period (ms)", iocshArgInt};
621+
static const iocshArg nf874xCreateControllerArg5 = {"Write-only delay (ms)", iocshArgInt};
601622
static const iocshArg * const nf874xCreateControllerArgs[] = {&nf874xCreateControllerArg0,
602623
&nf874xCreateControllerArg1,
603624
&nf874xCreateControllerArg2,
604625
&nf874xCreateControllerArg3,
605-
&nf874xCreateControllerArg4};
606-
static const iocshFuncDef nf874xCreateControllerDef = {"nf874xCreateController", 5, nf874xCreateControllerArgs};
626+
&nf874xCreateControllerArg4,
627+
&nf874xCreateControllerArg5};
628+
static const iocshFuncDef nf874xCreateControllerDef = {"nf874xCreateController", 6, nf874xCreateControllerArgs};
607629
static void nf874xCreateControllerCallFunc(const iocshArgBuf *args)
608630
{
609-
nf874xCreateController(args[0].sval, args[1].sval, args[2].ival, args[3].ival, args[4].ival);
631+
nf874xCreateController(args[0].sval, args[1].sval, args[2].ival, args[3].ival, args[4].ival, args[5].ival);
610632
}
611633

612634
static void nf874xMotorRegister(void)

newFocusApp/src/874xMotorDriver.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ friend class nf874xController;
6161

6262
class epicsShareClass nf874xController : public asynMotorController {
6363
public:
64-
nf874xController(const char *portName, const char *nf874xPortName, int numAxes, double movingPollPeriod, double idlePollPeriod);
64+
nf874xController(const char *portName, const char *nf874xPortName, int numAxes, double movingPollPeriod, double idlePollPeriod, double writeOnlyDelay);
6565

6666
/* These are the methods that we override from asynMotorDriver */
6767
asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value);
6868
asynStatus writeFloat64(asynUser *pasynUser, epicsFloat64 value);
69+
asynStatus writeController();
6970
void report(FILE *fp, int level);
7071
nf874xAxis* getAxis(asynUser *pasynUser);
7172
nf874xAxis* getAxis(int axisNo);
@@ -77,6 +78,8 @@ class epicsShareClass nf874xController : public asynMotorController {
7778
int motorUpdateInterval_;
7879
int motorDeadband_;
7980
int motorFollowingError_;
81+
82+
double writeOnlyDelay_;
8083

8184
int hasClosedLoopSupport_; /**< Flag indicating if controller supports closed-loop functionality */
8285

0 commit comments

Comments
 (0)