1

I am trying to create a Diagnostic Service Request specifying only a PDU, and print back the corresponding qualifier of that service using the ToString function of the Request Class, on C# in Visual Studio. Both the Ecu class and the Request class are members of the Vector.Diagnostics assembly.

But I am confused about how one is supposed to use these classes.

Is it possible to create an object of the Ecu class,and create a new request with that object? I tried some code to do that, but it's simply showing errors or throwing a "NullReferenceException" during run-time.

        Ecu New_Ecu = Vector.Diagnostics.Application.GetEcu("ECU6");
        Request Sample = new New_Ecu.Request();
        Sample = New_Ecu.CreateRequest(new byte[] { 0x10, 0x03 });
        string Result = Sample.ToString();
        Console.WriteLine(Result); 

The errors are saying that Request class doesn't have a constructor. Why not? It's a class,ergo it must have a default constructor.

And if If I delete the second line, and make modifications to the third line as follows:

Request Sample = New_Ecu.CreateRequest(new byte[] { 0x10, 0x03 });

It's happy while I'm typing, but throws the above mentioned exception during run-time.

What is happening, and why?

  • `Request` does not have a default constructor. How should such an object look like and behave? A default constructed and thus empty request simply makes no sense. Therefore no default constructor is provided. You say that `New_Ecu.CreateRequest(new byte[] { 0x10, 0x03 });` throws a `NullReferenceException`? This means that most likely `New_Ecu` is null. How does you diagnostic configuration in CANoe look like? Did you try to inspect `New_Ecu` in the debugger? – MSpiller Mar 06 '19 at 15:54
  • Okay,so I directly created a new request through the New_Ecu, not trying to create an object for the Request class. It still threw the same NullReferenceException, so I went and checked out the Configuration in CANoe. That's when I found out that the qualifier for the ECU was not the just the title of that specific Node, but was instead mentioned specifically in the Diagnostics/ISO TP Configuration Panel. So, that was the end of the mystery. – Gamma-ray-burst Mar 08 '19 at 08:31
  • Please consider marking this question as answered if you have received the solution. – Shyam Apr 09 '21 at 07:03

0 Answers0