CAPL Script

IsTimerActive

This reference collection includes Vector documentation reproduced with permission. Snippets may require configuration-specific symbols and are not all standalone programs. Sources and validation limits.

Syntax and result

int isTimerActive(timer t);
int isTimerActive(msTimer t);

Returns 1 while the timer is active and 0 otherwise. For a one-shot setTimer call, the pending interval is between scheduling and entry into its on timer procedure. The reference states that the query returns 0 inside that event procedure before a new scheduling call.

Observe the state transitions

variables
{
  msTimer tick;
}
on key 's'
{
  write("Before scheduling: %d", isTimerActive(tick));
  setTimer(tick, 200);
  write("After scheduling: %d", isTimerActive(tick));
}
on timer tick
{
  write("Inside one-shot handler: %d", isTimerActive(tick));
}
on key 'x'
{
  cancelTimer(tick);
  write("After cancellation: %d", isTimerActive(tick));
}

On a fresh run, press s once: the expected states to inspect are 0 before scheduling, 1 afterward and 0 when the handler begins. These are expectations from the API contract, not captured output. Press x during the pending delay to inspect cancellation.

Do not use a momentary zero inside a handler to infer that your entire periodic task was intentionally stopped. Keep an explicit task-state flag when start/stop behavior matters. See cancelTimer for that pattern and setTimer for units.

Source and validation

API signatures and behavior follow the authorized Vector reference. The explanations and inspection examples are site guidance, not recorded CANoe test results. Check the installed help for your tool version and node type. See sources and validation limits.