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:
- 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;
- I tried using .Configurations method but was neither available:
measurement.Configurations.System.SysVar["Debug.Target_Level_ALL"].Value = 100;
- Same issue if I try to use directly SysVar from the Application object
CANoeApp.SysVar["Debug.Target_Level_ALL"].Value = 100;
- 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