127 lines
4.9 KiB
C#
127 lines
4.9 KiB
C#
using HardwareControl.Core.FocusSystem;
|
|
|
|
namespace HardwareControl.Core.HardwareServiceImpl.HardwareService
|
|
{
|
|
/// <summary>
|
|
/// 定焦系统服务,封装 FocusSystem2.dll。
|
|
///
|
|
/// 串口在连接时从系统参数 focus_com 读取,读取不到时回退到
|
|
/// appsettings.json 的 "FocusSystem:ComPort"。命令函数内部已完成
|
|
/// "组包→发送→收应答",返回即表示设备已回执;运行结果与系统信息
|
|
/// 需通过 <see cref="ReadSystemInfoAsync"/> / <see cref="ReadResultAsync"/> 查询。
|
|
/// 所有原生调用串行执行。
|
|
/// </summary>
|
|
public interface IFocusSystemService : IAsyncDisposable
|
|
{
|
|
/// <summary>串口是否已打开。</summary>
|
|
bool IsConnected { get; }
|
|
|
|
/// <summary>当前使用的串口名(已规范化为 "\\.\COMx");未连接时为 null。</summary>
|
|
string? PortName { get; }
|
|
|
|
Task ConnectAsync(CancellationToken ct = default);
|
|
|
|
Task DisconnectAsync(CancellationToken ct = default);
|
|
|
|
// ---------- 对焦 ----------
|
|
|
|
/// <summary>单次对焦。</summary>
|
|
Task StartSingleFocusAsync(CancellationToken ct = default);
|
|
|
|
/// <summary>连续对焦。</summary>
|
|
Task StartContinuousFocusAsync(CancellationToken ct = default);
|
|
|
|
// ---------- 校准 ----------
|
|
|
|
/// <summary>进入校准模式。</summary>
|
|
Task EnterCalibrationModeAsync(CancellationToken ct = default);
|
|
|
|
/// <summary>校准滑台移动指定距离,正值为正向;速度为空时使用配置默认值。</summary>
|
|
Task MoveCalibrationAsync(
|
|
int distanceMm,
|
|
int? speed = null,
|
|
CancellationToken ct = default);
|
|
|
|
/// <summary>保存当前校准参数到设备存储器。</summary>
|
|
Task SaveCalibrationAsync(CancellationToken ct = default);
|
|
|
|
// ---------- 激光器 ----------
|
|
|
|
/// <summary>激光器按指定频率出光。</summary>
|
|
Task TurnLaserOnAsync(byte frequency, CancellationToken ct = default);
|
|
|
|
/// <summary>立即关闭激光器。</summary>
|
|
Task TurnLaserOffAsync(CancellationToken ct = default);
|
|
|
|
/// <summary>设置激光能量值(0~255)。</summary>
|
|
Task SetLaserPowerAsync(byte power, CancellationToken ct = default);
|
|
|
|
// ---------- 测距 ----------
|
|
|
|
/// <summary>触发激光传感器执行一次测距。</summary>
|
|
Task StartSingleRangeAsync(CancellationToken ct = default);
|
|
|
|
/// <summary>激光传感器进入连续测距模式。</summary>
|
|
Task StartContinuousRangeAsync(CancellationToken ct = default);
|
|
|
|
// ---------- 升降机构 ----------
|
|
|
|
/// <summary>升降机构到达指定位置,正值为上升。</summary>
|
|
Task ControlLiftAsync(int position, CancellationToken ct = default);
|
|
|
|
// ---------- 外部触发 ----------
|
|
|
|
/// <summary>配置外部触发参数。</summary>
|
|
Task SetExternalTriggerAsync(CancellationToken ct = default);
|
|
|
|
/// <summary>响应外部触发信号控制激光器出光。</summary>
|
|
Task FireExternalTriggerAsync(CancellationToken ct = default);
|
|
|
|
// ---------- 自动检测 ----------
|
|
|
|
/// <summary>启动自动下降检测流程。</summary>
|
|
Task StartAutoDescendAsync(CancellationToken ct = default);
|
|
|
|
/// <summary>按指定周期和次数循环出光。</summary>
|
|
Task StartFixedCycleAsync(
|
|
ushort intervalMs,
|
|
ushort count,
|
|
CancellationToken ct = default);
|
|
|
|
// ---------- 光谱仪同步 ----------
|
|
|
|
/// <summary>设置光谱仪同步延时参数。</summary>
|
|
Task SetSyncTimeAsync(
|
|
FocusSyncTime parameters,
|
|
CancellationToken ct = default);
|
|
|
|
/// <summary>请求设备返回当前同步延时,结果通过 <see cref="ReadResultAsync"/> 读取。</summary>
|
|
Task RequestSyncTimeAsync(CancellationToken ct = default);
|
|
|
|
// ---------- 电源 ----------
|
|
|
|
/// <summary>控制设备总电源关机。</summary>
|
|
Task PowerOffAsync(CancellationToken ct = default);
|
|
|
|
// ---------- 查询 ----------
|
|
|
|
/// <summary>
|
|
/// 读取系统信息(对焦位置、错误码、电压、版本等)。
|
|
/// 在 <paramref name="timeoutMs"/> 内重试直到收到有效帧。
|
|
/// </summary>
|
|
Task<FocusSystemStatus> ReadSystemInfoAsync(
|
|
int? timeoutMs = null,
|
|
CancellationToken ct = default);
|
|
|
|
/// <summary>
|
|
/// 读取设备缓存的运行结果/查询结果(type=0x02/0x03)。
|
|
/// 在 <paramref name="timeoutMs"/> 内轮询直到收到结果帧。
|
|
/// </summary>
|
|
Task<FocusRealTimeResult> ReadResultAsync(
|
|
int? timeoutMs = null,
|
|
CancellationToken ct = default);
|
|
|
|
event EventHandler<FocusSystemStatusChangedEventArgs>? StatusChanged;
|
|
}
|
|
}
|