0
votes

I am using CANoe tool for CAPL scripting.

And I have referred this link for help given by Vector: https://vector.com/portal/medien/cmc/application_notes/AN-IND-1-011_Using_CANoe_NET_API.pdf

Now I am facing issue at step or section: 2.7 Calling CAPL Functions. There are no syntax errors, but I think, the code is not able to retrieve the function from the CAPL file as it is giving this error when I pass values to the function from C# code.

Error statement:

An exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in System.Core.dll but was not handled in user code

Additional information: Cannot convert null to 'int' because it is a non-nullable value type

If there is a handler for this exception, the program may be safely continued.

Can some one tell me what exactly the issue is?

Code:

public void Init()
{
 CANoe.Application myApp;
 myApp = new CANoe.Application();
 CANoe.Measurement mymeasure;
 mymeasure = (CANoe.Measurement)myApp.Measurement;
 myApp.Open(@"D:\Planter CAPl\CANoeCAPLdll.cfg", true, true);
 CANoe.OpenConfigurationResult ocresult = myApp.Configuration.OpenConfigurationResult;

 if (ocresult.result == 0)
   {
     CANoe.CAPL CANoeCAPL = (CANoe.CAPL)myApp.CAPL;
     CANoeCAPL.Compile(null);
     CANoe.CAPLFunction mydata;
     mydata = (CANoe.CAPLFunction)CANoeCAPL.GetFunction("Data");//CANoeCAPL.GetFunction("DataShare");

      mymeasure.Start();
      Thread.Sleep(2000);
      int Result = (int)mydata.Call(10,20,30);// Exeception error is coming at this point*

       if (mymeasure.Running)
         {
           mymeasure.Stop();
         }
   }
}
1

1 Answers

0
votes

I think the error message is relatively self-explanatory, you're trying to convert a null value to an int type. Since int is a value type, it cannot be null, therefore, you get an exception.

In the line

int Result = (int)mydata.Call(10,20,30);

The value returned by mydata.Call(10,20,30) is null. You should check if that value is null and do something.

var myDataResult = mydata.Call(10,20,30);
if(myDataResult == null)
   // do something
else
   int result = (int)myDataResult;

As to why the call to the Call method returns null, you'll have to check the API you're using.