def startCANable(self, port="can0", bitrate=250000): # if port == "auto": # print("Finding serial port") # port = "/dev/CAN" # print("Connecting to serial port '%s'"%port) #self.dev = cantact.CantactDev( port ) # just opens the serial port self.dev = socketcan.SocketCanDev( port ) #print("Setting bitrate to 250k") #self.dev.set_bitrate(250000) # 250,000 = s5 print("Starting CANable") self.dev.start()
from canard import can from canard.hw import socketcan dev = socketcan.SocketCanDev('vcan0') frame = can.Frame(id=0x100) frame.dlc = 8 frame.data=[1,2,3,4,5,6,7,8] while True: dev.send(frame)
from canard import can from canard.hw import socketcan import sys dev = socketcan.SocketCanDev(sys.argv[1]) dev.start() count = 0 while True: count = count + 1 frame = dev.recv() dev.send(frame) print("%d: %s" % (count, str(frame)))
from canard.hw import socketcan # create a SocketCAN usb_port = "/dev/tty.usbmodem146101" dev = socketcan.SocketCanDev(usb_port) # wrap the device in a CanQueue cq = CanQueue(dev) cq.start() # create a request frame req = can.Frame(0x083) req.dlc = 3 req.data = [0x04, 0xE0, 0x80] # send the request cq.send(req) # receive a response, timing out after 10 seconds print(cq.recv(filter=0x083, timeout=10)) cq.stop()
from canard import can from canard.hw import peak from canard.hw import socketcan #dev = peak.PcanDev() dev = socketcan.SocketCanDev("vcan0") dev.start() frame = can.Frame(0) frame.dlc = 8 while True: dev.send(frame)