|
|
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 ControlHPManualViewModule : ViewModelBase
|
|
|
{
|
|
|
#region base parameters
|
|
|
private int rows = 20;
|
|
|
private int pagenumber = 1;
|
|
|
public ControlHPManualView View { get; set; }
|
|
|
private bool IsConfirm;
|
|
|
private bool isLoading;
|
|
|
private System.Timers.Timer timer;
|
|
|
private HardDTMEntity dtm;
|
|
|
private CancellationTokenSource cancellationTokenSource;
|
|
|
private DateTime dtStart;
|
|
|
private bool IsCanceling = false;
|
|
|
private bool Homing = false;
|
|
|
private int MovingPostion = 0;
|
|
|
#endregion
|
|
|
|
|
|
#region constructor
|
|
|
public ControlHPManualViewModule()
|
|
|
{
|
|
|
View = new ControlHPManualView();
|
|
|
View.DataContext = this;
|
|
|
|
|
|
InitializeCommands();
|
|
|
InitializeParameters();
|
|
|
}
|
|
|
|
|
|
private void InitializeCommands()
|
|
|
{
|
|
|
AttractCommand = new DelegateCommand(OnAttractCommand);
|
|
|
MainAxisTopCommand = new DelegateCommand(OnMainAxisTopCommand);
|
|
|
HOMECommand = new DelegateCommand(OnHOMECommand);
|
|
|
DMTSetCommand = new DelegateCommand(OnDMTSetCommand);
|
|
|
PrepareCommand = new DelegateCommand(OnPrepareCommand);
|
|
|
TerminateCommand = new DelegateCommand(OnTerminateCommand);
|
|
|
WindowCommand = new DelegateCommand(OnWindowCommand);
|
|
|
BrowN2Command = new DelegateCommand(OnBrowN2Command);
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
}//*/
|
|
|
}
|
|
|
|
|
|
~ControlHPManualViewModule()
|
|
|
{
|
|
|
}
|
|
|
public void LoadDefaultValue()
|
|
|
{
|
|
|
MainAxisSpeed = Common.ToDouble(HardParameters.Read(StationCode + Constant.HPMainAxisSpeed));
|
|
|
MainAxisTopPosition = Common.ToDouble(HardParameters.Read(StationCode + Constant.HPMainAxisTopPosition));
|
|
|
//HOMEPosition = Common.ToDouble(HardParameters.Read(StationCode + Constant.HPMainAxisBackPosition));
|
|
|
string postionkey = string.Format("HP_{0}HomingOffset", StationCode);
|
|
|
var postionSet = Global.Settings.FirstOrDefault(q => q.RecId == postionkey);
|
|
|
HOMEPosition = (double)postionSet.SettingValue;
|
|
|
|
|
|
dtm = HardDTMDA.LoadByCode(StationCode);
|
|
|
if(dtm != null)
|
|
|
{
|
|
|
HPSV = dtm.SV;
|
|
|
HPAlmOffset = dtm.AlmOffset;
|
|
|
HPOffset = dtm.Offset;
|
|
|
}
|
|
|
}
|
|
|
#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 _HPSV;
|
|
|
public decimal HPSV
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _HPSV;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_HPSV = value;
|
|
|
OnPropertyChanged("HPSV");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private decimal _HPAlmOffset;
|
|
|
public decimal HPAlmOffset
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _HPAlmOffset;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_HPAlmOffset = value;
|
|
|
OnPropertyChanged("HPAlmOffset");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private decimal _HPOffset;
|
|
|
public decimal HPOffset
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _HPOffset;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_HPOffset = value;
|
|
|
OnPropertyChanged("HPOffset");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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 _ForwardStatus;
|
|
|
public ushort ForwardStatus
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _ForwardStatus;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_ForwardStatus = value;
|
|
|
OnPropertyChanged("ForwardStatus");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private ushort _BackStatus;
|
|
|
public ushort BackStatus
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _BackStatus;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_BackStatus = value;
|
|
|
OnPropertyChanged("BackStatus");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private ushort _SVONStatus;
|
|
|
public ushort SVONStatus
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _SVONStatus;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_SVONStatus = value;
|
|
|
OnPropertyChanged("SVONStatus");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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 _HOMEStatus;
|
|
|
public ushort HOMEStatus
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _HOMEStatus;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_HOMEStatus = value;
|
|
|
OnPropertyChanged("HOMEStatus");
|
|
|
}
|
|
|
}
|
|
|
private ushort _DingZhenStatus;
|
|
|
public ushort DingZhenStatus
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _DingZhenStatus;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_DingZhenStatus = value;
|
|
|
OnPropertyChanged("DingZhenStatus");
|
|
|
}
|
|
|
}
|
|
|
private ushort _MainAxisTopStatus;
|
|
|
public ushort MainAxisTopStatus
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _MainAxisTopStatus;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_MainAxisTopStatus = value;
|
|
|
OnPropertyChanged("MainAxisTopStatus");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private double _HOMEPosition;
|
|
|
public double HOMEPosition
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _HOMEPosition;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_HOMEPosition = value;
|
|
|
OnPropertyChanged("HOMEPosition");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private double _MainAxisTopPosition;
|
|
|
public double MainAxisTopPosition
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _MainAxisTopPosition;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
if (value < 0)
|
|
|
{
|
|
|
value = 0;
|
|
|
}
|
|
|
_MainAxisTopPosition = value;
|
|
|
OnPropertyChanged("MainAxisTopPosition");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private double _MainAxisSpeed;
|
|
|
public double MainAxisSpeed
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _MainAxisSpeed;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_MainAxisSpeed = value;
|
|
|
OnPropertyChanged("MainAxisSpeed");
|
|
|
}
|
|
|
}
|
|
|
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 _WindowStatus;
|
|
|
public ushort WindowStatus
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _WindowStatus;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_WindowStatus = value;
|
|
|
OnPropertyChanged("WindowStatus");
|
|
|
}
|
|
|
}
|
|
|
private bool _IsSub1Open;
|
|
|
public bool IsSub1Open
|
|
|
{
|
|
|
get { return _IsSub1Open; }
|
|
|
set
|
|
|
{
|
|
|
_IsSub1Open = value;
|
|
|
OnPropertyChanged("IsSub1Open");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
private bool _IsSub2Open;
|
|
|
public bool IsSub2Open
|
|
|
{
|
|
|
get { return _IsSub2Open; }
|
|
|
set
|
|
|
{
|
|
|
_IsSub2Open = value;
|
|
|
OnPropertyChanged("IsSub2Open");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private bool _IsSub3Open;
|
|
|
public bool IsSub3Open
|
|
|
{
|
|
|
get { return _IsSub3Open; }
|
|
|
set
|
|
|
{
|
|
|
_IsSub3Open = value;
|
|
|
OnPropertyChanged("IsSub3Open");
|
|
|
}
|
|
|
}
|
|
|
private decimal _CurPosition;
|
|
|
public decimal CurPosition
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _CurPosition;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_CurPosition = value;
|
|
|
OnPropertyChanged("CurPosition");
|
|
|
}
|
|
|
}
|
|
|
private ushort _BrowN2Status;
|
|
|
public ushort BrowN2Status
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _BrowN2Status;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_BrowN2Status = value;
|
|
|
OnPropertyChanged("BrowN2Status");
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region Binding Commands
|
|
|
private ICommand _MainAxisTopCommand;
|
|
|
public ICommand MainAxisTopCommand
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _MainAxisTopCommand;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_MainAxisTopCommand = value;
|
|
|
OnPropertyChanged("MainAxisTopCommand");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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 _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 ICommand _BrowN2Command;
|
|
|
public ICommand BrowN2Command
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _BrowN2Command;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_BrowN2Command = value;
|
|
|
OnPropertyChanged("BrowN2Command");
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region Private Methods
|
|
|
private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
|
|
{
|
|
|
if (this.IsActiveChildPage)
|
|
|
{
|
|
|
var dtm = Global.DTM?.FirstOrDefault(q => q.DTMCode == StationCode);
|
|
|
if (dtm != null)
|
|
|
{
|
|
|
DMTSetStatus = dtm.IsAutoSetStatus;
|
|
|
}
|
|
|
int position = 0;
|
|
|
var axis = HardParameters.GetHPMainAxis(StationCode);
|
|
|
if (axis != null && !Helpering.IsTerminate)
|
|
|
{
|
|
|
DeviceControl.GetPosition(axis.NodeId, axis.SlotId, ref position);
|
|
|
if (Homing && ControlCheck.IsHPHomeDone(axis.NodeId, axis.SlotId))//恢复Home状态
|
|
|
{
|
|
|
HOMEStatus = 0;
|
|
|
DingZhenStatus = 1;
|
|
|
Homing = false;
|
|
|
}
|
|
|
if (MovingPostion == position)
|
|
|
{
|
|
|
MainAxisTopStatus = 0;
|
|
|
DingZhenStatus = 0;
|
|
|
}
|
|
|
if (0 == position)
|
|
|
{
|
|
|
DingZhenStatus = 1;
|
|
|
}
|
|
|
ushort Datasize = 4;
|
|
|
byte[] Data = new byte[4];
|
|
|
DeviceControl.ReadPDOParameter(axis.NodeId, 0, Global.PositionSign, 0, Datasize, ref Data[0]);
|
|
|
int c = TypeHelper.ByteArrayToInt(Data);
|
|
|
string values = Convert.ToString(c, 2);
|
|
|
IsSub1Open = false;
|
|
|
IsSub2Open = false;
|
|
|
IsSub3Open = false;
|
|
|
//原点最右侧
|
|
|
if (values.Length > 0)
|
|
|
{
|
|
|
IsSub3Open = values.Substring(values.Length - 1) == "1";
|
|
|
}
|
|
|
//中间负极
|
|
|
if (values.Length > 1)
|
|
|
{
|
|
|
IsSub2Open = values.Substring(values.Length - 2, 1) == "1";
|
|
|
}
|
|
|
//左侧正极
|
|
|
if (values.Length > 2)
|
|
|
{
|
|
|
IsSub1Open = values.Substring(values.Length - 3, 1) == "1";
|
|
|
}
|
|
|
|
|
|
//var inputIO = Global.InputIOs.FirstOrDefault(q => q.RecId == "DI5.1");
|
|
|
//bool isDone = DeviceControl.GetPortStatus(inputIO.NodeId, inputIO.SlotId, inputIO.PortIndex, true);
|
|
|
//inputIO = Global.InputIOs.FirstOrDefault(q => q.RecId == "DI5.2");
|
|
|
//isDone = DeviceControl.GetPortStatus(inputIO.NodeId, inputIO.SlotId, inputIO.PortIndex, true);
|
|
|
var postion = BusinessHelper.ConvertHPMapSpeed(axis.NodeId, (double)position);
|
|
|
View.Dispatcher.BeginInvoke(new Action(() =>
|
|
|
{
|
|
|
CurPosition = MainAxisTopPosition == 0 ? postion : (decimal)MainAxisTopPosition - postion;
|
|
|
}), null);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
private void RefreshIOStatus()
|
|
|
{
|
|
|
//状态位刷新
|
|
|
WindowStatus = Global.GetInPortStatus(StationCode, "Window");
|
|
|
AttractIOStatus = Global.GetInPortStatus(StationCode, "Attract");
|
|
|
BrowN2Status = Global.GetOutPortStatus(StationCode, "BrowN2");//*/
|
|
|
}
|
|
|
//吸片真空
|
|
|
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.GetHPAttractIO(StationCode);
|
|
|
if (flow != null)
|
|
|
{
|
|
|
AttractIOStatus = value;
|
|
|
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;
|
|
|
}
|
|
|
if (DMTSetStatus != 1)
|
|
|
{
|
|
|
DMTSetStatus = 1;
|
|
|
DTM.Write(dtm.Channel, dtm.WriteAddress, (ushort)((HPSV + HPOffset) * 10));
|
|
|
DTM.Write(dtm.Channel, dtm.ATAddress, 1);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
DMTSetStatus = 0;
|
|
|
DTM.Write(dtm.Channel, dtm.ATAddress, 0);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void OnMainAxisSpeedTextChangedCommand(string value)
|
|
|
{
|
|
|
HardParameterDA.Save(StationCode + Constant.HPMainAxisSpeed, Convert.ToString(value));
|
|
|
}
|
|
|
public void OnMainAxisTopPositionTextChangedCommand(string value)
|
|
|
{
|
|
|
HardParameterDA.Save(StationCode + Constant.HPMainAxisTopPosition, Convert.ToString(value));
|
|
|
}
|
|
|
public void OnHOMEPositionTextChangedCommand(string value)
|
|
|
{
|
|
|
//HardParameterDA.Save(StationCode + Constant.HPMainAxisBackPosition, Convert.ToString(value));
|
|
|
string postionkey = string.Format("HP_{0}HomingOffset", StationCode);
|
|
|
var postionSet = Global.Settings.FirstOrDefault(q => q.RecId == postionkey);
|
|
|
postionSet.SettingValue = Common.ToDecimal(value);
|
|
|
SysSettingDA.Update(postionSet);
|
|
|
}
|
|
|
|
|
|
public void OnHPSVTextChangedCommand(string value)
|
|
|
{
|
|
|
HPSV = Common.ToDecimal(value);
|
|
|
UpdateParameter();
|
|
|
}
|
|
|
public void OnHPAlmOffsetTextChangedCommand(string value)
|
|
|
{
|
|
|
HPAlmOffset = Common.ToDecimal(value);
|
|
|
UpdateParameter();
|
|
|
}
|
|
|
public void OnHPOffsetTextChangedCommand(string value)
|
|
|
{
|
|
|
HPOffset = Common.ToDecimal(value);
|
|
|
UpdateParameter();
|
|
|
}
|
|
|
|
|
|
private void UpdateParameter()
|
|
|
{
|
|
|
HardDTMEntity dtm = new HardDTMEntity();
|
|
|
dtm.RecId = StationCode;
|
|
|
dtm.DTMCode = StationCode;
|
|
|
dtm.DTMName = StationCode;
|
|
|
dtm.SV = HPSV;
|
|
|
dtm.AlmOffset = HPAlmOffset;
|
|
|
dtm.Offset = HPOffset;
|
|
|
HardDTMDA.Update(dtm);
|
|
|
}
|
|
|
|
|
|
public void OnJogForwardStart()
|
|
|
{
|
|
|
if (StationLockControl.StationIsLock(StationCode))
|
|
|
{
|
|
|
ShowMessageBox(HintMessage.StationLocked);
|
|
|
return;
|
|
|
}
|
|
|
var flow = HardParameters.GetHPMainAxis(StationCode);
|
|
|
if (flow != null)
|
|
|
{
|
|
|
int axisSpeed = BusinessHelper.GetHPMapSpeed(flow.NodeId, (double)MainAxisSpeed);
|
|
|
double axisAcc = 0.1;
|
|
|
SVONStatus = 1;
|
|
|
if (ControlCheck.PMCInvoke(false, "SetSvon", null, () => DeviceControl.SetSvon(flow.NodeId, flow.SlotId, SVONStatus)))
|
|
|
{
|
|
|
ForwardStatus = 1;
|
|
|
//匀速运动
|
|
|
ControlCheck.PMCInvoke(false, "StartMove", null, () => DeviceControl.StartMove(flow.NodeId, flow.SlotId, 1, axisSpeed, axisSpeed, axisAcc));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
public void OnJogForwardStop()
|
|
|
{
|
|
|
var flow = HardParameters.GetHPMainAxis(StationCode);
|
|
|
if (flow != null)
|
|
|
{
|
|
|
int axisSpeed = BusinessHelper.GetHPMapSpeed(flow.NodeId, (double)MainAxisSpeed);
|
|
|
double axisAcc = 0.1;
|
|
|
SVONStatus = 1;
|
|
|
if (ControlCheck.PMCInvoke(false, "SetSvon", null, () => DeviceControl.SetSvon(flow.NodeId, flow.SlotId, SVONStatus)))
|
|
|
{
|
|
|
ForwardStatus = 0;
|
|
|
//匀速运动
|
|
|
ControlCheck.PMCInvoke(false, "StopMove", null, () => DeviceControl.StopMove(flow.NodeId, flow.SlotId, axisAcc));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
public void OnJogBackStart()
|
|
|
{
|
|
|
if (StationLockControl.StationIsLock(StationCode))
|
|
|
{
|
|
|
ShowMessageBox(HintMessage.StationLocked);
|
|
|
return;
|
|
|
}
|
|
|
var flow = HardParameters.GetHPMainAxis(StationCode);
|
|
|
if (flow != null)
|
|
|
{
|
|
|
int axisSpeed = BusinessHelper.GetHPMapSpeed(flow.NodeId, (double)MainAxisSpeed);
|
|
|
double axisAcc = 0.1;
|
|
|
SVONStatus = 1;
|
|
|
if (ControlCheck.PMCInvoke(false, "SetSvon", null, () => DeviceControl.SetSvon(flow.NodeId, flow.SlotId, SVONStatus)))
|
|
|
{
|
|
|
BackStatus = 1;
|
|
|
//匀速运动
|
|
|
ControlCheck.PMCInvoke(false, "StartMove", null, () => DeviceControl.StartMove(flow.NodeId, flow.SlotId, 0, axisSpeed, axisSpeed, axisAcc));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
public void OnJogBackStop()
|
|
|
{
|
|
|
var flow = HardParameters.GetHPMainAxis(StationCode);
|
|
|
if (flow != null)
|
|
|
{
|
|
|
int axisSpeed = BusinessHelper.GetHPMapSpeed(flow.NodeId, (double)MainAxisSpeed);
|
|
|
double axisAcc = 0.1;
|
|
|
SVONStatus = 1;
|
|
|
if (ControlCheck.PMCInvoke(false, "SetSvon", null, () => DeviceControl.SetSvon(flow.NodeId, flow.SlotId, SVONStatus)))
|
|
|
{
|
|
|
BackStatus = 0;
|
|
|
//匀速运动
|
|
|
ControlCheck.PMCInvoke(false, "StopMove", null, () => DeviceControl.StopMove(flow.NodeId, flow.SlotId, axisAcc));
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
private void OnHOMECommand(Object sender)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
if (StationLockControl.StationIsLock(StationCode))
|
|
|
{
|
|
|
ShowMessageBox(HintMessage.StationLocked);
|
|
|
return;
|
|
|
}
|
|
|
var axis = HardParameters.GetHPMainAxis(StationCode);
|
|
|
if (axis != null)
|
|
|
{
|
|
|
int homeSpeed = BusinessHelper.GetHPMapSpeed(axis.NodeId, (double)MainAxisSpeed);
|
|
|
int homePostion = BusinessHelper.GetHPMapSpeed(axis.NodeId, (double)HOMEPosition);
|
|
|
if (ControlCheck.PMCInvoke(false, "SetSvon", null, () => DeviceControl.SetSvon(axis.NodeId, axis.SlotId, 1)))
|
|
|
{
|
|
|
MainAxisTopStatus = 0;
|
|
|
if (HOMEStatus != 1)
|
|
|
{
|
|
|
Homing = true;
|
|
|
HOMEStatus = 1;
|
|
|
//匀速运动
|
|
|
ControlCheck.PMCInvoke(false, "GoHPHome", null, () => DeviceControl.GoHPHome(Global.HPHomeWay, axis.NodeId, axis.SlotId, homePostion, (uint)homeSpeed));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
HOMEStatus = 0;
|
|
|
//停止运动
|
|
|
ControlCheck.PMCInvoke(false, "StopMove", null, () => DeviceControl.StopMove(axis.NodeId, axis.SlotId, Global.ArmAcc));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ShowErrorBox(ex.Message);
|
|
|
HOMEStatus = 0;
|
|
|
}
|
|
|
}
|
|
|
private void OnMainAxisTopCommand(Object sender)
|
|
|
{
|
|
|
if (StationLockControl.StationIsLock(StationCode))
|
|
|
{
|
|
|
ShowMessageBox(HintMessage.StationLocked);
|
|
|
return;
|
|
|
}
|
|
|
var axis = HardParameters.GetHPMainAxis(StationCode);
|
|
|
if (axis != null)
|
|
|
{
|
|
|
int axisSpeed = BusinessHelper.GetHPMapSpeed(axis.NodeId, (double)MainAxisSpeed);
|
|
|
int position = BusinessHelper.GetHPMapSpeed(axis.NodeId, (double)MainAxisTopPosition);
|
|
|
double scale = Global.GetRPMScale(axis.NodeId);
|
|
|
if (scale == 0)
|
|
|
{
|
|
|
scale = 1;//默认值
|
|
|
}
|
|
|
position = (int)(position * 1.0 / scale);
|
|
|
double axisAcc = Global.DefaultAcc;
|
|
|
if (ControlCheck.PMCInvoke(false, "SetSvon", null, () => DeviceControl.SetSvon(axis.NodeId, axis.SlotId, 1)))
|
|
|
{
|
|
|
HOMEStatus = 0;
|
|
|
if (MainAxisTopStatus != 1)
|
|
|
{
|
|
|
MovingPostion = position;
|
|
|
MainAxisTopStatus = 1;
|
|
|
//匀速运动
|
|
|
ControlCheck.PMCInvoke(false, "StartMove", null, () => DeviceControl.StartMove(axis.NodeId, axis.SlotId, position, axisSpeed, axisSpeed, 0, axisAcc, axisAcc, 1));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MainAxisTopStatus = 0;
|
|
|
//停止运动
|
|
|
ControlCheck.PMCInvoke(false, "StopMove", null, () => DeviceControl.StopMove(axis.NodeId, axis.SlotId, Global.ArmAcc));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void OnWindowCommand(Object sender)
|
|
|
{
|
|
|
if (StationLockControl.StationIsLock(StationCode))
|
|
|
{
|
|
|
ShowMessageBox(HintMessage.StationLocked);
|
|
|
return;
|
|
|
}
|
|
|
var flow = HardParameters.GetHPWindowIO(StationCode);
|
|
|
if (flow != null)
|
|
|
{
|
|
|
WindowStatus = (ushort)(WindowStatus != 1 ? 1 : 0);
|
|
|
ControlCheck.PMCInvoke(false, "SetPortStatus", null, () => DeviceControl.SetPortStatus(flow.NodeId, flow.SlotId, flow.BitNum, WindowStatus));
|
|
|
}
|
|
|
}
|
|
|
private void OnBrowN2Command(Object sender)
|
|
|
{
|
|
|
if (StationLockControl.StationIsLock(StationCode))
|
|
|
{
|
|
|
ShowMessageBox(HintMessage.StationLocked);
|
|
|
return;
|
|
|
}
|
|
|
BrowN2Status = (ushort)(BrowN2Status != 1 ? 1 : 0);
|
|
|
OnBrowN2Command(BrowN2Status);
|
|
|
}
|
|
|
private void OnBrowN2Command(ushort value)
|
|
|
{
|
|
|
var action = HardParameters.GetHPBrowN2(StationCode);
|
|
|
if (action != null)
|
|
|
{
|
|
|
BrowN2Status = value;
|
|
|
ControlCheck.PMCInvoke(false, "SetPortStatus", null, () => DeviceControl.SetPortStatus(action.NodeId, action.SlotId, action.BitNum, BrowN2Status));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void OnPrepareCommand(Object sender)
|
|
|
{
|
|
|
if (StationLockControl.StationIsLock(StationCode))
|
|
|
{
|
|
|
ShowMessageBox(HintMessage.StationLocked);
|
|
|
return;
|
|
|
}
|
|
|
//关闭遮挡
|
|
|
var flow = HardParameters.GetHPWindowIO(StationCode);
|
|
|
if (flow != null)
|
|
|
{
|
|
|
WindowStatus = 0;
|
|
|
ControlCheck.PMCInvoke(false, "SetPortStatus", null, () => DeviceControl.SetPortStatus(flow.NodeId, flow.SlotId, flow.BitNum, WindowStatus));
|
|
|
}
|
|
|
var axis = HardParameters.GetHPMainAxis(StationCode);
|
|
|
if (axis != null)
|
|
|
{
|
|
|
cancellationTokenSource = new CancellationTokenSource();
|
|
|
ProgressEnabled = false;
|
|
|
ProgressTime = 0;
|
|
|
dtStart = DateTime.Now;
|
|
|
IsCanceling = false;
|
|
|
Task formulaTask = new Task(() =>
|
|
|
{
|
|
|
Global.ClearErrorState(StationCode);
|
|
|
ProgressTime = 0;
|
|
|
int axisSpeed = BusinessHelper.GetHPMapSpeed(axis.NodeId, (double)MainAxisSpeed);
|
|
|
int homePostion = BusinessHelper.GetHPMapSpeed(axis.NodeId, (double)HOMEPosition);
|
|
|
int topPosition = BusinessHelper.GetHPMapSpeed(axis.NodeId, (double)MainAxisTopPosition);
|
|
|
double axisAcc = 0.1;
|
|
|
if (ControlCheck.PMCInvoke(false, "SetSvon", null, () => DeviceControl.SetSvon(axis.NodeId, axis.SlotId, 1)))
|
|
|
{
|
|
|
if (IsCanceling)
|
|
|
return;
|
|
|
//运行到Home位置,间隙最大
|
|
|
ControlCheck.PMCInvoke(false, "GoHPHome", null, () => DeviceControl.GoHPHome(Global.HPHomeWay, axis.NodeId, axis.SlotId, homePostion, (uint)axisSpeed));
|
|
|
if (IsCanceling)
|
|
|
return;
|
|
|
//等待执行时间后自动关闭
|
|
|
ControlCheck.WaitAxisDone(axis.NodeId);
|
|
|
if (IsCanceling)
|
|
|
return;
|
|
|
//吸片真空
|
|
|
OnAttractCommand(0);
|
|
|
//吹氮气
|
|
|
OnBrowN2Command(0);
|
|
|
if (IsCanceling)
|
|
|
return;
|
|
|
//再运行到顶部部位置
|
|
|
//ControlCheck.PMCInvoke(false, "StartMove", null, () => DeviceControl.StartMove(axis.NodeId, axis.SlotId, topPosition, axisSpeed, axisSpeed, 0, axisAcc, axisAcc, 1));
|
|
|
if (IsCanceling)
|
|
|
return;
|
|
|
//等待执行时间后自动关闭
|
|
|
//ControlCheck.WaitAxisDone(axis.NodeId);
|
|
|
//停止运动
|
|
|
//ControlCheck.PMCInvoke(false, "StopMove", null, () => DeviceControl.StopMove(axis.NodeId, axis.SlotId, Global.ArmAcc));
|
|
|
//RefreshIOStatus();
|
|
|
}
|
|
|
ProgressEnabled = true;
|
|
|
}, cancellationTokenSource.Token, TaskCreationOptions.LongRunning);
|
|
|
formulaTask.Start();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void OnTerminateCommand(Object sender)
|
|
|
{
|
|
|
IsCanceling = true;
|
|
|
if (cancellationTokenSource != null)
|
|
|
{
|
|
|
cancellationTokenSource.Cancel();
|
|
|
}
|
|
|
//稍等待后停止主轴
|
|
|
Helpering.Sleep(1000);
|
|
|
var axis = HardParameters.GetHPMainAxis(StationCode);
|
|
|
if (axis != null)
|
|
|
{
|
|
|
if (ControlCheck.PMCInvoke(false, "SetSvon", null, () => DeviceControl.SetSvon(axis.NodeId, axis.SlotId, 1)))
|
|
|
{
|
|
|
HOMEStatus = 0;
|
|
|
//停止运动
|
|
|
ControlCheck.PMCInvoke(false, "StopMove", null, () => DeviceControl.StopMove(axis.NodeId, axis.SlotId, Global.ArmAcc));
|
|
|
}
|
|
|
}
|
|
|
ProgressEnabled = true;
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
}
|