Wednesday, July 4, 2018

How to Create Periodic and One-shot Timer in EIM

**Note that this also works on EIM @ solaris**


Assuming you want to create a periodic timer that starts with program or EIM loading, add the these codes to the following EIM entry points:

void myEIM::ExtIntfInit( ProgramControl *program, const int head )
{
// ------------------------------------------------------------------
// create periodic timer that fires every x amount of seconds
// ------------------------------------------------------------------
StopTimer(0xFF); // stop this timer first in case there's already one running with this id
unsigned int nSec = 60;
if (!CreateTimer(0xFF, 1, nSec, 0, true))
{
program->writeln(STDOUT, "ERROR! Failed to create periodic timer of %d seconds!\n", nSec);
}
else
{
time_t tTime;
  struct tm * localTime;
time ( &tTime );
  localTime = localtime ( &tTime );
program->writeln(STDOUT, "SUCCESS! Created periodic timer of %d seconds Starting at %s", nSec, asctime (localTime));
}
}

- myEIM is the external interface' name
- timer id for this code is 0xFF; you can set any unique integer you want
- the above code creates a periodic timer that immediately starts its countdown when CreateTimer() call is successful
- the timer is set to periodically trigger every 60 seconds

No comments:

Post a Comment