5987 lines
208 KiB
C#
5987 lines
208 KiB
C#
using Community;
|
||
using DAL;
|
||
using MahApps.Metro.Controls.Dialogs;
|
||
using Model;
|
||
using Model.HSL;
|
||
using Model.MotionControl;
|
||
using Model.Vision;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Collections.ObjectModel;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Numerics;
|
||
using System.Reflection;
|
||
using System.Text;
|
||
using System.Threading;
|
||
using System.Windows;
|
||
using System.Windows.Controls;
|
||
using System.Windows.Data;
|
||
using System.Windows.Media;
|
||
using System.Windows.Threading;
|
||
using ViewModel.MotionControl;
|
||
using ViewModel.Robots;
|
||
using ViewModel.Vision;
|
||
using Views;
|
||
|
||
namespace ViewModel
|
||
{
|
||
public partial class MainWindowVM : NotificationObject
|
||
{
|
||
#region IO
|
||
const int I00启动 = 0;
|
||
const int I01停止 = 1;
|
||
const int I02急停 = 2;
|
||
const int I03气压检知 = 3;
|
||
const int I04_ = 4;
|
||
const int I05_ = 5;
|
||
const int I06左测试完成 = 6;
|
||
const int I07右测试完成 = 7;
|
||
const int I08门禁1 = 8;
|
||
const int I09门禁2 = 9;
|
||
const int I10门禁3 = 10;
|
||
const int I11门禁4 = 11;
|
||
const int I12光幕检测 = 12;
|
||
const int I13_ = 13;
|
||
const int I14左投料完成 = 14;
|
||
const int I15右投料完成 = 15;
|
||
const int I16左伸缩气缸伸出 = 16;
|
||
const int I17左伸缩气缸缩回 = 17;
|
||
const int I18左顶升气缸1下位 = 18;
|
||
const int I19左顶升气缸1上位 = 19;
|
||
const int I20左顶升气缸2下位 = 20;
|
||
const int I21左顶升气缸2上位 = 21;
|
||
const int I22右伸缩气缸伸出 = 22;
|
||
const int I23右伸缩气缸缩回 = 23;
|
||
const int I24右顶升气缸1下位 = 24;
|
||
const int I25右顶升气缸1上位 = 25;
|
||
const int I26右顶升气缸2下位 = 26;
|
||
const int I27右顶升气缸2上位 = 27;
|
||
const int I28_ = 28;
|
||
const int I29_ = 29;
|
||
const int I30_ = 30;
|
||
const int I31_ = 31;
|
||
const int I32机械手真空检1 = 32;
|
||
const int I33机械手真空检2 = 33;
|
||
const int I34机械手上下气缸1上位 = 34;
|
||
const int I35机械手上下气缸1下位 = 35;
|
||
const int I36机械手上下气缸2上位 = 36;
|
||
const int I37机械手上下气缸2下位 = 37;
|
||
const int I38NG皮带检知1 = 38;
|
||
const int I39NG皮带检知2 = 39;
|
||
const int I40NG皮带检知3 = 40;
|
||
const int I41流线1皮带检知1 = 41;
|
||
const int I42流线1皮带检知2 = 42;
|
||
const int I43流线2皮带检知1 = 43;
|
||
const int I44流线2皮带检知2 = 44;
|
||
const int I45_ = 45;
|
||
const int I46_ = 46;
|
||
const int I47_ = 47;
|
||
const int O00红灯 = 0;
|
||
const int O01黄灯 = 1;
|
||
const int O02绿灯 = 2;
|
||
const int O03蜂鸣器 = 3;
|
||
const int O04_ = 4;
|
||
const int O05_ = 5;
|
||
const int O06_ = 6;
|
||
const int O07_ = 7;
|
||
const int O08左触发 = 8;
|
||
const int O09右触发 = 9;
|
||
const int O10_ = 10;
|
||
const int O11_ = 11;
|
||
const int O12_ = 12;
|
||
const int O13_ = 13;
|
||
const int O14上光源控制 = 14;
|
||
const int O15下光源控制 = 15;
|
||
const int O16左伸缩气缸伸出 = 16;
|
||
const int O17左伸缩气缸缩回 = 17;
|
||
const int O18左顶升气缸1下位 = 18;
|
||
const int O19左顶升气缸1上位 = 19;
|
||
const int O20左顶升气缸2下位 = 20;
|
||
const int O21左顶升气缸2上位 = 21;
|
||
const int O22右伸缩气缸伸出 = 22;
|
||
const int O23右伸缩气缸缩回 = 23;
|
||
const int O24右顶升气缸1下位 = 24;
|
||
const int O25右顶升气缸1上位 = 25;
|
||
const int O26右顶升气缸2下位 = 26;
|
||
const int O27右顶升气缸2上位 = 27;
|
||
const int O28_ = 28;
|
||
const int O29NG皮带控制 = 29;
|
||
const int O30流线1皮带控制 = 30;
|
||
const int O31流线2皮带控制 = 31;
|
||
const int O32机械手真空吸1 = 32;
|
||
const int O33机械手真空破1 = 33;
|
||
const int O34机械手真空吸2 = 34;
|
||
const int O35机械手真空破2 = 35;
|
||
const int O36机械手上下气缸1上位 = 36;
|
||
const int O37机械手上下气缸1下位 = 37;
|
||
const int O38机械手上下气缸2上位 = 38;
|
||
const int O39机械手上下气缸2下位 = 39;
|
||
const int O40_ = 40;
|
||
const int O41_ = 41;
|
||
const int O42_ = 42;
|
||
const int O43_ = 43;
|
||
const int O44_ = 44;
|
||
const int O45_ = 45;
|
||
const int O46_ = 46;
|
||
const int O47_ = 47;
|
||
#endregion
|
||
|
||
#region 生产的Grid状态
|
||
private string gridWidth;
|
||
/// <summary>
|
||
/// Grid的宽
|
||
/// </summary>
|
||
public string GridWidth
|
||
{
|
||
get { return gridWidth; }
|
||
set
|
||
{
|
||
gridWidth = value;
|
||
this.RaisePropertyChanged("GridWidth");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 通讯服务器对象
|
||
private CommunicationServerVM serverComm;
|
||
/// <summary>
|
||
/// 通讯服务器对象
|
||
/// </summary>
|
||
public CommunicationServerVM ServerComm
|
||
{
|
||
get { return serverComm; }
|
||
set
|
||
{
|
||
serverComm = value;
|
||
RaisePropertyChanged("ServerComm");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region ERP交互管理类
|
||
private ERPManageVM eRPVM;
|
||
/// <summary>
|
||
/// ERP交互管理类
|
||
/// </summary>
|
||
public ERPManageVM ERPVM
|
||
{
|
||
get { return eRPVM; }
|
||
set
|
||
{
|
||
eRPVM = value;
|
||
RaisePropertyChanged("ERPVM");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 视觉对象A
|
||
private HalconVisual visualA;
|
||
/// <summary>
|
||
/// 视觉对象A
|
||
/// </summary>
|
||
public HalconVisual VisualA
|
||
{
|
||
get { return visualA; }
|
||
set
|
||
{
|
||
visualA = value;
|
||
RaisePropertyChanged("VisualA");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 视觉对象B
|
||
private HalconVisual visualB;
|
||
/// <summary>
|
||
/// 视觉对象B
|
||
/// </summary>
|
||
public HalconVisual VisualB
|
||
{
|
||
get { return visualB; }
|
||
set
|
||
{
|
||
visualB = value;
|
||
RaisePropertyChanged("VisualB");
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 视觉对象C
|
||
private HalconVisual visualC;
|
||
/// <summary>
|
||
/// 视觉对象C
|
||
/// </summary>
|
||
public HalconVisual VisualC
|
||
{
|
||
get { return visualC; }
|
||
set
|
||
{
|
||
visualC = value;
|
||
RaisePropertyChanged("VisualC");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 串口相关
|
||
private SerialComVM sCVM;
|
||
/// <summary>
|
||
/// 串口服务对象
|
||
/// </summary>
|
||
public SerialComVM SCVM
|
||
{
|
||
get { return sCVM; }
|
||
set
|
||
{
|
||
sCVM = value;
|
||
this.RaisePropertyChanged("SCVM");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
#endregion
|
||
|
||
#region 机器人对象
|
||
private FeiYuRobotVM robot;
|
||
/// <summary>
|
||
/// 机器人对象
|
||
/// </summary>
|
||
public FeiYuRobotVM Robot
|
||
{
|
||
get { return robot; }
|
||
set
|
||
{
|
||
robot = value;
|
||
RaisePropertyChanged("Robot");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 运动控制对象VM
|
||
private MotionControlVM mCVM;
|
||
/// <summary>
|
||
/// 运动控制对象VM
|
||
/// </summary>
|
||
public MotionControlVM MCVM
|
||
{
|
||
get { return mCVM; }
|
||
set
|
||
{
|
||
mCVM = value;
|
||
RaisePropertyChanged("MCVM");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 软件开启时间
|
||
/// <summary>
|
||
/// 软件开启时间
|
||
/// </summary>
|
||
DateTime OpenTime { get; set; }
|
||
|
||
/// <summary>
|
||
/// 生产运行开始时间
|
||
/// </summary>
|
||
DateTime RunStartTime { get; set; }
|
||
|
||
|
||
private string openTimeStr;
|
||
/// <summary>
|
||
/// 软件开启时间
|
||
/// </summary>
|
||
public string OpenTimeStr
|
||
{
|
||
get { return openTimeStr; }
|
||
set
|
||
{
|
||
openTimeStr = value;
|
||
this.RaisePropertyChanged("OpenTimeStr");
|
||
}
|
||
}
|
||
|
||
#region CT时间
|
||
private TimeSpan cTTime;
|
||
/// <summary>
|
||
/// CT时间
|
||
/// </summary>
|
||
public TimeSpan CTTime
|
||
{
|
||
get { return cTTime; }
|
||
set
|
||
{
|
||
cTTime = value;
|
||
ShowCtTime = value.TotalSeconds.ToString();
|
||
this.RaisePropertyChanged("CTTime");
|
||
}
|
||
}
|
||
|
||
|
||
private string showCtTime;
|
||
/// <summary>
|
||
/// 显示CT时间
|
||
/// </summary>
|
||
public string ShowCtTime
|
||
{
|
||
get { return showCtTime; }
|
||
set
|
||
{
|
||
showCtTime = value;
|
||
this.RaisePropertyChanged("ShowCtTime");
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
|
||
|
||
#endregion
|
||
|
||
#region 图表相关
|
||
private ChartVM cVM;
|
||
/// <summary>
|
||
/// 图表对象
|
||
/// </summary>
|
||
public ChartVM CVM
|
||
{
|
||
get { return cVM; }
|
||
set
|
||
{
|
||
cVM = value;
|
||
this.RaisePropertyChanged("CVM");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region Ttay料盘
|
||
private TrayModel tray1;
|
||
/// <summary>
|
||
/// 料盘1
|
||
/// </summary>
|
||
public TrayModel Tray1
|
||
{
|
||
get { return tray1; }
|
||
set
|
||
{
|
||
tray1 = value;
|
||
this.RaisePropertyChanged("Tray1");
|
||
}
|
||
}
|
||
|
||
private TrayModel tray2;
|
||
/// <summary>
|
||
/// 料盘2
|
||
/// </summary>
|
||
public TrayModel Tray2
|
||
{
|
||
get { return tray2; }
|
||
set
|
||
{
|
||
tray2 = value;
|
||
this.RaisePropertyChanged("Tray2");
|
||
}
|
||
}
|
||
private TrayModel tray3;
|
||
/// <summary>
|
||
/// 料盘3
|
||
/// </summary>
|
||
public TrayModel Tray3
|
||
{
|
||
get { return tray3; }
|
||
set
|
||
{
|
||
tray3 = value;
|
||
this.RaisePropertyChanged("Tray3");
|
||
}
|
||
}
|
||
private TrayModel tray4;
|
||
/// <summary>
|
||
/// 料盘4
|
||
/// </summary>
|
||
public TrayModel Tray4
|
||
{
|
||
get { return tray4; }
|
||
set
|
||
{
|
||
tray4 = value;
|
||
this.RaisePropertyChanged("Tray4");
|
||
}
|
||
}
|
||
|
||
private TrayModel tray5;
|
||
/// <summary>
|
||
/// 料盘5
|
||
/// </summary>
|
||
public TrayModel Tray5
|
||
{
|
||
get { return tray5; }
|
||
set
|
||
{
|
||
tray5 = value;
|
||
this.RaisePropertyChanged("Tray5");
|
||
}
|
||
}
|
||
|
||
private TrayModel tray6;
|
||
/// <summary>
|
||
/// 料盘6
|
||
/// </summary>
|
||
public TrayModel Tray6
|
||
{
|
||
get { return tray6; }
|
||
set
|
||
{
|
||
tray6 = value;
|
||
this.RaisePropertyChanged("Tray6");
|
||
}
|
||
}
|
||
private TrayModel tray7;
|
||
/// <summary>
|
||
/// 料盘7
|
||
/// </summary>
|
||
public TrayModel Tray7
|
||
{
|
||
get { return tray7; }
|
||
set
|
||
{
|
||
tray7 = value;
|
||
this.RaisePropertyChanged("Tray7");
|
||
}
|
||
}
|
||
|
||
private TrayModel tray8;
|
||
/// <summary>
|
||
/// 料盘8
|
||
/// </summary>
|
||
public TrayModel Tray8
|
||
{
|
||
get { return tray8; }
|
||
set
|
||
{
|
||
tray8 = value;
|
||
this.RaisePropertyChanged("Tray8");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 空跑模式
|
||
private bool runningMode;
|
||
|
||
/// <summary>
|
||
/// 空跑模式
|
||
/// </summary>
|
||
public bool RunningMode
|
||
{
|
||
get { return runningMode; }
|
||
set
|
||
{
|
||
runningMode = value;
|
||
if (!value)
|
||
{
|
||
RunningModePlas = false;
|
||
}
|
||
this.RaisePropertyChanged("RunningMode");
|
||
}
|
||
}
|
||
|
||
private bool runningModePlas;
|
||
/// <summary>
|
||
/// 联机空跑模式
|
||
/// </summary>
|
||
public bool RunningModePlas
|
||
{
|
||
get { return runningModePlas; }
|
||
set
|
||
{
|
||
runningModePlas = value;
|
||
|
||
if (value)
|
||
{
|
||
RunningMode = true;
|
||
}
|
||
this.RaisePropertyChanged("RunningModePlas");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 清理机台模式
|
||
private bool cleanMachine;
|
||
/// <summary>
|
||
/// 清理机台模式
|
||
/// </summary>
|
||
public bool CleanMachine
|
||
{
|
||
get { return cleanMachine; }
|
||
set
|
||
{
|
||
cleanMachine = value;
|
||
this.RaisePropertyChanged("CleanMachine");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 不进行MES验证
|
||
private bool mesCheck;
|
||
/// <summary>
|
||
/// 不进行MES验证
|
||
/// </summary>
|
||
public bool MesCheck
|
||
{
|
||
get { return mesCheck; }
|
||
set
|
||
{
|
||
mesCheck = value;
|
||
this.RaisePropertyChanged("MesCheck");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 不进行数据上传
|
||
private bool noUpData;
|
||
/// <summary>
|
||
/// 不进行数据上传
|
||
/// </summary>
|
||
public bool NoUpData
|
||
{
|
||
get { return noUpData; }
|
||
set
|
||
{
|
||
noUpData = value;
|
||
this.RaisePropertyChanged("NoUpData");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 系统设置权限控制
|
||
private string permissionButtonName;
|
||
/// <summary>
|
||
/// 权限按钮名称
|
||
/// </summary>
|
||
public string PermissionButtonName
|
||
{
|
||
get { return permissionButtonName; }
|
||
set
|
||
{
|
||
permissionButtonName = value;
|
||
this.RaisePropertyChanged("PermissionButtonName");
|
||
}
|
||
}
|
||
|
||
|
||
#region 管理员权限
|
||
private Visibility allVis;
|
||
/// <summary>
|
||
/// 管理员权限
|
||
/// </summary>
|
||
public Visibility AllVis
|
||
{
|
||
get { return allVis; }
|
||
set
|
||
{
|
||
allVis = value;
|
||
this.RaisePropertyChanged("AllVis");
|
||
|
||
|
||
if (HVlist != null)
|
||
{
|
||
foreach (HalconVisual hv in HVlist)
|
||
{
|
||
hv.DisplayLevel = value;
|
||
}
|
||
}
|
||
|
||
if (StandVMList != null)
|
||
{
|
||
foreach (var item in StandVMList)
|
||
{
|
||
item.IsEnable = value == Visibility.Visible ? true : false;
|
||
}
|
||
}
|
||
|
||
//PermissionButtonName = Application.Current.Resources[value == Visibility.Collapsed ? "编辑模式" : "普通模式"].ToString();
|
||
PermissionButtonName = value == Visibility.Collapsed ? "编辑模式" : "普通模式";
|
||
if (value == Visibility.Collapsed)
|
||
{
|
||
SuperPrivilege = value;
|
||
}
|
||
else
|
||
{
|
||
if (GridWidth == "30*")
|
||
{
|
||
GridWidth = "0";
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 超级权限
|
||
private Visibility superPrivilege;
|
||
/// <summary>
|
||
/// 超级权限
|
||
/// </summary>
|
||
public Visibility SuperPrivilege
|
||
{
|
||
get { return superPrivilege; }
|
||
set
|
||
{
|
||
superPrivilege = value;
|
||
this.RaisePropertyChanged("SuperPrivilege");
|
||
|
||
if (value == Visibility.Visible)
|
||
{
|
||
AllVis = value;
|
||
}
|
||
|
||
if (HVlist != null)
|
||
{
|
||
foreach (HalconVisual hv in HVlist)
|
||
{
|
||
hv.SuperPrivilege = value;
|
||
}
|
||
}
|
||
|
||
|
||
if (MCVM != null)
|
||
{
|
||
MCVM.DisplayLevel = value;
|
||
}
|
||
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#endregion
|
||
|
||
#region 系统参数对象
|
||
private SystemParameter systemPar;
|
||
/// <summary>
|
||
/// 系统参数对象
|
||
/// </summary>
|
||
public SystemParameter SystemPar
|
||
{
|
||
get { return systemPar; }
|
||
set
|
||
{
|
||
systemPar = value;
|
||
this.RaisePropertyChanged("SystemPar");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 数据对象
|
||
/// <summary>
|
||
/// 数据对象
|
||
/// </summary>
|
||
public MainWindowDAL dal = new MainWindowDAL();
|
||
/// <summary>
|
||
/// 视觉数据对象
|
||
/// </summary>
|
||
public VisualDAL Vdal = new VisualDAL();
|
||
#endregion
|
||
|
||
#region 控制卡
|
||
|
||
/// <summary>
|
||
/// Io控制卡ID
|
||
/// </summary>
|
||
public ushort IoCardID { get; set; }
|
||
#endregion
|
||
|
||
#region 输入信号集合
|
||
private List<InputSignal> inputList;
|
||
/// <summary>
|
||
/// 输入信号集合
|
||
/// </summary>
|
||
public List<InputSignal> InputList
|
||
{
|
||
get { return inputList; }
|
||
set
|
||
{
|
||
inputList = value;
|
||
if (value != null && value.Count > 0)
|
||
{
|
||
InputGrid = GetInputGrid();
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 输出信号集合
|
||
private List<OutputSignal> outputList;
|
||
/// <summary>
|
||
/// 输出信号集合
|
||
/// </summary>
|
||
public List<OutputSignal> OutputList
|
||
{
|
||
get { return outputList; }
|
||
set
|
||
{
|
||
outputList = value;
|
||
if (value != null && value.Count > 0)
|
||
{
|
||
OutputGrid = GetOutputGrid();
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 各线程
|
||
/// <summary>
|
||
/// 状态监控线程
|
||
/// </summary>
|
||
Thread ThStateMonitoring { get; set; }
|
||
/// <summary>
|
||
/// 运行线程
|
||
/// </summary>
|
||
Thread ThRun { get; set; }
|
||
/// <summary>
|
||
/// 网络连接控制线程
|
||
/// </summary>
|
||
Thread ThConnect { get; set; }
|
||
#endregion
|
||
|
||
#region 机器运行状态
|
||
private RunStatuEnum runStatu;
|
||
/// <summary>
|
||
/// 机器运行状态枚举
|
||
/// </summary>
|
||
public RunStatuEnum RunStatu
|
||
{
|
||
get { return runStatu; }
|
||
set
|
||
{
|
||
runStatu = value;
|
||
switch (value)
|
||
{
|
||
case RunStatuEnum.Prepare:
|
||
ShowStatu.StatusBackground = ColorStr.Yellow;
|
||
ShowStatu.StatusForeground = ColorStr.Black;
|
||
ShowStatu.StatuInfo = "准备中";
|
||
if (OutputList != null)
|
||
{
|
||
OutputList[0].Switchs = false; //红灯
|
||
OutputList[1].Switchs = true; //黄灯
|
||
OutputList[2].Switchs = false; //绿灯
|
||
OutputList[3].Switchs = false; //蜂鸣器
|
||
}
|
||
break;
|
||
case RunStatuEnum.Prepareations:
|
||
ShowStatu.StatusBackground = ColorStr.Green;
|
||
ShowStatu.StatusForeground = ColorStr.Black;
|
||
ShowStatu.StatuInfo = "准备就绪";
|
||
|
||
OutputList[0].Switchs = false; //红灯
|
||
OutputList[1].Switchs = true; //黄灯
|
||
OutputList[2].Switchs = false; //绿灯
|
||
OutputList[3].Switchs = false; //蜂鸣器
|
||
break;
|
||
case RunStatuEnum.Normal:
|
||
ShowStatu.StatusBackground = ColorStr.Green;
|
||
ShowStatu.StatusForeground = ColorStr.Black;
|
||
ShowStatu.StatuInfo = "运行中";
|
||
|
||
OutputList[0].Switchs = false; //红灯
|
||
OutputList[1].Switchs = false; //黄灯
|
||
OutputList[2].Switchs = true; //绿灯
|
||
OutputList[3].Switchs = false; //蜂鸣器
|
||
break;
|
||
case RunStatuEnum.Stop:
|
||
ShowStatu.StatusBackground = ColorStr.Yellow;
|
||
ShowStatu.StatusForeground = ColorStr.Black;
|
||
ShowStatu.StatuInfo = "停止中";
|
||
|
||
OutputList[0].Switchs = false; //红灯
|
||
OutputList[1].Switchs = true; //黄灯
|
||
OutputList[2].Switchs = false; //绿灯
|
||
OutputList[3].Switchs = false; //蜂鸣器
|
||
break;
|
||
case RunStatuEnum.EmgStop:
|
||
ShowStatu.StatusBackground = ColorStr.Yellow;
|
||
ShowStatu.StatusForeground = ColorStr.Black;
|
||
ShowStatu.StatuInfo = "紧急停止中";
|
||
|
||
OutputList[0].Switchs = true; //红灯
|
||
OutputList[1].Switchs = true; //黄灯
|
||
OutputList[2].Switchs = false; //绿灯
|
||
OutputList[3].Switchs = false; //蜂鸣器
|
||
break;
|
||
case RunStatuEnum.Exceptional:
|
||
ShowStatu.StatusBackground = ColorStr.Red;
|
||
ShowStatu.StatusForeground = ColorStr.White;
|
||
|
||
OutputList[0].Switchs = true; //红灯
|
||
OutputList[1].Switchs = false; //黄灯
|
||
OutputList[2].Switchs = false; //绿灯
|
||
OutputList[3].Switchs = true; //蜂鸣器
|
||
break;
|
||
}
|
||
|
||
|
||
}
|
||
}
|
||
|
||
private ShowInfo showStatu;
|
||
/// <summary>
|
||
/// 机器状态 显示
|
||
/// </summary>
|
||
public ShowInfo ShowStatu
|
||
{
|
||
get { return showStatu; }
|
||
set
|
||
{
|
||
showStatu = value;
|
||
this.RaisePropertyChanged("ShowStatu");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
#endregion
|
||
|
||
#region 异常信息集合
|
||
private ObservableCollection<RecordInfo> excepList;
|
||
/// <summary>
|
||
/// 异常信息集合
|
||
/// </summary>
|
||
public ObservableCollection<RecordInfo> ExcepList
|
||
{
|
||
get { return excepList; }
|
||
set
|
||
{
|
||
excepList = value;
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 各种运行方法
|
||
/// <summary>
|
||
/// 开始运行
|
||
/// </summary>
|
||
public DelegateCommand StartCommand { get; set; }
|
||
/// <summary>
|
||
/// 停止运行
|
||
/// </summary>
|
||
public DelegateCommand StopCommand { get; set; }
|
||
/// <summary>
|
||
/// 重启软件
|
||
/// </summary>
|
||
public DelegateCommand ResetSoftCommand { get; set; }
|
||
/// <summary>
|
||
/// 退出程序
|
||
/// </summary>
|
||
public DelegateCommand CloseCommand { get; set; }
|
||
|
||
/// <summary>
|
||
/// 切换语言
|
||
/// </summary>
|
||
public DelegateCommand SwitchLanguageCommand { get; set; }
|
||
|
||
/// <summary>
|
||
/// 保存站别参数
|
||
/// </summary>
|
||
public DelegateCommand SaveStandCommand { get; set; }
|
||
|
||
|
||
#endregion
|
||
|
||
#region 选中的TabItem
|
||
|
||
private TabItem selectTabItem;
|
||
/// <summary>
|
||
/// 选中的TabItem
|
||
/// </summary>
|
||
public TabItem SelectTabItem
|
||
{
|
||
get { return selectTabItem; }
|
||
set
|
||
{
|
||
selectTabItem = value;
|
||
|
||
if (AllVis == Visibility.Visible)
|
||
{
|
||
if (value.Tag != null && value.Tag.ToString() == "v")
|
||
{
|
||
GridWidth = "0";
|
||
}
|
||
else
|
||
{
|
||
GridWidth = "30*";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
GridWidth = "30*";
|
||
}
|
||
|
||
this.RaisePropertyChanged("SelectTabItem");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 当前生产的机种ID
|
||
|
||
private int currentMachineID;
|
||
/// <summary>
|
||
/// 当前生产的机种
|
||
/// </summary>
|
||
public int CurrentMachineID
|
||
{
|
||
get { return currentMachineID; }
|
||
set
|
||
{
|
||
currentMachineID = value;
|
||
this.RaisePropertyChanged("CurrentMachineID");
|
||
if (value <= 0)
|
||
{
|
||
return;
|
||
}
|
||
CurrentMachine = AllMachineList.Where(w => w.ID == value).FirstOrDefault(); //dal.ByIDGeMachine(value); //获取当前生产机种对象
|
||
|
||
if (Robot != null)
|
||
{
|
||
Robot.MachineObj = CurrentMachine;
|
||
}
|
||
|
||
if (MCVM != null)
|
||
{
|
||
MCVM.MachineObj = CurrentMachine;
|
||
}
|
||
|
||
if (HVlist != null)
|
||
{
|
||
foreach (HalconVisual hv in HVlist)
|
||
{
|
||
hv.MachineObj = CurrentMachine;
|
||
hv.QRModelInitialize = false;
|
||
hv.CodeModelInitialize = false;
|
||
}
|
||
}
|
||
|
||
//异步新增项 这是微软的BUG 只能这么麻烦了
|
||
MyDispatcher.BeginInvoke(DispatcherPriority.Background, new ParameterizedThreadStart(ShuaxingContent), info);
|
||
|
||
SystemPar.DefaultMachineID = value;
|
||
dal.UpdateSystemPar(SystemPar); //更新默认机种
|
||
|
||
|
||
|
||
}
|
||
}
|
||
|
||
private void ShuaxingContent(object obj)
|
||
{
|
||
Tray1 = new TrayModel(CurrentMachine, "料盘", 0);
|
||
//Tray2 = new TrayModel(CurrentMachine, "料盘", 2);
|
||
}
|
||
#endregion
|
||
|
||
#region 当前生产机种对象
|
||
private MachineModel currentMachine;
|
||
/// <summary>
|
||
/// 当前生产机种对象
|
||
/// </summary>
|
||
public MachineModel CurrentMachine
|
||
{
|
||
get { return currentMachine; }
|
||
set
|
||
{
|
||
currentMachine = value;
|
||
|
||
this.RaisePropertyChanged("CurrentMachine");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
#endregion
|
||
|
||
#region 各步骤
|
||
|
||
|
||
#region 回原点步骤枚举
|
||
/// <summary>
|
||
/// 回原点步骤枚举
|
||
/// </summary>
|
||
GengralProcessEnum GoHomeSteps { get; set; }
|
||
#endregion
|
||
|
||
|
||
#endregion
|
||
|
||
#region 动态Grid控件
|
||
private Grid inputGrid;
|
||
/// <summary>
|
||
/// 输入信号Grid
|
||
/// </summary>
|
||
public Grid InputGrid
|
||
{
|
||
get { return inputGrid; }
|
||
set
|
||
{
|
||
inputGrid = value;
|
||
this.RaisePropertyChanged("InputGrid");
|
||
}
|
||
}
|
||
|
||
private Grid outputGrid;
|
||
/// <summary>
|
||
/// 输出信号Grid
|
||
/// </summary>
|
||
public Grid OutputGrid
|
||
{
|
||
get { return outputGrid; }
|
||
set
|
||
{
|
||
outputGrid = value;
|
||
this.RaisePropertyChanged("OutputGrid");
|
||
}
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
#region PLC连接管理
|
||
private PLCVM plcConVM;
|
||
/// <summary>
|
||
/// PLC连接管理
|
||
/// </summary>
|
||
public PLCVM PlcConVM
|
||
{
|
||
get { return plcConVM; }
|
||
set
|
||
{
|
||
plcConVM = value;
|
||
this.RaisePropertyChanged("PlcConVM");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 当前PLC连接对象
|
||
/// </summary>
|
||
FeiYuHsl CurrHsl { get; set; }
|
||
#endregion
|
||
|
||
#region 光源串口号
|
||
private string serialProt;
|
||
/// <summary>
|
||
/// 光源串口号
|
||
/// </summary>
|
||
public string SerialProt
|
||
{
|
||
get { return serialProt; }
|
||
set
|
||
{
|
||
if (!string.IsNullOrEmpty(value) && LightCOM != null)
|
||
{
|
||
if (!LightCOM.OpenSerialCom(value))
|
||
{
|
||
// MessageBox.Show(LightCOM.ErrorMag);
|
||
}
|
||
else
|
||
{
|
||
serialProt = value;
|
||
if (value != SystemPar.SerialProt)
|
||
{
|
||
SystemPar.SerialProt = value;
|
||
try
|
||
{
|
||
dal.UpdateSystemPar(SystemPar);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message);
|
||
}
|
||
}
|
||
}
|
||
this.RaisePropertyChanged("SerialProt");
|
||
}
|
||
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 光源串口对象
|
||
private SerialCom lightCOM;
|
||
/// <summary>
|
||
/// 光源串口对象
|
||
/// </summary>
|
||
public SerialCom LightCOM
|
||
{
|
||
get { return lightCOM; }
|
||
set
|
||
{
|
||
lightCOM = value;
|
||
this.RaisePropertyChanged("LightCOM");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 系统功能控件集合
|
||
private ObservableCollection<TabItem> tabItemList;
|
||
/// <summary>
|
||
/// 系统功能控件集合
|
||
/// </summary>
|
||
public ObservableCollection<TabItem> TabItemList
|
||
{
|
||
get { return tabItemList; }
|
||
set
|
||
{
|
||
tabItemList = value;
|
||
this.RaisePropertyChanged("TabItemList");
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 视觉对象VM集合
|
||
/// <summary>
|
||
/// 视觉对象VM集合
|
||
/// </summary>
|
||
List<HalconVisual> HVlist { get; set; }
|
||
#endregion
|
||
|
||
#region 选中的站别
|
||
private StandModel selectStand;
|
||
/// <summary>
|
||
/// 选中的站别
|
||
/// </summary>
|
||
public StandModel SelectStand
|
||
{
|
||
get { return selectStand; }
|
||
set
|
||
{
|
||
selectStand = value;
|
||
this.RaisePropertyChanged("SelectStand");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 站别逻辑控制集合
|
||
private List<StandVM> standVMList;
|
||
/// <summary>
|
||
/// 站别逻辑控制集合
|
||
/// </summary>
|
||
public List<StandVM> StandVMList
|
||
{
|
||
get { return standVMList; }
|
||
set { standVMList = value; RaisePropertyChanged("StandVMList"); }
|
||
}
|
||
#endregion
|
||
|
||
#region 构造函数
|
||
/// <summary>
|
||
/// 构造函数
|
||
/// </summary>
|
||
public MainWindowVM(Window mywd)
|
||
{
|
||
//adtIO3224.adtIO3224_initial();//初始化IO卡
|
||
|
||
Mywindow = mywd;
|
||
MyDispatcher = mywd.Dispatcher;
|
||
|
||
GridWidth = "30*";
|
||
Initialize(); //初始化
|
||
|
||
LoadingFunctionInterface();//加载功能界面
|
||
|
||
|
||
#region 实例化各运行方法
|
||
this.StartCommand = new DelegateCommand();
|
||
this.StartCommand.ExecuteAction = new Action<object>(this.Start);
|
||
|
||
this.StopCommand = new DelegateCommand();
|
||
this.StopCommand.ExecuteAction = new Action<object>(this.Stop);
|
||
|
||
this.ResetSoftCommand = new DelegateCommand();
|
||
this.ResetSoftCommand.ExecuteAction = new Action<object>(ResetSoft);
|
||
|
||
this.CloseCommand = new DelegateCommand();
|
||
this.CloseCommand.ExecuteAction = new Action<object>(this.Close);
|
||
|
||
this.SwitchLanguageCommand = new DelegateCommand();
|
||
this.SwitchLanguageCommand.ExecuteAction = new Action<object>(SwitchLanguage);
|
||
|
||
this.SaveStandCommand = new DelegateCommand();
|
||
this.SaveStandCommand.ExecuteAction = new Action<object>(SaveStand);
|
||
|
||
#endregion
|
||
|
||
GoHomeSteps = GengralProcessEnum.Start;
|
||
|
||
//开启状态监控线程
|
||
if (ThStateMonitoring == null)
|
||
{
|
||
ThStateMonitoring = new Thread(StateMonitoring);
|
||
ThStateMonitoring.IsBackground = true;
|
||
ThStateMonitoring.Start();
|
||
}
|
||
|
||
GetXizuiLabelGrid();//吸嘴状态初始化
|
||
GetTestBenchGrid();//缓存载具初始化
|
||
GetCacheLineGrid(); //缓存流线对象
|
||
GetProduceLineGrid(); //良品流线对象
|
||
GetStationProduceGrid(); //获取后站信息
|
||
GetInCacheGrid(); //进料平台状态
|
||
|
||
LogicDispatchFlow = new FlowModel("大总管");
|
||
TakeFlow = new FlowModel("取料");
|
||
DownVisionFlow = new FlowModel("测试盒取出");
|
||
BoxInPutFlow = new FlowModel("测试盒投入");
|
||
CarryPutOutFlow = new FlowModel("机台搬运");
|
||
OKLineFlow = new FlowModel("良品皮带运行");
|
||
PassLineFlow = new FlowModel("过站皮带运行");
|
||
TestBoxFlow = new FlowModel("测试平台运行");
|
||
|
||
//把吸嘴给机器人 避免撞坏吸嘴
|
||
Robot.XizuiLabelPaperList = this.XizuiLabelPaperList;
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 保存站别信息
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void SaveStand(object obj)
|
||
{
|
||
if (SelectStand != null)
|
||
{
|
||
if (dal.UpdataStandModel(SelectStand) <= 0)
|
||
{
|
||
MyMessageBox.Show("保存失败");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
MyMessageBox.Show("请选中要保存的点位");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 1、系统初始化
|
||
/// <summary>
|
||
/// 系统初始化
|
||
/// </summary>
|
||
public void Initialize()
|
||
{
|
||
//1、初始化系统参数
|
||
SystemPar = dal.GetSystemPar();
|
||
|
||
PlcConVM = new PLCVM();
|
||
CurrHsl = PlcConVM.HslList[0];
|
||
|
||
AllVis = Visibility.Collapsed;
|
||
OpenTime = DateTime.Now;
|
||
|
||
ShowStatu = new ShowInfo();
|
||
RunStatu = RunStatuEnum.Prepare;
|
||
|
||
ExcepList = new ObservableCollection<RecordInfo>();
|
||
|
||
//2、初始化输入输出信号
|
||
InputList = dal.GetInputList();
|
||
OutputList = dal.GetOutputList();
|
||
|
||
ERPVM = new ERPManageVM(SystemPar.ID, this.dal);
|
||
|
||
SCVM = new SerialComVM(SystemPar.ID); //串口对象
|
||
ServerComm = new CommunicationServerVM(SystemPar.ID, Mywindow.Dispatcher);
|
||
ServerComm.MonitorsWitch = true;
|
||
|
||
CVM = new ChartVM();//图表对象
|
||
|
||
//机种参数
|
||
InitializeMachineEditor();
|
||
RunStartTime = DateTime.Now;//产能计时开始
|
||
|
||
|
||
NextStation = ServerComm.CommList.Where(w => w.ShortCode == "NS").FirstOrDefault();
|
||
NextStation.ReceiveCallback += NextStation_ReceiveCallback;
|
||
|
||
FrontStation = ServerComm.CommList.Where(w => w.ShortCode == "FS").FirstOrDefault();
|
||
FrontStation.ReceiveCallback += FrontStation_ReceiveCallback;
|
||
|
||
TestMachine = ServerComm.CommList.Where(w => w.ShortCode == "Force").FirstOrDefault();
|
||
TestMachine.ReceiveCallback += TestMachine_ReceiveCallback;
|
||
|
||
}
|
||
|
||
#region 获取输出信号Grid
|
||
/// <summary>
|
||
/// 获取输出信号Grid
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private Grid GetOutputGrid()
|
||
{
|
||
Grid g = new Grid();
|
||
int row = 0;
|
||
int column = 0;
|
||
//int count = OutputList.Count;
|
||
var showList = OutputList.Where(w => !w.EmptySignal).ToList(); //筛选出要显示在控制卡上的输入信号,空信号不显示
|
||
int count = showList.Count;
|
||
if (count <= 16)
|
||
{
|
||
row = count;
|
||
column = 1;
|
||
}
|
||
else
|
||
{
|
||
row = 16;
|
||
column = count / 16;
|
||
if (count % 16 > 0)
|
||
{
|
||
column = column + 1;
|
||
}
|
||
}
|
||
|
||
int number = 0;
|
||
CheckBox cb;
|
||
for (int i = 0; i < column; i++)
|
||
{
|
||
g.ColumnDefinitions.Add(new ColumnDefinition()); //添加列
|
||
for (int j = 0; j < row; j++)
|
||
{
|
||
if (i == 0)
|
||
{
|
||
g.RowDefinitions.Add(new RowDefinition()); //添加行
|
||
}
|
||
|
||
if (number < count)
|
||
{
|
||
//cb = GetCheckBox(OutputList[number]);
|
||
cb = GetCheckBox(showList[number]);
|
||
//加一个控件修饰控件 用于控制字体的大小
|
||
Viewbox vb = new Viewbox();
|
||
vb.Stretch = Stretch.Uniform;
|
||
vb.StretchDirection = StretchDirection.Both;
|
||
vb.HorizontalAlignment = HorizontalAlignment.Left;
|
||
vb.Child = cb;
|
||
|
||
g.Children.Add(vb);
|
||
vb.SetValue(Grid.RowProperty, j);//设置按钮所在Grid控件的行
|
||
vb.SetValue(Grid.ColumnProperty, i);//设置按钮所在Grid控件的列
|
||
//g.Children.Add(cb);
|
||
//cb.SetValue(Grid.RowProperty, j); //设置按钮所在Grid控件的行
|
||
//cb.SetValue(Grid.ColumnProperty, i); //设置按钮所在Grid控件的列
|
||
|
||
number++;
|
||
}
|
||
}
|
||
}
|
||
return g;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取CheckBox
|
||
/// </summary>
|
||
/// <param name="os"></param>
|
||
/// <returns></returns>
|
||
private CheckBox GetCheckBox(OutputSignal os)
|
||
{
|
||
CheckBox cb = new CheckBox();
|
||
//指定样式
|
||
cb.Style = (Style)Mywindow.FindResource("CheckBoxStyle");//CheckBoxStyle 这个样式是引用的资源文件中的样式名称
|
||
//设置数据上下文
|
||
cb.DataContext = os;
|
||
//绑定背景颜色
|
||
cb.SetBinding(CheckBox.BackgroundProperty, new Binding() { Path = new PropertyPath("OutputColor"), Mode = BindingMode.TwoWay });
|
||
|
||
//绑定内容
|
||
// cb.SetBinding(CheckBox.ContentProperty, new Binding() { Path = new PropertyPath("OutputMeaning"), Mode = BindingMode.TwoWay });
|
||
if (Application.Current.Resources[os.OutputMeaning] != null)
|
||
{
|
||
cb.Content = Application.Current.Resources[os.OutputMeaning].ToString();
|
||
}
|
||
else
|
||
{
|
||
cb.Content = os.OutputMeaning;
|
||
}
|
||
|
||
//绑定勾属性
|
||
cb.SetBinding(CheckBox.IsCheckedProperty, new Binding() { Path = new PropertyPath("Switchs"), Mode = BindingMode.TwoWay });
|
||
//设置前景色
|
||
cb.Foreground = new SolidColorBrush(Colors.White);
|
||
//Labels.MouseDoubleClick += Labels_MouseDoubleClick; //增加鼠标双击事件
|
||
|
||
//鼠标悬停显示端口号
|
||
cb.MouseEnter += (s, e) =>
|
||
{
|
||
cb.ToolTip = $"{os.IoNumber}";
|
||
};
|
||
|
||
cb.FontFamily = new System.Windows.Media.FontFamily("楷体");
|
||
cb.Margin = new Thickness(1); //设置边距
|
||
cb.HorizontalContentAlignment = HorizontalAlignment.Left;
|
||
cb.VerticalContentAlignment = VerticalAlignment.Center;
|
||
return cb;
|
||
}
|
||
#endregion
|
||
|
||
#region 获取输入信号Grid
|
||
/// <summary>
|
||
/// 获取输入信号Grid
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private Grid GetInputGrid()
|
||
{
|
||
Grid g = new Grid();
|
||
int row = 0;
|
||
int coloum = 0;
|
||
var showList = InputList.Where(w => !w.EmptySignal).ToList(); //筛选出要显示在控制卡上的输入信号,空信号不显示
|
||
int count = showList.Count;
|
||
|
||
if (count <= 16)
|
||
{
|
||
row = count;
|
||
coloum = 1;
|
||
}
|
||
else
|
||
{
|
||
row = 16;
|
||
coloum = count / 16;
|
||
if (count % 16 > 0)
|
||
{
|
||
coloum = coloum + 1;
|
||
}
|
||
}
|
||
|
||
int number = 0;
|
||
Label label;
|
||
for (int i = 0; i < coloum; i++)
|
||
{
|
||
g.ColumnDefinitions.Add(new ColumnDefinition()); //添加列
|
||
for (int j = 0; j < row; j++)
|
||
{
|
||
if (i == 0)
|
||
{
|
||
g.RowDefinitions.Add(new RowDefinition()); //添加行
|
||
}
|
||
|
||
if (number < count)
|
||
{
|
||
//label = GetLabel(InputList[number]);
|
||
|
||
label = GetLabel(showList[number]);
|
||
g.Children.Add(label);
|
||
label.SetValue(Grid.RowProperty, j); //设置按钮所在Grid控件的行
|
||
label.SetValue(Grid.ColumnProperty, i); //设置按钮所在Grid控件的列
|
||
}
|
||
number++;
|
||
}
|
||
}
|
||
return g;
|
||
}
|
||
|
||
private Label GetLabel(InputSignal Is)
|
||
{
|
||
Label Labels = new Label();
|
||
//数据样式
|
||
Labels.Style = (Style)Mywindow.FindResource("LabelStyle");//CheckBoxStyle 这个样式是引用的资源文件中的样式名称
|
||
//设置数据上下文
|
||
Labels.DataContext = Is;
|
||
//绑定背景颜色
|
||
Labels.SetBinding(Label.BackgroundProperty, new Binding() { Path = new PropertyPath("InputColor"), Mode = BindingMode.TwoWay });
|
||
//绑定内容
|
||
//Labels.SetBinding(Label.ContentProperty, new Binding() { Path = new PropertyPath("InputMeaning"), Mode = BindingMode.TwoWay });
|
||
|
||
//加一个控件修饰控件 用于控制字体的大小
|
||
Viewbox vb = new Viewbox();
|
||
vb.Stretch = Stretch.Uniform;
|
||
vb.StretchDirection = StretchDirection.Both;
|
||
//vb.HorizontalAlignment = HorizontalAlignment.Left;
|
||
|
||
if (Application.Current.Resources[Is.InputMeaning] != null)
|
||
{
|
||
vb.Child = new TextBlock() { Text = Application.Current.Resources[Is.InputMeaning].ToString() };
|
||
Labels.Content = vb; //Application.Current.Resources[Is.InputMeaning].ToString();
|
||
}
|
||
else
|
||
{
|
||
vb.Child = new TextBlock() { Text = Is.InputMeaning };
|
||
Labels.Content = vb; //Is.InputMeaning;
|
||
}
|
||
|
||
//设置前景色
|
||
Labels.Foreground = new SolidColorBrush(Colors.White);
|
||
|
||
//鼠标悬停显示端口号
|
||
Labels.MouseEnter += (s, e) =>
|
||
{
|
||
Labels.ToolTip = $"{Is.IoNumber}";
|
||
};
|
||
|
||
//Labels.MouseDoubleClick += Labels_MouseDoubleClick; //增加鼠标双击事件
|
||
Labels.FontFamily = new System.Windows.Media.FontFamily("楷体");
|
||
|
||
Labels.Margin = new Thickness(1); //设置边距
|
||
Labels.HorizontalContentAlignment = HorizontalAlignment.Center;
|
||
Labels.VerticalContentAlignment = VerticalAlignment.Center;
|
||
return Labels;
|
||
}
|
||
#endregion
|
||
|
||
#region 获取IO控制卡
|
||
/// <summary>
|
||
/// 初始化IO控制卡
|
||
/// </summary>
|
||
private void GetIOCard()
|
||
{
|
||
//IO卡ID集合
|
||
List<ushort> ioCarIdList = HelperTxp.GetIoCard();
|
||
if (ioCarIdList == null)
|
||
{
|
||
IoCardID = 0;
|
||
}
|
||
else
|
||
{
|
||
IoCardID = ioCarIdList[0]; //获取Io控制卡ID
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#endregion
|
||
|
||
#region 2、状态监控
|
||
|
||
int A1, A2;
|
||
string lastMsg;
|
||
int msgNumber;
|
||
/// <summary>
|
||
/// 状态监控
|
||
/// </summary>
|
||
private void StateMonitoring()
|
||
{
|
||
while (true)
|
||
{
|
||
Thread.Sleep(10);
|
||
|
||
//记录当前软件运行时间
|
||
TimeSpan ts = DateTime.Now.Subtract(OpenTime).Duration();
|
||
OpenTimeStr = string.Format("{0}天{1}小时{2}分{3}秒", ts.Days, ts.Hours, ts.Minutes, ts.Seconds);
|
||
if (MCVM == null || MCVM.ConnectAllCard())
|
||
{
|
||
#region 1、输入信号状态
|
||
foreach (InputSignal input in InputList)
|
||
{
|
||
input.GetInputLever();
|
||
}
|
||
if (InputList[0].LightUp)
|
||
{
|
||
Start(0);//启动信号
|
||
}
|
||
if (InputList[1].LightUp)
|
||
{
|
||
Stop(0); //停止信号
|
||
}
|
||
if (InputList[2].LightUp)
|
||
{
|
||
EmgStop();// 急停信号
|
||
}
|
||
//if (InputList[3].LightUp)
|
||
//{
|
||
// ExcepStop(InputList[3].InputMeaning);
|
||
//}
|
||
//if (InputList[4].LightUp)
|
||
//{
|
||
// ExcepStop(InputList[4].InputMeaning);
|
||
//}
|
||
|
||
#endregion
|
||
|
||
#region 获取轴状态
|
||
if (MCVM != null)
|
||
{
|
||
MCVM.OrginALL(InputList[2]);
|
||
|
||
if (RunStatu != RunStatuEnum.Normal)
|
||
{
|
||
MCVM.PointRun();
|
||
mCVM.RunMotionTrajectory();
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
DualControlRun();//双控运行
|
||
|
||
GoHome(); //回原点
|
||
|
||
if (lastMsg != TestRecStr)
|
||
{
|
||
CacheLineList[1].State.StatuInfo = lastMsg;
|
||
CacheLineList[0].State.StatuInfo = TestRecStr;
|
||
msgNumber++;
|
||
info = new RecordInfo() { Number = msgNumber, HappenTime = DateTime.Now, Describe = TestRecStr };
|
||
//异步新增项 这是微软的BUG 只能这么麻烦了
|
||
MyDispatcher.BeginInvoke(DispatcherPriority.Background, new ParameterizedThreadStart(AddItem), info);
|
||
|
||
lastMsg = TestRecStr;
|
||
if (ExcepList.Count > 50)
|
||
{
|
||
MyDispatcher.BeginInvoke(DispatcherPriority.Background, new ParameterizedThreadStart(DelItem), info);
|
||
}
|
||
}
|
||
DualControlRun();//双控运行
|
||
|
||
GoHome(); //回原点
|
||
|
||
SendFrontStation();//发送信息给前站
|
||
|
||
SendNextStation();//发送消息给下一站
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
#region 回原点
|
||
DateTime GoHomeTime { get; set; }
|
||
/// <summary>
|
||
/// 回原点
|
||
/// </summary>
|
||
private void GoHome()
|
||
{
|
||
// GoHomeSteps = GengralProcessEnum.End;
|
||
switch (GoHomeSteps)
|
||
{
|
||
case GengralProcessEnum.Start:
|
||
GoHomeSteps++;
|
||
GoHomeTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step1:
|
||
//优先机械手回原点
|
||
if (Robot != null)
|
||
{
|
||
if (Robot.HomeStep == GengralProcessEnum.End)
|
||
{
|
||
GoHomeSteps++;
|
||
}
|
||
else
|
||
{
|
||
Robot.RobotOrgin();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
GoHomeSteps++;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step2:
|
||
if (MCVM != null)
|
||
{
|
||
MCVM.HomeStep = GengralProcessEnum.Start;
|
||
GoHomeSteps++;
|
||
}
|
||
else
|
||
{
|
||
GoHomeSteps = GengralProcessEnum.End;
|
||
RunStatu = RunStatuEnum.Prepareations; //准备就绪
|
||
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step3:
|
||
if (MCVM.HomeStep == GengralProcessEnum.End)
|
||
{
|
||
GoHomeSteps = GengralProcessEnum.End;
|
||
RunStatu = RunStatuEnum.Prepareations; //准备就绪
|
||
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#endregion
|
||
|
||
#region 3、运行
|
||
/// <summary>
|
||
/// 启动运行
|
||
/// </summary>
|
||
private void Run()
|
||
{
|
||
while (true)
|
||
{
|
||
Thread.Sleep(10);
|
||
if (RunStatu == RunStatuEnum.Normal)
|
||
{
|
||
try
|
||
{
|
||
if (!GRRMode)
|
||
{
|
||
LogicDispatch(LogicDispatchFlow);//逻辑总管
|
||
//CarryPutOutRun(CarryPutOutFlow); //机台搬运
|
||
|
||
}
|
||
|
||
ProLineRun(OKLineFlow);//良品皮带
|
||
|
||
TestBoxRun(TestBoxFlow);//测试平台
|
||
//CheckXizui();
|
||
//BadRun(); //不良皮带
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ExcepStop(ex.Message);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
#region 大总管
|
||
/// <summary>
|
||
/// 总流程管理
|
||
/// </summary>
|
||
FlowModel LogicDispatchFlow { get; set; }
|
||
|
||
bool ClearBox { get; set; }
|
||
|
||
/// <summary>
|
||
/// 大总管 //蓝色:测试中 黄色:取出不投入 绿色:取出并投入 红色:异常
|
||
/// </summary>
|
||
private void LogicDispatch(FlowModel MyFlow)
|
||
{
|
||
switch (MyFlow.RunStep)
|
||
{
|
||
case GengralProcessEnum.Start:
|
||
RobotSafe = true;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
TakeFlow = new FlowModel("取料运行");
|
||
break;
|
||
case GengralProcessEnum.Step1:
|
||
//取料运行
|
||
if (TakeRun(TakeFlow))
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
DownVisionFlow = new FlowModel("下视觉检查");
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step2:
|
||
RobotSafe = true;
|
||
//下视觉检查
|
||
if (DownVisionRun(DownVisionFlow))
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step3:
|
||
//获取可以取料的测试盒
|
||
CurrBox = TestBenchBox.Where(w => (w.State.StatusBackground == ColorStr.White && !ClearBox) || w.State.StatusBackground == ColorStr.Green || w.State.StatusBackground == ColorStr.Red).FirstOrDefault();
|
||
if (CurrBox != null)
|
||
{
|
||
//获取吸嘴
|
||
CurrXizui = XizuiLabelPaperList[1];
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
BoxOutPutFlow = new FlowModel("测试盒取出");
|
||
}
|
||
else if(PassLineFlow.EnPut )
|
||
|
||
{
|
||
|
||
|
||
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step4:
|
||
RobotSafe = true;
|
||
//测试盒取出
|
||
if (BoxOutPutRun(BoxOutPutFlow))
|
||
{
|
||
if (!ClearBox)
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
//清料
|
||
AnalysisFlow = new FlowModel("产品分选");
|
||
MyFlow.RunStep = GengralProcessEnum.Step7;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step5:
|
||
//获取可以投入的测试盒
|
||
CurrBox = TestBenchBox.Where(w => w.State.StatusBackground == ColorStr.Blue).FirstOrDefault();
|
||
if (CurrBox != null)
|
||
{
|
||
//指定吸嘴
|
||
CurrXizui = XizuiLabelPaperList[0];
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
BoxInPutFlow = new FlowModel("测试盒投入");
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step6:
|
||
RobotSafe = true;
|
||
//测试盒投入
|
||
if (BoxInPutRun(BoxInPutFlow))
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
AnalysisFlow = new FlowModel("产品分选");
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step7:
|
||
RobotSafe = true;
|
||
//产品分选
|
||
if (AnalysisRun(AnalysisFlow))
|
||
{
|
||
MyFlow.RunStep = GengralProcessEnum.Start;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 取料运行
|
||
/// <summary>
|
||
/// 当前操作对应的格子
|
||
/// </summary>
|
||
MyLabel CurrLabel { get; set; }
|
||
|
||
/// <summary>
|
||
/// 临时点位
|
||
/// </summary>
|
||
RobotPoint TempPoint { get; set; }
|
||
|
||
/// <summary>
|
||
/// 料盘取料流程
|
||
/// </summary>
|
||
FlowModel TakeFlow { get; set; }
|
||
/// <summary>
|
||
/// 当前吸嘴
|
||
/// </summary>
|
||
HandModel CurrXizui { get; set; }
|
||
|
||
/// <summary>
|
||
/// 视觉检查点位
|
||
/// </summary>
|
||
V_RectangleModel RM { get; set; }
|
||
|
||
/// <summary>
|
||
/// 视觉定位次数
|
||
/// </summary>
|
||
int VisonCount { get; set; }
|
||
|
||
/// <summary>
|
||
/// 取料运行
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private bool TakeRun(FlowModel MyFlow)
|
||
{
|
||
bool bl = false;
|
||
switch (MyFlow.RunStep)
|
||
{
|
||
case GengralProcessEnum.Start:
|
||
RobotSafe = true;
|
||
//获取可以取料的吸嘴
|
||
CurrXizui = XizuiLabelPaperList[0];
|
||
if (CurrXizui.State.StatusBackground == ColorStr.White)
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
bl = true;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step1:
|
||
RobotSafe = true;
|
||
//获取可取产品,并且搬运轴在安全位置
|
||
if (InCacheList[0].State.StatusBackground == ColorStr.Green || CurrentMachine.RunningMode)
|
||
{
|
||
RobotSafe = false;
|
||
//获取取料点
|
||
TempPoint = Coper(Robot.RobotPointList.Where(w => w.PointType == 3).FirstOrDefault());
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
//测试盒有待取料,清料
|
||
else if (TestBenchBox.Where(w => w.State.StatusBackground == ColorStr.Green || w.State.StatusBackground == ColorStr.Red).Count() > 0)
|
||
{
|
||
//清料模式
|
||
ClearBox = true;
|
||
bl = true;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step2:
|
||
RobotSafe = false;
|
||
//发送机器人点位
|
||
Robot.RunRobotPoint(TempPoint);
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step3:
|
||
RobotSafe = false;
|
||
//机器人到位
|
||
if (Robot.RcvShowInfo.Contains("runpointok"))
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 20000, "机器人到位超时"))
|
||
{
|
||
MyFlow.RunStep--;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step4:
|
||
//气缸下降
|
||
CurrXizui.QiGang.Switchs = true;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step5:
|
||
//气缸下降到位
|
||
if (CurrXizui.QiGangDown.LightUp)
|
||
{
|
||
//真空吸
|
||
if (!CurrentMachine.RunningMode)
|
||
{
|
||
CurrXizui.VacuumSwitch.Switchs = true;
|
||
}
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 3000, CurrXizui.QiGangDown.InputMeaning + "异常"))
|
||
{
|
||
//气缸下降
|
||
CurrXizui.QiGang.Switchs = true;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step6:
|
||
//真空检知有
|
||
if (CurrXizui.VacuumCheck.LightUp || CurrentMachine.RunningMode)
|
||
{
|
||
CurrXizui.QiGang.Switchs = false; //气缸上升
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 3000, CurrXizui.VacuumCheck.InputMeaning + "异常"))
|
||
{
|
||
//真空吸
|
||
if (!CurrentMachine.RunningMode)
|
||
{
|
||
CurrXizui.VacuumSwitch.Switchs = true;
|
||
}
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step7:
|
||
//气缸上升到位
|
||
if (CurrXizui.QiGangUp.LightUp)
|
||
{
|
||
//二次检查真空
|
||
if (CurrXizui.VacuumCheck.LightUp || CurrentMachine.RunningMode)
|
||
{
|
||
//机械手状态变成有料
|
||
CurrXizui.State.StatusBackground = ColorStr.Blue;
|
||
InCacheList[0].State.StatusBackground = ColorStr.White;
|
||
MyFlow.RunStep = GengralProcessEnum.End;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
bl = true;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 3000, CurrXizui.VacuumCheck.InputMeaning + "异常"))
|
||
{
|
||
MyFlow.RunStep = GengralProcessEnum.Step4;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 3000, CurrXizui.QiGangUp.InputMeaning + "超时"))
|
||
{
|
||
CurrXizui.QiGang.Switchs = false; //气缸上升
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
//case GengralProcessEnum.Step8:
|
||
// //获取待机位
|
||
// TempPoint = Coper(Robot.RobotPointList.Where(w => w.PointType == 1).FirstOrDefault());
|
||
// MyFlow.RunStep++;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
// break;
|
||
//case GengralProcessEnum.Step9:
|
||
// //发送机器人点位
|
||
// Robot.RunRobotPoint(TempPoint);
|
||
// MyFlow.RunStep++;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
// break;
|
||
//case GengralProcessEnum.Step10:
|
||
// //机器人到位
|
||
// if (Robot.RcvShowInfo.Contains("runpointok"))
|
||
// {
|
||
// //机械手状态变成有料
|
||
// CurrXizui.State.StatusBackground = ColorStr.Blue;
|
||
// InCacheList[0].State.StatusBackground = ColorStr.White;
|
||
// MyFlow.RunStep = GengralProcessEnum.End;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
// bl = true;
|
||
// }
|
||
// else if (TimeOutValidation(MyFlow.RunTime, 20000, "机器人到位超时"))
|
||
// {
|
||
// MyFlow.RunStep--;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
// }
|
||
// break;
|
||
}
|
||
|
||
return bl;
|
||
}
|
||
#endregion
|
||
|
||
#region 缓存皮带取料运行(GRR)
|
||
private FlowModel cacheTakeFlow;
|
||
/// <summary>
|
||
/// 缓存取料流程
|
||
/// </summary>
|
||
public FlowModel CacheTakeFlow
|
||
{
|
||
get { return cacheTakeFlow; }
|
||
set { cacheTakeFlow = value; this.RaisePropertyChanged("CacheTakeFlow"); }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 临时缓存取料对象
|
||
/// </summary>
|
||
public HandModel CacheHand { get; set; }
|
||
|
||
/// <summary>
|
||
/// 缓存取料运行
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private bool CacheTakeRun(FlowModel MyFlow)
|
||
{
|
||
bool bl = false;
|
||
switch (MyFlow.RunStep)
|
||
{
|
||
case GengralProcessEnum.Start:
|
||
//获取可以取料的吸嘴
|
||
CurrXizui = XizuiLabelPaperList[0];
|
||
if (CurrXizui.State.StatusBackground == ColorStr.White)
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
bl = true;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step1:
|
||
CacheHand = CacheLineList.Where(w => w.State.StatusBackground == ColorStr.Green).FirstOrDefault();
|
||
//获取可以取料的缓存产品
|
||
if (CacheHand != null)
|
||
{
|
||
//获取取料点
|
||
TempPoint = Coper(CacheHand.PutProPoint1);
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step2:
|
||
//发送机器人点位
|
||
Robot.RunRobotPoint(TempPoint);
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step3:
|
||
//机器人到位
|
||
if (Robot.RcvShowInfo.Contains("runpointok"))
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 20000, "机器人到位超时"))
|
||
{
|
||
MyFlow.RunStep--;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step4:
|
||
//气缸下降
|
||
CurrXizui.QiGang.Switchs = true;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step5:
|
||
//气缸下降到位
|
||
if (CurrXizui.QiGangDown.LightUp)
|
||
{
|
||
//真空吸
|
||
if (!CurrentMachine.RunningMode)
|
||
{
|
||
CurrXizui.VacuumSwitch.Switchs = true;
|
||
}
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 3000, CurrXizui.QiGangDown.InputMeaning + "异常"))
|
||
{
|
||
//气缸下降
|
||
CurrXizui.QiGang.Switchs = true;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step6:
|
||
//真空检知有
|
||
if (CurrXizui.VacuumCheck.LightUp || CurrentMachine.RunningMode)
|
||
{
|
||
CurrXizui.QiGang.Switchs = false; //气缸上升
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 3000, CurrXizui.VacuumCheck.InputMeaning + "异常"))
|
||
{
|
||
//真空吸
|
||
if (!CurrentMachine.RunningMode)
|
||
{
|
||
CurrXizui.VacuumSwitch.Switchs = true;
|
||
}
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step7:
|
||
//气缸上升到位
|
||
if (CurrXizui.QiGangUp.LightUp)
|
||
{
|
||
//二次检查真空
|
||
if (CurrXizui.VacuumCheck.LightUp || CurrentMachine.RunningMode)
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 3000, CurrXizui.VacuumCheck.InputMeaning + "异常"))
|
||
{
|
||
MyFlow.RunStep = GengralProcessEnum.Step4;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 3000, CurrXizui.QiGangUp.InputMeaning + "超时"))
|
||
{
|
||
CurrXizui.QiGang.Switchs = false; //气缸上升
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step8:
|
||
//获取待机位
|
||
TempPoint = Coper(Robot.RobotPointList.Where(w => w.PointType == 1).FirstOrDefault());
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step9:
|
||
//发送机器人点位
|
||
Robot.RunRobotPoint(TempPoint);
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step10:
|
||
//机器人到位
|
||
if (Robot.RcvShowInfo.Contains("runpointok"))
|
||
{
|
||
//机械手状态变成有料
|
||
CurrXizui.State.StatusBackground = ColorStr.Blue;
|
||
InCacheList[0].State.StatusBackground = ColorStr.White;
|
||
MyFlow.RunStep = GengralProcessEnum.End;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
bl = true;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 20000, "机器人到位超时"))
|
||
{
|
||
MyFlow.RunStep--;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
}
|
||
|
||
return bl;
|
||
}
|
||
#endregion
|
||
|
||
#region 分选产品
|
||
|
||
FlowModel AnalysisFlow { get; set; }
|
||
/// <summary>
|
||
/// 分选不良品
|
||
/// </summary>
|
||
/// <param name="MyFlow"></param>
|
||
/// <returns></returns>
|
||
private bool AnalysisRun(FlowModel MyFlow)
|
||
{
|
||
bool bl = false;
|
||
switch (MyFlow.RunStep)
|
||
{
|
||
case GengralProcessEnum.Start:
|
||
//获取需要分拣的吸嘴
|
||
CurrXizui = XizuiLabelPaperList[1];
|
||
if (CurrXizui.State.StatusBackground == ColorStr.Green || CurrXizui.State.StatusBackground == ColorStr.Red)
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
bl = true;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step1:
|
||
if (CurrXizui.State.StatusBackground == ColorStr.Green)
|
||
{
|
||
//获取良品点位
|
||
TempPoint = CurrentMachine.RobotPointList.Where(w => w.PointType == 13).FirstOrDefault();
|
||
}
|
||
else
|
||
{
|
||
//获取不良品点位
|
||
TempPoint = CurrentMachine.RobotPointList.Where(w => w.PointType == 14).FirstOrDefault();
|
||
}
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step2:
|
||
//发送坐标
|
||
if (Robot.RunRobotPoint(TempPoint))
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step3:
|
||
//机器人到位
|
||
if (Robot.RcvShowInfo.Contains("runpointok"))
|
||
{
|
||
|
||
if (CurrXizui.State.StatusBackground == ColorStr.Green)
|
||
{
|
||
if (OKLineFlow.EnPut)
|
||
{
|
||
|
||
CurrXizui.QiGang.Switchs = true;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
CurrXizui.QiGang.Switchs = true;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 10000, "机器人到位超时"))
|
||
{
|
||
MyFlow.RunStep--;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step4:
|
||
//气缸下降到位
|
||
if (CurrXizui.QiGangDown.LightUp)
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 10000, CurrXizui.QiGangDown.InputMeaning + "异常"))
|
||
{
|
||
CurrXizui.QiGang.Switchs = true;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step5:
|
||
CurrXizui.VacuumSwitch.Switchs = false;//真空吸
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step6:
|
||
//真空捡知有
|
||
if (!CurrXizui.VacuumCheck.LightUp && MyFlow.RunTime.AddMilliseconds(500) < DateTime.Now)
|
||
{
|
||
CurrXizui.QiGang.Switchs = false;//气缸上升
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 3000, CurrXizui.VacuumCheck.InputMeaning + "超时"))
|
||
{
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step7:
|
||
//气缸上升到位
|
||
if (CurrXizui.QiGangUp.LightUp)
|
||
{
|
||
if (CurrXizui.State.StatusBackground == ColorStr.Green)
|
||
{
|
||
|
||
}
|
||
else
|
||
{
|
||
BadLineRun = true;
|
||
}
|
||
CurrXizui.State = new ShowInfo();
|
||
ClearBox = false; //清料完成
|
||
MyFlow.RunStep = GengralProcessEnum.Start;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
|
||
//MyFlow.RunStep++;
|
||
//MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 3000, CurrXizui.QiGangUp.InputMeaning + "异常"))
|
||
{
|
||
CurrXizui.QiGang.Switchs = false;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
//case GengralProcessEnum.Step8:
|
||
// //获取待机位
|
||
// TempPoint = Coper(Robot.RobotPointList.Where(w => w.PointType == 1).FirstOrDefault());
|
||
// MyFlow.RunStep++;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
// break;
|
||
//case GengralProcessEnum.Step9:
|
||
// //发送机器人点位
|
||
// Robot.RunRobotPoint(TempPoint);
|
||
// MyFlow.RunStep++;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
// break;
|
||
//case GengralProcessEnum.Step10:
|
||
// //机器人到位
|
||
// if (Robot.RcvShowInfo.Contains("runpointok"))
|
||
// {
|
||
// ClearBox = false; //清料完成
|
||
// MyFlow.RunStep = GengralProcessEnum.Start;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
// }
|
||
// else if (TimeOutValidation(MyFlow.RunTime, 20000, "机器人到位超时"))
|
||
// {
|
||
// MyFlow.RunStep--;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
// }
|
||
// break;
|
||
}
|
||
|
||
return bl;
|
||
}
|
||
|
||
#endregion
|
||
|
||
|
||
#region 过站产品
|
||
|
||
FlowModel PassFlow { get; set; }
|
||
/// <summary>
|
||
/// 分选不良品
|
||
/// </summary>
|
||
/// <param name="MyFlow"></param>
|
||
/// <returns></returns>
|
||
private bool PassRun(FlowModel MyFlow)
|
||
{
|
||
bool bl = false;
|
||
switch (MyFlow.RunStep)
|
||
{
|
||
case GengralProcessEnum.Start:
|
||
//获取需要分拣的吸嘴
|
||
CurrXizui = XizuiLabelPaperList[1];
|
||
|
||
break;
|
||
case GengralProcessEnum.Step1:
|
||
|
||
TempPoint = CurrentMachine.RobotPointList.Where(w => w.PointType == 13).FirstOrDefault();
|
||
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step2:
|
||
//发送坐标
|
||
if (Robot.RunRobotPoint(TempPoint))
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step3:
|
||
//机器人到位
|
||
if (Robot.RcvShowInfo.Contains("runpointok"))
|
||
{
|
||
|
||
if (CurrXizui.State.StatusBackground == ColorStr.Green)
|
||
{
|
||
if (OKLineFlow.EnPut)
|
||
{
|
||
|
||
CurrXizui.QiGang.Switchs = true;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
CurrXizui.QiGang.Switchs = true;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 10000, "机器人到位超时"))
|
||
{
|
||
MyFlow.RunStep--;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step4:
|
||
//气缸下降到位
|
||
if (CurrXizui.QiGangDown.LightUp)
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 10000, CurrXizui.QiGangDown.InputMeaning + "异常"))
|
||
{
|
||
CurrXizui.QiGang.Switchs = true;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step5:
|
||
CurrXizui.VacuumSwitch.Switchs = false;//真空吸
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step6:
|
||
//真空捡知有
|
||
if (!CurrXizui.VacuumCheck.LightUp && MyFlow.RunTime.AddMilliseconds(500) < DateTime.Now)
|
||
{
|
||
CurrXizui.QiGang.Switchs = false;//气缸上升
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 3000, CurrXizui.VacuumCheck.InputMeaning + "超时"))
|
||
{
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step7:
|
||
//气缸上升到位
|
||
if (CurrXizui.QiGangUp.LightUp)
|
||
{
|
||
if (CurrXizui.State.StatusBackground == ColorStr.Green)
|
||
{
|
||
|
||
}
|
||
else
|
||
{
|
||
BadLineRun = true;
|
||
}
|
||
CurrXizui.State = new ShowInfo();
|
||
ClearBox = false; //清料完成
|
||
MyFlow.RunStep = GengralProcessEnum.Start;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
|
||
//MyFlow.RunStep++;
|
||
//MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 3000, CurrXizui.QiGangUp.InputMeaning + "异常"))
|
||
{
|
||
CurrXizui.QiGang.Switchs = false;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
//case GengralProcessEnum.Step8:
|
||
// //获取待机位
|
||
// TempPoint = Coper(Robot.RobotPointList.Where(w => w.PointType == 1).FirstOrDefault());
|
||
// MyFlow.RunStep++;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
// break;
|
||
//case GengralProcessEnum.Step9:
|
||
// //发送机器人点位
|
||
// Robot.RunRobotPoint(TempPoint);
|
||
// MyFlow.RunStep++;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
// break;
|
||
//case GengralProcessEnum.Step10:
|
||
// //机器人到位
|
||
// if (Robot.RcvShowInfo.Contains("runpointok"))
|
||
// {
|
||
// ClearBox = false; //清料完成
|
||
// MyFlow.RunStep = GengralProcessEnum.Start;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
// }
|
||
// else if (TimeOutValidation(MyFlow.RunTime, 20000, "机器人到位超时"))
|
||
// {
|
||
// MyFlow.RunStep--;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
// }
|
||
// break;
|
||
}
|
||
|
||
return bl;
|
||
}
|
||
|
||
#endregion
|
||
|
||
|
||
|
||
#region 上视觉检查运行
|
||
/// <summary>
|
||
/// 上视觉检查
|
||
/// </summary>
|
||
public FlowModel UpVisionFlow { get; set; }
|
||
|
||
/// <summary>
|
||
/// 上视觉模板
|
||
/// </summary>
|
||
public V_RectangleModel UPRM { get; set; }
|
||
|
||
/// <summary>
|
||
/// 上视觉检查
|
||
/// </summary>
|
||
public bool UpVisionRun(FlowModel MyFlow)
|
||
{
|
||
bool bl = false;
|
||
switch (MyFlow.RunStep)
|
||
{
|
||
case GengralProcessEnum.Start:
|
||
//获取可以取料的吸嘴
|
||
CurrXizui = XizuiLabelPaperList.Where(w => w.State.StatusBackground == ColorStr.White).FirstOrDefault();
|
||
if (CurrXizui != null)
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
bl = true;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step1:
|
||
//获取可取产品
|
||
CurrLabel = Tray1.MyLabelList.Where(w => (w.Prouct.StateColour == ColorStr.Green)).FirstOrDefault();
|
||
if (CurrLabel != null)
|
||
{
|
||
TempPoint = Coper(CurrLabel.TakeVisionPoint);
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step2:
|
||
//发送机器人点位
|
||
Robot.RunRobotPoint(TempPoint);
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step3:
|
||
//机器人到位
|
||
if (Robot.RcvShowInfo.Contains("runpointok"))
|
||
{
|
||
//获取视觉模板
|
||
UPRM = VisualA.VisualEngineeringList[0].VisualEngineeringItemsList[0].MyRectangleModel;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 20000, "机器人到位超时"))
|
||
{
|
||
MyFlow.RunStep--;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step4:
|
||
//视觉定位
|
||
VisonCount++;
|
||
if (VisualA.FeatureMatchingIng(UPRM) || CurrentMachine.RunningMode)
|
||
{
|
||
bl = true;
|
||
MyFlow.RunStep = GengralProcessEnum.Start;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
|
||
//记录补偿值
|
||
CurrXizui.OfficeX = (double)UPRM.MyROI.ModelFeaturePiont.DeviationX;
|
||
CurrXizui.OfficeY = (double)UPRM.MyROI.ModelFeaturePiont.DeviationX;
|
||
}
|
||
else
|
||
{
|
||
if (VisonCount >= 3)
|
||
{
|
||
CurrLabel.Prouct.StateColour = ColorStr.White; //料盘当前位置置为白色,取下一个产品
|
||
MyFlow.RunStep = GengralProcessEnum.Start;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
OutputList[12].Switchs = false;//光源
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
return bl;
|
||
}
|
||
#endregion
|
||
|
||
#region 下视觉检查运行
|
||
/// <summary>
|
||
/// 下视觉检查流程
|
||
/// </summary>
|
||
FlowModel DownVisionFlow { get; set; }
|
||
|
||
/// <summary>
|
||
/// 下视觉检查运行
|
||
/// </summary>
|
||
/// <param name="MyFlow"></param>
|
||
/// <returns></returns>
|
||
private bool DownVisionRun(FlowModel MyFlow)
|
||
{
|
||
bool bl = false;
|
||
switch (MyFlow.RunStep)
|
||
{
|
||
case GengralProcessEnum.Start:
|
||
CurrXizui = XizuiLabelPaperList[0];
|
||
if (CurrXizui.State.StatusBackground == ColorStr.Blue)
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
bl = true;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step1:
|
||
//获取下视觉扫码点
|
||
TempPoint = Coper(CurrentMachine.RobotPointList.Where(w => w.PointType == 10).FirstOrDefault());
|
||
//发送机器人点位
|
||
Robot.RunRobotPoint(TempPoint);
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step2:
|
||
//机器人到位
|
||
if (Robot.RcvShowInfo.Contains("runpointok"))
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 10000, "机器人到位超时"))
|
||
{
|
||
MyFlow.RunStep--;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step3:
|
||
//获取下视觉模板
|
||
RM = VisualB.VisualEngineeringList[0].VisualEngineeringItemsList[2].MyRectangleModel;
|
||
VisonCount = 0;
|
||
OutputList[O15下光源控制].Switchs = true;//光源
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step4:
|
||
VisonCount++;
|
||
if (VisualB.SweepCode(RM) || CurrentMachine.RunningMode)
|
||
{
|
||
CurrXizui.State.StatuInfo = VisualB.QrCodeStr;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
if (VisonCount >= 3)
|
||
{
|
||
ExcepStop("下视觉扫码失败");
|
||
MyFlow.RunStep--;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
OutputList[O15下光源控制].Switchs = false;//光源
|
||
}
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step5:
|
||
//下视觉定位点位
|
||
TempPoint = Coper(CurrentMachine.RobotPointList.Where(w => w.PointType == 8).FirstOrDefault());
|
||
//发送机器人点位
|
||
Robot.RunRobotPoint(TempPoint);
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step6:
|
||
//机器人到位
|
||
if (Robot.RcvShowInfo.Contains("runpointok"))
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 10000, "机器人到位超时"))
|
||
{
|
||
MyFlow.RunStep--;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step7:
|
||
//延时0.3S
|
||
if (MyFlow.RunTime.AddMilliseconds(300) > DateTime.Now)
|
||
{
|
||
break;
|
||
}
|
||
|
||
//获取下视觉模板
|
||
RM = VisualB.VisualEngineeringList[0].VisualEngineeringItemsList[0].MyRectangleModel;
|
||
VisonCount = 0;
|
||
OutputList[O15下光源控制].Switchs = true;//光源
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step8:
|
||
VisonCount++;
|
||
if (VisualB.FeatureMatchingIng(RM) || CurrentMachine.RunningMode)
|
||
{
|
||
//空跑不二次定位
|
||
if (CurrentMachine.RunningMode)
|
||
{
|
||
OutputList[O15下光源控制].Switchs = false;//光源
|
||
CurrXizui.State.StatusBackground = ColorStr.Green;
|
||
MyFlow.RunStep = GengralProcessEnum.Start;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
if (Math.Abs(RM.MyROI.ModelFeaturePiont.AngleU) < 10)
|
||
{
|
||
CurrXizui.OfficeU = (double)RM.MyROI.ModelFeaturePiont.AngleU;
|
||
TempPoint.PointU -= (double)RM.MyROI.ModelFeaturePiont.AngleU;
|
||
TempPoint.SpeedGear = 40;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
ExcepStop("下视觉定位偏差过大,请检查!");
|
||
}
|
||
|
||
}
|
||
|
||
//if (Math.Abs(RM.MyROI.ModelFeaturePiont.AngleU) < 10)
|
||
//{
|
||
// CurrXizui.OfficeU = (double)RM.MyROI.ModelFeaturePiont.AngleU;
|
||
// TempPoint.PointU += (double)RM.MyROI.ModelFeaturePiont.AngleU;
|
||
// TempPoint.SpeedGear = 40;
|
||
// MyFlow.RunStep++;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
//}
|
||
//else
|
||
//{
|
||
// ExcepStop("下视觉定位偏差过大,请检查!");
|
||
//}
|
||
|
||
}
|
||
else
|
||
{
|
||
if (VisonCount >= 3)
|
||
{
|
||
ExcepStop("下视觉定位失败");
|
||
MyFlow.RunStep = GengralProcessEnum.Start;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
OutputList[O15下光源控制].Switchs = false;//光源
|
||
}
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step9:
|
||
//发送机器人点位
|
||
Robot.RunRobotPoint(TempPoint);
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step10:
|
||
//机器人到位
|
||
if (Robot.RcvShowInfo.Contains("runpointok"))
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
VisonCount = 0;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 10000, "机器人到位超时"))
|
||
{
|
||
MyFlow.RunStep--;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step11:
|
||
//延时0.3S
|
||
if (MyFlow.RunTime.AddMilliseconds(300) > DateTime.Now)
|
||
{
|
||
break;
|
||
}
|
||
|
||
VisonCount++;
|
||
if (VisualB.FeatureMatchingIng(RM) || CurrentMachine.RunningMode)
|
||
{
|
||
CurrXizui.State.StatusBackground = ColorStr.Green;
|
||
MyFlow.RunStep = GengralProcessEnum.Start;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
|
||
OutputList[O15下光源控制].Switchs = false;//光源
|
||
|
||
//记录补偿值
|
||
if (Math.Abs(RM.MyROI.ModelFeaturePiont.DeviationX) < 10 && Math.Abs(RM.MyROI.ModelFeaturePiont.DeviationY) < 10)
|
||
{
|
||
CurrXizui.OfficeX = (double)RM.MyROI.ModelFeaturePiont.DeviationX;
|
||
CurrXizui.OfficeY = (double)RM.MyROI.ModelFeaturePiont.DeviationY;
|
||
}
|
||
else
|
||
{
|
||
ExcepStop("下视觉定位偏差过大,请检查!");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (VisonCount >= 3)
|
||
{
|
||
ExcepStop("下视觉定位失败");
|
||
MyFlow.RunStep = GengralProcessEnum.Start;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
OutputList[O15下光源控制].Switchs = false;//光源
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
|
||
return bl;
|
||
}
|
||
#endregion
|
||
|
||
#region 测试盒放料运行
|
||
/// <summary>
|
||
/// 投入料盘流程
|
||
/// </summary>
|
||
FlowModel BoxInPutFlow { get; set; }
|
||
|
||
/// <summary>
|
||
/// 当前载具对象
|
||
/// </summary>
|
||
public HandModel CurrBox { get; set; }
|
||
|
||
/// <summary>
|
||
/// 放料运行
|
||
/// </summary>
|
||
/// <param name="MyFlow"></param>
|
||
/// <returns></returns>
|
||
private bool BoxInPutRun(FlowModel MyFlow)
|
||
{
|
||
bool bl = false;
|
||
switch (MyFlow.RunStep)
|
||
{
|
||
case GengralProcessEnum.Start:
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step1:
|
||
//获取放料点
|
||
TempPoint = Coper(CurrBox.PutProPoint1);
|
||
|
||
//下视觉定位补偿
|
||
TempPoint.PointX -= CurrXizui.OfficeX;
|
||
TempPoint.PointY += CurrXizui.OfficeY;
|
||
TempPoint.PointU -= CurrXizui.OfficeU;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step2:
|
||
//发送点位
|
||
if (Robot.RunRobotPoint(TempPoint))
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step3:
|
||
//机器人到位
|
||
if (Robot.RcvShowInfo.Contains("runpointok"))
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 10000, "机器人到位超时"))
|
||
{
|
||
MyFlow.RunStep--;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step4:
|
||
CurrXizui.QiGang.Switchs = true; //气缸下降
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step5:
|
||
//气缸下降到位
|
||
if (CurrXizui.QiGangDown.LightUp)
|
||
{
|
||
CurrXizui.VacuumSwitch.Switchs = false;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 3000, CurrXizui.QiGangDown.InputMeaning + "异常"))
|
||
{
|
||
//气缸下降
|
||
CurrXizui.QiGang.Switchs = true;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step6:
|
||
//真空检知有
|
||
if (!CurrXizui.VacuumCheck.LightUp)
|
||
{
|
||
CurrXizui.QiGang.Switchs = false; //气缸上升
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 3000, CurrXizui.VacuumCheck.InputMeaning + "关闭异常"))
|
||
{
|
||
CurrXizui.VacuumSwitch.Switchs = false;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step7:
|
||
//气缸上升到位
|
||
if (CurrXizui.QiGangUp.LightUp)
|
||
{
|
||
//测试盒状态赋值为有料
|
||
CurrBox.State.StatuInfo = CurrXizui.State.StatuInfo;
|
||
CurrXizui.State = new ShowInfo();
|
||
CurrBox.State.StatusBackground = ColorStr.Yellow;
|
||
MyFlow.RunStep = GengralProcessEnum.End;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
bl = true;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 3000, CurrXizui.QiGangUp.InputMeaning + "超时"))
|
||
{
|
||
CurrXizui.QiGang.Switchs = false; //气缸上升
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
}
|
||
|
||
return bl;
|
||
}
|
||
#endregion
|
||
|
||
#region 测试盒取料运行
|
||
/// <summary>
|
||
/// 测试盒取出流程
|
||
/// </summary>
|
||
FlowModel BoxOutPutFlow { get; set; }
|
||
|
||
/// <summary>
|
||
/// 测试盒取出运行
|
||
/// </summary>
|
||
/// <param name="MyFlow"></param>
|
||
/// <returns></returns>
|
||
private bool BoxOutPutRun(FlowModel MyFlow)
|
||
{
|
||
bool bl = false;
|
||
switch (MyFlow.RunStep)
|
||
{
|
||
case GengralProcessEnum.Start:
|
||
//获取测试盒取料位
|
||
TempPoint = Coper(CurrBox.TakeProPoint1);
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step1:
|
||
//先运行点位,打开测试盒,再检查到位
|
||
if (Robot.RunRobotPoint(TempPoint))
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step2:
|
||
//打开测试盒
|
||
//顶升气缸原位
|
||
CurrBox.YDingShengQiGangDW.Switchs = false;
|
||
CurrBox.YDingShengQiGangYW.Switchs = true;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step3:
|
||
//顶升气缸原位
|
||
if (CurrBox.XDingShengQigangYW.LightUp || CurrentMachine.RunningMode)
|
||
{
|
||
//伸缩气缸原位
|
||
CurrBox.YShenSuoQiGangDW.Switchs = false;
|
||
CurrBox.YShenSuoQiGangYW.Switchs = true;
|
||
|
||
//顶升置位
|
||
CurrBox.YDingShengQiGangDW.Switchs = false;
|
||
CurrBox.YDingShengQiGangYW.Switchs = false;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (MyFlow.RunTime.AddSeconds(3) <= DateTime.Now)
|
||
{
|
||
ExcepStop(CurrBox.XDingShengQigangYW.InputMeaning + "异常");
|
||
CurrBox.YDingShengQiGangDW.Switchs = false;
|
||
CurrBox.YDingShengQiGangYW.Switchs = true;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step4:
|
||
//伸缩气缸原位
|
||
if (CurrBox.XShenSuoQigangYW.LightUp || CurrentMachine.RunningMode)
|
||
{
|
||
//伸缩置位
|
||
CurrBox.YShenSuoQiGangDW.Switchs = false;
|
||
CurrBox.YShenSuoQiGangYW.Switchs = false;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (MyFlow.RunTime.AddSeconds(3) <= DateTime.Now)
|
||
{
|
||
ExcepStop(CurrBox.XShenSuoQigangYW.InputMeaning + "异常");
|
||
//伸缩气缸原位
|
||
CurrBox.YShenSuoQiGangDW.Switchs = false;
|
||
CurrBox.YShenSuoQiGangYW.Switchs = true;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step5:
|
||
//机器人到位
|
||
if (Robot.RcvShowInfo.Contains("runpointok"))
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 10000, "机器人到位超时"))
|
||
{
|
||
Robot.RunRobotPoint(TempPoint);
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step6:
|
||
CurrXizui.QiGang.Switchs = true; //气缸下降
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step7:
|
||
//气缸下降到位
|
||
if (CurrXizui.QiGangDown.LightUp)
|
||
{
|
||
//真空吸
|
||
if (!CurrentMachine.RunningMode)
|
||
{
|
||
CurrXizui.VacuumSwitch.Switchs = true;
|
||
}
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 3000, CurrXizui.QiGangDown.InputMeaning + "异常"))
|
||
{
|
||
//气缸下降
|
||
CurrXizui.QiGang.Switchs = true;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step8:
|
||
//真空检知有,无料不检查真空
|
||
if (CurrXizui.VacuumCheck.LightUp || CurrBox.State.StatusBackground == ColorStr.White || CurrentMachine.RunningMode)
|
||
{
|
||
CurrXizui.QiGang.Switchs = false; //气缸上升
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 3000, CurrXizui.VacuumCheck.InputMeaning + "异常"))
|
||
{
|
||
//真空吸
|
||
if (!CurrentMachine.RunningMode)
|
||
{
|
||
CurrXizui.VacuumSwitch.Switchs = true;
|
||
}
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step9:
|
||
//气缸上升到位
|
||
if (CurrXizui.QiGangUp.LightUp)
|
||
{
|
||
//二次检查真空
|
||
if (CurrXizui.VacuumCheck.LightUp || CurrBox.State.StatusBackground == ColorStr.White || CurrentMachine.RunningMode)
|
||
{
|
||
//测试盒状态赋值给吸嘴后清空测试盒状态
|
||
if (CurrBox.State.StatusBackground == ColorStr.Green)
|
||
{
|
||
CurrXizui.State.StatusBackground = ColorStr.Green;
|
||
}
|
||
else
|
||
{
|
||
CurrXizui.State.StatusBackground = ColorStr.Red;
|
||
}
|
||
//if (CurrBox.State.StatusBackground != ColorStr.Blue)
|
||
//{
|
||
// CurrBox.State = new ShowInfo();
|
||
|
||
//}
|
||
CurrBox.State = new ShowInfo();
|
||
|
||
if (!ClearBox) //清料
|
||
{
|
||
CurrBox.State.StatusBackground = ColorStr.Blue;
|
||
}
|
||
|
||
MyFlow.RunStep = GengralProcessEnum.End;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
bl = true;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 3000, CurrXizui.VacuumCheck.InputMeaning + "异常"))
|
||
{
|
||
CurrXizui.QiGang.Switchs = false; //气缸上升
|
||
MyFlow.RunStep = GengralProcessEnum.Step6;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 3000, CurrXizui.QiGangUp.InputMeaning + "超时"))
|
||
{
|
||
CurrXizui.QiGang.Switchs = false; //气缸上升
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
}
|
||
|
||
return bl;
|
||
}
|
||
#endregion
|
||
|
||
#region 搬运出料
|
||
/// <summary>
|
||
/// 搬运出料流程
|
||
/// </summary>
|
||
FlowModel CarryPutOutFlow { get; set; }
|
||
|
||
/// <summary>
|
||
/// 搬运出料平台临时对象
|
||
/// </summary>
|
||
HandModel CarryPutOutHand { get; set; }
|
||
|
||
/// <summary>
|
||
/// 搬运出料临时点位
|
||
/// </summary>
|
||
MotionPointModel CarryPutOutMotionPoint { get; set; }
|
||
|
||
/// <summary>
|
||
/// 搬运轴安全信号
|
||
/// </summary>
|
||
bool CarryAxisSafe { get; set; }
|
||
|
||
/// <summary>
|
||
/// 机械手安全信号
|
||
/// </summary>
|
||
bool RobotSafe { get; set; }
|
||
|
||
|
||
#endregion
|
||
|
||
|
||
|
||
#region 检查吸嘴真空
|
||
/// <summary>
|
||
/// 检查产品掉落
|
||
/// </summary>
|
||
public void CheckXizui()
|
||
{
|
||
if (RunStatu == RunStatuEnum.Normal)
|
||
{
|
||
if (XizuiLabelPaperList != null)
|
||
{
|
||
foreach (var item in XizuiLabelPaperList)
|
||
{
|
||
//运行中,产品掉落,报警提示
|
||
if (item.State.StatusBackground != ColorStr.White && item.State.StatusBackground != ColorStr.Red && item.VacuumSwitch.Switchs && !item.VacuumCheck.LightUp)
|
||
{
|
||
if (item.CheckVacuumTime.AddMilliseconds(1000) <= DateTime.Now)
|
||
{
|
||
ExcepStop("吸嘴" + item.Number + "产品掉落,请检查");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
item.CheckVacuumTime = DateTime.Now;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 测试平台运行
|
||
private FlowModel testBoxFlow;
|
||
/// <summary>
|
||
/// 测试平台运行
|
||
/// </summary>
|
||
public FlowModel TestBoxFlow
|
||
{
|
||
get { return testBoxFlow; }
|
||
set { testBoxFlow = value; this.RaisePropertyChanged("TestBoxFlow"); }
|
||
}
|
||
|
||
private HandModel currTestBox;
|
||
/// <summary>
|
||
/// 临时测试盒对象
|
||
/// </summary>
|
||
public HandModel CurrTestBox
|
||
{
|
||
get { return currTestBox; }
|
||
set { currTestBox = value; this.RaisePropertyChanged("CurrTestBox"); }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 测试中信号
|
||
/// </summary>
|
||
public bool Testing { get; set; }
|
||
|
||
/// <summary>
|
||
/// 测试结果字符串
|
||
/// </summary>
|
||
public string TestResultStr { get; set; }
|
||
|
||
/// <summary>
|
||
/// 测试平台运行
|
||
/// </summary>
|
||
/// <param name="MyFlow"></param>
|
||
private void TestBoxRun(FlowModel MyFlow)
|
||
{
|
||
switch (MyFlow.RunStep)
|
||
{
|
||
case GengralProcessEnum.Start:
|
||
if (CurrentMachine.RunningMode || TestMachine.Showmsg.StatusBackground == ColorStr.Green)
|
||
{
|
||
//放满两个产品,开始测试
|
||
if (TestBenchBox.Where(w => w.State.StatusBackground == ColorStr.Yellow).Count() >= 2)
|
||
{
|
||
MyFlow.RunStep = GengralProcessEnum.Step10;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ExcepStop("测试机未连接");
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step1:
|
||
//获取可以放料的测试盒
|
||
CurrTestBox = TestBenchBox.Where(w => w.State.StatusBackground == ColorStr.Blue).FirstOrDefault();
|
||
//CurrTestBox = TestBenchBox.Where(w => w.State.StatusBackground == ColorStr.White && w.Number == 1).FirstOrDefault();
|
||
if (CurrTestBox != null && (CurrentMachine.RunningMode || TestRecStr.Contains("QUERY?")))
|
||
{
|
||
CurrTestBox.State.StatusBackground = ColorStr.Blue;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
|
||
#region 测试盒气缸打开流程,已改为机械手流程控制
|
||
//case GengralProcessEnum.Step2:
|
||
// //顶升气缸原位
|
||
// CurrTestBox.YDingShengQiGangDW.Switchs = false;
|
||
// CurrTestBox.YDingShengQiGangYW.Switchs = true;
|
||
// MyFlow.RunStep++;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
// break;
|
||
//case GengralProcessEnum.Step3:
|
||
// //顶升气缸原位
|
||
// if (CurrTestBox.XDingShengQigangYW.LightUp)
|
||
// {
|
||
// //伸缩气缸原位
|
||
// CurrTestBox.YShenSuoQiGangDW.Switchs = false;
|
||
// CurrTestBox.YShenSuoQiGangYW.Switchs = true;
|
||
|
||
// //顶升置位
|
||
// CurrTestBox.YDingShengQiGangDW.Switchs = false;
|
||
// CurrTestBox.YDingShengQiGangYW.Switchs = false;
|
||
// MyFlow.RunStep++;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
// }
|
||
// else if (MyFlow.RunTime.AddSeconds(3) <= DateTime.Now)
|
||
// {
|
||
// ExcepStop(CurrTestBox.XDingShengQigangYW.InputMeaning + "异常");
|
||
// CurrTestBox.YDingShengQiGangDW.Switchs = false;
|
||
// CurrTestBox.YDingShengQiGangYW.Switchs = true;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
// }
|
||
// break;
|
||
//case GengralProcessEnum.Step4:
|
||
// //伸缩气缸原位
|
||
// if (CurrTestBox.XShenSuoQigangYW.LightUp)
|
||
// {
|
||
// //伸缩置位
|
||
// CurrTestBox.YShenSuoQiGangDW.Switchs = false;
|
||
// CurrTestBox.YShenSuoQiGangYW.Switchs = false;
|
||
// CurrTestBox.State.StatusBackground = ColorStr.Blue; //允许投料状态
|
||
// MyFlow.RunStep++;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
// }
|
||
// else if (MyFlow.RunTime.AddSeconds(3) <= DateTime.Now)
|
||
// {
|
||
// ExcepStop(CurrTestBox.XShenSuoQigangYW.InputMeaning + "异常");
|
||
// //伸缩气缸原位
|
||
// CurrTestBox.YShenSuoQiGangDW.Switchs = false;
|
||
// CurrTestBox.YShenSuoQiGangYW.Switchs = true;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
// }
|
||
// break;
|
||
#endregion
|
||
|
||
case GengralProcessEnum.Step2:
|
||
//已投料
|
||
if (CurrTestBox.State.StatusBackground == ColorStr.Yellow)
|
||
{
|
||
if (!CurrentMachine.RunningMode)
|
||
{
|
||
//伸缩气缸到位
|
||
CurrTestBox.YShenSuoQiGangDW.Switchs = true;
|
||
CurrTestBox.YShenSuoQiGangYW.Switchs = false;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else //空跑模式
|
||
{
|
||
MyFlow.RunStep = GengralProcessEnum.Start;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step3:
|
||
//伸缩气缸到位
|
||
if (CurrTestBox.XShenSuoQigangDW.LightUp)
|
||
{
|
||
//伸缩置位
|
||
CurrTestBox.YShenSuoQiGangDW.Switchs = false;
|
||
CurrTestBox.YShenSuoQiGangYW.Switchs = false;
|
||
|
||
//顶升到位
|
||
CurrTestBox.YDingShengQiGangDW.Switchs = true;
|
||
CurrTestBox.YDingShengQiGangYW.Switchs = false;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (MyFlow.RunTime.AddSeconds(3) <= DateTime.Now)
|
||
{
|
||
ExcepStop(CurrTestBox.XShenSuoQigangDW.InputMeaning + "异常");
|
||
//伸缩气缸到位
|
||
CurrTestBox.YShenSuoQiGangDW.Switchs = true;
|
||
CurrTestBox.YShenSuoQiGangYW.Switchs = false;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step4:
|
||
//顶升气缸到位
|
||
if (CurrTestBox.XDingShengQigangDW.LightUp)
|
||
{
|
||
CurrTestBox.State.StatusBackground = ColorStr.Yellow; //气缸到位,准备测试
|
||
MyFlow.RunStep = GengralProcessEnum.Start;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (MyFlow.RunTime.AddSeconds(3) <= DateTime.Now)
|
||
{
|
||
ExcepStop(CurrTestBox.XDingShengQigangDW.InputMeaning + "异常");
|
||
//顶升到位
|
||
CurrTestBox.YDingShengQiGangDW.Switchs = true;
|
||
CurrTestBox.YDingShengQiGangYW.Switchs = false;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
|
||
case GengralProcessEnum.Step10:
|
||
if (!CurrentMachine.RunningMode)
|
||
{
|
||
//发送机械手准备就绪
|
||
TestMachine.SendInfo("READY");
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
TestBenchBox.ForEach(w => w.State.StatusBackground = ColorStr.Green);
|
||
MyFlow.RunStep = GengralProcessEnum.Start;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
|
||
break;
|
||
case GengralProcessEnum.Step11:
|
||
//接受测试机就绪信号
|
||
if (TestRecStr.Contains("LOAD"))
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (MyFlow.RunTime.AddMilliseconds(1000) <= DateTime.Now)
|
||
{
|
||
MyFlow.RunStep--;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step12:
|
||
if (TestBenchBox[0].XDingShengQigangDW.LightUp && TestBenchBox[0].XShenSuoQigangDW.LightUp && TestBenchBox[1].XDingShengQigangDW.LightUp && TestBenchBox[1].XShenSuoQigangDW.LightUp)
|
||
{
|
||
string sn1 = TestBenchBox[0].State.StatuInfo == "" ? "12345678901234567890" : TestBenchBox[0].State.StatuInfo;
|
||
string sn2 = TestBenchBox[1].State.StatuInfo == "" ? "12345678901234567890" : TestBenchBox[1].State.StatuInfo;
|
||
//string sn1 = "1234567890123";
|
||
//string sn2 = "1234567890123";
|
||
|
||
//清空测试结果
|
||
TestResultStr = "";
|
||
TestFinish = false;
|
||
Testing = true; //测试中
|
||
|
||
//发送二维码和开始信号
|
||
TestMachine.SendInfo(sn1 + ";" + sn2 + ";LOADOK");
|
||
TestMachine.SendInfo(sn1 + ";" + sn2 + ";LOADOK");
|
||
TestMachine.SendInfo(sn1 + ";" + sn2 + ";LOADOK");
|
||
TestMachine.SendInfo(sn1 + ";" + sn2 + ";LOADOK");
|
||
TestMachine.SendInfo(sn1 + ";" + sn2 + ";LOADOK");
|
||
|
||
//TestMachine.SendInfo("12;34;LOADOK");
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
ExcepStop("左右工位感应器到位异常,请检查");
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step13:
|
||
//等待测试机回复测试完成
|
||
//if (TestRecStr.Contains("TESTOK"))
|
||
//{
|
||
// MyFlow.RunStep++;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
//}
|
||
//else if (TestRecStr.Contains("ALARM")) //测试机回复报错,产品判定为NG
|
||
//{
|
||
// TestBenchBox.ForEach(w => w.State.StatusBackground = ColorStr.Red);
|
||
// MyFlow.RunStep = GengralProcessEnum.Step15;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
//}
|
||
////200秒未回复,重置流程
|
||
//else if (MyFlow.RunTime.AddSeconds(200) <= DateTime.Now)
|
||
//{
|
||
// MyFlow.RunStep = GengralProcessEnum.Start;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
//}
|
||
|
||
//测试结束,测试结果字符串不为空
|
||
if (!Testing && !string.IsNullOrEmpty(TestResultStr))
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
//200秒未回复,重置流程
|
||
else if (MyFlow.RunTime.AddSeconds(120) <= DateTime.Now)
|
||
{
|
||
Testing = false;
|
||
ExcepStop("测试超时,请重置流程");
|
||
MyFlow.RunStep = GengralProcessEnum.End;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step14:
|
||
#region 获取测试结果
|
||
if (TestFinish) //测试成功
|
||
{
|
||
if (TestResultStr != "NG") //测试机报错
|
||
{
|
||
string[] strList = TestResultStr.Split(';'); //分割结果
|
||
//找到TEST数组所在位置,寻找结果
|
||
int i = 0;
|
||
foreach (var item in strList)
|
||
{
|
||
if (item.Contains("TESTOK"))
|
||
{
|
||
break;
|
||
}
|
||
|
||
i++;
|
||
}
|
||
|
||
if (strList[i + 1] == "OK")
|
||
{
|
||
TestBenchBox[0].State.StatusBackground = ColorStr.Green;
|
||
}
|
||
else
|
||
{
|
||
TestBenchBox[0].State.StatusBackground = ColorStr.Green;
|
||
//TestBenchBox[0].State.StatusBackground = ColorStr.Red;
|
||
}
|
||
|
||
if (strList[i + 2] == "OK")
|
||
{
|
||
TestBenchBox[1].State.StatusBackground = ColorStr.Green;
|
||
}
|
||
else
|
||
{
|
||
TestBenchBox[1].State.StatusBackground = ColorStr.Green;
|
||
//TestBenchBox[1].State.StatusBackground = ColorStr.Red;
|
||
}
|
||
MyFlow.RunStep = MyFlow.RunStep = GengralProcessEnum.Start;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
Testing = false;
|
||
ExcepStop("测试机报错,请重置流程");
|
||
MyFlow.RunStep = GengralProcessEnum.End;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
TestBenchBox.ForEach(w => w.State.StatusBackground = ColorStr.Red);
|
||
MyFlow.RunStep = MyFlow.RunStep = GengralProcessEnum.Start;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
|
||
#endregion
|
||
|
||
break;
|
||
|
||
#region 打开气缸,已交由机械手流程
|
||
//case GengralProcessEnum.Step15:
|
||
// //测试结束
|
||
// if (TestBenchBox.Where(w => w.State.StatusBackground == ColorStr.Green || w.State.StatusBackground == ColorStr.Red).Count() >= 2)
|
||
// {
|
||
// //平台顶升气缸下降
|
||
// TestBenchBox[0].YDingShengQiGangDW.Switchs = false;
|
||
// TestBenchBox[0].YDingShengQiGangYW.Switchs = true;
|
||
|
||
// TestBenchBox[1].YDingShengQiGangDW.Switchs = false;
|
||
// TestBenchBox[1].YDingShengQiGangYW.Switchs = true;
|
||
// MyFlow.RunStep++;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
// }
|
||
// break;
|
||
//case GengralProcessEnum.Step16:
|
||
// //顶升原位
|
||
// if (TestBenchBox[0].XDingShengQigangYW.LightUp && TestBenchBox[1].XDingShengQigangYW.LightUp)
|
||
// {
|
||
// //顶升置位
|
||
// //平台顶升气缸下降
|
||
// TestBenchBox[0].YDingShengQiGangDW.Switchs = false;
|
||
// TestBenchBox[0].YDingShengQiGangYW.Switchs = false;
|
||
|
||
// TestBenchBox[1].YDingShengQiGangDW.Switchs = false;
|
||
// TestBenchBox[1].YDingShengQiGangYW.Switchs = false;
|
||
|
||
// //伸缩气缸原位
|
||
// TestBenchBox[0].YShenSuoQiGangDW.Switchs = false;
|
||
// TestBenchBox[0].YShenSuoQiGangYW.Switchs = true;
|
||
|
||
// TestBenchBox[1].YShenSuoQiGangDW.Switchs = false;
|
||
// TestBenchBox[1].YShenSuoQiGangYW.Switchs = true;
|
||
|
||
// MyFlow.RunStep++;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
// }
|
||
// else if (MyFlow.RunTime.AddSeconds(3) <= DateTime.Now)
|
||
// {
|
||
// ExcepStop(TestBenchBox[0].XDingShengQigangYW.InputMeaning + "\\" + TestBenchBox[1].XDingShengQigangYW.InputMeaning + "异常");
|
||
// //平台顶升气缸下降
|
||
// TestBenchBox[0].YDingShengQiGangDW.Switchs = false;
|
||
// TestBenchBox[0].YDingShengQiGangYW.Switchs = true;
|
||
|
||
// TestBenchBox[1].YDingShengQiGangDW.Switchs = false;
|
||
// TestBenchBox[1].YDingShengQiGangYW.Switchs = true;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
// }
|
||
// break;
|
||
//case GengralProcessEnum.Step17:
|
||
// //伸缩原位
|
||
// if (TestBenchBox[0].XShenSuoQigangYW.LightUp && TestBenchBox[1].XShenSuoQigangYW.LightUp)
|
||
// {
|
||
// //伸缩置位
|
||
// TestBenchBox[0].YDingShengQiGangDW.Switchs = false;
|
||
// TestBenchBox[0].YDingShengQiGangYW.Switchs = false;
|
||
|
||
// TestBenchBox[1].YDingShengQiGangDW.Switchs = false;
|
||
// TestBenchBox[1].YDingShengQiGangYW.Switchs = false;
|
||
|
||
|
||
// MyFlow.RunStep = GengralProcessEnum.Start;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
// }
|
||
// else if (MyFlow.RunTime.AddSeconds(3) <= DateTime.Now)
|
||
// {
|
||
// ExcepStop(TestBenchBox[0].XShenSuoQigangYW.InputMeaning + "\\" + TestBenchBox[1].XShenSuoQigangYW.InputMeaning + "异常");
|
||
// //伸缩气缸原位
|
||
// TestBenchBox[0].YShenSuoQiGangDW.Switchs = false;
|
||
// TestBenchBox[0].YShenSuoQiGangYW.Switchs = true;
|
||
|
||
// TestBenchBox[1].YShenSuoQiGangDW.Switchs = false;
|
||
// TestBenchBox[1].YShenSuoQiGangYW.Switchs = true;
|
||
// MyFlow.RunTime = DateTime.Now;
|
||
// }
|
||
// break;
|
||
#endregion
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region GRR模式
|
||
private bool gRRMode;
|
||
/// <summary>
|
||
/// GRR模式
|
||
/// </summary>
|
||
public bool GRRMode
|
||
{
|
||
get { return gRRMode; }
|
||
set { gRRMode = value; this.RaisePropertyChanged("GRRMode"); }
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 不良传送运行
|
||
/// <summary>
|
||
/// NG皮带运行信号
|
||
/// </summary>
|
||
public bool BadLineRun { get; set; }
|
||
|
||
DateTime BadLineRunTime { get; set; }
|
||
|
||
/// <summary>
|
||
/// 不良传送运行
|
||
/// </summary>
|
||
private void BadRun()
|
||
{
|
||
//NG满料检知
|
||
if (!InputList[I39NG皮带检知2].LightUp)
|
||
{
|
||
//不良运行信号
|
||
if (BadLineRun)
|
||
{
|
||
//NG皮带转1S
|
||
if (BadLineRunTime.AddMilliseconds(700) >= DateTime.Now)
|
||
{
|
||
OutputList[O29NG皮带控制].Switchs = true; //左ng皮带
|
||
}
|
||
else
|
||
{
|
||
BadLineRun = false;
|
||
OutputList[O29NG皮带控制].Switchs = false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
OutputList[O29NG皮带控制].Switchs = false;
|
||
BadLineRunTime = DateTime.Now;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ExcepStop("NG料满,请清料");
|
||
BadLineRunTime = DateTime.Now;
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 双控运行
|
||
/// <summary>
|
||
/// 光栅信号
|
||
/// </summary>
|
||
bool GratingSignal { get; set; }
|
||
|
||
/// <summary>
|
||
/// 载具是否已放行
|
||
/// </summary>
|
||
bool yifangxing { get; set; }
|
||
|
||
/// <summary>
|
||
/// 载具字符串
|
||
/// </summary>
|
||
public string SendVehicleStr { get; set; }
|
||
|
||
/// <summary>
|
||
/// 双控运行
|
||
/// </summary>
|
||
private void DualControlRun()
|
||
{
|
||
|
||
OutputList[O36机械手上下气缸1上位].Switchs = !OutputList[O37机械手上下气缸1下位].Switchs;
|
||
OutputList[O38机械手上下气缸2上位].Switchs = !OutputList[O39机械手上下气缸2下位].Switchs;
|
||
}
|
||
#endregion
|
||
|
||
#region 网络连接控制
|
||
/// <summary>
|
||
/// 网络连接控制
|
||
/// </summary>
|
||
private void ConnectNet()
|
||
{
|
||
while (true)
|
||
{
|
||
Thread.Sleep(100);
|
||
|
||
//连接下一站
|
||
if (NextStation != null)
|
||
{
|
||
if (!NextStation.ConnectSwitch)
|
||
{
|
||
NextStation.ConnectSwitch = true;
|
||
}
|
||
else if (NextStation.Showmsg.StatusBackground != ColorStr.Green)
|
||
{
|
||
NextStation.ConnectSwitch = false;
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 测试机连接对象
|
||
private CommunicationManagementClass testMachine;
|
||
/// <summary>
|
||
/// 测试机连接对象
|
||
/// </summary>
|
||
public CommunicationManagementClass TestMachine
|
||
{
|
||
get { return testMachine; }
|
||
set { testMachine = value; this.RaisePropertyChanged("TestMachine"); }
|
||
}
|
||
|
||
|
||
string TestRecStr { get; set; }
|
||
|
||
/// <summary>
|
||
/// 测试成功信号,测试机回复
|
||
/// </summary>
|
||
bool TestFinish { get; set; }
|
||
int QUERY = 0;
|
||
/// <summary>
|
||
/// 测试机回调函数
|
||
/// </summary>
|
||
/// <param name="str"></param>
|
||
private void TestMachine_ReceiveCallback(string str)
|
||
{
|
||
if (!String.IsNullOrEmpty(str))
|
||
{
|
||
if (str.Contains("TESTOK"))
|
||
{
|
||
QUERY = 0;
|
||
var real = str.Replace("QUERY?", "");
|
||
TestRecStr = real;
|
||
TestResultStr = real;
|
||
|
||
}
|
||
|
||
else if (str.Contains("LOAD"))
|
||
{
|
||
QUERY = 0;
|
||
var real = str.Replace("QUERY?", "");
|
||
real = real.Replace("QUERY?", "");
|
||
TestRecStr = real;
|
||
|
||
}
|
||
else if (str.Contains("ALARM"))
|
||
{
|
||
QUERY = 0;
|
||
TestRecStr = str;
|
||
|
||
}
|
||
else if (str.Contains("QUERY"))
|
||
{
|
||
if (RunStatu == RunStatuEnum.Normal)
|
||
{
|
||
QUERY++;
|
||
if (QUERY > 20)
|
||
{
|
||
QUERY = 0;
|
||
|
||
TestRecStr = str;
|
||
|
||
}
|
||
}
|
||
else
|
||
{
|
||
|
||
QUERY = 0;
|
||
}
|
||
|
||
}
|
||
}
|
||
//测试中,获取测试结果
|
||
if (Testing)
|
||
{
|
||
if (TestRecStr.Contains("TESTOK"))
|
||
{
|
||
Testing = false; //测试结束
|
||
TestFinish = true; //测试完成信号
|
||
}
|
||
else if (TestRecStr.Contains("ALARM")) //测试机回复报错
|
||
{
|
||
TestResultStr = "NG";
|
||
Testing = false; //测试结束
|
||
TestFinish = true; //测试完成信号
|
||
}
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 上一站连接
|
||
/// <summary>
|
||
/// 上一站连接
|
||
/// </summary>
|
||
public CommunicationManagementClass FrontStation { get; set; }
|
||
#endregion
|
||
|
||
#region 下一站连接
|
||
/// <summary>
|
||
/// 下一站连接
|
||
/// </summary>
|
||
public CommunicationManagementClass NextStation { get; set; }
|
||
#endregion
|
||
|
||
#region 发送消息给下一站
|
||
|
||
/// <summary>
|
||
/// 发送载具状态的字符串
|
||
/// </summary>
|
||
|
||
DateTime SendNextStationTime { get; set; }
|
||
/// <summary>
|
||
/// 发送消息给下一站
|
||
/// </summary>
|
||
private void SendNextStation()
|
||
{
|
||
if (SendNextStationTime.AddMilliseconds(100) < DateTime.Now)
|
||
{
|
||
if (NextStation.Showmsg.StatusBackground == ColorStr.Green)
|
||
{
|
||
var sendStr = ShareHelp.ObjToJson(NextStationSend);
|
||
NextStation.SendInfo(sendStr);
|
||
}
|
||
else
|
||
{
|
||
|
||
NextStation.ConnectSwitch = !NextStation.ConnectSwitch;
|
||
}
|
||
SendNextStationTime = DateTime.Now;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 发送信息给上一站
|
||
|
||
DateTime SendFrontStationTime { get; set; }
|
||
/// <summary>
|
||
/// 发送信息给上一站
|
||
/// </summary>
|
||
/// <param name="CommandStr"></param>
|
||
private void SendFrontStation()
|
||
{
|
||
if (SendFrontStationTime.AddMilliseconds(100) < DateTime.Now)
|
||
{
|
||
if (FrontStation.Showmsg.StatusBackground == ColorStr.Green)
|
||
{
|
||
var sendStr = ShareHelp.ObjToJson(FrontStationSend);
|
||
FrontStation.SendInfo(sendStr);
|
||
}
|
||
else
|
||
{
|
||
|
||
FrontStation.ConnectSwitch = !FrontStation.ConnectSwitch;
|
||
}
|
||
|
||
SendFrontStationTime = DateTime.Now;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 前站消息
|
||
/// <summary>
|
||
/// 从后站收到的消息
|
||
/// </summary>
|
||
StationMessage _FrontStationReceive = new StationMessage();
|
||
/// <summary>
|
||
/// 从前站收到的消息
|
||
/// </summary>
|
||
StationMessage FrontStationReceive
|
||
{
|
||
get
|
||
{
|
||
return _FrontStationReceive;
|
||
}
|
||
set
|
||
{
|
||
if (value != null)
|
||
{
|
||
_FrontStationReceive = value;
|
||
}
|
||
else
|
||
{
|
||
_FrontStationReceive.Safe = false;
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 发送给前站的消息
|
||
/// </summary>
|
||
StationMessage FrontStationSend = new StationMessage();
|
||
|
||
/// <summary>
|
||
/// 前站回调函数
|
||
/// </summary>
|
||
/// <param name="str"></param>
|
||
private void FrontStation_ReceiveCallback(string str)
|
||
{
|
||
try
|
||
{
|
||
FrontStationReceive = ShareHelp.JsonToObj<StationMessage>(str);
|
||
|
||
}
|
||
catch (Exception)
|
||
{
|
||
FrontStationReceive = new StationMessage();
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
|
||
#endregion
|
||
|
||
#region 4、加载功能界面
|
||
/// <summary>
|
||
/// 加载功能界面
|
||
/// </summary>
|
||
private void LoadingFunctionInterface()
|
||
{
|
||
TabItemList = new ObservableCollection<TabItem>();
|
||
|
||
//先加载一个视觉运行预览界面
|
||
//Views.Vision.AOI2 aoi2 = new Views.Vision.AOI2();
|
||
//TabItem tabiyu = new TabItem() { Content = aoi2 };
|
||
////tabiyu.SetResourceReference(TabItem.HeaderProperty, "视觉预览"); //设定资源引用 即可进行语言的切换
|
||
//tabiyu.Header = "视觉预览";
|
||
//TabItemList.Add(tabiyu);
|
||
|
||
//添加主页界面
|
||
MainInterface mi = new MainInterface();
|
||
TabItem tabmi = new TabItem() { Content = mi, Tag = "V" };
|
||
tabmi.Header = "主界面";
|
||
TabItemList.Add(tabmi);
|
||
|
||
if (SystemPar.VisionBool)
|
||
{
|
||
List<FeiYuCamere> Camlist = Vdal.GetCameraList();
|
||
HVlist = new List<HalconVisual>();
|
||
|
||
foreach (FeiYuCamere cam in Camlist)
|
||
{
|
||
HalconVisual hv = new HalconVisual(CurrentMachine, LightCOM, cam);
|
||
HVlist.Add(hv);
|
||
TabItem tabi = new TabItem() { Content = hv.MyWindow, Tag = "v" };
|
||
//tabi.SetResourceReference(TabItem.HeaderProperty, cam.VisualName); //设定资源引用 即可进行语言的切换
|
||
tabi.Header = cam.VisualName;
|
||
tabi.SetBinding(TabItem.VisibilityProperty, new Binding("AllVis"));
|
||
TabItemList.Add(tabi);
|
||
}
|
||
VisualA = HVlist[0];
|
||
VisualB = HVlist[1];
|
||
//VisualC = HVlist[2];
|
||
//VisualD = HVlist[3];
|
||
}
|
||
|
||
if (SystemPar.MotionControlBool)
|
||
{
|
||
MCVM = new MotionControlVM(CurrentMachine, InputList, OutputList);
|
||
MCVM.eventExcepReport += ExcepStop;
|
||
TabItem tbai = new TabItem() { Content = MCVM.MyWindow };
|
||
// tbai.SetResourceReference(TabItem.HeaderProperty, "运动控制"); //设定资源引用 即可进行语言的切换
|
||
tbai.Header = "运动控制";
|
||
tbai.SetBinding(TabItem.VisibilityProperty, new Binding("AllVis"));
|
||
TabItemList.Add(tbai);
|
||
}
|
||
|
||
if (SystemPar.RobotBool)
|
||
{
|
||
switch (SystemPar.RobotBrand)
|
||
{
|
||
case 0:
|
||
Robot = new EpsonRobotVM(CurrentMachine);//初始化爱普生机器人
|
||
break;
|
||
case 1:
|
||
Robot = new FanucRobotVM(CurrentMachine);//初始化发那科机器人
|
||
break;
|
||
case 2:
|
||
Robot = new QkmRobotVM(CurrentMachine);//初始化李群机器人
|
||
break;
|
||
case 3:
|
||
Robot = new TurinRobotVM(CurrentMachine);//图灵机器人
|
||
break;
|
||
case 4:
|
||
Robot = new YamahaRobotVM(CurrentMachine);//雅马哈
|
||
break;
|
||
case 5:
|
||
Robot = new InoRobotVM(CurrentMachine, CurrHsl); //汇川机器人
|
||
break;
|
||
}
|
||
|
||
Robot.eventExcepReport += ExcepStop;
|
||
Robot.ShuaxinPointing += Robot_ShuaxinPointing;
|
||
TabItem tbai = new TabItem() { Content = Robot.MyWindow };
|
||
//tbai.SetResourceReference(TabItem.HeaderProperty, "机器人"); //设定资源引用 即可进行语言的切换
|
||
tbai.Header = "机器人";
|
||
tbai.SetBinding(TabItem.VisibilityProperty, new Binding("AllVis"));
|
||
TabItemList.Add(tbai);
|
||
}
|
||
|
||
TabItem ti = new TabItem() { Content = new ParameterSetting(ServerComm.CommList) };
|
||
// ti.SetResourceReference(TabItem.HeaderProperty, "参数设置"); //设定资源引用 即可进行语言的切换
|
||
ti.Header = "参数设置";
|
||
ti.SetBinding(TabItem.VisibilityProperty, new Binding("AllVis"));
|
||
TabItemList.Add(ti);
|
||
|
||
TabItem t2 = new TabItem() { Content = new LogInformation() };
|
||
//t2.SetResourceReference(TabItem.HeaderProperty, "日志信息"); //设定资源引用 即可进行语言的切换
|
||
t2.Header = "日志信息";
|
||
TabItemList.Add(t2);
|
||
|
||
SelectTabItem = TabItemList[0];
|
||
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
#region 刷新机械手阵列点位
|
||
/// <summary>
|
||
/// 刷新机械手阵列点位
|
||
/// </summary>
|
||
/// <param name="hv"></param>
|
||
private void Robot_ShuaxinPointing(int type)
|
||
{
|
||
try
|
||
{
|
||
switch (type)
|
||
{
|
||
case 0:
|
||
Tray1.PointListInitialization();
|
||
break;
|
||
//case 2:
|
||
// Tray2.PointListInitialization();
|
||
// break;
|
||
//case 3:
|
||
// Tray3.PointListInitialization();
|
||
// break;
|
||
//case 4:
|
||
// Tray4.PointListInitialization();
|
||
// break;
|
||
//case 5:
|
||
// Tray5.PointListInitialization();
|
||
// break;
|
||
//case 6:
|
||
// Tray6.PointListInitialization();
|
||
// break;
|
||
//case 7:
|
||
// Tray7.PointListInitialization();
|
||
// break;
|
||
//case 8:
|
||
// Tray8.PointListInitialization();
|
||
// break;
|
||
|
||
}
|
||
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 验证是否超时
|
||
/// <summary>
|
||
/// 验证是否超时
|
||
/// </summary>
|
||
/// <param name="tiem">起点时间</param>
|
||
/// <param name="timeLimit">时限(毫秒)</param>
|
||
/// <param name="showMsg">报错信息</param>
|
||
private bool TimeOutValidation(DateTime tiem, int timeLimit, string showMsg)
|
||
{
|
||
if (tiem.AddMilliseconds(timeLimit) < DateTime.Now)
|
||
{
|
||
ExcepStop(showMsg);
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 异常停止 +ExcepStop(string showMag)
|
||
/// <summary>
|
||
/// 异常停止
|
||
/// </summary>
|
||
/// <param name="showMag"></param>
|
||
public void ExcepStop(string showMag)
|
||
{
|
||
if (RunStatu != RunStatuEnum.Stop && RunStatu != RunStatuEnum.EmgStop && RunStatu != RunStatuEnum.Exceptional)
|
||
{
|
||
if (RunStatu == RunStatuEnum.Normal)
|
||
{
|
||
if (MCVM != null)
|
||
{
|
||
foreach (FeiYuShaft sf in MCVM.AllShaftList)
|
||
{
|
||
sf.ShaftStop();
|
||
}
|
||
}
|
||
}
|
||
|
||
RunStatu = RunStatuEnum.Exceptional;
|
||
ShowStatu.StatuInfo = showMag;
|
||
|
||
//记录异常信息
|
||
try
|
||
{
|
||
RecordLog(showMag);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.ToString());
|
||
}
|
||
//皮带
|
||
OutputList[17].Switchs = false;//正转
|
||
OutputList[18].Switchs = false;//反转
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 异常不停机(无痛报警)
|
||
/// <summary>
|
||
/// 不停机报警中
|
||
/// </summary>
|
||
bool ExcepNoIng { get; set; }
|
||
/// <summary>
|
||
/// 异常不停机(无痛报警)
|
||
/// </summary>
|
||
public void ExcepNoStop(string showMag)
|
||
{
|
||
try
|
||
{
|
||
//if (ExcepNoIng)
|
||
//{
|
||
// return;
|
||
//}
|
||
|
||
ShowStatu.StatusBackground = ColorStr.Yellow;
|
||
ShowStatu.StatusForeground = ColorStr.Red;
|
||
|
||
ShowStatu.StatuInfo = showMag;
|
||
|
||
// OutputList[0].Switchs = true; //红灯
|
||
OutputList[1].Switchs = true; //黄灯
|
||
//OutputList[2].Switchs = true; //绿灯
|
||
OutputList[3].Switchs = true; //蜂鸣器
|
||
|
||
//记录异常信息
|
||
try
|
||
{
|
||
RecordLog(showMag);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.ToString());
|
||
}
|
||
|
||
ExcepNoIng = true;
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 启动按钮 +void Start(object per)
|
||
/// <summary>
|
||
/// 启动按钮
|
||
/// </summary>
|
||
/// <param name="per"></param>
|
||
public void Start(object per)
|
||
{
|
||
if (GoHomeSteps != GengralProcessEnum.End)
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (RunStatu != RunStatuEnum.Stop && RunStatu != RunStatuEnum.Prepareations)
|
||
{
|
||
return;
|
||
}
|
||
try
|
||
{
|
||
|
||
if (ThRun == null && RunStatu != RunStatuEnum.Prepare)
|
||
{
|
||
RunStatu = RunStatuEnum.Normal;
|
||
ThRun = new Thread(Run);
|
||
ThRun.IsBackground = true;
|
||
ThRun.Start();
|
||
}
|
||
else if (RunStatu != RunStatuEnum.Normal && RunStatu != RunStatuEnum.Prepare)
|
||
{
|
||
RunStatu = RunStatuEnum.Normal;
|
||
RecordLog("开始运行");
|
||
}
|
||
|
||
TakeFlow.RunTime = DateTime.Now;
|
||
DownVisionFlow.RunTime = DateTime.Now;
|
||
BoxInPutFlow.RunTime = DateTime.Now;
|
||
|
||
|
||
|
||
}
|
||
catch (Exception)
|
||
{
|
||
MessageBox.Show("开启运行线程失败,请联系系统管理员或重启软件稍后重试");
|
||
return;
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 停止按钮 void Stop(object per)
|
||
/// <summary>
|
||
/// 停止工作
|
||
/// </summary>
|
||
/// <param name="per"></param>
|
||
public void Stop(object per)
|
||
{
|
||
|
||
if (RunStatu != RunStatuEnum.Stop)
|
||
{
|
||
RunStatu = RunStatuEnum.Stop;
|
||
RecordLog("停止运行");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 重启按钮 +void ResetSoft(object obj)
|
||
/// <summary>
|
||
/// 重启按钮
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void ResetSoft(object obj)
|
||
{
|
||
if (RunStatu == RunStatuEnum.Normal)
|
||
{
|
||
MessageBox.Show("机器运行中,无法重启");
|
||
return;
|
||
}
|
||
//如果运行线程还在运行
|
||
if (ThRun != null)
|
||
{
|
||
ThRun.Abort();
|
||
ThRun = null;
|
||
}
|
||
|
||
MessageBoxResult res = MessageBox.Show("你确定要重新启动软件吗?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Asterisk);
|
||
if (res == MessageBoxResult.Yes)
|
||
{
|
||
ResetALL(); //重置所有参数
|
||
RecordLog("重新开始");
|
||
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 重置所有
|
||
/// </summary>
|
||
private void ResetALL()
|
||
{
|
||
foreach (OutputSignal os in OutputList)
|
||
{
|
||
os.Switchs = false;
|
||
}
|
||
|
||
AllVis = Visibility.Collapsed;
|
||
ShowStatu = new ShowInfo();
|
||
RunStatu = RunStatuEnum.Prepare;
|
||
|
||
ExcepList = new ObservableCollection<RecordInfo>();
|
||
|
||
|
||
if (Robot != null)
|
||
{
|
||
Robot.HomeStep = GengralProcessEnum.Start;
|
||
}
|
||
if (MCVM != null)
|
||
{
|
||
foreach (var item in MCVM.AllShaftList)
|
||
{
|
||
item.ShaftStop();
|
||
item.HomeStep = GengralProcessEnum.Start;
|
||
item.org_Successful = false;
|
||
}
|
||
}
|
||
GoHomeSteps = GengralProcessEnum.Start;
|
||
GratingSignal = false;
|
||
|
||
LogicDispatchFlow = new FlowModel("大总管");
|
||
TakeFlow = new FlowModel("取料");
|
||
DownVisionFlow = new FlowModel("测试盒取出");
|
||
BoxInPutFlow = new FlowModel("测试盒投入");
|
||
CarryPutOutFlow = new FlowModel("机台搬运");
|
||
OKLineFlow = new FlowModel("良品皮带运行");
|
||
TestBoxFlow = new FlowModel("测试平台运行");
|
||
PassLineFlow = new FlowModel("过站皮带运行");
|
||
TestFinish = false;
|
||
Testing = false;
|
||
|
||
//MyVehicleBox.ForEach(w => w.State.StatusBackground = ColorStr.White);
|
||
|
||
//重置吸嘴状态
|
||
if (XizuiLabelPaperList != null)
|
||
{
|
||
foreach (var item in XizuiLabelPaperList)
|
||
{
|
||
item.VacuumSwitch.Switchs = false;//关闭真空
|
||
item.State.StatusBackground = ColorStr.White;
|
||
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 紧急停止按钮 +void EmgStop()
|
||
/// <summary>
|
||
/// 紧急停止工作
|
||
/// </summary>
|
||
public void EmgStop()
|
||
{
|
||
if (RunStatu != RunStatuEnum.EmgStop)
|
||
{
|
||
if (ThRun != null) //停止线程
|
||
{
|
||
ThRun.Abort();
|
||
ThRun = null;
|
||
}
|
||
if (MCVM != null)
|
||
{
|
||
foreach (FeiYuShaft sf in MCVM.AllShaftList)
|
||
{
|
||
sf.ShaftStop();
|
||
}
|
||
}
|
||
RunStatu = RunStatuEnum.EmgStop;
|
||
RecordLog("紧急停止");
|
||
//皮带
|
||
|
||
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 关闭程序按钮
|
||
|
||
/// <summary>
|
||
/// 关闭程序确认的返回值
|
||
/// </summary>
|
||
public MessageDialogResult CloseRes { get; set; }
|
||
|
||
/// <summary>
|
||
/// 关闭程序按钮
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
public void Close(object obj)
|
||
{
|
||
if (RunStatu == RunStatuEnum.Normal)
|
||
{
|
||
MyMessageBox.Show("设备运行中无法退出,请先停止运行");
|
||
return;
|
||
}
|
||
|
||
|
||
Tray1.GetTrayState(CurrentMachine);
|
||
|
||
dal.UpdateProductionData(CurrentMachine); //更新生产数据
|
||
dal.UpdateMachineData(CurrentMachine);
|
||
dal.UpdateSystemPar(SystemPar);
|
||
dal.UpdateRobotModel(Robot.RobotPer);
|
||
|
||
CloseRes = MyMessageBox.Show("你确定要退出吗?", "提示", MessageDialogStyle.AffirmativeAndNegative);
|
||
|
||
|
||
if (CloseRes == MessageDialogResult.Negative)
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (ThRun != null)
|
||
{
|
||
ThRun.Abort();
|
||
ThRun = null;
|
||
}
|
||
|
||
if (ThStateMonitoring != null)
|
||
{
|
||
ThStateMonitoring.Abort();
|
||
ThStateMonitoring = null;
|
||
}
|
||
|
||
foreach (OutputSignal o in OutputList)
|
||
{
|
||
o.Switchs = false;
|
||
}
|
||
|
||
//关闭相机
|
||
if (VisualA != null)
|
||
{
|
||
VisualA.CamReset(0);
|
||
}
|
||
if (VisualB != null)
|
||
{
|
||
VisualB.CamReset(0);
|
||
}
|
||
|
||
if (MCVM != null)
|
||
{
|
||
foreach (FeiYuCard cd in MCVM.CardList)
|
||
{
|
||
cd.MoveFunction_Estop();
|
||
}
|
||
|
||
}
|
||
|
||
System.Environment.Exit(0);
|
||
}
|
||
#endregion
|
||
|
||
#region 切换系统语言
|
||
/// <summary>
|
||
/// 切换系统语言
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void SwitchLanguage(object obj)
|
||
{
|
||
|
||
if (obj != null)
|
||
{
|
||
//在APP.xaml中第四个引用是语言字典资源
|
||
Application.Current.Resources.MergedDictionaries[4].Source = new Uri(@"./Language/" + SystemPar.SystemLanguage, UriKind.RelativeOrAbsolute); //切换语言
|
||
}
|
||
else
|
||
{
|
||
if (SystemPar.SystemLanguage == "zh-cn.xaml")
|
||
{
|
||
Application.Current.Resources.MergedDictionaries[4].Source = new Uri(@"./Language/en-us.xaml", UriKind.RelativeOrAbsolute);
|
||
SystemPar.SystemLanguage = "en-us.xaml";
|
||
}
|
||
else if (SystemPar.SystemLanguage == "en-us.xaml")
|
||
{
|
||
Application.Current.Resources.MergedDictionaries[4].Source = new Uri(@"./Language/zh-cn.xaml", UriKind.RelativeOrAbsolute);
|
||
SystemPar.SystemLanguage = "zh-cn.xaml";
|
||
}
|
||
|
||
//机器状态描述语言切换
|
||
ShowStatu.StatuInfo = ShowStatu.StatuInfoTemp;
|
||
|
||
//权限按钮语言切换
|
||
PermissionButtonName = Application.Current.Resources[AllVis == Visibility.Collapsed ? "编辑模式" : "普通模式"].ToString();
|
||
|
||
if (MCVM != null)
|
||
{
|
||
foreach (FeiYuShaft df in MCVM.AllShaftList)
|
||
{
|
||
df.ShaftState.StatuInfo = df.ShaftState.StatuInfoTemp;
|
||
}
|
||
}
|
||
|
||
//输入信号语言切换
|
||
if (InputList != null && InputList.Count > 0)
|
||
{
|
||
InputGrid = GetInputGrid();
|
||
}
|
||
//输出信号语言切换
|
||
if (OutputList != null && OutputList.Count > 0)
|
||
{
|
||
OutputGrid = GetOutputGrid();
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 利用反射进行对象复制
|
||
/// <summary>
|
||
/// 利用反射进行对象复制
|
||
/// </summary>
|
||
/// <typeparam name="InsertRunPar">复制对象类型</typeparam>
|
||
/// <param name="startPoint">被复制对象</param>
|
||
/// <returns></returns>
|
||
public RobotPoint Coper(RobotPoint startPoint)
|
||
{
|
||
RobotPoint irpa = new RobotPoint();
|
||
try
|
||
{
|
||
var Types = startPoint.GetType();//获得类型
|
||
var Typed = irpa.GetType();
|
||
foreach (PropertyInfo sp in Types.GetProperties())//获得类型的属性字段
|
||
{
|
||
foreach (PropertyInfo dp in Typed.GetProperties())
|
||
{
|
||
if (dp.Name == sp.Name)//判断属性名是否相同
|
||
{
|
||
dp.SetValue(irpa, sp.GetValue(startPoint, null), null);//获得s对象属性的值复制给d对象的属性
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
|
||
return irpa;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 利用反射进行对象复制
|
||
/// </summary>
|
||
/// <typeparam name="T"></typeparam>
|
||
/// <param name="Coperobj"></param>
|
||
/// <returns></returns>
|
||
public T Coper<T>(T Coperobj)
|
||
{
|
||
T a = System.Activator.CreateInstance<T>();
|
||
try
|
||
{
|
||
var Types = Coperobj.GetType();//获得类型
|
||
var Typed = a.GetType();
|
||
foreach (PropertyInfo sp in Types.GetProperties())//获得类型的属性字段
|
||
{
|
||
foreach (PropertyInfo dp in Typed.GetProperties())
|
||
{
|
||
if (dp.Name == sp.Name)//判断属性名是否相同
|
||
{
|
||
dp.SetValue(a, sp.GetValue(Coperobj, null), null);//获得s对象属性的值复制给d对象的属性
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
|
||
return a;
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 记录日志信息
|
||
byte[] data { get; set; }
|
||
|
||
/// <summary>
|
||
/// 文件夹路径
|
||
/// </summary>
|
||
string path { get; set; }
|
||
/// <summary>
|
||
/// 文件路径
|
||
/// </summary>
|
||
string paths { get; set; }
|
||
/// <summary>
|
||
/// 记录信息对象
|
||
/// </summary>
|
||
RecordInfo info { get; set; }
|
||
/// <summary>
|
||
/// 打开的文件流对象
|
||
/// </summary>
|
||
FileStream FS { get; set; }
|
||
|
||
/// <summary>
|
||
/// 对应的窗体对象
|
||
/// </summary>
|
||
Window Mywindow { get; set; }
|
||
|
||
/// <summary>
|
||
/// 这里需要用到异步新增项
|
||
/// </summary>
|
||
Dispatcher MyDispatcher { get; set; }
|
||
|
||
/// <summary>
|
||
/// 记录日志信息到文件
|
||
/// </summary>
|
||
/// <param name="info"></param>
|
||
private void RecordLog(string showMag)
|
||
{
|
||
lock (this)
|
||
{
|
||
info = new RecordInfo() { Number = ExcepList.Count() + 1, HappenTime = DateTime.Now, Describe = showMag };
|
||
//异步新增项 这是微软的BUG 只能这么麻烦了
|
||
MyDispatcher.BeginInvoke(DispatcherPriority.Background, new ParameterizedThreadStart(AddItem), info);
|
||
|
||
path = @"D:\\SystemLog"; //文件夹路径
|
||
|
||
paths = @"D:\\SystemLog\" + DateTime.Now.ToString("D") + ".txt"; //文件路径 以年月日为名称
|
||
|
||
//创建文件夹
|
||
if (!Directory.Exists(path))
|
||
{
|
||
Directory.CreateDirectory(path);
|
||
}
|
||
|
||
//打开或创建文件
|
||
FS = File.Open(paths, FileMode.Append);
|
||
|
||
//获得字节数组
|
||
|
||
data = System.Text.Encoding.Default.GetBytes(info.Number + "-" + info.HappenTime + "-" + info.Describe + "\r\n");
|
||
//开始写入
|
||
FS.Write(data, 0, data.Length);
|
||
//清空缓冲区、关闭流
|
||
FS.Flush();
|
||
FS.Close();
|
||
}
|
||
|
||
}
|
||
void AddItem(object info)
|
||
{
|
||
ExcepList.Add((RecordInfo)info);
|
||
}
|
||
|
||
void DelItem(object info)
|
||
{
|
||
|
||
ExcepList.Clear();
|
||
RaisePropertyChanged("ExcepList");
|
||
|
||
}
|
||
/// <summary>
|
||
/// 记录检查平结果LOG
|
||
/// </summary>
|
||
/// <param name="CM"></param>
|
||
private void WarpageLog(string sn, ShowInfo res, string notes)
|
||
{
|
||
lock (this)
|
||
{
|
||
path = @"D:\\WarpageLog\";
|
||
paths = @"D:\\WarpageLog\" + DateTime.Now.ToString("D") + ".CSV";
|
||
|
||
//实例化字符串流
|
||
StringBuilder sb = new StringBuilder();
|
||
//创建文件夹
|
||
if (!Directory.Exists(path))
|
||
{
|
||
Directory.CreateDirectory(path);
|
||
}
|
||
//创建文件
|
||
if (!File.Exists(paths))
|
||
{
|
||
//sb.Append("判定标准:,大于," + CurrentMachine.CoplanarMinValue + ",小于" + CurrentMachine.CoplanarMmxValue + "\r");
|
||
sb.Append("时间,SN码,共面度,判定结果,说明\r");
|
||
}
|
||
|
||
using (FileStream fs = new FileStream(paths, FileMode.Append))
|
||
{
|
||
using (StreamWriter sw = new StreamWriter(fs, UnicodeEncoding.GetEncoding("GB2312"))) //UnicodeEncoding.GetEncoding("GB2312")
|
||
{
|
||
sb.Append(DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss.fff")).Append(",").Append(sn).Append(",").Append(res.StatuValue).Append(",").Append(res.StatuInfo).Append(",").Append(notes).Append(",");
|
||
//将字符串流数据写入文件
|
||
sw.WriteLine(sb);
|
||
//刷新文件流
|
||
sw.Flush();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 吸嘴对象
|
||
private Grid xizuiLabelGrid;
|
||
/// <summary>
|
||
/// 吸嘴Grid
|
||
/// </summary>
|
||
public Grid XizuiLabelGrid
|
||
{
|
||
get { return xizuiLabelGrid; }
|
||
set { xizuiLabelGrid = value; RaisePropertyChanged("XizuiLabelGrid"); }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 吸嘴对象集合
|
||
/// </summary>
|
||
public List<HandModel> XizuiLabelPaperList { get; set; }
|
||
/// <summary>
|
||
/// 获取吸嘴Grid
|
||
/// </summary>
|
||
public void GetXizuiLabelGrid()
|
||
{
|
||
XizuiLabelPaperList = new List<HandModel>();
|
||
|
||
Grid gd = new Grid();
|
||
for (int i = 0; i < 2; i++)
|
||
{
|
||
gd.ColumnDefinitions.Add(new ColumnDefinition()); //添加列
|
||
HandModel sm = new HandModel() { Number = i + 1, State = new ShowInfo() { StatuInfo = (i + 1).ToString() } };
|
||
gd.Children.Add(sm.Labels);
|
||
sm.Labels.SetValue(Grid.RowProperty, 0); //设置按钮所在Grid控件的行
|
||
sm.Labels.SetValue(Grid.ColumnProperty, i); //设置按钮所在Grid控件的列
|
||
XizuiLabelPaperList.Add(sm);
|
||
}
|
||
|
||
//吸嘴吸真空
|
||
XizuiLabelPaperList[0].VacuumSwitch = OutputList[32];
|
||
XizuiLabelPaperList[0].VacuumPoSwitch = OutputList[33];
|
||
XizuiLabelPaperList[0].VacuumCheck = InputList[32];
|
||
|
||
XizuiLabelPaperList[1].VacuumSwitch = OutputList[34];
|
||
XizuiLabelPaperList[1].VacuumPoSwitch = OutputList[35];
|
||
XizuiLabelPaperList[1].VacuumCheck = InputList[33];
|
||
|
||
//吸嘴气缸
|
||
XizuiLabelPaperList[0].QiGang = OutputList[37];
|
||
XizuiLabelPaperList[0].QiGangUp = InputList[34];
|
||
XizuiLabelPaperList[0].QiGangDown = InputList[35];
|
||
|
||
XizuiLabelPaperList[1].QiGang = OutputList[39];
|
||
XizuiLabelPaperList[1].QiGangUp = InputList[36];
|
||
XizuiLabelPaperList[1].QiGangDown = InputList[37];
|
||
|
||
XizuiLabelGrid = gd;
|
||
}
|
||
#endregion
|
||
|
||
#region 测试平台初始化
|
||
private Grid testBenchGrid;
|
||
/// <summary>
|
||
/// 测试平台Grid
|
||
/// </summary>
|
||
public Grid TestBenchGrid
|
||
{
|
||
get { return testBenchGrid; }
|
||
set { testBenchGrid = value; this.RaisePropertyChanged("TestBenchGrid"); }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 测试平台集合
|
||
/// </summary>
|
||
public List<HandModel> TestBenchBox { get; set; }
|
||
|
||
/// <summary>
|
||
/// 测试平台Grid
|
||
/// </summary>
|
||
public void GetTestBenchGrid()
|
||
{
|
||
TestBenchBox = new List<HandModel>();
|
||
|
||
Grid gd = new Grid();
|
||
for (int i = 0; i < 2; i++)
|
||
{
|
||
gd.ColumnDefinitions.Add(new ColumnDefinition()); //添加列
|
||
HandModel sm = new HandModel() { Number = i + 1, State = new ShowInfo() { StatuInfo = (i + 1).ToString() } };
|
||
gd.Children.Add(sm.Labels);
|
||
sm.Labels.SetValue(Grid.RowProperty, 0); //设置按钮所在Grid控件的行
|
||
sm.Labels.SetValue(Grid.ColumnProperty, i); //设置按钮所在Grid控件的列
|
||
TestBenchBox.Add(sm);
|
||
}
|
||
TestBenchGrid = gd;
|
||
|
||
//分配载具放料点
|
||
TestBenchBox[0].PutProPoint1 = Robot.RobotPointList.Where(w => w.PointType == 5).FirstOrDefault();
|
||
TestBenchBox[0].TakeProPoint1 = Robot.RobotPointList.Where(w => w.PointType == 4).FirstOrDefault();
|
||
TestBenchBox[1].PutProPoint1 = Robot.RobotPointList.Where(w => w.PointType == 7).FirstOrDefault();
|
||
TestBenchBox[1].TakeProPoint1 = Robot.RobotPointList.Where(w => w.PointType == 6).FirstOrDefault();
|
||
|
||
//平台顶升气缸
|
||
TestBenchBox[0].YDingShengQiGangYW = OutputList[18];
|
||
TestBenchBox[0].YDingShengQiGangDW = OutputList[19];
|
||
TestBenchBox[0].XDingShengQigangYW = InputList[18];
|
||
TestBenchBox[0].XDingShengQigangDW = InputList[19];
|
||
TestBenchBox[1].YDingShengQiGangYW = OutputList[24];
|
||
TestBenchBox[1].YDingShengQiGangDW = OutputList[25];
|
||
TestBenchBox[1].XDingShengQigangYW = InputList[24];
|
||
TestBenchBox[1].XDingShengQigangDW = InputList[25];
|
||
|
||
//平台伸缩气缸
|
||
TestBenchBox[0].YShenSuoQiGangYW = OutputList[16];
|
||
TestBenchBox[0].YShenSuoQiGangDW = OutputList[17];
|
||
TestBenchBox[0].XShenSuoQigangYW = InputList[16];
|
||
TestBenchBox[0].XShenSuoQigangDW = InputList[17];
|
||
TestBenchBox[1].YShenSuoQiGangYW = OutputList[22];
|
||
TestBenchBox[1].YShenSuoQiGangDW = OutputList[23];
|
||
TestBenchBox[1].XShenSuoQigangYW = InputList[22];
|
||
TestBenchBox[1].XShenSuoQigangDW = InputList[23];
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 流线对象
|
||
#region 缓存流线对象
|
||
private Grid cacheLineGrid;
|
||
/// <summary>
|
||
/// 缓存流线对象
|
||
/// </summary>
|
||
public Grid CacheLineGrid
|
||
{
|
||
get { return cacheLineGrid; }
|
||
set { cacheLineGrid = value; this.RaisePropertyChanged("CacheLineGrid"); }
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 缓存流线对象集合
|
||
/// </summary>
|
||
public List<HandModel> CacheLineList { get; set; }
|
||
|
||
/// <summary>
|
||
/// 获取缓存流线Grid
|
||
/// </summary>
|
||
public void GetCacheLineGrid()
|
||
{
|
||
CacheLineList = new List<HandModel>();
|
||
|
||
Grid gd = new Grid();
|
||
for (int i = 0; i < 1; i++)
|
||
{
|
||
gd.ColumnDefinitions.Add(new ColumnDefinition()); //添加列
|
||
HandModel sm = new HandModel() { Number = i + 1, State = new ShowInfo() { StatuInfo = (i + 1).ToString() } };
|
||
gd.Children.Add(sm.Labels);
|
||
sm.Labels.SetValue(Grid.RowProperty, 0); //设置按钮所在Grid控件的行
|
||
sm.Labels.SetValue(Grid.ColumnProperty, i); //设置按钮所在Grid控件的列
|
||
CacheLineList.Add(sm);
|
||
}
|
||
CacheLineGrid = gd;
|
||
}
|
||
#endregion
|
||
|
||
#region 良品流线对象
|
||
private Grid produceLineGrid;
|
||
/// <summary>
|
||
/// 良品流线对象
|
||
/// </summary>
|
||
public Grid ProduceLineGrid
|
||
{
|
||
get { return produceLineGrid; }
|
||
set { produceLineGrid = value; this.RaisePropertyChanged("ProduceLineGrid"); }
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 良品流线对象集合
|
||
/// </summary>
|
||
public List<HandModel> ProduceLineList { get; set; }
|
||
|
||
/// <summary>
|
||
/// 获取良品流线Grid
|
||
/// </summary>
|
||
public void GetProduceLineGrid()
|
||
{
|
||
ProduceLineList = new List<HandModel>();
|
||
|
||
Grid gd = new Grid();
|
||
for (int i = 0; i < 1; i++)
|
||
{
|
||
gd.ColumnDefinitions.Add(new ColumnDefinition()); //添加列
|
||
HandModel sm = new HandModel() { Number = i + 1, State = new ShowInfo() { StatuInfo = (i + 1).ToString() } };
|
||
gd.Children.Add(sm.Labels);
|
||
sm.Labels.SetValue(Grid.RowProperty, 0); //设置按钮所在Grid控件的行
|
||
sm.Labels.SetValue(Grid.ColumnProperty, i); //设置按钮所在Grid控件的列
|
||
ProduceLineList.Add(sm);
|
||
}
|
||
ProduceLineGrid = gd;
|
||
}
|
||
#endregion
|
||
#endregion
|
||
|
||
#region 前后站物料状态
|
||
private Grid stationProduceGrid;
|
||
/// <summary>
|
||
/// 前后站物料Grid
|
||
/// </summary>
|
||
public Grid StationProduceGrid
|
||
{
|
||
get { return stationProduceGrid; }
|
||
set { stationProduceGrid = value; RaisePropertyChanged("StationProduceGrid"); }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 前后站物料集合
|
||
/// </summary>
|
||
public List<HandModel> StationProduceList { get; set; }
|
||
/// <summary>
|
||
/// 前后站物料Grid
|
||
/// </summary>
|
||
public void GetStationProduceGrid()
|
||
{
|
||
StationProduceList = new List<HandModel>();
|
||
|
||
Grid gd = new Grid();
|
||
for (int i = 0; i < 2; i++)
|
||
{
|
||
gd.ColumnDefinitions.Add(new ColumnDefinition()); //添加列
|
||
HandModel sm = new HandModel() { Number = i + 1, State = new ShowInfo() { StatuInfo = (i + 1).ToString() } };
|
||
gd.Children.Add(sm.Labels);
|
||
sm.Labels.SetValue(Grid.RowProperty, 0); //设置按钮所在Grid控件的行
|
||
sm.Labels.SetValue(Grid.ColumnProperty, i); //设置按钮所在Grid控件的列
|
||
StationProduceList.Add(sm);
|
||
}
|
||
StationProduceGrid = gd;
|
||
}
|
||
#endregion
|
||
|
||
#region 进料平台状态
|
||
private Grid inCacheGrid;
|
||
/// <summary>
|
||
/// 进料平台对象
|
||
/// </summary>
|
||
public Grid InCacheGrid
|
||
{
|
||
get { return inCacheGrid; }
|
||
set { inCacheGrid = value; this.RaisePropertyChanged("InCacheGrid"); }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 进料平台对象集合
|
||
/// </summary>
|
||
public List<HandModel> InCacheList { get; set; }
|
||
|
||
/// <summary>
|
||
/// 进料平台对象Grid
|
||
/// </summary>
|
||
public void GetInCacheGrid()
|
||
{
|
||
InCacheList = new List<HandModel>();
|
||
|
||
Grid gd = new Grid();
|
||
for (int i = 0; i < 1; i++)
|
||
{
|
||
gd.ColumnDefinitions.Add(new ColumnDefinition()); //添加列
|
||
HandModel sm = new HandModel() { Number = i + 1, State = new ShowInfo() { StatuInfo = (i + 1).ToString() } };
|
||
gd.Children.Add(sm.Labels);
|
||
sm.Labels.SetValue(Grid.RowProperty, 0); //设置按钮所在Grid控件的行
|
||
sm.Labels.SetValue(Grid.ColumnProperty, i); //设置按钮所在Grid控件的列
|
||
InCacheList.Add(sm);
|
||
}
|
||
InCacheGrid = gd;
|
||
}
|
||
#endregion
|
||
|
||
|
||
|
||
#region 连线
|
||
|
||
#region 后站消息
|
||
List<StationMessage> _NextStationReceive = new List<StationMessage> { new StationMessage { Number = 1 }, new StationMessage { Number = 2 } };
|
||
/// <summary>
|
||
/// 从后站收到的消息
|
||
/// </summary>
|
||
List<StationMessage> NextStationReceive
|
||
{
|
||
get
|
||
{
|
||
return _NextStationReceive;
|
||
}
|
||
set
|
||
{
|
||
if (value != null && value.Count == 2)
|
||
{
|
||
_NextStationReceive = value;
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 发送给后站的消息
|
||
/// </summary>
|
||
|
||
public List<StationMessage> NextStationSend { get; set; } = new List<StationMessage> { new StationMessage { Number = 1 }, new StationMessage { Number = 2 } };
|
||
/// <summary>
|
||
/// 后站回调函数
|
||
/// </summary>
|
||
/// <param name="str"></param>
|
||
private void NextStation_ReceiveCallback(string str)
|
||
{
|
||
try
|
||
{
|
||
|
||
NextStationReceive = ShareHelp.JsonToObj<List<StationMessage>>(str);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
|
||
|
||
|
||
|
||
#endregion
|
||
|
||
#region 良品运行
|
||
/// <summary>
|
||
/// 出料流程
|
||
/// </summary>
|
||
FlowModel OKLineFlow { get; set; }
|
||
|
||
FlowModel PassLineFlow { get; set; }
|
||
|
||
|
||
/// <summary>
|
||
/// 皮带运行
|
||
/// </summary>
|
||
private void ProLineRun(FlowModel MyFlow)
|
||
{
|
||
switch (MyFlow.RunStep)
|
||
{
|
||
case GengralProcessEnum.Start:
|
||
|
||
MyFlow.InSignal = InputList[I41流线1皮带检知1];
|
||
MyFlow.OutSignal = InputList[I42流线1皮带检知2];
|
||
MyFlow.OutCmd = OutputList[O30流线1皮带控制];
|
||
MyFlow.OutCmd.Switchs = false;
|
||
if (MyFlow.InSignal.LightUp == false && MyFlow.OutSignal.LightUp == false)
|
||
{
|
||
MyFlow.EnPut = true;
|
||
|
||
}
|
||
else
|
||
{
|
||
|
||
MyFlow.EnPut = false;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
|
||
break;
|
||
case GengralProcessEnum.Step1:
|
||
|
||
if (MyFlow.InSignal.LightUp && MyFlow.OutSignal.LightUp == false)
|
||
{
|
||
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
|
||
}
|
||
else if (MyFlow.InSignal.LightUp == false && MyFlow.OutSignal.LightUp)
|
||
{
|
||
MyFlow.RunStep = GengralProcessEnum.Step10;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (MyFlow.InSignal.LightUp && MyFlow.OutSignal.LightUp)
|
||
|
||
{
|
||
|
||
ExcepStop($" {MyFlow.InSignal.InputMeaning} 和 {MyFlow.OutSignal.InputMeaning} 不能同时有料,请取出一个 ");
|
||
|
||
}
|
||
else
|
||
{
|
||
|
||
MyFlow.RunStep--;
|
||
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step2:
|
||
|
||
MyFlow.OutCmd.Switchs = true;
|
||
if (MyFlow.OutSignal.LightUp)
|
||
{
|
||
MyFlow.OutCmd.Switchs = false;
|
||
MyFlow.RunStep = GengralProcessEnum.Step10;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
|
||
}
|
||
else if (MyFlow.RunTime.AddSeconds(20) < DateTime.Now)
|
||
{
|
||
MyFlow.OutCmd.Switchs = false;
|
||
ExcepStop($"从 {MyFlow.InSignal.InputMeaning} 到 {MyFlow.OutSignal.InputMeaning} 传递超时 ");
|
||
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step10:
|
||
|
||
if (NextStationReceive[0].Request)
|
||
{
|
||
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
|
||
break;
|
||
case GengralProcessEnum.Step11:
|
||
|
||
MyFlow.OutCmd.Switchs = true;
|
||
if (MyFlow.OutSignal.LightUp == false)
|
||
{
|
||
MyFlow.OutCmd.Switchs = false;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
|
||
}
|
||
else if (MyFlow.RunTime.AddSeconds(20) < DateTime.Now)
|
||
{
|
||
|
||
ExcepStop($"{MyFlow.OutSignal.InputMeaning} 出料超时");
|
||
|
||
}
|
||
|
||
break;
|
||
|
||
case GengralProcessEnum.Step12:
|
||
|
||
if (NextStationReceive[0].Request == false)
|
||
{
|
||
|
||
MyFlow.RunStep = GengralProcessEnum.Start;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (MyFlow.RunTime.AddSeconds(20) < DateTime.Now)
|
||
{
|
||
|
||
ExcepStop($"后站交互超时");
|
||
|
||
}
|
||
break;
|
||
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
|
||
#region 自定义Label控件类
|
||
/// <summary>
|
||
/// 自定义Label控件类
|
||
/// </summary>
|
||
public class MyLabel : NotificationObject
|
||
{
|
||
/// <summary>
|
||
/// 序号
|
||
/// </summary>
|
||
public int Number { get; set; }
|
||
|
||
private string myColor;
|
||
/// <summary>
|
||
/// 表示颜色
|
||
/// </summary>
|
||
public string MyColor
|
||
{
|
||
get { return myColor; }
|
||
set
|
||
{
|
||
myColor = value;
|
||
this.RaisePropertyChanged("MyColor");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 对于的Tray名称
|
||
/// </summary>
|
||
public string TrayName { get; set; }
|
||
|
||
public Label Labels { get; set; }
|
||
|
||
private string labelConten;
|
||
/// <summary>
|
||
/// label内容
|
||
/// </summary>
|
||
public string LabelConten
|
||
{
|
||
get { return labelConten; }
|
||
set
|
||
{
|
||
labelConten = value;
|
||
this.RaisePropertyChanged("LabelConten");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 吸嘴1取放料点位
|
||
/// </summary>
|
||
public RobotPoint TakePutPoint1 { get; set; }
|
||
/// <summary>
|
||
/// 吸嘴2取放料点位
|
||
/// </summary>
|
||
public RobotPoint TakePutPoint2 { get; set; }
|
||
|
||
/// <summary>
|
||
/// 吸嘴1取料视觉点位
|
||
/// </summary>
|
||
public RobotPoint TakeVisionPoint { get; set; }
|
||
|
||
|
||
/// <summary>
|
||
/// 第一个吸嘴贴标点
|
||
/// </summary>
|
||
public MotionPointModel Point_M1 { get; set; }
|
||
/// <summary>
|
||
/// 第二个吸嘴贴标点
|
||
/// </summary>
|
||
public MotionPointModel Point_M2 { get; set; }
|
||
|
||
/// <summary>
|
||
/// 第三个吸嘴贴标点
|
||
/// </summary>
|
||
public MotionPointModel Point_M3 { get; set; }
|
||
|
||
/// <summary>
|
||
/// 第四个吸嘴贴标点
|
||
/// </summary>
|
||
public MotionPointModel Point_M4 { get; set; }
|
||
|
||
/// <summary>
|
||
/// 第五个吸嘴贴标点
|
||
/// </summary>
|
||
public MotionPointModel Point_M5 { get; set; }
|
||
|
||
/// <summary>
|
||
/// 第六个吸嘴贴标点
|
||
/// </summary>
|
||
public MotionPointModel Point_M6 { get; set; }
|
||
|
||
private ProductModel prouct;
|
||
/// <summary>
|
||
/// Mylabel对应的产品对象
|
||
/// </summary>
|
||
public ProductModel Prouct
|
||
{
|
||
get { return prouct; }
|
||
set { prouct = value; RaisePropertyChanged("Prouct"); }
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// Label显示控件对象
|
||
/// </summary>
|
||
public MyLabel()
|
||
{
|
||
Prouct = new ProductModel();
|
||
Labels = new Label();
|
||
MyColor = ColorStr.White;
|
||
//LabelConten ="11";
|
||
//绑定背景颜色
|
||
Labels.SetBinding(Label.BackgroundProperty, new Binding() { Source = this, Path = new PropertyPath("Prouct.StateColour"), Mode = BindingMode.TwoWay });
|
||
//绑定内容
|
||
Labels.SetBinding(Label.ContentProperty, new Binding() { Source = this, Path = new PropertyPath("Prouct.SnCode"), Mode = BindingMode.TwoWay });
|
||
|
||
Labels.MouseDoubleClick += Labels_MouseDoubleClick; //增加鼠标双击事件
|
||
Labels.Margin = new Thickness(1); //设置边距
|
||
Labels.HorizontalContentAlignment = HorizontalAlignment.Center;
|
||
Labels.VerticalContentAlignment = VerticalAlignment.Center;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// Label的双击事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void Labels_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
||
{
|
||
//如果为绿色 则不允许改其他颜色
|
||
if (Prouct.StateColour == ColorStr.White)
|
||
{
|
||
Prouct.StateColour = ColorStr.Blue;
|
||
}
|
||
else if (Prouct.StateColour == ColorStr.Blue)
|
||
{
|
||
Prouct.StateColour = ColorStr.Green;
|
||
}
|
||
else
|
||
{
|
||
Prouct.StateColour = ColorStr.White;
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region Tray盘类
|
||
/// <summary>
|
||
/// Tray盘类
|
||
/// </summary>
|
||
public class TrayModel : NotificationObject
|
||
{
|
||
/// <summary>
|
||
/// 构造函数
|
||
/// </summary>
|
||
/// <param name="cloumnNumber"></param>
|
||
/// <param name="rowNumber"></param>
|
||
/// <param name="robotpointlist"></param>
|
||
/// <param name="trayName">料盘名称</param>
|
||
public TrayModel(MachineModel machin, string trayName, int type)
|
||
{
|
||
TrayName = trayName;
|
||
TrayType = type;
|
||
//switch (TrayType)
|
||
//{
|
||
// case 1:
|
||
// this.Cloumn = machin.PictureColoumns;
|
||
// this.Row = machin.PictureRows;
|
||
// break;
|
||
// case 2:
|
||
// this.Cloumn = machin.ColoumsNumber;
|
||
// this.Row = machin.RowsNumber;
|
||
// break;
|
||
//}
|
||
this.Cloumn = machin.ColoumsNumber;
|
||
this.Row = machin.RowsNumber;
|
||
|
||
this.RobotPointList = machin.RobotPointList;
|
||
//this.MotionPointList = machin.MotionPointList.ToList();
|
||
//this.MotionPointList1 = machin.MotionTrajectoryList[1].PointList.ToList();
|
||
this.GridContent = GetTrayGrid(Row, Cloumn, ref MyLabelList); //获取Grid控件
|
||
|
||
PointListInitialization(); //初始化点位集合
|
||
ReductionTrayState(machin);//还原Tray状态
|
||
}
|
||
/// <summary>
|
||
/// 列
|
||
/// </summary>
|
||
int Cloumn { get; set; }
|
||
/// <summary>
|
||
/// 行
|
||
/// </summary>
|
||
int Row { get; set; }
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// Tray名称
|
||
/// </summary>
|
||
public string TrayName { get; set; }
|
||
/// <summary>
|
||
/// Tray类型
|
||
/// </summary>
|
||
public int TrayType { get; set; }
|
||
|
||
private Grid gridContent;
|
||
/// <summary>
|
||
/// grid控件
|
||
/// </summary>
|
||
public Grid GridContent
|
||
{
|
||
get { return gridContent; }
|
||
set
|
||
{
|
||
gridContent = value;
|
||
this.RaisePropertyChanged("GridContent");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Mylabel集合
|
||
/// </summary>
|
||
public List<MyLabel> MyLabelList;
|
||
|
||
|
||
/// <summary>
|
||
/// 机器人对位集合
|
||
/// </summary>
|
||
public List<RobotPoint> RobotPointList { get; set; }
|
||
|
||
/// <summary>
|
||
/// 视觉阵列点位
|
||
/// </summary>
|
||
public List<RobotPoint> TakePutRobotPointList1 { get; set; }
|
||
/// <summary>
|
||
/// 取料阵列点位
|
||
/// </summary>
|
||
public List<RobotPoint> TakePutRobotPointList2 { get; set; }
|
||
|
||
/// <summary>
|
||
/// 放料阵列点位
|
||
/// </summary>
|
||
public List<RobotPoint> TakePutRobotPointList3 { get; set; }
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 运动控制所有点位
|
||
/// </summary>
|
||
public List<MotionPointModel> MotionPointList { get; set; }
|
||
|
||
public List<MotionPointModel> MotionPointList1 { get; set; }
|
||
|
||
|
||
/// <summary>
|
||
/// 第一个吸嘴运动控制阵列点位集合
|
||
/// </summary>
|
||
public List<MotionPointModel> TakeMotionPointList1 { get; set; }
|
||
|
||
/// <summary>
|
||
/// 第二个吸嘴运动控制阵列点位集合
|
||
/// </summary>
|
||
public List<MotionPointModel> TakeMotionPointList2 { get; set; }
|
||
|
||
/// <summary>
|
||
/// 第三个吸嘴运动控制阵列点位集合
|
||
/// </summary>
|
||
public List<MotionPointModel> TakeMotionPointList3 { get; set; }
|
||
|
||
/// <summary>
|
||
/// 第四个吸嘴运动控制阵列点位集合
|
||
/// </summary>
|
||
public List<MotionPointModel> TakeMotionPointList4 { get; set; }
|
||
|
||
/// <summary>
|
||
/// 第五个吸嘴运动控制阵列点位集合
|
||
/// </summary>
|
||
public List<MotionPointModel> TakeMotionPointList5 { get; set; }
|
||
|
||
/// <summary>
|
||
/// 第六个吸嘴运动控制阵列点位集合
|
||
/// </summary>
|
||
public List<MotionPointModel> TakeMotionPointList6 { get; set; }
|
||
|
||
#region 获取当前Tray盘状态
|
||
/// <summary>
|
||
/// 获取当前Tray盘状态
|
||
/// </summary>
|
||
public void GetTrayState(MachineModel currmachine)
|
||
{
|
||
List<ProductModel> list = new List<ProductModel>();
|
||
|
||
list = MyLabelList.Select(w => w.Prouct).ToList();
|
||
switch (TrayType)
|
||
{
|
||
case 1:
|
||
currmachine.Tray1 = ShareHelp.ObjToJson(list);
|
||
break;
|
||
case 2:
|
||
currmachine.Tray2 = ShareHelp.ObjToJson(list);
|
||
break;
|
||
case 3:
|
||
currmachine.Tray3 = ShareHelp.ObjToJson(list);
|
||
break;
|
||
case 4:
|
||
currmachine.Tray4 = ShareHelp.ObjToJson(list);
|
||
break;
|
||
case 5:
|
||
currmachine.Tray5 = ShareHelp.ObjToJson(list);
|
||
break;
|
||
case 6:
|
||
currmachine.Tray6 = ShareHelp.ObjToJson(list);
|
||
break;
|
||
case 7:
|
||
currmachine.Tray7 = ShareHelp.ObjToJson(list);
|
||
break;
|
||
case 8:
|
||
currmachine.Tray8 = ShareHelp.ObjToJson(list);
|
||
break;
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 还原Tray盘状态
|
||
/// <summary>
|
||
/// 还原Tray盘状态
|
||
/// </summary>
|
||
public void ReductionTrayState(MachineModel currmachine)
|
||
{
|
||
List<ProductModel> list = new List<ProductModel>();
|
||
|
||
switch (TrayType)
|
||
{
|
||
case 1:
|
||
list = ShareHelp.JsonToObj<List<ProductModel>>(currmachine.Tray1);
|
||
break;
|
||
case 2:
|
||
list = ShareHelp.JsonToObj<List<ProductModel>>(currmachine.Tray2);
|
||
break;
|
||
case 3:
|
||
list = ShareHelp.JsonToObj<List<ProductModel>>(currmachine.Tray3);
|
||
break;
|
||
case 4:
|
||
list = ShareHelp.JsonToObj<List<ProductModel>>(currmachine.Tray4);
|
||
break;
|
||
case 5:
|
||
list = ShareHelp.JsonToObj<List<ProductModel>>(currmachine.Tray5);
|
||
break;
|
||
case 6:
|
||
list = ShareHelp.JsonToObj<List<ProductModel>>(currmachine.Tray6);
|
||
break;
|
||
case 7:
|
||
list = ShareHelp.JsonToObj<List<ProductModel>>(currmachine.Tray7);
|
||
break;
|
||
case 8:
|
||
list = ShareHelp.JsonToObj<List<ProductModel>>(currmachine.Tray8);
|
||
break;
|
||
}
|
||
|
||
|
||
|
||
int a = 0;
|
||
if (list != null && list.Count >= MyLabelList.Count)
|
||
{
|
||
|
||
if (list != null)
|
||
{
|
||
foreach (var item in MyLabelList)
|
||
{
|
||
item.Prouct = list[a];
|
||
a++;
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 各点位集合初始化
|
||
|
||
/// <summary>
|
||
/// 点位集合初始化
|
||
/// </summary>
|
||
public void PointListInitialization()
|
||
{
|
||
#region 1、机械手阵列点位
|
||
if (RobotPointList != null && RobotPointList.Count > 0)
|
||
{
|
||
//获取阵列1的三个点位
|
||
RobotPoint point1 = Coper(RobotPointList.Where(R => R.PointClass == TrayType && R.PointType == 2).FirstOrDefault());
|
||
RobotPoint point2 = Coper(RobotPointList.Where(R => R.PointClass == TrayType && R.PointType == 3).FirstOrDefault());
|
||
RobotPoint point3 = Coper(RobotPointList.Where(R => R.PointClass == TrayType && R.PointType == 4).FirstOrDefault());
|
||
|
||
//获取取料阵列
|
||
TakePutRobotPointList1 = GetTakePutPointListEpson(point1, point2, point3);
|
||
|
||
RobotPoint visionPoint = Coper(RobotPointList.Where(R => R.PointType == 5).FirstOrDefault());
|
||
double Dx = point1.PointX - visionPoint.PointX;
|
||
double Dy = point1.PointY - visionPoint.PointY;
|
||
|
||
int a = 0;
|
||
foreach (var item in MyLabelList)
|
||
{
|
||
item.TakePutPoint1 = TakePutRobotPointList1 != null ? TakePutRobotPointList1[a] : null;
|
||
item.TakeVisionPoint = Coper(visionPoint);
|
||
item.TakeVisionPoint.PointX = item.TakePutPoint1.PointX - Dx;
|
||
item.TakeVisionPoint.PointY = item.TakePutPoint1.PointY - Dy;
|
||
a++;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 2、运动控制点位
|
||
if (MotionPointList != null && MotionPointList.Count > 0)
|
||
{
|
||
//获取阵列1的三个点位
|
||
MotionPointModel point1 = Coper(MotionPointList.Where(R => R.PointType == 1).FirstOrDefault());
|
||
MotionPointModel point2 = Coper(MotionPointList.Where(R => R.PointType == 2).FirstOrDefault());
|
||
MotionPointModel point3 = Coper(MotionPointList.Where(R => R.PointType == 3).FirstOrDefault());
|
||
|
||
#region 获取正常阵列点位
|
||
//获取取料阵列
|
||
TakeMotionPointList1 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
|
||
|
||
//获取阵列2的三个点位
|
||
point1 = Coper(MotionPointList.Where(R => R.PointType == 4).FirstOrDefault());
|
||
point2 = Coper(MotionPointList.Where(R => R.PointType == 5).FirstOrDefault());
|
||
point3 = Coper(MotionPointList.Where(R => R.PointType == 6).FirstOrDefault());
|
||
|
||
//获取取料阵列
|
||
TakeMotionPointList2 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
|
||
|
||
//获取阵列3的三个点位
|
||
point1 = Coper(MotionPointList.Where(R => R.PointType == 7).FirstOrDefault());
|
||
point2 = Coper(MotionPointList.Where(R => R.PointType == 8).FirstOrDefault());
|
||
point3 = Coper(MotionPointList.Where(R => R.PointType == 9).FirstOrDefault());
|
||
|
||
//获取取料阵列
|
||
TakeMotionPointList3 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
|
||
|
||
//获取阵列4的三个点位
|
||
point1 = Coper(MotionPointList.Where(R => R.PointType == 10).FirstOrDefault());
|
||
point2 = Coper(MotionPointList.Where(R => R.PointType == 11).FirstOrDefault());
|
||
point3 = Coper(MotionPointList.Where(R => R.PointType == 12).FirstOrDefault());
|
||
|
||
//获取取料阵列
|
||
TakeMotionPointList4 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
|
||
|
||
//获取阵列5的三个点位
|
||
point1 = Coper(MotionPointList.Where(R => R.PointType == 13).FirstOrDefault());
|
||
point2 = Coper(MotionPointList.Where(R => R.PointType == 14).FirstOrDefault());
|
||
point3 = Coper(MotionPointList.Where(R => R.PointType == 15).FirstOrDefault());
|
||
|
||
//获取取料阵列
|
||
TakeMotionPointList5 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
|
||
|
||
//获取阵列6的三个点位
|
||
point1 = Coper(MotionPointList.Where(R => R.PointType == 16).FirstOrDefault());
|
||
point2 = Coper(MotionPointList.Where(R => R.PointType == 17).FirstOrDefault());
|
||
point3 = Coper(MotionPointList.Where(R => R.PointType == 18).FirstOrDefault());
|
||
|
||
//获取取料阵列
|
||
TakeMotionPointList6 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
|
||
|
||
#endregion
|
||
|
||
|
||
#region 获取正常阵列点位
|
||
//获取阵列1的三个点位
|
||
point1 = Coper(MotionPointList1.Where(R => R.PointType == 4).FirstOrDefault());
|
||
point2 = Coper(MotionPointList1.Where(R => R.PointType == 5).FirstOrDefault());
|
||
point3 = Coper(MotionPointList1.Where(R => R.PointType == 6).FirstOrDefault());
|
||
|
||
//获取取料阵列
|
||
List<MotionPointModel> JxPointList1 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
|
||
|
||
//获取阵列2的三个点位
|
||
point1 = Coper(MotionPointList1.Where(R => R.PointType == 4).FirstOrDefault());
|
||
point2 = Coper(MotionPointList1.Where(R => R.PointType == 5).FirstOrDefault());
|
||
point3 = Coper(MotionPointList1.Where(R => R.PointType == 6).FirstOrDefault());
|
||
|
||
//获取取料阵列
|
||
List<MotionPointModel> JxPointList2 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
|
||
|
||
//获取阵列3的三个点位
|
||
point1 = Coper(MotionPointList1.Where(R => R.PointType == 7).FirstOrDefault());
|
||
point2 = Coper(MotionPointList1.Where(R => R.PointType == 8).FirstOrDefault());
|
||
point3 = Coper(MotionPointList1.Where(R => R.PointType == 9).FirstOrDefault());
|
||
|
||
//获取取料阵列
|
||
List<MotionPointModel> JxPointList3 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
|
||
|
||
//获取阵列4的三个点位
|
||
point1 = Coper(MotionPointList1.Where(R => R.PointType == 10).FirstOrDefault());
|
||
point2 = Coper(MotionPointList1.Where(R => R.PointType == 11).FirstOrDefault());
|
||
point3 = Coper(MotionPointList1.Where(R => R.PointType == 12).FirstOrDefault());
|
||
|
||
//获取取料阵列
|
||
List<MotionPointModel> JxPointList4 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
|
||
|
||
//获取阵列5的三个点位
|
||
point1 = Coper(MotionPointList1.Where(R => R.PointType == 13).FirstOrDefault());
|
||
point2 = Coper(MotionPointList1.Where(R => R.PointType == 14).FirstOrDefault());
|
||
point3 = Coper(MotionPointList1.Where(R => R.PointType == 15).FirstOrDefault());
|
||
|
||
//获取取料阵列
|
||
List<MotionPointModel> JxPointList5 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
|
||
|
||
//获取阵列6的三个点位
|
||
point1 = Coper(MotionPointList1.Where(R => R.PointType == 16).FirstOrDefault());
|
||
point2 = Coper(MotionPointList1.Where(R => R.PointType == 17).FirstOrDefault());
|
||
point3 = Coper(MotionPointList1.Where(R => R.PointType == 18).FirstOrDefault());
|
||
|
||
//获取取料阵列
|
||
List<MotionPointModel> JxPointList6 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
|
||
|
||
#endregion
|
||
|
||
//分配正常点位
|
||
int a = 0;
|
||
foreach (var item in MyLabelList)
|
||
{
|
||
item.Point_M1 = TakeMotionPointList1 != null ? TakeMotionPointList1[a] : null;
|
||
item.Point_M2 = TakeMotionPointList2 != null ? TakeMotionPointList2[a] : null;
|
||
item.Point_M3 = TakeMotionPointList3 != null ? TakeMotionPointList3[a] : null;
|
||
item.Point_M4 = TakeMotionPointList4 != null ? TakeMotionPointList4[a] : null;
|
||
item.Point_M5 = TakeMotionPointList5 != null ? TakeMotionPointList5[a] : null;
|
||
item.Point_M6 = TakeMotionPointList6 != null ? TakeMotionPointList6[a] : null;
|
||
a++;
|
||
}
|
||
|
||
|
||
}
|
||
#endregion
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取机器人点位集合EPSON机械手算法
|
||
/// </summary>
|
||
/// <param name="p_start"></param>
|
||
/// <param name="p_end"></param>
|
||
public List<RobotPoint> GetTakePutPointListEpson(RobotPoint p1, RobotPoint p2, RobotPoint p3)
|
||
{
|
||
if (p1 == null || p2 == null || p3 == null)
|
||
{
|
||
return null;
|
||
}
|
||
|
||
Vector2 v1 = new Vector2() { X = (float)p1.PointX, Y = (float)p1.PointY };
|
||
Vector2 v2 = new Vector2() { X = (float)p2.PointX, Y = (float)p2.PointY };
|
||
Vector2 v3 = new Vector2() { X = (float)p3.PointX, Y = (float)p3.PointY };
|
||
List<Vector2> lv = GenerateParallelogramGrid2(v1, v2, v3, Cloumn, Row);
|
||
|
||
List<RobotPoint> list = new List<RobotPoint>();
|
||
foreach (var item in lv)
|
||
{
|
||
RobotPoint pr = Coper(p1);
|
||
pr.PointX = item.X;
|
||
pr.PointY = item.Y;
|
||
list.Add(pr);
|
||
}
|
||
|
||
return list;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取机器人点位集合发那科机械手算法
|
||
/// </summary>
|
||
/// <param name="p1"></param>
|
||
/// <param name="p2"></param>
|
||
/// <param name="p3"></param>
|
||
/// <returns></returns>
|
||
public List<RobotPoint> GetTakePutPointListFanuc(RobotPoint p1, RobotPoint p2, RobotPoint p3)
|
||
{
|
||
if (p1 == null || p2 == null || p3 == null)
|
||
{
|
||
return null;
|
||
}
|
||
|
||
//获取两点的行列间距
|
||
double y = p1.PointY - p3.PointY;//Math.Abs(p1.PointY - p3.PointY);
|
||
double x = p1.PointX - p2.PointX;// Math.Abs(p1.PointX - p2.PointX);
|
||
|
||
//获取Tray的行列间距
|
||
double Average_X = Math.Round(x / (Row - 1), 4);
|
||
double Average_Y = Math.Round(y / (Cloumn - 1), 4);
|
||
|
||
|
||
//单个细分间距
|
||
double Offset_x = Math.Round((p1.PointX - p3.PointX) / (Cloumn - 1), 4);
|
||
double Offset_y = Math.Round((p1.PointY - p2.PointY) / (Row - 1), 4);
|
||
|
||
|
||
|
||
List<RobotPoint> list = new List<RobotPoint>();
|
||
RobotPoint rp = new RobotPoint();
|
||
int number = 0;
|
||
for (int j = 0; j < Cloumn; j++)
|
||
{
|
||
for (int i = 0; i < Row; i++)
|
||
{
|
||
rp = ShareHelp.FeiyuCoper(p1);
|
||
|
||
rp.PointNumber = number;
|
||
rp.PointX = rp.PointX - i * Average_X;
|
||
rp.PointY = rp.PointY - j * Average_Y;
|
||
|
||
rp.PointY = rp.PointY - i * Offset_y;
|
||
rp.PointX = rp.PointX - j * Offset_x;
|
||
|
||
rp.Xyzwpr.SetValue((float)rp.PointX, 0);
|
||
rp.Xyzwpr.SetValue((float)rp.PointY, 1);
|
||
|
||
number++;
|
||
list.Add(rp);
|
||
}
|
||
}
|
||
|
||
return list;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取运行控制点位集合
|
||
/// </summary>
|
||
/// <param name="p1"></param>
|
||
/// <param name="p2"></param>
|
||
/// <param name="p3"></param>
|
||
/// <returns></returns>
|
||
public List<MotionPointModel> GetTakePutPointList_M(int row, int cloumn, MotionPointModel p1, MotionPointModel p2, MotionPointModel p3)
|
||
{
|
||
if (p1 == null || p2 == null || p3 == null)
|
||
{
|
||
return null;
|
||
}
|
||
|
||
int Row = row;
|
||
int Cloumn = cloumn;
|
||
|
||
|
||
//获取两点的行列间距
|
||
double x = p1.ShaftPoint_X - p2.ShaftPoint_X; //Math.Abs(p1.PointX - p3.PointX);
|
||
double y = p1.ShaftPoint_Y - p3.ShaftPoint_Y; //Math.Abs(p1.PointY - p2.PointY);
|
||
|
||
|
||
//获取Tray的行列间距
|
||
double Average_X = Math.Round(x / (Cloumn - 1), 4);
|
||
double Average_Y = Math.Round(y / (Row - 1), 4);
|
||
|
||
//单个细分间距
|
||
double Offset_x = Math.Round((p1.ShaftPoint_X - p3.ShaftPoint_X) / (row - 1), 4);
|
||
double Offset_y = Math.Round((p1.ShaftPoint_Y - p2.ShaftPoint_Y) / (Cloumn - 1), 4);
|
||
|
||
|
||
|
||
List<MotionPointModel> list = new List<MotionPointModel>();
|
||
MotionPointModel rp = new MotionPointModel();
|
||
int number = 0;
|
||
for (int i = 0; i < Row; i++)
|
||
{
|
||
for (int j = 0; j < Cloumn; j++)
|
||
{
|
||
rp = Coper(p1);
|
||
rp.PointNumber = number;
|
||
rp.ShaftPoint_X = rp.ShaftPoint_X - j * Average_X;
|
||
rp.ShaftPoint_Y = rp.ShaftPoint_Y - i * Average_Y;
|
||
|
||
rp.ShaftPoint_X = rp.ShaftPoint_X - j * Offset_x;
|
||
rp.ShaftPoint_Y = rp.ShaftPoint_Y - i * Offset_y;
|
||
|
||
|
||
number++;
|
||
list.Add(rp);
|
||
}
|
||
}
|
||
|
||
return list;
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 获取料盘动态Grid
|
||
/// <summary>
|
||
/// 获取料盘动态Grid
|
||
/// </summary>
|
||
/// <param name="grid"></param>
|
||
/// <returns></returns>
|
||
private Grid GetTrayGrid(int Row, int Cloumn, ref List<MyLabel> myLabelList)
|
||
{
|
||
Grid grid = new Grid();
|
||
for (int i = 0; i < Cloumn; i++)
|
||
{
|
||
grid.ColumnDefinitions.Add(new ColumnDefinition()); //添加列
|
||
}
|
||
|
||
for (int j = 0; j < Row; j++)
|
||
{
|
||
grid.RowDefinitions.Add(new RowDefinition()); //添加行
|
||
}
|
||
|
||
myLabelList = new List<MyLabel>();
|
||
|
||
MyLabel label;
|
||
int numbe = 0;
|
||
|
||
|
||
for (int j = 0; j < Row; j++)
|
||
{
|
||
for (int i = 0; i < Cloumn; i++)
|
||
{
|
||
label = new MyLabel();
|
||
label.TrayName = this.TrayName;
|
||
label.Number = numbe++;
|
||
label.LabelConten = numbe.ToString(); //显示编号
|
||
grid.Children.Add(label.Labels);
|
||
label.Labels.SetValue(Grid.RowProperty, j); //设置按钮所在Grid控件的行
|
||
label.Labels.SetValue(Grid.ColumnProperty, i); //设置按钮所在Grid控件的列
|
||
myLabelList.Add(label);
|
||
|
||
}
|
||
|
||
}
|
||
return grid;
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 三点定义平行四边形2维网格
|
||
/// </summary>
|
||
/// <param name="p0"></param>
|
||
/// <param name="p1"></param>
|
||
/// <param name="p2"></param>
|
||
/// <param name="xCount"></param>
|
||
/// <param name="yCount"></param>
|
||
/// <returns></returns>
|
||
public static List<Vector2> GenerateParallelogramGrid2(Vector2 p0, Vector2 p1, Vector2 p2, int xCount, int yCount)
|
||
{
|
||
List<Vector2> gridPoints = new List<Vector2>();
|
||
|
||
Vector2 xVector = (p1 - p0) / (xCount - 1);
|
||
Vector2 yVector = (p2 - p0) / (yCount - 1);
|
||
|
||
for (int y = 0; y < yCount; y++)
|
||
{
|
||
for (int x = 0; x < xCount; x++)
|
||
{
|
||
Vector2 point = p0 + (xVector * x) + (yVector * y);
|
||
gridPoints.Add(point);
|
||
}
|
||
}
|
||
|
||
return gridPoints;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 利用反射进行对象复制
|
||
/// </summary>
|
||
/// <typeparam name="T"></typeparam>
|
||
/// <param name="Coperobj"></param>
|
||
/// <returns></returns>
|
||
private T Coper<T>(T Coperobj)
|
||
{
|
||
if (Coperobj == null)
|
||
{
|
||
return default(T);
|
||
|
||
}
|
||
|
||
T a = System.Activator.CreateInstance<T>();
|
||
|
||
try
|
||
{
|
||
var Types = Coperobj.GetType();//获得类型
|
||
var Typed = a.GetType();
|
||
foreach (PropertyInfo sp in Types.GetProperties())//获得类型的属性字段
|
||
{
|
||
foreach (PropertyInfo dp in Typed.GetProperties())
|
||
{
|
||
if (dp.Name == sp.Name)//判断属性名是否相同
|
||
{
|
||
if (dp.PropertyType.FullName == typeof(Array).FullName)
|
||
{
|
||
dp.SetValue(a, ((Array)sp.GetValue(Coperobj, null)).Clone(), null);//获得s对象属性的值复制给d对象的属性
|
||
|
||
}
|
||
else
|
||
{
|
||
dp.SetValue(a, sp.GetValue(Coperobj, null), null);//获得s对象属性的值复制给d对象的属性
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
|
||
return a;
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
}
|