From 7d94a8ecb71b80a5646602bf774294234cc2b4da Mon Sep 17 00:00:00 2001 From: tfarcraw <123211521@163.com> Date: Sun, 5 Jul 2026 22:39:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E5=BF=AB=E6=8D=B7=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PLCSharpWpf/Core/Common/FlowModel.cs | 4 +- PLCSharpWpf/VVMs/Connects/Connect.cs | 84 +++++----- PLCSharpWpf/VVMs/Robots/Epson/EpsonRobot.cs | 79 ++++----- PLCSharpWpf/VVMs/Robots/Robot.cs | 10 +- PLCSharpWpf/VVMs/Robots/RobotsViewModel.cs | 64 +++---- PLCSharpWpf/VVMs/Workflows/Extension.cs | 157 +++++++++++------- .../VVMs/Workflows/Script/全局变量.spt | 6 + .../VVMs/Workflows/Script/变量赋值.spt | 7 - .../VVMs/Workflows/Script/机器人Jog.spt | 24 +++ .../VVMs/Workflows/Script/机器人Move.spt | 21 +++ .../VVMs/Workflows/Script/机器人运动.spt | 20 --- .../Script/网络指定客户端.spt | 37 +++++ .../VVMs/Workflows/Script/网络收发.spt | 53 ++++-- .../VVMs/Workflows/Script/视觉功能.spt | 34 ++-- 14 files changed, 361 insertions(+), 239 deletions(-) create mode 100644 PLCSharpWpf/VVMs/Workflows/Script/全局变量.spt delete mode 100644 PLCSharpWpf/VVMs/Workflows/Script/变量赋值.spt create mode 100644 PLCSharpWpf/VVMs/Workflows/Script/机器人Jog.spt create mode 100644 PLCSharpWpf/VVMs/Workflows/Script/机器人Move.spt delete mode 100644 PLCSharpWpf/VVMs/Workflows/Script/机器人运动.spt create mode 100644 PLCSharpWpf/VVMs/Workflows/Script/网络指定客户端.spt diff --git a/PLCSharpWpf/Core/Common/FlowModel.cs b/PLCSharpWpf/Core/Common/FlowModel.cs index aefa053..d3d1ec6 100644 --- a/PLCSharpWpf/Core/Common/FlowModel.cs +++ b/PLCSharpWpf/Core/Common/FlowModel.cs @@ -1,4 +1,4 @@ -namespace PLCSharp.Core.Common +namespace PLCSharp.Core.Common { /// /// 流程模型 @@ -75,5 +75,7 @@ namespace PLCSharp.Core.Common return FlowStarTime.AddSeconds(second) < DateTime.Now; } + + public Task TaskBool { get; set; } } } diff --git a/PLCSharpWpf/VVMs/Connects/Connect.cs b/PLCSharpWpf/VVMs/Connects/Connect.cs index d4477a0..08254d5 100644 --- a/PLCSharpWpf/VVMs/Connects/Connect.cs +++ b/PLCSharpWpf/VVMs/Connects/Connect.cs @@ -1,4 +1,4 @@ -using Microsoft.EntityFrameworkCore.Metadata.Internal; +using Microsoft.EntityFrameworkCore.Metadata.Internal; using Newtonsoft.Json; using PLCSharp.VVMs.Connects.ModbusTcp; using PLCSharp.VVMs.Connects.Socket; @@ -70,12 +70,10 @@ namespace PLCSharp.VVMs.Connects private ProtocolType _Type; /// - /// 类型 - /// - [JsonIgnore] - /// /// 协议类型 /// + [JsonIgnore] + public ProtocolType Type { get { return _Type; } @@ -111,12 +109,10 @@ namespace PLCSharp.VVMs.Connects private bool _LogSwitch; /// - /// 日志Switch - /// - [NotMapped] - /// /// 日志开关 /// + [NotMapped] + public bool LogSwitch { get { return _LogSwitch; } @@ -125,12 +121,10 @@ namespace PLCSharp.VVMs.Connects private bool _Connected; /// - /// Connected - /// - [NotMapped] - /// /// 连接成功 /// + [NotMapped] + public bool Connected { get { return _Connected; } @@ -139,12 +133,10 @@ namespace PLCSharp.VVMs.Connects private bool _Successful; /// - /// Successful - /// - [NotMapped] - /// /// 读写成功 /// + [NotMapped] + public bool Successful { get { return _Successful; } @@ -154,12 +146,10 @@ namespace PLCSharp.VVMs.Connects private bool _Online; /// - /// Online - /// - [NotMapped] - /// /// 在线 /// + [NotMapped] + public bool Online { get { return _Online; } @@ -167,9 +157,7 @@ namespace PLCSharp.VVMs.Connects } private string _ReceiveInfo; - /// - /// 接收信息 - /// + [NotMapped] /// /// 收到的信息 @@ -182,9 +170,7 @@ namespace PLCSharp.VVMs.Connects private byte[] _ReceiveData; - /// - /// 接收数据 - /// + [NotMapped] /// /// 收到的数据 @@ -195,9 +181,7 @@ namespace PLCSharp.VVMs.Connects set { SetProperty(ref _ReceiveData, value); } } private string _SendInfo; - /// - /// 发送信息 - /// + [NotMapped] /// /// 要发送的信息 @@ -207,6 +191,11 @@ namespace PLCSharp.VVMs.Connects get { return _SendInfo; } set { SetProperty(ref _SendInfo, value); } } + /// + /// 告警信息 + /// + [NotMapped] + public string ErrInfo { get; set; } = "无异常"; /// /// 序列化Params @@ -336,7 +325,7 @@ namespace PLCSharp.VVMs.Connects if (LogQueue.Count > 1000) LogQueue.TryDequeue(out _); - RaisePropertyChanged("LogQueue"); + RaisePropertyChanged(nameof(LogQueue)); } } #endregion @@ -395,11 +384,11 @@ namespace PLCSharp.VVMs.Connects /// /// msg /// 返回结果 - public virtual async Task SendAsync(string msg) + public virtual async Task SendAsync(string msg) { if (Params.DataType == CommunicationDataType.String) { - await SendMsgAsync(msg); + return await SendMsgAsync(msg); } else @@ -407,11 +396,14 @@ namespace PLCSharp.VVMs.Connects if (HexStringToBytes(msg, out List bytes, out string format)) { SendInfo = format; - await SendDataAsync([.. bytes]); + return await SendDataAsync([.. bytes]); } else { - Log("请输入正确的十六进制字符串"); + ErrInfo = "请输入正确的十六进制字符串"; + Log(ErrInfo); + return false; + } } @@ -423,14 +415,14 @@ namespace PLCSharp.VVMs.Connects /// msg /// 客户端名称 /// 返回结果 - public virtual async Task SendAsync(string msg, string clientName) + public virtual async Task SendAsync(string msg, string clientName) { if (this is SocketServer server) { if (Params.DataType == CommunicationDataType.String) { - await server.SendMsgAsync(msg, clientName); + return await server.SendMsgAsync(msg, clientName); } else @@ -439,20 +431,29 @@ namespace PLCSharp.VVMs.Connects if (HexStringToBytes(msg, out List bytes, out string format)) { SendInfo = format; - await server.SendDataAsync([.. bytes], clientName); + return await server.SendDataAsync([.. bytes], clientName); } else { - Log("请输入正确的十六进制字符串"); + ErrInfo = "请输入正确的十六进制字符串"; + Log(ErrInfo); + return false; } } - - } } + else + { + ErrInfo = "此连接不是服务器"; + Log(ErrInfo); + return false; + + } } + + /// /// 发送HexMsgAsync /// @@ -478,6 +479,7 @@ namespace PLCSharp.VVMs.Connects { if (string.IsNullOrEmpty(msg)) { + ErrInfo = "消息为空,未发送"; Log($"{DateTime.Now:HH:mm:ss:fff} 消息为空,未发送"); return false; } diff --git a/PLCSharpWpf/VVMs/Robots/Epson/EpsonRobot.cs b/PLCSharpWpf/VVMs/Robots/Epson/EpsonRobot.cs index b51fc42..bb5ed5c 100644 --- a/PLCSharpWpf/VVMs/Robots/Epson/EpsonRobot.cs +++ b/PLCSharpWpf/VVMs/Robots/Epson/EpsonRobot.cs @@ -278,33 +278,30 @@ public class EpsonRobot : Robot } - private bool SendCommand(RobotPoint point) + private void SendCommand(RobotPoint point) { - try + if (!ClientCtrl.Connected) { - - ClientCommand.ReceiveInfo = ""; - if (!point.Safe) - { - RcvShowInfo = "不安全,请检查点位"; - return false; - } - - Status[12] = false; - if (!ClientCommand.Connected) return false; - - var speedPercent = (int)(point.Rate * Speed / 100); - var sendMsg = - $"@{point.Command} {speedPercent} {point.X} {point.Y} {point.Z} {point.U} {point.V} {point.W},{point.Hand}\r\n"; - ClientCommand.SendMsg(sendMsg); - - return true; + throw new Exception($"机器人未连接"); } - catch (Exception ex) + if (!ClientCommand.Connected) { - System.Diagnostics.Debug.WriteLine($"SendCommand 失败: {ex.Message}"); - return false; + throw new Exception($"机器人未启动"); } + ClientCommand.ReceiveInfo = ""; + if (!point.Safe) + { + throw new Exception($"机器人点位{point.Name}不安全"); + } + + Status[12] = false; + + + var speedPercent = (int)(point.Rate * Speed / 100); + var sendMsg = + $"@{point.Command} {speedPercent} {point.X} {point.Y} {point.Z} {point.U} {point.V} {point.W},{point.Hand}\r\n"; + ClientCommand.SendMsg(sendMsg); + } /// @@ -312,17 +309,13 @@ public class EpsonRobot : Robot /// /// 点位 /// 返回布尔值 - public override bool RunPoint(string pointName) + public override void RunPoint(string pointName) { PointDone = false; - var point = Points.FirstOrDefault(p => p.Name == pointName); - if (point == null) - { - return false; - } + var point = Points.FirstOrDefault(p => p.Name == pointName) ?? throw new Exception($"机器人点位{pointName}不存在"); point.Command = "RunPoint"; PointCommand = point.DeepCopy(); - return SendCommand(PointCommand); + SendCommand(PointCommand); } /// @@ -333,15 +326,11 @@ public class EpsonRobot : Robot /// /// /// - public override bool Jog(string pointName, string cmd, double dist, double rate = 0) + public override void Jog(string pointName, string cmd, double dist, double rate = 0) { PointDone = false; - var cmdDone = false; - var point = Points.FirstOrDefault(p => p.Name == pointName); - if (point == null) - { - return false; - } + + var point = Points.FirstOrDefault(p => p.Name == pointName) ?? throw new Exception($"机器人点位{pointName}不存在"); PointCommand = CurrPoint.DeepCopy(); @@ -353,29 +342,29 @@ public class EpsonRobot : Robot case "X-": PointCommand.Command = cmd; PointCommand.X = dist; - PointCommand.Rate = rate > 0 ? rate : point.Rate; - cmdDone = SendCommand(PointCommand); + PointCommand.Rate = rate > 0 ? rate : point.Rate; + SendCommand(PointCommand); break; case "Y+": case "Y-": PointCommand.Command = cmd; PointCommand.Y = dist; PointCommand.Rate = rate > 0 ? rate : point.Rate; - cmdDone = SendCommand(PointCommand); + SendCommand(PointCommand); break; case "Z+": case "Z-": PointCommand.Command = cmd; PointCommand.Z = dist; PointCommand.Rate = rate > 0 ? rate : point.Rate; - cmdDone = SendCommand(PointCommand); + SendCommand(PointCommand); break; case "U+": case "U-": PointCommand.Command = cmd; PointCommand.U = dist; PointCommand.Rate = rate > 0 ? rate : point.Rate; - cmdDone = SendCommand(PointCommand); + SendCommand(PointCommand); break; } } @@ -386,24 +375,21 @@ public class EpsonRobot : Robot var tool = Tools.FirstOrDefault(w => w.Key == point.ToolNum); - if (tool.Value == null) return false; + if (tool.Value == null) throw new Exception("工具坐标配置"); var pointTool = ToolFrame4Axis.WorldToTool(PointCommand, tool.Value); switch (cmd) { - case "X+": pointTool.X += dist; break; case "X-": - pointTool.X -= dist; break; case "Y+": pointTool.Y += dist; break; case "Y-": - pointTool.Y -= dist; break; case "Z+": @@ -422,10 +408,9 @@ public class EpsonRobot : Robot } var pointWord = ToolFrame4Axis.ToolToWorld(pointTool, tool.Value); - cmdDone = SendCommand(pointWord); + SendCommand(pointWord); } - return cmdDone; } /// diff --git a/PLCSharpWpf/VVMs/Robots/Robot.cs b/PLCSharpWpf/VVMs/Robots/Robot.cs index ed8b147..29157fa 100644 --- a/PLCSharpWpf/VVMs/Robots/Robot.cs +++ b/PLCSharpWpf/VVMs/Robots/Robot.cs @@ -415,9 +415,9 @@ namespace PLCSharp.VVMs.Robots /// /// 机器人点位 /// 返回布尔值 - public virtual bool RunPoint(string pointName) + public virtual void RunPoint(string pointName) { - return false; + } /// @@ -428,11 +428,9 @@ namespace PLCSharp.VVMs.Robots /// dist /// rate /// 返回布尔值 - public virtual bool Jog(string pointName, string cmd, double dist, double rate = 0) + public virtual void Jog(string pointName, string cmd, double dist, double rate = 0) { - - return false; - + } /// diff --git a/PLCSharpWpf/VVMs/Robots/RobotsViewModel.cs b/PLCSharpWpf/VVMs/Robots/RobotsViewModel.cs index a5d1254..53191e9 100644 --- a/PLCSharpWpf/VVMs/Robots/RobotsViewModel.cs +++ b/PLCSharpWpf/VVMs/Robots/RobotsViewModel.cs @@ -296,40 +296,48 @@ namespace PLCSharp.VVMs.Robots void ExecuteRobotPointCommand(object cmd) { - - var cmdStr = cmd as string; - if (SelectedRobot.SelectedPoint == null) + try { - SendInfoDialog("请选择点位"); - return; - } - SelectedRobot.SelectedPoint.Safe = true; - switch (cmdStr) + var cmdStr = cmd as string; + if (SelectedRobot.SelectedPoint == null) + { + SendInfoDialog("请选择点位"); + return; + } + SelectedRobot.SelectedPoint.Safe = true; + switch (cmdStr) + { + case "RunPoint": + + SelectedRobot.RunPoint(SelectedRobot.SelectedPoint.Name); + break; + + + case "X+": + case "X-": + + case "Y+": + case "Y-": + + case "Z+": + case "Z-": + + case "U+": + case "U-": + + SelectedRobot.Jog(SelectedRobot.SelectedPoint.Name, cmdStr, RelativeDistance); + break; + } + } + catch (Exception ex) { - case "RunPoint": - - SelectedRobot.RunPoint(SelectedRobot.SelectedPoint.Name); - break; - - - case "X+": - case "X-": - - case "Y+": - case "Y-": - - case "Z+": - case "Z-": - - case "U+": - case "U-": - - SelectedRobot.Jog(SelectedRobot.SelectedPoint.Name, cmdStr, RelativeDistance); - break; + SendErrDialog(ex.Message); } + + } diff --git a/PLCSharpWpf/VVMs/Workflows/Extension.cs b/PLCSharpWpf/VVMs/Workflows/Extension.cs index c36f996..103f548 100644 --- a/PLCSharpWpf/VVMs/Workflows/Extension.cs +++ b/PLCSharpWpf/VVMs/Workflows/Extension.cs @@ -31,16 +31,9 @@ namespace PLCSharp.VVMs.Workflows //视觉功能 case 0: CurrVF = globalModel.GetVisionFunction("视觉功能名"); - if (CurrVF != null) - { - CurrVF.Flow.Reset(); - flow.Step++; - } - else - { + CurrVF.Flow.Reset(); + flow.Step++; - throw new Exception("视觉功能名称错误!"); - } break; case 1: @@ -49,71 +42,43 @@ namespace PLCSharp.VVMs.Workflows flow.Step++; } else if (flow.CheckStepTime(3)) + { + flow.Step--; throw new Exception("视觉功能超时!"); - + } break; - + //全局变量 case 2: CurrVariable = globalModel.GetVariable("变量名"); - if (CurrVariable != null) - { - CurrVariable.Value = 100; // 设置变量值 - flow.Step++; - } - else - { - throw new Exception("机器人名称错误!"); - - } - + CurrVariable.Value = 100; // 设置变量值 + flow.Step++; break; + //机器人绝对运动 case 3: CurrRobot = globalModel.GetRobot("机器人名称"); - if (CurrRobot != null) - { - - flow.Step++; - - } - else - { - throw new Exception("机器人名称错误!"); - } - + flow.Step++; break; case 4: - - if (CurrRobot.RunPoint("点位名称")) - { - flow.Step++; - } - else - { - throw new Exception("机器人点位运行失败!"); - } - + CurrRobot.RunPoint("点位名称"); + flow.Step++; break; - case 5: if (CurrRobot.PointDone) // 等待运动完成 { flow.Step++; } - else if (flow.CheckStepTime(3)) + else if (flow.CheckStepTime(3)) // 超时处理 + { + flow.Step--; throw new Exception("机器人点位运动超时!"); + } break; + + //机器人相对运动 case 6: - - if (CurrRobot.Jog("点位名称", "X+", 10)) - { - flow.Step++; - } - else - { - throw new Exception("机器人点位运行失败!"); - } - + CurrRobot.Jog("点位名称", "X+", 10); + flow.Step++; break; @@ -123,7 +88,10 @@ namespace PLCSharp.VVMs.Workflows flow.Step++; } else if (flow.CheckStepTime(3)) + { + flow.Step--; throw new Exception("机器人点位运动超时!"); + } break; case 8: //显示状态 @@ -133,10 +101,87 @@ namespace PLCSharp.VVMs.Workflows CurrControl.Params.CellInfos[0].State = CellState.完成; flow.Step++; } - else { + else + { throw new Exception("控件名称错误!"); } + break; + //网络通信 SocketServer广播 /SocketClient / FreeSerialProtocol + case 9: + + CurrConnect = globalModel.GetConnect("网络连接名"); + flow.TaskBool = CurrConnect.SendAsync("要发送的消息"); + flow.Step++; + + break; + case 10: + if (flow.TaskBool.IsCompleted) + { + if (flow.TaskBool.Result) + { + if (string.IsNullOrEmpty(CurrConnect.ReceiveInfo)) + { + //这里处理 接收到的消息 CurrConnect.ReceiveInfo + flow.Step++; + } + else if (flow.CheckStepTime(3)) // 如果不需要判断超时,可以不写这个判断 + { + flow.Step--; + throw new Exception("回复超时!"); + } + + } + else + { + flow.Step--; + throw new Exception($"发送失败!{CurrConnect.ErrInfo}"); + } + } + else if (flow.CheckStepTime(3)) + { + flow.Step--; + throw new Exception("发送超时!"); + } + + break; + + //网络通信 SocketServer 向指定客户端发送消息 + case 11: + CurrConnect = globalModel.GetConnect("网络连接名"); + flow.TaskBool = CurrConnect.SendAsync("要发送的消息", "客户端名称"); + flow.Step++; + break; + + case 12: + if (flow.TaskBool.IsCompleted) + { + if (flow.TaskBool.Result) + { + if (string.IsNullOrEmpty(CurrConnect.ReceiveInfo)) + { + //这里处理 接收到的消息 CurrConnect.ReceiveInfo + flow.Step++; + } + else if (flow.CheckStepTime(3)) // 如果不需要判断超时,可以不写这个判断 + { + flow.Step--; + throw new Exception("回复超时!"); + } + + } + else + { + flow.Step--; + throw new Exception($"发送失败!{CurrConnect.ErrInfo}"); + } + } + else if (flow.CheckStepTime(3)) + { + flow.Step--; + throw new Exception("发送超时!"); + } + break; } } diff --git a/PLCSharpWpf/VVMs/Workflows/Script/全局变量.spt b/PLCSharpWpf/VVMs/Workflows/Script/全局变量.spt new file mode 100644 index 0000000..c032221 --- /dev/null +++ b/PLCSharpWpf/VVMs/Workflows/Script/全局变量.spt @@ -0,0 +1,6 @@ +//全局变量 +case 2: + CurrVariable = globalModel.GetVariable("变量名");//如果前面已经获取,这里可以省略 + CurrVariable.Value = 100; // 设置变量值 + flow.Step++; + break; \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Workflows/Script/变量赋值.spt b/PLCSharpWpf/VVMs/Workflows/Script/变量赋值.spt deleted file mode 100644 index 506f4e4..0000000 --- a/PLCSharpWpf/VVMs/Workflows/Script/变量赋值.spt +++ /dev/null @@ -1,7 +0,0 @@ - case 0: - { - CurrVariable = globalModel.GetVariable("变量名"); - CurrVariable.Value = 100; // 设置变量值 - flow.Step++; - } - break; diff --git a/PLCSharpWpf/VVMs/Workflows/Script/机器人Jog.spt b/PLCSharpWpf/VVMs/Workflows/Script/机器人Jog.spt new file mode 100644 index 0000000..7038e89 --- /dev/null +++ b/PLCSharpWpf/VVMs/Workflows/Script/机器人Jog.spt @@ -0,0 +1,24 @@ +//机器人相对运动 + +case 4: + CurrRobot = globalModel.GetRobot("机器人名称"); //如果前面已经获取过机器人对象,这里可以省略 + flow.Step++; + break; + +case 6: + CurrRobot.Jog("点位名称", "X+", 10); + flow.Step++; + break; + + +case 7: + if (CurrRobot.PointDone) // 等待运动完成 + { + flow.Step++; + } + else if (flow.CheckStepTime(3)) + { + flow.Step--; + throw new Exception("机器人点位运动超时!"); + } + break; \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Workflows/Script/机器人Move.spt b/PLCSharpWpf/VVMs/Workflows/Script/机器人Move.spt new file mode 100644 index 0000000..52d3ac2 --- /dev/null +++ b/PLCSharpWpf/VVMs/Workflows/Script/机器人Move.spt @@ -0,0 +1,21 @@ +//机器人绝对运动 +case 3: + CurrRobot = globalModel.GetRobot("机器人名称");//如果前面已经获取过机器人对象,这里可以省略 + flow.Step++; + break; +case 4: + CurrRobot.RunPoint("点位名称"); + flow.Step++; + break; + +case 5: + if (CurrRobot.PointDone) // 等待运动完成 + { + flow.Step++; + } + else if (flow.CheckStepTime(3)) // 超时处理 + { + flow.Step--; + throw new Exception("机器人点位运动超时!"); + } + break; \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Workflows/Script/机器人运动.spt b/PLCSharpWpf/VVMs/Workflows/Script/机器人运动.spt deleted file mode 100644 index e3f1535..0000000 --- a/PLCSharpWpf/VVMs/Workflows/Script/机器人运动.spt +++ /dev/null @@ -1,20 +0,0 @@ - case 0: - { - var robot = globalModel.GetRobot("机器人名称"); - if (robot != null) - { - var point = robot.Points.FirstOrDefault(p => p.Name == "点位名称"); - if (point != null) - { - robot.RunPoint(point); - flow.Step++; - } - } - } - break; - case 1: - if (robot.) // 等待运动完成 - { - flow.Step++; - } - break; diff --git a/PLCSharpWpf/VVMs/Workflows/Script/网络指定客户端.spt b/PLCSharpWpf/VVMs/Workflows/Script/网络指定客户端.spt new file mode 100644 index 0000000..91a24c8 --- /dev/null +++ b/PLCSharpWpf/VVMs/Workflows/Script/网络指定客户端.spt @@ -0,0 +1,37 @@ + //网络通信 SocketServer 向指定客户端发送消息 + case 11: + CurrConnect = globalModel.GetConnect("网络连接名"); + flow.TaskBool = CurrConnect.SendAsync("要发送的消息", "客户端名称"); + flow.Step++; + break; + + case 12: + if (flow.TaskBool.IsCompleted) + { + if (flow.TaskBool.Result) + { + if (string.IsNullOrEmpty(CurrConnect.ReceiveInfo)) + { + //这里处理 接收到的消息 CurrConnect.ReceiveInfo + flow.Step++; + } + else if (flow.CheckStepTime(3)) // 如果不需要判断超时,可以不写这个判断 + { + flow.Step--; + throw new Exception("回复超时!"); + } + + } + else + { + flow.Step--; + throw new Exception($"发送失败!{CurrConnect.ErrInfo}"); + } + } + else if (flow.CheckStepTime(3)) + { + flow.Step--; + throw new Exception("发送超时!"); + } + + break; \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Workflows/Script/网络收发.spt b/PLCSharpWpf/VVMs/Workflows/Script/网络收发.spt index 58f492f..8a38f65 100644 --- a/PLCSharpWpf/VVMs/Workflows/Script/网络收发.spt +++ b/PLCSharpWpf/VVMs/Workflows/Script/网络收发.spt @@ -1,17 +1,38 @@ - case 0: - - CurrConnect = globalModel.GetConnect("网络连接名"); - _ = CurrConnect.SendAsync("要发送的消息"); - flow.Step++; - - break; - case 1: - - - if (string.IsNullOrEmpty(CurrConnect.ReceiveInfo)) - { - - flow.Step++; +//网络通信 SocketServer广播 /SocketClient / FreeSerialProtocol +case 9: - } - break; + CurrConnect = globalModel.GetConnect("网络连接名"); + flow.TaskBool = CurrConnect.SendAsync("要发送的消息"); + flow.Step++; + + break; +case 10: + if (flow.TaskBool.IsCompleted) + { + if (flow.TaskBool.Result) + { + if (string.IsNullOrEmpty(CurrConnect.ReceiveInfo)) + { + //这里处理 接收到的消息 CurrConnect.ReceiveInfo + flow.Step++; + } + else if (flow.CheckStepTime(3)) // 如果不需要判断超时,可以不写这个判断 + { + flow.Step--; + throw new Exception("回复超时!"); + } + + } + else + { + flow.Step--; + throw new Exception($"发送失败!{CurrConnect.ErrInfo}"); + } + } + else if (flow.CheckStepTime(3)) + { + flow.Step--; + throw new Exception("发送超时!"); + } + + break; \ No newline at end of file diff --git a/PLCSharpWpf/VVMs/Workflows/Script/视觉功能.spt b/PLCSharpWpf/VVMs/Workflows/Script/视觉功能.spt index f591a7b..8556081 100644 --- a/PLCSharpWpf/VVMs/Workflows/Script/视觉功能.spt +++ b/PLCSharpWpf/VVMs/Workflows/Script/视觉功能.spt @@ -1,19 +1,19 @@ - case 0: - - CurrVF= globalModel.GetVisionFunction("视觉功能名"); - CurrVF.Flow.Reset(); - flow.Step++; - - break; - case 1: - { - if(CurrVF.RunAll(CurrVF.Flow)) - { - flow.Step++; + //视觉功能 + case 0: + CurrVF = globalModel.GetVisionFunction("视觉功能名");//如果前面已经获取,这里可以省略 + CurrVF.Flow.Reset(); + flow.Step++; - }else if (flow.CheckStepTime(3)) - throw new Exception("视觉功能超时!"); - } - } + break; - break; + case 1: + if (CurrVF.RunAll(CurrVF.Flow)) + { + flow.Step++; + } + else if (flow.CheckStepTime(3)) + { + flow.Step--; + throw new Exception("视觉功能超时!"); + } + break;