2

I want to send some diagnostics request using python. Code:

clr.AddReference('Vector.CANoe.Interop')
clr.AddReference('Vector.Diagnostics')
import CANoe
import Vector.Diagnostics
 
mCANoeApp = CANoe.Application()
mCANoeApp.Open("myPath")
mCANoeMeasurement =  mCANoeApp.Measurement
mCANoeMeasurement.Start()
mCANoeBus = CANoe.Bus(mCANoeApp.get_Bus("Ethernet"))
MNetwork = CANoe.Networks(mCANoeApp.get_Networks(11))
net = CANoe.Network(MNetwork.get_Item(1))
devices = CANoe.Devices(net.Devices)
device = CANoe.Device(devices.get_Item("myDevice"))

I also attached the following image with the COM Hierarchy from CANoe. COM Object Hierarchy Where it says that device should have a object Diagnostic. But on my side device isn`t having the Diagnostic object, only: ApplicationSocket, AudioInterface and MostDisassambler. Because of this I can not access Diagnostic object in order to create a request.

    diag_ob = device.Diagnostic             #isnt creating a Diag object
    diag_ob.CreateRequest("Default_Start")  #Error

device details

CANoe.Diagnostic failing

device.Diagnostic

Because i cant get access to the Diagnostic object i tried to use directly the Vector.Diagnostics which is seem is not recognize the measurement and im trying to understand how can I link them.

When I'm trying to use the Vector.Diagnostics.Application.GetEcu() I'm receiving a NoneType and My assumption is that GetEcu() method is not seeing the CANoe opened.

Do you have any idea how can a link them ?

Alex
  • 21
  • 4
  • Could you please share your code and some details about your CANoe configuration? – MSpiller Dec 17 '20 at 12:55
  • Hello, I edited my post and paste the code inside the initial post. For a better visibility, I have CANoe 11 64 bit and im using an ETH simulation based on an arxml. – Alex Dec 21 '20 at 21:54
  • Not sure, what you are doing there. _Vector.Diagnostics.dll_ is meant for doing diagnostics *within* CANoe, e.g. when writing simulation or tests in C#. Using the COM-Interface should be done using COM within python, e.g using _pywin32_ and not IronPython. Apart from that, can you confirm that your device is called _myDevice_ in CANoe's Diagnostic-Configuration Dialog? Maybe post a screenshot of that dialog. – MSpiller Dec 22 '20 at 09:17
  • Isnt called myDevice, in the actual code i have the real name. Everything is good but i cant Find the Object called Diagnositcs even when Im looking inside Vector.Interop.dll, Diagnostic class isnt there. But this Vector.Diagnostic.dll how can see that my CANoe is opened ? – Alex Dec 22 '20 at 12:53
  • I also added a new photo in the link named "device details" there you can see that the Diagnostic isnt a class. – Alex Dec 22 '20 at 14:33
  • What do you mean by _Diagnostic isn’t a class_? It is a COM object. In your Screenshot you see that `device` is of the same type. As it should be. – MSpiller Dec 22 '20 at 14:55
  • Vector.Diagnostics.dll is not related to the COM interface at all – MSpiller Dec 22 '20 at 14:58
  • Yes, it is a COM Object but in order to access the methods, i need to create an instance of CANoe.Diagnostic which is giving attribute error. Because of this i cant use any method of diagnostic class like CreateRequest or others methods and because of this i tried to use the Vector.Diagnostics. If i Could make it work with Interop is ok – Alex Dec 22 '20 at 17:45
  • This is the error when im trying to create a diagnostic request: AttributeError: '__ComObject' object has no attribute 'CreateRequest' – Alex Dec 22 '20 at 18:08

1 Answers1

1

Few things to note at the beginning:

  1. You don't have to mention the add reference lines since those dlls are registered when installing CANoe.
  2. Most important is "Vector.Diagnostics" is not to be referenced as this is something which is used by CANoe.
  3. What you are trying to use is the COM interface and not the diagnostic interface.

Check out the following code for sending a default session request:

from win32com.client import *
import time
mainApp = DispatchEx('CANoe.Application')
print(mainApp.Networks("CAN network 1").Devices("Example_ECU").Name) # To make sure you are referencing the correct ECU
diagreq = mainApp.Networks("CAN network 1").Devices("Example_ECU").Diagnostic.CreateRequest("DefaultSession_Start")
time.sleep(1)
diagreq.Send()

Try this out and post any errors which you see in the console. The measurement is to be started before executing the above code.

Shyam
  • 649
  • 1
  • 5
  • 20
  • Hello, This solution is working, but i wanted a way somehow to use the Diagnostics.dll. Why? Because i want to get the output of an executed command and more freedom. Now i have to following problem, how can i get the Response from diagnostics job in a string format? This is my code: `while diagreq.Pending: time.sleep(0.5) print(diagreq.Responses.Count) for x in range(diagreq.Responses.Count): diagResp = diagreq.Responses(x+1) print(diagResp.Stream)` – Alex Jan 29 '21 at 14:02
  • `diagResp.Stream` is returning a memoryview, when im trying to convert it to string isnt working. This is the way im trying to convert it: `diagResp.Stream.tobytes().decode("utf-16")` – Alex Jan 29 '21 at 14:09