Changes between Version 2 and Version 3 of BlueCANReader
- Timestamp:
- 05/31/13 03:08:29 (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
BlueCANReader
v2 v3 17 17 18 18 19 19 20 {{{ 20 def parseLine(line): 21 msgLength = line[0] & 0b1111 22 isExtended = (line[0] >> 4) & 1 23 isRTR = (line[0] >> 5) & 1 24 payload = line[1:msgLength+1] 25 id = line[-4:] 26 id = id[0] + (id[1] << 8) + (id[2] << 16) + (id[3] << 24) 27 #print msgLength, isExtended, isRTR, [hex(x) for x in payload], hex(id) 28 return id, payload 21 to send a CAN message: 29 22 23 3Ah,3Dh,(X), ID0,ID1,ID2,ID3, byte0,byte1,byte2,byte3,byte4,byte5,byte6,byte7 (number of bytes depends on (X) value) 30 24 25 (X) is bitmapped value: 26 i.e. 00111000b 27 bit3 bit2 bit1 bit0 defines number of DATA bytes to send on CAN BUS 1000b will send 8 bytes, (when CANex module receives (X) with last 4 bits equal 1000b, it will expect 4 bytes for ID + 8 bytes for DATA bytes to send) 28 bit4 is CAN EXTENSION bit normaly =1 for NMEA 29 bit5 is RTR mark, normaly =0 30 bit6 and bit7 MUST BE 0 !!!!!!!! 31 31 32 while True:33 s = ser.read()34 if s == ";":35 buffer = buffer[1:]36 print [x for x in buffer]37 print buffer38 id,strData = parseLine(buffer)39 buffer = bytearray()40 # strID, strData = parseLine(buffer)41 # id = int(strID, base=16)42 priority, source_id, pgn, destination_id = parseCanID(id)43 #44 print strformat.format(i, buffer, id, (priority, source_id, pgn, destination_id)), strData, msgdict.get(pgn)45 # i+=146 # buffer = ''47 else:48 buffer.append(ord(s))49 32 }}} 50 33