longout rec: fix behaviour when record is processed for the first time and OOPT is On Change

This commit is contained in:
Joao Paulo Martins
2021-03-10 18:50:42 +01:00
parent 1d85bc7424
commit 6c573b496a
4 changed files with 37 additions and 12 deletions

View File

@@ -81,8 +81,8 @@ rset longoutRSET={
};
epicsExportAddress(rset,longoutRSET);
#define OUT_LINK_UNCHANGED 0
#define OUT_LINK_CHANGED 1
#define DONT_EXEC_OUTPUT 0
#define EXEC_OUTPUT 1
static void checkAlarms(longoutRecord *prec);
static void monitor(longoutRecord *prec);
@@ -124,7 +124,8 @@ static long init_record(struct dbCommon *pcommon, int pass)
prec->alst = prec->val;
prec->lalm = prec->val;
prec->pval = prec->val;
prec->outpvt = OUT_LINK_UNCHANGED;
prec->outpvt = EXEC_OUTPUT;
return 0;
}
@@ -219,8 +220,8 @@ static long special(DBADDR *paddr, int after)
/* Detect an output link re-direction (change) */
if (dbGetFieldIndex(paddr) == longoutRecordOUT) {
if (after)
prec->outpvt = OUT_LINK_CHANGED;
if ((after) && (prec->ooch == menuYesNoYES))
prec->outpvt = EXEC_OUTPUT;
return(0);
}
@@ -453,8 +454,8 @@ static long conditional_write(longoutRecord *prec)
switch (prec->oopt)
{
case longoutOOPT_On_Change:
/* Forces a write op if a change in the OUT field is detected */
if ((prec->ooch == menuYesNoYES) && (prec->outpvt == OUT_LINK_CHANGED)) {
/* Forces a write op if a change in the OUT field is detected OR is first process */
if (prec->outpvt == EXEC_OUTPUT) {
doDevSupWrite = 1;
} else {
/* Only write if value is different from the previous one */
@@ -490,6 +491,6 @@ static long conditional_write(longoutRecord *prec)
status = pdset->write_longout(prec);
prec->pval = prec->val;
prec->outpvt = OUT_LINK_UNCHANGED; /* reset status of OUT link */
prec->outpvt = DONT_EXEC_OUTPUT; /* reset status */
return status;
}

View File

@@ -426,13 +426,13 @@ for more information on simulation mode and its fields.
prompt("Previous Value")
}
field(OUTPVT,DBF_NOACCESS) {
prompt("Output Link Changed Private")
prompt("Output Write Control Private")
special(SPC_NOMOD)
interest(4)
extra("epicsEnum16 outpvt")
}
field(OOCH,DBF_MENU) {
prompt("Output Execute On Change")
prompt("Output Exec. On Change (Opt)")
promptgroup("50 - Output")
interest(1)
menu(menuYesNo)

View File

@@ -222,12 +222,28 @@ static void test_changing_out_field(void){
/* Test if the counter was processed once */
testdbGetFieldEqual("counter_a", DBF_DOUBLE, 1.0);
//number of tests 24
/* reset rec processing counters */
testdbPutFieldOk("counter_a.VAL", DBF_DOUBLE, 0.0);
/* test if record with OOPT == On Change will
write to output at its first process */
testdbPutFieldOk("longout_rec2.VAL", DBF_LONG, 16);
/* Test if the counter was processed once */
testdbGetFieldEqual("counter_a", DBF_DOUBLE, 1.0);
/* write the same value */
testdbPutFieldOk("longout_rec2.VAL", DBF_LONG, 16);
/* Test if the counter was not processed again */
testdbGetFieldEqual("counter_a", DBF_DOUBLE, 1.0);
//number of tests 29
}
MAIN(longoutTest) {
testPlan(6+8+8+8+9+8+24);
testPlan(6+8+8+8+9+8+29);
testdbPrepare();
testdbReadDatabase("recTestIoc.dbd", NULL, NULL);

View File

@@ -15,3 +15,11 @@ record(longout, "longout_rec") {
field(OUT, "counter_a.B PP")
field(PINI, "YES")
}
record(longout, "longout_rec2") {
field(VAL, "16")
field(OUT, "counter_a.B PP")
field(PINI, "NO")
field(OOPT, "On Change")
}