将Feature/XP.Common和Feature/XP.Hardware分支合并至Develop/XP.forHardwareAndCommon,完善XPapp注册和相关硬件类库通用类库功能。
This commit is contained in:
@@ -0,0 +1,533 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Prism.Events;
|
||||
using XP.Hardware.Detector.Abstractions.Enums;
|
||||
using XP.Hardware.Detector.Abstractions.Events;
|
||||
|
||||
namespace XP.Hardware.Detector.Abstractions
|
||||
{
|
||||
/// <summary>
|
||||
/// 面阵探测器抽象基类 | Area detector abstract base class
|
||||
/// 封装通用逻辑:参数校验、状态更新、事件发布
|
||||
/// 使用模板方法模式,子类实现具体的硬件操作
|
||||
/// </summary>
|
||||
public abstract class AreaDetectorBase : IAreaDetector
|
||||
{
|
||||
protected readonly IEventAggregator _eventAggregator;
|
||||
protected readonly object _statusLock = new object();
|
||||
protected DetectorStatus _status = DetectorStatus.Uninitialized;
|
||||
protected bool _disposed = false;
|
||||
|
||||
/// <summary>
|
||||
/// 探测器状态 | Detector status
|
||||
/// </summary>
|
||||
public DetectorStatus Status
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_statusLock)
|
||||
{
|
||||
return _status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 探测器类型 | Detector type
|
||||
/// </summary>
|
||||
public abstract DetectorType Type { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数 | Constructor
|
||||
/// </summary>
|
||||
/// <param name="eventAggregator">事件聚合器 | Event aggregator</param>
|
||||
protected AreaDetectorBase(IEventAggregator eventAggregator)
|
||||
{
|
||||
_eventAggregator = eventAggregator ?? throw new ArgumentNullException(nameof(eventAggregator));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化探测器 | Initialize detector
|
||||
/// </summary>
|
||||
public async Task<DetectorResult> InitializeAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
// 参数校验 | Parameter validation
|
||||
if (Status != DetectorStatus.Uninitialized)
|
||||
{
|
||||
return DetectorResult.Failure("探测器已初始化 | Detector already initialized");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 更新状态 | Update status
|
||||
UpdateStatus(DetectorStatus.Initializing);
|
||||
|
||||
// 调用子类实现 | Call derived class implementation
|
||||
var result = await InitializeInternalAsync(cancellationToken);
|
||||
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
UpdateStatus(DetectorStatus.Ready);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateStatus(DetectorStatus.Error);
|
||||
PublishError(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
UpdateStatus(DetectorStatus.Error);
|
||||
var errorResult = DetectorResult.Failure($"初始化异常 | Initialization exception: {ex.Message}", ex);
|
||||
PublishError(errorResult);
|
||||
return errorResult;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 启动连续采集 | Start continuous acquisition
|
||||
/// </summary>
|
||||
public async Task<DetectorResult> StartAcquisitionAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
// 参数校验 | Parameter validation
|
||||
if (Status != DetectorStatus.Ready)
|
||||
{
|
||||
return DetectorResult.Failure($"探测器状态不正确,当前状态:{Status} | Detector status incorrect, current status: {Status}");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 更新状态 | Update status
|
||||
UpdateStatus(DetectorStatus.Acquiring);
|
||||
|
||||
// 调用子类实现 | Call derived class implementation
|
||||
var result = await StartAcquisitionInternalAsync(cancellationToken);
|
||||
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
UpdateStatus(DetectorStatus.Ready);
|
||||
PublishError(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
UpdateStatus(DetectorStatus.Error);
|
||||
var errorResult = DetectorResult.Failure($"启动采集异常 | Start acquisition exception: {ex.Message}", ex);
|
||||
PublishError(errorResult);
|
||||
return errorResult;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 停止采集 | Stop acquisition
|
||||
/// </summary>
|
||||
public async Task<DetectorResult> StopAcquisitionAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
// 参数校验 | Parameter validation
|
||||
// 未初始化时不允许停止采集操作 | Stop acquisition not allowed when uninitialized
|
||||
if (Status == DetectorStatus.Uninitialized)
|
||||
{
|
||||
return DetectorResult.Failure("探测器未初始化,无法执行停止采集操作 | Detector not initialized, cannot stop acquisition");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 调用子类实现 | Call derived class implementation
|
||||
var result = await StopAcquisitionInternalAsync(cancellationToken);
|
||||
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
UpdateStatus(DetectorStatus.Ready);
|
||||
}
|
||||
else
|
||||
{
|
||||
PublishError(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
UpdateStatus(DetectorStatus.Error);
|
||||
var errorResult = DetectorResult.Failure($"停止采集异常 | Stop acquisition exception: {ex.Message}", ex);
|
||||
PublishError(errorResult);
|
||||
return errorResult;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 单帧采集 | Single frame acquisition
|
||||
/// </summary>
|
||||
public async Task<DetectorResult> AcquireSingleFrameAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
// 参数校验 | Parameter validation
|
||||
if (Status != DetectorStatus.Ready)
|
||||
{
|
||||
return DetectorResult.Failure($"探测器状态不正确,当前状态:{Status} | Detector status incorrect, current status: {Status}");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 更新状态 | Update status
|
||||
UpdateStatus(DetectorStatus.Acquiring);
|
||||
|
||||
// 调用子类实现 | Call derived class implementation
|
||||
var result = await AcquireSingleFrameInternalAsync(cancellationToken);
|
||||
|
||||
// 恢复状态 | Restore status
|
||||
UpdateStatus(DetectorStatus.Ready);
|
||||
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
PublishError(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
UpdateStatus(DetectorStatus.Error);
|
||||
var errorResult = DetectorResult.Failure($"单帧采集异常 | Single frame acquisition exception: {ex.Message}", ex);
|
||||
PublishError(errorResult);
|
||||
return errorResult;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 暗场校正 | Dark field correction
|
||||
/// </summary>
|
||||
public async Task<DetectorResult> DarkCorrectionAsync(int frameCount, CancellationToken cancellationToken = default)
|
||||
{
|
||||
// 参数校验 | Parameter validation
|
||||
if (Status != DetectorStatus.Ready)
|
||||
{
|
||||
return DetectorResult.Failure($"探测器状态不正确,当前状态:{Status} | Detector status incorrect, current status: {Status}");
|
||||
}
|
||||
|
||||
if (frameCount <= 0)
|
||||
{
|
||||
return DetectorResult.Failure("帧数必须大于 0 | Frame count must be greater than 0");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 更新状态 | Update status
|
||||
UpdateStatus(DetectorStatus.Correcting);
|
||||
|
||||
// 调用子类实现 | Call derived class implementation
|
||||
var result = await DarkCorrectionInternalAsync(frameCount, cancellationToken);
|
||||
|
||||
// 恢复状态 | Restore status
|
||||
UpdateStatus(DetectorStatus.Ready);
|
||||
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
PublishCorrectionCompleted(CorrectionType.Dark, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
PublishError(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
UpdateStatus(DetectorStatus.Error);
|
||||
var errorResult = DetectorResult.Failure($"暗场校正异常 | Dark correction exception: {ex.Message}", ex);
|
||||
PublishError(errorResult);
|
||||
return errorResult;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增益校正 | Gain correction
|
||||
/// </summary>
|
||||
public async Task<DetectorResult> GainCorrectionAsync(int frameCount, CancellationToken cancellationToken = default)
|
||||
{
|
||||
// 参数校验 | Parameter validation
|
||||
if (Status != DetectorStatus.Ready)
|
||||
{
|
||||
return DetectorResult.Failure($"探测器状态不正确,当前状态:{Status} | Detector status incorrect, current status: {Status}");
|
||||
}
|
||||
|
||||
if (frameCount <= 0)
|
||||
{
|
||||
return DetectorResult.Failure("帧数必须大于 0 | Frame count must be greater than 0");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 更新状态 | Update status
|
||||
UpdateStatus(DetectorStatus.Correcting);
|
||||
|
||||
// 调用子类实现 | Call derived class implementation
|
||||
var result = await GainCorrectionInternalAsync(frameCount, cancellationToken);
|
||||
|
||||
// 恢复状态 | Restore status
|
||||
UpdateStatus(DetectorStatus.Ready);
|
||||
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
PublishCorrectionCompleted(CorrectionType.Gain, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
PublishError(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
UpdateStatus(DetectorStatus.Error);
|
||||
var errorResult = DetectorResult.Failure($"增益校正异常 | Gain correction exception: {ex.Message}", ex);
|
||||
PublishError(errorResult);
|
||||
return errorResult;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自动校正 | Auto correction
|
||||
/// </summary>
|
||||
public async Task<DetectorResult> AutoCorrectionAsync(int frameCount, CancellationToken cancellationToken = default)
|
||||
{
|
||||
// 参数校验 | Parameter validation
|
||||
if (Status != DetectorStatus.Ready)
|
||||
{
|
||||
return DetectorResult.Failure($"探测器状态不正确,当前状态:{Status} | Detector status incorrect, current status: {Status}");
|
||||
}
|
||||
|
||||
if (frameCount <= 0)
|
||||
{
|
||||
return DetectorResult.Failure("帧数必须大于 0 | Frame count must be greater than 0");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 更新状态 | Update status
|
||||
UpdateStatus(DetectorStatus.Correcting);
|
||||
|
||||
// 调用子类实现 | Call derived class implementation
|
||||
var result = await AutoCorrectionInternalAsync(frameCount, cancellationToken);
|
||||
|
||||
// 恢复状态 | Restore status
|
||||
UpdateStatus(DetectorStatus.Ready);
|
||||
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
PublishCorrectionCompleted(CorrectionType.Auto, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
PublishError(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
UpdateStatus(DetectorStatus.Error);
|
||||
var errorResult = DetectorResult.Failure($"自动校正异常 | Auto correction exception: {ex.Message}", ex);
|
||||
PublishError(errorResult);
|
||||
return errorResult;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 坏像素校正 | Bad pixel correction
|
||||
/// </summary>
|
||||
public async Task<DetectorResult> BadPixelCorrectionAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
// 参数校验 | Parameter validation
|
||||
if (Status != DetectorStatus.Ready)
|
||||
{
|
||||
return DetectorResult.Failure($"探测器状态不正确,当前状态:{Status} | Detector status incorrect, current status: {Status}");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 更新状态 | Update status
|
||||
UpdateStatus(DetectorStatus.Correcting);
|
||||
|
||||
// 调用子类实现 | Call derived class implementation
|
||||
var result = await BadPixelCorrectionInternalAsync(cancellationToken);
|
||||
|
||||
// 恢复状态 | Restore status
|
||||
UpdateStatus(DetectorStatus.Ready);
|
||||
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
PublishCorrectionCompleted(CorrectionType.BadPixel, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
PublishError(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
UpdateStatus(DetectorStatus.Error);
|
||||
var errorResult = DetectorResult.Failure($"坏像素校正异常 | Bad pixel correction exception: {ex.Message}", ex);
|
||||
PublishError(errorResult);
|
||||
return errorResult;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取探测器信息 | Get detector information
|
||||
/// </summary>
|
||||
public abstract DetectorInfo GetInfo();
|
||||
|
||||
// 模板方法,由子类实现 | Template methods, implemented by derived classes
|
||||
protected abstract Task<DetectorResult> InitializeInternalAsync(CancellationToken cancellationToken);
|
||||
protected abstract Task<DetectorResult> StartAcquisitionInternalAsync(CancellationToken cancellationToken);
|
||||
protected abstract Task<DetectorResult> StopAcquisitionInternalAsync(CancellationToken cancellationToken);
|
||||
protected abstract Task<DetectorResult> AcquireSingleFrameInternalAsync(CancellationToken cancellationToken);
|
||||
protected abstract Task<DetectorResult> DarkCorrectionInternalAsync(int frameCount, CancellationToken cancellationToken);
|
||||
protected abstract Task<DetectorResult> GainCorrectionInternalAsync(int frameCount, CancellationToken cancellationToken);
|
||||
protected abstract Task<DetectorResult> AutoCorrectionInternalAsync(int frameCount, CancellationToken cancellationToken);
|
||||
protected abstract Task<DetectorResult> BadPixelCorrectionInternalAsync(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// 更新状态并发布事件 | Update status and publish event
|
||||
/// </summary>
|
||||
/// <param name="newStatus">新状态 | New status</param>
|
||||
/// <summary>
|
||||
/// 更新状态并发布事件 | Update status and publish event
|
||||
/// 验证状态转换的合法性 | Validate state transition legality
|
||||
/// </summary>
|
||||
/// <param name="newStatus">新状态 | New status</param>
|
||||
protected void UpdateStatus(DetectorStatus newStatus)
|
||||
{
|
||||
lock (_statusLock)
|
||||
{
|
||||
// 验证状态转换的合法性 | Validate state transition legality
|
||||
if (!IsValidStateTransition(_status, newStatus))
|
||||
{
|
||||
var errorMsg = $"非法的状态转换:{_status} -> {newStatus} | Invalid state transition: {_status} -> {newStatus}";
|
||||
PublishError(DetectorResult.Failure(errorMsg));
|
||||
return;
|
||||
}
|
||||
|
||||
if (_status != newStatus)
|
||||
{
|
||||
var oldStatus = _status;
|
||||
_status = newStatus;
|
||||
_eventAggregator.GetEvent<StatusChangedEvent>().Publish(newStatus);
|
||||
|
||||
// 记录状态转换日志(如果需要)| Log state transition (if needed)
|
||||
System.Diagnostics.Debug.WriteLine($"状态转换 | State transition: {oldStatus} -> {newStatus}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证状态转换是否合法 | Validate if state transition is legal
|
||||
/// </summary>
|
||||
/// <param name="currentStatus">当前状态 | Current status</param>
|
||||
/// <param name="newStatus">新状态 | New status</param>
|
||||
/// <returns>是否合法 | Whether it's legal</returns>
|
||||
private bool IsValidStateTransition(DetectorStatus currentStatus, DetectorStatus newStatus)
|
||||
{
|
||||
// 相同状态总是允许的 | Same state is always allowed
|
||||
if (currentStatus == newStatus)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// 定义合法的状态转换规则 | Define legal state transition rules
|
||||
return (currentStatus, newStatus) switch
|
||||
{
|
||||
// 从未初始化状态只能转到初始化中 | From Uninitialized can only go to Initializing
|
||||
(DetectorStatus.Uninitialized, DetectorStatus.Initializing) => true,
|
||||
|
||||
// 从初始化中可以转到就绪或错误 | From Initializing can go to Ready or Error
|
||||
(DetectorStatus.Initializing, DetectorStatus.Ready) => true,
|
||||
(DetectorStatus.Initializing, DetectorStatus.Error) => true,
|
||||
|
||||
// 从就绪状态可以转到采集中、校正中 | From Ready can go to Acquiring or Correcting
|
||||
(DetectorStatus.Ready, DetectorStatus.Acquiring) => true,
|
||||
(DetectorStatus.Ready, DetectorStatus.Correcting) => true,
|
||||
|
||||
// 从采集中可以转到就绪或错误 | From Acquiring can go to Ready or Error
|
||||
(DetectorStatus.Acquiring, DetectorStatus.Ready) => true,
|
||||
(DetectorStatus.Acquiring, DetectorStatus.Error) => true,
|
||||
|
||||
// 从校正中可以转到就绪或错误 | From Correcting can go to Ready or Error
|
||||
(DetectorStatus.Correcting, DetectorStatus.Ready) => true,
|
||||
(DetectorStatus.Correcting, DetectorStatus.Error) => true,
|
||||
|
||||
// 从错误状态可以转到初始化中(重新初始化)| From Error can go to Initializing (re-initialize)
|
||||
(DetectorStatus.Error, DetectorStatus.Initializing) => true,
|
||||
|
||||
// 任何状态都可以转到错误状态 | Any state can go to Error
|
||||
(_, DetectorStatus.Error) => true,
|
||||
|
||||
// 其他转换都是非法的 | All other transitions are illegal
|
||||
_ => false
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 发布错误事件 | Publish error event
|
||||
/// </summary>
|
||||
/// <param name="result">错误结果 | Error result</param>
|
||||
protected void PublishError(DetectorResult result)
|
||||
{
|
||||
_eventAggregator.GetEvent<ErrorOccurredEvent>().Publish(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发布图像采集事件 | Publish image captured event
|
||||
/// </summary>
|
||||
/// <param name="args">事件参数 | Event arguments</param>
|
||||
protected void PublishImageCaptured(ImageCapturedEventArgs args)
|
||||
{
|
||||
_eventAggregator.GetEvent<ImageCapturedEvent>().Publish(args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发布校正完成事件 | Publish correction completed event
|
||||
/// </summary>
|
||||
/// <param name="type">校正类型 | Correction type</param>
|
||||
/// <param name="result">校正结果 | Correction result</param>
|
||||
protected void PublishCorrectionCompleted(CorrectionType type, DetectorResult result)
|
||||
{
|
||||
_eventAggregator.GetEvent<CorrectionCompletedEvent>().Publish(
|
||||
new CorrectionCompletedEventArgs(type, result));
|
||||
}
|
||||
|
||||
// IDisposable 实现 | IDisposable implementation
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源 | Dispose resources
|
||||
/// </summary>
|
||||
/// <param name="disposing">是否释放托管资源 | Whether to dispose managed resources</param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!_disposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// 释放托管资源 | Release managed resources
|
||||
}
|
||||
// 释放非托管资源 | Release unmanaged resources
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using XP.Hardware.Detector.Abstractions.Enums;
|
||||
|
||||
namespace XP.Hardware.Detector.Abstractions
|
||||
{
|
||||
/// <summary>
|
||||
/// 探测器信息 | Detector information
|
||||
/// 包含探测器的硬件参数和配置信息
|
||||
/// </summary>
|
||||
public class DetectorInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 探测器类型 | Detector type
|
||||
/// </summary>
|
||||
public DetectorType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 探测器型号 | Detector model
|
||||
/// </summary>
|
||||
public string Model { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 序列号 | Serial number
|
||||
/// </summary>
|
||||
public string SerialNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 固件版本 | Firmware version
|
||||
/// </summary>
|
||||
public string FirmwareVersion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最大分辨率宽度 | Maximum resolution width
|
||||
/// </summary>
|
||||
public uint MaxWidth { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最大分辨率高度 | Maximum resolution height
|
||||
/// </summary>
|
||||
public uint MaxHeight { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 像素尺寸(微米)| Pixel size (micrometers)
|
||||
/// </summary>
|
||||
public double PixelSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 位深度 | Bit depth
|
||||
/// </summary>
|
||||
public int BitDepth { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
|
||||
namespace XP.Hardware.Detector.Abstractions
|
||||
{
|
||||
/// <summary>
|
||||
/// 探测器操作结果封装 | Detector operation result wrapper
|
||||
/// 统一封装成功/失败状态、数据和错误信息
|
||||
/// </summary>
|
||||
public class DetectorResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 操作是否成功 | Whether the operation succeeded
|
||||
/// </summary>
|
||||
public bool IsSuccess { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 错误消息 | Error message
|
||||
/// </summary>
|
||||
public string ErrorMessage { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 异常对象 | Exception object
|
||||
/// </summary>
|
||||
public Exception Exception { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 错误码 | Error code
|
||||
/// </summary>
|
||||
public int ErrorCode { get; }
|
||||
|
||||
protected DetectorResult(bool isSuccess, string errorMessage = null, Exception exception = null, int errorCode = 0)
|
||||
{
|
||||
IsSuccess = isSuccess;
|
||||
ErrorMessage = errorMessage;
|
||||
Exception = exception;
|
||||
ErrorCode = errorCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建成功结果 | Create success result
|
||||
/// </summary>
|
||||
/// <param name="message">成功消息 | Success message</param>
|
||||
/// <returns>成功结果 | Success result</returns>
|
||||
public static DetectorResult Success(string message = null)
|
||||
{
|
||||
return new DetectorResult(true, message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建失败结果 | Create failure result
|
||||
/// </summary>
|
||||
/// <param name="errorMessage">错误消息 | Error message</param>
|
||||
/// <param name="exception">异常对象 | Exception object</param>
|
||||
/// <param name="errorCode">错误码 | Error code</param>
|
||||
/// <returns>失败结果 | Failure result</returns>
|
||||
public static DetectorResult Failure(string errorMessage, Exception exception = null, int errorCode = -1)
|
||||
{
|
||||
return new DetectorResult(false, errorMessage, exception, errorCode);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 带数据的探测器操作结果 | Detector operation result with data
|
||||
/// </summary>
|
||||
/// <typeparam name="T">数据类型 | Data type</typeparam>
|
||||
public class DetectorResult<T> : DetectorResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 结果数据 | Result data
|
||||
/// </summary>
|
||||
public T Data { get; }
|
||||
|
||||
private DetectorResult(bool isSuccess, T data, string errorMessage = null, Exception exception = null, int errorCode = 0)
|
||||
: base(isSuccess, errorMessage, exception, errorCode)
|
||||
{
|
||||
Data = data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建成功结果 | Create success result
|
||||
/// </summary>
|
||||
/// <param name="data">结果数据 | Result data</param>
|
||||
/// <param name="message">成功消息 | Success message</param>
|
||||
/// <returns>成功结果 | Success result</returns>
|
||||
public static DetectorResult<T> Success(T data, string message = null)
|
||||
{
|
||||
return new DetectorResult<T>(true, data, message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建失败结果 | Create failure result
|
||||
/// </summary>
|
||||
/// <param name="errorMessage">错误消息 | Error message</param>
|
||||
/// <param name="exception">异常对象 | Exception object</param>
|
||||
/// <param name="errorCode">错误码 | Error code</param>
|
||||
/// <returns>失败结果 | Failure result</returns>
|
||||
public new static DetectorResult<T> Failure(string errorMessage, Exception exception = null, int errorCode = -1)
|
||||
{
|
||||
return new DetectorResult<T>(false, default(T), errorMessage, exception, errorCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace XP.Hardware.Detector.Abstractions.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// 采集模式枚举 | Acquisition mode enumeration
|
||||
/// 定义图像采集的工作模式
|
||||
/// </summary>
|
||||
public enum AcquisitionMode
|
||||
{
|
||||
/// <summary>
|
||||
/// 连续采集模式 | Continuous acquisition mode
|
||||
/// </summary>
|
||||
Continuous = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 单帧采集模式 | Single frame acquisition mode
|
||||
/// </summary>
|
||||
SingleFrame = 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace XP.Hardware.Detector.Abstractions.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// Binning 模式枚举 | Binning mode enumeration
|
||||
/// 定义像素合并模式,用于提高信噪比或采集速度
|
||||
/// </summary>
|
||||
public enum BinningMode
|
||||
{
|
||||
/// <summary>
|
||||
/// 1x1 模式(无合并)| 1x1 mode (no binning)
|
||||
/// </summary>
|
||||
Bin1x1 = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 2x2 模式(2x2 像素合并)| 2x2 mode (2x2 pixel binning)
|
||||
/// </summary>
|
||||
Bin2x2 = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 4x4 模式(4x4 像素合并)| 4x4 mode (4x4 pixel binning)
|
||||
/// </summary>
|
||||
Bin4x4 = 2
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
namespace XP.Hardware.Detector.Abstractions.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// 校正类型枚举 | Correction type enumeration
|
||||
/// 定义探测器支持的校正类型
|
||||
/// </summary>
|
||||
public enum CorrectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// 暗场校正 | Dark field correction
|
||||
/// </summary>
|
||||
Dark = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 增益校正(亮场校正)| Gain correction (bright field correction)
|
||||
/// </summary>
|
||||
Gain = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 自动校正(暗场+增益+坏像素)| Auto correction (dark + gain + bad pixel)
|
||||
/// </summary>
|
||||
Auto = 2,
|
||||
|
||||
/// <summary>
|
||||
/// 坏像素校正 | Bad pixel correction
|
||||
/// </summary>
|
||||
BadPixel = 3
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
namespace XP.Hardware.Detector.Abstractions.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// 探测器状态枚举 | Detector status enumeration
|
||||
/// 定义探测器的运行状态
|
||||
/// </summary>
|
||||
public enum DetectorStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// 未初始化 | Uninitialized
|
||||
/// </summary>
|
||||
Uninitialized = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 初始化中 | Initializing
|
||||
/// </summary>
|
||||
Initializing = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 就绪 | Ready
|
||||
/// </summary>
|
||||
Ready = 2,
|
||||
|
||||
/// <summary>
|
||||
/// 采集中 | Acquiring
|
||||
/// </summary>
|
||||
Acquiring = 3,
|
||||
|
||||
/// <summary>
|
||||
/// 校正中 | Correcting
|
||||
/// </summary>
|
||||
Correcting = 4,
|
||||
|
||||
/// <summary>
|
||||
/// 错误 | Error
|
||||
/// </summary>
|
||||
Error = 5
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace XP.Hardware.Detector.Abstractions.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// 探测器类型枚举 | Detector type enumeration
|
||||
/// 定义支持的探测器厂商类型
|
||||
/// </summary>
|
||||
public enum DetectorType
|
||||
{
|
||||
/// <summary>
|
||||
/// Varex 探测器 | Varex detector
|
||||
/// </summary>
|
||||
Varex = 0,
|
||||
|
||||
/// <summary>
|
||||
/// iRay 探测器 | iRay detector (预留)
|
||||
/// </summary>
|
||||
IRay = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Hamamatsu 探测器 | Hamamatsu detector (预留)
|
||||
/// </summary>
|
||||
Hamamatsu = 2
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace XP.Hardware.Detector.Abstractions.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// 增益模式枚举 | Gain mode enumeration
|
||||
/// 定义探测器的信号放大倍数
|
||||
/// </summary>
|
||||
public enum GainMode
|
||||
{
|
||||
/// <summary>
|
||||
/// 低增益模式 | Low gain mode
|
||||
/// </summary>
|
||||
Low = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 高增益模式 | High gain mode
|
||||
/// </summary>
|
||||
High = 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Prism.Events;
|
||||
using XP.Hardware.Detector.Abstractions;
|
||||
|
||||
namespace XP.Hardware.Detector.Abstractions.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// 校正完成事件 | Correction completed event
|
||||
/// 当探测器校正操作完成时触发
|
||||
/// 线程安全:使用 Prism EventAggregator 确保线程安全的发布和订阅
|
||||
/// </summary>
|
||||
public class CorrectionCompletedEvent : PubSubEvent<CorrectionCompletedEventArgs>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using XP.Hardware.Detector.Abstractions.Enums;
|
||||
|
||||
namespace XP.Hardware.Detector.Abstractions
|
||||
{
|
||||
/// <summary>
|
||||
/// 校正完成事件参数 | Correction completed event arguments
|
||||
/// 携带校正类型和结果信息
|
||||
/// </summary>
|
||||
public class CorrectionCompletedEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// 校正类型 | Correction type
|
||||
/// </summary>
|
||||
public CorrectionType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 校正结果 | Correction result
|
||||
/// </summary>
|
||||
public DetectorResult Result { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数 | Constructor
|
||||
/// </summary>
|
||||
/// <param name="type">校正类型 | Correction type</param>
|
||||
/// <param name="result">校正结果 | Correction result</param>
|
||||
public CorrectionCompletedEventArgs(CorrectionType type, DetectorResult result)
|
||||
{
|
||||
Type = type;
|
||||
Result = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Prism.Events;
|
||||
using XP.Hardware.Detector.Abstractions;
|
||||
|
||||
namespace XP.Hardware.Detector.Abstractions.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// 错误发生事件 | Error occurred event
|
||||
/// 当探测器操作发生错误时触发
|
||||
/// 线程安全:使用 Prism EventAggregator 确保线程安全的发布和订阅
|
||||
/// </summary>
|
||||
public class ErrorOccurredEvent : PubSubEvent<DetectorResult>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Prism.Events;
|
||||
using XP.Hardware.Detector.Abstractions;
|
||||
|
||||
namespace XP.Hardware.Detector.Abstractions.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// 图像采集事件 | Image captured event
|
||||
/// 当探测器采集到新图像时触发
|
||||
/// 线程安全:使用 Prism EventAggregator 确保线程安全的发布和订阅
|
||||
/// </summary>
|
||||
public class ImageCapturedEvent : PubSubEvent<ImageCapturedEventArgs>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
|
||||
namespace XP.Hardware.Detector.Abstractions
|
||||
{
|
||||
/// <summary>
|
||||
/// 图像采集事件参数 | Image captured event arguments
|
||||
/// 携带图像数据和元信息
|
||||
/// </summary>
|
||||
public class ImageCapturedEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// 16 位图像原始数据(无符号)| 16-bit raw image data (unsigned)
|
||||
/// </summary>
|
||||
public ushort[] ImageData { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 图像宽度 | Image width
|
||||
/// </summary>
|
||||
public uint Width { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 图像高度 | Image height
|
||||
/// </summary>
|
||||
public uint Height { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 帧号 | Frame number
|
||||
/// </summary>
|
||||
public int FrameNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 存储路径 | Save path
|
||||
/// </summary>
|
||||
public string SavePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 曝光时间(毫秒)| Exposure time (milliseconds)
|
||||
/// </summary>
|
||||
public uint ExposureTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 采集时间戳 | Capture timestamp
|
||||
/// </summary>
|
||||
public DateTime CaptureTime { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Prism.Events;
|
||||
using XP.Hardware.Detector.Abstractions.Enums;
|
||||
|
||||
namespace XP.Hardware.Detector.Abstractions.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// 状态变更事件 | Status changed event
|
||||
/// 当探测器状态发生变化时触发
|
||||
/// 线程安全:使用 Prism EventAggregator 确保线程安全的发布和订阅
|
||||
/// </summary>
|
||||
public class StatusChangedEvent : PubSubEvent<DetectorStatus>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using XP.Hardware.Detector.Abstractions.Enums;
|
||||
|
||||
namespace XP.Hardware.Detector.Abstractions
|
||||
{
|
||||
/// <summary>
|
||||
/// 面阵探测器通用接口 | Area detector common interface
|
||||
/// 定义所有探测器必须实现的核心能力
|
||||
/// </summary>
|
||||
public interface IAreaDetector : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// 探测器状态 | Detector status
|
||||
/// </summary>
|
||||
DetectorStatus Status { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 探测器类型 | Detector type
|
||||
/// </summary>
|
||||
DetectorType Type { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 初始化探测器 | Initialize detector
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">取消令牌 | Cancellation token</param>
|
||||
/// <returns>操作结果 | Operation result</returns>
|
||||
Task<DetectorResult> InitializeAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// 启动连续采集 | Start continuous acquisition
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">取消令牌 | Cancellation token</param>
|
||||
/// <returns>操作结果 | Operation result</returns>
|
||||
Task<DetectorResult> StartAcquisitionAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// 停止采集 | Stop acquisition
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">取消令牌 | Cancellation token</param>
|
||||
/// <returns>操作结果 | Operation result</returns>
|
||||
Task<DetectorResult> StopAcquisitionAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// 单帧采集 | Single frame acquisition
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">取消令牌 | Cancellation token</param>
|
||||
/// <returns>操作结果 | Operation result</returns>
|
||||
Task<DetectorResult> AcquireSingleFrameAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// 暗场校正 | Dark field correction
|
||||
/// </summary>
|
||||
/// <param name="frameCount">采集帧数 | Frame count</param>
|
||||
/// <param name="cancellationToken">取消令牌 | Cancellation token</param>
|
||||
/// <returns>操作结果 | Operation result</returns>
|
||||
Task<DetectorResult> DarkCorrectionAsync(int frameCount, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// 增益校正(亮场校正)| Gain correction (bright field correction)
|
||||
/// </summary>
|
||||
/// <param name="frameCount">采集帧数 | Frame count</param>
|
||||
/// <param name="cancellationToken">取消令牌 | Cancellation token</param>
|
||||
/// <returns>操作结果 | Operation result</returns>
|
||||
Task<DetectorResult> GainCorrectionAsync(int frameCount, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// 自动校正(暗场+增益+坏像素)| Auto correction (dark + gain + bad pixel)
|
||||
/// </summary>
|
||||
/// <param name="frameCount">采集帧数 | Frame count</param>
|
||||
/// <param name="cancellationToken">取消令牌 | Cancellation token</param>
|
||||
/// <returns>操作结果 | Operation result</returns>
|
||||
Task<DetectorResult> AutoCorrectionAsync(int frameCount, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// 坏像素校正 | Bad pixel correction
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">取消令牌 | Cancellation token</param>
|
||||
/// <returns>操作结果 | Operation result</returns>
|
||||
Task<DetectorResult> BadPixelCorrectionAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// 获取探测器信息 | Get detector information
|
||||
/// </summary>
|
||||
/// <returns>探测器信息 | Detector information</returns>
|
||||
DetectorInfo GetInfo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System.Threading.Tasks;
|
||||
using XP.Hardware.Detector.Abstractions.Enums;
|
||||
|
||||
namespace XP.Hardware.Detector.Abstractions
|
||||
{
|
||||
/// <summary>
|
||||
/// iRay 探测器专属接口 | iRay detector specific interface
|
||||
/// 扩展 iRay 特有的功能
|
||||
/// </summary>
|
||||
public interface IIRayDetector : IAreaDetector
|
||||
{
|
||||
/// <summary>
|
||||
/// 设置采集模式 | Set acquisition mode
|
||||
/// </summary>
|
||||
/// <param name="mode">采集模式 | Acquisition mode</param>
|
||||
/// <returns>操作结果 | Operation result</returns>
|
||||
Task<DetectorResult> SetAcquisitionModeAsync(AcquisitionMode mode);
|
||||
|
||||
/// <summary>
|
||||
/// 获取采集模式 | Get acquisition mode
|
||||
/// </summary>
|
||||
/// <returns>当前采集模式 | Current acquisition mode</returns>
|
||||
AcquisitionMode GetAcquisitionMode();
|
||||
|
||||
/// <summary>
|
||||
/// 设置增益值 | Set gain value
|
||||
/// </summary>
|
||||
/// <param name="gain">增益值 | Gain value</param>
|
||||
/// <returns>操作结果 | Operation result</returns>
|
||||
Task<DetectorResult> SetGainAsync(double gain);
|
||||
|
||||
/// <summary>
|
||||
/// 获取增益值 | Get gain value
|
||||
/// </summary>
|
||||
/// <returns>当前增益值 | Current gain value</returns>
|
||||
double GetGain();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using System.Threading.Tasks;
|
||||
using XP.Hardware.Detector.Abstractions.Enums;
|
||||
|
||||
namespace XP.Hardware.Detector.Abstractions
|
||||
{
|
||||
/// <summary>
|
||||
/// Varex 探测器专属接口 | Varex detector specific interface
|
||||
/// 扩展 Varex 特有的功能
|
||||
/// </summary>
|
||||
public interface IVarexDetector : IAreaDetector
|
||||
{
|
||||
/// <summary>
|
||||
/// 设置 Binning 模式 | Set binning mode
|
||||
/// </summary>
|
||||
/// <param name="mode">Binning 模式 | Binning mode</param>
|
||||
/// <returns>操作结果 | Operation result</returns>
|
||||
Task<DetectorResult> SetBinningModeAsync(BinningMode mode);
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Binning 模式 | Get binning mode
|
||||
/// </summary>
|
||||
/// <returns>当前 Binning 模式 | Current binning mode</returns>
|
||||
BinningMode GetBinningMode();
|
||||
|
||||
/// <summary>
|
||||
/// 设置增益模式 | Set gain mode
|
||||
/// </summary>
|
||||
/// <param name="mode">增益模式 | Gain mode</param>
|
||||
/// <returns>操作结果 | Operation result</returns>
|
||||
Task<DetectorResult> SetGainModeAsync(GainMode mode);
|
||||
|
||||
/// <summary>
|
||||
/// 获取增益模式 | Get gain mode
|
||||
/// </summary>
|
||||
/// <returns>当前增益模式 | Current gain mode</returns>
|
||||
GainMode GetGainMode();
|
||||
|
||||
/// <summary>
|
||||
/// 设置曝光时间 | Set exposure time
|
||||
/// </summary>
|
||||
/// <param name="milliseconds">曝光时间(毫秒)| Exposure time (milliseconds)</param>
|
||||
/// <returns>操作结果 | Operation result</returns>
|
||||
Task<DetectorResult> SetExposureTimeAsync(uint milliseconds);
|
||||
|
||||
/// <summary>
|
||||
/// 获取曝光时间 | Get exposure time
|
||||
/// </summary>
|
||||
/// <returns>曝光时间(毫秒)| Exposure time (milliseconds)</returns>
|
||||
uint GetExposureTime();
|
||||
|
||||
/// <summary>
|
||||
/// 设置 ROI 区域 | Set ROI region
|
||||
/// </summary>
|
||||
/// <param name="x">起始 X 坐标 | Start X coordinate</param>
|
||||
/// <param name="y">起始 Y 坐标 | Start Y coordinate</param>
|
||||
/// <param name="width">宽度 | Width</param>
|
||||
/// <param name="height">高度 | Height</param>
|
||||
/// <returns>操作结果 | Operation result</returns>
|
||||
Task<DetectorResult> SetROIAsync(uint x, uint y, uint width, uint height);
|
||||
|
||||
/// <summary>
|
||||
/// 获取 ROI 区域 | Get ROI region
|
||||
/// </summary>
|
||||
/// <returns>ROI 参数 | ROI parameters</returns>
|
||||
(uint x, uint y, uint width, uint height) GetROI();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user