2025-03-14 11:02:02 +08:00

33 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import struct
class Command05:
def __init__(self):
self.pile_id = b"\x00\x27\x02\x12\x34\x56\x12\x34" # 示例桩号
def build_05h_request(self):
"""构建05H请求对时帧"""
frame = bytearray([0x4A, 0x58]) # 帧头: "JX"
frame.append(0x05) # 命令码: 05H
frame.extend(self.pile_id) # 桩号 (8字节)
frame.append(0x01) # 数据加密方式: 0x01 (不加密)
frame.extend([0x00, 0x00]) # 数据域长度 (0)
checksum = 0
for b in frame[2:-1]:
checksum ^= b
frame.append(checksum) # 校验码
return frame
def process_05h_response(self, response):
"""处理06H响应由充电桩调用"""
if response and len(response) >= 14 and response[2] == 0x06:
logging.info("对时成功")
return True
logging.warning("无效的06H响应")
return False
if __name__ == "__main__":
import logging
logging.basicConfig(level=logging.INFO)
cmd = Command05()
request = cmd.build_05h_request()
print(f"05H请求帧: {request.hex().upper()}")