title: onTimer not working as intended - Vector CANoe
body: <p>I am using a DEMO version of Vector CANoe 15.1 and for now, I've managed to create two nodes and two panels. I've created some buttons with which I can control some LEDs. The idea is that I want to use timers so that when I press a button, my LED is blinking with a frequency of 1Hz(1sec). I managed to make it work in 3 out of 5 IGNITION States, but not in the other 2, even if I used the same code. Maybe if I show you my code you can understand me better.</p>
  <pre><code>/*@!Encoding:1252*/
  includes
  {
    
  }
  
  variables
  {
    msTimer MainCyclic;
    msTimer TurnLeftCyclic;
    msTimer TurnRightCyclic;
    msTimer HazardCyclic;
    int ignition;
    int hazardWarning;
    int turnlights;
    int flag1;
    int flag2;
    int flag3;
    byte byte0;
  }
  
  on preStart
  {
    flag1=0;
    flag2=0;
    flag3=0;
  }
  
  on start
  {
    setTimer(MainCyclic,50);
  //  setTimer(TurnLeftCyclic,1500);
  //  setTimer(TurnRightCyclic,1500);
  //  setTimer(HazardCyclic,1000);
  }
  
  on timer MainCyclic
  {
    setTimer(MainCyclic,50);
    fMain();
  }
  
  on timer TurnLeftCyclic
  {
    setTimer(TurnLeftCyclic,1500);
    if (@IPC::LeftSignal == 1)
    {
      @IPC::LeftSignal=0;
      @IPC::RightSignal=0;
    }
    else
    {
      @IPC::LeftSignal=1;
      @IPC::RightSignal=0;
    }
  }
  
  on timer TurnRightCyclic
  {
    setTimer(TurnRightCyclic,1500);
    if (@IPC::RightSignal == 1)
    {
      @IPC::RightSignal=0;
      @IPC::LeftSignal=0;
    }
    else
    {
      @IPC::RightSignal=1;
      @IPC::LeftSignal=0;
    }
  }
  
  on timer HazardCyclic
  {
    setTimer(HazardCyclic,1000);
    if (@IPC::LeftSignal == 1 &amp;&amp; @IPC::RightSignal == 1)
    {
      @IPC::LeftSignal=0;
      @IPC::RightSignal=0;
    }
    else if (@IPC::LeftSignal == 0 &amp;&amp; @IPC::RightSignal == 0)
    {
      @IPC::LeftSignal=1;
      @IPC::RightSignal=1;
    }
  }
  
  on message ExternalLights
    {
      byte0=this.byte(0);
      if (byte0 == 0x0)
      {
        turnlights=0;
        hazardWarning=0;
      }
      if (byte0 == 0x1)
      {
        turnlights=1;
        hazardWarning=0;
      }
      if (byte0 == 0x2)
      {
        turnlights=2;
        hazardWarning=0;
      }
      if (byte0 == 0x4)
      {
        turnlights=0;
        hazardWarning=1;
      }
      if (byte0 == 0x5)
      {
        turnlights=1;
        hazardWarning=1;
      }
      if (byte0 == 0x6)
      {
        turnlights=2;
        hazardWarning=1;
      }
    }
  
  on message IGN
    {
      byte0=this.byte(0);
      if (byte0 == 0x0)
        ignition=0;
      if (byte0 == 0x1)
        ignition=1;
      if (byte0 == 0x2)
        ignition=2;
      if (byte0 == 0x3)
        ignition=3;
      if (byte0 == 0x4)
        ignition=4;
    }
  
  void fMain()
  {
    if (ignition == 0 || ignition == 1)
    {
       if (turnlights == 0 || turnlights == 1 || turnlights == 2)
       {
          @IPC::LeftSignal=0;
          @IPC::RightSignal=0;
          flag1=0;
          flag2=0;
          flag3=0;
          cancelTimer(TurnLeftCyclic);
          cancelTimer(TurnRightCyclic);
       }
       if (hazardWarning == 1 &amp;&amp; flag3==0)
       {
          @IPC::LeftSignal=1;
          @IPC::RightSignal=1;
          setTimer(HazardCyclic,1000);
          flag1=0;
          flag2=0;
          flag3=1;
          cancelTimer(TurnLeftCyclic);
          cancelTimer(TurnRightCyclic);
       }
       else
       {
          @IPC::LeftSignal=0;
          @IPC::RightSignal=0;
          flag1=0;
          flag2=0;
          flag3=0;
          cancelTimer(TurnLeftCyclic);
          cancelTimer(TurnRightCyclic);
          cancelTimer(HazardCyclic);
       }
    }
    else if (ignition == 2 || ignition == 3)
    {
      if (hazardWarning == 0) 
      {
        if (turnlights == 0)
        {
          @IPC::LeftSignal = 0;
          @IPC::RightSignal = 0;
          flag1=0;
          flag2=0;
          flag3=0;
          cancelTimer(TurnLeftCyclic);
          cancelTimer(TurnRightCyclic);
          cancelTimer(HazardCyclic);
        }
      
        else if (turnlights == 1 &amp;&amp; flag1==0)
        {
          @IPC::LeftSignal = 1;
          @IPC::RightSignal = 0;
          setTimer(TurnLeftCyclic,1500);
          flag1=1;
          flag2=0;
          flag3=0;
          cancelTimer(TurnRightCyclic);
          cancelTimer(HazardCyclic);
        }
      
        else if (turnlights == 2 &amp;&amp; flag2==0)
        {
          @IPC::LeftSignal = 0;
          @IPC::RightSignal = 1;
          setTimer(TurnRightCyclic,1500);
          flag1=0;
          flag2=1;
          flag3=0;
          cancelTimer(TurnLeftCyclic);
          cancelTimer(HazardCyclic);
        }
      }    
        else if (hazardWarning==1 &amp;&amp; flag3==0)
        {
          @IPC::LeftSignal = 1;
          @IPC::RightSignal = 1;
          setTimer(HazardCyclic,1000);
          flag1=0;
          flag2=0;
          flag3=1;
          cancelTimer(TurnLeftCyclic);
          cancelTimer(TurnRightCyclic);
        }
    }
    else if (ignition == 4 &amp;&amp; flag3==0)
    {
      @IPC::LeftSignal=1;
      @IPC::RightSignal=1;
      setTimer(HazardCyclic,1000);
      flag1=0;
      flag2=0;
      flag3=1;
      cancelTimer(TurnLeftCyclic);
      cancelTimer(TurnRightCyclic);
    }
  }
  </code></pre>
  <p>When ignition=0 or 1, should only work as hazardLights(both left and right blinking in the same time). The problem is that when I press the HazardSwitch, LEDs turn ON, but not blinking. I will attach a photo that contains a graphic. For the first seconds, is how this should work(as it works in ignition=2 or 3 or 4) and after that you can see how it works when ignition=0 or 1.</p>
  <p><a href="https://i.stack.imgur.com/bMY52.png" rel="nofollow noreferrer">My panels + graphic</a></p>