|
|
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 ControlCAManualViewModule : ViewModelBase
|
|
|
{
|
|
|
#region base parameters
|
|
|
private int rows = 20;
|
|
|
private int pagenumber = 1;
|
|
|
public ControlCAManualView View { get; set; }
|
|
|
private bool IsConfirm;
|
|
|
private bool isLoading;
|
|
|
private System.Timers.Timer timer;
|
|
|
private CancellationTokenSource cancellationTokenSource;
|
|
|
private DateTime dtStart;
|
|
|
private CAFlowExecuter CAFlowExecuter;
|
|
|
#endregion
|
|
|
|
|
|
#region constructor
|
|
|
public ControlCAManualViewModule()
|
|
|
{
|
|
|
View = new ControlCAManualView();
|
|
|
View.DataContext = this;
|
|
|
CAFlowExecuter = new CAFlowExecuter();
|
|
|
InitializeCommands();
|
|
|
InitializeParameters();
|
|
|
}
|
|
|
|
|
|
private void InitializeCommands()
|
|
|
{
|
|
|
AttractCommand = new DelegateCommand(OnAttractCommand);
|
|
|
CenterIOCommand = new DelegateCommand(OnCenterIOCommand);
|
|
|
MainAxisIOCommand = new DelegateCommand(OnMainAxisIOCommand);
|
|
|
PrepareCommand = new DelegateCommand(OnPrepareCommand);
|
|
|
TerminateCommand = new DelegateCommand(OnTerminateCommand);
|
|
|
}
|
|
|
|
|
|
public override void InitializeParameters(object content = null)
|
|
|
{
|
|
|
IsConfirm = false;
|
|
|
WindowTitle = "";
|
|
|
ProgressEnabled = true;
|
|
|
//*
|
|
|
if (timer == null)
|
|
|
{
|
|
|
timer = new System.Timers.Timer();
|
|
|
timer.Interval = 300;
|
|
|
timer.Elapsed += timer_Elapsed;
|
|
|
timer.Start();
|
|
|
}//*/
|
|
|
}
|
|
|
|
|
|
~ControlCAManualViewModule()
|
|
|
{
|
|
|
}
|
|
|
public void LoadDefaultValue()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
#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 ushort _CenterIOStatus;
|
|
|
public ushort CenterIOStatus
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _CenterIOStatus;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_CenterIOStatus = value;
|
|
|
OnPropertyChanged("CenterIOStatus");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private ushort _AttractIOStatus;
|
|
|
public ushort AttractIOStatus
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _AttractIOStatus;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_AttractIOStatus = value;
|
|
|
OnPropertyChanged("AttractIOStatus");
|
|
|
}
|
|
|
}
|
|
|
private ushort _AttractStatus;
|
|
|
public ushort AttractStatus
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _AttractStatus;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_AttractStatus = value;
|
|
|
OnPropertyChanged("AttractStatus");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private ushort _MainAxisIOStatus;
|
|
|
public ushort MainAxisIOStatus
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _MainAxisIOStatus;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_MainAxisIOStatus = value;
|
|
|
OnPropertyChanged("MainAxisIOStatus");
|
|
|
}
|
|
|
}
|
|
|
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 bool _ProgressEnabled;
|
|
|
public bool ProgressEnabled
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _ProgressEnabled;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_ProgressEnabled = value;
|
|
|
OnPropertyChanged("ProgressEnabled");
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region Binding Commands
|
|
|
private ICommand _CenterIOCommand;
|
|
|
public ICommand CenterIOCommand
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _CenterIOCommand;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_CenterIOCommand = value;
|
|
|
OnPropertyChanged("CenterIOCommand");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private ICommand _AttractCommand;
|
|
|
public ICommand AttractCommand
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _AttractCommand;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_AttractCommand = value;
|
|
|
OnPropertyChanged("AttractCommand");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private ICommand _MainAxisIOCommand;
|
|
|
public ICommand MainAxisIOCommand
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _MainAxisIOCommand;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_MainAxisIOCommand = value;
|
|
|
OnPropertyChanged("MainAxisIOCommand");
|
|
|
}
|
|
|
}
|
|
|
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");
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region Private Methods
|
|
|
private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
//<2F><>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD>
|
|
|
private void OnAttractCommand(Object sender)
|
|
|
{
|
|
|
if (StationLockControl.StationIsLock(StationCode))
|
|
|
{
|
|
|
ShowMessageBox(HintMessage.StationLocked);
|
|
|
return;
|
|
|
}
|
|
|
var flow = HardParameters.GetCAAttractIO(StationCode);
|
|
|
if (flow != null)
|
|
|
{
|
|
|
AttractIOStatus = (ushort)(AttractIOStatus != 1 ? 1 : 0);
|
|
|
ControlCheck.PMCInvoke(false, "SetPortStatus", null, () => DeviceControl.SetPortStatus(flow.NodeId, flow.SlotId, flow.BitNum, AttractIOStatus));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void OnCenterIOCommand(Object sender)
|
|
|
{
|
|
|
if (StationLockControl.StationIsLock(StationCode))
|
|
|
{
|
|
|
ShowMessageBox(HintMessage.StationLocked);
|
|
|
return;
|
|
|
}
|
|
|
var flow = HardParameters.GetCACenterIO(StationCode);
|
|
|
if (flow != null)
|
|
|
{
|
|
|
CenterIOStatus = (ushort)(CenterIOStatus != 1 ? 1 : 0);
|
|
|
ControlCheck.PMCInvoke(false, "SetPortStatus", null, () => DeviceControl.SetPortStatus(flow.NodeId, flow.SlotId, flow.BitNum, CenterIOStatus));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void OnMainAxisIOCommand(Object sender)
|
|
|
{
|
|
|
if (StationLockControl.StationIsLock(StationCode))
|
|
|
{
|
|
|
ShowMessageBox(HintMessage.StationLocked);
|
|
|
return;
|
|
|
}
|
|
|
var action = HardParameters.GetCAMainAxisIO(StationCode);
|
|
|
if (action != null)
|
|
|
{
|
|
|
MainAxisIOStatus = (ushort)(MainAxisIOStatus != 1 ? 1 : 0);
|
|
|
ControlCheck.PMCInvoke(false, "SetPortStatus", null, () => DeviceControl.SetPortStatus(action.NodeId, action.SlotId, action.BitNum, MainAxisIOStatus));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void OnPrepareCommand(Object sender)
|
|
|
{
|
|
|
if (StationLockControl.StationIsLock(StationCode))
|
|
|
{
|
|
|
ShowMessageBox(HintMessage.StationLocked);
|
|
|
return;
|
|
|
}
|
|
|
StationLockControl.LockStation(StationCode, null);
|
|
|
ProgressEnabled = false;
|
|
|
//<2F><><EFBFBD>ò<EFBFBD><C3B2><EFBFBD>
|
|
|
CenterIOStatus = 0;
|
|
|
MainAxisIOStatus = 0;
|
|
|
AttractIOStatus = 0;
|
|
|
List<HardFormulaFlowEntity> flows = Global.Flows.FindAll(q => q.StationCode == StationCode && q.IsPrepare);
|
|
|
cancellationTokenSource = new CancellationTokenSource();
|
|
|
Task flowTask = new Task(() =>
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
Global.ClearErrorState(StationCode);
|
|
|
CAFlowExecuter.Execute(cancellationTokenSource, flows, null, true, false);
|
|
|
ProgressEnabled = true;
|
|
|
StationLockControl.UnLockStation(StationCode);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
//StepMessage = string.Format(" ִ<><D6B4><EFBFBD>쳣:{0}!", ex.Message);
|
|
|
ProgressEnabled = true;
|
|
|
StationLockControl.UnLockStation(StationCode);
|
|
|
}
|
|
|
}, cancellationTokenSource.Token, TaskCreationOptions.LongRunning);
|
|
|
flowTask.Start();
|
|
|
}
|
|
|
|
|
|
private void OnTerminateCommand(Object sender)
|
|
|
{
|
|
|
if (cancellationTokenSource != null)
|
|
|
{
|
|
|
cancellationTokenSource.Cancel();
|
|
|
ProgressEnabled = true;
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
}
|