io板卡兼容优化

This commit is contained in:
hsc
2026-07-20 15:45:36 +08:00
parent 48492973c3
commit 7f2721ab11
6 changed files with 224 additions and 36 deletions

View File

@@ -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)

View File

@@ -568,6 +568,10 @@ namespace UIShare
{
instance = _deviceManager.CANFD;
}
else if (targetType.Name == "IOBoardGroup")
{
instance = _deviceManager.IOGroup;
}
else instance = _deviceManager.DeviceMap[targetType.Name];
}
catch (Exception ex)

View File

@@ -47,15 +47,7 @@ namespace UIShare.GlobalVariable
{
Category = ParameterCategory.Input,
Type = typeof(int),
Name = "单相充电",
Value = 0,
IsEditable=false
},
new ParameterVM
{
Category = ParameterCategory.Input,
Type = typeof(int),
Name = "抛负载",
Name = "台架序号",
Value = 1,
IsEditable=false
},
@@ -63,22 +55,15 @@ namespace UIShare.GlobalVariable
{
Category = ParameterCategory.Input,
Type = typeof(int),
Name = "短路测试",
Value = 0,
IsEditable=false
}, new ParameterVM
{
Category = ParameterCategory.Input,
Type = typeof(int),
Name = "初始化供电",
Value = 0,
Name = "直流负载通道",
Value = 1,
IsEditable=false
},
new ParameterVM
new ParameterVM
{
Category = ParameterCategory.Input,
Type = typeof(int),
Name = "蜂鸣器",
Name = "交流电源通道",
Value = 1,
IsEditable=false
},
@@ -94,7 +79,15 @@ namespace UIShare.GlobalVariable
{
Category = ParameterCategory.Input,
Type = typeof(int),
Name = "示波器通道",
Name = "示波器通道1",
Value = 0,
IsEditable=false
},
new ParameterVM
{
Category = ParameterCategory.Input,
Type = typeof(int),
Name = "示波器通道2",
Value = 0,
IsEditable=false
},