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.
4C/Gumming/Modules/Control/Manual/ControlCOTManualViewModule.cs

1261 lines
38 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 ControlCOTManualViewModule : ViewModelBase
{
#region base parameters
private int rows = 20;
private int pagenumber = 1;
public ControlCOTManualView View { get; set; }
private bool IsConfirm;
private bool isLoading;
private System.Timers.Timer timer;
private CancellationTokenSource cancellationTokenSource;
private COTPrepareExecuter COTFlowExecuter;
private bool Homing = false;
#endregion
#region constructor
public ControlCOTManualViewModule()
{
View = new ControlCOTManualView();
View.DataContext = this;
ProgressEnabled = true;
COTFlowExecuter = new COTPrepareExecuter();
InitializeCommands();
InitializeParameters();
}
private void InitializeCommands()
{
CCRCommand = new DelegateCommand(OnCCRCommand);
PR2Command = new DelegateCommand(OnPR2Command);
PR1Command = new DelegateCommand(OnPR1Command);
EBRIOCommand = new DelegateCommand(OnEBRIOCommand);
BSRIOCommand = new DelegateCommand(OnBSRIOCommand);
AttractCommand = new DelegateCommand(OnAttractCommand);
EbrArmIOCommand = new DelegateCommand(OnEbrArmIOCommand);
MainAxisIOCommand = new DelegateCommand(OnMainAxisIOCommand);
PrArmIOCommand = new DelegateCommand(OnPrArmIOCommand);
EbrArmCommand = new DelegateCommand(OnEbrArmCommand);
PrArmCommand = new DelegateCommand(OnPrArmCommand);
HOMECommand = new DelegateCommand(OnHOMECommand);
//RUNCommand = new DelegateCommand(OnRUNCommand);
SVONCommand = new DelegateCommand(OnSVONCommand);
WindowCommand = new DelegateCommand(OnWindowCommand);
PrepareCommand = new DelegateCommand(OnPrepareCommand);
TerminateCommand = new DelegateCommand(OnTerminateCommand);
PR1YeIOCommand = new DelegateCommand(OnPR1YeIOCommand);
PR2YeIOCommand = new DelegateCommand(OnPR2YeIOCommand);
}
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();
}//*/
}
~ControlCOTManualViewModule()
{
}
public void LoadDefaultValue()
{
AxisSpeed = Common.ToInt(HardParameters.Read(StationCode + Constant.COTMainAxisSpeed));
AxisAcc = Common.ToDouble(HardParameters.Read(StationCode + Constant.COTMainAxisAcc));
AxisDec = Common.ToDouble(HardParameters.Read(StationCode + Constant.COTMainAxisDec));
}
#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 string _MainAxisALM;
public string MainAxisALM
{
get
{
return _MainAxisALM;
}
set
{
_MainAxisALM = value;
OnPropertyChanged("MainAxisALM");
}
}
private double _MainAxisRPM;
public double MainAxisRPM
{
get
{
return _MainAxisRPM;
}
set
{
_MainAxisRPM = value;
OnPropertyChanged("MainAxisRPM");
}
}
private int _AxisSpeed;
public int AxisSpeed
{
get
{
return _AxisSpeed;
}
set
{
_AxisSpeed = value;
OnPropertyChanged("AxisSpeed");
}
}
private double _AxisAcc;
public double AxisAcc
{
get
{
return _AxisAcc;
}
set
{
_AxisAcc = value;
OnPropertyChanged("AxisAcc");
}
}
private double _AxisDec;
public double AxisDec
{
get
{
return _AxisDec;
}
set
{
_AxisDec = value;
OnPropertyChanged("AxisDec");
}
}
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 _SVONStatus;
public ushort SVONStatus
{
get
{
return _SVONStatus;
}
set
{
_SVONStatus = value;
OnPropertyChanged("SVONStatus");
}
}
private ushort _RUNStatus;
public ushort RUNStatus
{
get
{
return _RUNStatus;
}
set
{
_RUNStatus = value;
OnPropertyChanged("RUNStatus");
}
}
private ushort _HOMEStatus;
public ushort HOMEStatus
{
get
{
return _HOMEStatus;
}
set
{
_HOMEStatus = value;
OnPropertyChanged("HOMEStatus");
}
}
private ushort _MainAxisIOStatus;
public ushort MainAxisIOStatus
{
get
{
return _MainAxisIOStatus;
}
set
{
_MainAxisIOStatus = value;
OnPropertyChanged("MainAxisIOStatus");
}
}
private ushort _MainAxisIOStatus2;
public ushort MainAxisIOStatus2
{
get
{
return _MainAxisIOStatus2;
}
set
{
_MainAxisIOStatus2 = value;
OnPropertyChanged("MainAxisIOStatus2");
}
}
private ushort _PrArmIOStatus;
public ushort PrArmIOStatus
{
get
{
return _PrArmIOStatus;
}
set
{
_PrArmIOStatus = value;
OnPropertyChanged("PrArmIOStatus");
}
}
private ushort _EbrArmIOStatus;
public ushort EbrArmIOStatus
{
get
{
return _EbrArmIOStatus;
}
set
{
_EbrArmIOStatus = value;
OnPropertyChanged("EbrArmIOStatus");
}
}
private ushort _AttractIOStatus;
public ushort AttractIOStatus
{
get
{
return _AttractIOStatus;
}
set
{
_AttractIOStatus = value;
OnPropertyChanged("AttractIOStatus");
}
}
private ushort _BSRIOStatus;
public ushort BSRIOStatus
{
get
{
return _BSRIOStatus;
}
set
{
_BSRIOStatus = value;
OnPropertyChanged("BSRIOStatus");
}
}
private ushort _EBRIOStatus;
public ushort EBRIOStatus
{
get
{
return _EBRIOStatus;
}
set
{
_EBRIOStatus = value;
OnPropertyChanged("EBRIOStatus");
}
}
private ushort _PR2YeIOStatus;
public ushort PR2YeIOStatus
{
get
{
return _PR2YeIOStatus;
}
set
{
_PR2YeIOStatus = value;
OnPropertyChanged("PR2YeIOStatus");
}
}
private ushort _PR1YeIOStatus;
public ushort PR1YeIOStatus
{
get
{
return _PR1YeIOStatus;
}
set
{
_PR1YeIOStatus = value;
OnPropertyChanged("PR1YeIOStatus");
}
}
private ushort _WindowStatus;
public ushort WindowStatus
{
get
{
return _WindowStatus;
}
set
{
_WindowStatus = value;
OnPropertyChanged("WindowStatus");
}
}
private bool _ProgressEnabled;
public bool ProgressEnabled
{
get
{
return _ProgressEnabled;
}
set
{
_ProgressEnabled = value;
OnPropertyChanged("ProgressEnabled");
}
}
private ushort _Pr1IOStatus;
public ushort Pr1IOStatus
{
get
{
return _Pr1IOStatus;
}
set
{
_Pr1IOStatus = value;
OnPropertyChanged("Pr1IOStatus");
}
}
private ushort _Pr2IOStatus;
public ushort Pr2IOStatus
{
get
{
return _Pr2IOStatus;
}
set
{
_Pr2IOStatus = value;
OnPropertyChanged("Pr2IOStatus");
}
}
private ushort _CCRIOStatus;
public ushort CCRIOStatus
{
get
{
return _CCRIOStatus;
}
set
{
_CCRIOStatus = value;
OnPropertyChanged("CCRIOStatus");
}
}
#endregion
#region Binding Commands
private ICommand _PrArmCommand;
public ICommand PrArmCommand
{
get
{
return _PrArmCommand;
}
set
{
_PrArmCommand = value;
OnPropertyChanged("PrArmCommand");
}
}
private ICommand _EbrArmCommand;
public ICommand EbrArmCommand
{
get
{
return _EbrArmCommand;
}
set
{
_EbrArmCommand = value;
OnPropertyChanged("EbrArmCommand");
}
}
private ICommand _MainAxisIOCommand;
public ICommand MainAxisIOCommand
{
get
{
return _MainAxisIOCommand;
}
set
{
_MainAxisIOCommand = value;
OnPropertyChanged("MainAxisIOCommand");
}
}
private ICommand _PrArmIOCommand;
public ICommand PrArmIOCommand
{
get
{
return _PrArmIOCommand;
}
set
{
_PrArmIOCommand = value;
OnPropertyChanged("PrArmIOCommand");
}
}
private ICommand _EbrArmIOCommand;
public ICommand EbrArmIOCommand
{
get
{
return _EbrArmIOCommand;
}
set
{
_EbrArmIOCommand = value;
OnPropertyChanged("EbrArmIOCommand");
}
}
private ICommand _AttractCommand;
public ICommand AttractCommand
{
get
{
return _AttractCommand;
}
set
{
_AttractCommand = value;
OnPropertyChanged("AttractCommand");
}
}
private ICommand _BSRIOCommand;
public ICommand BSRIOCommand
{
get
{
return _BSRIOCommand;
}
set
{
_BSRIOCommand = value;
OnPropertyChanged("BSRIOCommand");
}
}
private ICommand _EBRIOCommand;
public ICommand EBRIOCommand
{
get
{
return _EBRIOCommand;
}
set
{
_EBRIOCommand = value;
OnPropertyChanged("EBRIOCommand");
}
}
private ICommand _PR2YeIOCommand;
public ICommand PR2YeIOCommand
{
get
{
return _PR2YeIOCommand;
}
set
{
_PR2YeIOCommand = value;
OnPropertyChanged("PR2YeIOCommand");
}
}
private ICommand _PR1YeIOCommand;
public ICommand PR1YeIOCommand
{
get
{
return _PR1YeIOCommand;
}
set
{
_PR1YeIOCommand = value;
OnPropertyChanged("PR1YeIOCommand");
}
}
private ICommand _PR1Command;
public ICommand PR1Command
{
get
{
return _PR1Command;
}
set
{
_PR1Command = value;
OnPropertyChanged("PR1Command");
}
}
private ICommand _PR2Command;
public ICommand PR2Command
{
get
{
return _PR2Command;
}
set
{
_PR2Command = value;
OnPropertyChanged("PR2Command");
}
}
private ICommand _CCRCommand;
public ICommand CCRCommand
{
get
{
return _CCRCommand;
}
set
{
_CCRCommand = value;
OnPropertyChanged("CCRCommand");
}
}
private ICommand _SVONCommand;
public ICommand SVONCommand
{
get
{
return _SVONCommand;
}
set
{
_SVONCommand = value;
OnPropertyChanged("SVONCommand");
}
}
private ICommand _RUNCommand;
public ICommand RUNCommand
{
get
{
return _RUNCommand;
}
set
{
_RUNCommand = value;
OnPropertyChanged("RUNCommand");
}
}
private ICommand _HOMECommand;
public ICommand HOMECommand
{
get
{
return _HOMECommand;
}
set
{
_HOMECommand = value;
OnPropertyChanged("HOMECommand");
}
}
private ICommand _WindowCommand;
public ICommand WindowCommand
{
get
{
return _WindowCommand;
}
set
{
_WindowCommand = value;
OnPropertyChanged("WindowCommand");
}
}
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 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)
{
if (this.IsActiveChildPage && !Helpering.IsTerminate)
{
Pr1IOStatus = Global.Pr1IOStatus;
Pr2IOStatus = Global.Pr2IOStatus;
int position = 0;
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>
int speed = 0;
var flow = HardParameters.GetCotMainAxis(StationCode);
if (flow != null)
{
DeviceControl.GetSpeed(flow.NodeId, flow.SlotId, ref speed);
DeviceControl.GetPosition(flow.NodeId, flow.SlotId, ref position);
if (Homing && ControlCheck.IsHomeDone(flow.NodeId, flow.SlotId))//<2F>ָ<EFBFBD>Home״̬
{
HOMEStatus = 0;
Homing = false;
}
//<2F><>ȡ<EFBFBD><EFBFBD><E6BEAF>Ϣ
ushort Datasize = 4;
byte[] Data = new byte[4];
DeviceControl.ReadPDOParameter(flow.NodeId, 0, Global.AlmSign, 0, Datasize, ref Data[0]);
string code = TypeHelper.IntToHex(TypeHelper.ByteArrayToInt(Data));
View.Dispatcher.BeginInvoke(new Action(() =>
{
MainAxisALM = Convert.ToString(code);
MainAxisRPM = speed / 10.0;
}), null);
}
//Һλ<D2BA><CEBB>ť<EFBFBD><C5A5><EFBFBD><EFBFBD>
var portCot1Pr1H = Global.InputIOs.FirstOrDefault(q => q.RecId == "DI6.9");
if (portCot1Pr1H.IsOpen && StationCode == Constant.COT1)
{
PR1YeIOStatus = 0;
}
var portCot1Pr2H = Global.InputIOs.FirstOrDefault(q => q.RecId == "DI6.12");
if (portCot1Pr2H.IsOpen && StationCode == Constant.COT1)
{
PR2YeIOStatus = 0;
}
var portCot2Pr1H = Global.InputIOs.FirstOrDefault(q => q.RecId == "DI7.1");
if (portCot2Pr1H.IsOpen && StationCode == Constant.COT2)
{
PR1YeIOStatus = 0;
}
var portCot2Pr2H = Global.InputIOs.FirstOrDefault(q => q.RecId == "DI7.4");
if (portCot2Pr2H.IsOpen && StationCode == Constant.COT2)
{
PR2YeIOStatus = 0;
}
//ˢ<><CBA2>IO״̬
if(Global.GetInPortStatus(StationCode, "MainAxis") == 1)
{
MainAxisIOStatus2 = 1;
}
if (Global.GetInPortStatus(StationCode, "MainAxisLow") == 1)
{
MainAxisIOStatus2 = 0;
}
}
}
private void RefreshIOStatus()
{
//״̬λˢ<CEBB><CBA2>
EBRIOStatus = Global.GetOutPortStatus(StationCode, "EBR");
BSRIOStatus = Global.GetOutPortStatus(StationCode, "BSR");
Pr1IOStatus = Global.Pr1IOStatus;
Pr2IOStatus = Global.Pr2IOStatus;
MainAxisIOStatus = Global.GetInPortStatus(StationCode, "MainAxis");
WindowStatus = Global.GetInPortStatus(StationCode, "Window");
AttractIOStatus = Global.GetInPortStatus(StationCode, "Attract");
PrArmIOStatus = Global.GetInPortStatus(StationCode, "PrArm");
EbrArmIOStatus = Global.GetInPortStatus(StationCode, "EbrArm");
CCRIOStatus = Global.GetOutPortStatus(StationCode, "CCR");//*/
}
//<2F><>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD>
private void OnAttractCommand(Object sender)
{
if (StationLockControl.StationIsLock(StationCode))
{
ShowMessageBox(HintMessage.StationLocked);
return;
}
AttractIOStatus = (ushort)(AttractIOStatus != 1 ? 1 : 0);
OnAttractCommand(AttractIOStatus);
}
private void OnAttractCommand(ushort value)
{
var flow = HardParameters.GetCotAttractIO(StationCode);
if (flow != null)
{
AttractIOStatus = value;
ControlCheck.PMCInvoke(false, "SetPortStatus", null, () => DeviceControl.SetPortStatus(flow.NodeId, flow.SlotId, flow.BitNum, AttractIOStatus));
}
}
// <20><><EFBFBD><EFBFBD>BSR,<2C><>Ӧ<EFBFBD>䷽BSR
private void OnBSRIOCommand(Object sender)
{
if (StationLockControl.StationIsLock(StationCode))
{
ShowMessageBox(HintMessage.StationLocked);
return;
}
BSRIOStatus = (ushort)(BSRIOStatus != 1 ? 1 : 0);
OnBSRIOCommand(BSRIOStatus);
}
private void OnBSRIOCommand(ushort value)
{
var action = HardParameters.GetCotBSRIO(StationCode);
if (action != null)
{
BSRIOStatus = value;
ControlCheck.PMCInvoke(false, "SetPortStatus", null, () => DeviceControl.SetPortStatus(action.NodeId, action.SlotId, action.BitNo, BSRIOStatus));
}
}
// ȥ<><C8A5>ҺEBR,<2C><>Ӧ<EFBFBD>䷽EBR
private void OnEBRIOCommand(Object sender)
{
if (StationLockControl.StationIsLock(StationCode))
{
ShowMessageBox(HintMessage.StationLocked);
return;
}
EBRIOStatus = (ushort)(EBRIOStatus != 1 ? 1 : 0);
OnEBRIOCommand(EBRIOStatus);
}
private void OnEBRIOCommand(ushort value)
{
var action = HardParameters.GetCotEBRIO(StationCode);
if (action != null)
{
EBRIOStatus = value;
ControlCheck.PMCInvoke(false, "SetPortStatus", null, () => DeviceControl.SetPortStatus(action.NodeId, action.SlotId, action.BitNo, EBRIOStatus));
}
}
private void OnEbrArmIOCommand(Object sender)
{
if (StationLockControl.StationIsLock(StationCode))
{
ShowMessageBox(HintMessage.StationLocked);
return;
}
EbrArmIOStatus = (ushort)(EbrArmIOStatus != 1 ? 1 : 0);
OnEbrArmIOCommand(EbrArmIOStatus);
}
private void OnEbrArmIOCommand(ushort value)
{
var flow = HardParameters.GetCotEbrArmIO(StationCode);
if (flow != null)
{
EbrArmIOStatus = value;
ControlCheck.PMCInvoke(false, "SetPortStatus", null, () => DeviceControl.SetPortStatus(flow.NodeId, flow.SlotId, flow.BitNum, EbrArmIOStatus));
}
}
private void OnMainAxisIOCommand(Object sender)
{
if (StationLockControl.StationIsLock(StationCode))
{
ShowMessageBox(HintMessage.StationLocked);
return;
}
MainAxisIOStatus = (ushort)(MainAxisIOStatus != 1 ? 1 : 0);
OnMainAxisIOCommand(MainAxisIOStatus, false);
}
private void OnMainAxisIOCommand(ushort value, bool wait)
{
HardFormulaFlowEntity mapFlow = null;
var flow = HardParameters.GetCotMainAxisIO(StationCode, out mapFlow);
if (flow != null && mapFlow != null)
{
MainAxisIOStatus = value;
//<2F><>Ϊ˫<CEAA><CBAB>
ControlCheck.PMCInvoke(false, "SetPortStatus", null, () => DeviceControl.SetPortStatus(mapFlow.NodeId, mapFlow.SlotId, mapFlow.BitNum, (ushort)(1 - MainAxisIOStatus)));
ControlCheck.PMCInvoke(false, "SetPortStatus", null, () => DeviceControl.SetPortStatus(flow.NodeId, flow.SlotId, flow.BitNum, MainAxisIOStatus));
if (wait)//<2F>ȴ<EFBFBD><C8B4><EFBFBD>λ
{
ControlCheck.WaitDIDone(value == 0 ? flow.RefPortLow : flow.RefPortHigh, true);
}
}
}
private void OnPrArmIOCommand(Object sender)
{
if (StationLockControl.StationIsLock(StationCode))
{
ShowMessageBox(HintMessage.StationLocked);
return;
}
PrArmIOStatus = (ushort)(PrArmIOStatus != 1 ? 1 : 0);
OnPrArmIOCommand(PrArmIOStatus);
}
private void OnPrArmIOCommand(ushort value)
{
var flow = HardParameters.GetCotPrArmIO(StationCode);
if (flow != null)
{
PrArmIOStatus = value;
ControlCheck.PMCInvoke(false, "SetPortStatus", null, () => DeviceControl.SetPortStatus(flow.NodeId, flow.SlotId, flow.BitNum, PrArmIOStatus));
}
}
private void OnEbrArmCommand(Object sender)
{
if (StationLockControl.StationIsLock(StationCode))
{
ShowMessageBox(HintMessage.StationLocked);
return;
}
//<2F>رճ<D8B1>Ƭ̨<C6AC><CCA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2>
OnMainAxisIOCommand(0, false);
//̧<><CCA7>EBR<42><52>
if (EbrArmIOStatus != 1)
{
OnEbrArmIOCommand(null);
}
ControlCOTArmViewModule ccvm = new ControlCOTArmViewModule();
ccvm.HeaderTitle = <>߱ۿ<DFB1><DBBF><EFBFBD>";
ccvm.StationCode = StationCode;
ccvm.IsPrArm = false;
ccvm.LoadDefaultValue();
ccvm.UpDownStatus = 1;
ViewModelLoad.SetActiveChildModel(ccvm);
ccvm.ShowDialog();
}
private void OnPrArmCommand(Object sender)
{
if (StationLockControl.StationIsLock(StationCode))
{
ShowMessageBox(HintMessage.StationLocked);
return;
}
//<2F>رճ<D8B1>Ƭ̨<C6AC><CCA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2>
OnMainAxisIOCommand(0, false);
//<2F><><EFBFBD><EFBFBD>PR<50><52>
if (PrArmIOStatus != 1)
{
OnPrArmIOCommand(null);
}
ControlCOTArmViewModule ccvm = new ControlCOTArmViewModule();
ccvm.HeaderTitle = "<22><><EFBFBD>ۿ<EFBFBD><DBBF><EFBFBD>";
ccvm.StationCode = StationCode;
ccvm.IsPrArm = true;
ccvm.LoadDefaultValue();
ccvm.UpDownStatus = 1;
ViewModelLoad.SetActiveChildModel(ccvm);
ccvm.ShowDialog();
}
private void OnCCRCommand(Object sender)
{
if (StationLockControl.StationIsLock(StationCode))
{
ShowMessageBox(HintMessage.StationLocked);
return;
}
CCRIOStatus = (ushort)(CCRIOStatus != 1 ? 1 : 0);
OnCCRIOCommand(CCRIOStatus);
}
private void OnCCRIOCommand(ushort value)
{
var action = HardParameters.GetCCRIO(StationCode);
if (action != null)
{
CCRIOStatus = value;
ControlCheck.PMCInvoke(false, "SetPortStatus", null, () => DeviceControl.SetPortStatus(action.NodeId, action.SlotId, action.PortIndex, CCRIOStatus));
}
}
private void OnPR2Command(Object sender)
{
if (StationLockControl.StationIsLock(StationCode))
{
ShowMessageBox(HintMessage.StationLocked);
return;
}
ControlCOTPrViewModule ccvm = new ControlCOTPrViewModule();
ccvm.HeaderTitle = "PR2<52><32><EFBFBD><EFBFBD>";
ccvm.StationCode = StationCode;
ccvm.FormulaId = string.Empty;
ccvm.LoadDefaultValue(2);
ccvm.ShowDialog();
}
private void OnPR1Command(Object sender)
{
if (StationLockControl.StationIsLock(StationCode))
{
ShowMessageBox(HintMessage.StationLocked);
return;
}
ControlCOTPrViewModule ccvm = new ControlCOTPrViewModule();
ccvm.HeaderTitle = "PR1<52><31><EFBFBD><EFBFBD>";
ccvm.StationCode = StationCode;
ccvm.FormulaId = string.Empty;
ccvm.LoadDefaultValue(1);
ccvm.ShowDialog();
}
private void OnHOMECommand(Object sender)
{
if (StationLockControl.StationIsLock(StationCode))
{
ShowMessageBox(HintMessage.StationLocked);
return;
}
var flow = HardParameters.GetCotMainAxis(StationCode);
if (flow != null)
{
int axisSpeed = BusinessHelper.GetHomeRPMSpeed(flow.NodeId, (double)AxisSpeed);
SVONStatus = 1;
if (ControlCheck.PMCInvoke(false, "SetSvon", null, () => DeviceControl.SetSvon(flow.NodeId, flow.SlotId, SVONStatus)))
{
double acc = AxisAcc / 1000.0;
if (HOMEStatus != 1)
{
Homing = true;
HOMEStatus = 1;
RUNStatus = 0;
//<2F><><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD>
ControlCheck.PMCInvoke(false, "GoHome", null, () => DeviceControl.GoHome(flow.NodeId, flow.SlotId, 0, (uint)axisSpeed, acc));
}
else
{
double dec = AxisDec / 1000.0;
HOMEStatus = 0;
//<2F><><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD>
ControlCheck.PMCInvoke(false, "StopMove", null, () => DeviceControl.StopMove(flow.NodeId, flow.SlotId, dec));
}
}
}
}
public void OnRUNStart()
{
if (StationLockControl.StationIsLock(StationCode))
{
ShowMessageBox(HintMessage.StationLocked);
return;
}
var flow = HardParameters.GetCotMainAxis(StationCode);
if (flow != null)
{
double acc = AxisAcc / 1000.0;
int axisSpeed = BusinessHelper.GetRPMMapSpeed(flow.NodeId, (double)AxisSpeed);
SVONStatus = 1;
if (ControlCheck.PMCInvoke(false, "SetSvon", null, () => DeviceControl.SetSvon(flow.NodeId, flow.SlotId, SVONStatus)))
{
RUNStatus = 1;
//<2F><><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD>
ControlCheck.PMCInvoke(false, "StartMove", null, () => DeviceControl.StartMove(flow.NodeId, flow.SlotId, 0, axisSpeed, axisSpeed, acc));
}
}
}
public void OnRUNStop()
{
if (StationLockControl.StationIsLock(StationCode))
{
ShowMessageBox(HintMessage.StationLocked);
return;
}
var flow = HardParameters.GetCotMainAxis(StationCode);
if (flow != null)
{
double dec = AxisDec / 1000.0;
int axisSpeed = BusinessHelper.GetRPMMapSpeed(flow.NodeId, (double)AxisSpeed);
SVONStatus = 1;
if (ControlCheck.PMCInvoke(false, "SetSvon", null, () => DeviceControl.SetSvon(flow.NodeId, flow.SlotId, SVONStatus)))
{
RUNStatus = 0;
//<2F><><EFBFBD><EFBFBD><EFBFBD>˶<EFBFBD>
ControlCheck.PMCInvoke(false, "StopMove", null, () => DeviceControl.StopMove(flow.NodeId, flow.SlotId, dec));
}
}
}
private void OnSVONCommand(Object sender)
{
if (StationLockControl.StationIsLock(StationCode))
{
ShowMessageBox(HintMessage.StationLocked);
return;
}
var flow = HardParameters.GetCotMainAxis(StationCode);
if (flow != null)
{
SVONStatus = (ushort)(SVONStatus != 1 ? 1 : 0);
DeviceControl.SetSvon(Common.ToUInt16(flow.NodeId), Common.ToUInt16(flow.SlotId), SVONStatus);
}
}
public void OnAxisSpeedTextChangedCommand(string value)
{
HardParameterDA.Save(StationCode + Constant.COTMainAxisSpeed, value);
}
public void OnAxisAccTextChangedCommand(string value)
{
HardParameterDA.Save(StationCode + Constant.COTMainAxisAcc, value);
}
public void OnAxisDecTextChangedCommand(string value)
{
HardParameterDA.Save(StationCode + Constant.COTMainAxisDec, value);
}
private void OnWindowCommand(Object sender)
{
if (StationLockControl.StationIsLock(StationCode))
{
ShowMessageBox(HintMessage.StationLocked);
return;
}
WindowStatus = (ushort)(WindowStatus != 1 ? 1 : 0);
OnWindowCommand(WindowStatus);
}
private void OnWindowCommand(ushort value)
{
var action = HardParameters.GetCotWindowIO(StationCode);
if (action != null)
{
WindowStatus = value;
ControlCheck.PMCInvoke(false, "SetPortStatus", null, () => DeviceControl.SetPortStatus(action.NodeId, action.SlotId, action.BitNum, WindowStatus));
}
}
private void OnPrepareCommand(Object sender)
{
if (StationLockControl.StationIsLock(StationCode))
{
ShowMessageBox(HintMessage.StationLocked);
return;
}
StationLockControl.LockStation(StationCode, null);
ProgressEnabled = false;
List<HardFormulaFlowEntity> flows = Global.Flows.FindAll(q => q.StationCode == StationCode && q.IsPrepare);
cancellationTokenSource = new CancellationTokenSource();
Task flowTask = new Task(() =>
{
try
{
Global.ClearErrorState(StationCode);
//<2F><><EFBFBD><EFBFBD>״̬
OnMainAxisIOCommand(0, true);
OnPrArmIOCommand(1);
OnEbrArmIOCommand(1);
//OnWindowCommand(0);
OnAttractCommand(0);
OnBSRIOCommand(0);
OnEBRIOCommand(1);
COTFlowExecuter.Execute(cancellationTokenSource, flows, null, true, false);
OnPrArmIOCommand(0);
OnEbrArmIOCommand(0);
OnEBRIOCommand(0);
//RefreshIOStatus();
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();
}
Helpering.Sleep(1000);
ProgressEnabled = true;
}
// PR2Ye
private void OnPR2YeIOCommand(Object sender)
{
if (StationLockControl.StationIsLock(StationCode))
{
ShowMessageBox(HintMessage.StationLocked);
return;
}
PR2YeIOStatus = (ushort)(PR2YeIOStatus != 1 ? 1 : 0);
OnPR2YeIOCommand(PR2YeIOStatus);
}
private void OnPR2YeIOCommand(ushort value)
{
var action = HardParameters.GetCotPRYeIO(StationCode, 2);
if (action != null)
{
PR2YeIOStatus = value;
ControlCheck.PMCInvoke(false, "SetPortStatus", null, () => DeviceControl.SetPortStatus(action.NodeId, action.SlotId, action.PortIndex, PR2YeIOStatus));
}
}
// ȥ<><C8A5>ҺPR1Ye,<2C><>Ӧ<EFBFBD>䷽PR1Ye
private void OnPR1YeIOCommand(Object sender)
{
if (StationLockControl.StationIsLock(StationCode))
{
ShowMessageBox(HintMessage.StationLocked);
return;
}
PR1YeIOStatus = (ushort)(PR1YeIOStatus != 1 ? 1 : 0);
OnPR1YeIOCommand(PR1YeIOStatus);
}
private void OnPR1YeIOCommand(ushort value)
{
var action = HardParameters.GetCotPRYeIO(StationCode, 1);
if (action != null)
{
PR1YeIOStatus = value;
ControlCheck.PMCInvoke(false, "SetPortStatus", null, () => DeviceControl.SetPortStatus(action.NodeId, action.SlotId, action.PortIndex, PR1YeIOStatus));
}
}
#endregion
}
}