Compare commits
36
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e6107b490 | ||
|
|
9772a2bf83 | ||
|
|
cd14ed2ca4 | ||
|
|
4cc418f863 | ||
|
|
040b628d54 | ||
|
|
51e2f1c51c | ||
|
|
8497b1979a | ||
|
|
05e4f3ae92 | ||
|
|
059ce6a540 | ||
|
|
b167ce3401 | ||
|
|
a6721415a6 | ||
|
|
f0f8073afc | ||
|
|
3f35ad2c21 | ||
|
|
c1a5712f76 | ||
|
|
8e8811a4a0 | ||
|
|
b70cf102fd | ||
|
|
b36dd3911f | ||
|
|
cda1e72f17 | ||
|
|
744fbfd298 | ||
|
|
90433064ec | ||
|
|
68c7909922 | ||
|
|
e131646156 | ||
|
|
96df14caea | ||
|
|
d92156e0cd | ||
|
|
f549ddf48b | ||
|
|
84838e3e74 | ||
|
|
1a9927d9bb | ||
|
|
22d0969569 | ||
|
|
d9ecff4e49 | ||
|
|
2459b33162 | ||
|
|
efaf4d658f | ||
|
|
a14e3e7621 | ||
|
|
a1f6fdd34a | ||
|
|
0977b275ee | ||
|
|
736b43efe4 | ||
|
|
d0cefeebf3 |
@@ -111,13 +111,6 @@ DLPilot/
|
||||
M303=u16 mV(12V 轨窗口 11400~12600),M304=s16 补码 mA(正=正向,固件原样上总线,
|
||||
上位机按有符号解析,FF 06=−250)。封装在 `payload_u16_be/payload_s16_be/format_power`,
|
||||
回归向量在 selftest_rs485.py(真机抓取帧)。
|
||||
- **电源自检序列**(M301 协议→M302 挡位最大电流→M303 实测母线电压,帧驱动状态机
|
||||
`_pd_on_frame/_pd_seq`,超时 3s/步):FPDO 判定 = 电压就近挡(标准 PD 固定挡
|
||||
5/9/12/15/20/28V,±5% 容差)+ M302 挡位电流;**12V 且 ≥3A 绿底,挡位不符红底,
|
||||
无匹配挡 ERR**。应答按 TYPE=0xF0 判成功;
|
||||
CH224Q 电压配置寄存器(0x0A)只写不可读,挡位只能实测判定。
|
||||
- **功率检测** = M303+M304 → 读数框 电压V / 电流mA;**功率值暂不计算**
|
||||
(用户要求:后续固件会提供功率命令直接返回,届时填充),显示占位"功率: —"。
|
||||
|
||||
## 5. 构建 / 发布流水线(全部在 src/ 下执行)
|
||||
|
||||
|
||||
+4
-13
@@ -52,11 +52,10 @@ DLPilot/
|
||||
```
|
||||
左列(HDMI 源端) 右列(光机控制 RS485)
|
||||
┌ 显示器选择区域 [刷新] ┐ ┌ 串口选择 + 波特率/8-N-1 参数/连接 ┐
|
||||
├ 支持的模式: 分辨率[应用][恢复] + 明细 ┐ ├ 电源检查 — PD自检/FPDO挡位/功率读数 ┤
|
||||
├ EDID 信息 ┘ ├ 串口数据 — 收发日志(译码+hex) ┤
|
||||
├ 测试图案 / 纯色 / 校准图案 / 测试卡区域 │ ├ 光机命令 — 快捷按钮+TEC │
|
||||
├ EDID 原始数据 [逐字节解析] ┘ │ 预设下拉 / 温度电流读取 / 自定义 │
|
||||
└─────────────────────────────┘ └ 快捷滑条 — 光强/定时/TEC温度 ┘
|
||||
├ 支持的模式: 分辨率[应用][恢复] + 明细 ┐ ├ 串口数据 — 收发日志(译码+hex) ┤
|
||||
├ EDID 信息(表格) ┘ ├ 光机命令 — 快捷按钮+TEC │
|
||||
├ 测试图案 / 纯色 / 自定义 / 测试卡区域 │ 预设下拉 / 自定义 / 温度读取 │
|
||||
├ EDID 原始数据 [逐字节解析] ┘ └ 快捷滑条 — 光强/定时/TEC温度 ┘
|
||||
```
|
||||
|
||||
1. 左上显示器下拉选择目标屏(多屏时注意别选成主屏),"刷新"重新枚举;
|
||||
@@ -100,12 +99,6 @@ GUI"光机控制"区:选串口 → 连接 → 点快捷按钮或命令下拉/
|
||||
多口描述相同时自动附物理位置消歧。日志区实时显示 `→ 命令` / `← 译码结果 (原始 hex)`,
|
||||
错误自动附释义(如 `err:3(I2C NACK)`)。
|
||||
|
||||
"电源检查"卡:**电源自检**依序发 M301(协议)→M302(挡位最大电流)→M303(实测母线电压),
|
||||
按实测电压就近判定 PD 固定挡(5/9/12/15/20/28V,容差 ±5%):**12V 挡且 ≥3A 绿底
|
||||
"FPDO: 12V@3A"**;挡位不符(如 9V 挡)**红底**显示实际挡位;不落在任何标准挡显示
|
||||
**ERR**(CH224Q 电压配置寄存器只写不可读,挡位只能靠实测判定)。**功率检测**依序发
|
||||
M303+M304,读数框显示 电压(V) / 电流(mA);功率暂留空(后续固件命令直接返回)。
|
||||
|
||||
| 命令 | 功能 | 响应示例 |
|
||||
|---|---|---|
|
||||
| `M730S0` / `M730S1` | 开 / 关光机 | `ok` |
|
||||
@@ -113,8 +106,6 @@ M303+M304,读数框显示 电压(V) / 电流(mA);功率暂留空(后续固
|
||||
| `M731S100` | 设光强 54-800(RGB 同值,写后读回复核) | `ok` / `err:R..G..B..` |
|
||||
| `M732` | 查三路电流设置值(0-65535) | `okR110G110B110` |
|
||||
| `M201` / `M202` | 查 DMD / LAMP 温度(0.1°C) | `okTL:246` = 24.6°C |
|
||||
| `M301` | 查电源协议(CH224Q 握手结果) | ASCII:`PD` / `QC3.0` / `EPR` … |
|
||||
| `M302` | 查 PD 挡位最大电流(u16 大端 **mA**,50mA/LSB 固件已换算) | 0x0BB8 = 3000 mA = 3 A |
|
||||
| `M303` | 查母线电压(SQ52205 实测,**2 字节大端二进制载荷**) | 0x2EF4 = 12020 mV = 12.02 V(12V 轨窗口 11400~12600) |
|
||||
| `M304` | 查负载电流(SQ52205 实测,**2 字节大端二进制载荷**) | s16 补码 mA:0x0034=+52;FF 06=−250(正=正向) |
|
||||
| `M999` | 查固件版本 | `okv20.0.0.1` |
|
||||
|
||||
Binary file not shown.
@@ -52,11 +52,10 @@ DLPilot/
|
||||
```
|
||||
左列(HDMI 源端) 右列(光机控制 RS485)
|
||||
┌ 显示器选择区域 [刷新] ┐ ┌ 串口选择 + 波特率/8-N-1 参数/连接 ┐
|
||||
├ 支持的模式: 分辨率[应用][恢复] + 明细 ┐ ├ 电源检查 — PD自检/FPDO挡位/功率读数 ┤
|
||||
├ EDID 信息 ┘ ├ 串口数据 — 收发日志(译码+hex) ┤
|
||||
├ 测试图案 / 纯色 / 校准图案 / 测试卡区域 │ ├ 光机命令 — 快捷按钮+TEC │
|
||||
├ EDID 原始数据 [逐字节解析] ┘ │ 预设下拉 / 温度电流读取 / 自定义 │
|
||||
└─────────────────────────────┘ └ 快捷滑条 — 光强/定时/TEC温度 ┘
|
||||
├ 支持的模式: 分辨率[应用][恢复] + 明细 ┐ ├ 串口数据 — 收发日志(译码+hex) ┤
|
||||
├ EDID 信息(表格) ┘ ├ 光机命令 — 快捷按钮+TEC │
|
||||
├ 测试图案 / 纯色 / 自定义 / 测试卡区域 │ 预设下拉 / 自定义 / 温度读取 │
|
||||
├ EDID 原始数据 [逐字节解析] ┘ └ 快捷滑条 — 光强/定时/TEC温度 ┘
|
||||
```
|
||||
|
||||
1. 左上显示器下拉选择目标屏(多屏时注意别选成主屏),"刷新"重新枚举;
|
||||
@@ -100,12 +99,6 @@ GUI"光机控制"区:选串口 → 连接 → 点快捷按钮或命令下拉/
|
||||
多口描述相同时自动附物理位置消歧。日志区实时显示 `→ 命令` / `← 译码结果 (原始 hex)`,
|
||||
错误自动附释义(如 `err:3(I2C NACK)`)。
|
||||
|
||||
"电源检查"卡:**电源自检**依序发 M301(协议)→M302(挡位最大电流)→M303(实测母线电压),
|
||||
按实测电压就近判定 PD 固定挡(5/9/12/15/20/28V,容差 ±5%):**12V 挡且 ≥3A 绿底
|
||||
"FPDO: 12V@3A"**;挡位不符(如 9V 挡)**红底**显示实际挡位;不落在任何标准挡显示
|
||||
**ERR**(CH224Q 电压配置寄存器只写不可读,挡位只能靠实测判定)。**功率检测**依序发
|
||||
M303+M304,读数框显示 电压(V) / 电流(mA);功率暂留空(后续固件命令直接返回)。
|
||||
|
||||
| 命令 | 功能 | 响应示例 |
|
||||
|---|---|---|
|
||||
| `M730S0` / `M730S1` | 开 / 关光机 | `ok` |
|
||||
@@ -113,10 +106,6 @@ M303+M304,读数框显示 电压(V) / 电流(mA);功率暂留空(后续固
|
||||
| `M731S100` | 设光强 54-800(RGB 同值,写后读回复核) | `ok` / `err:R..G..B..` |
|
||||
| `M732` | 查三路电流设置值(0-65535) | `okR110G110B110` |
|
||||
| `M201` / `M202` | 查 DMD / LAMP 温度(0.1°C) | `okTL:246` = 24.6°C |
|
||||
| `M301` | 查电源协议(CH224Q 握手结果) | ASCII:`PD` / `QC3.0` / `EPR` … |
|
||||
| `M302` | 查 PD 挡位最大电流(u16 大端 **mA**,50mA/LSB 固件已换算) | 0x0BB8 = 3000 mA = 3 A |
|
||||
| `M303` | 查母线电压(SQ52205 实测,**2 字节大端二进制载荷**) | 0x2EF4 = 12020 mV = 12.02 V(12V 轨窗口 11400~12600) |
|
||||
| `M304` | 查负载电流(SQ52205 实测,**2 字节大端二进制载荷**) | s16 补码 mA:0x0034=+52;FF 06=−250(正=正向) |
|
||||
| `M999` | 查固件版本 | `okv20.0.0.1` |
|
||||
| `M737` | 查投光是否结束(投光中延迟应答) | `ok` |
|
||||
| `M7S0` / `M7S1` | TEC 自动控温开 / 关(注意 S0=开) | `ok` |
|
||||
|
||||
+79
-187
@@ -40,7 +40,7 @@ CHIP_OK = '#2FA574'
|
||||
CHIP_ERR = '#D9534F'
|
||||
|
||||
APP_NAME = 'DLPilot'
|
||||
APP_VERSION = '0.3.5'
|
||||
APP_VERSION = '0.3.4'
|
||||
REPO_URL = 'https://gitea.hulk.wang/hulk/LT8619C_Debug_Tools'
|
||||
|
||||
|
||||
@@ -63,30 +63,10 @@ def _apply_dropdown_theme():
|
||||
ctk.ThemeManager.theme['DropdownMenu']['text_color'] = ('#1A1A1A', '#DADADA')
|
||||
|
||||
|
||||
def _ensure_single_instance():
|
||||
"""单实例锁(Windows 命名互斥体): 已有实例在运行时返回 False。
|
||||
|
||||
双击 exe 开多个实例时, 只有先启动的能连串口, 后续实例连接报"拒绝访问",
|
||||
且用户往往只看到后开的窗口 —— 表现为"连不上/断不开"。互斥体句柄随
|
||||
进程存活, 进程退出自动释放。"""
|
||||
ERROR_ALREADY_EXISTS = 183
|
||||
ctypes.windll.kernel32.CreateMutexW(None, False, 'hulk.DLPilot.single')
|
||||
return ctypes.windll.kernel32.GetLastError() != ERROR_ALREADY_EXISTS
|
||||
|
||||
|
||||
def run_gui(auto_close=0):
|
||||
"""入口: 配置外观并启动主窗口"""
|
||||
ctk.set_appearance_mode('System')
|
||||
_apply_dropdown_theme()
|
||||
if not _ensure_single_instance():
|
||||
from tkinter import messagebox
|
||||
import tkinter as tk
|
||||
r = tk.Tk()
|
||||
r.withdraw()
|
||||
messagebox.showinfo('DLPilot 已在运行',
|
||||
'检测到另一个 DLPilot 实例正在运行。\n'
|
||||
'请使用已打开的窗口(串口同时只能被一个实例占用)。')
|
||||
return
|
||||
App(auto_close).mainloop()
|
||||
|
||||
|
||||
@@ -115,17 +95,12 @@ class App(ctk.CTk):
|
||||
self._orig_modes = {} # device -> 切改前的原始 DEVMODEW
|
||||
# 光机控制链路: 回调发生在串口线程, 经队列投递回 GUI 主线程轮询
|
||||
self._dlpc_log_q = queue.Queue()
|
||||
self.dlpc = dlpc_rs485.DLPC485(self._dlpc_on_event, self._dlpc_on_status,
|
||||
on_frame=self._dlpc_on_frame)
|
||||
self.dlpc = dlpc_rs485.DLPC485(self._dlpc_on_event, self._dlpc_on_status)
|
||||
self._dlpc_connected = False
|
||||
self._poll_job = None
|
||||
self._tl_order = [] # 温度查询应答顺序: 'DMD'/'LAMP' 先到先得
|
||||
self._pd_seq = [] # 电源自检待执行步骤: [(命令, kind), ...]
|
||||
self._pd_values = {} # 自检采集值: {'ma': 挡位电流, 'mv': 实测电压}
|
||||
self._pd_timer = None # 自检单步超时定时器
|
||||
self._pwr_seq = [] # 功率检测待执行步骤
|
||||
self._pwr_values = {} # 功率检测采集值: {'mv', 'ma'}
|
||||
self._pwr_timer = None
|
||||
self._build()
|
||||
self._load_displays()
|
||||
# 主窗口按 ESC 也能关闭所有投屏(投屏窗口失焦时的兜底出口)
|
||||
@@ -238,13 +213,10 @@ class App(ctk.CTk):
|
||||
self.txt_modes.configure(state='disabled')
|
||||
|
||||
# -- EDID 信息 --
|
||||
# CTkTextbox 而非 CTkScrollableFrame+逐行 Label: 后者 40+ 个画布控件,
|
||||
# 窗口最大化时逐个重绘是卡顿主因; 文本框整体重排, 开销低一个量级
|
||||
card, c = self._card(col, 'EDID 信息')
|
||||
card.grid(row=2, column=0, sticky='nsew', pady=(10, 0))
|
||||
self.txt_edid = ctk.CTkTextbox(c, font=MONO, wrap='none')
|
||||
self.txt_edid.pack(fill='both', expand=True)
|
||||
self.txt_edid.configure(state='disabled')
|
||||
self.edid_scroll = ctk.CTkScrollableFrame(c, height=150)
|
||||
self.edid_scroll.pack(fill='both', expand=True)
|
||||
|
||||
# -- 测试图案 --
|
||||
card, c = self._card(col,'测试图案 — 黑底 1:1 居中, 投屏按 ESC 或"停止测试图像"退出',
|
||||
@@ -356,37 +328,29 @@ class App(ctk.CTk):
|
||||
'累加和校验; 全部命令见 README"光机控制"')
|
||||
|
||||
# -- 电源检查 --
|
||||
# 网格对齐两行: col2 为读数框列(weight=1) -> FPDO 色框与功率黑框
|
||||
# 起止位置完全一致(等长), 且随窗口拉伸自适应
|
||||
card, c = self._card(col, '电源检查 — PD 自检 / 功率读数')
|
||||
card.grid(row=2, column=0, sticky='ew', pady=(10, 0))
|
||||
pwr_grid = ctk.CTkFrame(c, fg_color='transparent')
|
||||
pwr_grid.pack(fill='x')
|
||||
pwr_grid.grid_columnconfigure(2, weight=1)
|
||||
ctk.CTkButton(pwr_grid, text='电源自检', width=90,
|
||||
command=self._pd_selftest).grid(row=0, column=0, sticky='w')
|
||||
proto_cell = ctk.CTkFrame(pwr_grid, fg_color='transparent')
|
||||
proto_cell.grid(row=0, column=1, sticky='w', padx=(10, 0))
|
||||
ctk.CTkLabel(proto_cell, text='协议:').pack(side='left', padx=(0, 4))
|
||||
self.chip_pd = ctk.CTkLabel(proto_cell, text='PD', width=60, height=26,
|
||||
rowp1 = ctk.CTkFrame(c, fg_color='transparent')
|
||||
rowp1.pack(fill='x')
|
||||
ctk.CTkButton(rowp1, text='电源自检', width=90,
|
||||
command=self._pd_selftest).pack(side='left')
|
||||
ctk.CTkLabel(rowp1, text='协议:').pack(side='left', padx=(10, 4))
|
||||
self.chip_pd = ctk.CTkLabel(rowp1, text='PD', width=60, height=26,
|
||||
corner_radius=6, fg_color=CHIP_IDLE,
|
||||
text_color=CHIP_IDLE_TEXT)
|
||||
self.chip_pd.pack(side='left')
|
||||
self.var_fpdo = tk.StringVar(value='FPDO: —')
|
||||
self.chip_fpdo = ctk.CTkLabel(pwr_grid, textvariable=self.var_fpdo,
|
||||
height=26, corner_radius=6,
|
||||
fg_color=CHIP_IDLE,
|
||||
text_color=CHIP_IDLE_TEXT, anchor='w', padx=8)
|
||||
self.chip_fpdo.grid(row=0, column=2, sticky='ew', padx=(12, 0))
|
||||
ctk.CTkButton(pwr_grid, text='功率检测', width=90,
|
||||
command=self._pwr_query).grid(row=1, column=0,
|
||||
sticky='w', pady=(6, 0))
|
||||
ctk.CTkLabel(rowp1, textvariable=self.var_fpdo, anchor='w',
|
||||
text_color='#3B8ED0').pack(side='left', padx=(12, 0))
|
||||
rowp2 = ctk.CTkFrame(c, fg_color='transparent')
|
||||
rowp2.pack(fill='x', pady=(6, 0))
|
||||
ctk.CTkButton(rowp2, text='功率检测', width=90,
|
||||
command=self._pwr_query).pack(side='left')
|
||||
self.var_pwr = tk.StringVar(value='电压: — 电流: — 功率: —')
|
||||
self.box_pwr = ctk.CTkLabel(pwr_grid, textvariable=self.var_pwr,
|
||||
height=26, corner_radius=6,
|
||||
fg_color=('#F2F2F2', '#181818'),
|
||||
anchor='w', padx=8)
|
||||
self.box_pwr.grid(row=1, column=2, sticky='ew', padx=(8, 0), pady=(6, 0))
|
||||
ctk.CTkLabel(rowp2, textvariable=self.var_pwr, height=28,
|
||||
corner_radius=6, fg_color=('#F2F2F2', '#181818'),
|
||||
anchor='w').pack(side='left', fill='x', expand=True,
|
||||
padx=(8, 0))
|
||||
|
||||
# -- 光机命令 --
|
||||
# 标题行右侧: 电流实时读数 + 查电流按钮(okR..G..B.. 应答解析)
|
||||
@@ -572,13 +536,16 @@ class App(ctk.CTk):
|
||||
self._set_text(self.txt_hex, edid_parse.hex_dump(d['edid']))
|
||||
|
||||
def _clear_edid_rows(self):
|
||||
self._set_text(self.txt_edid, '')
|
||||
for w in self.edid_scroll.winfo_children():
|
||||
w.destroy()
|
||||
|
||||
def _add_edid_row(self, k, v):
|
||||
self.txt_edid.configure(state='normal')
|
||||
self.txt_edid.insert('end', f'{k:<16}{v}\n')
|
||||
self.txt_edid.see('end')
|
||||
self.txt_edid.configure(state='disabled')
|
||||
row = ctk.CTkFrame(self.edid_scroll, fg_color='transparent')
|
||||
row.pack(fill='x', pady=1)
|
||||
ctk.CTkLabel(row, text=k, width=132, anchor='w',
|
||||
text_color='gray60').pack(side='left')
|
||||
ctk.CTkLabel(row, text=v, anchor='w').pack(side='left',
|
||||
fill='x', expand=True)
|
||||
|
||||
def _apply_mode(self):
|
||||
d = self._cur_display()
|
||||
@@ -746,13 +713,6 @@ class App(ctk.CTk):
|
||||
# ============================================================
|
||||
# 光机控制(RS485)
|
||||
# ============================================================
|
||||
def _dlpc_on_frame(self, fr):
|
||||
"""结构化应答帧(串口线程): 电源自检/功率检测序列进行中时路由给状态机"""
|
||||
if self._pd_seq:
|
||||
self._dlpc_log_q.put(('pdframe', fr))
|
||||
elif self._pwr_seq:
|
||||
self._dlpc_log_q.put(('pwrframe', fr))
|
||||
|
||||
def _dlpc_on_event(self, line):
|
||||
# 温度查询应答: okTL:<0.1°C>, 依发送顺序归入 DMD/LAMP 实时显示框
|
||||
m = re.search(r'← okTL:(-?\d+)', line)
|
||||
@@ -798,8 +758,6 @@ class App(ctk.CTk):
|
||||
else:
|
||||
color = 'gray60'
|
||||
self.lbl_dlpc_st.configure(text=text, text_color=color)
|
||||
if text.startswith(('已断开', '串口丢失')):
|
||||
self._serial_reset_state()
|
||||
elif kind == 'temp':
|
||||
if text.startswith('DMD'):
|
||||
self.var_dmd.set(text)
|
||||
@@ -807,12 +765,10 @@ class App(ctk.CTk):
|
||||
self.var_lamp.set(text)
|
||||
elif kind == 'current':
|
||||
self.var_current.set(text)
|
||||
elif kind == 'pdframe':
|
||||
self._pd_step_done(text.type_code == 0xF0, text)
|
||||
elif kind == 'pwrframe':
|
||||
self._pwr_step_done(text)
|
||||
else:
|
||||
self._dlpc_log(text)
|
||||
if (self._pd_seq and kind == 'event'
|
||||
and text.startswith('← ')):
|
||||
self._pd_on_reply(text) # 电源自检: 应答路由到状态机
|
||||
except queue.Empty:
|
||||
pass
|
||||
connected = self.dlpc.is_connected()
|
||||
@@ -858,7 +814,6 @@ class App(ctk.CTk):
|
||||
def _dlpc_toggle(self):
|
||||
if self.dlpc.is_connected():
|
||||
self.dlpc.close()
|
||||
self._serial_reset_state() # 断开时清序列/定时器/应答归位, 防旧账错配
|
||||
return
|
||||
port = self._dlpc_selected_port()
|
||||
if not port:
|
||||
@@ -877,28 +832,10 @@ class App(ctk.CTk):
|
||||
config.save_slots(self.slots, self.area_var.get()) # 记住本次串口
|
||||
self.dlpc.open(port, baud, bytesize=bytesize, parity=parity, stopbits=stopbits)
|
||||
|
||||
def _serial_reset_state(self):
|
||||
"""断开/失连时清理进行中的序列与应答归位队列(不碰串口线程本身)"""
|
||||
self._pd_seq.clear()
|
||||
self._pwr_seq.clear()
|
||||
for t in (self._pd_timer, self._pwr_timer):
|
||||
if t:
|
||||
try:
|
||||
self.after_cancel(t)
|
||||
except Exception:
|
||||
pass
|
||||
self._pd_timer = self._pwr_timer = None
|
||||
self._tl_order.clear()
|
||||
|
||||
def _dlpc_send(self, cmd):
|
||||
if not self.dlpc.is_connected():
|
||||
self.lbl_dlpc_st.configure(text='未连接串口', text_color='#E07A3F')
|
||||
return
|
||||
if self._pd_seq or self._pwr_seq:
|
||||
# 序列进行中: 手动命令的应答帧会被序列错认领(它不区分应答属于哪条
|
||||
# 命令, 来一帧消费一步), 值会错位 —— 拒绝并提示, 序列结束再发
|
||||
self._dlpc_log(f'序列进行中, 命令已忽略: {cmd}')
|
||||
return
|
||||
self.dlpc.send(cmd)
|
||||
|
||||
def _dlpc_send_preset(self):
|
||||
@@ -916,15 +853,14 @@ class App(ctk.CTk):
|
||||
# -- 电源检查: 自检序列 + 功率读数 --
|
||||
|
||||
def _pd_selftest(self):
|
||||
"""电源自检: 依序 M301(协议) → M302(挡位最大电流) → M303(实测母线电压),
|
||||
应答帧驱动序列前进(成功=TYPE 0xF0), 结束后按 _pd_fpdo_verdict 判定 FPDO"""
|
||||
"""电源自检: 按序自动执行 M301/M302(电压检测命令待固件定义后在序列追加),
|
||||
每步应答刷新状态位: 绿=正常回包, 红=错误/超时, 灰=未检测"""
|
||||
if not self.dlpc.is_connected():
|
||||
self.lbl_dlpc_st.configure(text='未连接串口', text_color='#E07A3F')
|
||||
return
|
||||
if self._pd_seq:
|
||||
return # 进行中, 忽略重复触发
|
||||
self._pd_seq = [('M301', 'pd'), ('M302', 'fpdo_ma'), ('M303', 'meas_mv')]
|
||||
self._pd_values = {}
|
||||
self._pd_seq = [('M301', 'pd'), ('M302', 'fpdo')]
|
||||
self._pd_chip_reset()
|
||||
self._dlpc_log('电源自检: 开始')
|
||||
self._pd_step_next()
|
||||
@@ -932,114 +868,72 @@ class App(ctk.CTk):
|
||||
def _pd_chip_reset(self):
|
||||
self.chip_pd.configure(fg_color=CHIP_IDLE,
|
||||
text_color=CHIP_IDLE_TEXT, text='PD')
|
||||
self.chip_fpdo.configure(fg_color=CHIP_IDLE, text_color=CHIP_IDLE_TEXT)
|
||||
self.var_fpdo.set('FPDO: —')
|
||||
|
||||
def _pd_step_next(self):
|
||||
if not self._pd_seq:
|
||||
self._pd_fpdo_verdict()
|
||||
self._dlpc_log('电源自检: 完成')
|
||||
return
|
||||
self.dlpc.send(self._pd_seq[0][0])
|
||||
self._pd_timer = self.after(3000, lambda: self._pd_step_done(False, None))
|
||||
self._pd_timer = self.after(3000, lambda: self._pd_step_done(False, '超时'))
|
||||
|
||||
def _pd_step_done(self, ok, fr):
|
||||
def _pd_on_reply(self, line):
|
||||
self._pd_step_done(self._pd_reply_ok(line), line)
|
||||
|
||||
@staticmethod
|
||||
def _pd_reply_ok(line):
|
||||
"""应答行 -> 是否成功帧(TYPE=0xF0): 成功行正文是 payload 原文(如 'PD'/'okTL:246',
|
||||
不必有 ok 前缀), 失败行正文是 TYPE 译码词或带 err:, 据此区分"""
|
||||
body = line[2:].split(' [')[0].strip()
|
||||
if 'err:' in body:
|
||||
return False
|
||||
return not any(n in body for n in dlpc_rs485.TYPE_NAMES.values()
|
||||
if n != '成功') # '成功' 不会出现在日志正文, 仅防 payload 撞词
|
||||
|
||||
def _pd_step_done(self, ok, line=''):
|
||||
if not self._pd_seq:
|
||||
return
|
||||
if self._pd_timer:
|
||||
self.after_cancel(self._pd_timer)
|
||||
self._pd_timer = None
|
||||
cmd, kind = self._pd_seq.pop(0)
|
||||
raw = dlpc_rs485.payload_bytes(fr) if fr is not None else b''
|
||||
if ok and kind == 'pd':
|
||||
proto = raw.decode('ascii', 'replace').strip()
|
||||
good = proto in ('PD', 'EPR')
|
||||
self.chip_pd.configure(fg_color=CHIP_OK if good else CHIP_ERR,
|
||||
text_color='#FFFFFF', text=proto or 'PD')
|
||||
elif ok and kind == 'fpdo_ma' and len(raw) == 2:
|
||||
self._pd_values['ma'] = dlpc_rs485.payload_u16_be(raw)
|
||||
elif ok and kind == 'meas_mv' and len(raw) == 2:
|
||||
self._pd_values['mv'] = dlpc_rs485.payload_u16_be(raw)
|
||||
_cmd, kind = self._pd_seq.pop(0)
|
||||
payload = ''
|
||||
if ok:
|
||||
body = line[2:].split(' [')[0].strip() # 去 '← ' 与尾部 hex
|
||||
payload = '' if body.lower() == 'ok' else \
|
||||
(body[2:].strip() if body[:2].lower() == 'ok' else body)
|
||||
if kind == 'pd':
|
||||
self.chip_pd.configure(fg_color=CHIP_OK if ok else CHIP_ERR,
|
||||
text_color='#FFFFFF',
|
||||
text=payload if ok and payload else 'PD')
|
||||
elif kind == 'fpdo':
|
||||
mv = re.search(r'(\d+(?:\.\d+)?)\s*V', payload, re.I)
|
||||
ma = re.search(r'(\d+(?:\.\d+)?)\s*A', payload, re.I)
|
||||
if not ok:
|
||||
self.var_fpdo.set('FPDO: 应答错误')
|
||||
elif mv and ma: # 电压 + 电源宣称最大电流 -> FPDO 功率
|
||||
v, a = float(mv.group(1)), float(ma.group(1))
|
||||
self.var_fpdo.set(f'FPDO: {v:g}V / {a:g}A ({v * a:.0f}W)')
|
||||
elif payload:
|
||||
self.var_fpdo.set(f'FPDO: {payload}')
|
||||
if ok:
|
||||
self._pd_step_next()
|
||||
else: # 出错即中止
|
||||
else: # 出错即中止, 后续状态位保持未检测灰
|
||||
self._pd_seq.clear()
|
||||
if kind == 'pd':
|
||||
self.chip_pd.configure(fg_color=CHIP_ERR, text_color='#FFFFFF',
|
||||
text='ERR')
|
||||
elif kind == 'fpdo_ma':
|
||||
self.chip_fpdo.configure(fg_color=CHIP_ERR, text_color='#FFFFFF')
|
||||
self.var_fpdo.set('FPDO: ERR')
|
||||
self._dlpc_log('电源自检: 应答错误/超时, 序列中止')
|
||||
|
||||
def _pd_fpdo_verdict(self):
|
||||
"""FPDO 判定: 电压挡位由 M303 实测母线电压就近判定(标准 PD 固定挡
|
||||
5/9/12/15/20/28V, 容差 ±5%; CH224Q 0x0A 只写不可读, 挡位只能实测判定),
|
||||
电流为 M302 挡位最大电流。默认挡 12V 且 ≥3A -> 绿底;
|
||||
挡位不符(如 9V 挡) -> 红底; 实测电压不落在任何标准挡 -> ERR"""
|
||||
mv = self._pd_values.get('mv')
|
||||
ma = self._pd_values.get('ma')
|
||||
if mv is None or ma is None:
|
||||
self.chip_fpdo.configure(fg_color=CHIP_ERR, text_color='#FFFFFF')
|
||||
self.var_fpdo.set('FPDO: ERR')
|
||||
return
|
||||
gear = next((g for g in (5, 9, 12, 15, 20, 28)
|
||||
if abs(mv - g * 1000) <= g * 50), None) # ±5% = g*50 mV
|
||||
a_txt = f'{ma / 1000:g}'
|
||||
if gear is None:
|
||||
self.chip_fpdo.configure(fg_color=CHIP_ERR, text_color='#FFFFFF')
|
||||
self.var_fpdo.set('FPDO: ERR')
|
||||
elif gear == 12 and ma >= 3000:
|
||||
self.chip_fpdo.configure(fg_color=CHIP_OK, text_color='#FFFFFF')
|
||||
self.var_fpdo.set(f'FPDO: 12V@{a_txt}A')
|
||||
else:
|
||||
self.chip_fpdo.configure(fg_color=CHIP_ERR, text_color='#FFFFFF')
|
||||
self.var_fpdo.set(f'FPDO: {gear}V@{a_txt}A')
|
||||
why = '超时无应答' if not line.startswith('← ') else '应答错误'
|
||||
self._dlpc_log(f'电源自检: {why}, 序列中止')
|
||||
|
||||
def _pwr_query(self):
|
||||
"""功率检测: M303 实测电压 + M304 实测电流(按有符号); 功率值待固件功率命令"""
|
||||
"""功率检测: 命令待固件实现, 先占位(定义后在此发送并接 _pwr_update)"""
|
||||
if not self.dlpc.is_connected():
|
||||
self.lbl_dlpc_st.configure(text='未连接串口', text_color='#E07A3F')
|
||||
return
|
||||
if self._pwr_seq:
|
||||
return
|
||||
self._pwr_seq = [('M303', 'mv'), ('M304', 'ma')]
|
||||
self._pwr_values = {}
|
||||
self._dlpc_log('功率检测: 开始')
|
||||
self._pwr_step_next()
|
||||
self._dlpc_log('功率检测: 命令待固件实现')
|
||||
|
||||
def _pwr_step_next(self):
|
||||
if not self._pwr_seq:
|
||||
v_mv = self._pwr_values.get('mv', 0)
|
||||
ma = self._pwr_values.get('ma', 0)
|
||||
self._pwr_update(v_mv, ma)
|
||||
self._dlpc_log('功率检测: 完成')
|
||||
return
|
||||
self.dlpc.send(self._pwr_seq[0][0])
|
||||
self._pwr_timer = self.after(3000, lambda: self._pwr_step_done(None))
|
||||
|
||||
def _pwr_step_done(self, fr):
|
||||
if not self._pwr_seq:
|
||||
return
|
||||
if self._pwr_timer:
|
||||
self.after_cancel(self._pwr_timer)
|
||||
self._pwr_timer = None
|
||||
cmd, kind = self._pwr_seq.pop(0)
|
||||
raw = dlpc_rs485.payload_bytes(fr) if fr is not None else b''
|
||||
if fr is None or fr.type_code != 0xF0 or len(raw) != 2:
|
||||
self._pwr_seq.clear()
|
||||
self.var_pwr.set('电压: ERR 电流: — 功率: —')
|
||||
self._dlpc_log('功率检测: 应答错误/超时, 中止')
|
||||
return
|
||||
if kind == 'mv':
|
||||
self._pwr_values['mv'] = dlpc_rs485.payload_u16_be(raw)
|
||||
elif kind == 'ma':
|
||||
self._pwr_values['ma'] = dlpc_rs485.payload_s16_be(raw)
|
||||
self._pwr_step_next()
|
||||
|
||||
def _pwr_update(self, v_mv, ma):
|
||||
"""功率读数框更新: 电压 V / 电流 mA; 功率暂不计算(待固件功率命令返回后填充)"""
|
||||
self.var_pwr.set(f'电压: {v_mv / 1000:.2f} V 电流: {ma} mA 功率: —')
|
||||
def _pwr_update(self, volts, amps):
|
||||
"""功率读数框更新入口: 电压/电流到手后换算功率并刷新"""
|
||||
self.var_pwr.set(f'电压: {volts:.1f} V 电流: {amps:.2f} A '
|
||||
f'功率: {volts * amps:.1f} W')
|
||||
|
||||
def _light_entry_apply(self, _evt=None):
|
||||
"""滑条数值输入框回车: 校验并限幅 54-800, 同步回滑条"""
|
||||
@@ -1106,13 +1000,11 @@ class App(ctk.CTk):
|
||||
self._dlpc_send(f'M8S{v}')
|
||||
|
||||
def destroy(self):
|
||||
try: # 取消待触发的轮询/自检/功率超时回调, 避免销毁后 Tcl 报错
|
||||
try: # 取消待触发的轮询/自检超时回调, 避免销毁后 Tcl 报错
|
||||
if self._poll_job:
|
||||
self.after_cancel(self._poll_job)
|
||||
if self._pd_timer:
|
||||
self.after_cancel(self._pd_timer)
|
||||
if self._pwr_timer:
|
||||
self.after_cancel(self._pwr_timer)
|
||||
except Exception:
|
||||
pass
|
||||
try: # 两种退出路径(关窗/--seconds 自动关)都收掉串口线程
|
||||
|
||||
@@ -196,8 +196,8 @@ class DLPC485:
|
||||
回调在后台线程触发, GUI 侧需自行投递回主线程(见 hdmi_gui 的轮询队列)。
|
||||
"""
|
||||
|
||||
def __init__(self, on_event, on_status, on_frame=None):
|
||||
self.on_event, self.on_status, self.on_frame = on_event, on_status, on_frame
|
||||
def __init__(self, on_event, on_status):
|
||||
self.on_event, self.on_status = on_event, on_status
|
||||
self.q = queue.Queue()
|
||||
self._target = None # 想态 (port, baud, bytesize, parity, stopbits)
|
||||
self._open_key = None # 当前已打开串口的参数元组
|
||||
@@ -290,9 +290,7 @@ class DLPC485:
|
||||
port, baud, bytesize=bytesizes.get(dbsize, serial.EIGHTBITS),
|
||||
parity=parities.get(parity, serial.PARITY_NONE),
|
||||
stopbits=stopbits.get(sbits, serial.STOPBITS_ONE),
|
||||
timeout=0.15,
|
||||
write_timeout=1.0) # 写超时: 转换器停滞时 write 会
|
||||
# 永久阻塞并卡死线程, 必须设上限
|
||||
timeout=0.15)
|
||||
self.parser = FrameParser()
|
||||
self._open_key = target
|
||||
self.on_status(f'已连接 {port} @ {baud} '
|
||||
@@ -301,11 +299,7 @@ class DLPC485:
|
||||
self.ser = None
|
||||
with self._lock:
|
||||
self._target = None
|
||||
et = str(e)
|
||||
if 'PermissionError' in repr(e) or '拒绝访问' in et \
|
||||
or 'Access is denied' in et:
|
||||
et += '(串口被占用: 检查串口助手/另一个本工具实例)'
|
||||
self.on_status(f'连接失败: {et}')
|
||||
self.on_status(f'连接失败: {e}')
|
||||
if self.ser is not None:
|
||||
try:
|
||||
item = None
|
||||
@@ -320,8 +314,6 @@ class DLPC485:
|
||||
data = self.ser.read(256)
|
||||
if data:
|
||||
for fr in self.parser.feed(data):
|
||||
if self.on_frame is not None:
|
||||
self.on_frame(fr) # 结构化帧(二进制载荷场景用)
|
||||
self.on_event(f'← {describe(fr)} '
|
||||
f'[{fr.raw.hex(" ").upper()}]')
|
||||
except OSError:
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user