Last active
May 13, 2020 20:22
-
-
Save msacchetin/dffd76afdd7276f49ffb6e9f4716658e to your computer and use it in GitHub Desktop.
Python code analogous to command cansend can0 7DF#0209020000000000
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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