优化ucd调用结构
This commit is contained in:
@@ -6,9 +6,8 @@
|
||||
"把模块级函数当类方法装到 PQAutomationApp 上" 的写法。
|
||||
- 拆掉 ``check_port_connection(is_ucd)`` 的布尔旗参数反模式,
|
||||
分离为 ``connect_ucd`` / ``connect_ca`` 两条独立路径。
|
||||
- UCD 这一侧不再直接调用旧 ``UCDController``,而是通过
|
||||
:class:`UCD323Device` + :class:`EventBus`;指示器更新由订阅
|
||||
:class:`ConnectionChanged` 事件触发,与 GUI 解耦。
|
||||
- UCD 经由 :class:`UCD323Device` + :class:`EventBus` 管理;
|
||||
指示灯由 GUI 订阅带 :class:`DeviceKind` 的 :class:`ConnectionChanged` 事件更新。
|
||||
|
||||
模块底部仍保留 7 个旧名字函数作为薄兼容层(``check_com_connections``
|
||||
等),供 ``pqAutomationApp.PQAutomationApp`` 类体继续以同名属性挂接,
|
||||
@@ -22,9 +21,8 @@ import time
|
||||
from tkinter import messagebox
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from app.ucd_domain import ConnectionChanged, UcdError
|
||||
from app.ucd import ConnectionChanged, DeviceKind, DeviceInfo, UCD323Device, UcdError
|
||||
from drivers.caSerail import CASerail
|
||||
from drivers.ucd_driver import DeviceInfo
|
||||
from app.views.modern_styles import get_theme_palette
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
@@ -34,8 +32,7 @@ if TYPE_CHECKING:
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from app.ucd_domain import EventBus
|
||||
from drivers.ucd_driver import UCD323Device
|
||||
from app.ucd import EventBus
|
||||
|
||||
|
||||
# ─── ConnectionController ────────────────────────────────────────
|
||||
@@ -133,7 +130,7 @@ class ConnectionController:
|
||||
channel_value = self._app.ca_channel_var.get()
|
||||
ca.setChannel(f"{int(channel_value):02d}")
|
||||
self._app.ca = ca
|
||||
self._bus.publish(ConnectionChanged(True, None))
|
||||
self._bus.publish(ConnectionChanged(DeviceKind.CA, True, None))
|
||||
return True
|
||||
except Exception as exc: # noqa: BLE001
|
||||
self._log(f"CA410 连接失败: {exc}", level="error")
|
||||
@@ -147,7 +144,7 @@ class ConnectionController:
|
||||
except Exception: # noqa: BLE001
|
||||
pass
|
||||
self._app.ca = None
|
||||
self._bus.publish(ConnectionChanged(False, None))
|
||||
self._bus.publish(ConnectionChanged(DeviceKind.CA, False, None))
|
||||
self._log("CA连接已断开", level="info")
|
||||
|
||||
# -- 一次性入口 ----------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user