graph TB
subgraph UI层["UI 层 - Plugin.*"]
A["Plugin.DeviceConfig 仪器仪表注册"]
B["Plugin.DeviceDebug 硬件调试"]
B1["PowerSupplyDebugPanel"]
B2["CanDebugPanel"]
B3["PlcDebugPanel"]
end
subgraph 基础设施层["Aging.Infrastructure 共享基础设施"]
C["IDeviceManager 设备生命周期"]
D["IDeviceService 命令执行"]
E["IResourceManager 资源预约/租约"]
F["DebugSessionManager 调试会话状态机"]
G["DriverFactory 驱动工厂"]
H["IDeviceDriver CAN/ModBus/S7/SCPI/Tcp"]
end
subgraph 数据层["SQLite"]
DB1[("data.db DeviceDefinition DeviceChannel SlotDeviceMapping DeviceConfigVersion DeviceGroupTemplate")]
DB2[("debug.db debug_session debug_operation")]
end
A -->|Save/Query| DB1
B -->|读设备列表| DB1
B -->|写会话/审计| DB2
B --> B1 & B2 & B3
B -->|Connect/Command| C
C -->|Create| G
G -->|Instantiate| H
B -->|Validate maintenance| F
F -->|Reserve/Release| E
D -->|SendCommandAsync| H
最关键的设计: DeviceConfig 是生产方(写入),DeviceDebug 是消费方(读取)。
两者不通过 API 直接调用,而是通过共享的 data.db 隐式契约。
表名
谁写入
谁读取
说明
DeviceDefinition
DeviceConfig
DeviceDebug
设备主表(DeviceId / Kind / Transport / Endpoint / DriverType)
DeviceChannel
DeviceConfig
DeviceDebug
设备通道(ChannelId / Capability / 电压电流上限)
SlotDeviceMapping
DeviceConfig
DeviceDebug
Slot ↔ 设备通道 的映射表
DeviceConfigVersion
DeviceConfig
DeviceDebug
配置版本(Draft/Published/Effective)
debug_session
DeviceDebug
DeviceDebug
调试会话(含状态机数据)
debug_operation
DeviceDebug
DeviceDebug
调试操作审计日志
共享机制源码
DeviceDebug.xaml.cs 第 95 行附近:
_deviceConfigDbPath = Path.Combine(BaseFolder, "data.db"); // 与 DeviceConfig 同目录
var sqliteHelper = new SqliteHelper(_deviceConfigDbPath);
var dt = sqliteHelper.GetDataTable(
"SELECT DeviceId, Kind FROM DeviceDefinition ORDER BY DeviceId");
sequenceDiagram
participant U as 用户
participant UI as DeviceConfig UI
participant M as DeviceEditModal
participant Model as DeviceConfigModel
participant DB as data.db
U->>UI: 点击"新增设备"
UI->>M: OpenDeviceEditModal(new DeviceDefinition)
M->>M: 填表 + 通道配置
U->>M: 点击"保存"
M->>Model: SaveDevice(device)
Model->>DB: INSERT OR REPLACE DeviceDefinition
M->>Model: SaveChannel(ch)
Model->>DB: INSERT OR REPLACE DeviceChannel
M-->>UI: DialogResult = true
UI->>UI: RefreshAllData()
场景 B:调试设备(DeviceDebug)
sequenceDiagram
participant U as 用户
participant DD as DeviceDebug UI
participant SM as DebugSessionManager
participant DM as DeviceManager
participant DF as DriverFactory
participant DRV as CanDriverAdapter
participant SIM as CanSimulator
participant DB as SQLite
U->>DD: 选择 CAN-001 下拉项
DD->>DB: SELECT * FROM DeviceDefinition (读取 data.db)
DD->>SM: OpenSession(...)
SM->>DB: INSERT debug_session (state=ReadOnly)
DD->>DM: ConnectAsync("CAN-001")
DM->>DF: CreateDriver("CAN", "CAN_BUS_1:0")
DF->>DRV: new CanDriverAdapter
DRV->>SIM: ConnectAsync → 注册节点到总线
Note over DD: 加载 CanDebugPanel AutoConnectOnLoad=true
U->>DD: 进入维护模式
DD->>SM: RequestMaintenance(sessionId)
SM->>DB: UPDATE debug_session SET state=Acquiring
SM->>SM: ResourceManager.Reserve(...)
DD->>SM: ActivateMaintenance(sessionId)
SM->>DB: UPDATE debug_session SET state=MaintenanceActive
DD->>DD: LoadPanel 重新加载 CanDebugPanel.IsMaintenanceMode = true
U->>DD: 发送 CAN 帧
DD->>SM: ValidateCommand(sessionId, cmd)
SM-->>DD: true
DD->>DRV: SendCommandAsync("SEND:0x100:AA BB CC DD")
DRV->>SIM: CanNode.SendFrame(frame)
SIM-->>DRV: DriverFrameReceived (自动响应)
DRV-->>DD: 事件回调
DD->>DB: INSERT debug_operation (审计)