def get_im218_device_id(canm=None): device_id = "" us = uds_server.UdsServer(can_bus=canm.can_bus) try: iap_info = Convert.bytes_to_hexstr(us.send("22F181"))[6:] bsp_info = Convert.bytes_to_hexstr(us.send("22FD05"))[6:] if len(iap_info) > 0: device_id += iap_info if len(bsp_info) > 0: device_id += bsp_info except Exception as e: print(e) us.close() return device_id
def get_serial_code(meter="IC216", canm=None): serial_code = b'' if meter == Constant.IC_216: send_frame_id = 0x660 recv_frame_id = 0x7E0 address_data = 'F60000000027FFE0' length = 'F507000000000000' elif meter == Constant.IC_218: send_frame_id = 0x660 recv_frame_id = 0x7E0 address_data = 'F6000000E0FF0700' length = 'F507000000000000' else: send_frame_id = 0x661 recv_frame_id = 0x7E1 address_data = 'F6000000E0FF0700' length = 'F507000000000000' # 创建链接 while True: canm.send_can(can_id=send_frame_id, can_data='FF00000000000000') time.sleep(0.2) if recv_frame_id in Common.can_recv_dict: if 255 == Common.can_recv_dict[recv_frame_id][0]: # print("connect success") break # 获取串码 canm.send_can(can_id=send_frame_id, can_data=address_data) while True: canm.send_can(can_id=send_frame_id, can_data=length) time.sleep(0.5) if recv_frame_id in Common.can_recv_dict: if b'\xff\xff\xff\xff\xff\xff\xff\xff' != Common.can_recv_dict[ recv_frame_id]: serial_code += Common.can_recv_dict[recv_frame_id] else: break # 退出boot canm.send_can(can_id=send_frame_id, can_data='CF00000000000000') canm.send_can(can_id=send_frame_id, can_data='FE00000000000000') if len(serial_code) > 0: serial_code = serial_code.replace(b'\xff', b'') serial_code = Convert.bytes_to_hexstr(serial_code) else: serial_code = "" return serial_code