Skip to content

Instantly share code, notes, and snippets.

@msacchetin
Last active May 13, 2020 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msacchetin/dffd76afdd7276f49ffb6e9f4716658e to your computer and use it in GitHub Desktop.
Save msacchetin/dffd76afdd7276f49ffb6e9f4716658e to your computer and use it in GitHub Desktop.
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