2

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!

4

3 回答 3

3

从 CAPL 文档中:

结构化类型可以在 CAPL 中以类似于 C 的方式声明...

...它们只能用于 CAPL 程序中的 CANoe 版本 7.0 Service Pack 3。

例子:

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);
}

输出:

i=42, f=1.320000
于 2016-08-17T12:13:38.217 回答
2

我在struct访问上有缺陷。试图struct在变量声明例程中初始化参数,而不是在on start例程中。

我的多数据访问的工作代码现在是:

variables
{
  struct Veh_Database
  {
    dword ECU;
    dword ParamID[8][2];
  };
  struct Veh_Database ECU_Info[12];
}

on start
{
  ECU_Info[0].ECU = 0x1A;
  ECU_Info[0].ParamID[0][0] = 0xDD;     
  ECU_Info[0].ParamID[0][1] = 0xF6;
  /* ... */
  ECU_Info[1].ECU = 0x12;
  ECU_Info[1].ParamID[0][0] = 0xDE;
  ECU_Info[1].ParamID[0][1] = 0x9C;
  /* ... */
}

谢谢你的帮助!

于 2016-08-17T17:11:14.357 回答
1

只是为了完整性:也可以struct在变量声明中初始化 a :

variables
{
   struct myStruct
   {
      dword val;
      dword arr[8];
   };
   struct myStruct myInstance = {1, {1,2,3,4,5,6,7,8}};
}

(在 CANoe 10 上测试)

于 2018-12-21T11:44:26.620 回答