SysVar in C# COM with CANoe

81 views Asked by At

I'm trying to communicate in C# with CANoe but I get some errors.

I have this setup to Open and Start (⚡) CANoe APP, and it is working fine:

private CANoe.Application CANoeApp;
private void buttonOpenStartCanoe_Click(object sender, EventArgs e)
{
    try
    {
       CANoeApp = (CANoe.Application)Marshal.GetActiveObject("CANoe.Application");
    }
    catch (COMException)
    {
        CANoeApp = new CANoe.Application();
    }
}

Now I would like to modify and read the values from System Variables, I have tried several options I found on internet bute none of them worked. The namespace "Debug" is where my variable is, and the name of my variable is "Target_Level_ALL".

If someone knows how to modify System Variables in Canoe from C# would be really helpfull because I have already tried very different codes and none is working.

Some of the codes I already tried are below:

  1. Here the problem was the GetSysVar was not availiable in LINBus:
CANoe.Application CANoeApp = (CANoe.Application)Marshal.GetActiveObject("CANoe.Application");
CANoe.Measurement measurement = CANoeApp.Measurement;

CANoe.Bus LINBus = CANoeApp.get_Bus("LIN");
CANoe.Variable sysVar = LINBus.GetSysVar("Debug", "Target_Level_ALL");
sysVar.Value = 100;
  1. I tried using .Configurations method but was neither available:
measurement.Configurations.System.SysVar["Debug.Target_Level_ALL"].Value = 100;
  1. Same issue if I try to use directly SysVar from the Application object
CANoeApp.SysVar["Debug.Target_Level_ALL"].Value = 100;
  1. I tried using canoe.system.system but with same result, not working
Canoe.System.System system = new Canoe.System.System();

system.SetVariableValue("Debug.Target_Level_ALL", 100);

Update: I'm trying with this new code but still not finding the System Variable in the environment of CANoe: (TableSel is my NameSpace and Target_Color is my variable)

CANoe.Environment CANoeEnvironment = CANoe.Environment)CANoeApp.Environment;

CANoe.EnvironmentVariable envVar = (CANoe.EnvironmentVariable)CANoeEnvironment.GetVariable("TableSel.Target_Color");

object value = envVar.Value;

envVar.Value = 3;

Any help will be very well received :) Thanks and have a nice day

1

There are 1 answers

0
Óscar On

little update, I found a document from Vector and I have modified some lines to succeed to read the CAnoe System Variables with the next code lines:

CANoe.System CANoeSystem = (CANoe.System)CANoeApp.System;
CANoe.Namespaces CANoeNamespaces = (CANoe.Namespaces)CANoeSystem.Namespaces;
CANoe.Namespace CANoeNamespaceGeneral = (CANoe.Namespace)CANoeNamespaces["Debug"];
CANoe.Variables CANoeVariablesGeneral = (CANoe.Variables)CANoeNamespaceGeneral.Variables;
CANoe.Variable sysVar = (CANoe.Variable)CANoeVariablesGeneral["Target_Level"];
Console.WriteLine($"Value Target_Level: " + sysVar.Value);

And these ones to edit the system variable:

CANoe.Measurement CANoeMeasurement = (CANoe.Measurement)CANoeApp.Measurement;
CANoe.Namespace CANoeNamespaceDebug = (CANoe.Namespace)CANoeNamespaces["Debug"];
CANoe.Variables CANoeVariablesDebug = (CANoe.Variables)CANoeNamespaceDebug.Variables;
CANoe.Variable sysVarTargetLevel = (CANoe.Variable)CANoeVariablesDebug["Target_Level"];
sysVarTargetLevel.Value = 20;

I hope I could help someone in the future with this information.