4065 lines
133 KiB
C#
4065 lines
133 KiB
C#
using Community;
|
||
using DAL;
|
||
using LiveCharts.Defaults;
|
||
using MahApps.Metro.Controls.Dialogs;
|
||
using Microsoft.Win32;
|
||
using Model;
|
||
using Model.HSL;
|
||
using Model.MotionControl;
|
||
using Model.Vision;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Collections.ObjectModel;
|
||
using System.Data;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Reflection;
|
||
using System.Text;
|
||
using System.Threading;
|
||
using System.Windows;
|
||
using System.Windows.Controls;
|
||
using System.Windows.Data;
|
||
using System.Windows.Media;
|
||
using System.Windows.Threading;
|
||
using ViewModel.MotionControl;
|
||
using ViewModel.Robots;
|
||
using ViewModel.Vision;
|
||
using Views;
|
||
|
||
namespace ViewModel
|
||
{
|
||
public partial class MainWindowVM : NotificationObject
|
||
{
|
||
private string gridWidth;
|
||
/// <summary>
|
||
/// Grid的宽
|
||
/// </summary>
|
||
public string GridWidth
|
||
{
|
||
get { return gridWidth; }
|
||
set
|
||
{
|
||
gridWidth = value;
|
||
this.RaisePropertyChanged("GridWidth");
|
||
}
|
||
}
|
||
|
||
private DelegateCommand _OpenDoor;
|
||
public DelegateCommand OpenDoor =>
|
||
_OpenDoor = _OpenDoor ?? new DelegateCommand() { ExecuteAction = ExecuteOpenDoor };
|
||
|
||
void ExecuteOpenDoor(object obj)
|
||
{
|
||
if (MyPLC != null && MyPLC.PLC != null && MyPLC.PLC.PlcStatus.StatusBackground == ColorStr.Green)
|
||
{
|
||
if (Door != "未锁")
|
||
{
|
||
if (RunStatu == RunStatuEnum.Normal) return;
|
||
MyPLC.PLC.Write("Y2", false);
|
||
Door = "未锁";
|
||
}
|
||
else
|
||
{
|
||
MyPLC.PLC.Write("Y2", true);
|
||
Door = "已锁";
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
|
||
private string _Door = "未锁";
|
||
public string Door
|
||
{
|
||
get { return _Door; }
|
||
set
|
||
{
|
||
_Door = value;
|
||
this.RaisePropertyChanged("Door");
|
||
}
|
||
}
|
||
#region 通讯服务器对象
|
||
private CommunicationServerVM serverComm;
|
||
/// <summary>
|
||
/// 通讯服务器对象
|
||
/// </summary>
|
||
public CommunicationServerVM ServerComm
|
||
{
|
||
get { return serverComm; }
|
||
set
|
||
{
|
||
serverComm = value;
|
||
RaisePropertyChanged("ServerComm");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region PLC连接管理
|
||
private PLCVM plcConVM;
|
||
/// <summary>
|
||
/// PLC连接管理
|
||
/// </summary>
|
||
public PLCVM PlcConVM
|
||
{
|
||
get { return plcConVM; }
|
||
set
|
||
{
|
||
plcConVM = value;
|
||
this.RaisePropertyChanged("PlcConVM");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region ERP交互管理类
|
||
private ERPManageVM eRPVM;
|
||
/// <summary>
|
||
/// ERP交互管理类
|
||
/// </summary>
|
||
public ERPManageVM ERPVM
|
||
{
|
||
get { return eRPVM; }
|
||
set
|
||
{
|
||
eRPVM = value;
|
||
RaisePropertyChanged("ERPVM");
|
||
}
|
||
}
|
||
#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>
|
||
TimeSpan OpenTime { get; set; }
|
||
|
||
/// <summary>
|
||
/// 生产运行开始时间
|
||
/// </summary>
|
||
DateTime RunStartTime { get; set; }
|
||
|
||
#region 已运行时间显示
|
||
|
||
private ShowInfo runTimeShow;
|
||
/// <summary>
|
||
/// 已运行时间显示
|
||
/// </summary>
|
||
public ShowInfo RunTimeShow
|
||
{
|
||
get { return runTimeShow; }
|
||
set
|
||
{
|
||
runTimeShow = value;
|
||
this.RaisePropertyChanged("RunTimeShow");
|
||
}
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 提示报警时间
|
||
/// </summary>
|
||
DateTime TiShiBaojingTime { get; set; }
|
||
|
||
#endregion
|
||
|
||
#region 图表相关
|
||
private ChartModel pie;
|
||
/// <summary>
|
||
/// 图表对象
|
||
/// </summary>
|
||
public ChartModel Pie
|
||
{
|
||
get { return pie; }
|
||
set
|
||
{
|
||
pie = value;
|
||
this.RaisePropertyChanged("ChartModel");
|
||
}
|
||
}
|
||
|
||
|
||
#region 图表相关2
|
||
private ChartVM cVM1;
|
||
/// <summary>
|
||
/// 图表对象
|
||
/// </summary>
|
||
public ChartVM CVM1
|
||
{
|
||
get { return cVM1; }
|
||
set
|
||
{
|
||
cVM1 = value;
|
||
this.RaisePropertyChanged("CVM1");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 图表2 饼图
|
||
private ChartVM cVM2;
|
||
/// <summary>
|
||
/// 图表2 饼图
|
||
/// </summary>
|
||
public ChartVM CVM2
|
||
{
|
||
get { return cVM2; }
|
||
set
|
||
{
|
||
cVM2 = value;
|
||
this.RaisePropertyChanged("CVM2");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
|
||
private ChartModel curve1;
|
||
/// <summary>
|
||
/// 电流噪音曲线图1
|
||
/// </summary>
|
||
public ChartModel Curve1
|
||
{
|
||
get { return curve1; }
|
||
set
|
||
{
|
||
curve1 = value;
|
||
this.RaisePropertyChanged("Curve1");
|
||
}
|
||
}
|
||
|
||
|
||
private ChartModel curve2;
|
||
/// <summary>
|
||
/// 电流噪音曲线图2
|
||
/// </summary>
|
||
public ChartModel Curve2
|
||
{
|
||
get { return curve2; }
|
||
set
|
||
{
|
||
curve2 = value;
|
||
this.RaisePropertyChanged("Curve2");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
#endregion
|
||
|
||
#region 空跑模式
|
||
private bool runningMode;
|
||
|
||
/// <summary>
|
||
/// 空跑模式
|
||
/// </summary>
|
||
public bool RunningMode
|
||
{
|
||
get { return runningMode; }
|
||
set
|
||
{
|
||
runningMode = value;
|
||
|
||
this.RaisePropertyChanged("RunningMode");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// GRR模式
|
||
/// </summary>
|
||
public bool GrrModel { get; set; }
|
||
|
||
#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;
|
||
|
||
ContorEnable = false;
|
||
}
|
||
else
|
||
{
|
||
if (GridWidth == "0")
|
||
{
|
||
GridWidth = "30*";
|
||
}
|
||
|
||
ContorEnable = true;
|
||
}
|
||
|
||
if (aoi2 != null)
|
||
{
|
||
if (value == Visibility.Visible)
|
||
{
|
||
((TextBox)aoi2.FindName("bads")).IsEnabled = true;
|
||
((TextBox)aoi2.FindName("quantitys")).IsEnabled = true;
|
||
((TextBox)aoi2.FindName("produce")).IsEnabled = true;
|
||
}
|
||
else
|
||
{
|
||
((TextBox)aoi2.FindName("bads")).IsEnabled = false;
|
||
((TextBox)aoi2.FindName("quantitys")).IsEnabled = false;
|
||
((TextBox)aoi2.FindName("produce")).IsEnabled = false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
#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;
|
||
}
|
||
|
||
//try
|
||
//{
|
||
// TabItem p = null;
|
||
// if (TabItemList != null)
|
||
// {
|
||
// p = TabItemList.Where(t => t.Header.ToString() == "参数设置").FirstOrDefault();
|
||
// }
|
||
|
||
// if (value == Visibility.Visible)
|
||
// {
|
||
// AllVis = value;
|
||
// if (p != null)
|
||
// {
|
||
// ParameterSetting ps = p.Content as ParameterSetting;
|
||
// (ps.FindName("holeBCX") as DataGridTextColumn).Visibility = Visibility.Visible;
|
||
// (ps.FindName("holeBCY") as DataGridTextColumn).Visibility = Visibility.Visible;
|
||
// (ps.FindName("nutBCX") as DataGridTextColumn).Visibility = Visibility.Visible;
|
||
// (ps.FindName("nutBCY") as DataGridTextColumn).Visibility = Visibility.Visible;
|
||
// }
|
||
// }
|
||
// else
|
||
// {
|
||
// if (p != null)
|
||
// {
|
||
// ParameterSetting ps = p.Content as ParameterSetting;
|
||
// (ps.FindName("holeBCX") as DataGridTextColumn).Visibility = Visibility.Collapsed;
|
||
// (ps.FindName("holeBCY") as DataGridTextColumn).Visibility = Visibility.Collapsed;
|
||
// (ps.FindName("nutBCX") as DataGridTextColumn).Visibility = Visibility.Collapsed;
|
||
// (ps.FindName("nutBCY") as DataGridTextColumn).Visibility = Visibility.Collapsed;
|
||
// }
|
||
// }
|
||
//}
|
||
//catch
|
||
//{
|
||
|
||
//}
|
||
|
||
if (HVlist != null)
|
||
{
|
||
foreach (HalconVisual hv in HVlist)
|
||
{
|
||
hv.SuperPrivilege = value;
|
||
}
|
||
}
|
||
|
||
|
||
if (MCVM != null)
|
||
{
|
||
MCVM.DisplayLevel = value;
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
private bool contorEnable;
|
||
/// <summary>
|
||
/// 控件启用
|
||
/// </summary>
|
||
public bool ContorEnable
|
||
{
|
||
get { return contorEnable; }
|
||
set
|
||
{
|
||
contorEnable = value;
|
||
this.RaisePropertyChanged("ContorEnable");
|
||
}
|
||
}
|
||
|
||
#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; }
|
||
|
||
/// <summary>
|
||
/// IE4.0数据上传线程
|
||
/// </summary>
|
||
Thread ThDataUpload { 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 (MyPLC != null && MyPLC.PLC != null && MyPLC.PLC.PlcStatus.StatusBackground == ColorStr.Green)
|
||
{
|
||
//Y12红灯,Y13黄灯,Y14绿灯,Y15蜂鸣器
|
||
MyPLC.PLC.Write("Y12", false);
|
||
MyPLC.PLC.Write("Y13", true);
|
||
MyPLC.PLC.Write("Y14", false);
|
||
MyPLC.PLC.Write("Y15", false);
|
||
}
|
||
break;
|
||
case RunStatuEnum.Prepareations:
|
||
ShowStatu.StatusBackground = ColorStr.Green;
|
||
ShowStatu.StatusForeground = ColorStr.Black;
|
||
ShowStatu.StatuInfo = "准备就绪";
|
||
if (MyPLC != null && MyPLC.PLC != null && MyPLC.PLC.PlcStatus.StatusBackground == ColorStr.Green)
|
||
{
|
||
//Y12红灯,Y13黄灯,Y14绿灯,Y15蜂鸣器
|
||
MyPLC.PLC.Write("Y12", false);
|
||
MyPLC.PLC.Write("Y13", true);
|
||
MyPLC.PLC.Write("Y14", false);
|
||
MyPLC.PLC.Write("Y15", false);
|
||
}
|
||
break;
|
||
case RunStatuEnum.Normal:
|
||
ShowStatu.StatusBackground = ColorStr.Green;
|
||
ShowStatu.StatusForeground = ColorStr.Black;
|
||
ShowStatu.StatuInfo = "运行中";
|
||
if (MyPLC != null && MyPLC.PLC != null && MyPLC.PLC.PlcStatus.StatusBackground == ColorStr.Green)
|
||
{
|
||
//Y12红灯,Y13黄灯,Y14绿灯,Y15蜂鸣器
|
||
MyPLC.PLC.Write("Y12", false);
|
||
MyPLC.PLC.Write("Y13", false);
|
||
MyPLC.PLC.Write("Y14", true);
|
||
MyPLC.PLC.Write("Y15", false);
|
||
}
|
||
break;
|
||
case RunStatuEnum.Stop:
|
||
ShowStatu.StatusBackground = ColorStr.Yellow;
|
||
ShowStatu.StatusForeground = ColorStr.Black;
|
||
ShowStatu.StatuInfo = "停止中";
|
||
|
||
if (MyPLC != null && MyPLC.PLC != null && MyPLC.PLC.PlcStatus.StatusBackground == ColorStr.Green)
|
||
{
|
||
//Y12红灯,Y13黄灯,Y14绿灯,Y15蜂鸣器
|
||
MyPLC.PLC.Write("Y12", false);
|
||
MyPLC.PLC.Write("Y13", true);
|
||
MyPLC.PLC.Write("Y14", false);
|
||
MyPLC.PLC.Write("Y15", false);
|
||
}
|
||
break;
|
||
case RunStatuEnum.EmgStop:
|
||
ShowStatu.StatusBackground = ColorStr.Yellow;
|
||
ShowStatu.StatusForeground = ColorStr.Black;
|
||
ShowStatu.StatuInfo = "紧急停止中";
|
||
if (MyPLC != null && MyPLC.PLC != null && MyPLC.PLC.PlcStatus.StatusBackground == ColorStr.Green)
|
||
{
|
||
//Y12红灯,Y13黄灯,Y14绿灯,Y15蜂鸣器
|
||
MyPLC.PLC.Write("Y12", true);
|
||
MyPLC.PLC.Write("Y13", false);
|
||
MyPLC.PLC.Write("Y14", false);
|
||
MyPLC.PLC.Write("Y15", false);
|
||
}
|
||
break;
|
||
case RunStatuEnum.Exceptional:
|
||
ShowStatu.StatusBackground = ColorStr.Red;
|
||
ShowStatu.StatusForeground = ColorStr.White;
|
||
if (MyPLC != null && MyPLC.PLC != null && MyPLC.PLC.PlcStatus.StatusBackground == ColorStr.Green)
|
||
{
|
||
//Y12红灯,Y13黄灯,Y14绿灯,Y15蜂鸣器
|
||
MyPLC.PLC.Write("Y12", false);
|
||
MyPLC.PLC.Write("Y13", true);
|
||
MyPLC.PLC.Write("Y14", false);
|
||
MyPLC.PLC.Write("Y15", true);
|
||
}
|
||
break;
|
||
case RunStatuEnum.Unknown:
|
||
ShowStatu.StatusBackground = ColorStr.Yellow;
|
||
ShowStatu.StatusForeground = ColorStr.Black;
|
||
ShowStatu.StatuInfo = "状态未知";
|
||
if (MyPLC != null && MyPLC.PLC != null && MyPLC.PLC.PlcStatus.StatusBackground == ColorStr.Green)
|
||
{
|
||
//Y12红灯,Y13黄灯,Y14绿灯,Y15蜂鸣器
|
||
MyPLC.PLC.Write("Y12", false);
|
||
MyPLC.PLC.Write("Y13", false);
|
||
MyPLC.PLC.Write("Y14", false);
|
||
MyPLC.PLC.Write("Y15", false);
|
||
}
|
||
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 SaveStandCommand { get; set; }
|
||
|
||
/// <summary>
|
||
/// 保存系统信息
|
||
/// </summary>
|
||
public DelegateCommand SaveSystemPerCommand { get; set; }
|
||
|
||
|
||
/// <summary>
|
||
/// 读取产能数据
|
||
/// </summary>
|
||
public DelegateCommand ReadDateCommand { get; set; }
|
||
/// <summary>
|
||
/// 导出产能数据
|
||
/// </summary>
|
||
public DelegateCommand ExportDateCommand { get; set; }
|
||
/// <summary>
|
||
/// 读取产能上一页
|
||
/// </summary>
|
||
public DelegateCommand ReadPageUpCommand { get; set; }
|
||
/// <summary>
|
||
/// 读取产能下一页
|
||
/// </summary>
|
||
public DelegateCommand ReadPageDownCommand { 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 选中的TabItem索引
|
||
private int selectedIndex;
|
||
/// <summary>
|
||
/// 选中的TabItem索引
|
||
/// </summary>
|
||
public int SelectedIndex
|
||
{
|
||
get { return selectedIndex; }
|
||
set
|
||
{
|
||
selectedIndex = value;
|
||
this.RaisePropertyChanged("SelectedIndex");
|
||
}
|
||
}
|
||
|
||
private int selectedIndex1;
|
||
/// <summary>
|
||
/// 选中的TabItem索引1
|
||
/// </summary>
|
||
public int SelectedIndex1
|
||
{
|
||
get { return selectedIndex1; }
|
||
set
|
||
{
|
||
selectedIndex1 = value;
|
||
this.RaisePropertyChanged("SelectedIndex1");
|
||
}
|
||
}
|
||
|
||
#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(shuxingContent), info);
|
||
|
||
SystemPar.DefaultMachineID = value;
|
||
dal.UpdateSystemPar(SystemPar); //更新默认机种
|
||
}
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
#region 当前生产机种对象
|
||
private MachineModel currentMachine;
|
||
/// <summary>
|
||
/// 当前生产机种对象
|
||
/// </summary>
|
||
public MachineModel CurrentMachine
|
||
{
|
||
get { return currentMachine; }
|
||
set
|
||
{
|
||
currentMachine = value;
|
||
|
||
this.RaisePropertyChanged("CurrentMachine");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
#endregion
|
||
|
||
#region 站别集合
|
||
private ObservableCollection<StandModel> standList;
|
||
/// <summary>
|
||
/// 站别集合
|
||
/// </summary>
|
||
public ObservableCollection<StandModel> StandList
|
||
{
|
||
get { return standList; }
|
||
set
|
||
{
|
||
standList = value;
|
||
this.RaisePropertyChanged("StandList");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 选中的站别
|
||
private StandModel selectStand;
|
||
/// <summary>
|
||
/// 选中的站别
|
||
/// </summary>
|
||
public StandModel SelectStand
|
||
{
|
||
get { return selectStand; }
|
||
set
|
||
{
|
||
selectStand = value;
|
||
this.RaisePropertyChanged("SelectStand");
|
||
}
|
||
}
|
||
#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 生产数据总数结合
|
||
private List<DataCollectionModel> dataList;
|
||
/// <summary>
|
||
/// 测试数据集合
|
||
/// </summary>
|
||
public List<DataCollectionModel> DataList
|
||
{
|
||
get { return dataList; }
|
||
set
|
||
{
|
||
dataList = value;
|
||
this.RaisePropertyChanged("DataList");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 计划生产数量
|
||
private DataCollectionModel planData;
|
||
/// <summary>
|
||
/// 计划生产数量
|
||
/// </summary>
|
||
public DataCollectionModel PlanData
|
||
{
|
||
get { return planData; }
|
||
set
|
||
{
|
||
planData = value;
|
||
this.RaisePropertyChanged("PlanData");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 实际生产数量
|
||
private DataCollectionModel actualData;
|
||
/// <summary>
|
||
/// 实际生产数量
|
||
/// </summary>
|
||
public DataCollectionModel ActualData
|
||
{
|
||
get { return actualData; }
|
||
set
|
||
{
|
||
actualData = value;
|
||
this.RaisePropertyChanged("ActualData");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 不启用MES
|
||
private bool mesCheck;
|
||
/// <summary>
|
||
/// 不启用MES
|
||
/// </summary>
|
||
public bool MesCheck
|
||
{
|
||
get { return mesCheck; }
|
||
set
|
||
{
|
||
mesCheck = value;
|
||
this.RaisePropertyChanged("MesCheck");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
|
||
#region PLC连接对象
|
||
private FeiYuHsl myPLC;
|
||
/// <summary>
|
||
/// PLC连接对象
|
||
/// </summary>
|
||
public FeiYuHsl MyPLC
|
||
{
|
||
get { return myPLC; }
|
||
set
|
||
{
|
||
myPLC = value;
|
||
RaisePropertyChanged("MyPLC");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 万用表
|
||
/// </summary>
|
||
CommunicationManagementClass WangYongbiao { get; set; }
|
||
/// <summary>
|
||
/// 老化柜连接
|
||
/// </summary>
|
||
CommunicationManagementClass Laohuagui { get; set; }
|
||
|
||
private List<CommandModel> showDataList;
|
||
/// <summary>
|
||
/// 显示数据
|
||
/// </summary>
|
||
public List<CommandModel> ShowDataList
|
||
{
|
||
get { return showDataList; }
|
||
set
|
||
{
|
||
showDataList = value;
|
||
RaisePropertyChanged("ShowDataList");
|
||
}
|
||
}
|
||
|
||
|
||
#region 构造函数
|
||
/// <summary>
|
||
/// 构造函数
|
||
/// </summary>
|
||
public MainWindowVM(Window mywd)
|
||
{
|
||
Mywindow = mywd;
|
||
MyDispatcher = mywd.Dispatcher;
|
||
GridWidth = "30*";
|
||
|
||
Initialize(); //初始化
|
||
|
||
LightCOM = new SerialCom();
|
||
SerialProt = SystemPar.SerialProt;
|
||
|
||
|
||
LoadingFunctionInterface();//加载功能界面
|
||
|
||
AllVis = Visibility.Collapsed;
|
||
|
||
|
||
#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.SaveSystemPerCommand = new DelegateCommand();
|
||
this.SaveSystemPerCommand.ExecuteAction = new Action<object>(SaveSystemPer);
|
||
|
||
SaveStandCommand = new DelegateCommand();
|
||
SaveStandCommand.ExecuteAction = new Action<object>(SaveStand);
|
||
|
||
ReadDateCommand = new DelegateCommand();
|
||
ReadDateCommand.ExecuteAction = new Action<object>(ReadDate);
|
||
|
||
ExportDateCommand = new DelegateCommand();
|
||
ExportDateCommand.ExecuteAction = new Action<object>(ExportDate);
|
||
|
||
ReadPageUpCommand = new DelegateCommand();
|
||
ReadPageUpCommand.ExecuteAction = new Action<object>(ReadPageUp);
|
||
|
||
ReadPageDownCommand = new DelegateCommand();
|
||
ReadPageDownCommand.ExecuteAction = new Action<object>(ReadPageDown);
|
||
|
||
|
||
|
||
#endregion
|
||
|
||
GoHomeSteps = GengralProcessEnum.Start;
|
||
|
||
initializationChart();//初始化图表
|
||
|
||
StartTime = DateTime.Now;
|
||
EndTime = DateTime.Now;
|
||
|
||
PlatFormInitialize();
|
||
SelectedIndex = 0;
|
||
|
||
//启动连接MES
|
||
ERPVM.ERP.Enableing = true;
|
||
|
||
InitializeAginTestVM();
|
||
|
||
RunStatu = RunStatuEnum.Prepareations;
|
||
RunStartTime = DateTime.Now;//重新计时
|
||
MyPLC.Conneced();
|
||
|
||
LogicDispatchFlow = new FlowModel("测试流程");
|
||
|
||
WangYongbiao = ServerComm.CommList.Where(w => w.ShortCode == "WYB").FirstOrDefault();
|
||
WangYongbiao.ReceiveCallback += WangYongbiao_ReceiveCallback;
|
||
Laohuagui = ServerComm.CommList.Where(w => w.ShortCode == "LHG").FirstOrDefault();
|
||
Laohuagui.ReceiveCallback += Laohuagui_ReceiveCallback;
|
||
//开启状态监控线程
|
||
if (ThStateMonitoring == null)
|
||
{
|
||
ThStateMonitoring = new Thread(StateMonitoring);
|
||
ThStateMonitoring.IsBackground = true;
|
||
ThStateMonitoring.Start();
|
||
}
|
||
|
||
//开启测试
|
||
ThRun = new Thread(Run);
|
||
ThRun.IsBackground = true;
|
||
ThRun.Start();
|
||
|
||
//还原测试状态
|
||
if (CurrentMachine.MyPar.StatusList != null && CurrentMachine.MyPar.StatusList.Count >= AllGrouhandList.Count)
|
||
{
|
||
int a = 0;
|
||
foreach (var item in CurrentMachine.MyPar.StatusList)
|
||
{
|
||
AllGrouhandList[a].State = item;
|
||
a++;
|
||
}
|
||
}
|
||
|
||
|
||
List<CommandModel> lsm = new List<CommandModel>();
|
||
foreach (var item in CurrentMachine.CommandGroupList)
|
||
{
|
||
//过滤无效类型
|
||
foreach (var item1 in item.CommandList)
|
||
{
|
||
if (item1.MyType != 1 && item1.ParsingModel != 4 && item1.Enable)
|
||
{
|
||
lsm.Add(item1);
|
||
}
|
||
}
|
||
}
|
||
ShowDataList = lsm;
|
||
|
||
CurrHeatShow = new ShowInfo();
|
||
TempTimeSpan = TimeSpan.Zero;
|
||
}
|
||
|
||
|
||
#region 老化柜回调函数
|
||
private ShowInfo currHeatShow;
|
||
/// <summary>
|
||
/// 当前老化柜温度
|
||
/// </summary>
|
||
public ShowInfo CurrHeatShow
|
||
{
|
||
get { return currHeatShow; }
|
||
set
|
||
{
|
||
currHeatShow = value;
|
||
RaisePropertyChanged("CurrHeatShow");
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 老化柜回调函数
|
||
/// </summary>
|
||
/// <param name="str"></param>
|
||
/// <exception cref="NotImplementedException"></exception>
|
||
private void Laohuagui_ReceiveCallback(string str)
|
||
{
|
||
try
|
||
{
|
||
//00-00-00-00-00-05-01-03-02-02-41
|
||
List<string> strArr = str.Trim().Split('-').ToList();
|
||
strArr = strArr.GetRange(strArr.Count - 2, 2);//截取数据有效部分
|
||
List<byte> b = strArr.Select(w => Convert.ToByte(w, 16)).ToList();
|
||
byte[] buf = b.ToArray();
|
||
// 大端ushort
|
||
ushort Res = BitConverter.ToUInt16(buf.Reverse().ToArray(), 0);
|
||
|
||
// 小端ushort
|
||
//ushort Res = BitConverter.ToUInt16(buf.ToArray(), 0);
|
||
CurrHeatShow = CurrHeatShow ?? new ShowInfo();
|
||
CurrHeatShow.StatuValue = Math.Round(Res * 0.01, 3);//转换成小数
|
||
if (CurrHeatShow.StatuValue < CurrentMachine.MyPar.TestHeatMin || CurrHeatShow.StatuValue > CurrentMachine.MyPar.TestHeatMax)
|
||
{
|
||
CurrHeatShow.StatusForeground = Colors.Red.ToString();
|
||
}
|
||
else
|
||
{
|
||
CurrHeatShow.StatusForeground = ColorStr.Green; //Colors.Lime.ToString();
|
||
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
CurrHeatShow = CurrHeatShow ?? new ShowInfo();
|
||
CurrHeatShow.StatuValue = double.NaN;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 万用表回调函数
|
||
private double currDianliu;
|
||
/// <summary>
|
||
/// 当前电流
|
||
/// </summary>
|
||
public double CurrDianliu
|
||
{
|
||
get { return currDianliu; }
|
||
set { currDianliu = value; RaisePropertyChanged("CurrDianliu"); }
|
||
}
|
||
/// <summary>
|
||
/// 万用表回调函数
|
||
/// </summary>
|
||
/// <param name="str"></param>
|
||
/// <exception cref="NotImplementedException"></exception>
|
||
private void WangYongbiao_ReceiveCallback(string str)
|
||
{
|
||
CurrDianliu = Math.Round(Convert.ToDouble(str), 6);
|
||
}
|
||
#endregion
|
||
|
||
#region 保存站别信息
|
||
private void SaveStand(object obj)
|
||
{
|
||
if (SelectStand != null && SelectStand.ID > 0)
|
||
{
|
||
if (dal.UpdataATSModel(SelectStand) > 0)
|
||
{
|
||
MyMessageBox.Show("保存成功");
|
||
}
|
||
else
|
||
{
|
||
MyMessageBox.Show("保存失败");
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 导出产能数据
|
||
|
||
/// <summary>
|
||
/// 导出产能数据
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void ExportDate(object obj)
|
||
{
|
||
ExportFile();
|
||
}
|
||
#endregion
|
||
|
||
#region 读取产能数据
|
||
|
||
#region 查询开始时间
|
||
private DateTime startTime;
|
||
/// <summary>
|
||
/// 查询开始时间
|
||
/// </summary>
|
||
public DateTime StartTime
|
||
{
|
||
get { return startTime; }
|
||
set
|
||
{
|
||
startTime = value;
|
||
this.RaisePropertyChanged("StartTime");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 查询结束时间
|
||
private DateTime endTime;
|
||
/// <summary>
|
||
/// 查询结束时间
|
||
/// </summary>
|
||
public DateTime EndTime
|
||
{
|
||
get { return endTime; }
|
||
set
|
||
{
|
||
endTime = value;
|
||
//使选中的时间包含时间
|
||
endTime = new DateTime(value.Year, value.Month, value.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
|
||
this.RaisePropertyChanged("EndTime");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
private ObservableCollection<TimeSlotCapacity> tList;
|
||
/// <summary>
|
||
/// 时间段数据集合
|
||
/// </summary>
|
||
public ObservableCollection<TimeSlotCapacity> TList
|
||
{
|
||
get { return tList; }
|
||
set
|
||
{
|
||
tList = value;
|
||
this.RaisePropertyChanged("TList");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 读取产能数据
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void ReadDate(object obj)
|
||
{
|
||
TList = dal.GetTimeSlotCapacityList(StartTime, EndTime);
|
||
}
|
||
#endregion
|
||
|
||
#region 读取下一页 上一页
|
||
/// <summary>
|
||
/// 读取下一页
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void ReadPageDown(object obj)
|
||
{
|
||
if (TList != null && TList.Count > 0)
|
||
{
|
||
int id = TList.LastOrDefault().ID;//获取最后一个元素的ID
|
||
TList = dal.GetTimeSlotCapacityList(StartTime, EndTime, id, false);
|
||
}
|
||
else
|
||
{
|
||
ReadDate(0);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 读取上一个
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void ReadPageUp(object obj)
|
||
{
|
||
if (TList != null && TList.Count > 0)
|
||
{
|
||
int id = TList.FirstOrDefault().ID;//获取第一个元素的ID
|
||
TList = dal.GetTimeSlotCapacityList(StartTime, EndTime, id, true);
|
||
}
|
||
else
|
||
{
|
||
ReadDate(0);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 初始化生产图表
|
||
/// <summary>
|
||
/// 初始化生产图表
|
||
/// </summary>
|
||
private void initializationChart()
|
||
{
|
||
double heat = (CurrentMachine.MyPar.TestHeatMin + CurrentMachine.MyPar.TestHeatMax) / 2;
|
||
//产能
|
||
CVM1 = new ChartVM();
|
||
CVM1.ColorV2 = Colors.SkyBlue.ToString(); ;
|
||
Random rd = new Random();
|
||
for (int i = 0; i < 101; i++)
|
||
{
|
||
CVM1.Labels.Add(i.ToString());
|
||
CVM1.V1.Add(new ObservableValue(heat));
|
||
//rd.Next(50, 80)
|
||
CVM1.V2.Add(new ObservableValue(double.NaN));
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 图标刷新时间
|
||
/// </summary>
|
||
DateTime RefreshTime { get; set; } = DateTime.Now;
|
||
/// <summary>
|
||
/// 刷新图标
|
||
/// </summary>
|
||
public void RefreshChart()
|
||
{
|
||
|
||
//CVM1.V2.Remove(CVM1.V2[0]);
|
||
//CVM1.V2.Add(new ObservableValue(HeatValue));
|
||
//RefreshTime = DateTime.Now;
|
||
|
||
try
|
||
{
|
||
if (RefreshTime.AddSeconds(1) < DateTime.Now && CurrHeatShow != null)
|
||
{
|
||
CVM1.ColorV2 = CurrHeatShow.StatusForeground;
|
||
CVM1.V2.Remove(CVM1.V2[0]);
|
||
CVM1.V2.Add(new ObservableValue(CurrHeatShow.StatuValue));
|
||
RefreshTime = DateTime.Now;
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 保存生产计划参数
|
||
/// <summary>
|
||
/// 保存生产计划参数
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void SavePlan(object obj)
|
||
{
|
||
if (dal.UpdateDataCollection(PlanData) > 0)
|
||
{
|
||
CVM1.V1[0] = new ObservableValue(PlanData.Phase1);
|
||
CVM1.V1[1] = new ObservableValue(PlanData.Phase2);
|
||
CVM1.V1[2] = new ObservableValue(PlanData.Phase3);
|
||
CVM1.V1[3] = new ObservableValue(PlanData.Phase4);
|
||
CVM1.V1[4] = new ObservableValue(PlanData.Phase5);
|
||
CVM1.V1[5] = new ObservableValue(PlanData.Phase6);
|
||
CVM1.V1[6] = new ObservableValue(PlanData.Phase7);
|
||
CVM1.V1[7] = new ObservableValue(PlanData.Phase8);
|
||
CVM1.V1[8] = new ObservableValue(PlanData.Phase9);
|
||
CVM1.V1[9] = new ObservableValue(PlanData.Phase10);
|
||
CVM1.V1[10] = new ObservableValue(PlanData.Phase11);
|
||
CVM1.V1[11] = new ObservableValue(PlanData.Phase12);
|
||
CVM1.V1[12] = new ObservableValue(PlanData.Phase13);
|
||
CVM1.V1[13] = new ObservableValue(PlanData.Phase14);
|
||
CVM1.V1[14] = new ObservableValue(PlanData.Phase15);
|
||
CVM1.V1[15] = new ObservableValue(PlanData.Phase16);
|
||
CVM1.V1[16] = new ObservableValue(PlanData.Phase17);
|
||
CVM1.V1[17] = new ObservableValue(PlanData.Phase18);
|
||
CVM1.V1[18] = new ObservableValue(PlanData.Phase19);
|
||
CVM1.V1[19] = new ObservableValue(PlanData.Phase20);
|
||
CVM1.V1[20] = new ObservableValue(PlanData.Phase21);
|
||
CVM1.V1[21] = new ObservableValue(PlanData.Phase22);
|
||
CVM1.V1[22] = new ObservableValue(PlanData.Phase23);
|
||
CVM1.V1[23] = new ObservableValue(PlanData.Phase24);
|
||
MyMessageBox.Show("保存成功");
|
||
}
|
||
else
|
||
{
|
||
MyMessageBox.Show("保存失败");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 保存系统信息
|
||
/// <summary>
|
||
/// 保存系统信息
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void SaveSystemPer(object obj)
|
||
{
|
||
if (dal.UpdateSystemPar(SystemPar) > 0)
|
||
{
|
||
MyMessageBox.Show("保存成功");
|
||
}
|
||
else
|
||
{
|
||
MyMessageBox.Show("保存失败");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
|
||
#endregion
|
||
|
||
#region 1、系统初始化
|
||
/// <summary>
|
||
/// 系统初始化
|
||
/// </summary>
|
||
public void Initialize()
|
||
{
|
||
//1、初始化系统参数
|
||
SystemPar = dal.GetSystemPar();
|
||
StandList = dal.GetATSList();
|
||
|
||
PlcConVM = new PLCVM();
|
||
MyPLC = PlcConVM.HslList[0];
|
||
|
||
//AllVis = Visibility.Collapsed;
|
||
RunTimeShow = new ShowInfo() { StatusForeground = ColorStr.White };
|
||
TiShiBaojingTime = DateTime.Now;
|
||
ShowStatu = new ShowInfo();
|
||
RunStatu = RunStatuEnum.Prepare;
|
||
|
||
ExcepList = new ObservableCollection<RecordInfo>();
|
||
|
||
|
||
ERPVM = new ERPManageVM(SystemPar.ID, this.dal);
|
||
SCVM = new SerialComVM(SystemPar.ID); //串口对象
|
||
|
||
|
||
ServerComm = new CommunicationServerVM(SystemPar.ID, Mywindow.Dispatcher);
|
||
ServerComm.MonitorsWitch = true;
|
||
|
||
|
||
//机种参数
|
||
InitializeMachineEditor();
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
#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>
|
||
private void StateMonitoring()
|
||
{
|
||
while (true)
|
||
{
|
||
//Thread.Sleep(10);
|
||
|
||
//记录当前软件运行时间
|
||
//TimeSpan ts = DateTime.Now.Subtract(RunStartTime).Duration();
|
||
// OpenTime = DateTime.Now.Subtract(SystemPar.StartupTime).Duration(); //DateTime.Now - RunStartTime;
|
||
// DateTime dt = DateTime.Now.AddMilliseconds(-Environment.TickCount);//获取电脑开机时间
|
||
// OpenTime= new TimeSpan(Convert.ToInt64(Environment.TickCount) * 10000);//TimeSpan.FromMilliseconds(-Environment.TickCount);//DateTime.Now.Subtract(dt).Duration();
|
||
// RunTimeShow.StatuInfo = string.Format("{0}:{1}:{2}", OpenTime.Hours, OpenTime.Minutes, OpenTime.Seconds);
|
||
//if (OpenTime.Seconds >= CurrentMachine.MyPar.TestTime)
|
||
//{
|
||
|
||
// ExcepStop("测试时间到");
|
||
//}
|
||
|
||
GetHeatRun();//实时获取老化柜温度
|
||
RefreshChart();//刷新图表
|
||
}
|
||
}
|
||
|
||
#region 回原点
|
||
DateTime GoHomeTIme { get; set; }
|
||
/// <summary>
|
||
/// 回原点
|
||
/// </summary>
|
||
private void GoHome()
|
||
{
|
||
|
||
switch (GoHomeSteps)
|
||
{
|
||
case GengralProcessEnum.Start:
|
||
//优先机械手回原点
|
||
if (Robot != null)
|
||
{
|
||
if (Robot.HomeStep == GengralProcessEnum.End)
|
||
{
|
||
GoHomeSteps++;
|
||
}
|
||
else
|
||
{
|
||
Robot.RobotOrgin();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
GoHomeSteps++;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step1:
|
||
if (MCVM != null)
|
||
{
|
||
MCVM.HomeStep = GengralProcessEnum.Start;
|
||
GoHomeSteps++;
|
||
}
|
||
else
|
||
{
|
||
GoHomeSteps = GengralProcessEnum.End;
|
||
RunStatu = RunStatuEnum.Prepareations; //准备就绪
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step2:
|
||
if (MCVM.HomeStep == GengralProcessEnum.End)
|
||
{
|
||
GoHomeSteps = GengralProcessEnum.End;
|
||
RunStatu = RunStatuEnum.Prepareations; //准备就绪
|
||
|
||
}
|
||
break;
|
||
}
|
||
|
||
|
||
}
|
||
#endregion
|
||
|
||
#endregion
|
||
|
||
#region 3、运行
|
||
|
||
#region 网络连接控制
|
||
bool fir { get; set; }
|
||
/// <summary>
|
||
/// 网络连接控制
|
||
/// </summary>
|
||
private void ConnectNet()
|
||
{
|
||
while (true)
|
||
{
|
||
try
|
||
{
|
||
//只执行一次连接
|
||
if (!RunningMode && !fir)
|
||
{
|
||
foreach (CommunicationManagementClass cc in ServerComm.CommList)
|
||
{
|
||
cc.ConnectSwitch = true;
|
||
|
||
}
|
||
fir = true;
|
||
}
|
||
|
||
// ComCheck();
|
||
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 启动运行
|
||
|
||
/// <summary>
|
||
/// 启动运行
|
||
/// </summary>
|
||
private void Run()
|
||
{
|
||
while (true)
|
||
{
|
||
try
|
||
{
|
||
|
||
|
||
if (RunStatu == RunStatuEnum.Normal)
|
||
{
|
||
|
||
if (!fir)
|
||
{
|
||
MyPLC.Conneced();
|
||
fir = true;
|
||
}
|
||
|
||
if (MyPLC.PLC.PlcStatus.StatusBackground != ColorStr.Green)
|
||
{
|
||
ExcepStop("PLC未连接");
|
||
continue;
|
||
}
|
||
if (Laohuagui.Showmsg.StatusBackground != ColorStr.Green)
|
||
|
||
{
|
||
ExcepStop("老化柜未连接");
|
||
continue;
|
||
}
|
||
if (powerTime.AddSeconds(1) < DateTime.Now)
|
||
{
|
||
powerTime = DateTime.Now;
|
||
|
||
if (MyPLC.PLC.ReadBool("X0") == false)
|
||
{
|
||
X0Err++;
|
||
if (X0Err > 3)
|
||
{
|
||
ExcepStop("测试电源未开");
|
||
continue;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
|
||
X0Err = 0;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
if (lockTime.AddSeconds(1) < DateTime.Now)
|
||
{
|
||
lockTime = DateTime.Now;
|
||
MyPLC.PLC.Write("Y2", true);
|
||
Door = "已锁";
|
||
}
|
||
|
||
LogicDispatch(LogicDispatchFlow);
|
||
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
ExcepStop(ex.Message);
|
||
|
||
}
|
||
|
||
}
|
||
}
|
||
private int X0Err;
|
||
private DateTime lockTime = DateTime.Now;
|
||
private DateTime powerTime = DateTime.Now;
|
||
#endregion
|
||
|
||
#region 大总管
|
||
/// <summary>
|
||
/// 大总管
|
||
/// </summary>
|
||
FlowModel LogicDispatchFlow { get; set; }
|
||
/// <summary>
|
||
/// 当前测试对象
|
||
/// </summary>
|
||
HandModel MyHand { get; set; }
|
||
|
||
/// <summary>
|
||
/// 测试中
|
||
/// </summary>
|
||
public bool Testing { get; set; }
|
||
|
||
/// <summary>
|
||
/// 当前测试群组
|
||
/// </summary>
|
||
CommandGroup MyGroup { get; set; }
|
||
|
||
/// <summary>
|
||
/// 已测试时间
|
||
/// </summary>
|
||
TimeSpan TestTimeSpan { get; set; }
|
||
/// <summary>
|
||
/// 测试临时缓存时间
|
||
/// </summary>
|
||
TimeSpan TempTimeSpan { get; set; }
|
||
/// <summary>
|
||
/// 大总管
|
||
/// </summary>
|
||
private void LogicDispatch(FlowModel MyFlow)
|
||
{
|
||
if (Testing)
|
||
{
|
||
TimeSpan ts = DateTime.Now.Subtract(RunStartTime).Duration();
|
||
TestTimeSpan = (ts + TempTimeSpan);
|
||
RunTimeShow.StatuInfo = string.Format("{0}:{1}:{2}", TestTimeSpan.Hours, TestTimeSpan.Minutes, TestTimeSpan.Seconds);
|
||
|
||
|
||
}
|
||
else
|
||
{
|
||
RunTimeShow.StatuInfo = "等待升温";
|
||
|
||
}
|
||
|
||
|
||
switch (MyFlow.RunStep)
|
||
{
|
||
case GengralProcessEnum.Start:
|
||
//老化柜温度要到达
|
||
if (CurrHeatShow.StatusForeground == ColorStr.Green || CurrentMachine.RunningMode|| TestTimeSpan.TotalMinutes >= CurrentMachine.MyPar.TestTime)
|
||
{
|
||
|
||
if (!Testing)
|
||
{
|
||
RunStartTime = DateTime.Now;
|
||
TempTimeSpan = TimeSpan.Zero;
|
||
Testing = true;
|
||
}
|
||
//空格子
|
||
int GrayCount = AllGrouhandList.Where(w => w.State.StatusBackground == ColorStr.Gray).Count();
|
||
//老化时间到 测试结束
|
||
if (TestTimeSpan.TotalMinutes >= CurrentMachine.MyPar.TestTime || GrayCount >= AllGrouhandList.Count)
|
||
{
|
||
|
||
|
||
MyPLC.PLC.Write("Y2", false);//开门
|
||
Door = "未锁";
|
||
|
||
Testing = false;
|
||
RunStatu = RunStatuEnum.Prepareations;
|
||
ShowStatu.StatuInfo = "测试完成";
|
||
|
||
JiawenCloseBl = true;//关闭老化柜加温
|
||
|
||
if (GrayCount < AllGrouhandList.Count)
|
||
{
|
||
int NGcout = 0;
|
||
foreach (var item in AllGrouhandList)
|
||
{
|
||
CurrentMachine.Quantitys++;
|
||
|
||
//产品测试测次数等于NG次数 直接判定产品NG 变大红色
|
||
if (item.State.TestCount > 0 && item.State.TestCount <= item.State.TestCountNG)
|
||
{
|
||
item.State.StatusBackground = Colors.Red.ToString();
|
||
item.TestData += "NG";
|
||
NGcout++;
|
||
}
|
||
else
|
||
{
|
||
item.State.StatusBackground = Colors.Green.ToString();
|
||
item.TestData += "OK";
|
||
CurrentMachine.Produce++;
|
||
}
|
||
}
|
||
try
|
||
{
|
||
//最后结算 是否为终极不良 记录日志
|
||
TestResultLog(ShowDataList);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
ExcepStop("CSV文档被打开,或其他错误");
|
||
}
|
||
|
||
if (NGcout > 0)
|
||
{
|
||
ExcepStop("测试完成,请留意NG品");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ExcepStop("没有进行任何产品测试,请检查电源是否开启");
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
|
||
|
||
|
||
MyHand = AllGrouhandList.Where(w => w.State.StatusBackground == ColorStr.Blue).FirstOrDefault();
|
||
if (MyHand != null)
|
||
{
|
||
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
AllGrouhandList.ForEach(w => { w.State.StatusBackground = w.State.StatusBackground != ColorStr.Gray ? ColorStr.Blue : ColorStr.Gray; });
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step1:
|
||
//切换测试模式
|
||
if (MyPLC.PLC.Write("Protocol", CurrentMachine.MyPar.TestModel))
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 2000, "切换测试模式失败"))
|
||
{
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step2:
|
||
//延时100毫秒
|
||
if (MyFlow.RunTime.AddMilliseconds(100) < DateTime.Now)
|
||
{
|
||
//切换到对应产品
|
||
if (MyPLC.PLC.Write("Conn", MyHand.Number))
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (TimeOutValidation(MyFlow.RunTime, 3000, "切换产品失败"))
|
||
{
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step3:
|
||
//延时1秒 使继电器充分切换完成
|
||
if (MyFlow.RunTime.AddMilliseconds(1000) < DateTime.Now)
|
||
{
|
||
//连接测试仪器
|
||
if (OpenOpenDevice(41, 0, 0))
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
//重置群组测试状态
|
||
foreach (var item in CurrentMachine.CommandGroupList)
|
||
{
|
||
item.RunOK = false;
|
||
foreach (var f in item.CommandList)
|
||
{
|
||
f.MyValue.ActualValue = "";
|
||
f.MyValue.Result = 0;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ExcepStop("打开【USBCANFD-200U 41】失败");
|
||
}
|
||
|
||
ShowStr = "";
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step4:
|
||
//唤醒
|
||
if (ZLGCAN.ZCAN_WakeUpLIN(linHandle[0]) == 1)
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step5:
|
||
if (MyFlow.RunTime.AddMilliseconds(100) < DateTime.Now)
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step6:
|
||
MyGroup = CurrentMachine.CommandGroupList.Where(w => w.RunOK == false && w.Enable).FirstOrDefault();
|
||
if (MyGroup != null)
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
MyFlow.NoteFlow = new FlowModel("测试流程");
|
||
foreach (var item in MyGroup.CommandList)
|
||
{
|
||
item.RunOK = false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (MyHand.State.StatusBackground != ColorStr.Gray)//如果禁用了 测不变颜色
|
||
{
|
||
MyHand.State.TestCount++;//记录测试总次数
|
||
MyHand.State.StatusBackground = ColorStr.Green;
|
||
string resStr = "OK";
|
||
//记录测试日志
|
||
|
||
foreach (var item in ShowDataList)
|
||
{
|
||
if (item.MyValue.Result != 1)
|
||
{
|
||
resStr = "NG";
|
||
MyHand.State.TestCountNG++;//记录测试NG次数
|
||
}
|
||
}
|
||
if (resStr != "OK")
|
||
{
|
||
MyHand.State.StatusBackground = ColorStr.Red;
|
||
CurrentMachine.Quantitys++;
|
||
CurrentMachine.Produce++;
|
||
}
|
||
|
||
try
|
||
{
|
||
TestResultLog(MyHand, ShowDataList, resStr);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
ExcepStop("CSV文档被打开,或其他错误");
|
||
}
|
||
}
|
||
|
||
MyFlow.RunStep = GengralProcessEnum.Start;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step7:
|
||
//if (TestRun(MyFlow.NoteFlow))
|
||
if (SingleItem(MyFlow.NoteFlow))
|
||
{
|
||
MyGroup.RunOK = true;
|
||
MyFlow.RunStep--;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (MyFlow.RunTime.AddSeconds(15) < DateTime.Now)//10秒都还没测完 直接重测
|
||
{
|
||
MyGroup.RunOK = false;
|
||
MyFlow.RunStep--;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 单项测试
|
||
/// </summary>
|
||
/// <param name="MyFlow"></param>
|
||
/// <returns></returns>
|
||
private bool SingleItem(FlowModel MyFlow)
|
||
{
|
||
MyFlow.bl = false;
|
||
switch (MyFlow.RunStep)
|
||
{
|
||
case GengralProcessEnum.Start:
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step1:
|
||
MyCommand = MyGroup.CommandList.Where(w => w.RunOK == false && w.Enable).FirstOrDefault();
|
||
if (MyCommand != null && MyHand.State.StatusBackground != ColorStr.Gray)
|
||
{
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
MyFlow.MyCommand = MyCommand;
|
||
MyFlow.MyCommand.DataLength = 0;//重置接收长度
|
||
MyFlow.NoteFlow = new FlowModel("子流程");
|
||
MyFlow.NoteFlow.MyCommand = MyCommand;
|
||
|
||
}
|
||
else
|
||
{
|
||
MyFlow.bl = true;
|
||
MyGroup.RunOK = true;//群组运行完成
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step2:
|
||
switch (MyFlow.MyCommand.MyType)
|
||
{
|
||
case 1:
|
||
case 2:
|
||
//获取指令数据
|
||
if (GetCommandData(MyFlow.NoteFlow))
|
||
{
|
||
MyFlow.RunStep--;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case 3:
|
||
//读取电流
|
||
if (ReadDianliu(MyFlow.NoteFlow))
|
||
{
|
||
MyFlow.RunStep--;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
|
||
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step3:
|
||
//唤醒
|
||
if (ZLGCAN.ZCAN_WakeUpLIN(linHandle[0]) == 1)
|
||
{
|
||
MyFlow.MyCommand.RunOK = true;
|
||
MyFlow.MyCommand.ResOK = true;
|
||
MyFlow.MyCommand.MyValue.ActualValue = "1";
|
||
MyFlow.MyCommand.MyValue.Result = 1;
|
||
}
|
||
else
|
||
{
|
||
MyFlow.MyCommand.RunOK = true;
|
||
MyFlow.MyCommand.ResOK = true;
|
||
MyFlow.MyCommand.MyValue.ActualValue = "0";
|
||
MyFlow.MyCommand.MyValue.Result = 2;
|
||
}
|
||
MyFlow.RunStep = GengralProcessEnum.Step1;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
|
||
break;
|
||
}
|
||
|
||
return MyFlow.bl;
|
||
|
||
}
|
||
|
||
#region 读取指令数据
|
||
/// <summary>
|
||
/// 读取指令数据
|
||
/// </summary>
|
||
/// <param name="MyFlow"></param>
|
||
/// <param name="MyCommand"></param>
|
||
/// <returns></returns>
|
||
private bool GetCommandData(FlowModel MyFlow)
|
||
{
|
||
MyFlow.bl = false;
|
||
switch (MyFlow.RunStep)
|
||
{
|
||
case GengralProcessEnum.Start:
|
||
//先发响应 此时不会有返回值
|
||
MyFlow.MyCommand.ID = MyFlow.MyCommand.TxID;
|
||
SetLINPublish_Test(linHandle[0], MyFlow.MyCommand);
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step1:
|
||
//间隔10毫秒 确认发送是否成功
|
||
if (MyFlow.RunTime.AddMilliseconds(50) < DateTime.Now)
|
||
{
|
||
ReceiveInfo = null;//清空返回值
|
||
//再发头部 有返回值
|
||
LIN_Send_Test(linHandle[0], MyFlow.MyCommand);
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step2:
|
||
//核对信息是否一致
|
||
if (ReceiveInfo != null && ReceiveInfo.ID == MyFlow.MyCommand.ID)
|
||
{
|
||
if (MyFlow.RunTime.AddMilliseconds(50) < DateTime.Now)
|
||
{
|
||
ReceiveInfo = null;//清空返回值
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
}
|
||
else if (MyFlow.RunTime.AddMilliseconds(1000) < DateTime.Now)
|
||
{
|
||
MyFlow.RunStep = GengralProcessEnum.Start;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step3:
|
||
MyFlow.MyCommand.ID = MyFlow.MyCommand.RxID;
|
||
//再发头部 有返回值
|
||
LIN_Send_Test(linHandle[0], MyFlow.MyCommand);
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step4:
|
||
if (ReceiveInfo != null)
|
||
{
|
||
//返回ID一致
|
||
if (MyFlow.MyCommand.ID == (ReceiveInfo.ID))
|
||
{
|
||
if (MyFlow.MyCommand.ID == "3F")
|
||
{
|
||
//接收长度 足够时 测试下一项否则继续发送3F
|
||
if (!ReceiveInfo.ReceiptCompleted)
|
||
{
|
||
if (MyFlow.RunTime.AddMilliseconds(20) < DateTime.Now)
|
||
{
|
||
MyFlow.RunStep--;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//结果结算
|
||
MyFlow.MyCommand.ReturnValue = ReceiveInfo.DataHex;
|
||
MyFlow.MyCommand.ParsingResult();//结果解析
|
||
MyFlow.MyCommand.RunOK = true;
|
||
MyFlow.MyCommand.ResOK = true;
|
||
MyFlow.bl = true;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
MyFlow.MyCommand.ReturnValue = ReceiveInfo.DataHex;
|
||
MyFlow.MyCommand.RunOK = true;
|
||
MyFlow.MyCommand.ResOK = true;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
}
|
||
}
|
||
//进入工厂模式失败,则认为没有产品直接不测 跳过测下一个
|
||
else if (MyFlow.MyCommand.MyType == 1)
|
||
{
|
||
if (MyFlow.RunTime.AddMilliseconds(500) <= DateTime.Now)
|
||
{
|
||
MyFlow.MyCommand.RunOK = true;
|
||
MyFlow.MyCommand.ResOK = false;
|
||
MyHand.State.StatusBackground = ColorStr.Gray;//测试失败
|
||
MyFlow.bl = true;
|
||
MyGroup.RunOK = true;//群组运行完成
|
||
MyFlow.RunStep = GengralProcessEnum.End;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
}
|
||
else if (MyFlow.RunTime.AddMilliseconds(3500) <= DateTime.Now)
|
||
{
|
||
MyFlow.RunStep = GengralProcessEnum.Start;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step5:
|
||
if (MyFlow.RunTime.AddMilliseconds(50) < DateTime.Now)
|
||
{
|
||
MyFlow.bl = true;
|
||
}
|
||
break;
|
||
}
|
||
return MyFlow.bl;
|
||
}
|
||
#endregion
|
||
|
||
#region 读取电流
|
||
/// <summary>
|
||
/// 读取电流
|
||
/// </summary>
|
||
/// <param name="MyFlow"></param>
|
||
/// <returns></returns>
|
||
private bool ReadDianliu(FlowModel MyFlow)
|
||
{
|
||
MyFlow.bl = false;
|
||
switch (MyFlow.RunStep)
|
||
{
|
||
case GengralProcessEnum.Start:
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step1:
|
||
//万用表连接成功
|
||
if (WangYongbiao.Showmsg.StatusBackground == ColorStr.Green)
|
||
{
|
||
//切换成直流模式
|
||
WangYongbiao.SendInfo("CONF:CURR:DC 200 mA,SLOW\r\n");
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (MyFlow.RunTime.AddMilliseconds(1000) <= DateTime.Now)
|
||
{
|
||
ExcepStop("万用表未连接");
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step2:
|
||
//延时0.5秒
|
||
if (MyFlow.RunTime.AddMilliseconds(1000) < DateTime.Now)
|
||
{
|
||
CurrDianliu = 99999;
|
||
//读取电流
|
||
WangYongbiao.SendInfo("READ?\r\n");
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step3:
|
||
//有接收到数据
|
||
if (!string.IsNullOrEmpty(WangYongbiao.ReceiveInfo) && CurrDianliu != 99999)
|
||
{
|
||
MyFlow.MyCommand.MyValue = MyFlow.MyCommand.MyValue ?? new RangeValueModel();
|
||
double jg = Math.Round((CurrDianliu * MyFlow.MyCommand.MyValue.ScalingFactor), 6);//转换系数 为了到达客户需求单位
|
||
MyFlow.MyCommand.MyValue.ActualValue = jg.ToString();
|
||
MyFlow.MyCommand.ReturnValue = jg.ToString();
|
||
MyFlow.MyCommand.RunOK = true;
|
||
MyFlow.MyCommand.ResOK = true;
|
||
//刷新结果
|
||
MyFlow.MyCommand.MyValue.RangeType = MyFlow.MyCommand.ParsingModel;
|
||
MyFlow.MyCommand.MyValue.GetResult();
|
||
MyFlow.RunStep = GengralProcessEnum.Step1;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
ShowStr += MyFlow.MyCommand.NameStr + ":" + MyFlow.MyCommand.ReturnValue + "\r\n";
|
||
MyFlow.bl = true;
|
||
}
|
||
break;
|
||
}
|
||
return MyFlow.bl;
|
||
}
|
||
#endregion
|
||
|
||
#region 测试运行
|
||
/// <summary>
|
||
/// 当前测试交互指令
|
||
/// </summary>
|
||
CommandModel MyCommand { get; set; }
|
||
/// <summary>
|
||
/// 测试运行
|
||
/// </summary>
|
||
/// <param name="MyFlow"></param>
|
||
/// <returns></returns>
|
||
private bool TestRun(FlowModel MyFlow)
|
||
{
|
||
MyFlow.bl = false;
|
||
switch (MyFlow.RunStep)
|
||
{
|
||
case GengralProcessEnum.Start:
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case GengralProcessEnum.Step1:
|
||
MyCommand = MyGroup.CommandList.Where(w => w.RunOK == false && w.Enable).FirstOrDefault();
|
||
if (MyCommand != null)
|
||
{
|
||
MyCommand.MyValue.ActualValue = "";
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else
|
||
{
|
||
MyFlow.bl = true;
|
||
MyGroup.RunOK = true;//群组运行完成
|
||
}
|
||
|
||
break;
|
||
case GengralProcessEnum.Step2:
|
||
ReceiveInfo = null;//清空返回值
|
||
//间隔10毫秒
|
||
switch (MyCommand.MyType)
|
||
{
|
||
case 1:
|
||
//先发响应 此时不会有返回值
|
||
SetLINPublish_Test(linHandle[0], MyCommand);
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case 2:
|
||
LIN_Send_Test(linHandle[0], MyCommand);
|
||
MyFlow.RunStep = GengralProcessEnum.Step4;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case 3:
|
||
SetLINPublish_Test(linHandle[0], MyCommand);
|
||
MyCommand.RunOK = true;
|
||
MyCommand.ResOK = true;
|
||
MyFlow.RunStep = GengralProcessEnum.Step5;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
case 4://读取电流
|
||
MyFlow.RunStep = GengralProcessEnum.Step10;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
break;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step3:
|
||
//间隔10毫秒
|
||
if (MyFlow.RunTime.AddMilliseconds(50) < DateTime.Now)
|
||
{
|
||
//再发头部 此时有方绘制
|
||
LIN_Send_Test(linHandle[0], MyCommand);
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step4:
|
||
if (ReceiveInfo != null)
|
||
{
|
||
//返回ID一致
|
||
if (MyCommand.ID == (ReceiveInfo.ID))
|
||
{
|
||
if (MyCommand.ID == "3F")
|
||
{
|
||
//接收长度 足够时 测试下一项否则继续发送3F
|
||
if (!ReceiveInfo.ReceiptCompleted)
|
||
{
|
||
if (MyFlow.RunTime.AddMilliseconds(10) < DateTime.Now)
|
||
{
|
||
MyFlow.RunStep--;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//结果全部转
|
||
MyCommand.ReturnValue = ReceiveInfo.DataHex;
|
||
MyCommand.ParsingResult();//结果解析
|
||
MyCommand.RunOK = true;
|
||
MyCommand.ResOK = true;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
MyCommand.ReturnValue = ReceiveInfo.DataHex;
|
||
MyCommand.RunOK = true;
|
||
MyCommand.ResOK = true;
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
}
|
||
}
|
||
//进入工厂模式失败,则认为没有产品直接不测 跳过测下一个
|
||
else if (MyCommand.ID == "3D" && MyFlow.RunTime.AddMilliseconds(1000) <= DateTime.Now)
|
||
{
|
||
MyCommand.RunOK = true;
|
||
MyCommand.ResOK = false;
|
||
MyHand.State.StatusBackground = ColorStr.Gray;//禁用 下一次不测
|
||
MyFlow.bl = true;
|
||
MyGroup.RunOK = true;//群组运行完成
|
||
MyFlow.RunStep = GengralProcessEnum.End; ;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step5:
|
||
if (MyFlow.RunTime.AddMilliseconds(50) < DateTime.Now)
|
||
{
|
||
MyFlow.RunStep = GengralProcessEnum.Step1;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step10:
|
||
if (WangYongbiao.Showmsg.StatusBackground == ColorStr.Green)
|
||
{
|
||
//切换成直流模式
|
||
WangYongbiao.SendInfo("CONF:CURR:DC 200 mA,SLOW\r\n");
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
else if (MyFlow.RunTime.AddMilliseconds(1000) <= DateTime.Now)
|
||
{
|
||
ExcepStop("万用表未连接");
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step11:
|
||
//延时0.5秒
|
||
if (MyFlow.RunTime.AddMilliseconds(100) < DateTime.Now)
|
||
{
|
||
CurrDianliu = 99999;
|
||
//读取电流
|
||
WangYongbiao.SendInfo("READ?\r\n");
|
||
MyFlow.RunStep++;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
}
|
||
break;
|
||
case GengralProcessEnum.Step12:
|
||
//有接收到数据
|
||
if (!string.IsNullOrEmpty(WangYongbiao.ReceiveInfo) && CurrDianliu != 99999)
|
||
{
|
||
MyCommand.MyValue = MyCommand.MyValue ?? new RangeValueModel();
|
||
double jg = Math.Round((CurrDianliu * MyCommand.MyValue.ScalingFactor), 6);//转换系数 为了到达客户需求单位
|
||
MyCommand.MyValue.ActualValue = jg.ToString();
|
||
MyCommand.ReturnValue = jg.ToString();
|
||
MyCommand.RunOK = true;
|
||
MyCommand.ResOK = true;
|
||
//刷新结果
|
||
MyCommand.MyValue.RangeType = MyCommand.ParsingModel;
|
||
MyCommand.MyValue.GetResult();
|
||
MyFlow.RunStep = GengralProcessEnum.Step1;
|
||
MyFlow.RunTime = DateTime.Now;
|
||
ShowStr += MyCommand.NameStr + ":" + MyCommand.ReturnValue + "\r\n";
|
||
}
|
||
break;
|
||
}
|
||
|
||
return MyFlow.bl;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 读取PLC生产资讯数据
|
||
/// </summary>
|
||
private void ReadMachineData()
|
||
{
|
||
//心跳 持续 写入1
|
||
MyPLC.PLC.Write("D6500", 0);
|
||
|
||
//批量读取机台数据
|
||
int aa = MyPLC.PLC.ReadInt32("D1500");
|
||
if (aa > 0)
|
||
{
|
||
try
|
||
{
|
||
//站别运行状态
|
||
switch (aa)
|
||
{
|
||
case 1:
|
||
//运行中
|
||
RunStatu = RunStatuEnum.Normal;
|
||
break;
|
||
case 2:
|
||
//停止中
|
||
RunStatu = RunStatuEnum.Stop;
|
||
break;
|
||
case 3:
|
||
//异常中
|
||
RunStatu = RunStatuEnum.Exceptional;
|
||
break;
|
||
case 4:
|
||
//准备中
|
||
RunStatu = RunStatuEnum.Prepare;
|
||
break;
|
||
default:
|
||
RunStatu = RunStatuEnum.Unknown;
|
||
break;
|
||
}
|
||
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
ShowStatu = new ShowInfo() { StatusBackground = ColorStr.Red, StatuInfo = "机台数据有误", ID = 10 };
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ShowStatu = new ShowInfo() { StatusBackground = ColorStr.Red, StatuInfo = "读取机台数据失败", ID = 10 };
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
|
||
#endregion
|
||
|
||
#region 4、加载功能界面
|
||
|
||
Views.Vision.AOI2 aoi2;
|
||
Views.Vision.AOIRDAAE aoiRDAAE;
|
||
private Visibility showShaftState;
|
||
/// <summary>
|
||
/// 是否显示轴状态
|
||
/// </summary>
|
||
public Visibility ShowShaftState
|
||
{
|
||
get { return showShaftState; }
|
||
set
|
||
{
|
||
showShaftState = value;
|
||
this.RaisePropertyChanged("ShowShaftState");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 加载功能界面
|
||
/// </summary>
|
||
private void LoadingFunctionInterface()
|
||
{
|
||
TabItemList = new ObservableCollection<TabItem>();
|
||
TabItem tabiyu;
|
||
//添加主页界面
|
||
MainInterface mi = new MainInterface();
|
||
TabItem tabmi = new TabItem() { Content = mi };
|
||
tabmi.Header = "主界面";
|
||
TabItemList.Add(tabmi);
|
||
|
||
//StandWindow sw = new StandWindow();
|
||
//TabItem swi = new TabItem() { Content = sw };
|
||
//swi.Header = "MES界面";
|
||
//TabItemList.Add(swi);
|
||
|
||
if (SystemPar.VisionBool)
|
||
{
|
||
List<FeiYuCamere> Camlist = Vdal.GetCameraList();
|
||
HVlist = new List<HalconVisual>();
|
||
|
||
//先加载一个视觉运行预览界面
|
||
aoi2 = new Views.Vision.AOI2();
|
||
//aoiRDAAE = new Views.Vision.AOIRDAAE();
|
||
//if (CurrentMachine.ID == 6 || CurrentMachine.ID == 7)
|
||
//{
|
||
// tabiyu = new TabItem() { Content = aoiRDAAE, Tag = "v" };
|
||
//}
|
||
//else
|
||
//{
|
||
// tabiyu = new TabItem() { Content = aoi2, Tag = "v" };
|
||
//}
|
||
//BCEF机种公共用一个界面
|
||
tabiyu = new TabItem() { Content = aoi2, Tag = "v" };
|
||
|
||
//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);
|
||
}
|
||
|
||
|
||
//VisualB = HVlist[1];
|
||
//VisualC = HVlist[2];
|
||
//VisualD = HVlist[3];
|
||
//VisualE = HVlist[4];
|
||
//VisualF = HVlist[5];
|
||
//VisualG = HVlist[6];
|
||
//VisualH = HVlist[7];
|
||
|
||
}
|
||
|
||
if (SystemPar.MotionControlBool)
|
||
{
|
||
MCVM = new MotionControlVM(CurrentMachine);
|
||
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);
|
||
|
||
ShowShaftState = Visibility.Visible;
|
||
}
|
||
else
|
||
{
|
||
ShowShaftState = Visibility.Collapsed;
|
||
}
|
||
|
||
if (SystemPar.RobotBool)
|
||
{
|
||
switch (SystemPar.RobotBrand)
|
||
{
|
||
case 0:
|
||
Robot = new EpsonRobotVM(CurrentMachine);//初始化爱普生机器人
|
||
break;
|
||
case 1:
|
||
Robot = new FanucRobotVM(CurrentMachine);//初始化发那科机器人
|
||
break;
|
||
case 2:
|
||
Robot = new YamahaRobotVM(CurrentMachine);//雅马哈机器人
|
||
break;
|
||
}
|
||
|
||
|
||
|
||
Robot.eventExcepReport += ExcepStop;
|
||
TabItem tbai = new TabItem() { Content = Robot.MyWindow };
|
||
tbai.SetBinding(TabItem.VisibilityProperty, new Binding("AllVis"));
|
||
//tbai.SetResourceReference(TabItem.HeaderProperty, "机器人"); //设定资源引用 即可进行语言的切换
|
||
tbai.Header = "机器人";
|
||
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 t1 = new TabItem() { Content = new MyChart(), Tag = "v" }; //这里增加了测试机集合 { StationList= this.TestStationList }
|
||
//t1.Header = "生产报表";
|
||
//TabItemList.Add(t1);
|
||
|
||
|
||
|
||
//TabItem t2 = new TabItem() { Content = new LogInformation() };
|
||
//t2.Header = "日志信息";
|
||
//TabItemList.Add(t2);
|
||
|
||
SelectTabItem = TabItemList[0];
|
||
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
#region 实时获取温度
|
||
/// <summary>
|
||
/// 获取温度指令
|
||
/// </summary>
|
||
string GetHeatStr { get; set; } = "00 00 00 00 00 06 01 03 1F 35 00 01";
|
||
/// <summary>
|
||
/// 启动加温
|
||
/// </summary>
|
||
string JiawenOpen { get; set; } = "00 00 00 00 00 06 01 05 1F 40 FF 00";
|
||
/// <summary>
|
||
/// 关闭加温
|
||
/// </summary>
|
||
string JiawenClose { get; set; } = "00 00 00 00 00 06 01 05 1F 41 FF 00";
|
||
|
||
|
||
bool JiawenOpenBl { get; set; }
|
||
bool JiawenCloseBl { get; set; }
|
||
|
||
DateTime SendTime { get; set; }
|
||
/// <summary>
|
||
/// 实时获取温度
|
||
/// </summary>
|
||
/// <param name="CommandStr"></param>
|
||
private void GetHeatRun()
|
||
{
|
||
if (SendTime.AddMilliseconds(100) < DateTime.Now)
|
||
{
|
||
if (Laohuagui.Showmsg.StatusBackground == ColorStr.Green)
|
||
{
|
||
if (JiawenOpenBl)
|
||
{
|
||
Laohuagui.SendInfo(JiawenOpen);
|
||
JiawenOpenBl = false;
|
||
}
|
||
else if (JiawenCloseBl)
|
||
{
|
||
Laohuagui.SendInfo(JiawenClose);
|
||
JiawenCloseBl = false;
|
||
}
|
||
else
|
||
{
|
||
Laohuagui.SendInfo(GetHeatStr);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Laohuagui.ConnectSwitch = !Laohuagui.ConnectSwitch;
|
||
}
|
||
SendTime = DateTime.Now;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 连接检查
|
||
|
||
/// <summary>
|
||
/// 连接检查
|
||
/// </summary>
|
||
private bool ComCheck()
|
||
{
|
||
bool bl = true;
|
||
if (RunningMode)
|
||
{
|
||
RunStatu = RunStatuEnum.Normal;
|
||
return bl;
|
||
}
|
||
|
||
|
||
foreach (var item in ServerComm.CommList)
|
||
{
|
||
if (item.Showmsg.StatusBackground != ColorStr.Green)
|
||
{
|
||
ExcepStop(item.ActionName + "连接失败");
|
||
if (item.ReconnectSwitch)
|
||
{
|
||
item.ConnectSwitch = false;
|
||
item.ConnectSwitch = true;//重新连接
|
||
}
|
||
bl = false;
|
||
|
||
}
|
||
}
|
||
|
||
if (bl)
|
||
{
|
||
RunStatu = RunStatuEnum.Normal;
|
||
}
|
||
|
||
|
||
return bl;
|
||
|
||
}
|
||
#endregion r
|
||
|
||
#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)
|
||
{
|
||
TempTimeSpan = TestTimeSpan;//记录缓存时间
|
||
RunStatu = RunStatuEnum.Exceptional;
|
||
ShowStatu.StatuInfo = showMag;
|
||
|
||
|
||
|
||
|
||
//记录异常信息
|
||
try
|
||
{
|
||
RecordLog(showMag);
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
|
||
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 异常停止
|
||
/// </summary>
|
||
/// <param name="showMag"></param>
|
||
public void ExcepStop(string ErrCode, string showMag)
|
||
{
|
||
if (RunStatu != RunStatuEnum.Stop && RunStatu != RunStatuEnum.EmgStop && RunStatu != RunStatuEnum.Exceptional)
|
||
{
|
||
RunStatu = RunStatuEnum.Exceptional;
|
||
ShowStatu.StatuInfo = showMag;
|
||
//记录异常信息
|
||
try
|
||
{
|
||
RecordLog(showMag);
|
||
|
||
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 异常不停机(无痛报警)
|
||
/// <summary>
|
||
/// 不停机报警中
|
||
/// </summary>
|
||
bool ExcepNoIng { get; set; }
|
||
/// <summary>
|
||
/// 异常不停机(无痛报警)
|
||
/// </summary>
|
||
public void ExcepNoStop(string showMag)
|
||
{
|
||
try
|
||
{
|
||
if (ExcepNoIng)
|
||
{
|
||
return;
|
||
}
|
||
|
||
ShowStatu.StatusBackground = ColorStr.Yellow;
|
||
ShowStatu.StatusForeground = ColorStr.Red;
|
||
|
||
ShowStatu.StatuInfo = showMag;
|
||
|
||
// OutputList[0].Switchs = true; //红灯
|
||
OutputList[1].Switchs = true; //黄灯
|
||
//OutputList[2].Switchs = true; //绿灯
|
||
OutputList[3].Switchs = true; //蜂鸣器
|
||
|
||
|
||
//记录异常信息
|
||
try
|
||
{
|
||
RecordLog(showMag);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.ToString());
|
||
}
|
||
|
||
ExcepNoIng = true;
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 启动按钮 +void Start(object per)
|
||
/// <summary>
|
||
/// 启动按钮
|
||
/// </summary>
|
||
/// <param name="per"></param>
|
||
public void Start(object per)
|
||
{
|
||
|
||
if (RunStatu == RunStatuEnum.Normal)
|
||
{
|
||
return;
|
||
}
|
||
try
|
||
{
|
||
|
||
if (!Testing)
|
||
{
|
||
//所以测试对象重置
|
||
AllGrouhandList.ForEach(w => { w.State.StatusBackground = ColorStr.Blue; w.State.TestCount = 0; w.State.TestCountNG = 0; });
|
||
TestTimeSpan = TimeSpan.Zero;//重置计时
|
||
}
|
||
JiawenOpenBl = true;//开启老化柜加热
|
||
RunStartTime = 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("开始运行");
|
||
}
|
||
|
||
ExcepNoIng = false;
|
||
}
|
||
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)
|
||
{
|
||
TempTimeSpan = TestTimeSpan;//记录缓存时间
|
||
|
||
RunStatu = RunStatuEnum.Stop;
|
||
RecordLog("停止运行");
|
||
JiawenCloseBl = true;//老化柜停止加热
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 重启按钮 +void ResetSoft(object obj)
|
||
/// <summary>
|
||
/// 重启按钮
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void ResetSoft(object obj)
|
||
{
|
||
|
||
if (RunStatu == RunStatuEnum.Normal)
|
||
{
|
||
MyMessageBox.Show("机器运行中,无法重置,要重置请先停止");
|
||
return;
|
||
}
|
||
|
||
|
||
//如果运行线程还在运行
|
||
//if (ThRun != null)
|
||
//{
|
||
// ThRun.Abort();
|
||
// ThRun = null;
|
||
//}
|
||
|
||
MessageBoxResult res = MessageBox.Show("你确定要重新启动软件吗?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Asterisk);
|
||
if (res == MessageBoxResult.Yes)
|
||
{
|
||
ResetALL(); //重置所有参数
|
||
// RecordLog("重新开始");
|
||
ShareHelp.UserLog("重置流程");
|
||
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 重置所有
|
||
/// </summary>
|
||
private void ResetALL()
|
||
{
|
||
Testing = false;
|
||
LogicDispatchFlow = new FlowModel("测试流程");
|
||
JiawenCloseBl = true;//老化柜停止加热
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 紧急停止按钮 +void EmgStop()
|
||
/// <summary>
|
||
/// 紧急停止工作
|
||
/// </summary>
|
||
public void EmgStop()
|
||
{
|
||
if (RunStatu != RunStatuEnum.EmgStop)
|
||
{
|
||
if (ThRun != null) //停止线程
|
||
{
|
||
ThRun.Abort();
|
||
ThRun = null;
|
||
}
|
||
if (MCVM != null)
|
||
{
|
||
foreach (Shaft 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 (CurrentMachine.MyPar.StatusList == null || CurrentMachine.MyPar.StatusList.Count < AllGrouhandList.Count)
|
||
{
|
||
CurrentMachine.MyPar.StatusList = AllGrouhandList.Select(x => x.State).ToList();
|
||
}
|
||
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;
|
||
}
|
||
|
||
|
||
System.Environment.Exit(0);
|
||
}
|
||
#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对象的属性
|
||
|
||
//}
|
||
|
||
if (dp.Name == sp.Name)//判断属性名是否相同
|
||
{
|
||
if (dp.PropertyType.FullName == typeof(Array).FullName)
|
||
{
|
||
dp.SetValue(irpa, ((Array)sp.GetValue(startPoint, null)).Clone(), null);//获得s对象属性的值复制给d对象的属性
|
||
|
||
}
|
||
else
|
||
{
|
||
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对象的属性
|
||
//}
|
||
|
||
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
|
||
|
||
#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)
|
||
{
|
||
try
|
||
{
|
||
info = new RecordInfo() { Number = ExcepList.Count() + 1, HappenTime = DateTime.Now, Describe = showMag };
|
||
//异步新增项 这是微软的BUG 只能这么麻烦了
|
||
MyDispatcher.BeginInvoke(DispatcherPriority.Background, new ParameterizedThreadStart(AddItem), info);
|
||
|
||
path = @"D:\\Log\SystemLog"; //文件夹路径
|
||
|
||
paths = @"D:\\Log\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();
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
}
|
||
|
||
}
|
||
void AddItem(object info)
|
||
{
|
||
ExcepList.Add((RecordInfo)info);
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 文件拷贝
|
||
/// </summary>
|
||
/// <param name="OrignFile">原路径</param>
|
||
/// <param name="NewFile">新路径</param>
|
||
private bool FileCopy(string OrignFile, string NewFile)
|
||
{
|
||
bool bl = false;
|
||
try
|
||
{
|
||
File.Copy(OrignFile, NewFile, true);
|
||
bl = true;
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
}
|
||
|
||
return bl;
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 记录测试结果
|
||
/// </summary>
|
||
/// <param name="CM"></param>
|
||
private void TestResultLog(HandModel hand, List<CommandModel> CM, string ResStr)
|
||
{
|
||
lock (this)
|
||
{
|
||
path = @"D:\\MeasureResultLog\";
|
||
paths = @"D:\\MeasureResultLog\" + DateTime.Now.ToString("D") + ".CSV";
|
||
|
||
//实例化字符串流
|
||
StringBuilder sb = new StringBuilder();
|
||
//创建文件夹
|
||
if (!Directory.Exists(path))
|
||
{
|
||
Directory.CreateDirectory(path);
|
||
|
||
|
||
}
|
||
//创建文件
|
||
if (!File.Exists(paths))
|
||
{
|
||
sb.Append("时间,").Append("治具编号,");
|
||
foreach (var item in CM)
|
||
{
|
||
sb.Append(item.NameStr + ",");
|
||
}
|
||
sb.Append("测试次数,").Append("测试NG次数,").Append("单次结果,").Append("最终结果,\r\n");
|
||
|
||
}
|
||
|
||
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(hand.ShortCode).Append(",");
|
||
foreach (var item in CM)
|
||
{
|
||
sb.Append(item.MyValue.ActualValue).Append(",");
|
||
}
|
||
sb.Append(hand.State.TestCount).Append(",").Append(hand.State.TestCountNG).Append(",").Append(ResStr).Append(",");
|
||
hand.TestData = sb.ToString();
|
||
//将字符串流数据写入文件
|
||
sw.WriteLine(sb);
|
||
//刷新文件流
|
||
sw.Flush();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 记录测试结果
|
||
/// </summary>
|
||
/// <param name="CM"></param>
|
||
private void TestResultLog(List<CommandModel> CM)
|
||
{
|
||
lock (this)
|
||
{
|
||
path = @"D:\\MeasureResultLog\";
|
||
paths = @"D:\\MeasureResultLog\" + DateTime.Now.ToString("D") + ".CSV";
|
||
|
||
//实例化字符串流
|
||
StringBuilder sb = new StringBuilder();
|
||
//创建文件夹
|
||
if (!Directory.Exists(path))
|
||
{
|
||
Directory.CreateDirectory(path);
|
||
|
||
|
||
}
|
||
//创建文件
|
||
if (!File.Exists(paths))
|
||
{
|
||
sb.Append("时间,").Append("治具编号,");
|
||
foreach (var item in CM)
|
||
{
|
||
sb.Append(item.NameStr + ",");
|
||
}
|
||
sb.Append("测试次数,").Append("测试NG次数,").Append("单次结果,").Append("最终结果,\r\n");
|
||
|
||
}
|
||
|
||
using (FileStream fs = new FileStream(paths, FileMode.Append))
|
||
{
|
||
using (StreamWriter sw = new StreamWriter(fs, UnicodeEncoding.GetEncoding("GB2312"))) //UnicodeEncoding.GetEncoding("GB2312")
|
||
{
|
||
foreach (var item in AllGrouhandList)
|
||
{
|
||
sb.Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")).Append(",").Append(item.TestData).Append(",\r\n");
|
||
}
|
||
|
||
//将字符串流数据写入文件
|
||
sw.WriteLine(sb);
|
||
//刷新文件流
|
||
sw.Flush();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 记录SN
|
||
/// <summary>
|
||
/// 记录SN
|
||
/// </summary>
|
||
/// <param name="snlist"></param>
|
||
/// <param name="writeFenjiexian"></param>
|
||
private void SetSnInfo(List<string> snlist, bool writeFenjiexian = false)
|
||
{
|
||
try
|
||
{
|
||
if (!writeFenjiexian)
|
||
{
|
||
if (snlist == null || snlist.Count <= 0)
|
||
{
|
||
return;
|
||
}
|
||
}
|
||
|
||
path = @"D:\\LAGLog\Product"; //文件夹路径
|
||
paths = @"D:\\LAGLog\Product\" + DateTime.Now.ToString("D") + ".txt"; //文件路径
|
||
|
||
//创建文件夹
|
||
if (!Directory.Exists(path))
|
||
{
|
||
Directory.CreateDirectory(path);
|
||
}
|
||
|
||
//打开或创建文件
|
||
FS = File.Open(paths, FileMode.Append);
|
||
if (!writeFenjiexian)
|
||
{
|
||
foreach (var item in snlist)
|
||
{
|
||
string code12 = item.Substring(SystemPar.StartBit, SystemPar.InterceptBits);
|
||
//获得字节数组
|
||
// data = System.Text.Encoding.Default.GetBytes(item + "\r\n");
|
||
data = System.Text.Encoding.Default.GetBytes(code12 + "\r\n");
|
||
//开始写入
|
||
FS.Write(data, 0, data.Length);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
data = System.Text.Encoding.Default.GetBytes("----------------------分界线-----------------------" + "\r\n");
|
||
//开始写入
|
||
FS.Write(data, 0, data.Length);
|
||
}
|
||
//清空缓冲区、关闭流
|
||
FS.Flush();
|
||
FS.Close();
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 导出测试数据
|
||
/// <summary>
|
||
/// 导出测试数据
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void ExportFile()
|
||
{
|
||
if (TList == null || TList.Count <= 0)
|
||
{
|
||
return;
|
||
}
|
||
|
||
|
||
SaveFileDialog sf = new SaveFileDialog();
|
||
sf.Title = "导出测试数据";
|
||
sf.DefaultExt = "txt";
|
||
sf.Filter = "ini files (*.CSV)|*.CSV|All files (*.*)|*.*";
|
||
sf.FilterIndex = 1;
|
||
sf.RestoreDirectory = true;
|
||
if ((bool)sf.ShowDialog())
|
||
{
|
||
//实例化字符串流
|
||
StringBuilder sb = new StringBuilder();
|
||
sb.Append("日期").Append(",").Append("00:00").Append(",").Append("01:00").Append(",").Append("02:00").Append(",").Append("03:00").Append(",").Append("04:00").Append(",").Append("05:00").Append(",").Append("06:00").Append(",").Append("07:00").Append(",").Append("08:00").Append(",").Append("09:00").Append(",").Append("10:00").Append(",").Append("11:00").Append(",").Append("12:00").Append(",").Append("13:00").Append(",").Append("14:00").Append(",").Append("15:00").Append(",").Append("16:00").Append(",").Append("17:00").Append(",").Append("18:00").Append(",").Append("19:00").Append(",").Append("20:00").Append(",").Append("21:00").Append(",").Append("22:00").Append(",").Append("23:00").Append(",\r");
|
||
using (FileStream fs = new FileStream(sf.FileName, FileMode.Append))
|
||
{
|
||
using (StreamWriter sw = new StreamWriter(fs, UnicodeEncoding.GetEncoding("GB2312")))
|
||
{
|
||
foreach (var item in TList)
|
||
{
|
||
|
||
//将数据添加进字符串流中(如果数据标题有变更,修改此处)
|
||
sb.Append(item.ProduceTate.ToShortDateString()).Append(",").Append(item.Phase1).Append(",").Append(item.Phase2).Append(",").Append(item.Phase3).Append(",").Append(item.Phase4).Append(",").Append(item.Phase5).Append(",").Append(item.Phase6).Append(",").Append(item.Phase7).Append(",").Append(item.Phase8).Append(",").Append(item.Phase9).Append(",").Append(item.Phase10).Append(",").Append(item.Phase11).Append(",").Append(item.Phase12).Append(",").Append(item.Phase13).Append(",").Append(item.Phase14).Append(",").Append(item.Phase15).Append(",").Append(item.Phase16).Append(",").Append(item.Phase17).Append(",").Append(item.Phase18).Append(",").Append(item.Phase19).Append(",").Append(item.Phase20).Append(",").Append(item.Phase21).Append(",").Append(item.Phase22).Append(",").Append(item.Phase23).Append(",").Append(item.Phase24).Append(",\r");
|
||
|
||
|
||
}
|
||
//将字符串流数据写入文件
|
||
sw.WriteLine(sb);
|
||
//刷新文件流
|
||
sw.Flush();
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
#endregion
|
||
|
||
#region 第一组数据
|
||
private List<HandModel> groupHand1;
|
||
/// <summary>
|
||
/// 第一组
|
||
/// </summary>
|
||
public List<HandModel> GroupHand1
|
||
{
|
||
get { return groupHand1; }
|
||
set
|
||
{
|
||
groupHand1 = value;
|
||
RaisePropertyChanged("GroupHand1");
|
||
}
|
||
}
|
||
|
||
private Grid groupGrid1;
|
||
/// <summary>
|
||
/// 第一组Grid
|
||
/// </summary>
|
||
public Grid GroupGrid1
|
||
{
|
||
get { return groupGrid1; }
|
||
set
|
||
{
|
||
groupGrid1 = value;
|
||
RaisePropertyChanged("GroupGrid1");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 第二组数据
|
||
private List<HandModel> groupHand2;
|
||
/// <summary>
|
||
/// 第二组
|
||
/// </summary>
|
||
public List<HandModel> GroupHand2
|
||
{
|
||
get { return groupHand2; }
|
||
set
|
||
{
|
||
groupHand2 = value;
|
||
RaisePropertyChanged("GroupHand2");
|
||
}
|
||
}
|
||
|
||
private Grid groupGrid2;
|
||
/// <summary>
|
||
/// 第二组Grid
|
||
/// </summary>
|
||
public Grid GroupGrid2
|
||
{
|
||
get { return groupGrid2; }
|
||
set
|
||
{
|
||
groupGrid2 = value;
|
||
RaisePropertyChanged("GroupGrid2");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 第三组数据
|
||
private List<HandModel> groupHand3;
|
||
/// <summary>
|
||
/// 第三组
|
||
/// </summary>
|
||
public List<HandModel> GroupHand3
|
||
{
|
||
get { return groupHand3; }
|
||
set
|
||
{
|
||
groupHand3 = value;
|
||
RaisePropertyChanged("GroupHand3");
|
||
}
|
||
}
|
||
|
||
private Grid groupGrid3;
|
||
/// <summary>
|
||
/// 第三组Grid
|
||
/// </summary>
|
||
public Grid GroupGrid3
|
||
{
|
||
get { return groupGrid3; }
|
||
set
|
||
{
|
||
groupGrid3 = value;
|
||
RaisePropertyChanged("GroupGrid3");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 第四组数据
|
||
private List<HandModel> groupHand4;
|
||
/// <summary>
|
||
/// 第四组
|
||
/// </summary>
|
||
public List<HandModel> GroupHand4
|
||
{
|
||
get { return groupHand4; }
|
||
set
|
||
{
|
||
groupHand4 = value;
|
||
RaisePropertyChanged("GroupHand4");
|
||
}
|
||
}
|
||
|
||
private Grid groupGrid4;
|
||
/// <summary>
|
||
/// 第四组Grid
|
||
/// </summary>
|
||
public Grid GroupGrid4
|
||
{
|
||
get { return groupGrid4; }
|
||
set
|
||
{
|
||
groupGrid4 = value;
|
||
RaisePropertyChanged("GroupGrid4");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 第五组数据
|
||
private List<HandModel> groupHand5;
|
||
/// <summary>
|
||
/// 第五组
|
||
/// </summary>
|
||
public List<HandModel> GroupHand5
|
||
{
|
||
get { return groupHand5; }
|
||
set
|
||
{
|
||
groupHand5 = value;
|
||
RaisePropertyChanged("GroupHand5");
|
||
}
|
||
}
|
||
|
||
private Grid groupGrid5;
|
||
/// <summary>
|
||
/// 第五组Grid
|
||
/// </summary>
|
||
public Grid GroupGrid5
|
||
{
|
||
get { return groupGrid5; }
|
||
set
|
||
{
|
||
groupGrid5 = value;
|
||
RaisePropertyChanged("GroupGrid5");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 所有测是对象集合
|
||
/// </summary>
|
||
List<HandModel> AllGrouhandList { get; set; }
|
||
|
||
|
||
#region 各状态初始化
|
||
/// <summary>
|
||
/// 平台状态初始化
|
||
/// </summary>
|
||
private void PlatFormInitialize()
|
||
{
|
||
#region 第一组
|
||
GroupGrid1 = new Grid();
|
||
GroupHand1 = new List<HandModel>();
|
||
GetGrid(GroupGrid1, GroupHand1, 20, 3);
|
||
#endregion
|
||
|
||
#region 第二组
|
||
GroupGrid2 = new Grid();
|
||
GroupHand2 = new List<HandModel>();
|
||
GetGrid(GroupGrid2, GroupHand2, 20, 3);
|
||
#endregion
|
||
|
||
#region 第三组
|
||
GroupGrid3 = new Grid();
|
||
GroupHand3 = new List<HandModel>();
|
||
GetGrid(GroupGrid3, GroupHand3, 20, 3);
|
||
#endregion
|
||
|
||
#region 第四组
|
||
GroupGrid4 = new Grid();
|
||
GroupHand4 = new List<HandModel>();
|
||
GetGrid(GroupGrid4, GroupHand4, 20, 3);
|
||
#endregion
|
||
|
||
#region 第五组
|
||
GroupGrid5 = new Grid();
|
||
GroupHand5 = new List<HandModel>();
|
||
GetGrid(GroupGrid5, GroupHand5, 20, 3);
|
||
#endregion
|
||
|
||
//把5组数据统一方到一个集合中
|
||
AllGrouhandList = new List<HandModel>();
|
||
AllGrouhandList.AddRange(GroupHand1);
|
||
AllGrouhandList.AddRange(GroupHand2);
|
||
AllGrouhandList.AddRange(GroupHand3);
|
||
AllGrouhandList.AddRange(GroupHand4);
|
||
AllGrouhandList.AddRange(GroupHand5);
|
||
}
|
||
#endregion
|
||
|
||
#region 生成Grid状态
|
||
int Xuhao = 0;
|
||
int PLCNumber = 0;
|
||
/// <summary>
|
||
/// 生成Grid状态
|
||
/// </summary>
|
||
/// <param name="gd"></param>
|
||
/// <param name="list"></param>
|
||
/// <param name="col"></param>
|
||
/// <param name="row"></param>
|
||
public void GetGrid(Grid gd, List<HandModel> list, int col = 1, int row = 1)
|
||
{
|
||
for (int i = 0; i < row; i++)
|
||
{
|
||
gd.RowDefinitions.Add(new RowDefinition()); //添加列
|
||
}
|
||
for (int i = 0; i < col; i++)
|
||
{
|
||
gd.ColumnDefinitions.Add(new ColumnDefinition()); //添加列
|
||
}
|
||
Xuhao++;
|
||
int number = 0;
|
||
for (int j = 0; j < row; j++)
|
||
{
|
||
for (int i = 0; i < col; i++)
|
||
{
|
||
number++;
|
||
PLCNumber++;
|
||
HandModel sm = new HandModel() { Number = PLCNumber, State = new ShowInfo() { StatuInfo = Xuhao + "-" + number }, ShortCode = Xuhao + "_" + number };
|
||
gd.Children.Add(sm.Box);
|
||
sm.Box.SetValue(Grid.RowProperty, j); //设置按钮所在Grid控件的行
|
||
sm.Box.SetValue(Grid.ColumnProperty, i); //设置按钮所在Grid控件的列
|
||
list.Add(sm);
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
|
||
}
|