io板卡兼容优化
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using DeviceCommand.Base;
|
||||
using DeviceCommand.Device;
|
||||
using DeviceCommand.Devices;
|
||||
using Logger;
|
||||
using Model.Models;
|
||||
using Prism.Events;
|
||||
@@ -34,6 +36,7 @@ namespace UIShare.GlobalVariable
|
||||
/// <summary>类名 → Type 的反射缓存(仅扫描一次)。</summary>
|
||||
private static readonly IReadOnlyDictionary<string, Type> _deviceTypeMap = BuildDeviceTypeMap();
|
||||
public ZLGCANFD CANFD { get; set; }
|
||||
public IOBoardGroup IOGroup { get; set; }
|
||||
|
||||
public DeviceManager(SystemConfig systemConfig, GlobalInfo globalInfo, IEventAggregator eventAggregator)
|
||||
{
|
||||
@@ -207,6 +210,25 @@ namespace UIShare.GlobalVariable
|
||||
LoggerHelper.ErrorWithNotify(_scopeName, $"设备 [{config.DeviceName}] 实例化失败:{inner}");
|
||||
}
|
||||
}
|
||||
|
||||
// IOGroup 初始化:从已实例化的设备中取出前两个 IOBoard 实例组建 IOBoardGroup
|
||||
try
|
||||
{
|
||||
var ioBoards = DeviceMap.Values.OfType<IOBoard>().Take(2).ToList();
|
||||
if (ioBoards.Count == 2)
|
||||
{
|
||||
IOGroup = new IOBoardGroup(ioBoards[0], ioBoards[1]);
|
||||
LoggerHelper.Info($"IOBoardGroup 已初始化,Board1={ioBoards[0].GetType().Name}, Board2={ioBoards[1].GetType().Name}。");
|
||||
}
|
||||
else
|
||||
{
|
||||
LoggerHelper.Warn($"IOBoardGroup 初始化跳过:需要 2 个 IOBoard 实例,当前仅找到 {ioBoards.Count} 个。");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LoggerHelper.ErrorWithNotify(_scopeName, $"IOBoardGroup 初始化失败:{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task ConnectAllDevices(CancellationToken ct = default)
|
||||
@@ -407,12 +429,16 @@ namespace UIShare.GlobalVariable
|
||||
|
||||
private static async Task<bool> ConnectTcpAsync(string name, IBaseInterface device, CancellationToken ct)
|
||||
{
|
||||
if (device is not ITcp tcp)
|
||||
if (device is ITcp tcp)
|
||||
{
|
||||
LoggerHelper.Warn($"设备 [{name}] 配置为 Tcp 但未实现 ITcp,实际类型为 {device.GetType().Name}。");
|
||||
return false;
|
||||
return await tcp.ConnectAsync(ct);
|
||||
}
|
||||
return await tcp.ConnectAsync(ct);
|
||||
if (device is IModbusDevice modbusTCP)
|
||||
{
|
||||
return await modbusTCP.ConnectAsync(ct);
|
||||
}
|
||||
LoggerHelper.Warn($"设备 [{name}] 配置为 Tcp 但未实现 ITcp,实际类型为 {device.GetType().Name}。");
|
||||
return false;
|
||||
}
|
||||
|
||||
private static async Task<bool> ConnectSerialAsync(string name, IBaseInterface device, CancellationToken ct)
|
||||
|
||||
Reference in New Issue
Block a user