From 2070c58fc39ddcaff2c5dedaadce3277e67e79d0 Mon Sep 17 00:00:00 2001 From: tfarcraw <123211521@163.com> Date: Sun, 2 Aug 2026 13:02:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AGENTS.md | 11 +- PLCSharpWpf/Core/Common/FlowModel.cs | 12 +- PLCSharpWpf/Models/GlobalModel.Recipes.cs | 8 + .../VVMs/MotionController/AxisPoint.cs | 10 +- .../VVMs/MotionController/ControllersModel.cs | 9 +- .../MotionController/InterpolationGroup.cs | 6 +- .../Vision/Camera/CameraConfigViewModel.cs | 8 +- .../Vision/VisionConfigViewModel.Flows.cs | 22 +-- .../Access/ImageFromCamera.xaml | 5 +- .../Access/ImageFromCameraHandler.cs | 47 +++-- .../Access/ImageFromLocalHandler.cs | 2 +- .../Access/ImageToGlobalHandler.cs | 2 +- .../Access/ImageToHomePageHandler.cs | 2 +- .../Access/ImageToLocalHandler.cs | 2 +- .../Algorithm/BarcodeDecodeHandler.cs | 23 ++- .../Algorithm/CaliperFindCircleHandler.cs | 4 +- .../Algorithm/CaliperFindEdgeHandler.cs | 4 +- .../Algorithm/CaliperFindRectHandler.cs | 4 +- .../Algorithm/ClearDrawHandler.cs | 2 - .../Algorithm/ColorAreaHandler.cs | 2 +- .../Algorithm/GalleryClassifierHandler.cs | 2 +- .../Algorithm/GrayAreaHandler.cs | 2 +- .../Algorithm/GrayTemplateMatchHandler.cs | 2 +- .../Algorithm/MatrixGenHandler.cs | 2 +- .../Algorithm/ORBMatchHandler.cs | 2 +- .../Algorithm/PointToLineDistanceHandler.cs | 2 +- .../Algorithm/PointToPointDistanceHandler.cs | 2 +- .../Algorithm/SiftMatchHandler.cs | 2 +- .../Algorithm/TwoLineIntersectHandler.cs | 4 +- .../Algorithm/WeChatDecodeHandler.cs | 4 +- .../Processing/Bgr2GrayHandler.cs | 2 +- .../Processing/CoordinateTransformHandler.cs | 2 +- .../Processing/HistogramEqualizeHandler.cs | 2 +- .../Processing/ImageWarpHandler.cs | 2 +- PLCSharpWpf/VVMs/Vision/VisionFunction.cs | 136 ++++++++------- PLCSharpWpf/VVMs/Vision/VisionsViewModel.cs | 8 +- PLCSharpWpf/VVMs/Workflows/Extension.cs | 42 ++--- .../Workflows/Script/网络等待接收.spt | 7 + .../Script/获取网络通信对象.spt | 1 + .../Workflows/Script/获取视觉项目.spt | 1 + .../VVMs/Workflows/ScriptManageDialog.xaml | 77 ++++++++ .../VVMs/Workflows/ScriptManageDialog.xaml.cs | 37 ++++ .../Workflows/ScriptManageDialogViewModel.cs | 165 ++++++++++++++++++ PLCSharpWpf/VVMs/Workflows/ScriptManager.cs | 134 ++++++++++++++ PLCSharpWpf/VVMs/Workflows/Workflow.cs | 36 +++- .../VVMs/Workflows/WorkflowConfig.xaml | 54 +++--- .../VVMs/Workflows/WorkflowConfigViewModel.cs | 36 ++-- PLCSharpWpf/VVMs/Workflows/Workflows.xaml | 2 +- PLCSharpWpf/VVMs/Workflows/WorkflowsModel.cs | 1 + 49 files changed, 697 insertions(+), 257 deletions(-) create mode 100644 PLCSharpWpf/VVMs/Workflows/Script/网络等待接收.spt create mode 100644 PLCSharpWpf/VVMs/Workflows/Script/获取网络通信对象.spt create mode 100644 PLCSharpWpf/VVMs/Workflows/Script/获取视觉项目.spt create mode 100644 PLCSharpWpf/VVMs/Workflows/ScriptManageDialog.xaml create mode 100644 PLCSharpWpf/VVMs/Workflows/ScriptManageDialog.xaml.cs create mode 100644 PLCSharpWpf/VVMs/Workflows/ScriptManageDialogViewModel.cs create mode 100644 PLCSharpWpf/VVMs/Workflows/ScriptManager.cs diff --git a/AGENTS.md b/AGENTS.md index d5a62a1..af515d8 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -17,21 +17,22 @@ WPF/.NET 8 上位机软件,通过自由配置硬件、全局变量、界面和 # 编译 dotnet build PLCSharpWpf/PLCSharp.csproj -# 编译(覆盖输出目录,避免进程锁定) -dotnet build PLCSharpWpf/PLCSharp.csproj -p:OutputPath=bin\tmp +# 编译(进程锁定 bin 时,输出到系统临时目录,不污染项目;Windows 临时目录由系统自动清理) +dotnet build PLCSharpWpf/PLCSharp.csproj -p:OutputPath="$(cygpath -w "$TEMP")/plcsharp_tmp" # 运行 dotnet run --project PLCSharpWpf/PLCSharp.csproj # 发布为单文件 dotnet publish PLCSharpWpf/PLCSharp.csproj -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true - -# 清除临时目录 -rm -rf PLCSharpWpf/bin/tmp_* ``` +> 约定:临时编译输出一律指向系统临时目录(`$LOCALAPPDATA\Temp\plcsharp_tmp`),**严禁**用 `-p:OutputPath` 在项目目录下生成 `bintmp*`、`bin\tmp*` 之类的目录(历史遗留的 bintmp* 目录即为此类污染)。如需手动清理临时输出:`rm -rf "$LOCALAPPDATA/Temp/plcsharp_tmp"`。 + > 注意:无单元测试项目,目前无测试命令。 +> 约定:修改任何文件前,先将原文件备份到项目目录外(`$LOCALAPPDATA\Temp\plcsharp_backup\`),禁止在项目目录内生成 `.bak`;撤销/还原**禁用** `git checkout`/`git restore` 还原工作区文件(会冲掉用户未提交改动),需还原时用备份文件或手动精确编辑;所有改动/撤销/还原操作前先列方案给用户确认。 + ## Architecture ### 分层结构 diff --git a/PLCSharpWpf/Core/Common/FlowModel.cs b/PLCSharpWpf/Core/Common/FlowModel.cs index 383c2eb..1d524a0 100644 --- a/PLCSharpWpf/Core/Common/FlowModel.cs +++ b/PLCSharpWpf/Core/Common/FlowModel.cs @@ -32,14 +32,14 @@ public DateTime FlowStarTime { get; set; } = DateTime.Now; /// - /// 是否完成 + /// 结束退出 /// - public bool Done { get; set; } + public bool Completed { get; set; } /// - /// 流程是否正常结束(默认 false,正常结束时置 true) + /// 异常结束 false,正常结束true /// - public bool IsSuccess { get; set; } + public bool Success { get; set; } /// /// 失败原因(非空表示异常结束) @@ -64,8 +64,8 @@ /// public void Reset() { - Done = false; - IsSuccess = false; + Completed = false; + Success = false; FailMessage = null; Step = 0; StepTime = DateTime.Now; diff --git a/PLCSharpWpf/Models/GlobalModel.Recipes.cs b/PLCSharpWpf/Models/GlobalModel.Recipes.cs index 2dfab00..d6b654c 100644 --- a/PLCSharpWpf/Models/GlobalModel.Recipes.cs +++ b/PLCSharpWpf/Models/GlobalModel.Recipes.cs @@ -170,6 +170,14 @@ namespace PLCSharp.Models case "Current": if (RecipeSelected != null) { + if (CurrentRecipe.Name == RecipeSelected.Name) { + + SendInfoDialog($"当前配方已经是:{CurrentRecipe.Name},不需要切换。"); + break; + } + + if (System.Windows.MessageBox.Show($"确认切换配方 [{RecipeSelected.Name}]?", "确认切换", MessageBoxButton.YesNo, MessageBoxImage.Warning) != MessageBoxResult.Yes) + break; foreach (var item in _DatasContext.Recipes) { item.Current = false; diff --git a/PLCSharpWpf/VVMs/MotionController/AxisPoint.cs b/PLCSharpWpf/VVMs/MotionController/AxisPoint.cs index 756ee31..70c5127 100644 --- a/PLCSharpWpf/VVMs/MotionController/AxisPoint.cs +++ b/PLCSharpWpf/VVMs/MotionController/AxisPoint.cs @@ -491,7 +491,7 @@ namespace PLCSharp.VVMs.MotionController if (AxisZ == null || AxisZ.AbsoluteDone) { flowModel.Step = 0; - flowModel.Done = true; + flowModel.Completed = true; } break; @@ -596,7 +596,7 @@ namespace PLCSharp.VVMs.MotionController if (AxisZ == null || AxisZ.AbsoluteDone) { flowModel.Step = 0; - flowModel.Done = true; + flowModel.Completed = true; } break; } @@ -612,7 +612,7 @@ namespace PLCSharp.VVMs.MotionController if (AxisY is not null) { AxisY.Params.Rate = _Rate * _YRate / 100; } if (AxisZ is not null) { AxisZ.Params.Rate = _Rate * _ZRate / 100; } if (AxisU is not null) { AxisU.Params.Rate = _Rate * _URate / 100; } - flowModel.Done = false; + flowModel.Completed = false; flowModel.Step = 1; return true; } @@ -627,7 +627,7 @@ namespace PLCSharp.VVMs.MotionController if (AxisY is not null) { AxisY.Params.Rate = _Rate * _YRate / 100; } if (AxisZ is not null) { AxisZ.Params.Rate = _Rate * _ZRate / 100; } if (AxisU is not null) { AxisU.Params.Rate = _Rate * _URate / 100; } - flowModel.Done = false; + flowModel.Completed = false; flowModel.Step = 11; return true; } @@ -638,7 +638,7 @@ namespace PLCSharp.VVMs.MotionController /// 返回布尔值 public bool IsDone() { - return flowModel.Done; + return flowModel.Completed; } /// diff --git a/PLCSharpWpf/VVMs/MotionController/ControllersModel.cs b/PLCSharpWpf/VVMs/MotionController/ControllersModel.cs index 696f507..ef34d11 100644 --- a/PLCSharpWpf/VVMs/MotionController/ControllersModel.cs +++ b/PLCSharpWpf/VVMs/MotionController/ControllersModel.cs @@ -51,11 +51,12 @@ namespace PLCSharp.VVMs.MotionController public void Stop() { - bkgWorker.CancelAsync(); - - while (bkgWorker.IsBusy) + + while (bkgWorker != null && !bkgWorker.CancellationPending) { - Thread.Sleep(10); + + bkgWorker.CancelAsync(); + Thread.Sleep(0); } } diff --git a/PLCSharpWpf/VVMs/MotionController/InterpolationGroup.cs b/PLCSharpWpf/VVMs/MotionController/InterpolationGroup.cs index c9cf29c..7804365 100644 --- a/PLCSharpWpf/VVMs/MotionController/InterpolationGroup.cs +++ b/PLCSharpWpf/VVMs/MotionController/InterpolationGroup.cs @@ -314,7 +314,7 @@ namespace PLCSharp.VVMs.MotionController if (AxisX.InterpolationDone) { flowModel.Step = 0; - flowModel.Done = true; + flowModel.Completed = true; } break; @@ -327,7 +327,7 @@ namespace PLCSharp.VVMs.MotionController /// 返回布尔值 public bool Go() { - flowModel.Done = false; + flowModel.Completed = false; if (AxisX == null || AxisY == null) { @@ -349,7 +349,7 @@ namespace PLCSharp.VVMs.MotionController /// 返回布尔值 public bool IsDone() { - return flowModel.Done; + return flowModel.Completed; } /// diff --git a/PLCSharpWpf/VVMs/Vision/Camera/CameraConfigViewModel.cs b/PLCSharpWpf/VVMs/Vision/Camera/CameraConfigViewModel.cs index 9c967bb..9e305f7 100644 --- a/PLCSharpWpf/VVMs/Vision/Camera/CameraConfigViewModel.cs +++ b/PLCSharpWpf/VVMs/Vision/Camera/CameraConfigViewModel.cs @@ -146,7 +146,7 @@ namespace PLCSharp.VVMs.Vision.Camera { case "Trig": { - while (flow.Done == false) + while (flow.Completed == false) { Thread.Sleep(1); switch (flow.Step) @@ -169,7 +169,7 @@ namespace PLCSharp.VVMs.Vision.Camera case 2: Camera.SetTriggerSource(); - flow.Done = true; + flow.Completed = true; break; } if (flow.CheckFlowTime(10)) @@ -182,7 +182,7 @@ namespace PLCSharp.VVMs.Vision.Camera case "Continuous": { - while (flow.Done == false) + while (flow.Completed == false) { Thread.Sleep(1); switch (flow.Step) @@ -209,7 +209,7 @@ namespace PLCSharp.VVMs.Vision.Camera case 2: Camera.SetTriggerSource(); - flow.Done = true; + flow.Completed = true; break; } } diff --git a/PLCSharpWpf/VVMs/Vision/VisionConfigViewModel.Flows.cs b/PLCSharpWpf/VVMs/Vision/VisionConfigViewModel.Flows.cs index c63ea04..67ba903 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionConfigViewModel.Flows.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionConfigViewModel.Flows.cs @@ -1,5 +1,4 @@ -using PLCSharp.Core.Common; -using PLCSharp.VVMs.GlobalVariables; +using PLCSharp.VVMs.GlobalVariables; using PLCSharp.VVMs.Vision.Camera; using PLCSharp.VVMs.Vision.Models; using PLCSharp.VVMs.Vision.VisionFlowHandler.Access; @@ -196,22 +195,9 @@ public partial class VisionConfigViewModel { try { - await Task.Run(() => - { - var runAllFlow = new FlowModel(); - while (true) - { - Thread.Sleep(1); - if (SelectedVisionFunction.RunAll(runAllFlow)) - { - return; - } - else if (runAllFlow.CheckFlowTime(10)) - { - throw new Exception("流程超时!"); - } - } - }); + SelectedVisionFunction.Flow.Reset(); + await SelectedVisionFunction.RunAllAsync(); + } catch (Exception ex) { diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageFromCamera.xaml b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageFromCamera.xaml index b6c87ed..cbf52e5 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageFromCamera.xaml +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageFromCamera.xaml @@ -11,7 +11,10 @@ - + diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageFromCameraHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageFromCameraHandler.cs index db3a4c0..c5e8f84 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageFromCameraHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageFromCameraHandler.cs @@ -18,31 +18,14 @@ /// 返回布尔值 public bool Execute(VisionFunction func, VisionFlow item) { - switch (item.Flow.Step) + + if (item.StringParams.TryGetValue("Camera", out string cameraName)) { - case 0: - if (item.StringParams.TryGetValue("Camera", out string cameraName)) - { - item.Camera = func.VisionsModel.Cameras.Where(c => c.Name == cameraName).FirstOrDefault(); - if (item.Camera != null) - { - item.Camera.Params.ExposureTime = item.DoubleParams["ExposureTime"]; - item.Camera.Trig(); - item.Flow.Step++; - } - else - { - throw new Exception("未找到流程配置的相机!"); - } - } - else - { - throw new Exception("本流程未正确配置相机!"); - } - break; - - case 1: - + item.Camera = func.VisionsModel.Cameras.Where(c => c.Name == cameraName).FirstOrDefault(); + if (item.Camera != null) + { + item.Camera.Params.ExposureTime = item.DoubleParams["ExposureTime"]; + item.Camera.Trig(); if (item.Camera.WaitOne(3000)) { // 取独立拷贝,避免相机下一帧覆盖/释放当前 Mat 后,流程继续使用已释放的内存 @@ -52,13 +35,23 @@ throw new Exception("未获取到相机图像!"); } func.Src = frame; - item.Flow.Done = true; - item.Flow.Step++; + return true; } - break; + } + else + { + throw new Exception("未找到流程配置的相机!"); + } + } + else + { + throw new Exception("本流程未正确配置相机!"); } return false; + + + } } } \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageFromLocalHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageFromLocalHandler.cs index da83373..4f57467 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageFromLocalHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageFromLocalHandler.cs @@ -24,7 +24,7 @@ if (theMat != null) { func.Src = theMat.Mat.Clone(); - item.Flow.Done = true; + item.Flow.Completed = true; return true; } else diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageToGlobalHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageToGlobalHandler.cs index e16a8aa..f9277d7 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageToGlobalHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageToGlobalHandler.cs @@ -24,7 +24,7 @@ if (imageData != null) { imageData.Mat = func.Src.Clone(); - item.Flow.Done = true; + item.Flow.Completed = true; return true; } else diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageToHomePageHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageToHomePageHandler.cs index 603edbe..0ee9479 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageToHomePageHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageToHomePageHandler.cs @@ -24,7 +24,7 @@ if (customControl != null) { customControl.ShowMat(func.Src); - item.Flow.Done = true; + item.Flow.Completed = true; return true; } } diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageToLocalHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageToLocalHandler.cs index 826a7c1..6cc478f 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageToLocalHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Access/ImageToLocalHandler.cs @@ -23,7 +23,7 @@ if (func.LocalImageDatas.Where(w => w.Name == imageName).Any()) { func.LocalImageDatas.Where(w => w.Name == imageName).FirstOrDefault().Mat = func.Src.Clone(); - item.Flow.Done = true; + item.Flow.Completed = true; return true; } } diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/BarcodeDecodeHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/BarcodeDecodeHandler.cs index f9d8807..ef3a4f0 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/BarcodeDecodeHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/BarcodeDecodeHandler.cs @@ -1,7 +1,7 @@ #nullable enable -using OpenCvSharp; using Libdmtx; +using OpenCvSharp; using System.Runtime.InteropServices; using System.Windows.Media; using ZXing; @@ -118,6 +118,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm if (pbResult != null) { return OutputResult(func, item, pbResult, roiLeft, roiTop, workW, workH, scaleInv, pipeline: -1); + } } @@ -151,7 +152,12 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm { int libPipeline = -1; DecodeResult[]? libResults = null; - var libOptions = new DecodeOptions { TimeoutMs = 100, MaxCodes = 10, ScanGap = 1, Shrink = 1, + var libOptions = new DecodeOptions + { + TimeoutMs = 100, + MaxCodes = 10, + ScanGap = 1, + Shrink = 1, EdgeMin = dmMinEdge > 0 ? dmMinEdge : null, EdgeMax = dmMaxEdge > 0 ? dmMaxEdge : null, }; @@ -206,7 +212,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm func.DrawCommands.Add(DrawCommand.Line(roiLeft, roiTop + imgH, roiLeft, roiTop, Colors.Red, 1)); } - item.Flow.Done = true; + item.Flow.Completed = true; return true; } @@ -321,7 +327,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm Y1 = ty, Text = decodedText.Length > 60 ? decodedText[..60] + "…" : decodedText, Color = Colors.Lime, - FontSize = 48, + FontSize = 24, }); } else @@ -362,7 +368,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm _ = func.RenderDrawAsync(); - item.Flow.Done = true; + item.Flow.Completed = true; return true; } @@ -557,16 +563,17 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm var existingVar = func.Params.Variables.FirstOrDefault(v => v.Name == varName); if (existingVar == null) { - existingVar = new LocalVariableItem(varName, "Barcode", new Barcode(new Pos(), "")); + existingVar = new LocalVariableItem(varName, "Barcode", new Barcode(new Pos(boxCX, boxCY, 0, 0), result.Text)); System.Windows.Application.Current.Dispatcher.Invoke( () => func.Params.Variables.Add(existingVar)); } - existingVar.RawValue = new Barcode(new Pos(boxCX, boxCY, 0, 0), result.Text); + + func.ResultBarcode = new Barcode(new Pos(boxCX, boxCY, 0, 0), result.Text); } _ = func.RenderDrawAsync(); - item.Flow.Done = true; + item.Flow.Completed = true; return true; } } diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/CaliperFindCircleHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/CaliperFindCircleHandler.cs index 729cf69..abc6865 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/CaliperFindCircleHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/CaliperFindCircleHandler.cs @@ -210,7 +210,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm item.DoubleParams["TemplateCircleCX"] = Math.Round(circle.CenterX, 3); item.DoubleParams["TemplateCircleCY"] = Math.Round(circle.CenterY, 3); item.DoubleParams["TemplateCircleR"] = Math.Round(circle.Radius, 3); - item.Flow.Done = true; + item.Flow.Completed = true; return true; } @@ -264,7 +264,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm } } - item.Flow.Done = true; + item.Flow.Completed = true; _ = func.RenderDrawAsync(); return true; } diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/CaliperFindEdgeHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/CaliperFindEdgeHandler.cs index a0f4fce..d2a3674 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/CaliperFindEdgeHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/CaliperFindEdgeHandler.cs @@ -166,7 +166,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm item.DoubleParams["TemplateLineEndX"] = Math.Round(te.X, 3); item.DoubleParams["TemplateLineEndY"] = Math.Round(te.Y, 3); item.DoubleParams["TemplateLineAngle"] = Math.Round(Math.Atan2(te.Y - ts.Y, te.X - ts.X) * 180 / Math.PI, 3); - item.Flow.Done = true; + item.Flow.Completed = true; return true; } @@ -261,7 +261,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm } } _ = func.RenderDrawAsync(); - item.Flow.Done = true; + item.Flow.Completed = true; return true; } diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/CaliperFindRectHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/CaliperFindRectHandler.cs index 8869684..3b9a9cb 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/CaliperFindRectHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/CaliperFindRectHandler.cs @@ -236,7 +236,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm item.DoubleParams["TemplateRectCX"] = Math.Round(fitCx, 3); item.DoubleParams["TemplateRectCY"] = Math.Round(fitCy, 3); item.DoubleParams["TemplateRectAngle"] = Math.Round(fitAngle, 3); - item.Flow.Done = true; + item.Flow.Completed = true; return true; } @@ -295,7 +295,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm offsetVar.RawValue = new Pos(offsetX, offsetY, 0, offsetAngle); } - item.Flow.Done = true; + item.Flow.Completed = true; _ = func.RenderDrawAsync(); return true; } diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/ClearDrawHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/ClearDrawHandler.cs index 5138b18..c443014 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/ClearDrawHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/ClearDrawHandler.cs @@ -14,8 +14,6 @@ func.DrawCommands.Clear(); func.EditImageEdit?.Remove("DrawOverlay"); func.GlobalModel.GetImageControl(func.ControlName)?.Remove("DrawOverlay"); - - item.Flow.Done = true; }); return true; } diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/ColorAreaHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/ColorAreaHandler.cs index 511719d..395aac2 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/ColorAreaHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/ColorAreaHandler.cs @@ -116,7 +116,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm // 写入判定结果到StringParams(用于UI绑定显示) item.StringParams["ColorAreaResult"] = result; - item.Flow.Done = true; + item.Flow.Completed = true; _ = func.RenderDrawAsync(); return true; } diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/GalleryClassifierHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/GalleryClassifierHandler.cs index fec6068..92c4f0a 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/GalleryClassifierHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/GalleryClassifierHandler.cs @@ -87,7 +87,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm } _ = func.RenderDrawAsync(); - item.Flow.Done = true; + item.Flow.Completed = true; return true; } finally diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/GrayAreaHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/GrayAreaHandler.cs index 66868a0..f05484e 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/GrayAreaHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/GrayAreaHandler.cs @@ -107,7 +107,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm // 写入判定结果到StringParams(用于UI绑定显示) item.StringParams["GrayAreaResult"] = result; - item.Flow.Done = true; + item.Flow.Completed = true; _ = func.RenderDrawAsync(); return true; } diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/GrayTemplateMatchHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/GrayTemplateMatchHandler.cs index 975ecdb..3de79e1 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/GrayTemplateMatchHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/GrayTemplateMatchHandler.cs @@ -280,7 +280,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm $"[灰度模板匹配] {totalTemplates} templates", lime, 48)); _ = func.RenderDrawAsync(); - item.Flow.Done = true; + item.Flow.Completed = true; return true; } finally diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/MatrixGenHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/MatrixGenHandler.cs index 4b88acb..63ce621 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/MatrixGenHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/MatrixGenHandler.cs @@ -36,7 +36,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm v.RawValue = json; } - item.Flow.Done = true; + item.Flow.Completed = true; return true; } } diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/ORBMatchHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/ORBMatchHandler.cs index 843b446..beb08c0 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/ORBMatchHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/ORBMatchHandler.cs @@ -341,7 +341,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm func.Src = reMat; colorSrc?.Dispose(); - item.Flow.Done = true; + item.Flow.Completed = true; return true; } finally diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/PointToLineDistanceHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/PointToLineDistanceHandler.cs index e79ae46..796c00a 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/PointToLineDistanceHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/PointToLineDistanceHandler.cs @@ -136,7 +136,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm (point.X + footX) / 2, (point.Y + footY) / 2 - 10, $"{func.Params.ResultDoubles["PointLineDist_Distance"]:F3}", Colors.Lime, 48)); _ = func.RenderDrawAsync(); - item.Flow.Done = true; + item.Flow.Completed = true; return true; } } diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/PointToPointDistanceHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/PointToPointDistanceHandler.cs index ac51e29..d64a6fb 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/PointToPointDistanceHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/PointToPointDistanceHandler.cs @@ -96,7 +96,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm (pos1.X + pos2.X) / 2 + 5, (pos1.Y + pos2.Y) / 2 - 5, $"{func.Params.ResultDoubles["PointDist_Distance"]:F3}", Colors.Lime, 48)); _ = func.RenderDrawAsync(); - item.Flow.Done = true; + item.Flow.Completed = true; return true; } } diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/SiftMatchHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/SiftMatchHandler.cs index 216e9f1..b4bc89a 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/SiftMatchHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/SiftMatchHandler.cs @@ -286,7 +286,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm func.Src = reMat; colorSrc?.Dispose(); - item.Flow.Done = true; + item.Flow.Completed = true; return true; } finally diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/TwoLineIntersectHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/TwoLineIntersectHandler.cs index 36d10b4..58e8e9b 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/TwoLineIntersectHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/TwoLineIntersectHandler.cs @@ -45,7 +45,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm item.DoubleParams["TemplateIntersectX"] = ix; item.DoubleParams["TemplateIntersectY"] = iy; item.DoubleParams["TemplateLineAngle"] = line1Angle; - item.Flow.Done = true; + item.Flow.Completed = true; return true; } @@ -105,7 +105,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm } } - item.Flow.Done = true; + item.Flow.Completed = true; return true; } } diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/WeChatDecodeHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/WeChatDecodeHandler.cs index 3422bca..f03ddcb 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/WeChatDecodeHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/WeChatDecodeHandler.cs @@ -129,7 +129,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm _ = func.RenderDrawAsync(); - item.Flow.Done = true; + item.Flow.Completed = true; return true; } @@ -137,7 +137,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm item.StringParams["DecodeResult"] = ""; func.Params.ResultDoubles["DecodeSuccess"] = 0; func.Params.ResultDoubles["DecodeCount"] = 0; - item.Flow.Done = true; + item.Flow.Completed = true; return true; } } diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Processing/Bgr2GrayHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Processing/Bgr2GrayHandler.cs index 20f285f..1bd2d0e 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Processing/Bgr2GrayHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Processing/Bgr2GrayHandler.cs @@ -23,7 +23,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Processing if (func.Src.Channels() == 3) { Cv2.CvtColor(func.Src, func.Src, ColorConversionCodes.BGR2GRAY); - item.Flow.Done = true; + item.Flow.Completed = true; } return true; } diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Processing/CoordinateTransformHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Processing/CoordinateTransformHandler.cs index abd5402..49fde38 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Processing/CoordinateTransformHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Processing/CoordinateTransformHandler.cs @@ -141,7 +141,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Processing outVar.RawValue = resultValue; } - item.Flow.Done = true; + item.Flow.Completed = true; return true; } } diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Processing/HistogramEqualizeHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Processing/HistogramEqualizeHandler.cs index 7057ae4..675010e 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Processing/HistogramEqualizeHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Processing/HistogramEqualizeHandler.cs @@ -39,7 +39,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Processing clahe.Apply(src, src); } - item.Flow.Done = true; + item.Flow.Completed = true; return true; } } diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Processing/ImageWarpHandler.cs b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Processing/ImageWarpHandler.cs index ab1a80d..35772ee 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Processing/ImageWarpHandler.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Processing/ImageWarpHandler.cs @@ -52,7 +52,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Processing func.Src = warped.Clone(); oldSrc.Dispose(); - item.Flow.Done = true; + item.Flow.Completed = true; return true; } } diff --git a/PLCSharpWpf/VVMs/Vision/VisionFunction.cs b/PLCSharpWpf/VVMs/Vision/VisionFunction.cs index 3582050..e739d9e 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionFunction.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionFunction.cs @@ -14,6 +14,7 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Diagnostics; using System.Text.Json; +using System.Threading; using System.Windows.Media; namespace PLCSharp.VVMs.Vision @@ -254,82 +255,87 @@ namespace PLCSharp.VVMs.Vision /// /// 流程状态模型 /// 返回布尔值 - public bool RunAll(FlowModel flow) + public async Task RunAllAsync() { - switch (flow.Step) + Flow.Completed = false; + while (!Flow.Completed) { - case 0: - index = 0; - flow.Step++; - System.Windows.Application.Current.Dispatcher.Invoke(() => - { - DrawCommands.Clear(); - EditImageEdit?.Remove("DrawOverlay"); - GlobalModel.GetImageControl(ControlName)?.Remove("DrawOverlay"); - }); - break; - - case 1: - if (VisionFlows.Count > index) - { - VisionFlows[index].Flow.Reset(); - flow.Step++; - } - else - { - var customControl = GlobalModel.GetCustomControl(ControlName); - if (customControl != null && Src != null) + switch (Flow.Step) + { + case 0: + index = 0; + Flow.Step++; + System.Windows.Application.Current.Dispatcher.Invoke(() => { - customControl.ShowMat(Src); + DrawCommands.Clear(); + EditImageEdit?.Remove("DrawOverlay"); + GlobalModel.GetImageControl(ControlName)?.Remove("DrawOverlay"); + }); + break; + + case 1: + if (VisionFlows.Count > index) + { + VisionFlows[index].Flow.Reset(); + Flow.Step++; } - flow.Done = true; - flow.IsSuccess = true; - } - break; - - case 2: - { - Sw.Restart(); - var item = VisionFlows[index]; - flow.TaskBool = System.Threading.Tasks.Task.Run(() => RunItem(item)); - item.Flow.StepTime = DateTime.Now; - flow.Step++; - } - break; - - case 3: - { - var item = VisionFlows[index]; - var task = flow.TaskBool; - if (task == null) { flow.Step--; break; } - if (task.IsCompleted) + else { - Sw.Stop(); - item.CT = Math.Round(Sw.ElapsedMilliseconds / 1000.0, 3); // 转换为秒 - if (task.Result) + var customControl = GlobalModel.GetCustomControl(ControlName); + if (customControl != null && Src != null) { - flow.Step = 1; // 回到 case 1 取下一个 - index++; + customControl.ShowMat(Src); } - else + Flow.Completed = true; + Flow.Success = true; + } + break; + + case 2: + { + Sw.Restart(); + Flow.Step++; + } + break; + + case 3: + { + // 设置 5 秒超时 + using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); + var item = VisionFlows[index]; + try { - item.Flow.FailMessage ??= "未知错误"; - flow.IsSuccess = false; - flow.Done = true; + + item.Flow.StepTime = DateTime.Now; + var result = await Task.Run(() => RunItem(item)); + item.CT = Math.Round(Sw.ElapsedMilliseconds / 1000.0, 3); // 转换为秒 + Sw.Stop(); + if (result) + { + Flow.Step = 1; // 回到 case 1 取下一个 + index++; + } + else + { + item.Flow.FailMessage ??= "未知错误"; + Flow.Success = false; + Flow.Completed = true; + } + } + catch (OperationCanceledException) when (cts.IsCancellationRequested) + { + Sw.Stop(); + item.CT = Math.Round(Sw.ElapsedMilliseconds / 1000.0, 3); // 转换为秒 + item.Flow.FailMessage = $"执行超时(>{Flow.TimeoutSeconds:F0}秒)"; + Flow.Success = false; + Flow.Completed = true; } } - else if (item.Flow.CheckStepTime(flow.TimeoutSeconds)) - { - Sw.Stop(); - item.CT = Math.Round(Sw.ElapsedMilliseconds / 1000.0, 3); // 转换为秒 - item.Flow.FailMessage = $"执行超时(>{flow.TimeoutSeconds:F0}秒)"; - flow.IsSuccess = false; - flow.Done = true; - } - } - break; + break; + } } - return flow.Done; + return true; + } /// diff --git a/PLCSharpWpf/VVMs/Vision/VisionsViewModel.cs b/PLCSharpWpf/VVMs/Vision/VisionsViewModel.cs index ac2ad0f..14242d7 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionsViewModel.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionsViewModel.cs @@ -165,7 +165,7 @@ namespace PLCSharp.VVMs.Vision { case "Trig": { - while (flow.Done == false) + while (flow.Completed == false) { switch (flow.Step) { @@ -189,7 +189,7 @@ namespace PLCSharp.VVMs.Vision case 2: Camera.SetTriggerSource(); - flow.Done = true; + flow.Completed = true; break; } if (flow.CheckFlowTime(10)) @@ -202,7 +202,7 @@ namespace PLCSharp.VVMs.Vision case "Continuous": { - while (flow.Done == false) + while (flow.Completed == false) { switch (flow.Step) { @@ -228,7 +228,7 @@ namespace PLCSharp.VVMs.Vision case 2: Camera.SetTriggerSource(); - flow.Done = true; + flow.Completed = true; break; } } diff --git a/PLCSharpWpf/VVMs/Workflows/Extension.cs b/PLCSharpWpf/VVMs/Workflows/Extension.cs index 113efdc..e8ba224 100644 --- a/PLCSharpWpf/VVMs/Workflows/Extension.cs +++ b/PLCSharpWpf/VVMs/Workflows/Extension.cs @@ -28,43 +28,25 @@ namespace PLCSharp.VVMs.Workflows { switch (flow.Step) { - //视觉功能 - case 0: - CurrVF = globalModel.GetVisionFunction("视觉功能名"); - CurrVF.Flow.Reset(); - flow.Step++; - - break; - - case 1: - if (CurrVF.RunAll(CurrVF.Flow)) - { - flow.Step++; - } - else if (flow.CheckStepTime(3)) - { - flow.Step--; - throw new Exception("视觉功能超时!"); - } - break; //全局变量 - case 2: + case 3: + ; CurrVariable = globalModel.GetVariable("变量名"); CurrVariable.Value = 100; // 设置变量值 flow.Step++; break; //机器人绝对运动 - case 3: + case 4: CurrRobot = globalModel.GetRobot("机器人名称"); flow.Step++; break; - case 4: + case 5: CurrRobot.RunPoint("点位名称"); flow.Step++; break; - case 5: + case 6: if (CurrRobot.PointDone) // 等待运动完成 { flow.Step++; @@ -77,12 +59,12 @@ namespace PLCSharp.VVMs.Workflows break; //机器人相对运动 - case 6: + case 7: CurrRobot.Jog("点位名称", "X+", 10); flow.Step++; break; - case 7: + case 8: if (CurrRobot.PointDone) // 等待运动完成 { flow.Step++; @@ -94,7 +76,7 @@ namespace PLCSharp.VVMs.Workflows } break; - case 8: + case 9: //显示状态 CurrControl = globalModel.GetCustomControl("控件名称"); if (CurrControl != null) @@ -109,7 +91,7 @@ namespace PLCSharp.VVMs.Workflows break; //网络通信 SocketServer广播 /SocketClient / FreeSerialProtocol - case 9: + case 10: CurrConnect = globalModel.GetConnect("网络连接名"); flow.TaskBool = CurrConnect.SendAsync("要发送的消息"); @@ -117,7 +99,7 @@ namespace PLCSharp.VVMs.Workflows break; - case 10: + case 11: if (flow.TaskBool.IsCompleted) { if (flow.TaskBool.Result) @@ -148,13 +130,13 @@ namespace PLCSharp.VVMs.Workflows break; //网络通信 SocketServer 向指定客户端发送消息 - case 11: + case 12: CurrConnect = globalModel.GetConnect("网络连接名"); flow.TaskBool = CurrConnect.SendAsync("要发送的消息", "客户端名称"); flow.Step++; break; - case 12: + case 13: if (flow.TaskBool.IsCompleted) { if (flow.TaskBool.Result) diff --git a/PLCSharpWpf/VVMs/Workflows/Script/网络等待接收.spt b/PLCSharpWpf/VVMs/Workflows/Script/网络等待接收.spt new file mode 100644 index 0000000..81265c0 --- /dev/null +++ b/PLCSharpWpf/VVMs/Workflows/Script/网络等待接收.spt @@ -0,0 +1,7 @@ + if (!string.IsNullOrEmpty(CurrConnect.ReceiveInfo)) + { + CurrVariable.Value = CurrConnect.ReceiveInfo; // 设置变量值 + CurrController.SetDQ(Y001, 1); // 0=通, 1=断 + //这里处理 接收到的消息 CurrConnect.ReceiveInfo + flow.Step++; + } diff --git a/PLCSharpWpf/VVMs/Workflows/Script/获取网络通信对象.spt b/PLCSharpWpf/VVMs/Workflows/Script/获取网络通信对象.spt new file mode 100644 index 0000000..5767a6c --- /dev/null +++ b/PLCSharpWpf/VVMs/Workflows/Script/获取网络通信对象.spt @@ -0,0 +1 @@ +CurrConnect = globalModel.GetConnect("网络连接名"); \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Workflows/Script/获取视觉项目.spt b/PLCSharpWpf/VVMs/Workflows/Script/获取视觉项目.spt new file mode 100644 index 0000000..20e089d --- /dev/null +++ b/PLCSharpWpf/VVMs/Workflows/Script/获取视觉项目.spt @@ -0,0 +1 @@ +CurrVision = globalModel.GetVisionFunction("视觉项目名称"); \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Workflows/ScriptManageDialog.xaml b/PLCSharpWpf/VVMs/Workflows/ScriptManageDialog.xaml new file mode 100644 index 0000000..dd828e0 --- /dev/null +++ b/PLCSharpWpf/VVMs/Workflows/ScriptManageDialog.xaml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + +