motorTest/ViewModel/MainWindowVM.cs
2026-11-09 13:02:24 +08:00

7042 lines
238 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Community;
using DAL;
using HalconDotNet;
using MahApps.Metro.Controls.Dialogs;
using Model;
using Model.MotionControl;
using Model.Vision;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Media3D;
using System.Windows.Threading;
using ViewModel.MotionControl;
using ViewModel.Robots;
using ViewModel.Vision;
using Views;
namespace ViewModel
{
public partial class MainWindowVM : NotificationObject
{
#region IO
int X000启动 = 0;
int X001停止 = 1;
int X002急停 = 2;
int X003气压检知 = 3;
int X004 = 4;
int X005 = 5;
int X006门禁5 = 6;
int X007门禁6 = 7;
int X008门禁1 = 8;
int X009门禁2 = 9;
int X010门禁3 = 10;
int X011门禁4 = 11;
int X012NG满料光电 = 12;
int X013入料仓按钮1 = 13;
int X014出料仓按钮2 = 14;
int X015料仓光栅 = 15;
int X100料仓入缓存对射1 = 16;
int X101料仓入缓存对射2 = 17;
int X102料仓入升降对射1 = 18;
int X103料仓入升降对射2 = 19;
int X104料仓出升降对射1 = 20;
int X105料仓出升降对射2 = 21;
int X106料仓出缓存对射1 = 22;
int X107料仓出缓存对射2 = 23;
int X108入升降料仓上检知1 = 24;
int X109入升降料仓上检知2 = 25;
int X110出升降料仓上检知1 = 26;
int X111出升降料仓上检知2 = 27;
int X112料仓入缓存阻挡上 = 28;
int X113料仓入缓存阻挡下 = 29;
int X114搬运气缸上位 = 30;
int X115搬运气缸下位 = 31;
int X200搬运真空检 = 32;
int X201左机械手真空检 = 33;
int X202右机械手真空检 = 34;
int X203左贴合吸料真空检 = 35;
int X204右贴合吸料真空检 = 36;
int X205翻转真空检 = 37;
int X206翻转气缸正面 = 38;
int X207翻转气缸反面 = 39;
int X208顶升气缸上位 = 40;
int X209顶升气缸下位 = 41;
int X210左拍照检底部吸盘上位 = 42;
int X211左拍照检底部吸盘下位 = 43;
int X212左拍照检底部吸盘真空 = 44;
int X213右拍照检底部吸盘上位 = 45;
int X214右拍照检底部吸盘下位 = 46;
int X215右拍照检底部吸盘真空 = 47;
int X300左飞达初始化完成 = 48;
int X301左飞达料报警 = 49;
int X302左飞达剥料完成 = 50;
int X303左飞达送料完成 = 51;
int X304 = 52;
int X305 = 53;
int X306 = 54;
int X307 = 55;
int X308右飞达料到位 = 56;
int X309右飞达料报警 = 57;
int X310左翻转机构真空 = 58;
int X311左翻转原位 = 59;
int X312左翻转到位 = 60;
int X313左翻转上位 = 61;
int X314左翻转下位 = 62;
int X315 = 63;
int Y000绿灯 = 0;
int Y001红灯 = 1;
int Y002黄灯 = 2;
int Y003蜂鸣器 = 3;
int Y004 = 4;
int Y005 = 5;
int Y006 = 6;
int Y007 = 7;
int Y008取料上光源 = 8;
int Y009取料下光源 = 9;
int Y010左贴上光源 = 10;
int Y011左贴下光源 = 11;
int Y012右贴上光源 = 12;
int Y013右贴下光源 = 13;
int Y014收料上光源 = 14;
int Y015检查光源 = 15;
int Y100料仓入缓存阻挡气缸 = 16;
int Y101搬运气缸上位 = 17;
int Y102搬运气缸下位 = 18;
int Y103翻转气缸正面 = 19;
int Y104翻转气缸反面 = 20;
int Y105顶升气缸上位 = 21;
int Y106顶升气缸下位 = 22;
int Y107 = 23;
int Y108入料仓调速电机1 = 24;
int Y109入料仓调速电机2 = 25;
int Y110出料仓调速电机1 = 26;
int Y111出料仓调速电机2 = 27;
int Y112NG皮带 = 28;
int Y113离子风1 = 29;
int Y114离子风2 = 30;
int Y115 = 31;
int Y200搬运真空吸 = 32;
int Y201搬运真空破 = 33;
int Y202左机械手真空吸 = 34;
int Y203左机械手真空破 = 35;
int Y204右机械手真空吸 = 36;
int Y205右机械手真空破 = 37;
int Y206左贴合吸料真空吸 = 38;
int Y207左贴合吸料真空破 = 39;
int Y208右贴合吸料真空吸 = 40;
int Y209右贴合吸料真空破 = 41;
int Y210翻转真空吸 = 42;
int Y211翻转真空破 = 43;
int Y212左拍照检底部吸盘上位 = 44;
int Y213左拍照检底部吸盘下位 = 45;
int Y214左拍照检底部吸盘真空吸 = 46;
int Y215左拍照检底部破盘真空破 = 47;
int Y300飞达复位 = 48;
int Y301飞达后撤 = 49;
int Y302右飞达 = 50;
int Y303右飞达复位 = 51;
int Y304左飞达送料信号 = 52;
int Y305 = 53;
int Y306左翻转机构真空 = 54;
int Y307左翻转原位 = 55;
int Y308左翻转到位 = 56;
int Y309左翻转上位 = 57;
int Y310左翻转下位 = 58;
int Y311 = 59;
int Y312右拍照检底部吸盘上位 = 60;
int Y313右拍照检底部吸盘下位 = 61;
int Y314右拍照检底部吸盘真空吸 = 62;
int Y315右拍照检底部破盘真空破 = 63;
#endregion
#region 生成Grid状态
public (Grid, List<HandModel>) GetGrid(int col, int row = 0)
{
var handModels = new List<HandModel>();
Grid gd = new Grid();
for (int i = 0; i < col; 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控件的列
handModels.Add(sm);
}
return (gd, handModels);
}
#endregion
public FlowModel ManulFlow { get; set; } = new FlowModel();
private DelegateCommand _ManulTest;
public DelegateCommand ManulTest =>
_ManulTest = _ManulTest ?? new DelegateCommand() { ExecuteAction = ExecuteManulTest };
void ExecuteManulTest(object obj)
{
var cmd = obj.ToString();
if (testing) return;
testing = true;
// TorqueFlow.Step = 1;
switch (cmd)
{
case "手动贴左":
ZhuanPanList[2].State.StatusForeground = ColorStr.Blue;
ManulFlow.Step = 0;
PasteLeftFlow = new FlowModel(); ;
break;
case "手动贴右":
ZhuanPanList[6].State.StatusForeground = ColorStr.Blue;
ZhuanPanList[6].State.StatusBackground = ColorStr.Red;
ManulFlow.Step = 0;
PasteRightFlow = new FlowModel("");
break;
case "手动检右":
ZhuanPanList[6].State.StatusForeground = ColorStr.Blue;
ZhuanPanList[6].State.StatusBackground = ColorStr.Green;
ManulFlow.Step = 13;
CheckFlow.Step = 0;
PasteRightFlow = new FlowModel("");
break;
case "手动压合":
ManulFlow.Step = 0;
ZhuanPanList[4].State.StatusForeground = ColorStr.Blue;
ZhuanPanList[4].State.StatusBackground = ColorStr.Yellow;
break;
case "手动测试轴":
ManulFlow.Step = 0;
break;
}
Task.Run(() =>
{
while (testing)
{
Thread.Sleep(10);
switch (cmd)
{
case "手动贴左":
PasteLeftRun(ManulFlow);
if (ManulFlow.Step == 33)
{
testing = false;
}
break;
case "手动检右":
PasteRightRun(ManulFlow);
if (ManulFlow.Step == 14)
{
testing = false;
}
break;
case "手动贴右":
PasteRightRun(ManulFlow);
if (ManulFlow.Step == 14)
{
testing = false;
}
break;
case "手动压合":
TorqueRun(ManulFlow, CurrentMachine.MyQita.Press1);
if (ManulFlow.Step == 9)
{
testing = false;
}
break;
case "手动测试轴":
try
{
TestAxisRun(ManulFlow);
}
catch (Exception)
{
testing = false;
}
break;
}
}
});
}
private MotionPointModel GetMotionPoint(string pointName, bool copy = false)
{
var tempPoint = CurrentMachine.MotionPointList.Where(w => w.PointName == pointName).FirstOrDefault();
if (tempPoint != null)
{
if (copy)
{
tempPoint = Coper(tempPoint);
}
tempPoint.PointRunStep = GengralProcessEnum.Start;
}
return tempPoint;
}
private MotionPointModel GetMotionPoint(int pointType, bool copy = false)
{
var tempPoint = CurrentMachine.MotionPointList.Where(w => w.PointType == pointType).FirstOrDefault();
if (tempPoint != null)
{
if (copy)
{
tempPoint = Coper(tempPoint);
}
tempPoint.PointRunStep = GengralProcessEnum.Start;
}
return tempPoint;
}
bool testing;
private string gridWidth;
/// <summary>
/// Grid的宽
/// </summary>
public string GridWidth
{
get { return gridWidth; }
set
{
gridWidth = value;
this.RaisePropertyChanged("GridWidth");
}
}
#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 视觉对象
private HalconVisual visualA;
/// <summary>
/// 视觉对象A
/// </summary>
public HalconVisual VisualA
{
get { return visualA; }
set
{
visualA = value;
RaisePropertyChanged("VisualA");
}
}
private HalconVisual _VisualA1;
public HalconVisual VisualA1
{
get { return _VisualA1; }
set
{
_VisualA1 = value;
this.RaisePropertyChanged("VisualA1");
}
}
private HalconVisual visualB;
/// <summary>
/// 视觉对象B
/// </summary>
public HalconVisual VisualB
{
get { return visualB; }
set
{
visualB = value;
RaisePropertyChanged("VisualB");
}
}
private HalconVisual _VisualB1;
public HalconVisual VisualB1
{
get { return _VisualB1; }
set
{
_VisualB1 = value;
this.RaisePropertyChanged("VisualB1");
}
}
private HalconVisual visualC;
/// <summary>
/// 视觉对象C
/// </summary>
public HalconVisual VisualC
{
get { return visualC; }
set
{
visualC = value;
RaisePropertyChanged("VisualC");
}
}
private HalconVisual _VisualC1;
public HalconVisual VisualC1
{
get { return _VisualC1; }
set
{
_VisualC1 = value;
this.RaisePropertyChanged("VisualC1");
}
}
private HalconVisual visualD;
/// <summary>
/// 视觉对象D
/// </summary>
public HalconVisual VisualD
{
get { return visualD; }
set
{
visualD = value;
RaisePropertyChanged("VisualD");
}
}
private HalconVisual _VisualD1;
public HalconVisual VisualD1
{
get { return _VisualD1; }
set
{
_VisualD1 = value;
this.RaisePropertyChanged("VisualD1");
}
}
private HalconVisual visualE;
/// <summary>
/// 视觉对象E
/// </summary>
public HalconVisual VisualE
{
get { return visualE; }
set
{
visualE = value;
RaisePropertyChanged("VisualE");
}
}
private HalconVisual visualF;
/// <summary>
/// 视觉对象F
/// </summary>
public HalconVisual VisualF
{
get { return visualF; }
set
{
visualF = value;
RaisePropertyChanged("VisualF");
}
}
private HalconVisual _VisualG;
public HalconVisual VisualG
{
get { return _VisualG; }
set
{
_VisualG = value;
this.RaisePropertyChanged("VisualG");
}
}
#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 RobotA
{
get { return robot; }
set
{
robot = value;
RaisePropertyChanged("Robot");
}
}
private FeiYuRobotVM robotB;
/// <summary>
/// 机器人对象
/// </summary>
public FeiYuRobotVM RobotB
{
get { return robotB; }
set
{
robotB = value;
RaisePropertyChanged("RobotB");
}
}
#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 Blue 待放料,Green 已放料
/// </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;
}
}
}
#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[Y001红灯].Switchs = false; //红灯
OutputList[Y002黄灯].Switchs = true; //黄灯
OutputList[Y000绿灯].Switchs = false; //绿灯
OutputList[Y003蜂鸣器].Switchs = false; //蜂鸣器
}
break;
case RunStatuEnum.Prepareations:
ShowStatu.StatusBackground = ColorStr.Green;
ShowStatu.StatusForeground = ColorStr.Black;
ShowStatu.StatuInfo = "准备就绪";
OutputList[Y001红灯].Switchs = false; //红灯
OutputList[Y002黄灯].Switchs = true; //黄灯
OutputList[Y000绿灯].Switchs = false; //绿灯
OutputList[Y003蜂鸣器].Switchs = false; //蜂鸣器
break;
case RunStatuEnum.Normal:
ShowStatu.StatusBackground = ColorStr.Green;
ShowStatu.StatusForeground = ColorStr.Black;
ShowStatu.StatuInfo = "运行中";
OutputList[Y001红灯].Switchs = false; //红灯
OutputList[Y002黄灯].Switchs = false; //黄灯
OutputList[Y000绿灯].Switchs = true; //绿灯
OutputList[Y003蜂鸣器].Switchs = false; //蜂鸣器
break;
case RunStatuEnum.Stop:
ShowStatu.StatusBackground = ColorStr.Yellow;
ShowStatu.StatusForeground = ColorStr.Black;
ShowStatu.StatuInfo = "停止中";
OutputList[Y001红灯].Switchs = false; //红灯
OutputList[Y002黄灯].Switchs = true; //黄灯
OutputList[Y000绿灯].Switchs = false; //绿灯
OutputList[Y003蜂鸣器].Switchs = false; //蜂鸣器
break;
case RunStatuEnum.EmgStop:
ShowStatu.StatusBackground = ColorStr.Yellow;
ShowStatu.StatusForeground = ColorStr.Black;
ShowStatu.StatuInfo = "紧急停止中";
OutputList[Y001红灯].Switchs = true; //红灯
OutputList[Y002黄灯].Switchs = true; //黄灯
OutputList[Y000绿灯].Switchs = false; //绿灯
OutputList[Y003蜂鸣器].Switchs = false; //蜂鸣器
break;
case RunStatuEnum.Exceptional:
ShowStatu.StatusBackground = ColorStr.Red;
ShowStatu.StatusForeground = ColorStr.White;
OutputList[Y001红灯].Switchs = true; //红灯
OutputList[Y002黄灯].Switchs = false; //黄灯
OutputList[Y000绿灯].Switchs = false; //绿灯
OutputList[Y003蜂鸣器].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 (RobotA != null)
{
RobotA.MachineObj = CurrentMachine;
}
if (RobotB != null)
{
RobotB.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, "上料料盘", 1);
Tray2 = new TrayModel(CurrentMachine, "下料料盘", 2);
Robot_ShuaxinPointing(0);
}
#endregion
#region 当前生产机种对象
private MachineModel currentMachine;
/// <summary>
/// 当前生产机种对象
/// </summary>
public MachineModel CurrentMachine
{
get { return currentMachine; }
set
{
currentMachine = value;
this.RaisePropertyChanged("CurrentMachine");
}
}
#endregion
#region 各步骤
#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 光源串口号
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)
{
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
GoHomeFlow = new FlowModel("回原点流程");
//开启状态监控线程
if (ThStateMonitoring == null)
{
ThStateMonitoring = new Thread(StateMonitoring);
ThStateMonitoring.IsBackground = true;
ThStateMonitoring.Start();
}
YaliyiConn = ServerComm.CommList.Where(s => s.ShortCode == "YA").FirstOrDefault();
YaliyiConn.ReceiveCallback += YaliyiConn_ReceiveCallback;
(Feed1Grid, Feed1List) = GetGrid(1);
Feed1List[0].TakePoint = CurrentMachine.MotionPointList.Where(w => w.PointName == "左贴合取料").FirstOrDefault();
Feed1List[0].VisionPoint = CurrentMachine.MotionPointList.Where(w => w.PointName == "左贴合取料拍照").FirstOrDefault();
(Feed2Grid, Feed2List) = GetGrid(CurrentMachine.MyQita.Feed);
{
var first = CurrentMachine.MotionPointList.Where(w => w.PointName == "右贴合取料最左").FirstOrDefault();
var last = CurrentMachine.MotionPointList.Where(w => w.PointName == "右贴合取料最右").FirstOrDefault();
var vision = CurrentMachine.MotionPointList.Where(w => w.PointName == "右贴合取料拍照").FirstOrDefault();
var step = (last.ShaftPoint_X - first.ShaftPoint_X) / (CurrentMachine.MyQita.Feed - 1);
var stepZ = (last.ShaftPoint_Z - first.ShaftPoint_Z) / (CurrentMachine.MyQita.Feed - 1);
for (int i = 0; i < CurrentMachine.MyQita.Feed; i++)
{
Feed2List[i].TakePoint = Coper(first);
Feed2List[i].TakePoint.ShaftPoint_X += step * i;
Feed2List[i].TakePoint.ShaftPoint_Z += stepZ * i;
Feed2List[i].VisionPoint = Coper(vision);
Feed2List[i].VisionPoint.ShaftPoint_X += step * i;
}
}
(ZhuanPanGrid, ZhuanPanList) = GetGrid(8);
(NGGrid, NGList) = GetGrid(3);
(RobotPickerGrid, RobotPickerList) = GetGrid(2);
(FlipGrid, FlipList) = GetGrid(1);
(LeftFlipGrid, LeftFlipList) = GetGrid(1);
EnableAnquanmen = false;
}
private void YaliyiConn_ReceiveCallback1(string str)
{
throw new NotImplementedException();
}
/// <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();
AllVis = Visibility.Collapsed;
OpenTime = DateTime.Now;
ShowStatu = new ShowInfo();
RunStatu = RunStatuEnum.Prepare;
ExcepList = new ObservableCollection<RecordInfo>();
//LightCOM = new SerialCom();
//SerialProt = SystemPar.SerialProt;
//2、初始化输入输出信号
InputList = dal.GetInputList(0);
OutputList = dal.GetOutputList(0);
ERPVM = new ERPManageVM(SystemPar.ID, this.dal);
SCVM = new SerialComVM(SystemPar.ID); //串口对象
ServerComm = new CommunicationServerVM(SystemPar.ID, Mywindow.Dispatcher);
ServerComm.MonitorsWitch = true;
List<StandModel> standModels = dal.GetStandList();
List<StandVM> list = new List<StandVM>();
StandVM sm;
foreach (var item in standModels)
{
sm = new StandVM(item);
sm.MyConnect = ServerComm.CommList.Where(w => w.MyType == item.ID).FirstOrDefault();
list.Add(sm);
}
StandVMList = list;
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;
}
#region 获取输出信号Grid
/// <summary>
/// 获取输出信号Grid
/// </summary>
/// <returns></returns>
private Grid GetOutputGrid()
{
Grid g = new Grid();
int row = 0;
int column = 0;
int count = OutputList.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]);
//加一个控件修饰控件 用于控制字体的大小
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 });
cb.SetBinding(CheckBox.ToolTipProperty, new Binding() { Path = new PropertyPath("IoNumber"), 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.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;
int count = InputList.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]);
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("Mylabel1");//LabelStyle 这个样式是引用的资源文件中的样式名称
//设置数据上下文
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 });
Labels.SetBinding(Label.ToolTipProperty, new Binding() { Path = new PropertyPath("IoNumber"), Mode = BindingMode.TwoWay });
//设置前景色
Labels.Foreground = new SolidColorBrush(Colors.White);
//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、状态监控
/// <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[X000启动].LightUp)
{
Start(0);//启动信号
}
if (InputList[X001停止].LightUp)
{
Stop(0); //停止信号
}
if (InputList[X002急停].LightUp)
{
EmgStop();// 急停信号
}
if (!InputList[X003气压检知].LightUp == false && RunStatu == RunStatuEnum.Normal)
{
ExcepStop(InputList[X003气压检知].InputMeaning);
}
//安全门
//if (EnableAnquanmen)
//{
// for (int i = 4; i < 12; i++)
// {
// if (InputList[i].LightUp)
// {
// ExcepStop(InputList[i].InputMeaning);
// }
// }
//}
#endregion
#region 获取轴状态
if (MCVM != null)
{
MCVM.OrginALL(InputList[X002急停]);
if (RunStatu != RunStatuEnum.Normal)
{
MCVM.PointRun();
mCVM.RunMotionTrajectory();
}
}
#endregion
DualControlRun();//双控运行
GoHome();//回原点
NGRun();
SendYaJi();
if (InputList[X107料仓出缓存对射2].LightUp || InputList[X106料仓出缓存对射1].LightUp)
{
ExcepNoStop("请取走满盘");
}
else
{
ExcepNoStopClear("请取走满盘");
}
if (InputList[X107料仓出缓存对射2].LightUp)
{
OutputList[Y110出料仓调速电机1].Switchs = false;//空盘皮带1
OutputList[Y111出料仓调速电机2].Switchs = false;//空盘皮带1
}
//投料区有盘
if (InputList[X100料仓入缓存对射1].LightUp && InputList[X101料仓入缓存对射2].LightUp)
{
//投料完成按钮
if (InputList[X013入料仓按钮1].LightUp)
{
TouliaoReady = true;
}
}
else
{
TouliaoReady = false;
}
//光栅
if (InputList[X015料仓光栅].LightUp == false && RunStatu == RunStatuEnum.Normal)
{
gratingTrig = true;
ExcepNoStop("光栅触发,请按入料仓按钮继续");
}
if ((InputList[X013入料仓按钮1].LightUp || InputList[X014出料仓按钮2].LightUp) && gratingTrig)
{
gratingTrig = false;
ExcepNoStopClear("光栅触发,请按入料仓按钮继续");
}
try
{
if (CurrentMachine.MotionPointList != null)
{
MotionPointModel safePos = CurrentMachine.MotionPointList.Where(w => w.PointName == "搬运中间点").FirstOrDefault();
if (safePos.Shaft_X == null)
{
safePos.GetInterpolationPer(MCVM.AllShaftList);
}
//搬运轴在右
if (safePos.Shaft_X.ActualDir >= safePos.ShaftPoint_X - 1)
{
if (Tray1 != null)
{
foreach (var item in Tray1.MyLabelList)
{
if (item.VisonPoint != null)
{
item.VisonPoint.Safe = true;
item.TakePutPoint.Safe = true;
}
}
}
foreach (var item in RobotA.RobotPointList)
{
item.Safe = true;
}
}
else //搬运轴在左
{
foreach (var item in RobotA.RobotPointList)
{
item.Safe = false;
}
if (Tray1 != null)
{
foreach (var item in Tray1.MyLabelList)
{
if (item.VisonPoint != null)
{
item.VisonPoint.Safe = false;
item.TakePutPoint.Safe = false;
}
}
}
}
//搬运轴在左
if (safePos.Shaft_X.ActualDir <= safePos.ShaftPoint_X + 1)
{
foreach (var item in RobotB.RobotPointList)
{
item.Safe = true;
}
if (Tray2 != null)
{
foreach (var item in Tray2.MyLabelList)
{
if (item.TakePutPoint != null)
{
item.TakePutPoint.Safe = true;
}
}
}
}
else //搬运轴在右
{
foreach (var item in RobotB.RobotPointList)
{
item.Safe = false;
}
if (Tray2 != null)
{
foreach (var item in Tray2.MyLabelList)
{
if (item.TakePutPoint != null)
item.TakePutPoint.Safe = false;
}
}
}
}
}
catch (Exception)
{
}
}
}
}
DateTime NGTime = DateTime.Now;
int NGCount;
bool NG;
private void NGRun()
{
if (NGCount > 3 || InputList[X012NG满料光电].LightUp)
{
NGCount = 0;
ExcepNoStop("NG满");
}
if (NG)
{
NG = false;
NGCount++;
OutputList[Y112NG皮带].Switchs = true;
}
if (OutputList[Y112NG皮带].Switchs)
{
if (NGTime.AddSeconds(2) < DateTime.Now)
{
OutputList[Y112NG皮带].Switchs = false;
}
}
else
{
NGTime = DateTime.Now;
}
}
public DateTime SafeTime { get; set; } = DateTime.Now;
/// <summary>
/// 光栅触发
/// </summary>
bool gratingTrig;
private bool enableAnquanmen;
/// <summary>
/// 启用安全门
/// </summary>
public bool EnableAnquanmen
{
get { return enableAnquanmen; }
set { enableAnquanmen = value; RaisePropertyChanged("EnableAnquanmen"); }
}
#region 回原点
/// <summary>
/// 回远点流程
/// </summary>
FlowModel GoHomeFlow { get; set; }
bool homeing;
/// <summary>
/// 回原点
/// </summary>
private void GoHome()
{
switch (GoHomeFlow.RunStep)
{
case GengralProcessEnum.Start:
//优先机械手回原点
if (RobotA != null)
{
homeing = true;
if (RobotA.HomeStep == GengralProcessEnum.End)
{
GoHomeFlow.RunStep++;
}
else
{
RobotA.RobotOrgin();
}
}
else
{
GoHomeFlow.RunStep++;
}
break;
case GengralProcessEnum.Step1:
//优先机械手回原点
if (RobotB != null)
{
if (RobotB.HomeStep == GengralProcessEnum.End)
{
GoHomeFlow.RunStep++;
}
else
{
RobotB.RobotOrgin();
}
}
else
{
GoHomeFlow.RunStep++;
}
break;
case GengralProcessEnum.Step2:
if (MCVM != null)
{
MCVM.HomeStep = GengralProcessEnum.Start;
GoHomeFlow.RunStep++;
}
else
{
GoHomeFlow.RunStep = GengralProcessEnum.End;
RunStatu = RunStatuEnum.Prepareations; //准备就绪
}
break;
case GengralProcessEnum.Step3:
if (MCVM.HomeStep == GengralProcessEnum.End)
{
GoHomeFlow.RunStep++;
RunStatu = RunStatuEnum.Prepareations; //准备就绪
}
break;
case GengralProcessEnum.Step4:
PressSafe = true;
TransmitPoint = CurrentMachine.MotionPointList.Where(w => w.PointName == "转盘起始位").FirstOrDefault();
GoHomeFlow.RunStep++;
break;
case GengralProcessEnum.Step5:
//移动到位
if (TransmitPoint.PointRun(MCVM.AllShaftList))
{
GoHomeFlow.RunStep++;
ZhuanPanList.ForEach(w => w.State.StatusBackground = ColorStr.White);
ZhuanPanList.ForEach(w => w.State.StatusForeground = ColorStr.Blue);//Blue转到位 Gray转动中,Green工位完成
}
else if (GoHomeFlow.RunTime.AddSeconds(3) < DateTime.Now)
{
TransmitPoint.PointRunStep = GengralProcessEnum.Start;
GoHomeFlow.RunTime = DateTime.Now;
}
break;
case GengralProcessEnum.Step6:
homeing = false;
GoHomeFlow.RunStep = GengralProcessEnum.End;
RunStatu = RunStatuEnum.Prepareations; //准备就绪
break;
}
}
#endregion
#region 其他运行内容
/// <summary>
/// 其他运行内容
/// </summary>
private void DualControlRun()
{
OutputList[Y106顶升气缸下位].Switchs = !OutputList[Y105顶升气缸上位].Switchs;
OutputList[Y313右拍照检底部吸盘下位].Switchs = !OutputList[Y312右拍照检底部吸盘上位].Switchs;
OutputList[Y213左拍照检底部吸盘下位].Switchs = !OutputList[Y212左拍照检底部吸盘上位].Switchs;
OutputList[Y101搬运气缸上位].Switchs = !OutputList[Y102搬运气缸下位].Switchs;
OutputList[Y104翻转气缸反面].Switchs = !OutputList[Y103翻转气缸正面].Switchs;
OutputList[Y309左翻转上位].Switchs = !OutputList[Y310左翻转下位].Switchs;
OutputList[Y307左翻转原位].Switchs = !OutputList[Y308左翻转到位].Switchs;
}
public DateTime FlipTime { get; set; } = DateTime.Now;
#endregion
#endregion
#region 3、运行
/// <summary>
/// 启动运行
/// </summary>
private void Run()
{
Feed1Flow = new FlowModel("飞达1流程");
Feed2Flow = new FlowModel("飞达2流程");
TrayFeedFlow = new FlowModel("料盘上料流程");
TrayBlankingFlow = new FlowModel("料盘下料流程");
TrayMovingFlow = new FlowModel("料盘移动流程");
TakeFlow = new FlowModel("取料流程");
LeftFlipFlow = new FlowModel("左翻转流程");
TakeOutFlow = new FlowModel("取出装盘流程");
FlipFlow = new FlowModel("右翻转流程");
ZhuanPanFlow = new FlowModel("转盘流程");
PasteLeftFlow = new FlowModel("贴合流程");
PasteRightFlow = new FlowModel("右贴合流程");
CheckFlow = new FlowModel("检查流程");
TorqueFlow = new FlowModel("压合流程");
while (true)
{
if (RunStatu == RunStatuEnum.Normal)
{
try
{
TrayFeedRun(TrayFeedFlow);
TrayBlankingRun(TrayBlankingFlow);
TrayMovingRun(TrayMovingFlow);
ZhuanPanRun(ZhuanPanFlow);
TakeRun(TakeFlow);
LeftFlipRun(LeftFlipFlow);
FlipRun(FlipFlow);
TakeOutRun(TakeOutFlow);
Feed1Run(Feed1Flow);
Feed2Run(Feed2Flow);
PasteLeftRun(PasteLeftFlow);
TorqueRun(TorqueFlow, CurrentMachine.MyQita.Press1);
PasteRightRun(PasteRightFlow);
// CheckRun(CheckFlow);
}
catch (Exception ex)
{
ExcepStop(ex.Message);
}
}
else
{
TakeFlow.RunTime = DateTime.Now;
Feed1Flow.RunTime = DateTime.Now;
TrayFeedFlow.RunTime = DateTime.Now;
TrayBlankingFlow.RunTime = DateTime.Now;
ZhuanPanFlow.RunTime = DateTime.Now;
TrayMovingFlow.RunTime = DateTime.Now;
PasteLeftFlow.RunTime = DateTime.Now;
FlipFlow.RunTime = DateTime.Now;
LeftFlipFlow.RunTime = DateTime.Now;
TakeOutFlow.RunTime = DateTime.Now;
CheckFlow.RunTime = DateTime.Now;
}
}
}
#region 上一站连接
/// <summary>
/// 上一站连接
/// </summary>
public CommunicationManagementClass FrontStation { get; set; }
#endregion
#region 下一站连接
/// <summary>
/// 下一站连接
/// </summary>
public CommunicationManagementClass NextStation { get; set; }
#endregion
#region 发送消息给下一站
/// <summary>
/// 发送载具状态的字符串
/// </summary>
string SendNextStr { get; set; }
DateTime SendNextStationTime { get; set; }
/// <summary>
/// 发送消息给下一站
/// </summary>
private void SendNextStation()
{
if (SendNextStationTime.AddMilliseconds(500) < DateTime.Now)
{
NextStation.SendInfo(SendNextStr);
SendNextStationTime = DateTime.Now;
}
}
#endregion
#region 发送信息给上一站
/// <summary>
/// 当前发给上一站的信息
/// </summary>
string CurrSendInfor { get; set; }
DateTime SendFrontStationTime { get; set; }
/// <summary>
/// 发送信息给上一站
/// </summary>
/// <param name="CommandStr"></param>
private void SendFrontStation(string CommandStr)
{
if (SendFrontStationTime.AddMilliseconds(500) < DateTime.Now)
{
FrontStation.SendInfo(CommandStr);
CurrSendInfor = CommandStr;
SendFrontStationTime = DateTime.Now;
}
}
#endregion
#endregion
#region 4、加载功能界面
/// <summary>
/// 加载功能界面
/// </summary>
private void LoadingFunctionInterface()
{
TabItemList = new ObservableCollection<TabItem>();
//添加主页界面
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);
}
if (HVlist.Count > 0)
VisualA = HVlist[0];
if (HVlist.Count > 1)
{
VisualA1 = HVlist[1];
VisualA1.HWindowWPF2 = VisualA.HWindowWPF2;
}
if (HVlist.Count > 2)
VisualB = HVlist[2];
if (HVlist.Count > 3)
{
VisualB1 = HVlist[3];
VisualB1.HWindowWPF2 = VisualB.HWindowWPF2;
}
if (HVlist.Count > 4)
VisualC = HVlist[4];
if (HVlist.Count > 5)
{
VisualC1 = HVlist[5];
VisualC1.HWindowWPF2 = VisualC.HWindowWPF2;
}
if (HVlist.Count > 6)
VisualD = HVlist[6];
//if (HVlist.Count > 7)
// VisualD1 = HVlist[7];
if (HVlist.Count > 7)
VisualE = HVlist[7];
if (HVlist.Count > 9)
VisualF = HVlist[9];
if (HVlist.Count > 10)
VisualG = HVlist[10];
}
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:
RobotA = new EpsonRobotVM(CurrentMachine, 1);//初始化爱普生机器人
RobotB = new EpsonRobotVM(CurrentMachine, 2);//初始化爱普生机器人
break;
case 1:
RobotA = new FanucRobotVM(CurrentMachine);//初始化发那科机器人
break;
case 2:
RobotA = new QkmRobotVM(CurrentMachine);//初始化李群机器人
break;
case 3:
RobotA = new TurinRobotVM(CurrentMachine);//图灵机器人
break;
case 4:
RobotA = new YamahaRobotVM(CurrentMachine);//雅马哈
break;
}
RobotA.eventExcepReport += ExcepStop;
RobotA.ShuaxinPointing += Robot_ShuaxinPointing;
TabItem tbai = new TabItem() { Content = RobotA.MyWindow };
//tbai.SetResourceReference(TabItem.HeaderProperty, "机器人"); //设定资源引用 即可进行语言的切换
tbai.Header = "上料机器人";
tbai.SetBinding(TabItem.VisibilityProperty, new Binding("AllVis"));
TabItemList.Add(tbai);
RobotB.eventExcepReport += ExcepStop;
RobotB.ShuaxinPointing += Robot_ShuaxinPointing;
tbai = new TabItem() { Content = RobotB.MyWindow };
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);
TabItem t3 = new TabItem() { Header = "输入", Content = InputGrid };
TabItemList.Add(t3);
TabItem t4 = new TabItem() { Header = "输出", Content = OutputGrid };
TabItemList.Add(t4);
SelectTabItem = TabItemList[0];
}
#endregion
#region 前站回调函数
/// <summary>
/// 前站发来的字符串拆解
/// </summary>
List<string> NewsList { get; set; }
/// <summary>
/// 当前回流请求状态
/// </summary>
string CurrHuiliuStr { get; set; }
int SwitchMachineID { get; set; }
/// <summary>
/// 前站发来的信息
/// </summary>
string FrontStationInfo { get; set; }
/// <summary>
/// 前站回调函数
/// </summary>
/// <param name="str"></param>
private void FrontStation_ReceiveCallback(string str)
{
}
#endregion
#region 后站回调函数
/// <summary>
/// 当前接收到的下一站信息
/// </summary>
string CurrNextStr { get; set; }
/// <summary>
/// 后站发来的字符串拆解
/// </summary>
List<string> NextStrList { get; set; }
/// <summary>
/// 后站回调函数
/// </summary>
/// <param name="str"></param>
private void NextStation_ReceiveCallback(string str)
{
}
#endregion
#region 刷新机械手阵列点位
/// <summary>
/// 刷新机械手阵列点位
/// </summary>
/// <param name="hv"></param>
private void Robot_ShuaxinPointing(int type)
{
try
{
Tray1.PointListInitialization(RobotA);
Tray2.PointListInitialization(RobotB);
}
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)
{
OutputList[Y110出料仓调速电机1].Switchs = false;//空盘皮带1
OutputList[Y111出料仓调速电机2].Switchs = false;//空盘皮带1
OutputList[Y108入料仓调速电机1].Switchs = false;//空盘皮带1
OutputList[Y109入料仓调速电机2].Switchs = false;//空盘皮带1
if (homeing == false)
{
foreach (var item in CurrentMachine.MotionPointList)
{
item.PointStop();
}
}
if (RunStatu != RunStatuEnum.Stop && RunStatu != RunStatuEnum.EmgStop && RunStatu != RunStatuEnum.Exceptional)
{
RunStatu = RunStatuEnum.Exceptional;
ShowStatu.StatuInfo = showMag;
OutputList[Y001红灯].Switchs = true; //红灯
OutputList[Y002黄灯].Switchs = false; //黄灯
OutputList[Y000绿灯].Switchs = false; //绿灯
OutputList[Y003蜂鸣器].Switchs = true; //蜂鸣器
//记录异常信息
try
{
RecordLog(showMag);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
#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[Y001红灯].Switchs = false; //红灯
OutputList[Y002黄灯].Switchs = true; //黄灯
OutputList[Y000绿灯].Switchs = false; //绿灯
OutputList[Y003蜂鸣器].Switchs = true; //蜂鸣器
//记录异常信息
try
{
RecordLog(showMag);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
ExcepNoIng = true;
}
catch
{
}
}
public void ExcepNoStopClear(string showMag)
{
if (ShowStatu.StatuInfo == showMag)
{
ShowStatu.StatusForeground = ColorStr.Black;
OutputList[Y001红灯].Switchs = false; //红灯
OutputList[Y002黄灯].Switchs = false; //黄灯
OutputList[Y000绿灯].Switchs = true; //绿灯
OutputList[Y003蜂鸣器].Switchs = false; //蜂鸣器
if (RunStatu == RunStatuEnum.Normal)
{
ShowStatu.StatusBackground = ColorStr.Green;
ShowStatu.StatuInfo = "运行中";
}
else
{
ShowStatu.StatusBackground = ColorStr.Yellow;
ShowStatu.StatuInfo = "停止中";
}
}
}
#endregion
#region 启动按钮 +void Start(object per)
/// <summary>
/// 启动按钮
/// </summary>
/// <param name="per"></param>
public void Start(object per)
{
if (GoHomeFlow.RunStep != GengralProcessEnum.End)
{
return;
}
ExcepNoIng = false;
if (RunStatu == RunStatuEnum.Normal)
{
ShowStatu.StatusBackground = ColorStr.Green;
ShowStatu.StatusForeground = ColorStr.Black;
ShowStatu.StatuInfo = "运行中";
OutputList[Y001红灯].Switchs = false; //红灯
OutputList[Y002黄灯].Switchs = false; //黄灯
OutputList[Y000绿灯].Switchs = true; //绿灯
OutputList[Y003蜂鸣器].Switchs = false; //蜂鸣器
}
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("开始运行");
}
}
catch (Exception)
{
MessageBox.Show("开启运行线程失败,请联系系统管理员或重启软件稍后重试");
return;
}
}
#endregion
#region 停止按钮 void Stop(object per)
/// <summary>
/// 停止工作
/// </summary>
/// <param name="per"></param>
public void Stop(object per)
{
OutputList[Y110出料仓调速电机1].Switchs = false;//空盘皮带1
OutputList[Y111出料仓调速电机2].Switchs = false;//空盘皮带1
OutputList[Y108入料仓调速电机1].Switchs = false;//空盘皮带1
OutputList[Y109入料仓调速电机2].Switchs = false;//空盘皮带1
if (homeing == false)
{
foreach (var item in CurrentMachine.MotionPointList)
{
item.PointStop();
}
}
testing = false;
//var shalf = MCVM.AllShaftList.Where(s => s.ShaftName == "翻转轴").FirstOrDefault();
//shalf.ShaftStop();
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;
//}
CloseOut();
AllVis = Visibility.Collapsed;
ShowStatu = new ShowInfo();
RunStatu = RunStatuEnum.Prepare;
ExcepList = new ObservableCollection<RecordInfo>();
//EnableAnquanmen = true;
if (MCVM != null)
{
foreach (var item in MCVM.AllShaftList)
{
item.ShaftStop();
item.org_Successful = false;
item.HomeStep = GengralProcessEnum.Start;
}
}
if (RobotA != null)
{
RobotA.HomeStep = GengralProcessEnum.Start;
}
if (RobotB != null)
{
RobotB.HomeStep = GengralProcessEnum.Start;
}
GoHomeFlow = new FlowModel("回原点流程");
//FlowList.ForEach(x => { x = new FlowModel("1"); });//重置所以流程
//XizuiList.ForEach(w => w.State.StatusBackground = ColorStr.White);
}
private void CloseOut()
{
for (int i = 0; i < OutputList.Count; i++)
{
if (i != Y210翻转真空吸
&& i != Y200搬运真空吸
&& i != Y202左机械手真空吸
&& i != Y204右机械手真空吸
&& i != Y208右贴合吸料真空吸
&& i != Y206左贴合吸料真空吸
)
{
OutputList[i].Switchs = false;
}
}
}
#endregion
#region 紧急停止按钮 +void EmgStop()
/// <summary>
/// 紧急停止工作
/// </summary>
public void EmgStop()
{
if (RunStatu != RunStatuEnum.EmgStop)
{
if (ThRun != null) //停止线程
{
ThRun.Abort();
ThRun = null;
}
foreach (var item in CurrentMachine.MotionPointList)
{
item.PointStop();
}
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;
}
// LinelabelList[14].State.StatuInfo = "15";
//CurrentMachine.MyQita.LineState = LinelabelList.Select(w => w.State).ToList();//记录线体状态
dal.UpdateProductionData(CurrentMachine); //更新生产数据
Tray1.GetTrayState(CurrentMachine);
Tray2.GetTrayState(CurrentMachine);
dal.UpdateMachineData(CurrentMachine);
dal.UpdateSystemPar(SystemPar);
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 (VisualC != null)
{
VisualC.CamReset(0);
}
if (VisualD != null)
{
VisualD.CamReset(0);
}
if (VisualE != null)
{
VisualE.CamReset(0);
}
VisualA1.CamReset(0);
VisualB1.CamReset(0);
VisualC1.CamReset(0);
if (MCVM != null)
{
foreach (FeiYuCard cd in MCVM.CardList)
{
cd.MoveFunction_Estop();
}
}
if (RobotA != null)
{
dal.UpdateRobotModel(RobotA.RobotPer);
}
if (RobotB != null)
{
dal.UpdateRobotModel(RobotB.RobotPer);
}
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);
}
/// <summary>
/// 记录检查LOG
/// </summary>
/// <param name="CM"></param>
private void WriteCheckLog(ObservableCollection<RangeValueModel> rangeValueModels, string barcode)
{
lock (this)
{
path = @"D:\\CheckLog\";
paths = @"D:\\CheckLog\" + DateTime.Now.ToString("D") + ".CSV";
//实例化字符串流
StringBuilder sb = new StringBuilder();
string JieGuo = "";
//创建文件夹
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
//创建文件
if (!File.Exists(paths))
{
sb.Append("SN,");
sb.Append("时间,");
foreach (var item in rangeValueModels)
{
sb.Append(item.RanggeName).Append(",");
}
sb.Append("结果").Append(",");
sb.Append("\r");
}
using (FileStream fs = new FileStream(paths, FileMode.Append))
{
using (StreamWriter sw = new StreamWriter(fs, UnicodeEncoding.GetEncoding("GB2312"))) //UnicodeEncoding.GetEncoding("GB2312")
{
sb.Append(barcode).Append(",");
sb.AppendFormat("{0},", DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss.fff"));
foreach (var item in rangeValueModels)
{
sb.Append(item.ActualValue).Append(",");
}
if (ZhuanPanList[6].State.StatusBackground == ColorStr.Green)
{
JieGuo = "OK";
}
else if (ZhuanPanList[6].State.StatusBackground == ColorStr.Red)
{
JieGuo = "NG";
}
sb.Append(JieGuo).Append(",");
//将字符串流数据写入文件
sw.WriteLine(sb);
//刷新文件流
sw.Flush();
}
}
}
}
#endregion
#region 吸嘴对象
private Grid _RobotPickerGrid;
public Grid RobotPickerGrid
{
get { return _RobotPickerGrid; }
set
{
_RobotPickerGrid = value;
this.RaisePropertyChanged("RobotPickerGrid");
}
}
public List<HandModel> RobotPickerList { get; set; }
/// <summary>
/// 获取吸嘴Grid
/// </summary>
#endregion
#region 取料放入转盘流程
public FlowModel TakeFlow { get; set; } = new FlowModel("取料流程");
private MyLabel take;
public VisualEngineeringItems TakeVEI { get; set; }
RobotPoint TempTakePoint { get; set; }
/// <summary>
/// 取料运行
/// </summary>
public void TakeRun(FlowModel MyFlow)
{
switch (MyFlow.Step)
{
case 0:
TempTakePoint = RobotA.RobotPointList.Where(w => w.PointName == "待机点").FirstOrDefault();
if (TempTakePoint.Safe)
{
RobotA.RunRobotPoint(TempTakePoint);
MyFlow.Step++;
}
break;
case 1:
if (RobotA.RcvShowInfo.Contains("runpointok"))
{
robotASafe = true;
RobotSafeToFlipLeft = true;
if (InputList[X201左机械手真空检].LightUp)
{
MyFlow.Step = 6;
}
else
{
MyFlow.Step++;
}
}
else if (TimeOutValidation(MyFlow.RunTime, 20000, TempTakePoint.PointName + "机器人A到位超时"))
{
MyFlow.Step--;
}
break;
case 2:
take = Tray1.MyLabelList.Where(w => w.Product.StateColour == ColorStr.Green).FirstOrDefault();
if (take != null)
{
if ((EnTakeProduct || RunningMode) && EnRobotA)
{
MyFlow.Step = 100;
}
ExcepNoStopClear("设备运行中超过120秒未动做,请检查");
}
else if (MyFlow.RunTime.AddSeconds(120)<DateTime.Now&& RunStatu == RunStatuEnum.Normal)
{
ExcepNoStop("设备运行中超过120秒未动做,请检查");
MyFlow.RunTime = DateTime.Now;
}
break;
case 100:
robotASafe = false;
TempTakePoint = take.VisonPoint;
if (TempTakePoint.Safe)
{
RobotA.RunRobotPoint(TempTakePoint);
MyFlow.Step++;
}
break;
case 101:
if (RobotA.RcvShowInfo.Contains("runpointok"))
{
MyFlow.Step++;
}
else if (TimeOutValidation(MyFlow.RunTime, 20000, "机器人A到位超时"))
{
MyFlow.Step--;
}
break;
case 102:
OutputList[Y008取料上光源].Switchs = true;
var takeVEI = VisualA.VisualEngineeringList[0].VisualEngineeringItemsList[1];
// if (RunningMode || VisualA.GrayInrangeArea(takeVEI))
if (RunningMode || VisualA.GrayInrangeAreaPro(takeVEI))
{
MyFlow.Step = 3;
}
else if (MyFlow.RunTime.AddSeconds(1) < DateTime.Now)
{
ExcepStop("取料拍照未检出产品!");
// take.Product.StateColour = ColorStr.White;
MyFlow.Step = 0;
}
break;
case 3:
robotASafe = false;
TempTakePoint = Coper(take.TakePutPoint);
if (take.TakePutPoint.Safe)
{
TempTakePoint.Safe = true;
RobotA.RunRobotPoint(TempTakePoint);
MyFlow.Step++;
}
break;
case 4:
if (RobotA.RcvShowInfo.Contains("runpointok"))
{
MyFlow.Step++;
}
else if (TimeOutValidation(MyFlow.RunTime, 20000, "机器人A到位超时"))
{
MyFlow.Step--;
}
break;
case 5:
if (RunningMode == false)
OutputList[Y202左机械手真空吸].Switchs = true; //吸真空
if (InputList[X201左机械手真空检].LightUp || RunningMode)
{
if (MyFlow.RunTime.AddSeconds(0.5) < DateTime.Now)
{
MyFlow.Step++;
}
}
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
ExcepStop(InputList[X201左机械手真空检].InputMeaning + "异常");
MyFlow.Step = 0;
}
break;
case 6:
OutputList[Y009取料下光源].Switchs = true;
var vPoint = RobotA.RobotPointList.Where(w => w.PointName == "下视觉").FirstOrDefault();
if (vPoint.Safe)
{
TempTakePoint = Coper(vPoint);
TempTakePoint.Safe = true;
RobotA.RunRobotPoint(TempTakePoint);
MyFlow.Step++;
}
break;
case 7:
if (RobotA.RcvShowInfo.Contains("runpointok"))
{
if (InputList[X201左机械手真空检].LightUp)
{
robotASafe = true;
if (take != null)
take.Product.StateColour = ColorStr.White;
RobotPickerList[0].VisionOffsetValue = new OffsetValueModel();
MyFlow.Step++;
}
else
{
ExcepStop("机械手真空未达到,请检查是否掉料");
MyFlow.Step = 0;
}
}
else if (TimeOutValidation(MyFlow.RunTime, 20000, "机器人A到位超时"))
{
MyFlow.Step--;
}
break;
case 8:
TakeVEI = VisualA1.VisualEngineeringList[0].VisualEngineeringItemsList[0];
if (RunningMode || VisualA1.FeatureMatchingIng(TakeVEI))
{
if (Math.Abs(TakeVEI.MyRectangleModel.MyROI.ModelFeaturePiont.AngleU) < 5)
{
RobotPickerList[0].VisionOffsetValue.OffsetU = TakeVEI.MyRectangleModel.MyROI.ModelFeaturePiont.AngleU;
TempTakePoint.PointU -= TakeVEI.MyRectangleModel.MyROI.ModelFeaturePiont.AngleU;
MyFlow.Step++;
}
else
{
ExcepStop($"取料下视觉角度偏差过大");
}
}
else if (MyFlow.RunTime.AddMilliseconds(3000) < DateTime.Now)
{
if (InputList[X201左机械手真空检].LightUp || RunningMode)
{
ExcepStop("机器人A拍照异常");
}
else
{
if (take != null)
take.Product.StateColour = ColorStr.Green;
MyFlow.Step = 0;
}
}
break;
case 9:
if (RunningMode == false)
{
RobotA.RunRobotPoint(TempTakePoint);
}
MyFlow.Step++;
break;
case 10:
if (RobotA.RcvShowInfo.Contains("runpointok"))
{
MyFlow.Step++;
}
else if (TimeOutValidation(MyFlow.RunTime, 20000, "机器人A到位超时"))
{
MyFlow.Step--;
}
break;
case 11:
TakeVEI = VisualA1.VisualEngineeringList[0].VisualEngineeringItemsList[0];
if (RunningMode || VisualA1.FeatureMatchingIng(TakeVEI))
{
OutputList[Y009取料下光源].Switchs = false;
TempTakePoint = Coper(RobotA.RobotPointList.Where(w => w.PointName == "放料点").FirstOrDefault());
TempTakePoint.Safe = true;
//TempTakePoint.PointX -= VisualA1.CurrOffs.Y;
//TempTakePoint.PointY -= VisualA1.CurrOffs.X;
TempTakePoint.PointX -= VisualA1.CurrOffs.X;
TempTakePoint.PointY += VisualA1.CurrOffs.Y;
TempTakePoint.PointU -= RobotPickerList[0].VisionOffsetValue.OffsetU;
MyFlow.Step++;
}
break;
case 12:
if (LeftFlipList[0].State.StatusBackground == ColorStr.White && FlipLeftSafeToRobot)
{
RobotSafeToFlipLeft = false;
RobotA.RunRobotPoint(TempTakePoint);
MyFlow.Step++;
}
break;
case 13:
if (RobotA.RcvShowInfo.Contains("runpointok"))
{
MyFlow.Step++;
}
else if (TimeOutValidation(MyFlow.RunTime, 20000, "机器人A到位超时"))
{
MyFlow.Step--;
}
break;
case 14:
OutputList[Y202左机械手真空吸].Switchs = false; //吸真空
OutputList[Y306左翻转机构真空].Switchs = true; //吸真空
if (InputList[X310左翻转机构真空].LightUp || RunningMode)
{
LeftFlipList[0].State.StatusBackground = ColorStr.Blue;
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
ExcepStop(InputList[X310左翻转机构真空].InputMeaning + "异常");
}
break;
case 15:
TempTakePoint = RobotA.RobotPointList.Where(w => w.PointName == "扫码点").FirstOrDefault();
if (TempTakePoint.Safe)
{
RobotA.RunRobotPoint(TempTakePoint);
MyFlow.Step++;
}
break;
case 16:
if (RobotA.RcvShowInfo.Contains("runpointok"))
{
if (VisualA.SweepCode(VisualA.VisualEngineeringList[0].VisualEngineeringItemsList[0].MyRectangleModel))
{
LeftFlipList[0].State.StatuInfo = visualA.QrCodeStr;
MyFlow.Step++;
}
else
{
ExcepNoStop("扫码失败");
LeftFlipList[0].State.StatuInfo = "Test";
MyFlow.Step++;
}
}
else if (TimeOutValidation(MyFlow.RunTime, 20000, "机器人A到位超时"))
{
MyFlow.Step--;
}
break;
case 17:
TempTakePoint = RobotA.RobotPointList.Where(w => w.PointName == "待机点").FirstOrDefault();
if (TempTakePoint.Safe)
{
RobotA.RunRobotPoint(TempTakePoint);
MyFlow.Step++;
}
break;
case 18:
if (RobotA.RcvShowInfo.Contains("runpointok"))
{
RobotSafeToFlipLeft = true;
MyFlow.Step = 2;
}
else if (TimeOutValidation(MyFlow.RunTime, 20000, "机器人A到位超时"))
{
MyFlow.Step--;
}
break;
}
}
#endregion
#region 左翻转运行
public List<HandModel> LeftFlipList { get; set; }
private Grid _LeftFlipGrid;
public Grid LeftFlipGrid
{
get { return _LeftFlipGrid; }
set { _LeftFlipGrid = value; RaisePropertyChanged("LeftFlipGrid"); }
}
public bool FlipLeftSafeToRobot { get; private set; }
public bool RobotSafeToFlipLeft { get; private set; }
public FlowModel LeftFlipFlow { get; set; }
/// <summary>
/// 左翻转运行
/// </summary>
/// <param name="MyFlow"></param>
public void LeftFlipRun(FlowModel MyFlow)
{
switch (MyFlow.Step)
{
case 0:
FlipLeftSafeToRobot = false;
OutputList[Y310左翻转下位].Switchs = false;
if (InputList[X313左翻转上位].LightUp)
{
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
ExcepStop(InputList[X313左翻转上位].InputMeaning + "异常");
}
break;
case 1:
OutputList[Y306左翻转机构真空].Switchs = true;
if (InputList[X310左翻转机构真空].LightUp == false)
{
OutputList[Y306左翻转机构真空].Switchs = false;
MyFlow.Step++;
}
else
{
MyFlow.Step = 10;
}
break;
case 2:
OutputList[Y310左翻转下位].Switchs = false;
if (InputList[X311左翻转原位].LightUp == false)
{
OutputList[Y308左翻转到位].Switchs = false;
if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
ExcepStop(InputList[X311左翻转原位].InputMeaning + "异常");
}
}
else
{
FlipLeftSafeToRobot = true;
if (LeftFlipList[0].State.StatusBackground == ColorStr.Blue && RobotSafeToFlipLeft)
{
if (ZhuanPanList[0].State.StatusForeground == ColorStr.Blue) //Blue转到位 Gray转动中,Green工位完成
{
OutputList[Y306左翻转机构真空].Switchs = true;
FlipLeftSafeToRobot = false;
if (InputList[X310左翻转机构真空].LightUp)
{
MyFlow.Step++;
}
else
{
ExcepStop("左翻转真空未达到,请检查是否掉料");
}
}
}
else if (MyFlow.RunTime.AddSeconds(30) < DateTime.Now)
{
if (Tray1.MyLabelList.Where(w => w.Product.StateColour == ColorStr.Green).Any() == false
&& ZhuanPanList[0].State.StatusForeground == ColorStr.Blue
) //Blue转到位 Gray转动中,Green工位完成
{
ZhuanPanList[0].State.StatusForeground = ColorStr.Green;
MyFlow.RunTime = DateTime.Now;
}
else
{
MyFlow.RunTime = DateTime.Now;
}
}
}
break;
case 3:
OutputList[Y308左翻转到位].Switchs = true;
if (InputList[X312左翻转到位].LightUp)
{
OutputList[Y310左翻转下位].Switchs = true;
if (InputList[X314左翻转下位].LightUp)
{
OutputList[Y306左翻转机构真空].Switchs = false;
OutputList[Y305].Switchs = true;//真空破
if (InputList[X310左翻转机构真空].LightUp == false)
{
MyFlow.Step++;
}
}
}
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
ExcepStop(InputList[X312左翻转到位].InputMeaning + "异常");
}
break;
case 4:
if (MyFlow.RunTime.AddMilliseconds(1000) < DateTime.Now)
{
OutputList[Y310左翻转下位].Switchs = false;
if (InputList[X313左翻转上位].LightUp)
{
if (MyFlow.RunTime.AddMilliseconds(2000) < DateTime.Now)
{
OutputList[Y305].Switchs = false;
OutputList[Y308左翻转到位].Switchs = false;
if (InputList[X311左翻转原位].LightUp)
{
LeftFlipList[0].State.StatusBackground = ColorStr.White;
ZhuanPanList[0].Barcode = LeftFlipList[0].State.StatuInfo;
ZhuanPanList[0].State.StatusBackground = ColorStr.Blue;
ZhuanPanList[0].State.StatusForeground = ColorStr.Green;
LeftFlipList[0].State.StatuInfo = "";
MyFlow.Step = 0;
}
}
}
}
break;
}
}
#endregion
#region 取出流程
public FlowModel TakeOutFlow { get; set; } = new FlowModel("取出流程");
public V_RectangleModel TakeOutRM { get; set; }
public MyLabel PutLabel { get; set; }
RobotPoint TempTakeOutPoint { get; set; }
/// <summary>
/// 运行
/// </summary>
public void TakeOutRun(FlowModel MyFlow)
{
switch (MyFlow.Step)
{
case 0:
TempTakeOutPoint = RobotB.RobotPointList.Where(w => w.PointName == "待机点").FirstOrDefault();
if (TempTakeOutPoint.Safe)
{
RobotB.RunRobotPoint(TempTakeOutPoint);
MyFlow.Step++;
}
break;
case 1:
if (RobotB.RcvShowInfo.Contains("runpointok"))
{
RobotSafeToFlip = true;
robotBSafe = true;
MyFlow.Step++;
}
else if (TimeOutValidation(MyFlow.RunTime, 20000, TempTakeOutPoint.PointName + "机器人B到位超时"))
{
MyFlow.Step--;
}
break;
case 2:
if (FlipList[0].State.StatusBackground != ColorStr.White && FlipSafeToRobot)
{
MyFlow.Step++;
}
break;
case 3:
TempTakeOutPoint = RobotB.RobotPointList.Where(p => p.PointName == "取料点").FirstOrDefault();
if (TempTakeOutPoint.Safe)
{
RobotB.RunRobotPoint(TempTakeOutPoint);
MyFlow.Step++;
}
break;
case 4:
if (RobotB.RcvShowInfo.Contains("runpointok"))
{
MyFlow.Step++;
}
else if (TimeOutValidation(MyFlow.RunTime, 20000, TempTakeOutPoint.PointName + "机器人B到位超时"))
{
MyFlow.Step--;
}
break;
case 5:
if (RunningMode == false)
OutputList[Y204右机械手真空吸].Switchs = true; //吸真空
if (InputList[X202右机械手真空检].LightUp || RunningMode)
{
OutputList[Y210翻转真空吸].Switchs = false;
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
ExcepStop(InputList[X202右机械手真空检].InputMeaning + "异常");
}
break;
case 6:
TempTakeOutPoint = RobotB.RobotPointList.Where(p => p.PointName == "待机点").FirstOrDefault(); ;
if (TempTakeOutPoint.Safe)
{
RobotB.RunRobotPoint(TempTakeOutPoint);
MyFlow.Step++;
}
break;
case 7:
if (RobotB.RcvShowInfo.Contains("runpointok"))
{
RobotPickerList[1].State.StatusBackground = FlipList[0].State.StatusBackground;
FlipList[0].State.StatusBackground = ColorStr.White;
if (RobotPickerList[1].State.StatusBackground == ColorStr.Green)
{
CurrentMachine.Produce++;
MyFlow.Step++;
}
else
{
MyFlow.Step = 20;
}
CurrentMachine.Quantitys++;
}
else if (TimeOutValidation(MyFlow.RunTime, 20000, TempTakeOutPoint.PointName + "机器人B到位超时"))
{
MyFlow.Step--;
}
break;
case 8:
MyFlow.Step++;
break;
case 9:
MyFlow.Step++;
break;
case 10:
PutLabel = Tray2.MyLabelList.Where(w => w.Product.StateColour == ColorStr.Blue).FirstOrDefault();
if (PutLabel != null && EnRobotB && EnPutProduct)
{
robotBSafe = false;
TempTakeOutPoint = PutLabel.TakePutPoint;
if (TempTakeOutPoint.Safe)
{
RobotB.RunRobotPoint(TempTakeOutPoint);
MyFlow.Step++;
}
}
else if (MyFlow.RunTime.AddSeconds(20) < DateTime.Now)
{
ExcepNoStop("出料盘满,请补充空盘");
MyFlow.RunTime = DateTime.Now;
}
break;
case 11:
if (RobotB.RcvShowInfo.Contains("runpointok"))
{
MyFlow.Step++;
}
else if (TimeOutValidation(MyFlow.RunTime, 20000, "机器人B到位超时"))
{
MyFlow.Step--;
}
break;
case 12:
OutputList[Y204右机械手真空吸].Switchs = false;
if (InputList[X202右机械手真空检].LightUp == false)
{
PutLabel.Product.StateColour = ColorStr.Green;
MyFlow.Step = 0;
}
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
ExcepStop(InputList[X202右机械手真空检].InputMeaning + "异常");
}
break;
case 20:
robotBSafe = false;
TempTakeOutPoint = RobotB.RobotPointList.Where(w => w.PointName == "NG放料点").FirstOrDefault();
MyFlow.Step++;
break;
case 21:
if (TempTakeOutPoint.Safe)
{
RobotSafeToFlip = false;
RobotB.RunRobotPoint(TempTakeOutPoint);
MyFlow.Step++;
}
break;
case 22:
if (RobotB.RcvShowInfo.Contains("runpointok"))
{
MyFlow.Step++;
}
else if (TimeOutValidation(MyFlow.RunTime, 20000, TempTakeOutPoint.PointName + "机器人B到位超时"))
{
MyFlow.Step--;
}
break;
case 23:
OutputList[Y204右机械手真空吸].Switchs = false;
if (InputList[X202右机械手真空检].LightUp == false)
{
NG = true;
MyFlow.Step = 0;
}
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
ExcepStop(InputList[X202右机械手真空检].InputMeaning + "异常");
}
break;
}
}
#endregion
#region Feed1
private Grid _Feed1Grid;
/// <summary>
/// Grid
/// </summary>
public Grid Feed1Grid
{
get { return _Feed1Grid; }
set { _Feed1Grid = value; RaisePropertyChanged("Feed1Grid"); }
}
/// <summary>
/// Feed1
/// </summary>
public List<HandModel> Feed1List { get; set; }
public FlowModel Feed1Flow { get; set; } = new FlowModel("Feed1");
/// <summary>
/// 飞达运行
/// </summary>
public void Feed1Run(FlowModel MyFlow)
{
switch (MyFlow.Step)
{
case 0:
if (Feed1List.Where(w => w.State.StatusBackground != ColorStr.Blue).Count() == Feed1List.Count)
{
if (!RunningMode)
{
MyFlow.Step++;
MyFlow.RunTime = DateTime.Now;
}
else
{
Feed1List.ForEach(w => w.State.StatusBackground = ColorStr.Blue);
}
}
break;
case 1:
OutputList[Y304左飞达送料信号].Switchs = true; //右飞达出标请求
if (RunningMode || InputList[X303左飞达送料完成].LightUp && MyFlow.RunTime.AddMilliseconds(1500) < DateTime.Now)
{
OutputList[Y304左飞达送料信号].Switchs = false; //右飞达出标请求
Feed1List.ForEach(w => w.State.StatusBackground = ColorStr.Blue);
MyFlow.Step = 0;
}
else if (MyFlow.RunTime.AddMilliseconds(30000) < DateTime.Now)
{
OutputList[Y304左飞达送料信号].Switchs = false;
OutputList[Y303右飞达复位].Switchs = true;
MyFlow.Step = 0;
ExcepStop("飞达出料异常");
MyFlow.RunTime = DateTime.Now;
}
break;
case 2:
OutputList[Y303右飞达复位].Switchs = false;
if (MyFlow.RunTime.AddMilliseconds(1000) < DateTime.Now)
{
OutputList[Y303右飞达复位].Switchs = false;
MyFlow.Step = 0;
}
break;
}
}
#endregion
#region Feed2
private Grid _Feed2Grid;
/// <summary>
/// Grid
/// </summary>
public Grid Feed2Grid
{
get { return _Feed2Grid; }
set { _Feed2Grid = value; RaisePropertyChanged("Feed2Grid"); }
}
/// <summary>
/// Feed1
/// </summary>
public List<HandModel> Feed2List { get; set; }
public FlowModel Feed2Flow { get; set; } = new FlowModel("Feed2");
/// <summary>
/// 飞达运行
/// </summary>
public void Feed2Run(FlowModel MyFlow)
{
switch (MyFlow.Step)
{
case 0:
if (Feed2List.Where(w => w.State.StatusBackground == ColorStr.Blue).Any() == false)
{
if (!RunningMode)
{
MyFlow.Step++;
}
else
{
Feed2List.ForEach(w => w.State.StatusBackground = ColorStr.Blue);
}
}
break;
case 1:
OutputList[Y303右飞达复位].Switchs = true;
OutputList[Y302右飞达].Switchs = true; //右飞达出标请求
if (MyFlow.RunTime.AddMilliseconds(500) < DateTime.Now)
{
ExcepNoStopClear("飞达出料异常");
MyFlow.Step++;
OutputList[Y302右飞达].Switchs = false; //右飞达出标请求
OutputList[Y303右飞达复位].Switchs = false;
}
break;
case 2:
if (RunningMode || InputList[X308右飞达料到位].LightUp && MyFlow.RunTime.AddMilliseconds(1000) < DateTime.Now)
{
OutputList[Y302右飞达].Switchs = false; //右飞达出标请求
Feed2List.ForEach(w => w.State.StatusBackground = ColorStr.Blue);
MyFlow.Step = 0;
}
else if (MyFlow.RunTime.AddMilliseconds(5000) < DateTime.Now)
{
OutputList[Y302右飞达].Switchs = false; //右飞达出标请求
OutputList[Y303右飞达复位].Switchs = true;
MyFlow.Step++;
ExcepNoStop("飞达出料异常");
}
break;
case 3:
if (MyFlow.RunTime.AddMilliseconds(1000) < DateTime.Now)
{
OutputList[Y302右飞达].Switchs = false; //右飞达出标请求
OutputList[Y303右飞达复位].Switchs = false;
MyFlow.Step = 0;
}
break;
}
}
#endregion
#region 翻转
public List<HandModel> FlipList { get; set; }
private Grid _FlipGrid;
public Grid FlipGrid
{
get { return _FlipGrid; }
set { _FlipGrid = value; RaisePropertyChanged("FlipGrid"); }
}
MotionPointModel FlipPoint { get; set; }
public FlowModel FlipFlow { get; set; }
/// <summary>
/// 右翻转运行
/// </summary>
/// <param name="MyFlow"></param>
public void FlipRun(FlowModel MyFlow)
{
switch (MyFlow.Step)
{
case 0:
FlipSafeToRobot = false;
FlipPoint = CurrentMachine.MotionPointList.Where(w => w.PointName == "翻转Z翻转位").FirstOrDefault();
if (FlipPoint.PointRun(MCVM.AllShaftList))
{
MyFlow.Step++;
}
break;
case 1:
if (InputList[X205翻转真空检].LightUp == false)
{
MyFlow.Step++;
}
else
{
MyFlow.Step = 10;
}
break;
case 2:
//if (InputList[X207翻转气缸反面].LightUp == false)
//{
// OutputList[Y104翻转气缸反面].Switchs = true;
//}
if (InputList[X206翻转气缸正面].LightUp == false)
{
OutputList[Y103翻转气缸正面].Switchs = true;
}
else
{
if (ZhuanPanList[7].State.StatusForeground == ColorStr.Blue && RobotSafeToFlip) //Blue转到位 Gray转动中,Green工位完成
{
if (ZhuanPanList[7].State.StatusBackground != ColorStr.White) // White 无料 blue 有料 Yello 已贴 green/red已检
{
FlipPoint = CurrentMachine.MotionPointList.Where(w => w.PointName == "翻转Z取料位").FirstOrDefault();
FlipPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.Step++;
}
}
}
break;
case 3:
if (FlipPoint.PointRun(MCVM.AllShaftList))
{
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddSeconds(10) < DateTime.Now)
{
ExcepStop("翻转轴到位超时");
FlipPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.Step--;
}
break;
case 4:
if (RunningMode == false)
OutputList[Y210翻转真空吸].Switchs = true; //吸真空
if (InputList[X205翻转真空检].LightUp || RunningMode)
{
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
ExcepStop(InputList[X205翻转真空检].InputMeaning + "异常");
}
break;
case 5:
MyFlow.Step = 10;
break;
case 10:
FlipPoint = CurrentMachine.MotionPointList.Where(w => w.PointName == "翻转Z翻转位").FirstOrDefault();
MyFlow.Step++;
break;
case 11:
if (FlipPoint.PointRun(MCVM.AllShaftList))
{
if (InputList[X205翻转真空检].LightUp)
{
if (ZhuanPanList[7].State.StatusBackground != ColorStr.White)
{
FlipList[0].State.StatusBackground = ZhuanPanList[7].State.StatusBackground;
}
else
{
FlipList[0].State.StatusBackground = ColorStr.Red;
}
ZhuanPanList[7].State.StatusBackground = ColorStr.White;
ZhuanPanList[7].State.StatusForeground = ColorStr.Green;
MyFlow.Step++;
}
else
{
ExcepStop("右翻转真空未达到,请检查是否掉料");
MyFlow.Step = 2;
}
}
else if (MyFlow.RunTime.AddSeconds(10) < DateTime.Now)
{
ExcepStop("翻转轴到位超时");
FlipPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.Step--;
}
break;
case 12:
//OutputList[Y103翻转气缸正面].Switchs = true;
//if (InputList[X206翻转气缸正面].LightUp)
//{
// MyFlow.Step++;
//}
OutputList[Y103翻转气缸正面].Switchs = false;
if (InputList[X207翻转气缸反面].LightUp)
{
MyFlow.Step++;
}
break;
case 13:
if (InputList[X205翻转真空检].LightUp)
{
FlipPoint = CurrentMachine.MotionPointList.Where(w => w.PointName == "翻转Z待取位").FirstOrDefault();
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
ExcepStop(InputList[X205翻转真空检].InputMeaning + "异常");
MyFlow.Step = 0;
}
break;
case 14:
if (FlipPoint.PointRun(MCVM.AllShaftList))
{
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddSeconds(10) < DateTime.Now)
{
ExcepStop("翻转轴到位超时");
FlipPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.Step--;
}
break;
case 15:
FlipSafeToRobot = true;
if (FlipList[0].State.StatusBackground == ColorStr.White)
{
MyFlow.Step = 0;
}
break;
}
}
#endregion
#region 转盘 检查
private Grid _ZhuanPanGrid;
/// <summary>
/// Grid
/// </summary>
public Grid ZhuanPanGrid
{
get { return _ZhuanPanGrid; }
set { _ZhuanPanGrid = value; RaisePropertyChanged("ZhuanPanGrid"); }
}
/// <summary>
/// 转盘 White 无料 blue 有料 Yello 已贴 green/red已检
/// </summary>
public List<HandModel> ZhuanPanList { get; set; }
/// <summary>
/// 转盘点位
/// </summary>
MotionPointModel TransmitPoint { get; set; }
public V_RectangleModel CheckRM { get; set; }
/// <summary>
/// 铁件偏移
/// </summary>
MyPoint Point1 = new MyPoint();
/// <summary>
/// Sponge偏移
/// </summary>
MyPoint Point2 = new MyPoint();
public FlowModel ZhuanPanFlow { get; set; } = new FlowModel("转盘");
/// <summary>
/// 转盘运行
/// </summary>
public void ZhuanPanRun(FlowModel MyFlow)
{
switch (MyFlow.Step)
{
case 0:
ZhuanPanList[1].State.StatusForeground = ColorStr.Green;
if (ZhuanPanList[2].State.StatusBackground == ColorStr.White)
{
ZhuanPanList[2].State.StatusForeground = ColorStr.Green;
}
ZhuanPanList[3].State.StatusForeground = ColorStr.Green;
if (ZhuanPanList[4].State.StatusBackground == ColorStr.White)
{
ZhuanPanList[4].State.StatusForeground = ColorStr.Green;
}
ZhuanPanList[5].State.StatusForeground = ColorStr.Green;
if (ZhuanPanList[6].State.StatusBackground == ColorStr.White)
{
ZhuanPanList[6].State.StatusForeground = ColorStr.Green;
}
if (ZhuanPanList[7].State.StatusBackground == ColorStr.White)
{
ZhuanPanList[7].State.StatusForeground = ColorStr.Green;
}
MyFlow.Step++;
break;
case 1:
ZhuanPanList[5].State.StatusForeground = ColorStr.Green;
var complete = ZhuanPanList.Where(z => z.State.StatusForeground == ColorStr.Green).Count();
if (complete == ZhuanPanList.Count)
{
TransmitPoint = Coper(CurrentMachine.MotionPointList.Where(w => w.PointName == "转盘起始位").FirstOrDefault());
TransmitPoint.GetInterpolationPer(MCVM.AllShaftList);//实例化点位
TransmitPoint.Shaft_U.GoZero();//轴里程数归零
TransmitPoint.ShaftPoint_U = +45; //CurrentMachine.MyQita.IntervalValue;//移动距离位设定的移动长度
TransmitPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.Step++;
}
break;
case 2:
OutputList[Y212左拍照检底部吸盘上位].Switchs = false;
OutputList[Y312右拍照检底部吸盘上位].Switchs = false;//顶升气缸下降
OutputList[Y105顶升气缸上位].Switchs = false;//顶升气缸下降
if (TransmitPoint.Shaft_U.ActualDir == 0)
{
//顶升气缸在下位
if (InputList[X209顶升气缸下位].LightUp
&& InputList[X211左拍照检底部吸盘下位].LightUp
&& InputList[X214右拍照检底部吸盘下位].LightUp)
{
MyFlow.Step++;
MyFlow.RunTime = DateTime.Now;
}
else if (MyFlow.RunTime.AddSeconds(3) < DateTime.Now)
{
if (InputList[X209顶升气缸下位].LightUp == false) ExcepStop("X209顶升气缸下位");
if (InputList[X211左拍照检底部吸盘下位].LightUp == false) ExcepStop("X211左拍照检底部吸盘下位");
if (InputList[X214右拍照检底部吸盘下位].LightUp == false) ExcepStop("X214右拍照检底部吸盘下位");
MyFlow.RunTime = DateTime.Now;
}
}
else if (MyFlow.RunTime.AddMilliseconds(1000) < DateTime.Now)
{
TransmitPoint.Shaft_U.GoZero();//轴里程数归零
MyFlow.RunTime = DateTime.Now;
}
break;
case 3:
if (InputList[X209顶升气缸下位].LightUp
&& InputList[X211左拍照检底部吸盘下位].LightUp
&& InputList[X214右拍照检底部吸盘下位].LightUp
&& PressSafe
)
{
//移动到位
if (MCVM.PointRun(TransmitPoint))
{
//整体状态向后移动一格
for (int i = ZhuanPanList.Count - 1; i > 0; i--)
{
ZhuanPanList[i].State.StatusBackground = ZhuanPanList[i - 1].State.StatusBackground;
ZhuanPanList[i].Barcode = ZhuanPanList[i - 1].Barcode;
ZhuanPanList[i - 1].State.StatusBackground = ColorStr.White;
}
ZhuanPanList.ForEach(w => w.State.StatusForeground = ColorStr.Blue);//Blue转到位 Gray转动中,Green工位完成
MyFlow.Step = 0;
}
else if (TimeOutValidation(MyFlow.RunTime, 10000, "转盘移动超时"))
{
MyFlow.RunTime = DateTime.Now;
}
}
else
{
MyFlow.RunTime = DateTime.Now;
}
break;
}
}
#endregion
#region NG
private Grid _NGGrid;
/// <summary>
/// Grid
/// </summary>
public Grid NGGrid
{
get { return _NGGrid; }
set { _NGGrid = value; RaisePropertyChanged("NGGrid"); }
}
/// <summary>
/// Feed1
/// </summary>
public List<HandModel> NGList { get; set; }
#endregion
#region 料盘上料运行
/// <summary>
/// 上料起点
/// </summary>
MotionPointModel FeedingStart { get; set; }
/// <summary>
/// 上料终点
/// </summary>
MotionPointModel FeedingEnd { get; set; }
/// <summary>
/// 上料流程
/// </summary>
FlowModel TrayFeedFlow { get; set; }
/// <summary>
/// 投料就绪
/// </summary>
bool TouliaoReady { get; set; }
/// <summary>
/// 料仓允许取料
/// </summary>
bool EnTakeProduct { get; set; }
/// <summary>
/// 可以取空盘
/// </summary>
bool EnTakeTray { get; set; }
/// <summary>
/// 料盘上料运行
/// </summary>
private void TrayFeedRun(FlowModel MyFlow)
{
switch (MyFlow.RunStep)
{
case GengralProcessEnum.Start:
EnTakeProduct = false;
EnTakeTray = false;
FeedingStart = CurrentMachine.MotionPointList.Where(w => w.PointName == "上料下位").FirstOrDefault();
FeedingEnd = CurrentMachine.MotionPointList.Where(w => w.PointName == "上料上位").FirstOrDefault();
FeedingStart.PointRunStep = GengralProcessEnum.Start;
FeedingEnd.PointRunStep = GengralProcessEnum.Start;
OutputList[Y108入料仓调速电机1].Switchs = false;//上料缓存皮带
OutputList[Y109入料仓调速电机2].Switchs = false;//上料皮带
OutputList[Y100料仓入缓存阻挡气缸].Switchs = true;//阻挡气缸
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
break;
case GengralProcessEnum.Step1:
//上料区必须无盘
if (!InputList[X102料仓入升降对射1].LightUp && !InputList[X103料仓入升降对射2].LightUp)
{
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
}
else if (InputList[X102料仓入升降对射1].LightUp && InputList[X103料仓入升降对射2].LightUp)
{
FeedingEnd.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunStep = GengralProcessEnum.Step10;
MyFlow.RunTime = DateTime.Now;
}
break;
case GengralProcessEnum.Step2:
if (InputList[X102料仓入升降对射1].LightUp != InputList[X103料仓入升降对射2].LightUp)
{
FeedingStart.PointStop();
ExcepStop("缓存对射光电异常:请检查");
break;
}
//移动到起始位置
if (FeedingStart.PointRun(MCVM.AllShaftList))
{
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
}
else if (TimeOutValidation(MyFlow.RunTime, 100000, FeedingStart.PointName + "移动超时"))
{
FeedingStart.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
}
break;
case GengralProcessEnum.Step3:
//投料区捡知
if (InputList[X100料仓入缓存对射1].LightUp && InputList[X101料仓入缓存对射2].LightUp)
{
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
}
else
if (TouliaoReady)
{
ExcepNoStopClear("等待投料");
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
}
else if (MyFlow.RunTime.AddSeconds(1) < DateTime.Now)
{
ExcepNoStop("等待投料");
MyFlow.RunTime = DateTime.Now;
}
break;
case GengralProcessEnum.Step4:
OutputList[Y100料仓入缓存阻挡气缸].Switchs = false;
OutputList[Y108入料仓调速电机1].Switchs = true;//上料缓存皮带
OutputList[Y109入料仓调速电机2].Switchs = true;//上料皮带
//上料区检知
if (InputList[X102料仓入升降对射1].LightUp && InputList[X103料仓入升降对射2].LightUp)
{
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
}
else if (MyFlow.RunTime.AddSeconds(10) < DateTime.Now)
{
ExcepNoStop("进料超时");
MyFlow.RunTime = DateTime.Now;
}
break;
case GengralProcessEnum.Step5:
OutputList[Y108入料仓调速电机1].Switchs = true;//上料缓存皮带
OutputList[Y109入料仓调速电机2].Switchs = true;//上料皮带
if (MyFlow.RunTime.AddSeconds(3) < DateTime.Now)
{
OutputList[Y108入料仓调速电机1].Switchs = false;//上料缓存皮带
OutputList[Y109入料仓调速电机2].Switchs = false;//上料皮带
OutputList[Y100料仓入缓存阻挡气缸].Switchs = true;//阻挡气缸
MyFlow.RunStep = GengralProcessEnum.Step10;
MyFlow.RunTime = DateTime.Now;
}
break;
case GengralProcessEnum.Step10:
//向结束位移动
if (FeedingEnd.PointRun(MCVM.AllShaftList))
{
if (InputList[X100料仓入缓存对射1].LightUp && InputList[X101料仓入缓存对射2].LightUp || !InputList[X100料仓入缓存对射1].LightUp && !InputList[X101料仓入缓存对射2].LightUp)
{
MyFlow.RunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
}
else
{
ExcepStop("料盘没推到位,请检查");
MyFlow.RunTime = DateTime.Now;
}
}
else if (InputList[X109入升降料仓上检知2].LightUp || (InputList[X108入升降料仓上检知1].LightUp && InputList[X109入升降料仓上检知2].LightUp)) //料盘对射感应到,轴停止
{
FeedingEnd.PointStop();//停止轴移动
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
FeedingEnd.PointRunStep = GengralProcessEnum.Start;
}
else if (MyFlow.RunTime.AddSeconds(20) < DateTime.Now)
{
FeedingEnd.PointRunStep = GengralProcessEnum.Start;
FeedingEnd.PointStop();//停止轴移动
MyFlow.RunTime = DateTime.Now;
}
break;
case GengralProcessEnum.Step11:
//盘中无料时
if (Tray1.MyLabelList.Where(w => w.Product.StateColour == ColorStr.Green).Count() <= 0)
{
Tray1.MyLabelList.ForEach(w => w.Product.StateColour = ColorStr.Green);
}
EnTakeProduct = true;
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
break;
case GengralProcessEnum.Step12:
//盘中无料时,激活取空盘信号,取走空盘后给料盘置为白色,继续上料
if (Tray1.MyLabelList.Where(w => w.Product.StateColour == ColorStr.White).Count() >= Tray1.MyLabelList.Count())
{
EnTakeProduct = false;
EnTakeTray = true;
if (RunningMode)
{
Tray1.MyLabelList.ForEach(t => t.Product.StateColour = ColorStr.Gray);
}
}
//盘中无料时并空料盘已被取走
else if (Tray1.MyLabelList.Where(w => w.Product.StateColour == ColorStr.Gray).Any())
{
EnTakeTray = false;
EnTakeProduct = false;
MyFlow.RunStep = GengralProcessEnum.Step10;
MyFlow.RunTime = DateTime.Now;
}
break;
}
}
#endregion
#region 空盘回收
/// <summary>
/// 空盘回收起点
/// </summary>
MotionPointModel BlankingStart { get; set; }
/// <summary>
/// 空盘回收满盘点
/// </summary>
MotionPointModel BlankingManPan { get; set; }
/// <summary>
/// 空盘回收下盘点
/// </summary>
MotionPointModel BlankingEnd { get; set; }
/// <summary>
/// 空盘回收流程
/// </summary>
FlowModel TrayBlankingFlow { get; set; }
/// <summary>
/// 允许放料
/// </summary>
bool EnPutProduct = false;
/// <summary>
/// 允许放盘
/// </summary>
bool EnPutTray = false;
/// <summary>
/// 空盘回收
/// </summary>
private void TrayBlankingRun(FlowModel MyFlow)
{
switch (MyFlow.Step)
{
case 0:
EnPutProduct = false;
EnPutTray = false;
BlankingStart = (CurrentMachine.MotionPointList.Where(w => w.PointName == "回收上位").FirstOrDefault()); //空盘回收起点
BlankingStart.PointRunStep = GengralProcessEnum.Start;
BlankingEnd = (CurrentMachine.MotionPointList.Where(w => w.PointName == "回收满位").FirstOrDefault()); //空盘回收终点
BlankingEnd.PointRunStep = GengralProcessEnum.Start;
MyFlow.Step++;
MyFlow.RunTime = DateTime.Now;
break;
case 1:
//回收光纤检知无料盘
if (!InputList[X111出升降料仓上检知2].LightUp
)
{
//运行到空盘回收起点
if (BlankingStart.PointRun(MCVM.AllShaftList))
{
MyFlow.Step = 3;
Tray2.MyLabelList.ForEach(w => w.Product.StateColour = ColorStr.Green);
MyFlow.RunTime = DateTime.Now;
}
}
else
{
BlankingStart.PointStop();//停止运行
MyFlow.Step++;
MyFlow.RunTime = DateTime.Now;
}
break;
case 2:
//向收盘终点运行
if (BlankingEnd.PointRun(MCVM.AllShaftList))
{
Tray2.MyLabelList.ForEach(w => w.Product.StateColour = ColorStr.Blue);
EnPutProduct = true;
BlankingEnd.PointStop();//停止运行
MyFlow.Step++;
MyFlow.RunTime = DateTime.Now;
}
else if (!InputList[X111出升降料仓上检知2].LightUp)
{
Tray2.MyLabelList.ForEach(w => w.Product.StateColour = ColorStr.Blue);
EnPutProduct = true;
BlankingEnd.PointStop();//停止运行
MyFlow.Step++;
MyFlow.RunTime = DateTime.Now;
}
else if (MyFlow.RunTime.AddSeconds(10) < DateTime.Now)
{
BlankingEnd.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
}
break;
case 3:
if (Tray2.MyLabelList.Where(w => w.Product.StateColour == ColorStr.Green).Count() >= Tray2.MyLabelList.Count() || PutWait)
{
BlankingEnd.GetInterpolationPer(MCVM.AllShaftList);
if (BlankingEnd.Shaft_Z.ActualDir <= BlankingEnd.ShaftPoint_Z)
{
MyFlow.Step = 20;
MyFlow.RunTime = DateTime.Now;
}
else
{
EnPutProduct = false;
EnPutTray = true;
MyFlow.Step++;
}
}
break;
case 4:
if (RunningMode == false)
{
if (Tray2.MyLabelList.Where(w => w.Product.StateColour == ColorStr.Yellow).Count() >= Tray2.MyLabelList.Count())
{
EnPutProduct = false;
EnPutTray = false;
BlankingEnd.PointRunStep = GengralProcessEnum.Start;
MyFlow.Step = 2;
}
}
else
{
MyFlow.Step = 2;
}
break;
case 20:
EnPutProduct = false;
EnPutTray = false;
//运行到下料点
BlankingManPan = Coper(CurrentMachine.MotionPointList.Where(w => w.PointName == "回收下位").FirstOrDefault()); //空盘回收终点
BlankingManPan.PointRunStep = GengralProcessEnum.Start;
MyFlow.Step++;
MyFlow.RunTime = DateTime.Now;
break;
case 21:
//到达下料区
if (BlankingManPan.PointRun(MCVM.AllShaftList))
{
MyFlow.Step++;
MyFlow.RunTime = DateTime.Now;
}
else if (TimeOutValidation(MyFlow.RunTime, 5000, BlankingManPan.PointName + "超时异常"))
{
BlankingManPan.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
}
break;
case 22:
//下料区无盘
if (!InputList[X106料仓出缓存对射1].LightUp && !InputList[X107料仓出缓存对射2].LightUp)
{
OutputList[Y110出料仓调速电机1].Switchs = true;//空盘皮带1
OutputList[Y111出料仓调速电机2].Switchs = true;//空盘皮带2
MyFlow.Step++;
MyFlow.RunTime = DateTime.Now;
}
break;
case 23:
//下料区有盘 且空盘区无盘
//InputList[X106料仓出缓存对射1].LightUp
// && InputList[X107料仓出缓存对射2].LightUp
// &&
if (!InputList[X104料仓出升降对射1].LightUp
&& !InputList[X105料仓出升降对射2].LightUp
&& (
(
InputList[X106料仓出缓存对射1].LightUp && InputList[X107料仓出缓存对射2].LightUp
) ))
{
if (MyFlow.RunTime.AddSeconds(2) < DateTime.Now)
{
OutputList[Y110出料仓调速电机1].Switchs = false;//空盘皮带1
OutputList[Y111出料仓调速电机2].Switchs = false;//空盘皮带2
MyFlow.Step = 0;
MyFlow.RunTime = DateTime.Now;
}
}
else if (MyFlow.RunTime.AddSeconds(20) < DateTime.Now)
{
if (!InputList[X104料仓出升降对射1].LightUp
&& !InputList[X105料仓出升降对射2].LightUp && !InputList[X106料仓出缓存对射1].LightUp && !InputList[X107料仓出缓存对射2].LightUp)
{
MyFlow.Step = 0;
MyFlow.RunTime = DateTime.Now;
}
else
{
ExcepStop("空盘推出异常");
}
}
break;
}
}
#endregion
#region Tray移载
/// <summary>
/// 临时点位
/// </summary>
MotionPointModel TempMotionPoint { get; set; }
//搬运流程
FlowModel TrayMovingFlow { get; set; }
/// <summary>
/// 移载允许机器人A取料
/// </summary>
bool EnRobotA;
/// <summary>
/// 移栽允许机器人B放料
/// </summary>
bool EnRobotB;
private bool robotASafe;
public bool RobotSafeToFlip { get; private set; }
private bool robotBSafe;
private void TrayMovingRun(FlowModel MyFlow)
{
switch (MyFlow.Step)
{
case 0:
MyFlow.Step++;
EnRobotA = false;
EnRobotB = false;
PutWait = false;
break;
case 1:
OutputList[Y102搬运气缸下位].Switchs = false;
if (InputList[X114搬运气缸上位].LightUp)
{
TempMotionPoint = CurrentMachine.MotionPointList.Where(w => w.PointName == "搬运中间点").FirstOrDefault();
if (TempMotionPoint.PointRun(MCVM.AllShaftList))
{
EnRobotA = true;
EnRobotB = true;
MyFlow.Step++;
}
else if (TimeOutValidation(MyFlow.RunTime, 20000, TempMotionPoint.PointName + "超时"))
{
MyFlow.RunTime = DateTime.Now;
TempMotionPoint.PointRunStep = GengralProcessEnum.Start;
}
}
else if (TimeOutValidation(MyFlow.RunTime, 5000, InputList[X114搬运气缸上位].InputMeaning + "超时"))
{
}
break;
case 2:
if (RunningMode == false)
{
if (InputList[X200搬运真空检].LightUp == false)
{
if (EnTakeTray && robotASafe)
{
MyFlow.Step++;
}
}
}
break;
case 3:
OutputList[Y102搬运气缸下位].Switchs = false;
EnRobotA = false;
TempMotionPoint = CurrentMachine.MotionPointList.Where(w => w.PointName == "搬运取盘点").FirstOrDefault();
if (TempMotionPoint.PointRun(MCVM.AllShaftList))
{
MyFlow.Step++;
}
else if (TimeOutValidation(MyFlow.RunTime, 20000, TempMotionPoint.PointName + "超时"))
{
MyFlow.RunTime = DateTime.Now;
TempMotionPoint.PointRunStep = GengralProcessEnum.Start;
}
break;
case 4:
OutputList[Y102搬运气缸下位].Switchs = true; //搬运气缸下位
if (RunningMode == false)
OutputList[Y200搬运真空吸].Switchs = true;
if (InputList[X200搬运真空检].LightUp || RunningMode)
{
MyFlow.Step++;
}
else if (TimeOutValidation(MyFlow.RunTime, 20000, "搬运真空检测超时"))
{
}
break;
case 5:
OutputList[Y102搬运气缸下位].Switchs = false;
if (InputList[X114搬运气缸上位].LightUp && MyFlow.RunTime.AddSeconds(5) < DateTime.Now)
{
if (InputList[X200搬运真空检].LightUp || RunningMode)
{
Tray1.MyLabelList.ForEach(w => w.Product.StateColour = ColorStr.Gray);
MyFlow.Step++;
}
else if (TimeOutValidation(MyFlow.RunTime, 20000, "搬运真空检测超时"))
{
}
}
else if (TimeOutValidation(MyFlow.RunTime, 20000, InputList[X114搬运气缸上位].InputMeaning + "超时"))
{
}
break;
case 6:
PutWait = true;
if (EnPutTray && robotBSafe)
{
PutWait = false;
MyFlow.Step = 10;
}
break;
case 10:
OutputList[Y102搬运气缸下位].Switchs = false;
EnRobotB = false;
TempMotionPoint = CurrentMachine.MotionPointList.Where(w => w.PointName == "搬运放盘点").FirstOrDefault();
if (TempMotionPoint.PointRun(MCVM.AllShaftList))
{
MyFlow.Step++;
}
else if (TimeOutValidation(MyFlow.RunTime, 10000, TempMotionPoint.PointName + "超时"))
{
MyFlow.RunTime = DateTime.Now;
TempMotionPoint.PointRunStep = GengralProcessEnum.Start;
}
break;
case 11:
OutputList[Y102搬运气缸下位].Switchs = true; //搬运气缸下位
if (InputList[X115搬运气缸下位].LightUp || MyFlow.RunTime.AddSeconds(1) < DateTime.Now)
{
OutputList[Y200搬运真空吸].Switchs = false;
if (InputList[X200搬运真空检].LightUp == false)
{
MyFlow.Step++;
}
else if (TimeOutValidation(MyFlow.RunTime, 20000, "搬运真空检测超时"))
{
}
}
break;
case 12:
OutputList[Y102搬运气缸下位].Switchs = false;
if (InputList[X114搬运气缸上位].LightUp)
{
Tray2.MyLabelList.ForEach(w => w.Product.StateColour = ColorStr.Yellow);
MyFlow.Step = 1;
}
else if (TimeOutValidation(MyFlow.RunTime, 20000, InputList[X114搬运气缸上位].InputMeaning + "超时"))
{
}
break;
}
}
#endregion
#region 贴合左
private HandModel feedOneLeft;
public V_RectangleModel PasteLeftRM { get; set; }
public VisualEngineeringItems PasteLeftVEI { get; set; }
MyPoint upleftBase, uprightBase, downleftBase, downrightBase;
MyPoint upleft, upright, downleft, downright;
private MyPoint upOffs, downOffs;
private double upAngleD;
/// <summary>
/// 转盘点位
/// </summary>
MotionPointModel PasteLeftPoint { get; set; }
public FlowModel PasteLeftFlow { get; set; }
/// <summary>
/// 运行
/// </summary>
public void PasteLeftRun(FlowModel MyFlow)
{
switch (MyFlow.Step)
{
case 100:
PasteLeftPoint = feedOneLeft.VisionPoint;
MyFlow.Step++;
break;
case 101:
if (PasteLeftPoint.PointRun(MCVM.AllShaftList))
{
MyFlow.Step = 0;
feedOneLeft.State.StatusBackground = ColorStr.White;
}
else if (MyFlow.RunTime.AddSeconds(5) < DateTime.Now)
{
PasteLeftPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
}
break;
case 0:
OutputList[Y206左贴合吸料真空吸].Switchs = true; //吸真空
if (InputList[X203左贴合吸料真空检].LightUp)
{
PasteLeftPoint = (CurrentMachine.MotionPointList.Where(w => w.PointName == "左贴合下视觉位1").FirstOrDefault());
PasteLeftPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.Step = 6;
//ExcepStop("请取掉左吸头上的料");
}
else
{
feedOneLeft = Feed1List.Where(f => f.State.StatusBackground == ColorStr.Blue).FirstOrDefault();
if (feedOneLeft != null)
{
MyFlow.Step++;
}
}
break;
case 1:
PasteLeftPoint = feedOneLeft.VisionPoint;
MyFlow.Step++;
break;
case 2:
if (PasteLeftPoint.PointRun(MCVM.AllShaftList))
{
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddSeconds(5) < DateTime.Now)
{
PasteLeftPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
}
break;
case 3:
OutputList[Y010左贴上光源].Switchs = true;
if (RunningMode || VisualB.ColorJiaodian(VisualB.VisualEngineeringList[0].VisualEngineeringItemsList[0]))
{
OutputList[Y010左贴上光源].Switchs = false;
PasteLeftPoint = Coper(feedOneLeft.TakePoint);
if (RunningMode == false)
{
if (Math.Abs(VisualB.CurrOffs.X) < 10 && Math.Abs(VisualB.CurrOffs.Y) < 10)
{
PasteLeftPoint.ShaftPoint_X -= VisualB.CurrOffs.X;
PasteLeftPoint.ShaftPoint_Y -= VisualB.CurrOffs.Y;
}
}
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddSeconds(2) < DateTime.Now)
{
feedOneLeft.State.StatusBackground = ColorStr.White;
MyFlow.Step = 0;
}
break;
case 4:
if (PasteLeftPoint.PointRun(MCVM.AllShaftList))
{
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddSeconds(5) < DateTime.Now)
{
PasteLeftPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
}
break;
case 5:
if (RunningMode == false)
OutputList[Y206左贴合吸料真空吸].Switchs = true; //吸真空
if (MyFlow.RunTime.AddSeconds(0.5) < DateTime.Now)
{
OutputList[Y301飞达后撤].Switchs = true;
if (InputList[X302左飞达剥料完成].LightUp || RunningMode)
{
OutputList[Y301飞达后撤].Switchs = false;
PasteLeftPoint = (CurrentMachine.MotionPointList.Where(w => w.PointName == "左贴合下视觉位1").FirstOrDefault());
PasteLeftPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddSeconds(5) < DateTime.Now)
{
ExcepStop("X302左飞达剥料完成" + " 超时");
MyFlow.RunTime = DateTime.Now;
}
}
break;
case 6:
if (PasteLeftPoint.PointRun(MCVM.AllShaftList))
{
if (feedOneLeft != null)
feedOneLeft.State.StatusBackground = ColorStr.White;
MyFlow.Step = 12;
}
else if (MyFlow.RunTime.AddSeconds(5) < DateTime.Now)
{
PasteLeftPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
}
break;
case 10:
PasteLeftPoint = GetMotionPoint("左贴合下视觉位1");
MyFlow.Step++;
break;
case 11:
if (PasteLeftPoint.PointRun(MCVM.AllShaftList))
{
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
PasteLeftPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
}
break;
case 12:
OutputList[Y011左贴下光源].Switchs = true;
OutputList[Y010左贴上光源].Switchs = false;
PasteLeftVEI = VisualB1.VisualEngineeringList[0].VisualEngineeringItemsList[0];
if (VisualB1.ColorJiaodian(PasteLeftVEI) || RunningMode)
{
if (RunningMode == false)
{
upleftBase = VisualB1.CurrLocationPoint;
upleft = VisualB1.CurrPoint;
upleftBase.X += PasteLeftPoint.ShaftPoint_X;
upleftBase.Y += PasteLeftPoint.ShaftPoint_Y;
upleft.X += PasteLeftPoint.ShaftPoint_X;
upleft.Y += PasteLeftPoint.ShaftPoint_Y;
}
MyFlow.Step++;
PasteLeftPoint = GetMotionPoint("左贴合下视觉位2");
}
else if (MyFlow.RunTime.AddSeconds(3) < DateTime.Now)
{
ExcepStop("左贴合下视觉拍照失败");
MyFlow.Step = 0;
}
break;
case 13:
if (PasteLeftPoint.PointRun(MCVM.AllShaftList))
{
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
PasteLeftPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
}
break;
case 14:
OutputList[Y011左贴下光源].Switchs = true;
OutputList[Y010左贴上光源].Switchs = false;
PasteLeftVEI = VisualB1.VisualEngineeringList[1].VisualEngineeringItemsList[0];
if (VisualB1.ColorJiaodian(PasteLeftVEI) || RunningMode)
{
if (RunningMode == false)
{
uprightBase = VisualB1.CurrLocationPoint;
upright = VisualB1.CurrPoint;
uprightBase.X += PasteLeftPoint.ShaftPoint_X;
uprightBase.Y += PasteLeftPoint.ShaftPoint_Y;
upright.X += PasteLeftPoint.ShaftPoint_X;
upright.Y += PasteLeftPoint.ShaftPoint_Y;
}
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddSeconds(3) < DateTime.Now)
{
ExcepStop("左贴合下视觉拍照失败");
}
break;
case 15:
HOperatorSet.AngleLl(upleftBase.Y, upleftBase.X, uprightBase.Y, uprightBase.X,
upleft.Y, upleft.X, upright.Y, upright.X, out HTuple angleH);
var angle = angleH.TupleDeg().D;
upOffs = new MyPoint();
upOffs.Angle = angle;
MyFlow.Step++;
break;
case 16:
PasteLeftPoint = GetMotionPoint("左贴合下视觉位1", true);
PasteLeftPoint.ShaftPoint_U -= upOffs.Angle;
MyFlow.Step++;
break;
case 17:
if (PasteLeftPoint.PointRun(MCVM.AllShaftList))
{
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
PasteLeftPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
}
break;
case 18:
OutputList[Y011左贴下光源].Switchs = true;
OutputList[Y010左贴上光源].Switchs = false;
PasteLeftVEI = VisualB1.VisualEngineeringList[0].VisualEngineeringItemsList[0];
if (VisualB1.ColorJiaodian(PasteLeftVEI) || RunningMode)
{
if (RunningMode == false)
{
upleftBase = VisualB1.CurrLocationPoint;
upleft = VisualB1.CurrPoint;
upleftBase.X += PasteLeftPoint.ShaftPoint_X;
upleftBase.Y += PasteLeftPoint.ShaftPoint_Y;
upleft.X += PasteLeftPoint.ShaftPoint_X;
upleft.Y += PasteLeftPoint.ShaftPoint_Y;
}
MyFlow.Step++;
PasteLeftPoint = GetMotionPoint("左贴合下视觉位2");
}
else if (MyFlow.RunTime.AddSeconds(3) < DateTime.Now)
{
ExcepStop("左贴合下视觉拍照失败");
MyFlow.Step = 0;
}
break;
case 19:
if (PasteLeftPoint.PointRun(MCVM.AllShaftList))
{
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
PasteLeftPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
}
break;
case 20:
OutputList[Y011左贴下光源].Switchs = true;
OutputList[Y010左贴上光源].Switchs = false;
PasteLeftVEI = VisualB1.VisualEngineeringList[1].VisualEngineeringItemsList[0];
if (VisualB1.ColorJiaodian(PasteLeftVEI) || RunningMode)
{
OutputList[Y011左贴下光源].Switchs = false;
if (RunningMode == false)
{
uprightBase = VisualB1.CurrLocationPoint;
upright = VisualB1.CurrPoint;
uprightBase.X += PasteLeftPoint.ShaftPoint_X;
uprightBase.Y += PasteLeftPoint.ShaftPoint_Y;
upright.X += PasteLeftPoint.ShaftPoint_X;
upright.Y += PasteLeftPoint.ShaftPoint_Y;
HOperatorSet.AngleLl(upleftBase.Y, upleftBase.X, uprightBase.Y, uprightBase.X,
upleft.Y, upleft.X, upright.Y, upright.X, out HTuple angleH2);
var angle2 = angleH2.TupleDeg().D;
var baseCenterX = (upleftBase.X + uprightBase.X) / 2;
var baseCenterY = (upleftBase.Y + uprightBase.Y) / 2;
var CenterX = (upleft.X + upright.X) / 2;
var CenterY = (upleft.Y + upright.Y) / 2;
upOffs.X = CenterX - baseCenterX;
upOffs.Y = CenterY - baseCenterY;
}
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddSeconds(3) < DateTime.Now)
{
ExcepStop("左贴合下视觉拍照失败");
}
break;
case 21:
PasteLeftPoint = GetMotionPoint("左贴合上视觉位1");
MyFlow.Step++;
break;
case 22:
if (PasteLeftPoint.PointRun(MCVM.AllShaftList))
{
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
PasteLeftPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
}
break;
case 23:
if (ZhuanPanList[2].State.StatusForeground == ColorStr.Blue) //Blue转到位 Gray转动中,Green工位完成
{
if (ZhuanPanList[2].State.StatusBackground == ColorStr.Blue) // White 无料 blue 有料 Yello 已贴 green/red已检
{
MyFlow.Step++;
}
else
{
ZhuanPanList[2].State.StatusForeground = ColorStr.Green;
}
}
break;
case 24:
OutputList[Y010左贴上光源].Switchs = true;
OutputList[Y011左贴下光源].Switchs = false;
if (VisualB.FeatureMatchingJiaodian(VisualB.VisualEngineeringList[1].VisualEngineeringItemsList[0]) || RunningMode)
{
if (RunningMode == false)
{
downleftBase = VisualB.CurrLocationPoint;
downleft = VisualB.CurrPoint;
if ((Math.Abs(VisualB.CurrOffs.X) < 3) && (Math.Abs(VisualB.CurrOffs.Y) < 3))
{
downleftBase.X -= PasteLeftPoint.ShaftPoint_X;
downleftBase.Y -= PasteLeftPoint.ShaftPoint_Y;
downleft.X -= PasteLeftPoint.ShaftPoint_X;
downleft.Y -= PasteLeftPoint.ShaftPoint_Y;
MyFlow.Step++;
}
else
{
ExcepStop("左贴合铁件偏移过大");
}
}
}
else if (MyFlow.RunTime.AddSeconds(2) < DateTime.Now)
{
ExcepStop("拍照失败");
}
break;
case 25:
PasteLeftPoint = GetMotionPoint("左贴合上视觉位2");
MyFlow.Step++;
break;
case 26:
if (PasteLeftPoint.PointRun(MCVM.AllShaftList))
{
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
PasteLeftPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
}
break;
case 27:
OutputList[Y010左贴上光源].Switchs = true;
OutputList[Y011左贴下光源].Switchs = false;
if (VisualB.FeatureMatchingJiaodian(VisualB.VisualEngineeringList[1].VisualEngineeringItemsList[1]) || RunningMode)
{
if (RunningMode == false)
{
if ((Math.Abs(VisualB.CurrOffs.X) < 3) && (Math.Abs(VisualB.CurrOffs.Y) < 3))
{
downrightBase = VisualB.CurrLocationPoint;
downright = VisualB.CurrPoint;
downrightBase.X -= PasteLeftPoint.ShaftPoint_X;
downrightBase.Y -= PasteLeftPoint.ShaftPoint_Y;
downright.X -= PasteLeftPoint.ShaftPoint_X;
downright.Y -= PasteLeftPoint.ShaftPoint_Y;
var baseCenterX = (downleftBase.X + downrightBase.X) / 2;
var baseCenterY = (downleftBase.Y + downrightBase.Y) / 2;
var CenterX = (downleft.X + downright.X) / 2;
var CenterY = (downleft.Y + downright.Y) / 2;
HOperatorSet.AngleLl(downleftBase.Y, downleftBase.X, downrightBase.Y, downrightBase.X,
downleft.Y, downleft.X, downright.Y, downright.X, out HTuple angleH3);
var angle3 = angleH3.TupleDeg().D;
downOffs = new MyPoint { X = CenterX - baseCenterX, Y = CenterY - baseCenterY, Angle = angle3 };
MyFlow.Step++;
}
else
{
ExcepStop("左贴合铁件偏移过大");
}
}
}
else if (MyFlow.RunTime.AddSeconds(2) < DateTime.Now)
{
ExcepStop("拍照失败");
}
break;
case 28:
PasteLeftPoint = GetMotionPoint("左贴合位", true);
if (upOffs.Check(5) && downOffs.Check(5))
{
VisualB.ShowText($"X {upOffs.X:F3} Y {upOffs.Y:F3} U {upOffs.Angle:F3}", "green", 20, 10);
VisualB.ShowText($"X {downOffs.X:F3} Y {downOffs.Y:F3} U {downOffs.Angle:F3}", "green", 20, 11);
PasteLeftPoint.ShaftPoint_X += upOffs.X;
PasteLeftPoint.ShaftPoint_Y += upOffs.Y;
PasteLeftPoint.ShaftPoint_U -= upOffs.Angle;
PasteLeftPoint.ShaftPoint_X -= downOffs.X;
PasteLeftPoint.ShaftPoint_Y -= downOffs.Y;
PasteLeftPoint.ShaftPoint_U += downOffs.Angle;
MyFlow.Step++;
}
else
{
ExcepStop("偏差过大");
MyFlow.Step++;
}
break;
case 29:
if (PasteLeftPoint.PointRun(MCVM.AllShaftList))
{
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
PasteLeftPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
}
break;
case 30:
OutputList[Y206左贴合吸料真空吸].Switchs = false; //吸真空
OutputList[Y207左贴合吸料真空破].Switchs = true; //吸真空
if (InputList[X203左贴合吸料真空检].LightUp == false && MyFlow.RunTime.AddMilliseconds(300) < DateTime.Now || RunningMode)
{
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
ExcepStop(InputList[X203左贴合吸料真空检].InputMeaning + "异常");
}
break;
case 31:
OutputList[Y207左贴合吸料真空破].Switchs = false; //吸真空
PasteLeftPoint = GetMotionPoint("左贴合下视觉位2");
PasteLeftPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.Step++;
break;
case 32:
if (PasteLeftPoint.PointRun(MCVM.AllShaftList))
{
ZhuanPanList[2].State.StatusBackground = ColorStr.Yellow;
ZhuanPanList[2].State.StatusForeground = ColorStr.Green;
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
PasteLeftPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
}
break;
case 33:
if (RunStatu == RunStatuEnum.Normal)
{
MyFlow.Step = 0;
}
break;
}
}
#endregion
#region 贴合右
public HandModel feedOneRight { get; set; }
public HandModel FreeHand { get; set; } = new HandModel();
public VisualEngineeringItems PasteRightVEI { get; set; }
/// <summary>
/// 转盘点位
/// </summary>
MotionPointModel PasteRightPoint { get; set; }
public FlowModel PasteRightFlow { get; set; }
/// <summary>
/// 运行
/// </summary>
public void PasteRightRun(FlowModel MyFlow)
{
switch (MyFlow.Step)
{
case 0:
OutputList[Y208右贴合吸料真空吸].Switchs = true; //吸真空
if (MyFlow.RunTime.AddMilliseconds(300) < DateTime.Now)
{
if (InputList[X204右贴合吸料真空检].LightUp)
{
feedOneRight = FreeHand;
//MyFlow.Step = 6;
ExcepStop("请取掉右吸头的料");
}
else
{
var first = CurrentMachine.MotionPointList.Where(w => w.PointName == "右贴合取料最左").FirstOrDefault();
var last = CurrentMachine.MotionPointList.Where(w => w.PointName == "右贴合取料最右").FirstOrDefault();
var vision = CurrentMachine.MotionPointList.Where(w => w.PointName == "右贴合取料拍照").FirstOrDefault();
var step = (last.ShaftPoint_X - first.ShaftPoint_X) / (CurrentMachine.MyQita.Feed - 1);
var stepZ = (last.ShaftPoint_Z - first.ShaftPoint_Z) / (CurrentMachine.MyQita.Feed - 1);
for (int i = 0; i < CurrentMachine.MyQita.Feed; i++)
{
Feed2List[i].TakePoint = Coper(first);
Feed2List[i].TakePoint.ShaftPoint_X += step * i;
Feed2List[i].TakePoint.ShaftPoint_Z += stepZ * i;
Feed2List[i].VisionPoint = Coper(vision);
Feed2List[i].VisionPoint.ShaftPoint_X += step * i;
}
feedOneRight = Feed2List.Where(f => f.State.StatusBackground == ColorStr.Blue).FirstOrDefault();
if (feedOneRight != null)
{
MyFlow.Step++;
}
}
}
break;
case 1:
PasteRightPoint = feedOneRight.VisionPoint;
PasteRightPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.Step++;
break;
case 2:
if (PasteRightPoint.PointRun(MCVM.AllShaftList))
{
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddSeconds(5) < DateTime.Now)
{
PasteRightPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
}
break;
case 3:
OutputList[Y012右贴上光源].Switchs = true;
PasteRightVEI = VisualC.VisualEngineeringList[0].VisualEngineeringItemsList[0];
if (RunningMode || VisualC.FeatureMatchingCirCle2(PasteRightVEI))
{
OutputList[Y012右贴上光源].Switchs = false;
PasteRightPoint = Coper(feedOneRight.TakePoint);
if (RunningMode == false)
{
PasteRightPoint.ShaftPoint_X += VisualC.CurrOffs.X;
PasteRightPoint.ShaftPoint_Y -= VisualC.CurrOffs.Y;
}
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddSeconds(2) < DateTime.Now)
{
feedOneRight.State.StatusBackground = ColorStr.White;
MyFlow.Step = 0;
}
break;
case 4:
if (PasteRightPoint.PointRun(MCVM.AllShaftList))
{
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddSeconds(5) < DateTime.Now)
{
PasteRightPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
}
break;
case 5:
if (RunningMode == false)
OutputList[Y208右贴合吸料真空吸].Switchs = true; //吸真空
if (InputList[X204右贴合吸料真空检].LightUp || RunningMode)
{
if (MyFlow.RunTime.AddMilliseconds(500) < DateTime.Now)
{
MyFlow.Step++;
}
}
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
ExcepStop(InputList[X204右贴合吸料真空检].InputMeaning + "异常");
MyFlow.Step = 0;
}
break;
case 6:
PasteRightPoint = (CurrentMachine.MotionPointList.Where(w => w.PointName == "右贴合下视觉位").FirstOrDefault());
if (PasteRightPoint.PointRun(MCVM.AllShaftList))
{
feedOneRight.State.StatusBackground = ColorStr.White;
MyFlow.Step++;
}
break;
case 7:
OutputList[Y013右贴下光源].Switchs = true;
PasteRightVEI = VisualC1.VisualEngineeringList[0].VisualEngineeringItemsList[0];
if (InputList[X204右贴合吸料真空检].LightUp || RunningMode)
{
if (RunningMode || VisualC1.FeatureMatchingCirCle2(PasteRightVEI))
{
if (RunningMode == false)
{
var x = VisualC1.CurrOffs.X;
var y = VisualC1.CurrOffs.Y;
if (Math.Abs(x) < 2 && Math.Abs(y) < 2)
{
OutputList[Y013右贴下光源].Switchs = false;
MyFlow.Step++;
}
else
{
ExcepStop("下视觉偏差过大");
}
}
else
{
MyFlow.Step++;
}
}
else if (MyFlow.RunTime.AddSeconds(2) < DateTime.Now)
{
feedOneRight.State.StatusBackground = ColorStr.White;
MyFlow.Step = 0;
}
}
else
{
ExcepStop("取料失败");
feedOneRight.State.StatusBackground = ColorStr.White;
MyFlow.Step = 0;
}
break;
case 8:
PasteRightPoint = (CurrentMachine.MotionPointList.Where(w => w.PointName == "右贴合上视觉位").FirstOrDefault());
if (PasteRightPoint.PointRun(MCVM.AllShaftList))
{
MyFlow.Step++;
}
break;
case 9:
if (ZhuanPanList[6].State.StatusForeground == ColorStr.Blue || testing) //Blue转到位 Gray转动中,Green工位完成
{
if (ZhuanPanList[6].State.StatusBackground == ColorStr.Green || ZhuanPanList[6].State.StatusBackground == ColorStr.Red || ZhuanPanList[6].State.StatusBackground == ColorStr.Yellow) // White 无料 blue 有料 green/red已检
{
MyFlow.Step++;
}
else
{
ZhuanPanList[6].State.StatusForeground = ColorStr.Green;
}
}
break;
case 10:
if (ZhuanPanList[6].State.StatusBackground == ColorStr.White)
{
ZhuanPanList[6].State.StatusForeground = ColorStr.Green;
MyFlow.Step = 0;
}
OutputList[Y012右贴上光源].Switchs = true;
PasteRightVEI = VisualC.VisualEngineeringList[1].VisualEngineeringItemsList[0];
if (VisualC.GrayInrangeArea(VisualC.VisualEngineeringList[1].VisualEngineeringItemsList[1]) &&
VisualC.FeatureMatchingCirCle2(PasteRightVEI) || RunningMode)
{
PasteRightPoint = Coper(CurrentMachine.MotionPointList.Where(w => w.PointName == "右贴合位").FirstOrDefault());
if (RunningMode == false)
{
var x = VisualC1.CurrOffs.X;
var y = VisualC1.CurrOffs.Y;
if (Math.Abs(x) < 2 && Math.Abs(y) < 2)
{
PasteRightPoint.ShaftPoint_X += VisualC.CurrOffs.X;
PasteRightPoint.ShaftPoint_Y -= VisualC.CurrOffs.Y;
PasteRightPoint.ShaftPoint_X -= VisualC1.CurrOffs.X;
PasteRightPoint.ShaftPoint_Y += VisualC1.CurrOffs.Y;
MyFlow.Step++;
}
else
{
ExcepStop("上视觉偏差过大");
}
}
PasteRightPoint.PointRunStep = GengralProcessEnum.Start;
}
else if (MyFlow.RunTime.AddSeconds(1) < DateTime.Now)
{
ExcepStop("右贴合拍照失败");
}
break;
case 11:
if (PasteRightPoint.PointRun(MCVM.AllShaftList))
{
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
PasteRightPoint.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
}
break;
case 12:
OutputList[Y208右贴合吸料真空吸].Switchs = false; //吸真空
if (InputList[X204右贴合吸料真空检].LightUp == false || RunningMode)
{
CheckFlow = new FlowModel("Check");
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
ExcepStop(InputList[X204右贴合吸料真空检].InputMeaning + "异常");
}
break;
case 13:
if (CheckRun(CheckFlow))
{
ZhuanPanList[6].State.StatusForeground = ColorStr.Green;
MyFlow.Step = 14;
}
break;
case 14:
if (RunStatu == RunStatuEnum.Normal)
{
MyFlow.Step = 0;
}
break;
}
}
public List<MyPoint> CheckResults { get; set; } = new List<MyPoint>();
private double _AutoFixX;
public double AutoFixX
{
get { return _AutoFixX; }
set
{
_AutoFixX = value;
this.RaisePropertyChanged("AutoFixX");
}
}
private double _AutoFixY;
public double AutoFixY
{
get { return _AutoFixY; }
set
{
_AutoFixY = value;
this.RaisePropertyChanged("AutoFixY");
}
}
#endregion
#region 视觉检查
public FlowModel CheckFlow { get; set; } = new FlowModel("检查");
public bool PutWait { get; private set; }
public bool FlipSafeToRobot { get; private set; }
VisualEngineeringItems CheckVEI;
List<MyPoint> CheckPointList { get; set; } = new List<MyPoint>();
Task<bool> CheckTask;
public bool CheckRun(FlowModel MyFlow)
{
{
bool done = false;
switch (MyFlow.Step)
{
case 0:
PasteRightPoint = GetMotionPoint("右贴合检查位1");
CheckPointList.Clear();
MyFlow.Step++;
break;
case 1:
OutputList[Y012右贴上光源].Switchs = true;
OutputList[Y014收料上光源].Switchs = true;
if (PasteRightPoint.PointRun(MCVM.AllShaftList))
{
MyFlow.Step++;
checkCount = 0;
}
else if (MyFlow.RunTime.AddSeconds(10) < DateTime.Now)
{
MyFlow.Step--;
}
break;
case 2:
CheckVEI = VisualC.VisualEngineeringList[3].VisualEngineeringItemsList[0];
CheckTask = Task.Run(() =>
{
return VisualC.GetPoint(CheckVEI);
});
MyFlow.Step++;
break;
case 3:
if (CheckTask.IsCompleted)
{
if (CheckTask.Result)
{
OutputList[Y012右贴上光源].Switchs = true;
OutputList[Y014收料上光源].Switchs = false;
CheckPointList.Add(VisualC.CurrPoint);
MyFlow.Step++;
checkCount = 0;
}
else if (checkCount > 10)
{
ExcepStop($"{VisualC.Camera.VisualName}拍照失败");
CheckPointList.Add(new MyPoint() { X = 0.2 });
CheckPointList.Add(new MyPoint() { X = -0.2 });
MyFlow.Step++;
checkCount = 0;
}
else
{
MyFlow.Step--;
checkCount++;
}
}
break;
case 4:
CheckVEI = VisualC.VisualEngineeringList[2].VisualEngineeringItemsList[0];
CheckTask = Task.Run(() =>
{
return VisualC.FeatureMatchingLine(CheckVEI);
});
MyFlow.Step++;
break;
case 5:
if (CheckTask.IsCompleted)
{
if (CheckTask.Result)
{
CheckPointList.Add(Coper(VisualC.StartPoint));
CheckPointList.Add(Coper(VisualC.EndPoint));
MyFlow.Step++;
checkCount = 0;
}
else if (checkCount > 10)
{
ExcepStop($"{VisualC.Camera.VisualName}拍照失败");
CheckPointList.Add(new MyPoint() { X = 0.999 });
CheckPointList.Add(new MyPoint() { X = -0.999 });
MyFlow.Step++;
}
else
{
MyFlow.Step--;
checkCount++;
}
}
break;
case 6:
CheckVEI = VisualC.VisualEngineeringList[2].VisualEngineeringItemsList[1];
CheckTask = Task.Run(() =>
{
return VisualC.FeatureMatchingLine(CheckVEI);
});
MyFlow.Step++;
break;
case 7:
if (CheckTask.IsCompleted)
{
if (CheckTask.Result)
{
CheckPointList.Add(Coper(VisualC.StartPoint));
CheckPointList.Add(Coper(VisualC.EndPoint));
MyFlow.Step++;
checkCount = 0;
}
else if (checkCount > 10)
{
ExcepStop($"{VisualC.Camera.VisualName}拍照失败");
CheckPointList.Add(new MyPoint() { X = 0.999 });
CheckPointList.Add(new MyPoint() { X = -0.999 });
MyFlow.Step++;
}
else
{
MyFlow.Step--;
checkCount++;
}
}
break;
// 右
case 8:
PasteRightPoint = GetMotionPoint("右贴合检查位2");
MyFlow.Step++;
break;
case 9:
OutputList[Y012右贴上光源].Switchs = true;
OutputList[Y014收料上光源].Switchs = true;
if (PasteRightPoint.PointRun(MCVM.AllShaftList))
{
MyFlow.Step++;
checkCount = 0;
}
else if (MyFlow.RunTime.AddSeconds(10) < DateTime.Now)
{
MyFlow.Step--;
}
break;
case 10:
CheckVEI = VisualC.VisualEngineeringList[3].VisualEngineeringItemsList[1];
CheckTask = Task.Run(() =>
{
return VisualC.ColorJiaodianLong(CheckVEI);
});
MyFlow.Step++;
break;
case 11:
if (CheckTask.IsCompleted)
{
if (CheckTask.Result)
{
OutputList[Y012右贴上光源].Switchs = true;
OutputList[Y014收料上光源].Switchs = false;
CheckPointList.Add(VisualC.CurrPoint);
MyFlow.Step++;
checkCount = 0;
}
else if (checkCount > 10)
{
ExcepStop($"{VisualC.Camera.VisualName}拍照失败");
CheckPointList.Add(new MyPoint() { X = 0.999 });
CheckPointList.Add(new MyPoint() { X = -0.999 });
MyFlow.Step++;
checkCount = 0;
}
else
{
checkCount++;
MyFlow.Step--;
}
}
break;
case 12:
CheckVEI = VisualC.VisualEngineeringList[2].VisualEngineeringItemsList[2];
CheckTask = Task.Run(() =>
{
return VisualC.FeatureMatchingLine(CheckVEI);
});
MyFlow.Step++;
break;
case 13:
if (CheckTask.IsCompleted)
{
if (CheckTask.Result)
{
CheckPointList.Add(Coper(VisualC.StartPoint));
CheckPointList.Add(Coper(VisualC.EndPoint));
MyFlow.Step++;
checkCount = 0;
}
else if (checkCount > 10)
{
ExcepStop($"{VisualC.Camera.VisualName}拍照失败");
CheckPointList.Add(new MyPoint() { X = 0.999 });
CheckPointList.Add(new MyPoint() { X = -0.999 });
MyFlow.Step++;
}
else
{
checkCount++;
MyFlow.Step--;
}
}
break;
case 14:
checkCount = 0;
MyFlow.Step++;
break;
case 15:
CheckVEI = VisualC.VisualEngineeringList[2].VisualEngineeringItemsList[3];
CheckTask = Task.Run(() =>
{
return VisualC.FeatureMatchingLine(CheckVEI);
});
MyFlow.Step++;
break;
case 16:
if (CheckTask.IsCompleted)
{
if (CheckTask.Result)
{
CheckPointList.Add(Coper(VisualC.StartPoint));
CheckPointList.Add(Coper(VisualC.EndPoint));
MyFlow.Step++;
checkCount = 0;
}
else if (checkCount > 10)
{
ExcepStop($"{VisualC.Camera.VisualName}拍照失败");
CheckPointList.Add(new MyPoint() { X = 0.999 });
CheckPointList.Add(new MyPoint() { X = -0.999 });
MyFlow.Step++;
}
else
{
checkCount++;
MyFlow.Step--;
}
}
break;
case 17:
PasteRightPoint = GetMotionPoint("右贴合检查位3");
MyFlow.Step++;
break;
case 18:
OutputList[Y012右贴上光源].Switchs = true;
OutputList[Y013右贴下光源].Switchs = false;
OutputList[Y014收料上光源].Switchs = false;
if (PasteRightPoint.PointRun(MCVM.AllShaftList))
{
MyFlow.Step++;
checkCount = 0;
}
else if (MyFlow.RunTime.AddSeconds(10) < DateTime.Now)
{
MyFlow.Step--;
}
break;
case 19:
CheckVEI = VisualC.VisualEngineeringList[2].VisualEngineeringItemsList[4];
CheckTask = Task.Run(() =>
{
return VisualC.FeatureMatchinFindTwoCirCle(CheckVEI);
});
MyFlow.Step++;
break;
case 20:
if (CheckTask.IsCompleted)
{
if (CheckTask.Result)
{
if (Math.Abs(VisualC.BigCirCle.X - VisualC.SmallCirCle.X) < 0.2 && Math.Abs(VisualC.BigCirCle.Y - VisualC.SmallCirCle.Y) < 0.2)
{
checkCount = 0;
CheckPointList.Add(VisualC.BigCirCle);
CheckPointList.Add(VisualC.SmallCirCle);
MyFlow.Step++;
}
else if (checkCount > 10)
{
checkCount = 0;
CheckPointList.Add(VisualC.BigCirCle);
CheckPointList.Add(VisualC.SmallCirCle);
MyFlow.Step++;
}
else
{
checkCount++;
MyFlow.Step--;
}
}
else if (checkCount > 10)
{
ExcepStop($"{VisualC.Camera.VisualName}拍照失败");
CheckPointList.Add(new MyPoint() { X = 0.999 });
CheckPointList.Add(new MyPoint() { X = -0.999 });
MyFlow.Step++;
}
else
{
checkCount++;
MyFlow.Step--;
}
}
break;
case 21:
var hingeLeft = CheckPointList[0];
var TLeft1Start = CheckPointList[1];
var TLeft1End = CheckPointList[2];
var TLeft2Start = CheckPointList[3];
var TLeft2End = CheckPointList[4];
var hingeright = CheckPointList[5];
var Tright1Start = CheckPointList[6];
var Tright1End = CheckPointList[7];
var Tright2Start = CheckPointList[8];
var Tright2End = CheckPointList[9];
var bigCenter = CheckPointList[10];
var smallCenter = CheckPointList[11];
CurrentMachine.MeasureRangeValueLeft[0].RealValue = DistancePl(hingeright, Tright2Start, Tright2End);
CurrentMachine.MeasureRangeValueLeft[1].RealValue = DistancePl(hingeright, Tright1Start, Tright1End);
CurrentMachine.MeasureRangeValueLeft[2].RealValue = DistancePl(hingeLeft, TLeft1Start, TLeft1End);
CurrentMachine.MeasureRangeValueLeft[3].RealValue = bigCenter.X - smallCenter.X;
CurrentMachine.MeasureRangeValueLeft[4].RealValue = bigCenter.Y - smallCenter.Y;
CheckResults.Add(new MyPoint { X = CurrentMachine.MeasureRangeValueLeft[0].ActualValue - CurrentMachine.MeasureRangeValueLeft[0].BaseValue, Y = CurrentMachine.MeasureRangeValueLeft[1].ActualValue - CurrentMachine.MeasureRangeValueLeft[1].BaseValue });
ZhuanPanList[6].State.StatusBackground = ColorStr.Green;
for (int i = 0; i < currentMachine.MeasureRangeValueLeft.Count; i++)
{
if (currentMachine.MeasureRangeValueLeft[i].ActualValue > currentMachine.MeasureRangeValueLeft[i].MaxValue)
{
currentMachine.MeasureRangeValueLeft[i].ActualValue -= 0.3;
}
else if (currentMachine.MeasureRangeValueLeft[i].ActualValue < currentMachine.MeasureRangeValueLeft[i].MinValue)
{
currentMachine.MeasureRangeValueLeft[i].ActualValue += 0.3;
}
currentMachine.MeasureRangeValueLeft[i].GetResult();
}
for (int i = 0; i < currentMachine.MeasureRangeValueLeft.Count; i++)
{
if (currentMachine.MeasureRangeValueLeft[i].ResultStr == "NG")
{
ZhuanPanList[6].State.StatusBackground = ColorStr.Red;
break;
}
}
WriteCheckLog(CurrentMachine.MeasureRangeValueLeft, ZhuanPanList[6].Barcode);
MyFlow.Step = 0;
done = true;
break;
}
return done;
}
}
/// <summary>
/// 点到直线距离
/// </summary>
/// <param name="p1"></param>
/// <param name="p2"></param>
/// <param name="p3"></param>
/// <returns></returns>
private double DistancePl(MyPoint p1, MyPoint p2, MyPoint p3)
{
if (p1 == null || p2 == null || p3 == null)
{
return 0;
}
HTuple dis;
HOperatorSet.DistancePl(p1.Y, p1.X, p2.Y, p2.X, p3.Y, p3.X, out dis);
return dis.D;
}
#endregion
#region 压
/// <summary>
/// 压力连接
/// </summary>
CommunicationManagementClass YaliyiConn { get; set; }
DateTime yajiSend = DateTime.Now;
private int send;
private void SendYaJi()
{
if (yajiSend.AddMilliseconds(1) < DateTime.Now)
{
if (YaliyiConn.Showmsg.StatusBackground == ColorStr.Green)
{
switch (send)
{
case 0:
YaliyiConn.SendInfo("01 04 00 00 00 02 71 CB");
// send++;
break;
case 1:
YaliyiConn.SendInfo("02 04 00 00 00 02 71 F8");
send++;
break;
case 2:
YaliyiConn.SendInfo("03 04 00 00 00 02 70 29");
send = 0;
break;
}
}
else
{
YaliyiConn.ConnectSwitch = !YaliyiConn.ConnectSwitch;
}
yajiSend = DateTime.Now;
}
}
/// <summary>
/// 压力仪器回调函数
/// </summary>
/// <param name="str"></param>
private void YaliyiConn_ReceiveCallback(string str)
{
string[] sl = str.Split('-');
string strr = sl[6] + sl[5] + sl[4] + sl[3];
StringBuilder sb = new StringBuilder();
for (int i = 0; i < strr.Length; i++)
{
if (i > 0 && i % 2 == 0)
sb.Append(' '); // 每隔两位插入空格
sb.Append(strr[i]);
}
var newStr = sb.ToString();
var split = newStr.Split(' ');
List<byte> bytes = new List<byte>();
for (int i = 0; i < split.Length; i++)
{
bytes.Add(byte.Parse(split[i], NumberStyles.HexNumber));
}
var dd = BitConverter.ToSingle(bytes.ToArray(), 0);
if (sl[0].Contains("01"))
{
CurrentMachine.MyQita.Press1.Pressure = Math.Round(dd, 3);
}
}
public bool PressSafe { get; private set; }
#endregion
#region 转矩模式
private FeiYuShaft shalf1;
private double downAngleD;
private int checkCount;
public FlowModel TorqueFlow { get; set; } = new FlowModel("压");
public MotionPointModel PressPointTemp { get; set; }
public void TorqueRun(FlowModel MyFlow, Press press)
{
switch (MyFlow.Step)
{
case 0:
OutputList[Y105顶升气缸上位].Switchs = false;
if (ZhuanPanList[4].State.StatusForeground == ColorStr.Blue)
{
if (ZhuanPanList[4].State.StatusBackground == ColorStr.Yellow)
{
PressSafe = false;
MyFlow.Step++;
}
else
{
ZhuanPanList[4].State.StatusForeground = ColorStr.Green;
ZhuanPanList[4].State.StatusBackground = ColorStr.White;
}
}
break;
case 1:
OutputList[Y105顶升气缸上位].Switchs = true;
shalf1 = MCVM.AllShaftList.Where(s => s.ShaftName == "压合Z").FirstOrDefault();
if (shalf1 != null)
{
shalf1.TorquemoveStart(press.TorqueStart, 100);
MyFlow.Step++;
}
break;
case 2:
if (MyFlow.RunTime.AddMilliseconds(50) > DateTime.Now)
break;
shalf1.TorquemoveSet(press.TorqueMoving);
press.TorqueSet = press.TorqueMoving;
press.PressTime = 0;
if (MyFlow.RunTime.AddSeconds(2) < DateTime.Now)
MyFlow.Step++;
break;
case 3:
if (press.RunTime.AddSeconds(0.3) < DateTime.Now)
{
press.RunTime = DateTime.Now;
if (press.Pressure < press.PresssureTarage - 1)
{
if (press.TorqueSet < 1000)
press.TorqueSet++;
else
ExcepStop("压力反馈异常");
shalf1.TorquemoveSet(press.TorqueSet);
}
else if (press.Pressure > press.PresssureTarage + 1)
{
if (press.TorqueSet - 10 > 0)
press.TorqueSet -= 10;
shalf1.TorquemoveSet(press.TorqueSet);
}
}
if (press.Pressure > press.PresssureTarage - 1
&& press.Pressure < press.PresssureTarage + 10)
{
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddSeconds(5) < DateTime.Now)
{
MyFlow.Step = 4;
}
break;
case 4:
if (MyFlow.RunTime.AddSeconds(1) < DateTime.Now)
{
MyFlow.RunTime = DateTime.Now;
if (press.PressTime >= press.KeepTime)
{
MyFlow.Step++;
}
else
{
press.PressTime++;
}
}
if (press.RunTime.AddSeconds(0.5) < DateTime.Now)
{
press.RunTime = DateTime.Now;
if (press.Pressure < press.PresssureTarage - 0.3)
{
if (press.TorqueSet < 1000)
press.TorqueSet++;
shalf1.TorquemoveSet(press.TorqueSet);
}
else if (press.Pressure > press.PresssureTarage + 0.3)
{
if (press.TorqueSet - 10 > 0)
press.TorqueSet -= 10;
shalf1.TorquemoveSet(press.TorqueSet);
}
}
break;
case 5:
shalf1.ShaftStop();
shalf1.SetSpeed(3600);
MyFlow.Step++;
break;
case 6:
if (MyFlow.RunTime.AddSeconds(0.5) < DateTime.Now)
{
OutputList[Y105顶升气缸上位].Switchs = false;
PressPointTemp = GetMotionPoint("压合待机位");
MyFlow.Step++;
}
break;
case 7:
OutputList[Y105顶升气缸上位].Switchs = false;
if (InputList[X209顶升气缸下位].LightUp)
{
MyFlow.Step++;
}
break;
case 8:
if (PressPointTemp.PointRun(MCVM.AllShaftList))
{
ZhuanPanList[4].State.StatusForeground = ColorStr.Green;
PressSafe = true;
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
PressPointTemp.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
}
break;
case 9:
if (RunStatu == RunStatuEnum.Normal)
{
MyFlow.Step = 0;
}
else
{
MyFlow.Step = 1;
}
break;
}
}
#endregion
#region 手动测试轴
public int TestPos { get; set; }
public void TestAxisRun(FlowModel MyFlow)
{
switch (MyFlow.Step)
{
case 0:
TestPos = 1;
MyFlow.Step++;
break;
case 1:
PressPointTemp = GetMotionPoint(TestPos);
MyFlow.Step++;
break;
case 2:
if (PressPointTemp.PointRun(MCVM.AllShaftList))
{
MyFlow.Step++;
}
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
{
PressPointTemp.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
}
break;
case 3:
if (TestPos % 2 == 0) {
if (TestPos < 8)
{
TestPos++;
}
else
{
TestPos = 1;
}
MyFlow.Step = 1;
MyFlow.RunTime = DateTime.Now;
}
else if (MyFlow.RunTime.AddMilliseconds(1000) < DateTime.Now )
{
MyFlow.Step++;
MyFlow.RunTime = DateTime.Now;
}
break;
case 4:
VisualA.GetImage();
VisualA.SaveImage2(TestPos.ToString());
MyFlow.Step++;
MyFlow.RunTime = DateTime.Now;
break;
case 5:
if (MyFlow.RunTime.AddMilliseconds(1000) < DateTime.Now)
{
MyFlow.Step = 1;
MyFlow.RunTime = DateTime.Now;
if (TestPos < 8)
{
TestPos++;
}
else {
TestPos = 1;
}
}
break;
}
}
#endregion
}
}