Search code examples
can-buscapl

CAPL - (this) keyword


I am new to CAPL , and I was wondering how this word works in my example ?

on errorFrame
{
   int ReportFirstDetecetdError_Ch1 = 0; 
   if ( this.msgChannel == 1 )
   {
      AmountOfDetected_CAN_Error_Ch1++;
      
      if ( ReportFirstDetecetdError_Ch1 == 0 )
      {   
         AST_SetReportStep( AST_STEP_WARNING, "CAN 1: First CAN error detected! Only the first will be in the test report." );
         ReportFirstDetecetdError_Ch1 = 1;
      }
   }
}

Solution

  • "this" here signifies message for which event is triggered.

    CAPL is event based. This code will be executed only if errorFrame is received. And when error frame is received, you can check if it is received from CAN1 or CAN2 or CANn.

    You can read other parameters of messages using "this" like, Read ID (this.id), Data (this.byte(x))