Esempio n. 1
0
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)
Esempio n. 2
0
import sys

from pyvit.proto.obdii import ObdInterface
from pyvit.hw.cantact import CantactDev
from pyvit.dispatch import Dispatcher

if len(sys.argv) != 2 and len(sys.argv) != 4:
    print("usage: %s CANtact_device [tx_arb_id] [rx_arb_id]" %
          sys.argv[0])
    sys.exit(1)

# set up a CANtact device
dev = CantactDev(sys.argv[1])
dev.set_bitrate(500000)

# create our dispatcher and OBD interface
disp = Dispatcher(dev)

# if we were given tx and rx ids, set them, otherwise use defaults
if len(sys.argv) > 4:
    tx_arb_id = int(sys.argv[4], 0)
    rx_arb_id = int(sys.argv[5], 0)
else:
    # functional address
    tx_arb_id = 0x7DF
    # physical response ID of ECM ECU, responses from other ECUs will be ignored
    rx_arb_id = 0x7E8

obd = ObdInterface(disp, tx_arb_id, rx_arb_id)

# setting debug to true will print all frames sent and received
Esempio n. 3
0
File: uds.py Progetto: reuted/pyvit
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)
Esempio n. 4
0
"""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