将Feature/XP.Common和Feature/XP.Hardware分支合并至Develop/XP.forHardwareAndCommon,完善XPapp注册和相关硬件类库通用类库功能。
This commit is contained in:
@@ -0,0 +1,262 @@
|
||||
using System;
|
||||
using XP.Common.Logging.Interfaces;
|
||||
using XP.Hardware.RaySource.Abstractions;
|
||||
|
||||
namespace XP.Hardware.RaySource.Implementations
|
||||
{
|
||||
/// <summary>
|
||||
/// Comet 225kV 射线源适配器
|
||||
/// 通过 CometIpcClient 和 CometHostManager 实现进程外隔离的 PVI 通信
|
||||
/// 所有操作委托给 CometIpcClient,Host 进程生命周期由 CometHostManager 管理
|
||||
/// </summary>
|
||||
public class Comet225RaySource : XRaySourceBase
|
||||
{
|
||||
#region 依赖注入字段
|
||||
|
||||
private readonly CometHostManager _hostManager;
|
||||
private readonly CometIpcClient _ipcClient;
|
||||
private readonly ILoggerService _logger;
|
||||
|
||||
#endregion
|
||||
|
||||
#region 构造函数
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数,注入依赖
|
||||
/// </summary>
|
||||
/// <param name="hostManager">Host 进程生命周期管理器</param>
|
||||
/// <param name="ipcClient">IPC 客户端,负责与 Host 进程通信</param>
|
||||
/// <param name="loggerService">日志服务</param>
|
||||
public Comet225RaySource(
|
||||
CometHostManager hostManager,
|
||||
CometIpcClient ipcClient,
|
||||
ILoggerService loggerService)
|
||||
{
|
||||
_hostManager = hostManager ?? throw new ArgumentNullException(nameof(hostManager));
|
||||
_ipcClient = ipcClient ?? throw new ArgumentNullException(nameof(ipcClient));
|
||||
_logger = loggerService?.ForModule<Comet225RaySource>() ?? throw new ArgumentNullException(nameof(loggerService));
|
||||
}
|
||||
|
||||
public override string SourceName => "Comet 225kV";
|
||||
|
||||
#endregion
|
||||
|
||||
#region IXRaySource 方法实现 - 委托给 CometIpcClient
|
||||
|
||||
/// <summary>
|
||||
/// 初始化射线源
|
||||
/// 先确保 Host 进程运行,再通过 IPC 客户端初始化 PVI 连接
|
||||
/// </summary>
|
||||
public override XRayResult Initialize()
|
||||
{
|
||||
_logger.Info("初始化 Comet225 射线源(IPC 模式)");
|
||||
try
|
||||
{
|
||||
// 先确保 Host 进程运行
|
||||
_hostManager.EnsureRunning();
|
||||
_logger.Info("Host 进程已就绪,开始 IPC 初始化");
|
||||
|
||||
// 再通过 IPC 客户端初始化
|
||||
var result = _ipcClient.Initialize();
|
||||
if (result.Success)
|
||||
{
|
||||
_isInitialized = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex, "初始化 Comet225 射线源异常:{Message}", ex.Message);
|
||||
return XRayResult.Error($"初始化异常:{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建和连接 PVI 变量
|
||||
/// </summary>
|
||||
public override XRayResult ConnectVariables()
|
||||
{
|
||||
var result = _ipcClient.ConnectVariables();
|
||||
if (result.Success)
|
||||
{
|
||||
_isConnected = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开启射线源高压
|
||||
/// </summary>
|
||||
public override XRayResult TurnOn()
|
||||
{
|
||||
return _ipcClient.TurnOn();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭射线源高压
|
||||
/// </summary>
|
||||
public override XRayResult TurnOff()
|
||||
{
|
||||
return _ipcClient.TurnOff();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置电压值
|
||||
/// </summary>
|
||||
public override XRayResult SetVoltage(float voltage)
|
||||
{
|
||||
return _ipcClient.SetVoltage(voltage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置电流值
|
||||
/// </summary>
|
||||
public override XRayResult SetCurrent(float current)
|
||||
{
|
||||
return _ipcClient.SetCurrent(current);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置焦点 - Comet 225kV 不支持
|
||||
/// </summary>
|
||||
public override XRayResult SetFocus(float focus)
|
||||
{
|
||||
return _ipcClient.SetFocus(focus);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取当前电压反馈值
|
||||
/// </summary>
|
||||
public override XRayResult ReadVoltage()
|
||||
{
|
||||
return _ipcClient.ReadVoltage();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取当前电流反馈值
|
||||
/// </summary>
|
||||
public override XRayResult ReadCurrent()
|
||||
{
|
||||
return _ipcClient.ReadCurrent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取系统状态
|
||||
/// </summary>
|
||||
public override XRayResult ReadSystemStatus()
|
||||
{
|
||||
return _ipcClient.ReadSystemStatus();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查错误状态
|
||||
/// </summary>
|
||||
public override XRayResult CheckErrors()
|
||||
{
|
||||
return _ipcClient.CheckErrors();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TXI 开启
|
||||
/// </summary>
|
||||
public override XRayResult TxiOn()
|
||||
{
|
||||
return _ipcClient.TxiOn();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TXI 关闭
|
||||
/// </summary>
|
||||
public override XRayResult TxiOff()
|
||||
{
|
||||
return _ipcClient.TxiOff();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 暖机设置
|
||||
/// </summary>
|
||||
public override XRayResult WarmUp()
|
||||
{
|
||||
return _ipcClient.WarmUp();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 训机设置
|
||||
/// </summary>
|
||||
public override XRayResult Training()
|
||||
{
|
||||
return _ipcClient.Training();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 灯丝校准
|
||||
/// </summary>
|
||||
public override XRayResult FilamentCalibration()
|
||||
{
|
||||
return _ipcClient.FilamentCalibration();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 全部电压自动定心
|
||||
/// </summary>
|
||||
public override XRayResult AutoCenter()
|
||||
{
|
||||
return _ipcClient.AutoCenter();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置功率模式
|
||||
/// </summary>
|
||||
public override XRayResult SetPowerMode(int mode)
|
||||
{
|
||||
return _ipcClient.SetPowerMode(mode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭射线源,释放 IPC 连接并关闭 Host 进程
|
||||
/// </summary>
|
||||
public override XRayResult CloseOff()
|
||||
{
|
||||
_logger.Info("执行 CloseOff 操作(IPC 模式)");
|
||||
try
|
||||
{
|
||||
// 先通过 IPC 客户端发送断开命令
|
||||
var result = _ipcClient.CloseOff();
|
||||
|
||||
// 再关闭 Host 进程
|
||||
_hostManager.Shutdown();
|
||||
|
||||
_isInitialized = false;
|
||||
_isConnected = false;
|
||||
_logger.Info("CloseOff 操作完成");
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warn("CloseOff 过程中发生异常:{Message}", ex.Message);
|
||||
_isInitialized = false;
|
||||
_isConnected = false;
|
||||
return XRayResult.Error($"CloseOff 异常:{ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 资源释放
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源,清理 IPC 客户端和 Host 进程管理器
|
||||
/// </summary>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (!_isDisposed && disposing)
|
||||
{
|
||||
_ipcClient?.Dispose();
|
||||
_hostManager?.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user