将Feature/XP.Common和Feature/XP.Hardware分支合并至Develop/XP.forHardwareAndCommon,完善XPapp注册和相关硬件类库通用类库功能。
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using XP.Common.Logging.Interfaces;
|
||||
using XP.Hardware.MotionControl.Abstractions.Enums;
|
||||
|
||||
namespace XP.Hardware.MotionControl.Config
|
||||
{
|
||||
/// <summary>
|
||||
/// 运动控制配置加载器 | Motion Control Configuration Loader
|
||||
/// 从 App.config 加载轴范围、几何原点和运行参数(PLC 信号名称已硬编码在 MotionSignalNames 中)
|
||||
/// Loads axis ranges, geometry origins and runtime params from App.config (PLC signal names hardcoded in MotionSignalNames)
|
||||
/// </summary>
|
||||
public class ConfigLoader
|
||||
{
|
||||
private const string P = "MotionControl";
|
||||
|
||||
/// <summary>
|
||||
/// 加载运动控制配置 | Load motion control configuration
|
||||
/// </summary>
|
||||
public static MotionControlConfig LoadConfig(string configFilePath = null, ILoggerService logger = null)
|
||||
{
|
||||
var config = new MotionControlConfig();
|
||||
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(configFilePath) && File.Exists(configFilePath))
|
||||
{
|
||||
var fileMap = new ExeConfigurationFileMap { ExeConfigFilename = configFilePath };
|
||||
var cfg = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
|
||||
LoadAll(config, (k, d) => cfg.AppSettings.Settings[k]?.Value ?? d);
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadAll(config, (k, d) => ConfigurationManager.AppSettings[k] ?? d);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger?.Error(ex, "运动控制配置加载失败,使用默认值 | MotionControl config load failed, using defaults: {Message}", ex.Message);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
private static void LoadAll(MotionControlConfig config, Func<string, string, string> get)
|
||||
{
|
||||
// 直线轴 | Linear axes
|
||||
config.LinearAxes[AxisId.SourceZ] = LoadLinear("SourceZ", get);
|
||||
config.LinearAxes[AxisId.DetectorZ] = LoadLinear("DetectorZ", get);
|
||||
config.LinearAxes[AxisId.StageX] = LoadLinear("StageX", get);
|
||||
config.LinearAxes[AxisId.StageY] = LoadLinear("StageY", get);
|
||||
|
||||
// 旋转轴 | Rotary axes
|
||||
config.RotaryAxes[RotaryAxisId.DetectorSwing] = LoadRotary("DetectorSwing", get);
|
||||
config.RotaryAxes[RotaryAxisId.StageRotation] = LoadRotary("StageRotation", get);
|
||||
config.RotaryAxes[RotaryAxisId.FixtureRotation] = LoadRotary("FixtureRotation", get);
|
||||
|
||||
// 几何原点 | Geometry origins
|
||||
config.Geometry.SourceZOrigin = Dbl(get($"{P}:Geometry:SourceZOrigin", "0"));
|
||||
config.Geometry.DetectorZOrigin = Dbl(get($"{P}:Geometry:DetectorZOrigin", "0"));
|
||||
config.Geometry.StageRotationCenterZ = Dbl(get($"{P}:Geometry:StageRotationCenterZ", "0"));
|
||||
config.Geometry.SwingPivotOffset = Dbl(get($"{P}:Geometry:SwingPivotOffset", "0"));
|
||||
config.Geometry.SwingRadius = Dbl(get($"{P}:Geometry:SwingRadius", "0"));
|
||||
|
||||
// 运行参数 | Runtime parameters
|
||||
config.PollingInterval = Int(get($"{P}:PollingInterval", "100"));
|
||||
config.DefaultVelocity = Int(get($"{P}:DefaultVelocity", "100"));
|
||||
}
|
||||
|
||||
private static LinearAxisConfig LoadLinear(string name, Func<string, string, string> get)
|
||||
{
|
||||
var p = $"{P}:{name}:";
|
||||
return new LinearAxisConfig
|
||||
{
|
||||
Min = Dbl(get(p + "Min", "0")),
|
||||
Max = Dbl(get(p + "Max", "0")),
|
||||
Origin = Dbl(get(p + "Origin", "0"))
|
||||
};
|
||||
}
|
||||
|
||||
private static RotaryAxisConfig LoadRotary(string name, Func<string, string, string> get)
|
||||
{
|
||||
var p = $"{P}:{name}:";
|
||||
return new RotaryAxisConfig
|
||||
{
|
||||
Min = Dbl(get(p + "Min", "0")),
|
||||
Max = Dbl(get(p + "Max", "0")),
|
||||
Origin = Dbl(get(p + "Origin", "0")),
|
||||
Enabled = bool.TryParse(get(p + "Enabled", "true"), out var e) && e
|
||||
};
|
||||
}
|
||||
|
||||
private static double Dbl(string v) => double.TryParse(v, out var r) ? r : 0;
|
||||
private static int Int(string v) => int.TryParse(v, out var r) ? r : 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
using System.Collections.Generic;
|
||||
using XP.Hardware.MotionControl.Abstractions.Enums;
|
||||
|
||||
namespace XP.Hardware.MotionControl.Config
|
||||
{
|
||||
/// <summary>
|
||||
/// 运动控制配置实体 | Motion Control Configuration Entity
|
||||
/// 包含所有轴、安全门、几何原点和运行参数的配置 | Contains all axis, safety door, geometry origin and runtime parameter configurations
|
||||
/// </summary>
|
||||
public class MotionControlConfig
|
||||
{
|
||||
/// <summary>直线轴配置字典 | Linear axis configurations</summary>
|
||||
public Dictionary<AxisId, LinearAxisConfig> LinearAxes { get; set; } = new();
|
||||
|
||||
/// <summary>旋转轴配置字典 | Rotary axis configurations</summary>
|
||||
public Dictionary<RotaryAxisId, RotaryAxisConfig> RotaryAxes { get; set; } = new();
|
||||
|
||||
/// <summary>几何原点配置 | Geometry origin configuration</summary>
|
||||
public GeometryConfig Geometry { get; set; } = new();
|
||||
|
||||
/// <summary>轮询周期(ms)| Polling interval (ms)</summary>
|
||||
public int PollingInterval { get; set; } = 100;
|
||||
|
||||
/// <summary>默认速度| Default velocity</summary>
|
||||
public int DefaultVelocity { get; set; } = 100;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 直线轴配置 | Linear Axis Configuration
|
||||
/// 每个直线轴包含运动范围、原点偏移 | Each linear axis contains motion range, origin offset
|
||||
/// </summary>
|
||||
public class LinearAxisConfig
|
||||
{
|
||||
/// <summary>最小位置(mm)| Minimum position (mm)</summary>
|
||||
public double Min { get; set; }
|
||||
|
||||
/// <summary>最大位置(mm)| Maximum position (mm)</summary>
|
||||
public double Max { get; set; }
|
||||
|
||||
/// <summary>原点偏移(mm)| Origin offset (mm)</summary>
|
||||
public double Origin { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 旋转轴配置 | Rotary Axis Configuration
|
||||
/// 每个旋转轴包含角度范围、原点偏移、启用标志 | Each rotary axis contains angle range, origin offset, enabled flag
|
||||
/// </summary>
|
||||
public class RotaryAxisConfig
|
||||
{
|
||||
/// <summary>最小角度(度)| Minimum angle (degrees)</summary>
|
||||
public double Min { get; set; }
|
||||
|
||||
/// <summary>最大角度(度)| Maximum angle (degrees)</summary>
|
||||
public double Max { get; set; }
|
||||
|
||||
/// <summary>原点偏移(度)| Origin offset (degrees)</summary>
|
||||
public double Origin { get; set; }
|
||||
|
||||
/// <summary>是否启用 | Is enabled</summary>
|
||||
public bool Enabled { get; set; } = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 几何原点配置 | Geometry Origin Configuration
|
||||
/// 包含射线源、探测器和旋转中心的原点参数 | Contains origin parameters for source, detector and rotation center
|
||||
/// </summary>
|
||||
public class GeometryConfig
|
||||
{
|
||||
/// <summary>射线源Z轴原点偏移(mm)| Source Z origin offset (mm)</summary>
|
||||
public double SourceZOrigin { get; set; }
|
||||
|
||||
/// <summary>探测器Z轴原点偏移(mm)| Detector Z origin offset (mm)</summary>
|
||||
public double DetectorZOrigin { get; set; }
|
||||
|
||||
/// <summary>旋转中心绝对Z坐标(mm,固定值)| Stage rotation center absolute Z (mm, fixed)</summary>
|
||||
public double StageRotationCenterZ { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 探测器摆动旋转中心(Pivot)相对于 DetectorZ 绝对坐标的 Z 方向偏移(mm)
|
||||
/// Detector swing pivot Z offset relative to DetectorZ absolute coordinate (mm)
|
||||
/// 正值表示 Pivot 在 DetectorZ_abs 下方(朝向射线源方向)| Positive means Pivot is below DetectorZ_abs (toward source)
|
||||
/// </summary>
|
||||
public double SwingPivotOffset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 探测器摆动半径(mm):Pivot 到探测器感光面中心的距离
|
||||
/// Detector swing radius (mm): distance from Pivot to detector active area center
|
||||
/// 当值为 0 时退化为无摆动模型 | When 0, degrades to non-swing model
|
||||
/// </summary>
|
||||
public double SwingRadius { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
namespace XP.Hardware.MotionControl.Config
|
||||
{
|
||||
/// <summary>
|
||||
/// 运动控制 PLC 信号名称常量 | Motion Control PLC Signal Name Constants
|
||||
/// 信号定义在 PlcAddrDfn.xml 中,此处硬编码名称供代码引用 | Signal definitions in PlcAddrDfn.xml, hardcoded names for code reference
|
||||
/// </summary>
|
||||
public static class MotionSignalNames
|
||||
{
|
||||
// ==================== 直线轴 SourceZ | Linear Axis SourceZ ====================
|
||||
public const string SourceZ_Pos = "MC_SourceZ_Pos";
|
||||
public const string SourceZ_Target = "MC_SourceZ_Target";
|
||||
public const string SourceZ_Speed = "MC_SourceZ_Speed";
|
||||
public const string SourceZ_JogPos = "MC_SourceZ_JogPos";
|
||||
public const string SourceZ_JogNeg = "MC_SourceZ_JogNeg";
|
||||
public const string SourceZ_Home = "MC_SourceZ_Home";
|
||||
public const string SourceZ_Stop = "MC_SourceZ_Stop";
|
||||
|
||||
// ==================== 直线轴 DetectorZ | Linear Axis DetectorZ ====================
|
||||
public const string DetZ_Pos = "MC_DetZ_Pos";
|
||||
public const string DetZ_Target = "MC_DetZ_Target";
|
||||
public const string DetZ_Speed = "MC_DetZ_Speed";
|
||||
public const string DetZ_JogPos = "MC_DetZ_JogPos";
|
||||
public const string DetZ_JogNeg = "MC_DetZ_JogNeg";
|
||||
public const string DetZ_Home = "MC_DetZ_Home";
|
||||
public const string DetZ_Stop = "MC_DetZ_Stop";
|
||||
|
||||
// ==================== 直线轴 StageX | Linear Axis StageX ====================
|
||||
public const string StageX_Pos = "MC_StageX_Pos";
|
||||
public const string StageX_Target = "MC_StageX_Target";
|
||||
public const string StageX_Speed = "MC_StageX_Speed";
|
||||
public const string StageX_JogPos = "MC_StageX_JogPos";
|
||||
public const string StageX_JogNeg = "MC_StageX_JogNeg";
|
||||
public const string StageX_Home = "MC_StageX_Home";
|
||||
public const string StageX_Stop = "MC_StageX_Stop";
|
||||
|
||||
// ==================== 直线轴 StageY | Linear Axis StageY ====================
|
||||
public const string StageY_Pos = "MC_StageY_Pos";
|
||||
public const string StageY_Target = "MC_StageY_Target";
|
||||
public const string StageY_Speed = "MC_StageY_Speed";
|
||||
public const string StageY_JogPos = "MC_StageY_JogPos";
|
||||
public const string StageY_JogNeg = "MC_StageY_JogNeg";
|
||||
public const string StageY_Home = "MC_StageY_Home";
|
||||
public const string StageY_Stop = "MC_StageY_Stop";
|
||||
|
||||
// ==================== 旋转轴 DetectorSwing | Rotary Axis DetectorSwing ====================
|
||||
public const string DetSwing_Angle = "MC_DetSwing_Angle";
|
||||
public const string DetSwing_Target = "MC_DetSwing_Target";
|
||||
public const string DetSwing_Speed = "MC_DetSwing_Speed";
|
||||
public const string DetSwing_JogPos = "MC_DetSwing_JogPos";
|
||||
public const string DetSwing_JogNeg = "MC_DetSwing_JogNeg";
|
||||
public const string DetSwing_Home = "MC_DetSwing_Home";
|
||||
public const string DetSwing_Stop = "MC_DetSwing_Stop";
|
||||
|
||||
// ==================== 旋转轴 StageRotation | Rotary Axis StageRotation ====================
|
||||
public const string StageRot_Angle = "MC_StageRot_Angle";
|
||||
public const string StageRot_Target = "MC_StageRot_Target";
|
||||
public const string StageRot_Speed = "MC_StageRot_Speed";
|
||||
public const string StageRot_JogPos = "MC_StageRot_JogPos";
|
||||
public const string StageRot_JogNeg = "MC_StageRot_JogNeg";
|
||||
public const string StageRot_Home = "MC_StageRot_Home";
|
||||
public const string StageRot_Stop = "MC_StageRot_Stop";
|
||||
|
||||
// ==================== 旋转轴 FixtureRotation | Rotary Axis FixtureRotation ====================
|
||||
public const string FixRot_Angle = "MC_FixRot_Angle";
|
||||
public const string FixRot_Target = "MC_FixRot_Target";
|
||||
public const string FixRot_Speed = "MC_FixRot_Speed";
|
||||
public const string FixRot_JogPos = "MC_FixRot_JogPos";
|
||||
public const string FixRot_JogNeg = "MC_FixRot_JogNeg";
|
||||
public const string FixRot_Home = "MC_FixRot_Home";
|
||||
public const string FixRot_Stop = "MC_FixRot_Stop";
|
||||
|
||||
// ==================== 安全门 | Safety Door ====================
|
||||
public const string Door_Open = "MC_Door_Open";
|
||||
public const string Door_Close = "MC_Door_Close";
|
||||
public const string Door_Stop = "MC_Door_Stop";
|
||||
public const string Door_Status = "MC_Door_Status";
|
||||
public const string Door_Interlock = "MC_Door_Interlock";
|
||||
|
||||
// ==================== 轴复位 | Axis Reset ====================
|
||||
/// <summary>轴复位命令(写入)| Axis reset command (write)</summary>
|
||||
public const string Axis_Reset = "MC_Axis_Reset";
|
||||
/// <summary>轴复位完成(读取)| Axis reset done (read)</summary>
|
||||
public const string Axis_ResetDone = "MC_Axis_ResetDone";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user