Search code examples
can-buscaplcanoecanalyzer

CAPL CANalyzer getting frames every 10ms


I am new to CAPL and CANalyzer,I am trying to read from CAN and I want every frame to be read every 10ms but I can't find any solution.

I tried with a timer but as I understood, every event has to finish before starting another so the timer doesn't help considering that the frames are read from one function.

I also tried to divide it in different functions but I couldn't get them to send the data from one to another.

variables {...}

on message CAN1.*
{
 setTimer(myTimer,2000);
 //for() reading from CAN1

}

on timer myTimer
{
 tile.FDF=1;
 tile.dataLength=64;
 tile.can=2; 

 while(tileData<endOfData)
 {
  //for() reading every byte from the tile
 }
 
 output(tile);
}

I need to read every frame row from the tile every 10ms, right now that happens every few nanoseconds.


Solution

  • From your question, it is not clear, what you want to process and how, nor what a tile is, so I can just give you pseudo code here. Change CAN1.* in the message handler to whatever message you are interested in.

    What about storing the timestamp when you last processed the data and only process again, when 10 ms have passed?

    E.g.

    variables {
      dword tsLastProcessed;
    }
    
    on message CAN1.*
    {
      // timeNow is incremented every 10 us
      if((timeNow() - tsLastProcessed) < 1000) { 
        return;
      }
      /* else */
    
      tsLastProcessed = timeNow();
    
      <process data>
    }