2896 lines
82 KiB
C#
2896 lines
82 KiB
C#
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.Threading;
|
||
using ViewModel.MotionControl;
|
||
using ViewModel.Robots;
|
||
using ViewModel.Vision;
|
||
using Views;
|
||
|
||
namespace ViewModel
|
||
{
|
||
public partial class MainWindowVM : NotificationObject
|
||
{
|
||
const int Y000绿灯 = 0;
|
||
const int Y001红灯 = 1;
|
||
const int Y002黄灯 = 2;
|
||
const int Y003蜂鸣器 = 3;
|
||
|
||
const int X000启动 = 0;
|
||
const int X001停止 = 1;
|
||
const int X002急停 = 2;
|
||
|
||
#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 "手动测试轴":
|
||
ManulFlow.Step = 0;
|
||
break;
|
||
}
|
||
Task.Run(() =>
|
||
{
|
||
while (testing)
|
||
{
|
||
Thread.Sleep(10);
|
||
switch (cmd)
|
||
{
|
||
|
||
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();
|
||
}
|
||
|
||
|
||
}
|
||
|
||
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();// 急停信号
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
#region 获取轴状态
|
||
if (MCVM != null)
|
||
{
|
||
MCVM.OrginALL(InputList[X002急停]);
|
||
|
||
if (RunStatu != RunStatuEnum.Normal)
|
||
{
|
||
MCVM.PointRun();
|
||
mCVM.RunMotionTrajectory();
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
DualControlRun();//双控运行
|
||
GoHome();//回原点
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
#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:
|
||
|
||
GoHomeFlow.RunStep++;
|
||
break;
|
||
case GengralProcessEnum.Step5:
|
||
GoHomeFlow.RunStep++;
|
||
|
||
break;
|
||
|
||
case GengralProcessEnum.Step6:
|
||
homeing = false;
|
||
GoHomeFlow.RunStep = GengralProcessEnum.End;
|
||
RunStatu = RunStatuEnum.Prepareations; //准备就绪
|
||
break;
|
||
}
|
||
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 其他运行内容
|
||
/// <summary>
|
||
/// 其他运行内容
|
||
/// </summary>
|
||
private void DualControlRun()
|
||
{
|
||
|
||
|
||
}
|
||
|
||
public DateTime FlipTime { get; set; } = DateTime.Now;
|
||
#endregion
|
||
|
||
#endregion
|
||
|
||
#region 3、运行
|
||
|
||
/// <summary>
|
||
/// 启动运行
|
||
/// </summary>
|
||
private void Run()
|
||
{
|
||
|
||
|
||
|
||
while (true)
|
||
{
|
||
if (RunStatu == RunStatuEnum.Normal)
|
||
{
|
||
try
|
||
{
|
||
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ExcepStop(ex.Message);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
#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)
|
||
{
|
||
|
||
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)
|
||
{
|
||
|
||
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++)
|
||
{
|
||
|
||
|
||
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);
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
|
||
#region 手动测试轴
|
||
|
||
public int TestPos { get; set; }
|
||
public void TestAxisRun(FlowModel MyFlow)
|
||
{
|
||
|
||
switch (MyFlow.Step)
|
||
{
|
||
case 0:
|
||
TestPos = 1;
|
||
MyFlow.Step++;
|
||
|
||
|
||
|
||
break;
|
||
|
||
case 1:
|
||
AxisPointTemp = GetMotionPoint(TestPos);
|
||
MyFlow.Step++;
|
||
|
||
|
||
|
||
break;
|
||
case 2:
|
||
if (AxisPointTemp.PointRun(MCVM.AllShaftList))
|
||
{
|
||
|
||
MyFlow.Step++;
|
||
|
||
|
||
}
|
||
else if (MyFlow.RunTime.AddMilliseconds(10000) < DateTime.Now)
|
||
{
|
||
AxisPointTemp.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
|
||
|
||
|
||
private DelegateCommand _SoftltcInit;
|
||
public DelegateCommand SoftltcInit =>
|
||
_SoftltcInit = _SoftltcInit ?? new DelegateCommand() { ExecuteAction = ExecuteSoftltcInit };
|
||
|
||
void ExecuteSoftltcInit(object obj)
|
||
{
|
||
|
||
var shaft = MCVM.AllShaftList.Where(w => w.ShaftName == "轴1").FirstOrDefault();
|
||
if (shaft != null)
|
||
{
|
||
shaft.SoftltcInit(0, 5, 1);
|
||
}
|
||
}
|
||
private DelegateCommand _SoftltcReset;
|
||
public DelegateCommand SoftltcReset =>
|
||
_SoftltcReset = _SoftltcReset ?? new DelegateCommand() { ExecuteAction = ExecuteSoftltcReset };
|
||
|
||
void ExecuteSoftltcReset(object obj)
|
||
{
|
||
|
||
var shaft = MCVM.AllShaftList.Where(w => w.ShaftName == "轴1").FirstOrDefault();
|
||
if (shaft != null)
|
||
{
|
||
shaft.SoftltcReset(0);
|
||
LatchPos = 0;
|
||
}
|
||
}
|
||
|
||
private DelegateCommand _SoftltcRead;
|
||
public DelegateCommand SoftltcRead =>
|
||
_SoftltcRead = _SoftltcRead ?? new DelegateCommand() { ExecuteAction = ExecuteSoftltcRead };
|
||
|
||
void ExecuteSoftltcRead(object obj)
|
||
{
|
||
var shaft = MCVM.AllShaftList.Where(w => w.ShaftName == "上料盘Z").FirstOrDefault();
|
||
if (shaft != null)
|
||
{
|
||
double latchPos = 0;
|
||
if (shaft.SoftltcRead(0, ref latchPos))
|
||
{
|
||
|
||
LatchPos = latchPos;
|
||
|
||
|
||
}
|
||
}
|
||
}
|
||
private double _LatchPos;
|
||
public double LatchPos
|
||
{
|
||
get { return _LatchPos; }
|
||
set
|
||
{
|
||
_LatchPos = value;
|
||
this.RaisePropertyChanged("LatchPos");
|
||
}
|
||
}
|
||
|
||
public MotionPointModel AxisPointTemp { get; private set; }
|
||
}
|
||
|
||
}
|