import struct import logging from datetime import datetime class Command2627: def __init__(self): self.command_26 = 0x26 # 停止充电命令 self.command_27 = 0x27 # 停止充电回复 def build_26h_command(self, pile_id, gun_no=1): """构建26H停止充电命令""" try: print("\n构建26H停止充电命令...") frame = bytearray() frame.extend(b'JX') # 帧起始标志 frame.append(self.command_26) # 命令码26H frame.extend(pile_id) # 桩号 frame.append(0x01) # 数据加密方式(不加密) # 构建数据域 data = bytearray() # 添加时间标识 (BCD格式) now = datetime.now() data.extend(bytes([ ((now.year - 2000) // 10 << 4) + ((now.year - 2000) % 10), (now.month // 10 << 4) + (now.month % 10), (now.day // 10 << 4) + (now.day % 10), (now.hour // 10 << 4) + (now.hour % 10), (now.minute // 10 << 4) + (now.minute % 10), (now.second // 10 << 4) + (now.second % 10) ])) # 添加枪号 data.append(gun_no) # 计算数据长度 frame.extend(struct.pack("