diff --git a/PLCSharpWpf/Models/GlobalModel.cs b/PLCSharpWpf/Models/GlobalModel.cs
index 5054cf1..28d1178 100644
--- a/PLCSharpWpf/Models/GlobalModel.cs
+++ b/PLCSharpWpf/Models/GlobalModel.cs
@@ -190,23 +190,21 @@ namespace PLCSharp.Models
{
var connect = Connects.Connects.FirstOrDefault(c => c.Name == name)
?? throw new Exception("网络未配置!");
- if (connect.Connected == false)
- {
- throw new Exception("网络未连接!");
- }
+
return connect;
}
///
- /// 获取相机
+ /// 获取Robot
///
/// 名称
/// 返回结果
- public CameraBase GetCamera(string name)
+ public Robot GetRobot(string name)
{
- return VisionsModel.Cameras.FirstOrDefault(c => c.Name == name)
- ?? throw new Exception("相机未配置!");
+ var robot = RobotModel.Robots.FirstOrDefault(c => c.Name == name)
+ ?? throw new Exception("Robot未配置!");
+
+ return robot;
}
-
///
/// 获取VisionFunction
///
diff --git a/PLCSharpWpf/VVMs/Homepage/HomeEdit.xaml b/PLCSharpWpf/VVMs/Homepage/HomeEdit.xaml
index 2403673..504350d 100644
--- a/PLCSharpWpf/VVMs/Homepage/HomeEdit.xaml
+++ b/PLCSharpWpf/VVMs/Homepage/HomeEdit.xaml
@@ -87,14 +87,14 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
diff --git a/PLCSharpWpf/VVMs/Robots/Epson/EpsonRobot.cs b/PLCSharpWpf/VVMs/Robots/Epson/EpsonRobot.cs
index c355866..b51fc42 100644
--- a/PLCSharpWpf/VVMs/Robots/Epson/EpsonRobot.cs
+++ b/PLCSharpWpf/VVMs/Robots/Epson/EpsonRobot.cs
@@ -1,4 +1,4 @@
-using PLCSharp.Core.Tools;
+using PLCSharp.Core.Tools;
using PLCSharp.VVMs.Connects.Socket;
using System.Threading;
@@ -232,7 +232,7 @@ public class EpsonRobot : Robot
case "u-":
case "returnhere":
case "runpoint":
-
+ PointDone = true;
if (parts.Length >= 7)
{
_ = double.TryParse(parts[1], out var x);
@@ -312,8 +312,14 @@ public class EpsonRobot : Robot
///
/// 点位
/// 返回布尔值
- public override bool RunPoint(RobotPoint point)
+ public override bool RunPoint(string pointName)
{
+ PointDone = false;
+ var point = Points.FirstOrDefault(p => p.Name == pointName);
+ if (point == null)
+ {
+ return false;
+ }
point.Command = "RunPoint";
PointCommand = point.DeepCopy();
return SendCommand(PointCommand);
@@ -327,13 +333,19 @@ public class EpsonRobot : Robot
///
///
///
- public override bool Jog(RobotPoint pointBase, string cmd, double dist, double rate = 0)
+ public override bool 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;
+ }
- PointCommand = pointBase.DeepCopy();
+ PointCommand = CurrPoint.DeepCopy();
- if (PointCommand.ToolNum == 0)
+ if (point.ToolNum == 0)
{
switch (cmd)
{
@@ -341,38 +353,38 @@ public class EpsonRobot : Robot
case "X-":
PointCommand.Command = cmd;
PointCommand.X = dist;
- PointCommand.Rate = rate > 0 ? rate : PointCommand.Rate;
+ PointCommand.Rate = rate > 0 ? rate : point.Rate;
cmdDone = SendCommand(PointCommand);
break;
case "Y+":
case "Y-":
PointCommand.Command = cmd;
PointCommand.Y = dist;
- PointCommand.Rate = rate > 0 ? rate : PointCommand.Rate;
+ PointCommand.Rate = rate > 0 ? rate : point.Rate;
cmdDone = SendCommand(PointCommand);
break;
case "Z+":
case "Z-":
PointCommand.Command = cmd;
PointCommand.Z = dist;
- PointCommand.Rate = rate > 0 ? rate : PointCommand.Rate;
+ PointCommand.Rate = rate > 0 ? rate : point.Rate;
cmdDone = SendCommand(PointCommand);
break;
case "U+":
case "U-":
PointCommand.Command = cmd;
PointCommand.U = dist;
- PointCommand.Rate = rate > 0 ? rate : PointCommand.Rate;
+ PointCommand.Rate = rate > 0 ? rate : point.Rate;
cmdDone = SendCommand(PointCommand);
break;
}
}
else
{
- PointCommand.Rate = rate > 0 ? rate : PointCommand.Rate;
+ PointCommand.Rate = rate > 0 ? rate : point.Rate;
PointCommand.Command = "RunPoint";
- var tool = Tools.FirstOrDefault(w => w.Key == PointCommand.ToolNum);
+ var tool = Tools.FirstOrDefault(w => w.Key == point.ToolNum);
if (tool.Value == null) return false;
var pointTool = ToolFrame4Axis.WorldToTool(PointCommand, tool.Value);
diff --git a/PLCSharpWpf/VVMs/Robots/Robot.cs b/PLCSharpWpf/VVMs/Robots/Robot.cs
index 4371fae..ed8b147 100644
--- a/PLCSharpWpf/VVMs/Robots/Robot.cs
+++ b/PLCSharpWpf/VVMs/Robots/Robot.cs
@@ -1,4 +1,4 @@
-using Newtonsoft.Json;
+using Newtonsoft.Json;
using PLCSharp.Core.Prism;
using Prism.Commands;
using Prism.Mvvm;
@@ -415,7 +415,7 @@ namespace PLCSharp.VVMs.Robots
///
/// 机器人点位
/// 返回布尔值
- public virtual bool RunPoint(RobotPoint robotPoint)
+ public virtual bool RunPoint(string pointName)
{
return false;
@@ -428,13 +428,20 @@ namespace PLCSharp.VVMs.Robots
/// dist
/// rate
/// 返回布尔值
- public virtual bool Jog(RobotPoint point, string cmd, double dist, double rate = 0)
+ public virtual bool Jog(string pointName, string cmd, double dist, double rate = 0)
{
return false;
}
+ ///
+ /// 点位运行完成
+ ///
+ [NotMapped]
+
+ public bool PointDone { get; set; }
+
private DelegateCommand _HomeCmd;
///
/// 回零Cmd
diff --git a/PLCSharpWpf/VVMs/Robots/RobotsViewModel.cs b/PLCSharpWpf/VVMs/Robots/RobotsViewModel.cs
index 3fb7214..a5d1254 100644
--- a/PLCSharpWpf/VVMs/Robots/RobotsViewModel.cs
+++ b/PLCSharpWpf/VVMs/Robots/RobotsViewModel.cs
@@ -309,7 +309,7 @@ namespace PLCSharp.VVMs.Robots
{
case "RunPoint":
- SelectedRobot.RunPoint(SelectedRobot.SelectedPoint);
+ SelectedRobot.RunPoint(SelectedRobot.SelectedPoint.Name);
break;
@@ -324,8 +324,8 @@ namespace PLCSharp.VVMs.Robots
case "U+":
case "U-":
- SelectedRobot.CurrPoint.ToolNum = SelectedRobot.SelectedPoint.ToolNum;
- SelectedRobot.Jog(SelectedRobot.CurrPoint, cmdStr, RelativeDistance);
+
+ SelectedRobot.Jog(SelectedRobot.SelectedPoint.Name, cmdStr, RelativeDistance);
break;
}
diff --git a/PLCSharpWpf/VVMs/Workflows/Extension.cs b/PLCSharpWpf/VVMs/Workflows/Extension.cs
index a3b2d81..c36f996 100644
--- a/PLCSharpWpf/VVMs/Workflows/Extension.cs
+++ b/PLCSharpWpf/VVMs/Workflows/Extension.cs
@@ -1,6 +1,7 @@
using PLCSharp.Core.Common;
using PLCSharp.Models;
using PLCSharp.VVMs.Connects;
+using PLCSharp.VVMs.GlobalVariables;
using PLCSharp.VVMs.Homepage;
using PLCSharp.VVMs.MotionController;
using PLCSharp.VVMs.Robots;
@@ -8,38 +9,138 @@ using PLCSharp.VVMs.Vision;
namespace PLCSharp.VVMs.Workflows
{
+ ///
+ /// 脚本代码示例
+ ///
public class Extension
{
- Robot CurrRobot;
- CustomControl CurrtateControl;
- VisionFunction CurrVF;
- Connect CurrConnect;
- AxisPoint CurrAxisPoint;
-
+ private Robot CurrRobot;
+ private CustomControl CurrtateControl;
+ private VisionFunction CurrVF;
+ private Connect CurrConnect;
+ private AxisPoint CurrAxisPoint;
+ private Variable CurrVariable;
+ private CustomControl CurrControl;
public void Run(GlobalModel globalModel, FlowModel flow)
{
- switch (flow.Step)
+ if (globalModel.ModeState.State.Execute)
{
- //视觉功能
- case 0:
- CurrVF = globalModel.GetVisionFunction("视觉功能名");
- CurrVF.Flow.Reset();
- flow.Step++;
- break;
- case 1:
+ switch (flow.Step)
+ {
+ //视觉功能
+ case 0:
+ CurrVF = globalModel.GetVisionFunction("视觉功能名");
+ if (CurrVF != null)
+ {
+ CurrVF.Flow.Reset();
+ flow.Step++;
+ }
+ else
+ {
- if (CurrVF.RunAll(CurrVF.Flow))
- {
- flow.Step++;
- }
- else if (flow.CheckStepTime(3))
- throw new Exception("视觉功能超时!");
+ throw new Exception("视觉功能名称错误!");
+ }
+ break;
- break;
+ case 1:
+ if (CurrVF.RunAll(CurrVF.Flow))
+ {
+ flow.Step++;
+ }
+ else if (flow.CheckStepTime(3))
+ throw new Exception("视觉功能超时!");
+
+ break;
+
+ case 2:
+ CurrVariable = globalModel.GetVariable("变量名");
+ if (CurrVariable != null)
+ {
+ CurrVariable.Value = 100; // 设置变量值
+ flow.Step++;
+ }
+ else
+ {
+ throw new Exception("机器人名称错误!");
+
+ }
+
+ break;
+ case 3:
+ CurrRobot = globalModel.GetRobot("机器人名称");
+ if (CurrRobot != null)
+ {
+
+ flow.Step++;
+
+ }
+ else
+ {
+ throw new Exception("机器人名称错误!");
+ }
+
+ break;
+ case 4:
+
+ if (CurrRobot.RunPoint("点位名称"))
+ {
+ flow.Step++;
+ }
+ else
+ {
+ throw new Exception("机器人点位运行失败!");
+ }
+
+ break;
+
+
+ case 5:
+ if (CurrRobot.PointDone) // 等待运动完成
+ {
+ flow.Step++;
+ }
+ else if (flow.CheckStepTime(3))
+ throw new Exception("机器人点位运动超时!");
+ break;
+ case 6:
+
+ if (CurrRobot.Jog("点位名称", "X+", 10))
+ {
+ flow.Step++;
+ }
+ else
+ {
+ throw new Exception("机器人点位运行失败!");
+ }
+
+ break;
+
+
+ case 7:
+ if (CurrRobot.PointDone) // 等待运动完成
+ {
+ flow.Step++;
+ }
+ else if (flow.CheckStepTime(3))
+ throw new Exception("机器人点位运动超时!");
+ break;
+ case 8:
+ //显示状态
+ CurrControl = globalModel.GetCustomControl("控件名称");
+ if (CurrControl != null)
+ {
+ CurrControl.Params.CellInfos[0].State = CellState.完成;
+ flow.Step++;
+ }
+ else {
+ 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 4a59ac4..506f4e4 100644
--- a/PLCSharpWpf/VVMs/Workflows/Script/变量赋值.spt
+++ b/PLCSharpWpf/VVMs/Workflows/Script/变量赋值.spt
@@ -1,7 +1,7 @@
- case 0:
+ case 0:
{
- var variable = globalModel.GetVariable("变量名");
- variable.Value = 100; // 设置变量值
+ CurrVariable = globalModel.GetVariable("变量名");
+ CurrVariable.Value = 100; // 设置变量值
flow.Step++;
}
break;
diff --git a/PLCSharpWpf/VVMs/Workflows/WorkflowConfig.xaml b/PLCSharpWpf/VVMs/Workflows/WorkflowConfig.xaml
index a2005e9..f81b6b8 100644
--- a/PLCSharpWpf/VVMs/Workflows/WorkflowConfig.xaml
+++ b/PLCSharpWpf/VVMs/Workflows/WorkflowConfig.xaml
@@ -35,7 +35,8 @@
-
@@ -77,7 +78,7 @@
-
+
@@ -93,7 +94,7 @@
-
+
@@ -103,8 +104,12 @@
-
-
+
+