You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
516 lines
14 KiB
516 lines
14 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Windows;
|
|
using System.Windows.Forms;
|
|
using System.Windows.Input;
|
|
using GummingCommon;
|
|
using GummingEntity;
|
|
using GummingSupport;
|
|
using GummingControl;
|
|
using System.Text;
|
|
using GummingBusiness;
|
|
using Newtonsoft.Json;
|
|
using GummingLine;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Gumming
|
|
{
|
|
public class ControlCPManualViewModule : ViewModelBase
|
|
{
|
|
#region base parameters
|
|
private int rows = 20;
|
|
private int pagenumber = 1;
|
|
public ControlCPManualView View { get; set; }
|
|
private bool IsConfirm;
|
|
private bool isLoading;
|
|
private System.Timers.Timer timer;
|
|
private HardDTMEntity dtm;
|
|
private DateTime dtStart;
|
|
#endregion
|
|
|
|
#region constructor
|
|
public ControlCPManualViewModule()
|
|
{
|
|
View = new ControlCPManualView();
|
|
View.DataContext = this;
|
|
|
|
InitializeCommands();
|
|
InitializeParameters();
|
|
}
|
|
|
|
private void InitializeCommands()
|
|
{
|
|
AttractCommand = new DelegateCommand(OnAttractCommand);
|
|
DMTSetCommand = new DelegateCommand(OnDMTSetCommand);
|
|
PrepareCommand = new DelegateCommand(OnPrepareCommand);
|
|
TerminateCommand = new DelegateCommand(OnTerminateCommand);
|
|
DingZhenCommand = new DelegateCommand(OnDingZhenCommand);
|
|
}
|
|
|
|
public override void InitializeParameters(object content = null)
|
|
{
|
|
IsConfirm = false;
|
|
WindowTitle = "";
|
|
|
|
//*
|
|
if (timer == null)
|
|
{
|
|
timer = new System.Timers.Timer();
|
|
timer.Interval = 300;
|
|
timer.Elapsed += timer_Elapsed;
|
|
timer.Start();
|
|
}//*/
|
|
}
|
|
|
|
~ControlCPManualViewModule()
|
|
{
|
|
}
|
|
public void LoadDefaultValue()
|
|
{
|
|
var baseTemp = Global.Settings.FirstOrDefault(q => q.RecId == "SYS_CoolTemperature");
|
|
var baseOffset = Global.Settings.FirstOrDefault(q => q.RecId == "SYS_CoolTemperatureOffset");
|
|
|
|
CPSV = baseTemp.SettingValue;
|
|
CPAlmOffset = baseOffset.SettingValue;
|
|
}
|
|
#endregion
|
|
|
|
#region Binding Properties
|
|
public string WindowTitle { get; private set; }
|
|
|
|
|
|
private string _ControlName;
|
|
public string ControlName
|
|
{
|
|
get
|
|
{
|
|
return _ControlName;
|
|
}
|
|
set
|
|
{
|
|
_ControlName = value;
|
|
OnPropertyChanged("ControlName");
|
|
}
|
|
}
|
|
private string _StationCode;
|
|
public string StationCode
|
|
{
|
|
get
|
|
{
|
|
return _StationCode;
|
|
}
|
|
set
|
|
{
|
|
_StationCode = value;
|
|
OnPropertyChanged("StationCode");
|
|
}
|
|
}
|
|
|
|
private decimal _CPSV;
|
|
public decimal CPSV
|
|
{
|
|
get
|
|
{
|
|
return _CPSV;
|
|
}
|
|
set
|
|
{
|
|
_CPSV = value;
|
|
OnPropertyChanged("CPSV");
|
|
}
|
|
}
|
|
|
|
private decimal _CPAlmOffset;
|
|
public decimal CPAlmOffset
|
|
{
|
|
get
|
|
{
|
|
return _CPAlmOffset;
|
|
}
|
|
set
|
|
{
|
|
_CPAlmOffset = value;
|
|
OnPropertyChanged("CPAlmOffset");
|
|
}
|
|
}
|
|
|
|
private decimal _CPOffset;
|
|
public decimal CPOffset
|
|
{
|
|
get
|
|
{
|
|
return _CPOffset;
|
|
}
|
|
set
|
|
{
|
|
_CPOffset = value;
|
|
OnPropertyChanged("CPOffset");
|
|
}
|
|
}
|
|
|
|
private ObservableCollection<HardFormulaEntity> _HardFormulas;
|
|
public ObservableCollection<HardFormulaEntity> HardFormulas
|
|
{
|
|
get
|
|
{
|
|
return _HardFormulas;
|
|
}
|
|
set
|
|
{
|
|
_HardFormulas = value;
|
|
OnPropertyChanged("HardFormulas");
|
|
}
|
|
}
|
|
|
|
private HardFormulaEntity _SelectedFormula;
|
|
public HardFormulaEntity SelectedFormula
|
|
{
|
|
get
|
|
{
|
|
return _SelectedFormula;
|
|
}
|
|
set
|
|
{
|
|
_SelectedFormula = value;
|
|
OnPropertyChanged("SelectedFormula");
|
|
}
|
|
}
|
|
private ushort _DMTSetStatus;
|
|
public ushort DMTSetStatus
|
|
{
|
|
get
|
|
{
|
|
return _DMTSetStatus;
|
|
}
|
|
set
|
|
{
|
|
_DMTSetStatus = value;
|
|
OnPropertyChanged("DMTSetStatus");
|
|
}
|
|
}
|
|
|
|
private ushort _MainAxisTopStatus;
|
|
public ushort MainAxisTopStatus
|
|
{
|
|
get
|
|
{
|
|
return _MainAxisTopStatus;
|
|
}
|
|
set
|
|
{
|
|
_MainAxisTopStatus = value;
|
|
OnPropertyChanged("MainAxisTopStatus");
|
|
}
|
|
}
|
|
|
|
private ushort _AttractIOStatus;
|
|
public ushort AttractIOStatus
|
|
{
|
|
get
|
|
{
|
|
return _AttractIOStatus;
|
|
}
|
|
set
|
|
{
|
|
_AttractIOStatus = value;
|
|
OnPropertyChanged("AttractIOStatus");
|
|
}
|
|
}
|
|
|
|
private ushort _PrepareStatus;
|
|
public ushort PrepareStatus
|
|
{
|
|
get
|
|
{
|
|
return _PrepareStatus;
|
|
}
|
|
set
|
|
{
|
|
_PrepareStatus = value;
|
|
OnPropertyChanged("PrepareStatus");
|
|
}
|
|
}
|
|
private ushort _TerminateStatus;
|
|
public ushort TerminateStatus
|
|
{
|
|
get
|
|
{
|
|
return _TerminateStatus;
|
|
}
|
|
set
|
|
{
|
|
_TerminateStatus = value;
|
|
OnPropertyChanged("TerminateStatus");
|
|
}
|
|
}
|
|
private ushort _MainAxisBackStatus;
|
|
public ushort MainAxisBackStatus
|
|
{
|
|
get
|
|
{
|
|
return _MainAxisBackStatus;
|
|
}
|
|
set
|
|
{
|
|
_MainAxisBackStatus = value;
|
|
OnPropertyChanged("MainAxisBackStatus");
|
|
}
|
|
}
|
|
private bool _ProgressEnabled;
|
|
public bool ProgressEnabled
|
|
{
|
|
get
|
|
{
|
|
return _ProgressEnabled;
|
|
}
|
|
set
|
|
{
|
|
_ProgressEnabled = value;
|
|
OnPropertyChanged("ProgressEnabled");
|
|
}
|
|
}
|
|
private int _ProgressTime;
|
|
public int ProgressTime
|
|
{
|
|
get
|
|
{
|
|
return _ProgressTime;
|
|
}
|
|
set
|
|
{
|
|
_ProgressTime = value;
|
|
OnPropertyChanged("ProgressTime");
|
|
}
|
|
}
|
|
private ushort _DingZhenStatus;
|
|
public ushort DingZhenStatus
|
|
{
|
|
get
|
|
{
|
|
return _DingZhenStatus;
|
|
}
|
|
set
|
|
{
|
|
_DingZhenStatus = value;
|
|
OnPropertyChanged("DingZhenStatus");
|
|
}
|
|
}
|
|
private double _RealTemprature;
|
|
public double RealTemprature
|
|
{
|
|
get
|
|
{
|
|
return _RealTemprature;
|
|
}
|
|
set
|
|
{
|
|
_RealTemprature = value;
|
|
OnPropertyChanged("RealTemprature");
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Binding Commands
|
|
private ICommand _AttractCommand;
|
|
public ICommand AttractCommand
|
|
{
|
|
get
|
|
{
|
|
return _AttractCommand;
|
|
}
|
|
set
|
|
{
|
|
_AttractCommand = value;
|
|
OnPropertyChanged("AttractCommand");
|
|
}
|
|
}
|
|
|
|
private ICommand _PrepareCommand;
|
|
public ICommand PrepareCommand
|
|
{
|
|
get
|
|
{
|
|
return _PrepareCommand;
|
|
}
|
|
set
|
|
{
|
|
_PrepareCommand = value;
|
|
OnPropertyChanged("PrepareCommand");
|
|
}
|
|
}
|
|
private ICommand _TerminateCommand;
|
|
public ICommand TerminateCommand
|
|
{
|
|
get
|
|
{
|
|
return _TerminateCommand;
|
|
}
|
|
set
|
|
{
|
|
_TerminateCommand = value;
|
|
OnPropertyChanged("TerminateCommand");
|
|
}
|
|
}
|
|
private ICommand _DMTSetCommand;
|
|
public ICommand DMTSetCommand
|
|
{
|
|
get
|
|
{
|
|
return _DMTSetCommand;
|
|
}
|
|
set
|
|
{
|
|
_DMTSetCommand = value;
|
|
OnPropertyChanged("DMTSetCommand");
|
|
}
|
|
}
|
|
private ICommand _DingZhenCommand;
|
|
public ICommand DingZhenCommand
|
|
{
|
|
get
|
|
{
|
|
return _DingZhenCommand;
|
|
}
|
|
set
|
|
{
|
|
_DingZhenCommand = value;
|
|
OnPropertyChanged("DingZhenCommand");
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Private Methods
|
|
private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
|
{
|
|
if (this.IsActiveChildPage && !Helpering.IsTerminate)
|
|
{
|
|
RealTemprature = Global.CurrentCPTemprature;
|
|
}
|
|
}
|
|
private void RefreshIOStatus()
|
|
{
|
|
//状态位刷新
|
|
DingZhenStatus = Global.GetInPortStatus(StationCode, "DingZhen");
|
|
AttractIOStatus = Global.GetInPortStatus(StationCode, "Attract");//*/
|
|
}
|
|
//吸片真空
|
|
private void OnAttractCommand(Object sender)
|
|
{
|
|
if (StationLockControl.StationIsLock(StationCode))
|
|
{
|
|
ShowMessageBox(HintMessage.StationLocked);
|
|
return;
|
|
}
|
|
var flow = HardParameters.GetCPAttractIO(StationCode);
|
|
if (flow != null)
|
|
{
|
|
AttractIOStatus = (ushort)(AttractIOStatus != 1 ? 1 : 0);
|
|
ControlCheck.PMCInvoke(false, "SetPortStatus", null, () => DeviceControl.SetPortStatus(flow.NodeId, flow.SlotId, flow.BitNum, AttractIOStatus));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 自整定,内容可设定为 0:停止、1:执行
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
private void OnDMTSetCommand(Object sender)
|
|
{
|
|
if (StationLockControl.StationIsLock(StationCode))
|
|
{
|
|
ShowMessageBox(HintMessage.StationLocked);
|
|
return;
|
|
}
|
|
RS485.SetTemprature((double)CPSV);
|
|
SysSettingEntity sse = Global.Settings.FirstOrDefault(q=>q.RecId == "SYS_CoolTemperature");
|
|
if (sse != null)
|
|
{
|
|
sse.SettingValue = CPSV;
|
|
SysSettingDA.Update(sse);
|
|
}
|
|
}
|
|
public void OnCPSVTextChangedCommand(string value)
|
|
{
|
|
CPSV = Common.ToDecimal(value);
|
|
}
|
|
public void OnCPAlmOffsetTextChangedCommand(string value)
|
|
{
|
|
CPAlmOffset= Common.ToDecimal(value);
|
|
}
|
|
|
|
private void OnPrepareCommand(Object sender)
|
|
{
|
|
if (StationLockControl.StationIsLock(StationCode))
|
|
{
|
|
ShowMessageBox(HintMessage.StationLocked);
|
|
return;
|
|
}
|
|
Global.ClearErrorState(StationCode);
|
|
var flow = HardParameters.GetCPDingZhen(StationCode);
|
|
if (flow != null)
|
|
{
|
|
DingZhenStatus = 0;
|
|
ControlCheck.PMCInvoke(false, "SetPortStatus", null, () => DeviceControl.SetPortStatus(flow.NodeId, flow.SlotId, flow.BitNum, DingZhenStatus));
|
|
}
|
|
|
|
if (StationLockControl.IsDoing(StationCode))
|
|
{
|
|
ShowMessageBox("该工位正在加工,不能进行初始化");
|
|
return;
|
|
}
|
|
CPFlowExecuter CPFlowExecuter = new CPFlowExecuter();
|
|
StationLockControl.LockStation(StationCode, null);
|
|
ProgressEnabled = false;
|
|
List<HardFormulaFlowEntity> flows = Global.Flows.FindAll(q => q.StationCode == StationCode && q.IsPrepare);
|
|
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
|
|
Task flowTask = new Task(() =>
|
|
{
|
|
try
|
|
{
|
|
Global.ClearErrorState(StationCode);
|
|
CPFlowExecuter.Execute(cancellationTokenSource, flows, null, true, false);
|
|
//RefreshIOStatus();
|
|
ProgressEnabled = true;
|
|
StationLockControl.UnLockStation(StationCode);
|
|
LoadDefaultValue();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ProgressEnabled = true;
|
|
StationLockControl.UnLockStation(StationCode);
|
|
}
|
|
}, cancellationTokenSource.Token, TaskCreationOptions.LongRunning);
|
|
flowTask.Start();
|
|
}
|
|
|
|
private void OnTerminateCommand(Object sender)
|
|
{
|
|
var flow = HardParameters.GetCPDingZhen(StationCode);
|
|
if (flow != null)
|
|
{
|
|
DingZhenStatus = 0;
|
|
ControlCheck.PMCInvoke(false, "SetPortStatus", null, () => DeviceControl.SetPortStatus(flow.NodeId, flow.SlotId, flow.BitNum, DingZhenStatus));
|
|
}
|
|
}
|
|
|
|
private void OnDingZhenCommand(Object sender)
|
|
{
|
|
if (StationLockControl.StationIsLock(StationCode))
|
|
{
|
|
ShowMessageBox(HintMessage.StationLocked);
|
|
return;
|
|
}
|
|
var flow = HardParameters.GetCPDingZhen(StationCode);
|
|
if (flow != null)
|
|
{
|
|
DingZhenStatus = (ushort)(DingZhenStatus != 1 ? 1 : 0);
|
|
ControlCheck.PMCInvoke(false, "SetPortStatus", null, () => DeviceControl.SetPortStatus(flow.NodeId, flow.SlotId, flow.BitNum, DingZhenStatus));
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|