#初步的cnc编辑功能,实现插入参考点的流程
This commit is contained in:
@@ -6,6 +6,7 @@ using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
using XP.Common.Logging.Interfaces;
|
||||
using XP.Hardware.RaySource.Services;
|
||||
using XplorePlane.Models;
|
||||
using XplorePlane.Services.AppState;
|
||||
|
||||
@@ -20,6 +21,7 @@ namespace XplorePlane.Services.Cnc
|
||||
public class CncProgramService : ICncProgramService
|
||||
{
|
||||
private readonly IAppStateService _appStateService;
|
||||
private readonly IRaySourceService _raySourceService;
|
||||
private readonly ILoggerService _logger;
|
||||
|
||||
// ── 序列化配置 | Serialization options ──
|
||||
@@ -32,12 +34,15 @@ namespace XplorePlane.Services.Cnc
|
||||
|
||||
public CncProgramService(
|
||||
IAppStateService appStateService,
|
||||
IRaySourceService raySourceService,
|
||||
ILoggerService logger)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(appStateService);
|
||||
ArgumentNullException.ThrowIfNull(raySourceService);
|
||||
ArgumentNullException.ThrowIfNull(logger);
|
||||
|
||||
_appStateService = appStateService;
|
||||
_raySourceService = raySourceService;
|
||||
_logger = logger.ForModule<CncProgramService>();
|
||||
|
||||
_logger.Info("CncProgramService 已初始化 | CncProgramService initialized");
|
||||
@@ -344,6 +349,7 @@ namespace XplorePlane.Services.Cnc
|
||||
private ReferencePointNode CreateReferencePointNode(Guid id, int index)
|
||||
{
|
||||
var motion = _appStateService.MotionState;
|
||||
var raySource = _appStateService.RaySourceState;
|
||||
return new ReferencePointNode(
|
||||
id, index, $"参考点_{index}",
|
||||
XM: motion.XM,
|
||||
@@ -351,7 +357,10 @@ namespace XplorePlane.Services.Cnc
|
||||
ZT: motion.ZT,
|
||||
ZD: motion.ZD,
|
||||
TiltD: motion.TiltD,
|
||||
Dist: motion.Dist);
|
||||
Dist: motion.Dist,
|
||||
IsRayOn: raySource.IsOn,
|
||||
Voltage: raySource.Voltage,
|
||||
Current: TryReadCurrent());
|
||||
}
|
||||
|
||||
/// <summary>创建保存节点(含图像)| Create save node with image</summary>
|
||||
@@ -382,5 +391,24 @@ namespace XplorePlane.Services.Cnc
|
||||
id, index, $"保存位置_{index}",
|
||||
MotionState: _appStateService.MotionState);
|
||||
}
|
||||
private double TryReadCurrent()
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _raySourceService.ReadCurrent();
|
||||
if (result?.Success == true)
|
||||
{
|
||||
return result.GetFloat();
|
||||
}
|
||||
|
||||
_logger.Warn("Failed to read ray source current, ReferencePoint node will use 0");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warn("Failed to read ray source current: {Message}", ex.Message);
|
||||
}
|
||||
|
||||
return 0d;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user