import sys from pyvit.proto.uds import UdsInterface from pyvit.hw.cantact import CantactDev d = CantactDev(sys.argv[1]) d.set_bitrate(500000) d.start() p = UdsInterface(d) # DiagnosticSessionControl Discovery for i in range(0x700, 0x800): # attempt to enter diagnostic session resp = p.uds_request(i, 0x10, [0x1], timeout=0.2) if resp is not None: print("ECU response for ID 0x%X!" % i)
from pyvit import can from pyvit.hw.cantact import CantactDev import time dev = CantactDev("/dev/ttyUSB1") dev.set_bitrate(50000) dev.start() def send_frame(id, data): frame = can.Frame(id) frame.data = data dev.send(frame) d = list(bytearray("unlock\0\0")) id = 0x332 while True: time.sleep(.1) send_frame(id, d) while dev.available(): f = dev.recv() if f is not None: print(f)
"""Connect to CANable; print and echo any received frames""" from pyvit import can from pyvit.hw.cantact import CantactDev from time import time from mpu6050 import mpu6050 import sys, os #initialize CAN device try: dev = CantactDev("/dev/ttyACM0") # Connect to CANable except Exception: print("CAN device not found") exit() dev.set_bitrate(500000) # Set the bitrate to a 500k baud dev.start() # Go on the bus #initialize accel/gyro try: sensor = mpu6050(0x68) except Exception: print("MPU6050 accel/gyro not found") exit() file = open('./logs/log' + str(len(os.listdir('./logs'))), 'w+') # Create log file to write to timestamp = time() try: count = 0