处理掉多余文件,修改CAN描述
This commit is contained in:
@@ -29,6 +29,9 @@ namespace UIShare.GlobalVariable
|
||||
private readonly string _scopeName;
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
|
||||
/// <summary>设备健康监控器:独立心跳检测 + 自动重连,与监控采样互不冲突</summary>
|
||||
private DeviceHealthMonitor? _healthMonitor;
|
||||
|
||||
/// <summary>按 DeviceName 索引的设备字典,便于业务层按名取实例。</summary>
|
||||
public IDictionary<string, IBaseInterface> DeviceMap { get; private set; }
|
||||
= new Dictionary<string, IBaseInterface>(StringComparer.OrdinalIgnoreCase);
|
||||
@@ -209,6 +212,30 @@ namespace UIShare.GlobalVariable
|
||||
}
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
|
||||
// 所有设备连接完成后,启动健康监控(心跳重连)
|
||||
StartHealthMonitor();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 启动设备健康监控器:周期性检查设备连接状态,断连自动重连。
|
||||
/// 与 HardwareDataBroadcaster 的监控采样互不干扰。
|
||||
/// </summary>
|
||||
private void StartHealthMonitor()
|
||||
{
|
||||
if (_healthMonitor != null || DeviceMap.Count == 0) return;
|
||||
|
||||
_healthMonitor = new DeviceHealthMonitor(DeviceMap, _systemConfig, _scopeName);
|
||||
_healthMonitor.Start();
|
||||
LoggerHelper.Info($"[{_scopeName}] 心跳重连机制已激活");
|
||||
}
|
||||
|
||||
/// <summary>停止设备健康监控器</summary>
|
||||
private void StopHealthMonitor()
|
||||
{
|
||||
_healthMonitor?.Stop();
|
||||
_healthMonitor?.Dispose();
|
||||
_healthMonitor = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -277,6 +304,9 @@ namespace UIShare.GlobalVariable
|
||||
/// </summary>
|
||||
public async Task CloseAllDevicesAsync()
|
||||
{
|
||||
// 先停止健康监控,避免重连定时器与关闭操作冲突
|
||||
StopHealthMonitor();
|
||||
|
||||
List<Task> tasks = new List<Task>();
|
||||
|
||||
lock (_lockObj)
|
||||
@@ -523,6 +553,9 @@ namespace UIShare.GlobalVariable
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// 停止健康监控
|
||||
StopHealthMonitor();
|
||||
|
||||
// 停止 CAN 信号监测服务
|
||||
_CANMonitoringService?.Stop();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user