4

What is the difference between system variable and environment variables in CAPL script with example?

Sachin Bharambe
  • 263
  • 3
  • 4
  • 16

2 Answers2

8

Environment variables have to be used as input/output of a node, mostly they belongs to specified ECU. They are defined by following system-parameters:

  • access for specified ECU's (r, w, rw, unrestricted => each ECU can access)
  • datatype: int (32bit), string (ascii), float, data + data length
  • unit/dimension
  • initial value, min, max values
  • value tables can be defined (probably only for int datatype?)

You can directly access environment variables by using @:

@EnvLightState

but you can't do this only for int or float. Any datatype can be accessed by using this two simple functions:

CAPL Function Overview » General » getValue

CAPL Function Overview » General » putValue

System variables are widely used by CANoe components, many of them are generated automatically and can't be edited. They belongs to a defined namespace. The values of sysvars are available only while measurement is running, so you don't want to use them for e.g. UI-panels.

  • datatype: int (32, 64), double, string, data, array of int, array of double, pre-defined structs (user defined not allowed)
  • initial value can be defined
  • value tables can be defined for int datatype

you can "directly" access sysvar by using

 @Namespace1::ParameterArray[2];
 @Namespace1::Parameter2;

however, this ways it's not possible to access the whole array or string (data is not mentioned in help, but probably same thing). You also can't access any of sysvar defined in XML-Test module by using @, read about this in help:

Direct Access to Values from System Variables

There are CAPL-Functions defined for System variables (SysGet..., SysSet..., SysDefine..., SysUndefine... and some other) take look into help:

CAPL Function Overview » System Variables CAPL Functions

here an example from XML test function Set where both is used, you can find this example in CANoe help

<!-- Context of this test function is e.g. a testcase, other contexts are possible -->    
<set title="Set">
    <cansignal name="CrashDetected"> 0 </cansignal>
    <linsignal name="MotorControl"> 0 </linsignal>
    <flexraysignal name="BreakLight"> 0 </flexraysignal>
    <envvar name="EnvAccelerate"> 0 </envvar>
    <sysvar name="SysFrontLight_Right" namespace="Lights">0</sysvar>
</set>
<wait time="200" title="Swing in time for system" />

please extend if you know/find any other differences

Community
  • 1
  • 1
An Other
  • 331
  • 1
  • 7
  • Thank you! I spent quite a lot of time looking at how to set the value of a sysvar in the section of an XML Test Module and I couldn't find this in the documentation. – Monica Voinescu Feb 23 '21 at 18:50
0

In my own experience of creating CANoe simulations there is a limitation of the 'On EnvVar' callback which is if the same value is applied to the Environment Variable, the code within will not execute, e.g.

variables
{
  mstimer tLoop;
  int i;
}

on start
{
  i = 0;
  setTimerCyclic(tLoop, 1000);
}

on envVar Env_Number 
{
  write("Env_Number is %d", @this); 
}

on sysvar_update Sys_Number 
{
  write("Sys_Number is %d", @this);
}

on timer tLoop
{
  write("%d", ++i);
  @Env_Number = 0x1;
  @sysvar::Sys_Number = 0x2;
}

in this example the value of the Environment Variable is written once as this is the only time that the variable value is changed.

CAPL / .NET 1
CAPL / .NET Env_Number is 1
CAPL / .NET Sys_Number is 2
CAPL / .NET 2
CAPL / .NET Sys_Number is 2
CAPL / .NET 3
CAPL / .NET Sys_Number is 2
CAPL / .NET 4
CAPL / .NET Sys_Number is 2
CAPL / .NET 5
CAPL / .NET Sys_Number is 2
CAPL / .NET 6
CAPL / .NET Sys_Number is 2
CAPL / .NET 7
CAPL / .NET Sys_Number is 2
CAPL / .NET 8
CAPL / .NET Sys_Number is 2
CAPL / .NET 9
CAPL / .NET Sys_Number is 2
CAPL / .NET 10
CAPL / .NET Sys_Number is 2

Using the 'on sysvar_update' the variable value is written even if the same value is applied. If you require the same behavior as the 'on envvar' but using a System Variable, then use 'on sysvar' instead.

SteveOll
  • 79
  • 1
  • 4