class UdsInterface(IsoTpProtocol): def __init__(self, can_dev): self.cq = CanQueue(can_dev) self.cq.start() def uds_request(self, ecu_id, service, payload, timeout=2): msg = IsoTpMessage(ecu_id) # first byte is service ID, rest of message is payload msg.data = [service] + payload # length is payload length plus 1 for service ID byte msg.length = len(payload) + 1 # generate a request request = self.generate_frames(msg) # send the request for f in request: self.cq.send(f) # get a response message with the request ID + 20 start_ts = time.time() result = None while result == None: if time.time() - start_ts > timeout: return None response = self.cq.recv() if response and response.id == ecu_id + 0x20: result = self.parse_frame(response) return result
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 # frame.data = [1,2,3] # dev.send(frame) # time.sleep(0.5)