Search code examples
structcaplcanoe

CANoe CAPL struct initialization


I'm having trouble with declaration and initialization of a struct in Vectors CANoe CAPL. I already know structs from C/C++ but it seems the declaration is a little different in CAPL.

The Vector help function isn't really revealing.

I have a number of CAN IDs (e.g. 0x61A). Every CAN ID is a different number of Signal IDs (e.g. 0xDDF6) assigned. I want to read out cyclic the Signal ID from the CAN IDs and plan to organize this in a convoluted struct.

I already tried out different types of declaration and initialization but every time I get a parse error.

Can you please give me a helping hand for my problem? Any other ideas to organize my values unlike a struct?

Thank you and regards!


Solution

  • From the CAPL documentation:

    Structured types can be declared in CAPL in a similar way to C...

    ... they may only be used in CAPL programs with CANoe from version 7.0 Service Pack 3.

    Example:

    variables
    {
      /* declarating a struct */
      struct MyData {
        int i;
        float f;
      };
    }
    
    on start
    {
      /* defining a struct variable and initiliazing the elements */
      struct MyData data = {
        i = 42,
        f = 1.32
      };
    
      /* accessing the struct elements */
      write("i=%d, f=%f", data.i, data.f);
    }
    

    Output:

    i=42, f=1.320000