def getDTC(llcf, tp, kwp): # Read Failure memory dtc1 = llcf.PAYLOAD((0x00, 0x04, 0x18, 0x02, 0xFF, 0x00)) tp.write1(dtc1, "can0") for i in range(100): time.sleep(0.05) recv_frame = tp.read() if recv_frame == -1: continue else: #print "Diagnostic response = ", map(hex,recv_frame) resp = kwp.parseKWPData(recv_frame) if resp.getSID() == 0x58: pl = resp.getPayload() if pl is not None: if (pl[0] is not 0x7F): dtcs = kwp.parseDTCData(pl) for dtc in dtcs: print dtc elif pl[0] is 0x7F: print "Negative response received." else: print "No KWP2000 payload received." break else: continue
def getMWB07(llcf, tp, kwp): # Read ucMedia SW version mwb7 = llcf.PAYLOAD((0x00, 0x02, 0x21, 0x07)) tp.write1(mwb7, "can0") for i in range(100): time.sleep(0.05) recv_frame = tp.read() if recv_frame == -1: continue else: #print "Diagnostic response = ", recv_frame resp = kwp.parseKWPData(recv_frame) if resp.getSID() == 0x61: pl = resp.getPayload() if pl is not None and (pl[0] is not 0x7F): mwbs = kwp.parseMWBData(pl[1:]) for mwb in mwbs: print "Measurement block = ", mwb break else: continue
tuple(frame.getFrame()), "can0") #time.sleep(0.015) res2 = bcm.read() finally: bcm.close() print "written character = ", res print "read character = ", res2 if res2 == 0: print "No TX or RX id received" else: tx_id = 0x4EC #res[0] rx_id = 0x300 #res[1] tp = llcf.SOCKET("PF_CAN", "SOCK_SEQPACKET", "CAN_TP20") tp.setblock(1) try: tp.connect("can0", (tx_id, rx_id)) except: print "Got exception during TP startup" tp.close() raise p = llcf.PAYLOAD() p = llcf.PAYLOAD((0x00, 0x02, 0x21, 0x01)) # Write some test data over TP 2.0 tp.write1(p, "can0") answer = tp.read() # if answer[0] == 0xb3 # print " acknolwdged" #recvdData = tp.read() tp.close()
print " llcf not found at all " try: reload(time) except: try: print('time reload unssucces') import time except: print " llcf not found at all " # raw = llcf.SOCKET("PF_CAN", "SOCK_RAW", "CAN_RAW") # frame = llcf.FRAME(0x200, (0x54, 0xc0, 0x00, 0x10, 0x00, 0x03, 0x01 )) # raw.send(frame, "can0") raw = llcf.SOCKET("PF_CAN", "SOCK_RAW", "CAN_RAW") frame = llcf.FRAME(0x200, (0x54, 0xc0, 0x00, 0x10, 0x00, 0x03, 0x01)) raw.send(frame, "can0") time.sleep(0.015) raw.close() a = llcf.SOCKET() p = llcf.PAYLOAD() try: a.connect("can0", (0x4ec, 0x300)) except: a.close else: a.write1(p, "can0") print "closing" a.close()