虚拟探测器与实时切换按钮的绑定

This commit is contained in:
zhengxuan.zhang
2026-05-15 16:51:21 +08:00
parent 8e9ef312ad
commit e9d388beb2
10 changed files with 153 additions and 19 deletions
+34 -8
View File
@@ -38,6 +38,7 @@ namespace XP.Hardware.Detector.Config
{
DetectorType.Varex => LoadVarexConfiguration(),
DetectorType.IRay => LoadIRayConfiguration(),
DetectorType.Simulated => LoadSimulatedConfiguration(),
_ => throw new NotSupportedException($"不支持的探测器类型:{detectorType} | Unsupported detector type: {detectorType}")
};
@@ -111,6 +112,27 @@ namespace XP.Hardware.Detector.Config
return config;
}
/// <summary>
/// 加载软件模拟探测器配置 | Load simulated detector configuration
/// </summary>
private static SimulatedDetectorConfig LoadSimulatedConfiguration()
{
var config = new SimulatedDetectorConfig();
if (int.TryParse(ConfigurationManager.AppSettings["Detector:Simulated:Width"], out var w) && w > 0)
config.Width = w;
if (int.TryParse(ConfigurationManager.AppSettings["Detector:Simulated:Height"], out var h) && h > 0)
config.Height = h;
if (double.TryParse(ConfigurationManager.AppSettings["Detector:Simulated:FrameRateFps"],
System.Globalization.NumberStyles.Any,
System.Globalization.CultureInfo.InvariantCulture, out var fps) && fps > 0)
config.FrameRateFps = fps;
return config;
}
/// <summary>
/// 加载 iRay 配置 | Load iRay configuration
/// </summary>
@@ -208,16 +230,20 @@ namespace XP.Hardware.Detector.Config
/// </summary>
private static DetectorResult ValidateConfiguration(DetectorConfig config)
{
// 验证 IP 地址 | Validate IP address
if (!IPAddress.TryParse(config.IP, out _))
// 模拟探测器不需要网络连接,跳过 IP/端口验证 | Simulated detector skips IP/port validation
if (config.Type != DetectorType.Simulated)
{
return DetectorResult.Failure($"无效的 IP 地址:{config.IP} | Invalid IP address: {config.IP}");
}
// 验证 IP 地址 | Validate IP address
if (!IPAddress.TryParse(config.IP, out _))
{
return DetectorResult.Failure($"无效的 IP 地址:{config.IP} | Invalid IP address: {config.IP}");
}
// 验证端口范围 | Validate port range
if (config.Port < 1 || config.Port > 65535)
{
return DetectorResult.Failure($"无效的端口号:{config.Port},必须在 1-65535 之间 | Invalid port: {config.Port}, must be between 1-65535");
// 验证端口范围 | Validate port range
if (config.Port < 1 || config.Port > 65535)
{
return DetectorResult.Failure($"无效的端口号:{config.Port},必须在 1-65535 之间 | Invalid port: {config.Port}, must be between 1-65535");
}
}
// 验证存储路径 | Validate save path