How to use python-can to connect to the vector virtual bus. I ran XCPsim(the software provided by Vector to simulate XCP slave) on my computer and wanted to use a python script to connect to the XCPsim bus and use pyxcp, but I don’t know how to connect. so, i need some help, thanks
how to connect to the vector virtual(python-can connect XCPsim)
how to use pyxcp? The documentation for this library ignores tutorials https://pyxcp.readthedocs.io/en/latest/
pyxcp:https://github.com/christoph2/pyxcp python-can: https://github.com/hardbyte/python-can
this is my code:
from pya2l.parser import A2lParser as Parser
import pyxcp
import can
with open("XCPSIM.a2l", "r") as f:
a2l_string = f.read()
# print('a2l_string', a2l_string)
with Parser() as p:
# get the AST.
ast = p.tree_from_a2l(a2l_string.encode())
# print('ast', ast)
measurements = []
for measurement in ast.PROJECT.MODULE[0].MEASUREMENT:
measurements.append(measurement)
print('measurements', len(measurements))
with can.interface.Bus(channel=0, bustype='vector', bitrate=500000) as can_bus:
message = can.Message(arbitration_id=0x1, data=[255, 0, 0, 0, 0, 0, 0, 0], is_extended_id=False, is_fd=False)
can_bus.send(message)
print('message', message)
# # master = pyxcp.master('CAN', 1, 2)
ok.i can answer my question.
Download the Vecter Hardware Configuration
Edit your python code, add the app_name
can.interface.Bus(bustype='vector', app_name='my_app', channel=0)
Configration the "Vecter Hardware Configuration"
Add 'my_app' application with 'Application Channels Configuration'
Set CAN Channels with 'my_app',set Virtual CAN Bus and Channel
switch to run status and deploy ('Vecter Hardware Configuration')
run XCPsim.exe and run your python code