修改了上电操作
This commit is contained in:
@@ -25,20 +25,24 @@ class PowerManagerApp:
|
||||
style.configure('.', font=('Microsoft YaHei', 10))
|
||||
|
||||
self.root.title("电源管理系统")
|
||||
self.root.geometry("1200x800")
|
||||
self.root.tk.call('tk', 'scaling', 1.5) # 适配高DPI显示
|
||||
# 移除固定窗口大小设置,实现自适应
|
||||
self.root.minsize(800, 600) # 设置最小窗口大小
|
||||
|
||||
# UDP通信配置
|
||||
# self.udp_ip = "127.0.0.1"
|
||||
self.udp_ip = "192.168.0.224"
|
||||
self.udp_port = 5002
|
||||
self.udp_ip = "192.168.0.140"
|
||||
self.udp_port = 7000
|
||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
self.sock.bind((self.udp_ip, self.udp_port))
|
||||
|
||||
self.disSysPortC1 = 6000
|
||||
self.disSysHostC1 = '192.168.1.154'
|
||||
# self.disSysHostC1 = '127.0.0.1'
|
||||
self.disSysPortC2 = 6000
|
||||
self.disSysHostC2 = '192.168.1.158'
|
||||
# self.disSysHostC2 = '127.0.0.1'
|
||||
|
||||
|
||||
# self.disSysPortC1 = 7000
|
||||
# self.disSysHostC1 = '192.168.0.140'
|
||||
@@ -210,12 +214,14 @@ class PowerManagerApp:
|
||||
# 主框架
|
||||
main_frame = ttk.Frame(self.root, padding="10")
|
||||
main_frame.pack(fill=tk.BOTH, expand=True)
|
||||
self.root.grid_rowconfigure(0, weight=1)
|
||||
self.root.grid_columnconfigure(0, weight=1)
|
||||
|
||||
# 状态显示区
|
||||
status_frame = ttk.LabelFrame(main_frame, text="系统状态", padding="10")
|
||||
status_frame.pack(fill=tk.X, pady=5)
|
||||
status_frame.pack(fill=tk.BOTH, expand=True, pady=5)
|
||||
|
||||
# 状态显示区 - 使用Notebook组织不同母线状态
|
||||
# 创建Canvas和Scrollbar
|
||||
self.notebook = ttk.Notebook(status_frame)
|
||||
self.notebook.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
|
||||
|
||||
@@ -242,10 +248,39 @@ class PowerManagerApp:
|
||||
# 控制区
|
||||
control_frame = ttk.LabelFrame(main_frame, text="控制面板", padding="10")
|
||||
control_frame.pack(fill=tk.BOTH, expand=True, pady=5)
|
||||
control_frame.grid_rowconfigure(0, weight=1)
|
||||
control_frame.grid_columnconfigure(0, weight=1)
|
||||
|
||||
# 创建Canvas和Scrollbar
|
||||
canvas = tk.Canvas(control_frame)
|
||||
scrollbar = ttk.Scrollbar(control_frame, orient="vertical", command=canvas.yview)
|
||||
canvas.configure(yscrollcommand=scrollbar.set)
|
||||
|
||||
# 将Canvas和Scrollbar放入控制区
|
||||
canvas.pack(side="left", fill="both", expand=True)
|
||||
scrollbar.pack(side="right", fill="y")
|
||||
|
||||
# 创建内部Frame用于放置Notebook
|
||||
inner_frame = ttk.Frame(canvas)
|
||||
self.inner_frame_id = canvas.create_window((0, 0), window=inner_frame, anchor="nw")
|
||||
|
||||
# 配置Canvas滚动区域
|
||||
def configure_canvas(event):
|
||||
canvas.configure(scrollregion=canvas.bbox("all"))
|
||||
canvas.itemconfig(self.inner_frame_id, width=event.width)
|
||||
|
||||
inner_frame.bind("<Configure>", configure_canvas)
|
||||
canvas.bind("<Configure>", configure_canvas)
|
||||
|
||||
# 绑定鼠标滚轮事件
|
||||
def on_mousewheel(event):
|
||||
canvas.yview_scroll(int(-1*(event.delta/120)), "units")
|
||||
|
||||
canvas.bind_all("<MouseWheel>", on_mousewheel)
|
||||
|
||||
# 状态显示区 - 使用Notebook组织不同母线状态
|
||||
self.notebook_c = ttk.Notebook(control_frame)
|
||||
self.notebook_c.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
|
||||
self.notebook_c = ttk.Notebook(inner_frame)
|
||||
self.notebook_c.pack(fill="both", expand=True, padx=5, pady=5)
|
||||
|
||||
high_vol_control_frame = ttk.Frame(self.notebook_c)
|
||||
self.notebook_c.add(high_vol_control_frame, text="高压母线")
|
||||
@@ -266,6 +301,8 @@ class PowerManagerApp:
|
||||
# 日志区
|
||||
log_frame = ttk.LabelFrame(main_frame, text="系统日志", padding="10")
|
||||
log_frame.pack(fill=tk.BOTH, expand=True, pady=5)
|
||||
log_frame.grid_rowconfigure(0, weight=1)
|
||||
log_frame.grid_columnconfigure(0, weight=1)
|
||||
|
||||
self.log_text = tk.Text(log_frame, height=10, state=tk.DISABLED)
|
||||
self.log_text.pack(fill=tk.BOTH, expand=True)
|
||||
@@ -465,6 +502,9 @@ class PowerManagerApp:
|
||||
cmd.emergencyLithiumBatteryGroup2CircuitBreaker = state
|
||||
|
||||
# self.send_udp_command(cmd.pack())
|
||||
print(breaker_name,state)
|
||||
print(cmd)
|
||||
# print(cmd.unpack())
|
||||
self.send_udp_command(cmd.pack(), self.disSysHostC2, self.disSysPortC2)
|
||||
self.db.insertLowMainBusCmd(cmd)
|
||||
if state==0x55:
|
||||
@@ -703,7 +743,7 @@ class PowerManagerApp:
|
||||
"""处理接收到的UDP消息"""
|
||||
try:
|
||||
msg_id = int.from_bytes(data[2:4], byteorder='little')
|
||||
print('----------------------------',hex(msg_id))
|
||||
# print('----------------------------',hex(msg_id))
|
||||
if msg_id == 0x0005: # 高压母线状态
|
||||
msg = msg_disHighVolBusFbMsg()
|
||||
if msg.unpack(data):
|
||||
@@ -865,10 +905,12 @@ class PowerManagerApp:
|
||||
# bus["alarms"]["应急电源故障"] = 1
|
||||
bus["alarms"]["应急电源故障"] = msg.emergencyPowerFailureSignal
|
||||
# bus["insulation"] = msg.instrumentBusbarInsulationLow
|
||||
if msg.instrumentBusbarInsulationLow == 0x55:
|
||||
bus["insulation"] = 0
|
||||
else:
|
||||
bus["insulation"] = 1
|
||||
bus["insulation"] = msg.instrumentBusbarInsulationLow
|
||||
|
||||
# if msg.instrumentBusbarInsulationLow == 0x55:
|
||||
# bus["insulation"] = 0
|
||||
# else:
|
||||
# bus["insulation"] = 1
|
||||
|
||||
self.log_message("收到仪表主母线状态更新")
|
||||
else:
|
||||
@@ -1097,7 +1139,7 @@ class PowerManagerApp:
|
||||
try:
|
||||
# self.sock.sendto(data, (self.udp_ip, self.udp_port + 1))
|
||||
self.sock.sendto(data, (ip, port))
|
||||
print(f"发送命令到 {ip}:{port} ", data)
|
||||
print(f"发送命令到 {ip}:{port} ", data.hex())
|
||||
except Exception as e:
|
||||
self.log_message(f"发送命令失败: {str(e)}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user