|
|
@@ -1334,14 +1334,25 @@ namespace TeamAAS_VP.Core
|
|
|
if (state)
|
|
|
{
|
|
|
SendTaskMessage($"触发固定相机检测拍照...", MessageLevel.Debug);
|
|
|
+ //相机的编号
|
|
|
+ //Int16 cameraIndex = plc.ReadNode<Int16>(addressConfig.In_FixedCameracheckNum.Address);
|
|
|
// 读取相机编号
|
|
|
-
|
|
|
+
|
|
|
Int16 cameraIndex = plc.ReadNode<Int16>(addressConfig.In_FixedCameracheckNum.Address);
|
|
|
SendTaskMessage($"编号:{cameraIndex}", MessageLevel.Info);
|
|
|
|
|
|
- // 直接遍历 CameraProcedures,查找名称为 "C{cameraIndex}" 的流程(不保存回退)
|
|
|
- string targetName = $"C{cameraIndex}";
|
|
|
- object selectedProcess = null;
|
|
|
+ // 找到对应编号的 PlcPoint
|
|
|
+ var targetPoint = currentProduct.AoiPoints?.FirstOrDefault(p => p.Number == cameraIndex);
|
|
|
+ if (targetPoint == null)
|
|
|
+ {
|
|
|
+ SendTaskMessage($"未找到 AOI 点位,编号:{cameraIndex}", MessageLevel.Alarm);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_FixedCameracheckStatus.Address, (Int16)2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // CameraProcedureId 存储的是具体的视觉流程 Id(ProcedureModel.Id),
|
|
|
+ // 需要在所有 CameraProcedures 的 ProcedureModels 中查找匹配的流程。
|
|
|
+ ProcedureModel selectedProcedure = null;
|
|
|
try
|
|
|
{
|
|
|
var cameraProcedures = currentProduct.CameraProcedures;
|
|
|
@@ -1349,41 +1360,20 @@ namespace TeamAAS_VP.Core
|
|
|
{
|
|
|
foreach (var cp in cameraProcedures)
|
|
|
{
|
|
|
- var pmProp = cp.GetType().GetProperty("ProcedureModels");
|
|
|
- if (pmProp == null) continue;
|
|
|
- var pms = pmProp.GetValue(cp) as IEnumerable;
|
|
|
- if (pms == null) continue;
|
|
|
-
|
|
|
- foreach (var pm in pms)
|
|
|
- {
|
|
|
- var nameProp = pm.GetType().GetProperty("Name")
|
|
|
- ?? pm.GetType().GetProperty("ProcedureName")
|
|
|
- ?? pm.GetType().GetProperty("CameraName");
|
|
|
- var name = nameProp?.GetValue(pm)?.ToString() ?? string.Empty;
|
|
|
-
|
|
|
- if (string.Equals(name, targetName, StringComparison.OrdinalIgnoreCase))
|
|
|
- {
|
|
|
- selectedProcess = pm;
|
|
|
- SendTaskMessage($"按名称匹配到流程: {name}", MessageLevel.Debug);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (selectedProcess != null) break;
|
|
|
+ if (cp?.ProcedureModels == null) continue;
|
|
|
+ selectedProcedure = cp.ProcedureModels.FirstOrDefault(pm => pm.Id == targetPoint.CameraProcedureId);
|
|
|
+ if (selectedProcedure != null) break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if (selectedProcess == null)
|
|
|
- {
|
|
|
- SendTaskMessage("未找到任何拍照流程,写入失败状态。", MessageLevel.Alarm);
|
|
|
- await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)2);
|
|
|
- return;
|
|
|
- }
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- LogHelper.WriteLogError("查找拍照流程时出错", ex);
|
|
|
- SendTaskMessage($"查找拍照流程时出错: {ex.Message}", MessageLevel.Alarm);
|
|
|
+ LogHelper.WriteLogError("查找 AOI 点位对应视觉流程时出错", ex);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (selectedProcedure == null)
|
|
|
+ {
|
|
|
+ SendTaskMessage($"未找到 AOI 点位对应的视觉流程,Point#{cameraIndex} ProcedureId={targetPoint.CameraProcedureId}", MessageLevel.Alarm);
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)2);
|
|
|
return;
|
|
|
}
|
|
|
@@ -1392,37 +1382,29 @@ namespace TeamAAS_VP.Core
|
|
|
try
|
|
|
{
|
|
|
var cts = new CancellationTokenSource();
|
|
|
- // 参数:根据当前流程需要,第二/第三参数可调整(这里保持 null)
|
|
|
- var visionResult = await _remoteCommandService.ExecutePhotoGetSinglePoint(selectedProcess as ProcedureModel, null, null, cts.Token);
|
|
|
-
|
|
|
+ var visionResult = await _remoteCommandService.ExecutePhotoGetSinglePoint(selectedProcedure, null, null, cts.Token);
|
|
|
if (visionResult.IsSucceed)
|
|
|
{
|
|
|
- SendTaskMessage($"流程 {targetName} 执行成功:X={visionResult.X:F3} Y={visionResult.Y:F3}", MessageLevel.Info);
|
|
|
- // 写回 PLC 成功状态
|
|
|
+ SendTaskMessage($"AOI 流程执行成功:X={visionResult.X:F3} Y={visionResult.Y:F3}", MessageLevel.Info);
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)1);
|
|
|
-
|
|
|
- // 如果需要把坐标写回 PLC,请在这里添加对应地址写入(Out_* 字段需在 PlcAddressConfig 中存在)
|
|
|
- // 例如:
|
|
|
- // await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPick_X.Address, (float)visionResult.X);
|
|
|
- // await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPick_Y.Address, (float)visionResult.Y);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- SendTaskMessage($"流程 {targetName} 执行失败。", MessageLevel.Alarm);
|
|
|
+ SendTaskMessage($"AOI 流程执行失败:Point#{cameraIndex}", MessageLevel.Alarm);
|
|
|
await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)2);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- LogHelper.WriteLogError("执行拍照流程时出错", ex);
|
|
|
- SendTaskMessage($"执行拍照流程异常: {ex.Message}", MessageLevel.Alarm);
|
|
|
+ LogHelper.WriteLogError("执行 AOI 视觉流程时出错", ex);
|
|
|
+ SendTaskMessage($"执行 AOI 视觉流程异常: {ex.Message}", MessageLevel.Alarm);
|
|
|
try { await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)2); } catch { }
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
SendTaskMessage($"触发固定相机检测拍照信号已关闭", MessageLevel.Alarm);
|
|
|
- await plc.WriteNodeAsync(addressConfig.Out_FixedCameracheckStatus.Address, (Int16)0);
|
|
|
+ await plc.WriteNodeAsync(addressConfig.Out_FixedCameraPickStatus.Address, (Int16)0);
|
|
|
}
|
|
|
}
|
|
|
}
|