liteon/ViewModel/MainWindowVM.cs
tfarcraw fc1d705cd8 1
2026-12-04 16:14:25 +08:00

4228 lines
136 KiB
C#
Raw Permalink 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 Model;
using Model.MotionControl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL;
using System.Threading;
using System.Collections.ObjectModel;
using Community;
using HalconDotNet;
using Microsoft.Win32;
using System.Windows;
using System.Reflection;
using System.Windows.Controls;
using System.Windows.Data;
using System.Net;
using System.IO;
using System.Windows.Threading;
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;
using System.ServiceProcess;
using LiveCharts;
using LiveCharts.Wpf;
using ViewModel.Vision;
using ViewModel.MotionControl;
using ViewModel.Robots;
using ControlzEx.Theming;
using System.Windows.Media;
using Model.Vision;
using Views;
using System.IO.Ports;
using System.Configuration;
namespace ViewModel
{
public partial class MainWindowVM : NotificationObject
{
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 视觉对象A
private HalconVisual visualA;
/// <summary>
/// 视觉对象A
/// </summary>
public HalconVisual VisualA
{
get { return visualA; }
set
{
visualA = value;
RaisePropertyChanged("VisualA");
}
}
#endregion
#region 视觉对象B
private HalconVisual visualB;
/// <summary>
/// 视觉对象B
/// </summary>
public HalconVisual VisualB
{
get { return visualB; }
set
{
visualB = value;
RaisePropertyChanged("VisualB");
}
}
#endregion
#region 视觉对象C
private HalconVisual visualC;
/// <summary>
/// 视觉对象C
/// </summary>
public HalconVisual VisualC
{
get { return visualC; }
set
{
visualC = value;
RaisePropertyChanged("VisualC");
}
}
#endregion
#region 串口相关
private SerialComVM sCVM;
/// <summary>
/// 串口服务对象
/// </summary>
public SerialComVM SCVM
{
get { return sCVM; }
set
{
sCVM = value;
this.RaisePropertyChanged("SCVM");
}
}
#endregion
#region 机器人对象
private FeiYuRobotVM robot;
/// <summary>
/// 机器人对象
/// </summary>
public FeiYuRobotVM Robot
{
get { return robot; }
set
{
robot = value;
RaisePropertyChanged("Robot");
}
}
#endregion
#region 运动控制对象VM
private MotionControlVM mCVM;
/// <summary>
/// 运动控制对象VM
/// </summary>
public MotionControlVM MCVM
{
get { return mCVM; }
set
{
mCVM = value;
RaisePropertyChanged("MCVM");
}
}
#endregion
#region 软件开启时间
/// <summary>
/// 软件开启时间
/// </summary>
DateTime OpenTime { get; set; }
/// <summary>
/// 生产运行开始时间
/// </summary>
DateTime RunStartTime { get; set; }
private string openTimeStr;
/// <summary>
/// 软件开启时间
/// </summary>
public string OpenTimeStr
{
get { return openTimeStr; }
set
{
openTimeStr = value;
this.RaisePropertyChanged("OpenTimeStr");
}
}
#region CT时间
private TimeSpan cTTime;
/// <summary>
/// CT时间
/// </summary>
public TimeSpan CTTime
{
get { return cTTime; }
set
{
cTTime = value;
ShowCtTime = value.TotalSeconds.ToString();
this.RaisePropertyChanged("CTTime");
}
}
private string showCtTime;
/// <summary>
/// 显示CT时间
/// </summary>
public string ShowCtTime
{
get { return showCtTime; }
set
{
showCtTime = value;
this.RaisePropertyChanged("ShowCtTime");
}
}
#endregion
#endregion
#region 图表相关
private ChartVM cVM;
/// <summary>
/// 图表对象
/// </summary>
public ChartVM CVM
{
get { return cVM; }
set
{
cVM = value;
this.RaisePropertyChanged("CVM");
}
}
#endregion
#region Ttay料盘
private TrayModel take1;
/// <summary>
/// Ttay料盘
/// </summary>
public TrayModel Take1
{
get { return take1; }
set
{
take1 = value;
this.RaisePropertyChanged("Take1");
}
}
#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;
}
}
//PermissionButtonName = Application.Current.Resources[value == Visibility.Collapsed ? "编辑模式" : "普通模式"].ToString();
PermissionButtonName = value == Visibility.Collapsed ? "编辑模式" : "普通模式";
if (value == Visibility.Collapsed)
{
SuperPrivilege = value;
}
else
{
if (GridWidth == "30*")
{
GridWidth = "0";
}
}
}
}
#endregion
#region 超级权限
private Visibility superPrivilege;
/// <summary>
/// 超级权限
/// </summary>
public Visibility SuperPrivilege
{
get { return superPrivilege; }
set
{
superPrivilege = value;
this.RaisePropertyChanged("SuperPrivilege");
if (value == Visibility.Visible)
{
AllVis = value;
}
if (HVlist != null)
{
foreach (HalconVisual hv in HVlist)
{
hv.SuperPrivilege = value;
}
}
if (MCVM != null)
{
MCVM.DisplayLevel = value;
}
}
}
#endregion
#endregion
#region 系统参数对象
private SystemParameter systemPar;
/// <summary>
/// 系统参数对象
/// </summary>
public SystemParameter SystemPar
{
get { return systemPar; }
set
{
systemPar = value;
this.RaisePropertyChanged("SystemPar");
}
}
#endregion
#region 数据对象
/// <summary>
/// 数据对象
/// </summary>
public MainWindowDAL dal = new MainWindowDAL();
/// <summary>
/// 视觉数据对象
/// </summary>
public VisualDAL Vdal = new VisualDAL();
#endregion
#region 控制卡
/// <summary>
/// Io控制卡ID
/// </summary>
public ushort IoCardID { get; set; }
#endregion
#region 输入信号集合
private List<InputSignal> inputList;
/// <summary>
/// 输入信号集合
/// </summary>
public List<InputSignal> InputList
{
get { return inputList; }
set
{
inputList = value;
if (value != null && value.Count > 0)
{
InputGrid = GetInputGrid();
}
}
}
#endregion
#region 输出信号集合
private List<OutputSignal> outputList;
/// <summary>
/// 输出信号集合
/// </summary>
public List<OutputSignal> OutputList
{
get { return outputList; }
set
{
outputList = value;
if (value != null && value.Count > 0)
{
OutputGrid = GetOutputGrid();
}
}
}
#endregion
#region 各线程
/// <summary>
/// 状态监控线程
/// </summary>
Thread ThStateMonitoring { get; set; }
/// <summary>
/// 运行线程
/// </summary>
Thread ThRun { get; set; }
/// <summary>
/// 网络连接控制线程
/// </summary>
Thread ThConnect { get; set; }
#endregion
#region 机器运行状态
private RunStatuEnum runStatu;
/// <summary>
/// 机器运行状态枚举
/// </summary>
public RunStatuEnum RunStatu
{
get { return runStatu; }
set
{
runStatu = value;
switch (value)
{
case RunStatuEnum.Prepare:
ShowStatu.StatusBackground = ColorStr.Yellow;
ShowStatu.StatusForeground = ColorStr.Black;
ShowStatu.StatuInfo = "准备中";
if (OutputList != null)
{
OutputList[0].Switchs = false; //红灯
OutputList[1].Switchs = true; //黄灯
OutputList[2].Switchs = false; //绿灯
OutputList[3].Switchs = false; //蜂鸣器
}
break;
case RunStatuEnum.Prepareations:
ShowStatu.StatusBackground = ColorStr.Green;
ShowStatu.StatusForeground = ColorStr.Black;
ShowStatu.StatuInfo = "准备就绪";
OutputList[0].Switchs = false; //红灯
OutputList[1].Switchs = true; //黄灯
OutputList[2].Switchs = false; //绿灯
OutputList[3].Switchs = false; //蜂鸣器
break;
case RunStatuEnum.Normal:
ShowStatu.StatusBackground = ColorStr.Green;
ShowStatu.StatusForeground = ColorStr.Black;
ShowStatu.StatuInfo = "运行中";
OutputList[0].Switchs = false; //红灯
OutputList[1].Switchs = false; //黄灯
OutputList[2].Switchs = true; //绿灯
OutputList[3].Switchs = false; //蜂鸣器
break;
case RunStatuEnum.Stop:
ShowStatu.StatusBackground = ColorStr.Yellow;
ShowStatu.StatusForeground = ColorStr.Black;
ShowStatu.StatuInfo = "停止中";
OutputList[0].Switchs = false; //红灯
OutputList[1].Switchs = true; //黄灯
OutputList[2].Switchs = false; //绿灯
OutputList[3].Switchs = false; //蜂鸣器
break;
case RunStatuEnum.EmgStop:
ShowStatu.StatusBackground = ColorStr.Yellow;
ShowStatu.StatusForeground = ColorStr.Black;
ShowStatu.StatuInfo = "紧急停止中";
OutputList[0].Switchs = true; //红灯
OutputList[1].Switchs = true; //黄灯
OutputList[2].Switchs = false; //绿灯
OutputList[3].Switchs = false; //蜂鸣器
break;
case RunStatuEnum.Exceptional:
ShowStatu.StatusBackground = ColorStr.Red;
ShowStatu.StatusForeground = ColorStr.White;
OutputList[0].Switchs = true; //红灯
OutputList[1].Switchs = false; //黄灯
OutputList[2].Switchs = false; //绿灯
OutputList[3].Switchs = true; //蜂鸣器
break;
}
}
}
private ShowInfo showStatu;
/// <summary>
/// 机器状态 显示
/// </summary>
public ShowInfo ShowStatu
{
get { return showStatu; }
set
{
showStatu = value;
this.RaisePropertyChanged("ShowStatu");
}
}
#endregion
#region 异常信息集合
private ObservableCollection<RecordInfo> excepList;
/// <summary>
/// 异常信息集合
/// </summary>
public ObservableCollection<RecordInfo> ExcepList
{
get { return excepList; }
set
{
excepList = value;
}
}
#endregion
#region 各种运行方法
/// <summary>
/// 开始运行
/// </summary>
public DelegateCommand StartCommand { get; set; }
/// <summary>
/// 停止运行
/// </summary>
public DelegateCommand StopCommand { get; set; }
/// <summary>
/// 重启软件
/// </summary>
public DelegateCommand ResetSoftCommand { get; set; }
/// <summary>
/// 退出程序
/// </summary>
public DelegateCommand CloseCommand { get; set; }
/// <summary>
/// 切换语言
/// </summary>
public DelegateCommand SwitchLanguageCommand { get; set; }
#endregion
#region 选中的TabItem
private TabItem selectTabItem;
/// <summary>
/// 选中的TabItem
/// </summary>
public TabItem SelectTabItem
{
get { return selectTabItem; }
set
{
selectTabItem = value;
if (AllVis == Visibility.Visible)
{
if (value.Tag != null && value.Tag.ToString() == "v")
{
GridWidth = "0";
}
else
{
GridWidth = "30*";
}
}
else
{
GridWidth = "30*";
}
this.RaisePropertyChanged("SelectTabItem");
}
}
#endregion
#region 当前生产的机种ID
private int currentMachineID;
/// <summary>
/// 当前生产的机种
/// </summary>
public int CurrentMachineID
{
get { return currentMachineID; }
set
{
currentMachineID = value;
this.RaisePropertyChanged("CurrentMachineID");
if (value <= 0)
{
return;
}
CurrentMachine = AllMachineList.Where(w => w.ID == value).FirstOrDefault(); //dal.ByIDGeMachine(value); //获取当前生产机种对象
if (Robot != null)
{
Robot.MachineObj = CurrentMachine;
}
if (MCVM != null)
{
MCVM.MachineObj = CurrentMachine;
}
if (HVlist != null)
{
foreach (HalconVisual hv in HVlist)
{
hv.MachineObj = CurrentMachine;
hv.QRModelInitialize = false;
hv.CodeModelInitialize = false;
}
}
//异步新增项 这是微软的BUG 只能这么麻烦了
// MyDispatcher.BeginInvoke(DispatcherPriority.Background, new ParameterizedThreadStart(ShuaxingContent), info);
SystemPar.DefaultMachineID = value;
dal.UpdateSystemPar(SystemPar); //更新默认机种
}
}
private void ShuaxingContent(object obj)
{
Take1 = new TrayModel(CurrentMachine, "料盘");
}
#endregion
#region 当前生产机种对象
private MachineModel currentMachine;
/// <summary>
/// 当前生产机种对象
/// </summary>
public MachineModel CurrentMachine
{
get { return currentMachine; }
set
{
currentMachine = value;
this.RaisePropertyChanged("CurrentMachine");
}
}
#endregion
#region 各步骤
#region 回原点步骤枚举
/// <summary>
/// 回原点步骤枚举
/// </summary>
GengralProcessEnum GoHomeSteps { get; set; }
#endregion
#endregion
#region 动态Grid控件
private Grid inputGrid;
/// <summary>
/// 输入信号Grid
/// </summary>
public Grid InputGrid
{
get { return inputGrid; }
set
{
inputGrid = value;
this.RaisePropertyChanged("InputGrid");
}
}
private Grid outputGrid;
/// <summary>
/// 输出信号Grid
/// </summary>
public Grid OutputGrid
{
get { return outputGrid; }
set
{
outputGrid = value;
this.RaisePropertyChanged("OutputGrid");
}
}
#endregion
#region 光源串口号
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 欧智通mes对象
private OuZhiTongMes oztmes;
/// <summary>
/// 欧智通MES对象
/// </summary>
public OuZhiTongMes Oztmes
{
get { return oztmes; }
set { oztmes = value; RaisePropertyChanged("Oztmes"); }
}
#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);
#endregion
GoHomeSteps = GengralProcessEnum.Start;
TestResult = new ShowInfo() { StatuInfo = "待运行...", StatuValue = 0.ToString(), StatusForeground = Colors.Yellow.ToString() };
//开启状态监控线程
if (ThStateMonitoring == null)
{
ThStateMonitoring = new Thread(StateMonitoring);
ThStateMonitoring.IsBackground = true;
ThStateMonitoring.Start();
}
//开启网络连接控制线程
//if (ThConnect == null)
//{
// ThConnect = new Thread(ConnectNet);
// ThConnect.IsBackground = true;
// ThConnect.Start();
//}
Transport1_1 = MCVM.AllShaftList.Where(w => w.InCode == "S1").FirstOrDefault();
Transport1_2 = MCVM.AllShaftList.Where(w => w.InCode == "S2").FirstOrDefault();
Transport3_1 = MCVM.AllShaftList.Where(w => w.InCode == "S5").FirstOrDefault();
Transport3_2 = MCVM.AllShaftList.Where(w => w.InCode == "S6").FirstOrDefault();
//初始化标签纸对象
GetMachineLabelGrid();
foreach (var item in XizuiLabelPaperList)
{
item.Point_Take1 = MCVM.TrajListL[0].PointList.Where(w => w.PointType == item.Number * 100 + 1).FirstOrDefault();
item.Point_Take2 = MCVM.TrajListL[0].PointList.Where(w => w.PointType == item.Number * 100 + 2).FirstOrDefault();
item.Point_Take3 = MCVM.TrajListL[0].PointList.Where(w => w.PointType == item.Number * 100 + 3).FirstOrDefault();
item.Point_Take4 = MCVM.TrajListL[0].PointList.Where(w => w.PointType == item.Number * 100 + 4).FirstOrDefault();
item.Point_Take5 = MCVM.TrajListL[0].PointList.Where(w => w.PointType == item.Number * 100 + 5).FirstOrDefault();
item.Point_Take6 = MCVM.TrajListL[0].PointList.Where(w => w.PointType == item.Number * 100 + 6).FirstOrDefault();
item.Point_Vision = MCVM.TrajListL[0].PointList.Where(w => w.PointType == item.Number + 1000).FirstOrDefault();
item.VacuumSwitch = OutputList[item.Number + 5]; //获取真空开关
item.VacuumCheck = InputList[item.Number + 9]; //获取真空捡知
}
Oztmes = new OuZhiTongMes(); //初始化mes信息
FeedingFlow = new FlowModel("送料流程");
HotBarRunFlow = new FlowModel("焊接流程");
ReceivingFlow = new FlowModel("出料流程");
HuiLiuRunFlow = new FlowModel("回流流程");
}
#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();
OutputList = dal.GetOutputList();
ERPVM = new ERPManageVM(SystemPar.ID, this.dal);
SCVM = new SerialComVM(SystemPar.ID); //串口对象
ServerComm = new CommunicationServerVM(SystemPar.ID, Mywindow.Dispatcher);
ServerComm.MonitorsWitch = true;
CVM = new ChartVM();//图表对象
//MachineLabelDev = ServerComm.CommList.Where(w => w.ShortCode == "BQJ").FirstOrDefault();
//MachineLabelDev.ReceiveCallback += MachineLabel_ReceiveCallback; ;
//机种参数
InitializeMachineEditor();
RunStartTime = DateTime.Now;//产能计时开始
//NextStation = ServerComm.CommList.Where(w => w.ShortCode == "XT").FirstOrDefault();
//NextStation.ReceiveCallback += NextStation_ReceiveCallback;
FrontStation = ServerComm.CommList.Where(w => w.ShortCode == "XT").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 <= 13)
{
row = count;
column = 1;
}
else
{
row = 13;
column = count / 13;
if (count % 13 > 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 });
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 <= 15)
{
row = count;
coloum = 1;
}
else
{
row = 15;
coloum = count / 15;
if (count % 15 > 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("LabelStyle");//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 });
//加一个控件修饰控件 用于控制字体的大小
Viewbox vb = new Viewbox();
vb.Stretch = Stretch.Uniform;
vb.StretchDirection = StretchDirection.Both;
//vb.HorizontalAlignment = HorizontalAlignment.Left;
if (Application.Current.Resources[Is.InputMeaning] != null)
{
vb.Child = new TextBlock() { Text = Application.Current.Resources[Is.InputMeaning].ToString() };
Labels.Content = vb; //Application.Current.Resources[Is.InputMeaning].ToString();
}
else
{
vb.Child = new TextBlock() { Text = Is.InputMeaning };
Labels.Content = vb; //Is.InputMeaning;
}
//设置前景色
Labels.Foreground = new SolidColorBrush(Colors.White);
//Labels.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>
DateTime tubiaoTime { get; set; }
/// <summary>
/// 状态监控
/// </summary>
private void StateMonitoring()
{
while (true)
{
Thread.Sleep(10);
//记录当前软件运行时间
TimeSpan ts = DateTime.Now.Subtract(OpenTime).Duration();
OpenTimeStr = string.Format("{0}天{1}小时{2}分{3}秒", ts.Days, ts.Hours, ts.Minutes, ts.Seconds);
if (MCVM == null || MCVM.ConnectAllCard())
{
#region 1、输入信号状态
foreach (InputSignal input in InputList)
{
input.GetInputLever();
}
if (InputList[0].LightUp)
{
Start(0);//启动信号
}
if (InputList[1].LightUp)
{
Stop(0); //停止信号
}
if (InputList[2].LightUp)
{
EmgStop();// 急停信号
}
if (InputList[4].LightUp)
{
ExcepStop(InputList[4].InputMeaning);// 急停信号
}
if (InputList[26].LightUp)
{
ExcepStop(InputList[26].InputMeaning);// 急停信号
}
#endregion
#region 获取轴状态
if (MCVM != null)
{
MCVM.OrginALL(InputList[2]);
if (RunStatu != RunStatuEnum.Normal)
{
MCVM.PointRun();
mCVM.RunMotionTrajectory();
}
}
#endregion
//双控IO 和AC马达控制
DoubleCylinder();
//回原点
GoHome();
//ChuansongDaiKongzhi();
}
//else
//{
// ExcepStop("运动控制卡未连接");
//}
}
}
#region 回原点
DateTime GoHomeTime { get; set; }
/// <summary>
/// 回原点
/// </summary>
private void GoHome()
{
switch (GoHomeSteps)
{
case GengralProcessEnum.Start:
//吸嘴必须在原位 双向气缸
//OutputList[4].Switchs = true;
//if (SystemPar.WhereOnLine)
//{
// OutputList[14].Switchs = true;
// OutputList[16].Switchs = true;
//}
//解除Z轴刹车
OutputList[17].Switchs = true;
OutputList[18].Switchs = true;
GoHomeSteps++;
GoHomeTime = DateTime.Now;
break;
case GengralProcessEnum.Step1:
GoHomeSteps++;
GoHomeTime = DateTime.Now;
break;
case GengralProcessEnum.Step2:
//优先机械手回原点
if (Robot != null)
{
if (Robot.HomeStep == GengralProcessEnum.End)
{
GoHomeSteps++;
}
else
{
Robot.RobotOrgin();
}
}
else
{
GoHomeSteps++;
}
break;
case GengralProcessEnum.Step3:
if (MCVM != null)
{
MCVM.HomeStep = GengralProcessEnum.Start;
GoHomeSteps++;
}
else
{
GoHomeSteps = GengralProcessEnum.End;
RunStatu = RunStatuEnum.Prepareations; //准备就绪
}
break;
case GengralProcessEnum.Step4:
if (MCVM.HomeStep == GengralProcessEnum.End)
{
GoHomeSteps = GengralProcessEnum.End;
RunStatu = RunStatuEnum.Prepareations; //准备就绪
}
break;
}
}
#endregion
#endregion
#region 3、运行
#region 检测测试状态
private ShowInfo testResult;
/// <summary>
/// 检测测试状态
/// </summary>
public ShowInfo TestResult
{
get { return testResult; }
set
{
testResult = value;
this.RaisePropertyChanged("TestResult");
}
}
#endregion
#region 标签机
private CommunicationManagementClass machineLabelDev;
/// <summary>
/// 标签机
/// </summary>
public CommunicationManagementClass MachineLabelDev
{
get { return machineLabelDev; }
set
{
machineLabelDev = value;
this.RaisePropertyChanged("MachineLabelDev");
}
}
private CommunicationManagementClass zebralabelDev;
/// <summary>
/// 斑马打印机
/// </summary>
public CommunicationManagementClass ZebralabelDev
{
get { return zebralabelDev; }
set { zebralabelDev = value; this.RaisePropertyChanged("ZebralabelDev"); }
}
/// <summary>
/// 在线打标OK
/// </summary>
bool MarkingOK { get; set; }
/// <summary>
/// 标签机回调函数
/// </summary>
/// <param name="str"></param>
private void MachineLabel_ReceiveCallback(string str)
{
MarkingOK = true;
}
#endregion
#region 打印标签
/// <summary>
/// 打印标签方法,传入标签属性对象
/// </summary>
/// <param name="properties"></param>
/// <returns></returns>
public string PrintLabels(LabelProperties properties)
{
var zplCommands = new StringBuilder();
zplCommands.AppendLine("^XA");
zplCommands.AppendLine($"^LT{properties.LabelOffsetY}");
zplCommands.AppendLine($"^LH{properties.LabelOffsetX},0");
for (int i = 0; i < properties.LabelSnList.Count; i++)
{
var item = properties.LabelSnList[i];
int xOffset = properties.QRCodeStartX + i * (properties.QRCodeSize + properties.Spacing);
zplCommands.AppendLine($"^FT{xOffset},{properties.QRCodeStartY + properties.QRCodeSize}");
zplCommands.AppendLine($"^BQN,2,{properties.QRCodeSize}");
zplCommands.AppendLine($"^FH\\^FDLA,{item}^FS");
zplCommands.AppendLine($"^FT{xOffset},{properties.QRCodeStartY + properties.QRCodeSize + properties.TextFontSize + properties.QRTextSpacingOffset}");
zplCommands.AppendLine($"^A0N,{properties.TextFontSize},{properties.TextFontSize}");
zplCommands.AppendLine($"^FH\\^FD{properties.TextContent}^FS");
}
zplCommands.AppendLine("^XZ");
return zplCommands.ToString();
}
#endregion
int CurrHandxiCount { get; set; }
/// <summary>
/// 启动运行
/// </summary>
private void Run()
{
while (true)
{
Thread.Sleep(10);
if (RunStatu == RunStatuEnum.Normal)
{
try
{
if (CurrHandxiCount < CurrentMachine.HanxiCount)
{
FeedingRun(FeedingFlow);
}
else
{
// HotBarQingjieRun(QingjieFlow);
CurrHandxiCount = 0;
ExcepStop("请清洁焊头");
}
if (CurrentMachine.MyQita.DanJi == false)
{
HuiLiuRun(HuiLiuRunFlow);
}
}
catch (Exception ex)
{
ExcepStop(ex.Message);
}
}
else
{
OutputList[12].Switchs = false;
OutputList[13].Switchs = false;
}
}
}
#region 连接检查
/// <summary>
/// 连接检查
/// </summary>
private bool ComCheck()
{
if (CurrentMachine.RunningMode || !SystemPar.WhereOnLine)
{
return true;
}
//连接标签机
if (!MachineLabelDev.ConnectSwitch)
{
MachineLabelDev.ConnectSwitch = true;
}
else if (MachineLabelDev.Showmsg.StatusBackground != ColorStr.Green)
{
MachineLabelDev.ConnectSwitch = false;
}
if (MachineLabelDev.Showmsg.StatusBackground != ColorStr.Green)
{
ExcepStop(MachineLabelDev.ActionName + "连接失败");
return false;
}
return true;
}
#endregion
DateTime upTime = DateTime.Now;
int upType;
bool upExsit, downExsit;
#region 双控气缸控制与IO马达控制
/// <summary>
/// 双控气缸控制与IO马达控制
/// </summary>
private void DoubleCylinder()
{
//Z轴刹车
OutputList[17].Switchs = true;
OutputList[18].Switchs = true;
//顶升气缸
if (OutputList[7].Switchs)
{
OutputList[6].Switchs = false;
}
else
{
OutputList[6].Switchs = true;
}
if (upTime.AddSeconds(0.1) < DateTime.Now && upType == 0) {
upTime = DateTime.Now;
upType = 1;
if (InputList[6].LightUp || (InputList[12].LightUp == false && InputList[14].LightUp == false) || RunStatu != RunStatuEnum.Normal)
{
SendFrontStation(VehicleRevoke);
}
else {
SendFrontStation(VehicleRequest);
}
}
//回流到位检知,向后站撤销要料
if (upTime.AddSeconds(0.1) < DateTime.Now && upType == 1)
{
upTime = DateTime.Now;
upType = 0;
if (InputList[9].LightUp || InputList[10].LightUp || InputList[11].LightUp || downExsit || RunStatu != RunStatuEnum.Normal)
{
SendFrontStation(BackflowRevoke);
}
else
{
SendFrontStation(BackflowRequest);
}
}
}
#endregion
#region 送料运行
/// <summary>
/// 送料步骤
/// </summary>
FlowModel FeedingFlow { get; set; }
/// <summary>
/// 传送轴1
/// </summary>
FeiYuShaft Transport1_1 { get; set; }
/// <summary>
/// 传送轴2
/// </summary>
FeiYuShaft Transport1_2 { get; set; }
/// <summary>
/// 送料运行
/// </summary>
private void FeedingRun(FlowModel MyFlow)
{
switch (MyFlow.RunStep)
{
case GengralProcessEnum.Start:
if (CurrentMachine.MyQita.DanJi == false)
{
//缓存区阻挡气缸升起
OutputList[4].Switchs = false;
//上皮带停转
OutputList[8].Switchs = false;
MyFlow.RunStep++;
}
else {
HotBarRunFlow = new FlowModel("焊接流程");
MyFlow.RunStep= GengralProcessEnum.Step6;
}
MyFlow.RunTime = DateTime.Now;
break;
case GengralProcessEnum.Step1:
//缓存区阻挡原位
if (InputList[12].LightUp)
{
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
}
break;
case GengralProcessEnum.Step2:
//缓存入料捡知
if (InputList[7].LightUp)
{
//向前站发送撤销载具请求
upExsit = true;
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
//缓存阻挡下降
OutputList[4].Switchs = false;
}
else
{
upExsit = false;
//上皮带正转
OutputList[8].Switchs = true;
//缓存阻挡下降
OutputList[4].Switchs = true;
}
break;
case GengralProcessEnum.Step3:
if (InputList[12].LightUp)
{
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
}
else if (TimeOutValidation(MyFlow.RunTime, 3000, InputList[12].InputMeaning + "异常"))
{
//缓存阻挡下降
OutputList[4].Switchs = true;
MyFlow.RunTime = DateTime.Now;
}
break;
case GengralProcessEnum.Step4:
//入料捡知保持500毫秒,预防光电闪烁造成的误感应
if ((InputList[7].LightUp && MyFlow.RunTime.AddMilliseconds(500) < DateTime.Now) || CurrentMachine.RunningMode)
{
//上皮带正转
//缓存阻挡下降
OutputList[4].Switchs = false;
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
}
else if (MyFlow.RunTime.AddMilliseconds(1000) < DateTime.Now)
{
MyFlow.RunStep--;
MyFlow.RunTime = DateTime.Now;
}
break;
case GengralProcessEnum.Step5:
if (InputList[12].LightUp)
{
HotBarRunFlow = new FlowModel("焊接流程");
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
}
else if (TimeOutValidation(MyFlow.RunTime, 3000, InputList[12].InputMeaning + "异常"))
{
MyFlow.RunTime = DateTime.Now;
}
break;
case GengralProcessEnum.Step6:
//等待焊接完成
if (!CurrentMachine.RunningMode)
{
if (HotBarRun(HotBarRunFlow))
{
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
}
}
else
{
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
}
break;
case GengralProcessEnum.Step7:
if (CurrentMachine.MyQita.DanJi == false)
{
//下站有载具请求
if (CurrNextStr == VehicleRequest)
{
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
//焊接阻挡
OutputList[5].Switchs = true;
}
else
{
OutputList[5].Switchs = false;
}
}
else {
MyFlow.RunStep = GengralProcessEnum.Start;
Stop(0); //停止信号
}
break;
case GengralProcessEnum.Step8:
//缓存阻挡下降到位,捡知保持500毫秒,预防光电闪烁造成的误感应
if (InputList[15].LightUp)
{
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
//上皮带正转
OutputList[8].Switchs = true;
}
else if (TimeOutValidation(MyFlow.RunTime, 3000, InputList[15].InputMeaning + "异常"))
{
MyFlow.RunTime = DateTime.Now;
}
break;
case GengralProcessEnum.Step9:
//载具流出完成
//if (CurrNextStr != VehicleRequest)
if (!InputList[8].LightUp&& !InputList[7].LightUp)
{
//上皮带停转
OutputList[8].Switchs = false;
OutputList[5].Switchs = false;
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
}
else
{
//上皮带正转
OutputList[8].Switchs = true;
}
break;
case GengralProcessEnum.Step10:
if (InputList[14].LightUp)
{
MyFlow.RunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
//上皮带停转
OutputList[8].Switchs = false;
}
else if (TimeOutValidation(MyFlow.RunTime, 3000, InputList[15].InputMeaning + "异常"))
{
MyFlow.RunTime = DateTime.Now;
}
break;
}
}
#endregion
#region 焊接运行
/// <summary>
/// 焊接运行流程
/// </summary>
public FlowModel HotBarRunFlow { get; set; }
/// <summary>
/// 焊锡点1到位
/// </summary>
bool dw1 { get; set; }
/// <summary>
/// 焊锡点2到位
/// </summary>
bool dw2 { get; set; }
MotionPointModel TempPoint { get; set; }
MotionPointModel TempPoint2 { get; set; }
/// <summary>
/// 焊接运行
/// </summary>
/// <param name="MyFlow"></param>
private bool HotBarRun(FlowModel MyFlow)
{
bool bl = false;
switch (MyFlow.RunStep)
{
case GengralProcessEnum.Start:
if (CurrentMachine.MyQita.DanJi == false)
{
//载具到焊接位
if (InputList[7].LightUp)
{
//顶升气缸
OutputList[7].Switchs = true;
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
}
}
else {
MyFlow.RunStep++;
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
}
break;
case GengralProcessEnum.Step1:
//顶升到位
if (InputList[17].LightUp)
{
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
}
else if (TimeOutValidation(MyFlow.RunTime, 10000, InputList[17].InputMeaning + "异常超时"))
{
MyFlow.RunTime = DateTime.Now;
}
break;
case GengralProcessEnum.Step2:
//左右焊机Ready
if (InputList[20].LightUp && InputList[21].LightUp)
{
//获取焊接点位
TempPoint = Coper( MCVM.TrajListL[0].PointList.Where(w => w.PointType == 10).FirstOrDefault());
TempPoint2 = Coper(MCVM.TrajListL[0].PointList.Where(w => w.PointType == 20).FirstOrDefault());
TempPoint.PointRunStep = GengralProcessEnum.Start;
TempPoint2.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
dw1 = false;
dw2 = false;
}
else if (TimeOutValidation(MyFlow.RunTime, 10000, InputList[20].InputMeaning + "/" + InputList[21].InputMeaning + "异常"))
{
MyFlow.RunTime = DateTime.Now;
}
break;
case GengralProcessEnum.Step3:
if (!dw1)
{
dw1 = TempPoint.PointRun(MCVM.AllShaftList);
}
if (!dw2)
{
dw2 = TempPoint2.PointRun(MCVM.AllShaftList);
}
//焊接轴到位下降
if (dw1 && dw2)
{
//焊机启动1
OutputList[12].Switchs = true;
//启动焊机2
OutputList[13].Switchs = true;
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
dw1 = false;
dw2 = false;
TempPoint.PointRunStep = GengralProcessEnum.Start;
TempPoint2.PointRunStep = GengralProcessEnum.Start;
TempPoint.ShaftPoint_Z += CurrentMachine.MyQita.XiaYa;
TempPoint2.ShaftPoint_Z += CurrentMachine.MyQita.XiaYa;
}
else if (TimeOutValidation(MyFlow.RunTime, 10000, "焊接位运行异常"))
{
TempPoint.PointRunStep = GengralProcessEnum.Start;
TempPoint2.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunStep--;
MyFlow.RunTime = DateTime.Now;
}
break;
case GengralProcessEnum.Step4:
//吹气信号
if (InputList[24].LightUp)
{
if (!dw1)
{
dw1 = TempPoint.PointRun(MCVM.AllShaftList);
}
if (!dw2)
{
dw2 = TempPoint2.PointRun(MCVM.AllShaftList);
}
//焊机1
OutputList[12].Switchs = false;
OutputList[14].Switchs = true;
}
if (InputList[25].LightUp)
{
//焊机2
OutputList[13].Switchs = false;
OutputList[15].Switchs = true;
}
if (OutputList[14].Switchs && OutputList[15].Switchs)
{
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
}
else if (TimeOutValidation(MyFlow.RunTime, 20000, "吹气信号异常"))
{
MyFlow.RunTime = DateTime.Now;
}
break;
case GengralProcessEnum.Step5:
if (MyFlow.RunTime.AddMilliseconds(CurrentMachine.HanxiTime) <= DateTime.Now)
{
//全部Z轴上上升到0点
List<FeiYuShaft> list = MCVM.AllShaftList.Where(w => w.InCode == "Z").ToList();
if (list != null)
{
list.ForEach(w => w.GengrelMp.ActualDir = 0);
foreach (var item in list)
{
item.DZDC(item.GengrelMp);
}
if (list.Where(w => w.ActualDir != 0).Count() <= 0)
{
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
}
else if (TimeOutValidation(MyFlow.RunTime, 10000, "Z轴抬升异常"))
{
MyFlow.RunTime = DateTime.Now;
}
}
//吹气
OutputList[14].Switchs = false;
OutputList[15].Switchs = false;
if (CurrentMachine.MyQita.DanJi == false)
{
//顶升,阻挡下降
OutputList[7].Switchs = false;
}
else {
CurrHandxiCount++;
CurrentMachine.Quantitys += 2;
bl = true;
MyFlow.RunStep = GengralProcessEnum.End;
MyFlow.RunTime = DateTime.Now;
}
}
break;
case GengralProcessEnum.Step6:
if (InputList[16].LightUp)
{
CurrHandxiCount++;
CurrentMachine.Quantitys += 2;
CurrentMachine.Produce = CurrHandxiCount;
QingjieFlow = new FlowModel("清洁流程");
bl = true;
MyFlow.RunStep = GengralProcessEnum.End;
MyFlow.RunTime = DateTime.Now;
}
else if (TimeOutValidation(MyFlow.RunTime, 10000, InputList[16].InputMeaning + "异常"))
{
MyFlow.RunTime = DateTime.Now;
}
break;
}
return bl;
}
/// <summary>
/// 清洁流程
/// </summary>
FlowModel QingjieFlow { get; set; }
/// <summary>
/// 焊接清洁运行
/// </summary>
/// <param name="MyFlow"></param>
private bool HotBarQingjieRun(FlowModel MyFlow)
{
bool bl = false;
switch (MyFlow.RunStep)
{
case GengralProcessEnum.Start:
TempPoint = MCVM.TrajListL[0].PointList.Where(w => w.PointType == 30).FirstOrDefault();
TempPoint2 = MCVM.TrajListL[0].PointList.Where(w => w.PointType == 40).FirstOrDefault();
TempPoint.PointRunStep = GengralProcessEnum.Start;
TempPoint2.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
dw1 = false;
dw2 = false;
break;
case GengralProcessEnum.Step1:
if (!dw1)
{
dw1 = TempPoint.PointRun(MCVM.AllShaftList);
}
if (!dw2)
{
dw2 = TempPoint2.PointRun(MCVM.AllShaftList);
}
//到达清洁点
if (dw1 && dw2)
{
//电笔旋转
OutputList[10].Switchs = true;
OutputList[11].Switchs = true;
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
}
else if (TimeOutValidation(MyFlow.RunTime, 10000, "清洁点位运行异常"))
{
TempPoint.PointRunStep = GengralProcessEnum.Start;
TempPoint2.PointRunStep = GengralProcessEnum.Start;
MyFlow.RunStep--;
MyFlow.RunTime = DateTime.Now;
}
break;
case GengralProcessEnum.Step2:
if (MyFlow.RunTime.AddMilliseconds(CurrentMachine.QingjieTime) <= DateTime.Now)
{
//电笔旋转
OutputList[10].Switchs = false;
OutputList[11].Switchs = false;
bl = true;
MyFlow.RunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
CurrHandxiCount = 0;
}
break;
}
return bl;
}
#endregion
#region 回流运行
/// <summary>
/// 回流运行流程
/// </summary>
public FlowModel HuiLiuRunFlow { get; set; }
/// <summary>
/// 回流运行
/// </summary>
/// <param name="MyFlow"></param>
private void HuiLiuRun(FlowModel MyFlow)
{
switch (MyFlow.RunStep)
{
case GengralProcessEnum.Start:
//回流到位检知有
if (InputList[11].LightUp)
{
downExsit = true;
MyFlow.RunStep = GengralProcessEnum.Step10;
MyFlow.RunTime = DateTime.Now;
}
else
{
downExsit = false;
MyFlow.RunStep = GengralProcessEnum.Step20;
MyFlow.RunTime = DateTime.Now;
}
OutputList[9].Switchs = false; //回流皮带
break;
case GengralProcessEnum.Step10:
//前瞻回流要料
if (CurrHuiliuStr == BackflowRequest)
{
OutputList[9].Switchs = true; //回流皮带
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
}
else
{
OutputList[9].Switchs = false; //回流皮带
}
break;
case GengralProcessEnum.Step11:
//前站回流要料撤销
if (CurrHuiliuStr == BackflowRevoke || !InputList[11].LightUp)
{
OutputList[9].Switchs = false; //回流皮带
MyFlow.RunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
OutputList[16].Switchs = false;
}
else
{
OutputList[16].Switchs = true;
OutputList[9].Switchs = true; //回流皮带
}
break;
case GengralProcessEnum.Step20:
//回流进料检知
if (InputList[9].LightUp|| InputList[10].LightUp)
{
OutputList[9].Switchs = true; //回流皮带
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
}
else
{
}
break;
case GengralProcessEnum.Step21:
//回流到位检知
if (InputList[11].LightUp)
{
OutputList[9].Switchs = false; //回流皮带
MyFlow.RunStep = GengralProcessEnum.Start;
MyFlow.RunTime = DateTime.Now;
OutputList[16].Switchs = false;
}
else
{
OutputList[9].Switchs = true; //回流皮带
}
break;
}
}
#endregion
#region 收料运行
/// <summary>
/// 收料步骤
/// </summary>
FlowModel ReceivingFlow { get; set; }
/// <summary>
/// 出料输送轴1
/// </summary>
FeiYuShaft Transport3_1 { get; set; }
/// <summary>
/// 出料输送轴2
/// </summary>
FeiYuShaft Transport3_2 { get; set; }
/// <summary>
/// 出料皮带控制
/// </summary>
bool TransportControl3 { get; set; }
/// <summary>
/// 收料运行
/// </summary>
private void ReceivingRun(FlowModel MyFlow)
{
switch (MyFlow.RunStep)
{
case GengralProcessEnum.Start:
//下站有请求 且流出感应有
if (InputList[7].LightUp)
{
if (InputList[16].LightUp)//下站有请求
{
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
TransportControl3 = true;
}
if (TransportControl3)
{
TransportControl3 = false;
}
}
break;
case GengralProcessEnum.Step1:
if (Transport3_1.ShaftState.StatusBackground == ColorStr.Green && Transport3_2.ShaftState.StatusBackground == ColorStr.Green)
{
if (!InputList[7].LightUp)
{
MyFlow.RunStep++;
MyFlow.RunTime = DateTime.Now;
}
else if (TimeOutValidation(MyFlow.RunTime, 10000, InputList[7].InputMeaning + "异常"))
{
MyFlow.RunTime = DateTime.Now;
}
}
else if (TimeOutValidation(MyFlow.RunTime, 10000, "出料传送轴异常"))
{
MyFlow.RunTime = DateTime.Now;
}
break;
case GengralProcessEnum.Step2:
if (!InputList[16].LightUp)
{
MyFlow.RunStep = GengralProcessEnum.Start;
TransportControl3 = false;
}
else if (TimeOutValidation(MyFlow.RunTime, 10000, InputList[16].InputMeaning + "异常超时"))
{
MyFlow.RunTime = DateTime.Now;
}
break;
}
}
#endregion
#region 上一站连接
/// <summary>
/// 上一站连接
/// </summary>
public CommunicationManagementClass FrontStation { get; set; }
#endregion
#region 下一站连接
/// <summary>
/// 下一站连接
/// </summary>
public CommunicationManagementClass NextStation { get; set; }
#endregion
#region 发送消息给下一站
DateTime SendNextStationTime { get; set; }
/// <summary>
/// 发送消息给下一站
/// </summary>
/// <param name="VehicleStr"></param>
private void SendNextStation(string VehicleStr)
{
if (SendNextStationTime.AddMilliseconds(500) < DateTime.Now)
{
NextStation.SendInfo(VehicleStr);
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 (FrontStation.Showmsg.StatusBackground == ColorStr.Green)
{
FrontStation.SendInfo(CommandStr);
}
else {
FrontStation.ConnectSwitch = !FrontStation.ConnectSwitch;
}
}
#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>();
//先加载一个视觉运行预览界面
//Views.Vision.AOI2 aoi2 = new Views.Vision.AOI2();
//TabItem tabiyu = new TabItem() { Content = aoi2 };
////tabiyu.SetResourceReference(TabItem.HeaderProperty, "视觉预览"); //设定资源引用 即可进行语言的切换
//tabiyu.Header = "视觉预览";
//TabItemList.Add(tabiyu);
//foreach (FeiYuCamere cam in Camlist)
//{
// HalconVisual hv = new HalconVisual(CurrentMachine, LightCOM, cam);
// HVlist.Add(hv);
// TabItem tabi = new TabItem() { Content = hv.MyWindow, Tag = "v" };
// //tabi.SetResourceReference(TabItem.HeaderProperty, cam.VisualName); //设定资源引用 即可进行语言的切换
// tabi.Header = cam.VisualName;
// tabi.SetBinding(TabItem.VisibilityProperty, new Binding("AllVis"));
// TabItemList.Add(tabi);
//}
//VisualA = HVlist[0];
//VisualB = HVlist[1];
//VisualC = HVlist[2];
// VisualD = HVlist[3];
}
if (SystemPar.MotionControlBool)
{
MCVM = new MotionControlVM(CurrentMachine, InputList, OutputList);
MCVM.eventExcepReport += ExcepStop;
TabItem tbai = new TabItem() { Content = MCVM.MyWindow };
// tbai.SetResourceReference(TabItem.HeaderProperty, "运动控制"); //设定资源引用 即可进行语言的切换
tbai.Header = "运动控制";
tbai.SetBinding(TabItem.VisibilityProperty, new Binding("AllVis"));
TabItemList.Add(tbai);
}
if (SystemPar.RobotBool)
{
switch (SystemPar.RobotBrand)
{
case 0:
Robot = new EpsonRobotVM(CurrentMachine);//初始化爱普生机器人
break;
case 1:
Robot = new FanucRobotVM(CurrentMachine);//初始化发那科机器人
break;
case 2:
Robot = new QkmRobotVM(CurrentMachine);//初始化发那科机器人
break;
}
Robot.eventExcepReport += ExcepStop;
TabItem tbai = new TabItem() { Content = Robot.MyWindow };
//tbai.SetResourceReference(TabItem.HeaderProperty, "机器人"); //设定资源引用 即可进行语言的切换
tbai.Header = "机器人";
tbai.SetBinding(TabItem.VisibilityProperty, new Binding("AllVis"));
TabItemList.Add(tbai);
}
TabItem ti = new TabItem() { Content = new ParameterSetting() };
// ti.SetResourceReference(TabItem.HeaderProperty, "参数设置"); //设定资源引用 即可进行语言的切换
ti.Header = "参数设置";
ti.SetBinding(TabItem.VisibilityProperty, new Binding("AllVis"));
TabItemList.Add(ti);
TabItem t2 = new TabItem() { Content = new LogInformation() };
//t2.SetResourceReference(TabItem.HeaderProperty, "日志信息"); //设定资源引用 即可进行语言的切换
t2.Header = "日志信息";
TabItemList.Add(t2);
SelectTabItem = TabItemList[0];
}
#endregion
#region 前站回调函数
/// <summary>
/// 载具请求 03kx
/// </summary>
string VehicleRequest = "03kx";
/// <summary>
/// 撤销载具 03ml
/// </summary>
string VehicleRevoke = "03ml";
/// <summary>
/// 回流请求 03hlkx
/// </summary>
string BackflowRequest = "03hlkx";
/// <summary>
/// 撤销回流 03hlml
/// </summary>
string BackflowRevoke = "03hlml";
/// <summary>
/// 前站发来的字符串拆解
/// </summary>
List<string> NewsList { get; set; }
/// <summary>
/// 当前回流请求状态
/// </summary>
string CurrHuiliuStr { get; set; }
/// <summary>
/// 当前前站请求状态
/// </summary>
string CurrFrontStationStr { get; set; }
int SwitchMachineID { get; set; }
/// <summary>
/// 前站回调函数
/// </summary>
/// <param name="str"></param>
private void FrontStation_ReceiveCallback(string str)
{
try
{
//NewsList = str.Split(' ').ToList();
//string str0 = NewsList[0].Split(':')[1];
//string str1 = NewsList[2].Split(':')[1];
//string str2 = NewsList[9].Split(':')[1];
if(str.Contains("21x:0"))
{
CurrHuiliuStr = BackflowRequest;
}
else
{
CurrHuiliuStr = BackflowRevoke;
}
if (str.Contains("04s:0"))
{
CurrNextStr = VehicleRequest;
}
else
{
CurrNextStr = VehicleRevoke;
}
//switch (str1)
//{
// case "0":
// CurrHuiliuStr = BackflowRequest;
// break;
// case "1":
// CurrHuiliuStr = BackflowRevoke;
// break;
// case "2":
// //CurrFrontStationStr = SendRequest;
// break;
//}
//switch (str1)
//{
// case "0":
// CurrNextStr = VehicleRequest;
// break;
// case "1":
// CurrNextStr = VehicleRevoke;
// break;
// case "2":
// //CurrFrontStationStr = SendRequest;
// break;
//}
}
catch (Exception)
{
}
}
#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)
{
NextStrList = str.Split(':').ToList();
switch (NextStrList[0])
{
case "ZJQQ":
CurrNextStr = VehicleRequest;
break;
case "CXZJ":
CurrNextStr = VehicleRevoke;
break;
}
}
#endregion
#region 验证是否超时
/// <summary>
/// 验证是否超时
/// </summary>
/// <param name="tiem">起点时间</param>
/// <param name="timeLimit">时限(毫秒)</param>
/// <param name="showMsg">报错信息</param>
private bool TimeOutValidation(DateTime tiem, int timeLimit, string showMsg)
{
if (tiem.AddMilliseconds(timeLimit) < DateTime.Now)
{
ExcepStop(showMsg);
return true;
}
else
{
return false;
}
}
#endregion
#region 异常停止 +ExcepStop(string showMag)
/// <summary>
/// 异常停止
/// </summary>
/// <param name="showMag"></param>
public void ExcepStop(string showMag)
{
if (RunStatu != RunStatuEnum.Stop && RunStatu != RunStatuEnum.EmgStop && RunStatu != RunStatuEnum.Exceptional)
{
RunStatu = RunStatuEnum.Exceptional;
ShowStatu.StatuInfo = showMag;
//记录异常信息
try
{
RecordLog(showMag);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
#endregion
#region 启动按钮 +void Start(object per)
/// <summary>
/// 启动按钮
/// </summary>
/// <param name="per"></param>
public void Start(object per)
{
//Take1.MyLabelList.ForEach(w => w.Prouct.StateColour = ColorStr.Blue);//全部变蓝色
//return;
if (GoHomeSteps != GengralProcessEnum.End)
{
return;
}
if (RunStatu != RunStatuEnum.Stop && RunStatu != RunStatuEnum.Prepareations)
{
return;
}
try
{
FeedingFlow.RunTime = DateTime.Now;
ReceivingFlow.RunTime = DateTime.Now;
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)
{
if (RunStatu != RunStatuEnum.Stop)
{
RunStatu = RunStatuEnum.Stop;
RecordLog("停止运行");
}
//皮带停转
OutputList[8].Switchs = false;
OutputList[9].Switchs = false;
}
#endregion
#region 重启按钮 +void ResetSoft(object obj)
/// <summary>
/// 重启按钮
/// </summary>
/// <param name="obj"></param>
private void ResetSoft(object obj)
{
if (RunStatu == RunStatuEnum.Normal)
{
MessageBox.Show("机器运行中,无法重启");
return;
}
//如果运行线程还在运行
if (ThRun != null)
{
ThRun.Abort();
ThRun = null;
}
MessageBoxResult res = MessageBox.Show("你确定要重新启动软件吗?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Asterisk);
if (res == MessageBoxResult.Yes)
{
ResetALL(); //重置所有参数
RecordLog("重新开始");
}
}
/// <summary>
/// 重置所有
/// </summary>
private void ResetALL()
{
foreach (OutputSignal os in OutputList)
{
os.Switchs = false;
}
AllVis = Visibility.Collapsed;
ShowStatu = new ShowInfo();
RunStatu = RunStatuEnum.Prepare;
ExcepList = new ObservableCollection<RecordInfo>();
if (Robot != null)
{
Robot.HomeStep = GengralProcessEnum.Start;
}
if (MCVM != null)
{
foreach (var item in MCVM.AllShaftList)
{
item.ShaftStop();
}
}
GoHomeSteps = GengralProcessEnum.Start;
FeedingFlow = new FlowModel("送料流程");
ReceivingFlow = new FlowModel("出料流程");
}
#endregion
#region 紧急停止按钮 +void EmgStop()
/// <summary>
/// 紧急停止工作
/// </summary>
public void EmgStop()
{
if (RunStatu != RunStatuEnum.EmgStop)
{
if (ThRun != null) //停止线程
{
ThRun.Abort();
ThRun = null;
}
if (MCVM != null)
{
foreach (FeiYuShaft sf in MCVM.AllShaftList)
{
sf.ShaftStop();
}
}
RunStatu = RunStatuEnum.EmgStop;
RecordLog("紧急停止");
}
}
#endregion
#region 关闭程序按钮
/// <summary>
/// 关闭程序确认的返回值
/// </summary>
public MessageDialogResult CloseRes { get; set; }
/// <summary>
/// 关闭程序按钮
/// </summary>
/// <param name="obj"></param>
public void Close(object obj)
{
if (RunStatu == RunStatuEnum.Normal)
{
MyMessageBox.Show("设备运行中无法退出,请先停止运行");
return;
}
// Take1.GetTrayState(CurrentMachine);//获取当前生产产品状态
dal.UpdateProductionData(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)
{
VisualA.CamReset(0);
}
if (MCVM != null)
{
foreach (FeiYuCard cd in MCVM.CardList)
{
cd.MoveFunction_Estop();
}
}
System.Environment.Exit(0);
}
#endregion
#region 切换系统语言
/// <summary>
/// 切换系统语言
/// </summary>
/// <param name="obj"></param>
private void SwitchLanguage(object obj)
{
if (obj != null)
{
//在APP.xaml中第四个引用是语言字典资源
Application.Current.Resources.MergedDictionaries[4].Source = new Uri(@"./Language/" + SystemPar.SystemLanguage, UriKind.RelativeOrAbsolute); //切换语言
}
else
{
if (SystemPar.SystemLanguage == "zh-cn.xaml")
{
Application.Current.Resources.MergedDictionaries[4].Source = new Uri(@"./Language/en-us.xaml", UriKind.RelativeOrAbsolute);
SystemPar.SystemLanguage = "en-us.xaml";
}
else if (SystemPar.SystemLanguage == "en-us.xaml")
{
Application.Current.Resources.MergedDictionaries[4].Source = new Uri(@"./Language/zh-cn.xaml", UriKind.RelativeOrAbsolute);
SystemPar.SystemLanguage = "zh-cn.xaml";
}
//机器状态描述语言切换
ShowStatu.StatuInfo = ShowStatu.StatuInfoTemp;
//权限按钮语言切换
PermissionButtonName = Application.Current.Resources[AllVis == Visibility.Collapsed ? "编辑模式" : "普通模式"].ToString();
if (MCVM != null)
{
foreach (FeiYuShaft df in MCVM.AllShaftList)
{
df.ShaftState.StatuInfo = df.ShaftState.StatuInfoTemp;
}
}
//输入信号语言切换
if (InputList != null && InputList.Count > 0)
{
InputGrid = GetInputGrid();
}
//输出信号语言切换
if (OutputList != null && OutputList.Count > 0)
{
OutputGrid = GetOutputGrid();
}
}
}
#endregion
#region 利用反射进行对象复制
/// <summary>
/// 利用反射进行对象复制
/// </summary>
/// <typeparam name="InsertRunPar">复制对象类型</typeparam>
/// <param name="startPoint">被复制对象</param>
/// <returns></returns>
public RobotPoint Coper(RobotPoint startPoint)
{
RobotPoint irpa = new RobotPoint();
try
{
var Types = startPoint.GetType();//获得类型
var Typed = irpa.GetType();
foreach (PropertyInfo sp in Types.GetProperties())//获得类型的属性字段
{
foreach (PropertyInfo dp in Typed.GetProperties())
{
if (dp.Name == sp.Name)//判断属性名是否相同
{
dp.SetValue(irpa, sp.GetValue(startPoint, null), null);//获得s对象属性的值复制给d对象的属性
}
}
}
}
catch (Exception ex)
{
throw ex;
}
return irpa;
}
/// <summary>
/// 利用反射进行对象复制
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="Coperobj"></param>
/// <returns></returns>
public T Coper<T>(T Coperobj)
{
T a = System.Activator.CreateInstance<T>();
try
{
var Types = Coperobj.GetType();//获得类型
var Typed = a.GetType();
foreach (PropertyInfo sp in Types.GetProperties())//获得类型的属性字段
{
foreach (PropertyInfo dp in Typed.GetProperties())
{
if (dp.Name == sp.Name)//判断属性名是否相同
{
dp.SetValue(a, sp.GetValue(Coperobj, null), null);//获得s对象属性的值复制给d对象的属性
}
}
}
}
catch (Exception ex)
{
throw ex;
}
return a;
}
#endregion
#region 记录日志信息
byte[] data { get; set; }
/// <summary>
/// 文件夹路径
/// </summary>
string path { get; set; }
/// <summary>
/// 文件路径
/// </summary>
string paths { get; set; }
/// <summary>
/// 记录信息对象
/// </summary>
RecordInfo info { get; set; }
/// <summary>
/// 打开的文件流对象
/// </summary>
FileStream FS { get; set; }
/// <summary>
/// 对应的窗体对象
/// </summary>
Window Mywindow { get; set; }
/// <summary>
/// 这里需要用到异步新增项
/// </summary>
Dispatcher MyDispatcher { get; set; }
/// <summary>
/// 记录日志信息到文件
/// </summary>
/// <param name="info"></param>
private void RecordLog(string showMag)
{
lock (this)
{
info = new RecordInfo() { Number = ExcepList.Count() + 1, HappenTime = DateTime.Now, Describe = showMag };
//异步新增项 这是微软的BUG 只能这么麻烦了
MyDispatcher.BeginInvoke(DispatcherPriority.Background, new ParameterizedThreadStart(AddItem), info);
path = @"D:\\SystemLog"; //文件夹路径
paths = @"D:\\SystemLog\" + DateTime.Now.ToString("D") + ".txt"; //文件路径 以年月日为名称
//创建文件夹
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
//打开或创建文件
FS = File.Open(paths, FileMode.Append);
//获得字节数组
data = System.Text.Encoding.Default.GetBytes(info.Number + "-" + info.HappenTime + "-" + info.Describe + "\r\n");
//开始写入
FS.Write(data, 0, data.Length);
//清空缓冲区、关闭流
FS.Flush();
FS.Close();
}
}
void AddItem(object info)
{
ExcepList.Add((RecordInfo)info);
}
/// <summary>
/// 记录检查平结果LOG
/// </summary>
/// <param name="CM"></param>
private void WarpageLog(string sn, ShowInfo res, string notes)
{
lock (this)
{
path = @"D:\\WarpageLog\";
paths = @"D:\\WarpageLog\" + DateTime.Now.ToString("D") + ".CSV";
//实例化字符串流
StringBuilder sb = new StringBuilder();
//创建文件夹
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
//创建文件
if (!File.Exists(paths))
{
//sb.Append("判定标准:,大于," + CurrentMachine.CoplanarMinValue + ",小于" + CurrentMachine.CoplanarMmxValue + "\r");
sb.Append("时间,SN码,共面度,判定结果,说明\r");
}
using (FileStream fs = new FileStream(paths, FileMode.Append))
{
using (StreamWriter sw = new StreamWriter(fs, UnicodeEncoding.GetEncoding("GB2312"))) //UnicodeEncoding.GetEncoding("GB2312")
{
sb.Append(DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss.fff")).Append(",").Append(sn).Append(",").Append(res.StatuValue).Append(",").Append(res.StatuInfo).Append(",").Append(notes).Append(",");
//将字符串流数据写入文件
sw.WriteLine(sb);
//刷新文件流
sw.Flush();
}
}
}
}
#endregion
#region 标签纸对象
private Grid machineLabelGrid;
/// <summary>
/// 标签机Grid
/// </summary>
public Grid MachineLabelGrid
{
get { return machineLabelGrid; }
set { machineLabelGrid = value; RaisePropertyChanged("MachineLabelGrid"); }
}
private Grid xizuiLabelGrid;
/// <summary>
/// 吸嘴Grid
/// </summary>
public Grid XizuiLabelGrid
{
get { return xizuiLabelGrid; }
set { xizuiLabelGrid = value; RaisePropertyChanged("XizuiLabelGrid"); }
}
/// <summary>
/// 吸嘴对应标签纸对象
/// </summary>
public List<LabelPaperModel> XizuiLabelPaperList { get; set; }
/// <summary>
/// 标签机对应标签对象
/// </summary>
public List<LabelPaperModel> MachineLabelPaper { get; set; }
/// <summary>
/// 获取标签纸Grid
/// </summary>
public void GetMachineLabelGrid()
{
XizuiLabelPaperList = new List<LabelPaperModel>();
MachineLabelPaper = new List<LabelPaperModel>();
Grid gd = new Grid();
Grid gd1 = new Grid();
for (int i = 0; i < 6; i++)
{
gd.ColumnDefinitions.Add(new ColumnDefinition()); //添加列
LabelPaperModel sm = new LabelPaperModel() { 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控件的列
MachineLabelPaper.Add(sm);
gd1.ColumnDefinitions.Add(new ColumnDefinition()); //添加列
LabelPaperModel sm1 = new LabelPaperModel() { Number = i + 1, State = new ShowInfo() { StatuInfo = (i + 1).ToString() } };
gd1.Children.Add(sm1.Labels);
sm1.Labels.SetValue(Grid.RowProperty, 0); //设置按钮所在Grid控件的行
sm1.Labels.SetValue(Grid.ColumnProperty, i); //设置按钮所在Grid控件的列
XizuiLabelPaperList.Add(sm1);
}
MachineLabelGrid = gd;
XizuiLabelGrid = gd1;
}
#endregion
}
#region 自定义Label控件类
/// <summary>
/// 自定义Label控件类
/// </summary>
public class MyLabel : NotificationObject
{
/// <summary>
/// 序号
/// </summary>
public int Number { get; set; }
private string myColor;
/// <summary>
/// 表示颜色
/// </summary>
public string MyColor
{
get { return myColor; }
set
{
myColor = value;
this.RaisePropertyChanged("MyColor");
}
}
/// <summary>
/// 对于的Tray名称
/// </summary>
public string TrayName { get; set; }
public Label Labels { get; set; }
private string labelConten;
/// <summary>
/// label内容
/// </summary>
public string LabelConten
{
get { return labelConten; }
set
{
labelConten = value;
this.RaisePropertyChanged("LabelConten");
}
}
/// <summary>
/// 第一个吸嘴取放点
/// </summary>
public RobotPoint TakePutPoint1 { get; set; }
/// <summary>
/// 第二个吸嘴取放点
/// </summary>
public RobotPoint TakePutPoint2 { get; set; }
/// <summary>
/// 第三个吸嘴取放点
/// </summary>
public RobotPoint TakePutPoint3 { get; set; }
/// <summary>
/// 第一个吸嘴贴标点
/// </summary>
public MotionPointModel Point_M1 { get; set; }
/// <summary>
/// 第二个吸嘴贴标点
/// </summary>
public MotionPointModel Point_M2 { get; set; }
/// <summary>
/// 第三个吸嘴贴标点
/// </summary>
public MotionPointModel Point_M3 { get; set; }
/// <summary>
/// 第四个吸嘴贴标点
/// </summary>
public MotionPointModel Point_M4 { get; set; }
/// <summary>
/// 第五个吸嘴贴标点
/// </summary>
public MotionPointModel Point_M5 { get; set; }
/// <summary>
/// 第六个吸嘴贴标点
/// </summary>
public MotionPointModel Point_M6 { get; set; }
/// <summary>
/// 视觉点位
/// </summary>
public MotionPointModel VisionPoint { get; set; }
private ProductModel prouct;
/// <summary>
/// Mylabel对应的产品对象
/// </summary>
public ProductModel Prouct
{
get { return prouct; }
set { prouct = value; RaisePropertyChanged("Prouct"); }
}
/// <summary>
/// Label显示控件对象
/// </summary>
public MyLabel()
{
Prouct = new ProductModel();
Labels = new Label();
MyColor = ColorStr.White;
//LabelConten ="11";
//绑定背景颜色
Labels.SetBinding(Label.BackgroundProperty, new Binding() { Source = this, Path = new PropertyPath("Prouct.StateColour"), Mode = BindingMode.TwoWay });
//绑定内容
Labels.SetBinding(Label.ContentProperty, new Binding() { Source = this, Path = new PropertyPath("LabelConten"), Mode = BindingMode.TwoWay });
Labels.MouseDoubleClick += Labels_MouseDoubleClick; //增加鼠标双击事件
Labels.Margin = new Thickness(1); //设置边距
Labels.HorizontalContentAlignment = HorizontalAlignment.Center;
Labels.VerticalContentAlignment = VerticalAlignment.Center;
}
/// <summary>
/// Label的双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Labels_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
//如果为绿色 则不允许改其他颜色
if (Prouct.StateColour == ColorStr.White)
{
Prouct.StateColour = ColorStr.Blue;
}
else if (Prouct.StateColour == ColorStr.Blue)
{
Prouct.StateColour = ColorStr.Green;
}
else
{
Prouct.StateColour = ColorStr.White;
}
}
}
#endregion
#region Tray盘类
/// <summary>
/// Tray盘类
/// </summary>
public class TrayModel : NotificationObject
{
/// <summary>
/// 构造函数
/// </summary>
/// <param name="cloumnNumber"></param>
/// <param name="rowNumber"></param>
/// <param name="robotpointlist"></param>
/// <param name="trayName">料盘名称</param>
public TrayModel(MachineModel machin, string trayName)
{
TrayName = trayName;
this.Cloumn = machin.ColoumsNumber;
this.Row = machin.RowsNumber;
this.JxCloumn = machin.PictureColoumns;
this.JxRow = machin.PictureRows;
this.RobotPointList = machin.RobotPointList;
this.MotionPointList = machin.MotionPointList.ToList();
this.GridContent = GetTrayGrid(Row, Cloumn, ref MyLabelList); //获取Grid控件
this.JxGridContent = GetTrayGrid(JxRow, JxCloumn, ref JxMyLabelList); //获取镜像Grid控件
//PointListInitialization(); //初始化点位集合
//ReductionTrayState(machin);//还原Tray状态
}
/// <summary>
/// 列
/// </summary>
int Cloumn { get; set; }
/// <summary>
/// 行
/// </summary>
int Row { get; set; }
/// <summary>
/// 镜像列
/// </summary>
int JxCloumn { get; set; }
/// <summary>
/// 镜像行
/// </summary>
int JxRow { get; set; }
/// <summary>
/// Tray名称
/// </summary>
public string TrayName { get; set; }
private Grid gridContent;
/// <summary>
/// grid控件
/// </summary>
public Grid GridContent
{
get { return gridContent; }
set
{
gridContent = value;
this.RaisePropertyChanged("GridContent");
}
}
/// <summary>
/// Mylabel集合
/// </summary>
public List<MyLabel> MyLabelList;
private Grid jxGridContent;
/// <summary>
/// 镜像Grid控件
/// </summary>
public Grid JxGridContent
{
get { return jxGridContent; }
set
{
jxGridContent = value;
this.RaisePropertyChanged("JxGridContent");
}
}
/// <summary>
/// 镜像MyLabel集合
/// </summary>
public List<MyLabel> JxMyLabelList;
/// <summary>
/// 机器人对位集合
/// </summary>
public List<RobotPoint> RobotPointList { get; set; }
/// <summary>
/// 第一个吸嘴取放点
/// </summary>
public List<RobotPoint> TakePutRobotPointList1 { get; set; }
/// <summary>
/// 第二个吸嘴取放点
/// </summary>
public List<RobotPoint> TakePutRobotPointList2 { get; set; }
/// <summary>
/// 第三个吸嘴取放点
/// </summary>
public List<RobotPoint> TakePutRobotPointList3 { get; set; }
/// <summary>
/// 运动控制所有点位
/// </summary>
public List<MotionPointModel> MotionPointList { get; set; }
public List<MotionPointModel> MotionPointList1 { get; set; }
/// <summary>
/// 第一个吸嘴运动控制阵列点位集合
/// </summary>
public List<MotionPointModel> TakeMotionPointList1 { get; set; }
/// <summary>
/// 第二个吸嘴运动控制阵列点位集合
/// </summary>
public List<MotionPointModel> TakeMotionPointList2 { get; set; }
/// <summary>
/// 第三个吸嘴运动控制阵列点位集合
/// </summary>
public List<MotionPointModel> TakeMotionPointList3 { get; set; }
/// <summary>
/// 第四个吸嘴运动控制阵列点位集合
/// </summary>
public List<MotionPointModel> TakeMotionPointList4 { get; set; }
/// <summary>
/// 第五个吸嘴运动控制阵列点位集合
/// </summary>
public List<MotionPointModel> TakeMotionPointList5 { get; set; }
/// <summary>
/// 第六个吸嘴运动控制阵列点位集合
/// </summary>
public List<MotionPointModel> TakeMotionPointList6 { get; set; }
/// <summary>
/// 视觉检查矩阵集合
/// </summary>
public List<MotionPointModel> VisionPointList { get; set; }
#region 获取当前Tray盘状态
/// <summary>
/// 获取当前Tray盘状态
/// </summary>
public void GetTrayState(MachineModel currmachine)
{
List<ProductModel> list = new List<ProductModel>();
//foreach (var item in MyLabelList)
//{
// if (item.Prouct ==null)
// {
// item.Prouct = new ProductModel();
// }
// list.Add(item.Prouct);
//}
list = MyLabelList.Select(w => w.Prouct).ToList();
currmachine.CellJson = ShareHelp.ObjToJson(list);
//list = new List<ProductModel>();
//foreach (var item in JxMyLabelList)
//{
// if (item.Prouct == null)
// {
// item.Prouct = new ProductModel();
// }
// list.Add(item.Prouct);
//}
list = JxMyLabelList.Select(w => w.Prouct).ToList();
currmachine.JxCellJson = ShareHelp.ObjToJson(list);
}
#endregion
#region 还原Tray盘状态
/// <summary>
/// 还原Tray盘状态
/// </summary>
public void ReductionTrayState(MachineModel currmachine)
{
List<ProductModel> list1 = ShareHelp.JsonToObj<List<ProductModel>>(currmachine.CellJson);
int a = 0;
if (list1 != null && list1.Count >= MyLabelList.Count)
{
if (list1 != null)
{
foreach (var item in MyLabelList)
{
item.Prouct = list1[a];
a++;
}
}
}
List<ProductModel> list2 = ShareHelp.JsonToObj<List<ProductModel>>(currmachine.JxCellJson);
if (list2 != null && list2.Count >= JxMyLabelList.Count)
{
a = 0;
if (list2 != null)
{
foreach (var item in JxMyLabelList)
{
item.Prouct = list2[a];
a++;
}
}
}
}
#endregion
#region 各点位集合初始化
/// <summary>
/// 点位集合初始化
/// </summary>
public void PointListInitialization()
{
#region 1、机械手阵列点位
if (RobotPointList != null && RobotPointList.Count > 0)
{
//获取阵列1的三个点位
RobotPoint point1 = Coper(RobotPointList.Where(R => R.PointType == 4).FirstOrDefault());
RobotPoint point2 = Coper(RobotPointList.Where(R => R.PointType == 5).FirstOrDefault());
RobotPoint point3 = Coper(RobotPointList.Where(R => R.PointType == 6).FirstOrDefault());
//获取取料阵列
TakePutRobotPointList1 = GetTakePutPointListEpson(point1, point2, point3);
//获取阵列2的三个点位
point1 = Coper(RobotPointList.Where(R => R.PointType == 7).FirstOrDefault());
point2 = Coper(RobotPointList.Where(R => R.PointType == 8).FirstOrDefault());
point3 = Coper(RobotPointList.Where(R => R.PointType == 9).FirstOrDefault());
TakePutRobotPointList2 = GetTakePutPointListEpson(point1, point2, point3);
point1 = Coper(RobotPointList.Where(R => R.PointType == 10).FirstOrDefault());
point2 = Coper(RobotPointList.Where(R => R.PointType == 11).FirstOrDefault());
point3 = Coper(RobotPointList.Where(R => R.PointType == 12).FirstOrDefault());
TakePutRobotPointList3 = GetTakePutPointListEpson(point1, point2, point3);
int a = 0;
foreach (var item in MyLabelList)
{
item.TakePutPoint1 = TakePutRobotPointList1 != null ? TakePutRobotPointList1[a] : null;
item.TakePutPoint2 = TakePutRobotPointList2 != null ? TakePutRobotPointList2[a] : null;
item.TakePutPoint3 = TakePutRobotPointList3 != null ? TakePutRobotPointList3[a] : null;
a++;
}
}
#endregion
#region 2、运动控制点位
if (MotionPointList != null && MotionPointList.Count > 0)
{
//获取阵列1的三个点位
MotionPointModel point1 = Coper(MotionPointList.Where(R => R.PointType == 1).FirstOrDefault());
MotionPointModel point2 = Coper(MotionPointList.Where(R => R.PointType == 2).FirstOrDefault());
MotionPointModel point3 = Coper(MotionPointList.Where(R => R.PointType == 3).FirstOrDefault());
#region 获取正常阵列点位
//获取取料阵列
TakeMotionPointList1 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
//获取阵列2的三个点位
point1 = Coper(MotionPointList.Where(R => R.PointType == 4).FirstOrDefault());
point2 = Coper(MotionPointList.Where(R => R.PointType == 5).FirstOrDefault());
point3 = Coper(MotionPointList.Where(R => R.PointType == 6).FirstOrDefault());
//获取取料阵列
TakeMotionPointList2 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
//获取阵列3的三个点位
point1 = Coper(MotionPointList.Where(R => R.PointType == 7).FirstOrDefault());
point2 = Coper(MotionPointList.Where(R => R.PointType == 8).FirstOrDefault());
point3 = Coper(MotionPointList.Where(R => R.PointType == 9).FirstOrDefault());
//获取取料阵列
TakeMotionPointList3 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
//获取阵列4的三个点位
point1 = Coper(MotionPointList.Where(R => R.PointType == 10).FirstOrDefault());
point2 = Coper(MotionPointList.Where(R => R.PointType == 11).FirstOrDefault());
point3 = Coper(MotionPointList.Where(R => R.PointType == 12).FirstOrDefault());
//获取取料阵列
TakeMotionPointList4 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
//获取阵列5的三个点位
point1 = Coper(MotionPointList.Where(R => R.PointType == 13).FirstOrDefault());
point2 = Coper(MotionPointList.Where(R => R.PointType == 14).FirstOrDefault());
point3 = Coper(MotionPointList.Where(R => R.PointType == 15).FirstOrDefault());
//获取取料阵列
TakeMotionPointList5 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
//获取阵列6的三个点位
point1 = Coper(MotionPointList.Where(R => R.PointType == 16).FirstOrDefault());
point2 = Coper(MotionPointList.Where(R => R.PointType == 17).FirstOrDefault());
point3 = Coper(MotionPointList.Where(R => R.PointType == 18).FirstOrDefault());
//获取取料阵列
TakeMotionPointList6 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
//获取阵列6的三个点位
point1 = Coper(MotionPointList.Where(R => R.PointType == 2001).FirstOrDefault());
point2 = Coper(MotionPointList.Where(R => R.PointType == 2002).FirstOrDefault());
point3 = Coper(MotionPointList.Where(R => R.PointType == 2003).FirstOrDefault());
//获取取料阵列
VisionPointList = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
#endregion
#region 获取正常阵列点位
//获取阵列1的三个点位
point1 = Coper(MotionPointList1.Where(R => R.PointType == 4).FirstOrDefault());
point2 = Coper(MotionPointList1.Where(R => R.PointType == 5).FirstOrDefault());
point3 = Coper(MotionPointList1.Where(R => R.PointType == 6).FirstOrDefault());
//获取取料阵列
List<MotionPointModel> JxPointList1 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
//获取阵列2的三个点位
point1 = Coper(MotionPointList1.Where(R => R.PointType == 4).FirstOrDefault());
point2 = Coper(MotionPointList1.Where(R => R.PointType == 5).FirstOrDefault());
point3 = Coper(MotionPointList1.Where(R => R.PointType == 6).FirstOrDefault());
//获取取料阵列
List<MotionPointModel> JxPointList2 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
//获取阵列3的三个点位
point1 = Coper(MotionPointList1.Where(R => R.PointType == 7).FirstOrDefault());
point2 = Coper(MotionPointList1.Where(R => R.PointType == 8).FirstOrDefault());
point3 = Coper(MotionPointList1.Where(R => R.PointType == 9).FirstOrDefault());
//获取取料阵列
List<MotionPointModel> JxPointList3 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
//获取阵列4的三个点位
point1 = Coper(MotionPointList1.Where(R => R.PointType == 10).FirstOrDefault());
point2 = Coper(MotionPointList1.Where(R => R.PointType == 11).FirstOrDefault());
point3 = Coper(MotionPointList1.Where(R => R.PointType == 12).FirstOrDefault());
//获取取料阵列
List<MotionPointModel> JxPointList4 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
//获取阵列5的三个点位
point1 = Coper(MotionPointList1.Where(R => R.PointType == 13).FirstOrDefault());
point2 = Coper(MotionPointList1.Where(R => R.PointType == 14).FirstOrDefault());
point3 = Coper(MotionPointList1.Where(R => R.PointType == 15).FirstOrDefault());
//获取取料阵列
List<MotionPointModel> JxPointList5 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
//获取阵列6的三个点位
point1 = Coper(MotionPointList1.Where(R => R.PointType == 16).FirstOrDefault());
point2 = Coper(MotionPointList1.Where(R => R.PointType == 17).FirstOrDefault());
point3 = Coper(MotionPointList1.Where(R => R.PointType == 18).FirstOrDefault());
//获取取料阵列
List<MotionPointModel> JxPointList6 = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
//视觉检查点位
point1 = Coper(MotionPointList1.Where(R => R.PointType == 2001).FirstOrDefault());
point2 = Coper(MotionPointList1.Where(R => R.PointType == 2002).FirstOrDefault());
point3 = Coper(MotionPointList1.Where(R => R.PointType == 2003).FirstOrDefault());
//获取取料阵列
List<MotionPointModel> JXVisionPointList = GetTakePutPointList_M(Row, Cloumn, point1, point2, point3);
#endregion
//分配正常点位
int a = 0;
foreach (var item in MyLabelList)
{
item.Point_M1 = TakeMotionPointList1 != null ? TakeMotionPointList1[a] : null;
item.Point_M2 = TakeMotionPointList2 != null ? TakeMotionPointList2[a] : null;
item.Point_M3 = TakeMotionPointList3 != null ? TakeMotionPointList3[a] : null;
item.Point_M4 = TakeMotionPointList4 != null ? TakeMotionPointList4[a] : null;
item.Point_M5 = TakeMotionPointList5 != null ? TakeMotionPointList5[a] : null;
item.Point_M6 = TakeMotionPointList6 != null ? TakeMotionPointList6[a] : null;
item.VisionPoint = VisionPointList != null ? VisionPointList[a] : null;
a++;
}
//分配镜像点位
a = 0;
foreach (var item in JxMyLabelList)
{
item.Point_M1 = JxPointList1 != null ? JxPointList1[a] : null;
item.Point_M2 = JxPointList2 != null ? JxPointList2[a] : null;
item.Point_M3 = JxPointList3 != null ? JxPointList3[a] : null;
item.Point_M4 = JxPointList4 != null ? JxPointList4[a] : null;
item.Point_M5 = JxPointList5 != null ? JxPointList5[a] : null;
item.Point_M6 = JxPointList6 != null ? JxPointList6[a] : null;
item.VisionPoint = JXVisionPointList != null ? JXVisionPointList[a] : null;
a++;
}
}
#endregion
}
/// <summary>
/// 获取机器人点位集合EPSON机械手算法
/// </summary>
/// <param name="p_start"></param>
/// <param name="p_end"></param>
public List<RobotPoint> GetTakePutPointListEpson(RobotPoint p1, RobotPoint p2, RobotPoint p3)
{
if (p1 == null || p2 == null || p3 == null)
{
return null;
}
//获取两点的行列间距
double x = p1.PointX - p3.PointX; //Math.Abs(p1.PointX - p3.PointX);
double y = p1.PointY - p2.PointY; //Math.Abs(p1.PointY - p2.PointY);
//获取Tray的行列间距
double Average_X = Math.Round(x / (Cloumn - 1), 4);
double Average_Y = Math.Round(y / (Row - 1), 4);
//单个细分间距
double Offset_x = Math.Round((p1.PointX - p2.PointX) / (Row - 1), 4);
double Offset_y = Math.Round((p1.PointY - p3.PointY) / (Cloumn - 1), 4);
List<RobotPoint> list = new List<RobotPoint>();
RobotPoint rp = new RobotPoint();
int number = 0;
for (int i = 0; i < Cloumn; i++)
{
for (int j = 0; j < Row; j++)
{
rp = Coper(p1);
rp.PointNumber = number;
rp.PointX = rp.PointX - i * Average_X;
rp.PointY = rp.PointY - j * Average_Y;
rp.PointY = rp.PointY - i * Offset_y;
rp.PointX = rp.PointX - j * Offset_x;
number++;
list.Add(rp);
}
}
return list;
}
/// <summary>
/// 获取机器人点位集合发那科机械手算法
/// </summary>
/// <param name="p1"></param>
/// <param name="p2"></param>
/// <param name="p3"></param>
/// <returns></returns>
public List<RobotPoint> GetTakePutPointListFanuc(RobotPoint p1, RobotPoint p2, RobotPoint p3)
{
if (p1 == null || p2 == null || p3 == null)
{
return null;
}
//获取两点的行列间距
double y = p1.PointY - p3.PointY;//Math.Abs(p1.PointY - p3.PointY);
double x = p1.PointX - p2.PointX;// Math.Abs(p1.PointX - p2.PointX);
//获取Tray的行列间距
double Average_X = Math.Round(x / (Row - 1), 4);
double Average_Y = Math.Round(y / (Cloumn - 1), 4);
//单个细分间距
double Offset_x = Math.Round((p1.PointX - p3.PointX) / (Cloumn - 1), 4);
double Offset_y = Math.Round((p1.PointY - p2.PointY) / (Row - 1), 4);
List<RobotPoint> list = new List<RobotPoint>();
RobotPoint rp = new RobotPoint();
int number = 0;
for (int j = 0; j < Cloumn; j++)
{
for (int i = 0; i < Row; i++)
{
rp = ShareHelp.FeiyuCoper(p1);
rp.PointNumber = number;
rp.PointX = rp.PointX - i * Average_X;
rp.PointY = rp.PointY - j * Average_Y;
rp.PointY = rp.PointY - i * Offset_y;
rp.PointX = rp.PointX - j * Offset_x;
rp.Xyzwpr.SetValue((float)rp.PointX, 0);
rp.Xyzwpr.SetValue((float)rp.PointY, 1);
number++;
list.Add(rp);
}
}
return list;
}
/// <summary>
/// 获取运行控制点位集合
/// </summary>
/// <param name="p1"></param>
/// <param name="p2"></param>
/// <param name="p3"></param>
/// <returns></returns>
public List<MotionPointModel> GetTakePutPointList_M(int row, int cloumn, MotionPointModel p1, MotionPointModel p2, MotionPointModel p3)
{
if (p1 == null || p2 == null || p3 == null)
{
return null;
}
int Row = row;
int Cloumn = cloumn;
//获取两点的行列间距
double x = p1.ShaftPoint_X - p2.ShaftPoint_X; //Math.Abs(p1.PointX - p3.PointX);
double y = p1.ShaftPoint_Y - p3.ShaftPoint_Y; //Math.Abs(p1.PointY - p2.PointY);
//获取Tray的行列间距
double Average_X = Math.Round(x / (Cloumn - 1), 4);
double Average_Y = Math.Round(y / (Row - 1), 4);
//单个细分间距
double Offset_x = Math.Round((p1.ShaftPoint_X - p3.ShaftPoint_X) / (row - 1), 4);
double Offset_y = Math.Round((p1.ShaftPoint_Y - p2.ShaftPoint_Y) / (Cloumn - 1), 4);
List<MotionPointModel> list = new List<MotionPointModel>();
MotionPointModel rp = new MotionPointModel();
int number = 0;
for (int i = 0; i < Row; i++)
{
for (int j = 0; j < Cloumn; j++)
{
rp = Coper(p1);
rp.PointNumber = number;
rp.ShaftPoint_X = rp.ShaftPoint_X - j * Average_X;
rp.ShaftPoint_Y = rp.ShaftPoint_Y - i * Average_Y;
rp.ShaftPoint_X = rp.ShaftPoint_X - j * Offset_x;
rp.ShaftPoint_Y = rp.ShaftPoint_Y - i * Offset_y;
number++;
list.Add(rp);
}
}
return list;
}
#endregion
#region 获取料盘动态Grid
/// <summary>
/// 获取料盘动态Grid
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
private Grid GetTrayGrid(int Row, int Cloumn, ref List<MyLabel> myLabelList)
{
Grid grid = new Grid();
for (int i = 0; i < Cloumn; i++)
{
grid.ColumnDefinitions.Add(new ColumnDefinition()); //添加列
}
for (int j = 0; j < Row; j++)
{
grid.RowDefinitions.Add(new RowDefinition()); //添加行
}
myLabelList = new List<MyLabel>();
MyLabel label;
int numbe = 0;
for (int j = 0; j < Row; j++)
{
for (int i = 0; i < Cloumn; i++)
{
label = new MyLabel();
label.TrayName = this.TrayName;
label.Number = numbe++;
label.LabelConten = numbe.ToString(); //显示编号
grid.Children.Add(label.Labels);
label.Labels.SetValue(Grid.RowProperty, j); //设置按钮所在Grid控件的行
label.Labels.SetValue(Grid.ColumnProperty, i); //设置按钮所在Grid控件的列
myLabelList.Add(label);
}
}
return grid;
}
#endregion
/// <summary>
/// 利用反射进行对象复制
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="Coperobj"></param>
/// <returns></returns>
private T Coper<T>(T Coperobj)
{
if (Coperobj == null)
{
return default(T);
}
T a = System.Activator.CreateInstance<T>();
try
{
var Types = Coperobj.GetType();//获得类型
var Typed = a.GetType();
foreach (PropertyInfo sp in Types.GetProperties())//获得类型的属性字段
{
foreach (PropertyInfo dp in Typed.GetProperties())
{
if (dp.Name == sp.Name)//判断属性名是否相同
{
if (dp.PropertyType.FullName == typeof(Array).FullName)
{
dp.SetValue(a, ((Array)sp.GetValue(Coperobj, null)).Clone(), null);//获得s对象属性的值复制给d对象的属性
}
else
{
dp.SetValue(a, sp.GetValue(Coperobj, null), null);//获得s对象属性的值复制给d对象的属性
}
}
}
}
}
catch
{
}
return a;
}
}
#endregion
/// <summary>
/// 打标标签对象
/// </summary>
public class LabelPaperModel : NotificationObject
{
/// <summary>
/// 序号
/// </summary>
public int Number { get; set; }
public Label Labels { get; set; }
private ShowInfo state;
/// <summary>
/// 标签状态
/// </summary>
public ShowInfo State
{
get { return state; }
set { state = value; RaisePropertyChanged("State"); }
}
#region 取标点
/// <summary>
/// 取标点1
/// </summary>
public MotionPointModel Point_Take1 { get; set; }
/// <summary>
/// 取标点2
/// </summary>
public MotionPointModel Point_Take2 { get; set; }
/// <summary>
/// 取标点3
/// </summary>
public MotionPointModel Point_Take3 { get; set; }
/// <summary>
/// 取标点4
/// </summary>
public MotionPointModel Point_Take4 { get; set; }
/// <summary>
/// 取标点5
/// </summary>
public MotionPointModel Point_Take5 { get; set; }
/// <summary>
/// 取标点6
/// </summary>
public MotionPointModel Point_Take6 { get; set; }
#endregion
/// <summary>
/// 视觉点
/// </summary>
public MotionPointModel Point_Vision { get; set; }
/// <summary>
/// 真空开关
/// </summary>
public OutputSignal VacuumSwitch { get; set; }
/// <summary>
/// 真空捡知
/// </summary>
public InputSignal VacuumCheck { get; set; }
private string codeStr;
/// <summary>
/// 标签SN
/// </summary>
public string CodeStr
{
get { return codeStr; }
set { codeStr = value; }
}
/// <summary>
/// 贴标补偿X
/// </summary>
public double PutLabelX { get; set; }
/// <summary>
/// 贴标补偿Y
/// </summary>
public double PutLabelY { get; set; }
/// <summary>
/// 贴标补偿U
/// </summary>
public double PutLabelU { get; set; }
/// <summary>
/// Label显示控件对象
/// </summary>
public LabelPaperModel()
{
State = new ShowInfo();
Labels = new Label();
//数据样式
Labels.Style = (Style)MyMessageBox.MetroWin.FindResource("Mylabel1");//LabelStyle 这个样式是引用的资源文件中的样式名称
//绑定背景颜色
Labels.SetBinding(Label.BackgroundProperty, new Binding() { Source = this, Path = new PropertyPath("State.StatusBackground"), Mode = BindingMode.TwoWay });
//绑定内容
Labels.SetBinding(Label.ContentProperty, new Binding() { Source = this, Path = new PropertyPath("State.StatuInfo"), Mode = BindingMode.TwoWay });
Labels.MouseDoubleClick += Labels_MouseDoubleClick; //增加鼠标双击事件
Labels.Margin = new Thickness(1); //设置边距
}
/// <summary>
/// Label的双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Labels_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
//如果为绿色 则不允许改其他颜色
if (State.StatusBackground == ColorStr.White)
{
State.StatusBackground = ColorStr.Blue;
}
else if (State.StatusBackground == ColorStr.Blue)
{
State.StatusBackground = ColorStr.Green;
}
else
{
State.StatusBackground = ColorStr.White;
}
}
}
}