I have a C# application that can control CANoe through its COM interface. I have it working for the most part, except what I'm about to describe below.
From section 2.4 in this document (https://assets.vector.com/cms/content/know-how/_application-notes/AN-AND-1-117_CANoe_CANalyzer_as_a_COM_Server.pdf), I have the following code that gets the current value of an environment variable:
string varName = "Some variable";
CANoe.Environment mEnvironment = (CANoe.Environment)mCANoeApp.Environment;
CANoe.EnvironmentVariable envVar = (CANoe.EnvironmentVariable)mEnvironment.GetVariable(varName);
if (envVar != null)
{
Console.WriteLine($"Current value of {varName} is {envVar.Value}");
}
Every environment variable I put in there returns the value 0.
The weird thing is, let's say I'm working on environment variable VarA:
varName = "VarA";
if (envVar != null)
{
Console.WriteLine($"Current value of {varName} is {envVar.Value}");
envVar.Value = value;
Console.WriteLine($"Value of {varName} now is {envVar.Value}");
}
I pass in the value of 2, I get:
Current value of VarA is 0
Value of VarA now is 0
Then I pass 3, I get:
Current value of VarA is 2
Value of VarA now is 2
Changing value of a variable works fine everytime, I see the change reflected on CANoe panel right away.
But it seems that in the code, the value I get is the previous value? Why is this the case and how can I get the actual current value of an environment variable?
edit: add reference document