def Start(self, callback):
        # self._canusb = lawicel_canusb.opencan(self._serialPort, self._speed)
        self._canusb = cantact.CantactDev(self._serialPort)
        self._canusb.set_bitrate(1000000)
        self._canusb.start()

        if not self._worker:
            self._worker = WorkerThread(self._canusb, self._lock, callback)
            self._worker.start()
Beispiel #2
0
"""Connect to CANable; print and echo any received frames"""
from canard import can
from canard.hw import cantact
import time

dev = cantact.CantactDev("/dev/ttyACM1") # Connect to CANable on this /dev/ttyACM#
dev.set_bitrate(500000) # Set the bitrate to a 0.5Mb/s
dev.start() # Go on the bus
count = 0
dev_id = 0x1871

while True:
    count += 1
    frame = can.Frame(dev_id, dlc=8, data = [0x00]*8, is_extended_id=True)
    dev.send(frame) # Echo the CAN frame back out on the bus
    print(str(frame))
    time.sleep(1)
Beispiel #3
0
from canard import can
from canard.hw import cantact
import sys
import argparse
import time
import re

parser = argparse.ArgumentParser()
parser.add_argument("-f", "--file", help="Input file.")
parser.add_argument("-s", "--serial", help="Serial port.")
parser.add_argument("-b", "--baud", help="Baud rate.", default=250000)
args = parser.parse_args()
print(f"Reading file '{args.file}', sending to {args.serial} @ {args.baud}")

dev = cantact.CantactDev(args.serial)
dev.set_bitrate(250000)
dev.start()
with open(args.file, "r") as f:
    count = 1
    for line in f:
        linennl = line.rstrip()
        lineparts = linennl.split(' ')
        lineid = int(re.search(r'<(.*)>', lineparts[0]).group(1), 0)
        linedata = [int(i, 16) for i in lineparts[2:]]
        print(f"{count}>{linennl}")
        frame = can.Frame(id=lineid,
                          dlc=len(linedata),
                          data=linedata,
                          is_extended_id=True)
        dev.send(frame)
        print("%d: %s" % (count, str(frame)))
from canard import can
from canard.hw import cantact

dev = cantact.CantactDev("./logfile.txt")

#dev.start()
#while True:
#      print(dev.recv())
Beispiel #5
0
from canard import can
from canard.hw import cantact

# CANable 1 (HS-CAN): /dev/tty.usbmodem146201
# CANable 2 (MS-CAN):

dev = cantact.CantactDev(
    "/dev/tty.usbmodem146201")  # Connect to CANable that enumerated as ttyACM0
dev.set_bitrate(500000)  # Set the bitrate to a 500kbps (for HS-CAN)
dev.start()  # Go on the bus
count = 0

while True:
    print(count)
    count += 1
    frame = dev.recv()  # Receive a CAN frame
    dev.send(frame)  # Echo the CAN frame back out on the bus
    print(str(count) + ": " + str(frame))  # Print out the received frame
Beispiel #6
0
from canard import can
from canard.hw import cantact

dev = cantact.CantactDev(
    "/dev/ttyACM0")  # Connect to CANable that enumerated as ttyACM0
dev.set_bitrate(500000)  # Set the bitrate to a 0.5 Mb/s
dev.start()  # Go on the bus
count = 0

while True:
    count += 1
    frame = dev.recv()  # Receive a CAN frame
    print(str(count) + ": " + str(frame))  # Print out the received frame
Beispiel #7
0
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
For a full copy of the license please vist this website: http://creativecommons.org/licenses/by-nc-sa/4.0/

"""

from canard import can
from canard.hw import cantact
import sys

#Serial Configuration
SERIAL_PORT = '/dev/cu.usbmodem1421'
CAN_BAUDRATE = 500000

#Setup CANtact Interface
dev = cantact.CantactDev(SERIAL_PORT)
dev.set_bitrate(CAN_BAUDRATE)
print("CANtact running on " + SERIAL_PORT + "...")

#Get file name from user and save to variable
if sys.version_info[0] > 2:
    fileName = input("Please Enter a file Name: ")
else:
    fileName = raw_input("Please Enter a file Name: ")

#File Configs
fileFormat = '.txt'

#Begin Program
file = open(fileName + fileFormat, 'r')  #Open the data file
data = file.readlines()  #Load the entire file into memory
Beispiel #8
0
from canard import can
from canard.hw import cantact
from canard.utils.queue import CanQueue
import time
import sys

dev = cantact.CantactDev(sys.argv[1])
dev.set_bitrate(125000)
cq = CanQueue(dev)

cq.start()

print cq.recv()

req = can.Frame(0x6A5)
req.dlc = 8
req.data = [0x10,0xFF, 0xFF]

cq.send(req)

print cq.recv(filter=0x625, timeout=10)

cq.stop()

#dev.stop()
#dev.ser.write('S0\r')
#dev.start()

#while True:
#    frame = can.Frame(0x10)
#    frame.dlc=3
Beispiel #9
0
def get_door_status():
    #CANable USB port. Find by calling  ls /dev/tty* in the mac terminal
    usb_port = "/dev/tty.usbmodem146201"

    # init the Cantact with the usb port
    dev = cantact.CantactDev(usb_port)
    # set the bitrate to 500kbps
    dev.set_bitrate(500000)
    # wrap in a CanQueue
    cq = CanQueue(dev)
    # start scanning
    cq.start()
    # receive the packets, and filter for only the 947 (hex: 0x3B3) (door sensor) and print to console
    frame = cq.recv(filter=0x3B3, timeout=1)
    # stop searching
    cq.stop()

    # All of my analysis was done on the hexadecimal format, so we need to convert the ascii into hex for the algorithm
    byte_1 = format(frame.data[0], '02x')
    byte_8 = format(frame.data[7], '02x')

    # print statements just to verify what the 1st and 8th bytes are (the only bytes that will ever change)
    print("Byte 1:")
    print(byte_1)
    print("Byte 8:")
    print(byte_8)
    print("===============")

    # set up the door statuses (default = False)
    trunk_ajar = False
    driver_ajar = False
    passenger_ajar = False
    hood_ajar = False

    # Algorithm as described in my notebook under Methodology > Door Ajar Status Notes

    # Check the second digit of the first byte
    if byte_1[1] == "1":
        trunk_ajar = True

    # Check the first digit of the last byte
    if byte_8[0] == "0":
        driver_ajar = False
        passenger_ajar = False
    if byte_8[0] == "1":
        passenger_ajar = True
    if byte_8[0] == "2":
        driver_ajar = True
    if byte_8[0] == "3":
        driver_ajar = True
        passenger_ajar = True

    # Check the second digit of the last byte
    if byte_8[1] == "a":
        hood_ajar = True

    # print out the statuses to console (as testing)
    print("Trunk Ajar? " + str(trunk_ajar))
    print("Driver Door Ajar? " + str(driver_ajar))
    print("Passenger Door Ajar? " + str(passenger_ajar))
    print("Hood Ajar? " + str(hood_ajar))