Skip to content

Instantly share code, notes, and snippets.

@msacchetin
Last active May 13, 2020
Embed
What would you like to do?
Python code analogous to command cansend can0 7DF#0209020000000000
import can
bus = can.interface.Bus(bustype='socketcan', channel='can0', bitrate=500000)
service_int = int("9", 16)
pid_int = int("2", 16)
msg = can.Message(arbitration_id=0x7DF, data=[2, service_int, pid_int, 0, 0, 0, 0, 0], is_extended_id=False)
try:
bus.send(msg)
response = bus.recv(timeout=2)
print(response)
except can.CanError:
print("CAN error")
finally:
bus.shutdown()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment