| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162 | using MECF.Framework.Common.CommonData;using MECF.Framework.Common.DataCenter;using MECF.Framework.Common.Equipment;using MECF.Framework.Common.OperationCenter;using OpenSEMI.ClientBase;using Prism.Commands;using Prism.Mvvm;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Threading;using PunkHPX8_Core;using PunkHPX8_MainPages.Unity;using PunkHPX8_MainPages.Views;using PunkHPX8_Themes.CustomControls;using PunkHPX8_Themes.Unity;using PunkHPX8_Themes.UserControls;using Aitex.Core.RT.Log;using MECF.Framework.Common.Reservior;using MECF.Framework.Common.ProcessCell;using MECF.Framework.Common.Utilities;using Aitex.Sorter.Common;using MECF.Framework.Common.Schedulers;using MECF.Framework.Common.Beckhoff.Station;using MECF.Framework.Common.Layout;using Aitex.Core.RT.Routine;using Aitex.Core.RT.Device;using System.Reflection;using MECF.Framework.Common.Beckhoff.IOAxis;using MECF.Framework.Common.TwinCat;using LiveCharts.Wpf;using MECF.Framework.Common.Beckhoff.AxisProvider;using QiHe.CodeLib;using MECF.Framework.Common.Jobs;using ExcelLibrary.BinaryFileFormat;namespace PunkHPX8_MainPages.ViewModels{    public class OperationOverNewViewModel : BindableBase    {        #region 常量        private const string CURRENT_STATION = "CurrentStation";        private const string MOTOR_POSITION = "MotorPosition";        private const string MOTION_DATA = "MotionData";        private const double LOADER_ROTATION_DIFFER = 90;        #endregion        #region 私有字段        private bool _isLp1Unable;        private bool _isLp2Unable;        private ModuleInfo _LP1ModuleInfo;        private ModuleInfo _LP2ModuleInfo;        private ModuleInfo _EFEMModuleInfo;        private ModuleInfo _alignerModuleInfo;        private ModuleInfo _srd1ModuleInfo;        private ModuleInfo _srd2ModuleInfo;        private ModuleInfo _dummy1ModuleInfo;        private ModuleInfo _dummy2ModuleInfo;        private WaferRobotTAction m_Robot1TAction;        private WaferRobotXAction m_Robot1XAction;        private WaferRobotTAction m_Robot2TAction;        private WaferRobotXAction m_Robot2XAction;        private WaferRobotFAction m_Robot2FAction;         private RobotMoveInfo m_robotMoveInfo;        private WaferInfo m_srd1Wafer;        private WaferInfo m_srd2Wafer;        private List<string> m_RtDataKeys = new List<string>();        private Dictionary<string, object> m_RtDataValues;        private bool m_EFEMIsInstalled;        private WaferInfo m_EFEMBladeAWafer;        private WaferInfo m_EFEMBladeBWafer;        private WaferInfo m_Aligner1Wafer;        private WaferInfo m_vpw1Wafer;        private WaferInfo m_vpw2Wafer;        private WaferInfo m_platingCell1Wafer;        private WaferInfo m_platingCell2Wafer;        private WaferInfo m_platingCell3Wafer;        private WaferInfo m_platingCell4Wafer;        private int m_LP1WaferCount;        private int m_LP2WaferCount;        private int m_dummy1WaferCount;        private int m_dummy2WaferCount;        private int m_CycledWafer;        private int m_CycleCountDisplay;        private EFEM.RobotPosition m_CurrentRobotPosition;        private WaferInfo m_BladeAWafer;        private WaferInfo m_BladeBWafer;        private string m_RouteState;        /// <summary>        /// 定时器        /// </summary>        private DispatcherTimer _timer;        /// <summary>        /// 是否存在Job        /// </summary>        private bool _isLp1HasNoJob;        private bool _isLp2HasNoJob;        #endregion        #region  属性        public bool IsLP1Unable        {            get { return _isLp1Unable; }            set { SetProperty(ref _isLp1Unable, value); }        }        public bool IsLP2Unable        {            get { return _isLp2Unable; }            set { SetProperty(ref _isLp2Unable, value); }        }        public ModuleInfo LP1ModuleInfo        {            get { return _LP1ModuleInfo; }            set { SetProperty(ref _LP1ModuleInfo, value); }        }        public ModuleInfo EFEMModuleInfo        {            get { return _EFEMModuleInfo; }            set { SetProperty(ref _EFEMModuleInfo, value); }        }        public ModuleInfo AlignerModuleInfo        {            get { return _alignerModuleInfo; }            set { SetProperty(ref _alignerModuleInfo, value); }        }        public ModuleInfo LP2ModuleInfo        {            get { return _LP2ModuleInfo; }            set { SetProperty(ref _LP2ModuleInfo, value); }        }        public ModuleInfo SRD1ModuleInfo        {            get { return _srd1ModuleInfo; }            set { SetProperty(ref _srd1ModuleInfo, value); }        }        public ModuleInfo SRD2ModuleInfo        {            get { return _srd2ModuleInfo; }            set { SetProperty(ref _srd2ModuleInfo, value); }        }         public ModuleInfo Dummy1ModuleInfo        {            get { return _dummy1ModuleInfo; }            set { SetProperty(ref _dummy1ModuleInfo, value); }        }        public ModuleInfo Dummy2ModuleInfo        {            get { return _dummy2ModuleInfo; }            set { SetProperty(ref _dummy2ModuleInfo, value); }        }        public WaferRobotTAction Robot1TAction        {            get { return m_Robot1TAction; }            set { SetProperty(ref m_Robot1TAction, value); }        }        public WaferRobotXAction Robot1XAction        {            get { return m_Robot1XAction; }            set { SetProperty(ref m_Robot1XAction, value); }        }        public WaferRobotTAction Robot2TAction        {            get { return m_Robot2TAction; }            set { SetProperty(ref m_Robot2TAction, value); }        }        public WaferRobotXAction Robot2XAction        {            get { return m_Robot2XAction; }            set { SetProperty(ref m_Robot2XAction, value); }        }        public WaferRobotFAction Robot2FAction        {            get { return m_Robot2FAction; }            set { SetProperty(ref m_Robot2FAction, value); }        }        public RobotMoveInfo RobotMoveInfo        {            get { return m_robotMoveInfo; }            set            {                RobotMoveInfoChanged(m_robotMoveInfo, value);                //m_robotMoveInfo = value;                SetProperty(ref m_robotMoveInfo, value);            }        }        public Dictionary<string, object> RtDataValues        {            get { return m_RtDataValues; }            set { SetProperty(ref m_RtDataValues, value); }        }        public bool EFEMIsInstalled        {            get { return m_EFEMIsInstalled; }            set { SetProperty(ref m_EFEMIsInstalled, value); }        }        public WaferInfo EFEMBladeAWafer        {            get { return m_EFEMBladeAWafer; }            set { SetProperty(ref m_EFEMBladeAWafer, value); }        }        public WaferInfo EFEMBladeBWafer        {            get { return m_EFEMBladeBWafer; }            set { SetProperty(ref m_EFEMBladeBWafer, value); }        }        public WaferInfo Aligner1Wafer        {            get { return m_Aligner1Wafer; }            set { SetProperty(ref m_Aligner1Wafer, value); }        }        public WaferInfo VPW1Wafer        {            get { return m_vpw1Wafer; }            set { SetProperty(ref m_vpw1Wafer, value); }        }        public WaferInfo VPW2Wafer        {            get { return m_vpw2Wafer; }            set { SetProperty(ref m_vpw2Wafer, value); }        }        public WaferInfo PlatingCell1Wafer        {            get { return m_platingCell1Wafer; }            set { SetProperty(ref m_platingCell1Wafer, value); }        }        public WaferInfo PlatingCell2Wafer        {            get { return m_platingCell2Wafer; }            set { SetProperty(ref m_platingCell2Wafer, value); }        }        public WaferInfo PlatingCell3Wafer        {            get { return m_platingCell3Wafer; }            set { SetProperty(ref m_platingCell3Wafer, value); }        }        public WaferInfo PlatingCell4Wafer        {            get { return m_platingCell4Wafer; }            set { SetProperty(ref m_platingCell4Wafer, value); }        }        public WaferInfo SRD1Wafer        {            get { return m_srd1Wafer; }            set { SetProperty(ref m_srd1Wafer, value); }        }        public WaferInfo SRD2Wafer        {             get { return m_srd2Wafer; }            set { SetProperty(ref m_srd2Wafer, value); }        }        public int LP1WaferCount        {            get { return m_LP1WaferCount; }            set { SetProperty(ref m_LP1WaferCount, value); }        }        public int LP2WaferCount        {            get { return m_LP2WaferCount; }            set { SetProperty(ref m_LP2WaferCount, value); }        }        public int Dummy1WaferCount        {            get { return m_dummy1WaferCount; }            set { SetProperty(ref m_dummy1WaferCount, value); }        }        public int Dummy2WaferCount        {            get { return m_dummy2WaferCount; }            set { SetProperty(ref m_dummy2WaferCount, value); }        }        public int CycledWafer        {            get { return m_CycledWafer; }            set { SetProperty(ref m_CycledWafer, value); }        }        public int CycleCountDisplay        {            get { return m_CycleCountDisplay; }            set { SetProperty(ref m_CycleCountDisplay, value); }        }        public RobotMoveInfo m_EfemRobotMoveInfo;        public RobotMoveInfo EfemRobotMoveInfo        {            get { return m_EfemRobotMoveInfo; }            set            {                EFEMRobotMoveInfoChanged(m_EfemRobotMoveInfo, value);                //m_EfemRobotMoveInfo = value;                SetProperty(ref m_EfemRobotMoveInfo, value);            }        }        public EFEM.RobotPosition CurrentRobotPosition        {            get { return m_CurrentRobotPosition; }            set { SetProperty(ref m_CurrentRobotPosition, value); }        }        public WaferInfo BladeAWafer        {            get { return m_BladeAWafer; }            set { SetProperty(ref m_BladeAWafer, value); }        }        public WaferInfo BladeBWafer        {            get { return m_BladeBWafer; }            set { SetProperty(ref m_BladeBWafer, value); }        }              public string RouteState        {            get { return m_RouteState; }            set { SetProperty(ref m_RouteState, value); }        }        public bool IsLP1HasNoJob        {            get { return _isLp1HasNoJob; }            set { SetProperty(ref _isLp1HasNoJob, value); }        }        public bool IsLP2HasNoJob        {            get { return _isLp2HasNoJob; }            set { SetProperty(ref _isLp2HasNoJob, value); }        }        #endregion        #region 命令        private DelegateCommand<object> _MapCommand;        public DelegateCommand<object> MapCommand =>            _MapCommand ?? (_MapCommand = new DelegateCommand<object>(OnMap));        private DelegateCommand<object> _StartCommand;        public DelegateCommand<object> StartCommand =>            _StartCommand ?? (_StartCommand = new DelegateCommand<object>(OnStart));        private DelegateCommand<object> _StopCommand;        public DelegateCommand<object> StopCommand =>            _StopCommand ?? (_StopCommand = new DelegateCommand<object>(OnStop));        private DelegateCommand<object> _AbortCommand;        public DelegateCommand<object> AbortCommand =>            _AbortCommand ?? (_AbortCommand = new DelegateCommand<object>(OnAbort));        private DelegateCommand _HomeAllCommand;        public DelegateCommand HomeAllCommand =>            _HomeAllCommand ?? (_HomeAllCommand = new DelegateCommand(OnHomeAll));        private DelegateCommand _ResumeAllJobCommand;        public DelegateCommand ResumeAllJobCommand =>            _ResumeAllJobCommand ?? (_ResumeAllJobCommand = new DelegateCommand(OnResumeAllJob));        private DelegateCommand _AbortAllCommand;        public DelegateCommand AbortAllCommand =>            _AbortAllCommand ?? (_AbortAllCommand = new DelegateCommand(OnAbortAll));        private DelegateCommand _ReturnAllWaferCommand;        public DelegateCommand ReturnAllWaferCommand =>            _ReturnAllWaferCommand ?? (_ReturnAllWaferCommand = new DelegateCommand(OnReturnAllWafer));        private DelegateCommand<object> _SetSequenceCommand;        public DelegateCommand<object> SetSequenceCommand =>            _SetSequenceCommand ?? (_SetSequenceCommand = new DelegateCommand<object>(OnSetSequence));        private DelegateCommand _EnableAutoCommand;        public DelegateCommand EnableAutoCommand =>            _EnableAutoCommand ?? (_EnableAutoCommand = new DelegateCommand(OnEnableAuto));        private DelegateCommand _EnableManualCommand;        public DelegateCommand EnableManualCommand =>            _EnableManualCommand ?? (_EnableManualCommand = new DelegateCommand(OnEnableManual));        private DelegateCommand<object> _GotoSrdViewCommond;        public DelegateCommand<object> GotoSrdViewCommond =>            _GotoSrdViewCommond ?? (_GotoSrdViewCommond = new DelegateCommand<object>(GotoSrdViewAction));        public bool SwitchFlag;                #endregion        #region 构造函数        public OperationOverNewViewModel()        {            addDataKeys();        }        #endregion        #region 命令方法        /// <summary>        /// 加载数据        /// </summary>        public void LoadData(string systemName)        {            Dictionary<string, object> allModulesDictionary = QueryDataClient.Instance.Service.PollData(new List<string>() { "System.InstalledModules" });            if (allModulesDictionary != null)            {                List<string> allModules = CommonFunction.GetValue<List<string>>(allModulesDictionary, "System.InstalledModules");                EFEMIsInstalled = allModules.Contains("EFEM");            }            if (_timer == null)            {                _timer = new DispatcherTimer();                _timer.Interval = TimeSpan.FromMilliseconds(100);                _timer.Tick += Timer_Tick;            }            _timer.Start();            RtDataValues = QueryDataClient.Instance.Service.PollData(m_RtDataKeys);        }                /// <summary>        /// 隐藏        /// </summary>        public void Hide()        {            if (_timer != null)            {                _timer.Stop();            }        }                private void OnMap(object obj)        {            InvokeClient.Instance.Service.DoOperation($"{obj.ToString()}.Map");        }        private void OnStart(object obj)        {            var info = obj as WaferAssociationInfo;            InvokeClient.Instance.Service.DoOperation("System.StartJob", info.LotId);        }        private void OnStop(object obj)        {            var info = obj as WaferAssociationInfo;            InvokeClient.Instance.Service.DoOperation("System.PauseJob", info.JobID);        }        private void OnAbort(object obj)        {            var info = obj as WaferAssociationInfo;            InvokeClient.Instance.Service.DoOperation("System.ResumeJob", info.JobID);        }        private void OnHomeAll()        {            InvokeClient.Instance.Service.DoOperation("System.HomeAll");        }        private void OnResumeAllJob()        {            if (CommonFunction.GetValue<int>(RtDataValues, "EquipmentStatus") == 4)            {                InvokeClient.Instance.Service.DoOperation("System.ResumeAllJob");            }            else            {                InvokeClient.Instance.Service.DoOperation("System.PauseAllJob");            }        }        private void OnAbortAll()        {            InvokeClient.Instance.Service.DoOperation("System.Abort");        }        private void OnReturnAllWafer()        {            //Dialog            WaferDialogView dialog = new WaferDialogView()            {                Owner = Application.Current.MainWindow,            };            dialog.Height = 300;            dialog.Width = 400;            double angel = 0;            double coolingtime = 0;            string message = "Please Confirm Return Wafer";            WaferDialogViewModel vm = new WaferDialogViewModel();            vm.ConfirmText = message;            dialog.DataContext = vm;            if (dialog.ShowDialog() == true)            {                if ((bool)dialog.AlignFlag == true && !string.IsNullOrEmpty(dialog.Angle))                {                    angel = Convert.ToDouble(dialog.Angle);                }                if ((bool)dialog.CoolingFlag == true && !string.IsNullOrEmpty(dialog.CoolingTime))                {                    coolingtime = Convert.ToDouble(dialog.CoolingTime);                }                InvokeClient.Instance.Service.DoOperation("System.ReturnAllWafer", dialog.CoolingFlag, coolingtime, dialog.AlignFlag, angel);            }        }        private void OnSetSequence(object obj)        {            var info = obj as WaferInfo;            bool flag = info.SequenceName != "" ? false : true;        }        private void OnEnableAuto()        {            InvokeClient.Instance.Service.DoOperation("System.SetAutoMode");        }        private void OnEnableManual()        {            InvokeClient.Instance.Service.DoOperation("System.SetManualMode");        }        private void GotoSrdViewAction(object obj)        {            PunkHPX8_Core.GlobalEvents.OnSwitchFixedTabItem("HardWare", "SRD", $"{obj.ToString()}");        }                #endregion        #region 私有方法        /// <summary>        /// 定时器        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void Timer_Tick(object sender, EventArgs e)        {            LP1ModuleInfo = ModuleManager.ModuleInfos["LP1"];            LP2ModuleInfo = ModuleManager.ModuleInfos["LP2"];            EFEMModuleInfo = ModuleManager.ModuleInfos["EfemRobot"];            SRD1ModuleInfo = ModuleManager.ModuleInfos["SRD1"];            SRD2ModuleInfo = ModuleManager.ModuleInfos["SRD2"];            Dummy1ModuleInfo = ModuleManager.ModuleInfos["Dummy1"];            Dummy2ModuleInfo = ModuleManager.ModuleInfos["Dummy2"];            AlignerModuleInfo = ModuleManager.ModuleInfos["Aligner1"];            if (ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers.Count != 0)            {                BladeAWafer = ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers[0];                BladeBWafer = ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers[1];            }            if (EFEMIsInstalled == true)            {                if (ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers.Count != 0)                {                    EFEMBladeAWafer = ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers[0];                    EFEMBladeBWafer = ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers[1];                }                if (ModuleManager.ModuleInfos["Aligner1"].WaferManager.Wafers.Count != 0)                {                    Aligner1Wafer = ModuleManager.ModuleInfos["Aligner1"].WaferManager.Wafers[0];                }            }            if (ModuleManager.ModuleInfos["VPW1"].WaferManager.Wafers.Count != 0)            {                VPW1Wafer = ModuleManager.ModuleInfos["VPW1"].WaferManager.Wafers[0];            }            if (ModuleManager.ModuleInfos["VPW2"].WaferManager.Wafers.Count != 0)            {                VPW2Wafer = ModuleManager.ModuleInfos["VPW2"].WaferManager.Wafers[0];            }            if (ModuleManager.ModuleInfos["PlatingCell1"].WaferManager.Wafers.Count!=0)            {                PlatingCell1Wafer = ModuleManager.ModuleInfos["PlatingCell1"].WaferManager.Wafers[0];            }            if (ModuleManager.ModuleInfos["PlatingCell2"].WaferManager.Wafers.Count != 0)            {                PlatingCell2Wafer = ModuleManager.ModuleInfos["PlatingCell2"].WaferManager.Wafers[0];            }            if (ModuleManager.ModuleInfos["PlatingCell3"].WaferManager.Wafers.Count != 0)            {                PlatingCell3Wafer = ModuleManager.ModuleInfos["PlatingCell3"].WaferManager.Wafers[0];            }            if (ModuleManager.ModuleInfos["PlatingCell4"].WaferManager.Wafers.Count != 0)            {                PlatingCell4Wafer = ModuleManager.ModuleInfos["PlatingCell4"].WaferManager.Wafers[0];            }            if (SRD1ModuleInfo != null&& SRD1ModuleInfo.WaferManager.Wafers.Count!=0)            {                SRD1Wafer = SRD1ModuleInfo.WaferManager.Wafers[0];            }            if (SRD2ModuleInfo != null&& SRD2ModuleInfo.WaferManager.Wafers.Count!=0)            {                SRD2Wafer = SRD2ModuleInfo.WaferManager.Wafers[0];            }            EfemRobotMoveInfo = (RobotMoveInfo)QueryDataClient.Instance.Service.GetData("EFEM.RobotMoveAction");            LP1WaferCount = LP1ModuleInfo.WaferManager.Wafers.Where(x => x.WaferStatus != 0).Count();            LP2WaferCount = LP2ModuleInfo.WaferManager.Wafers.Where(x => x.WaferStatus != 0).Count();            //Dummy1WaferCount = 15;            Dummy1WaferCount = Dummy1ModuleInfo.WaferManager.Wafers.Where(x => x.WaferStatus != 0).Count();            Dummy2WaferCount = Dummy2ModuleInfo.WaferManager.Wafers.Where(x => x.WaferStatus != 0).Count();            RtDataValues = QueryDataClient.Instance.Service.PollData(m_RtDataKeys);            IsLP1Unable = (bool)QueryDataClient.Instance.Service.GetConfig("EFEM.IsLoadPort1Unable");            IsLP2Unable = (bool)QueryDataClient.Instance.Service.GetConfig("EFEM.IsLoadPort2Unable");            if (RtDataValues != null)            {                if (CommonFunction.GetValue<int>(RtDataValues, "EquipmentStatus") == 4)                {                    RouteState = "Resume";                }                else                {                    RouteState = "Pause";                }                ControlJobInfo lp1Cj = CommonFunction.GetValue<ControlJobInfo>(RtDataValues, "LP1.CurrentControlJob");                IsLP1HasNoJob = lp1Cj == null ? true : false;                ControlJobInfo lp2Cj = CommonFunction.GetValue<ControlJobInfo>(RtDataValues, "LP2.CurrentControlJob");                IsLP2HasNoJob = lp2Cj == null ? true : false;            }        }        int count = 0;                private async void RobotMoveInfoChanged(RobotMoveInfo oldValue, RobotMoveInfo newValue)        {            string RobotTarget;            if (oldValue == null || newValue == null)            {                return;            }            #region Rotating            if ((oldValue.Action == RobotAction.None || oldValue.ArmTarget != newValue.ArmTarget) && (newValue.Action == RobotAction.Rotating))            {                var TMRobotMoveActionBladeTarget = newValue.BladeTarget;                if (TMRobotMoveActionBladeTarget != null)                {                    RobotTarget = TMRobotMoveActionBladeTarget.ToString();                }                else                {                    return;                }                var values = RobotTarget.Split('.');                var arm = values[0];                var module = values[1];                if (arm == "ArmA")                {                    Robot1TAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true);                }                else if (arm == "ArmB")                {                    Robot2TAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true);                }            }            #endregion            #region pick 和 place LL            else if ((oldValue.Action == RobotAction.None || oldValue.ArmTarget != newValue.ArmTarget) && (newValue.Action == RobotAction.Placing || newValue.Action == RobotAction.Picking))            {                var TMRobotMoveActionBladeTarget = newValue.BladeTarget;                if (TMRobotMoveActionBladeTarget != null)                {                    RobotTarget = TMRobotMoveActionBladeTarget.ToString();                }                else                {                    return;                }                var values = RobotTarget.Split('.');                var arm = values[0];                var module = values[1];                if (arm == "ArmA")                {                    var waferRobotTAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true);                    if (waferRobotTAction != Robot1TAction)                    {                        Robot1TAction = waferRobotTAction;                    }                    else                    {                        //await Task.Delay(100);                    }                    await Task.Delay(600);                    //Robot1TAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true);                    //await Task.Delay(600);                    Robot1XAction = WaferRobotXAction.Extend;                    while ((newValue.Action == RobotAction.Placing && ModuleManager.ModuleInfos["TMRobot"].WaferManager.Wafers[0].WaferStatus != 0) || (newValue.Action == RobotAction.Picking && ModuleManager.ModuleInfos["TMRobot"].WaferManager.Wafers[0].WaferStatus == 0))                    {                        await Task.Delay(100);                    }                    Robot1XAction = WaferRobotXAction.Retract;                }                else if (arm == "ArmB")                {                    var waferRobotTAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true);                    if (waferRobotTAction != Robot2TAction)                    {                        Robot2TAction = waferRobotTAction;                    }                    else                    {                        //await Task.Delay(100);                    }                    await Task.Delay(600);                    //Robot2TAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true);                    //await Task.Delay(600);                    Robot2XAction = WaferRobotXAction.Extend;                    while ((newValue.Action == RobotAction.Placing && ModuleManager.ModuleInfos["TMRobot"].WaferManager.Wafers[1].WaferStatus != 0) || (newValue.Action == RobotAction.Picking && ModuleManager.ModuleInfos["TMRobot"].WaferManager.Wafers[1].WaferStatus == 0))                    {                        await Task.Delay(100);                    }                    Robot2XAction = WaferRobotXAction.Retract;                }            }            #endregion            #region pick 和 place pm            else if ((oldValue.Action == RobotAction.None || oldValue.ArmTarget != newValue.ArmTarget) && newValue.Action == RobotAction.Extending)            {                var TMRobotMoveActionBladeTarget = newValue.BladeTarget;                if (TMRobotMoveActionBladeTarget != null)                {                    RobotTarget = TMRobotMoveActionBladeTarget.ToString();                }                else                {                    return;                }                var values = RobotTarget.Split('.');                var arm = values[0];                var module = values[1];                if (arm == "ArmA")                {                    var waferRobotTAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true);                    if (waferRobotTAction != Robot1TAction)                    {                        Robot1TAction = waferRobotTAction;                    }                    else                    {                        // await Task.Delay(100);                    }                    await Task.Delay(600);                    Robot1XAction = WaferRobotXAction.Extend;                }                else if (arm == "ArmB")                {                    var waferRobotTAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true);                    if (waferRobotTAction != Robot2TAction)                    {                        Robot2TAction = waferRobotTAction;                    }                    else                    {                        // await Task.Delay(100);                    }                    await Task.Delay(600);                    Robot2XAction = WaferRobotXAction.Extend;                }            }            else if ((oldValue.Action == RobotAction.None || oldValue.ArmTarget != newValue.ArmTarget) && newValue.Action == RobotAction.Retracting)            {                var TMRobotMoveActionBladeTarget = newValue.BladeTarget;                if (TMRobotMoveActionBladeTarget != null)                {                    RobotTarget = TMRobotMoveActionBladeTarget.ToString();                }                else                {                    return;                }                var values = RobotTarget.Split('.');                var arm = values[0];                if (arm == "ArmA")                {                    Robot1XAction = WaferRobotXAction.Retract;                }                else if (arm == "ArmB")                {                    Robot2XAction = WaferRobotXAction.Retract;                }            }            #endregion            #region Home            else if (oldValue.Action == RobotAction.None && newValue.Action == RobotAction.Homing)            {                if (Robot1XAction == WaferRobotXAction.Extend)                {                    Robot1XAction = WaferRobotXAction.Retract;                }                if (Robot2XAction == WaferRobotXAction.Extend)                {                    Robot2XAction = WaferRobotXAction.Retract;                }                await Task.Delay(2000);                if (Robot1TAction != WaferRobotTAction.T_Origin)                {                    Robot1TAction = WaferRobotTAction.T_Origin;                }                if (Robot2TAction != WaferRobotTAction.T_Origin)                {                    Robot2TAction = WaferRobotTAction.T_Origin;                }            }            #endregion        }        private async void EFEMRobotMoveInfoChanged(RobotMoveInfo oldValue, RobotMoveInfo newValue)        {            string RobotTarget;            if (oldValue == null || newValue == null)            {                return;            }            if ((oldValue.Action == RobotAction.None || oldValue.ArmTarget != newValue.ArmTarget) && (newValue.Action == RobotAction.Placing || newValue.Action == RobotAction.Picking))            {                var TMRobotMoveActionBladeTarget = newValue.BladeTarget;                if (TMRobotMoveActionBladeTarget != null)                {                    RobotTarget = TMRobotMoveActionBladeTarget.ToString();                }                else                {                    return;                }                var values = RobotTarget.Split('.');                var arm = values[0];                var module = values[1];                if (arm == "ArmA")                {                    var robot1Robot1TAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true);                    //Robot整体平移动画                    await ChangePosition(robot1Robot1TAction, newValue.Action);                    if (Robot1TAction != robot1Robot1TAction)                    {                        Robot1TAction = robot1Robot1TAction;                        await Task.Delay(600);                    }                    //await Task.Delay(1500);                    Robot1XAction = WaferRobotXAction.Extend;                    while ((newValue.Action == RobotAction.Placing && ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers[0].WaferStatus != 0) || (newValue.Action == RobotAction.Picking && ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers[0].WaferStatus == 0))                    {                        await Task.Delay(100);                    }                    Robot1XAction = WaferRobotXAction.Retract;                    if (newValue.Action == RobotAction.Placing)                    {                        await ChangePosition(WaferRobotTAction.T_Origin, newValue.Action);                    }                }                else  //使用上手臂                {                    //实现翻转动画                    if (newValue.BladeTarget.Split('.')[2] == "Down")                    {                        Robot2FAction = WaferRobotFAction.UpperToDown;                    }                    else if (newValue.BladeTarget.Split('.')[2] == "Upper")                    {                        Robot2FAction = WaferRobotFAction.DownToUpper;                    }                    var robot1Robot1TAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true);                    //Robot整体平移动画                    await ChangePosition(robot1Robot1TAction, newValue.Action);                    if (Robot1TAction != robot1Robot1TAction)                    {                        Robot1TAction = robot1Robot1TAction;                        await Task.Delay(600);                    }                    //await Task.Delay(1500);                    Robot1XAction = WaferRobotXAction.Extend2;                    while ((newValue.Action == RobotAction.Placing && ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers[1].WaferStatus != 0) || (newValue.Action == RobotAction.Picking && ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers[1].WaferStatus == 0))                    {                        await Task.Delay(100);                    }                    Robot1XAction = WaferRobotXAction.Retract2;                    if (newValue.Action == RobotAction.Placing)                    {                        await ChangePosition(WaferRobotTAction.T_Origin, newValue.Action);                    }                }            }            #region Home            else if (oldValue.Action == RobotAction.None && newValue.Action == RobotAction.Homing)            {                if (Robot1XAction == WaferRobotXAction.Extend || Robot2XAction == WaferRobotXAction.Extend2)                {                    Robot1XAction = WaferRobotXAction.Retract2;                }                if (Robot2XAction == WaferRobotXAction.Extend || Robot2XAction == WaferRobotXAction.Extend2)                {                    Robot2XAction = WaferRobotXAction.Retract2;                }                await Task.Delay(2000);                if (Robot1TAction != WaferRobotTAction.T_Origin)                {                    Robot1TAction = WaferRobotTAction.T_Origin;                }                if (Robot2TAction != WaferRobotTAction.T_Origin)                {                    Robot2TAction = WaferRobotTAction.T_Origin;                }                if (CurrentRobotPosition != EFEM.RobotPosition.Origin)                {                    CurrentRobotPosition = EFEM.RobotPosition.Origin;                }                await ChangePosition(WaferRobotTAction.T_Origin, newValue.Action);            }            #endregion        }        private void addDataKeys()        {            m_RtDataKeys.Add("LP1.IsLoaded");            m_RtDataKeys.Add("LP2.IsLoaded");            m_RtDataKeys.Add("LP1.CassettePlaced");            m_RtDataKeys.Add("LP2.CassettePlaced");            m_RtDataKeys.Add("LP1.CurrentControlJob");            m_RtDataKeys.Add("LP2.CurrentControlJob");            m_RtDataKeys.Add("LP1.WaferSize");            m_RtDataKeys.Add("LP2.WaferSize");            m_RtDataKeys.Add("Dummy1.CassettePlaced");             m_RtDataKeys.Add("Dummy2.CassettePlaced");            m_RtDataKeys.Add("Dummy1.WaferSize");            m_RtDataKeys.Add("Dummy2.WaferSize");            m_RtDataKeys.Add("System.IsAutoMode");            m_RtDataKeys.Add("System.IsBusy");                  m_RtDataKeys.Add("Scheduler.CycledCount");            m_RtDataKeys.Add("Scheduler.CycledWafer");            m_RtDataKeys.Add("Scheduler.CycleSetPoint");            m_RtDataKeys.Add("Scheduler.Throughput");            m_RtDataKeys.Add("EquipmentStatus");            m_RtDataKeys.Add("Scheduler.PjNameList");            m_RtDataKeys.Add("Scheduler.CjNameList");        }               private bool HasWaferOnSlot(List<WaferInfo> wafers, int index)        {            if (wafers[index].WaferStatus == 0)                return false;            return true;        }        private async Task ChangePosition(WaferRobotTAction waferRobotTAction, RobotAction robotAction)        {            //CurrentRobotPosition = RobotPosition.Origin;            //await Task.Delay(1000);            if (robotAction == RobotAction.Placing)            {                if (waferRobotTAction == WaferRobotTAction.LP1)                {                    CurrentRobotPosition = EFEM.RobotPosition.Left_Place;                }                else if (waferRobotTAction == WaferRobotTAction.LP2)                {                    CurrentRobotPosition = EFEM.RobotPosition.Middle_Place;                }                else if (waferRobotTAction == WaferRobotTAction.Aligner1)                {                    CurrentRobotPosition = EFEM.RobotPosition.Aligner_Place;                }                else if (waferRobotTAction == WaferRobotTAction.SRD1 || waferRobotTAction == WaferRobotTAction.SRD2)                {                    CurrentRobotPosition = EFEM.RobotPosition.SRD_Place;                }                else if (waferRobotTAction == WaferRobotTAction.Dummy1 || waferRobotTAction == WaferRobotTAction.Dummy2)                {                    CurrentRobotPosition = EFEM.RobotPosition.Dummy_Place;                }                else if (waferRobotTAction == WaferRobotTAction.VPW1)                {                    CurrentRobotPosition = EFEM.RobotPosition.VPW1_Place;                }                else if (waferRobotTAction == WaferRobotTAction.VPW2)                {                    CurrentRobotPosition = EFEM.RobotPosition.VPW2_Place;                }                else if (waferRobotTAction == WaferRobotTAction.PlatingCell1)                {                    CurrentRobotPosition = EFEM.RobotPosition.PlatingCell1_Place;                }                else if (waferRobotTAction == WaferRobotTAction.PlatingCell2)                {                    CurrentRobotPosition = EFEM.RobotPosition.PlatingCell2_Place;                }                else if (waferRobotTAction == WaferRobotTAction.PlatingCell3)                {                    CurrentRobotPosition = EFEM.RobotPosition.PlatingCell3_Place;                }                else if (waferRobotTAction == WaferRobotTAction.PlatingCell4)                {                    CurrentRobotPosition = EFEM.RobotPosition.PlatingCell4_Place;                }                else                {                    CurrentRobotPosition = EFEM.RobotPosition.Origin;                }            }            else            {                if (waferRobotTAction == WaferRobotTAction.LP1)                {                    CurrentRobotPosition = EFEM.RobotPosition.Left;                }                else if (waferRobotTAction == WaferRobotTAction.LP2)                {                    CurrentRobotPosition = EFEM.RobotPosition.Middle;                }                else if (waferRobotTAction == WaferRobotTAction.Aligner1)                {                    CurrentRobotPosition = EFEM.RobotPosition.Aligner;                }                else if (waferRobotTAction == WaferRobotTAction.SRD1 || waferRobotTAction == WaferRobotTAction.SRD2)                {                    CurrentRobotPosition = EFEM.RobotPosition.SRD;                }                else if (waferRobotTAction == WaferRobotTAction.Dummy1 || waferRobotTAction == WaferRobotTAction.Dummy2)                {                    CurrentRobotPosition = EFEM.RobotPosition.Dummy;                }                else if (waferRobotTAction == WaferRobotTAction.VPW1)                {                    CurrentRobotPosition = EFEM.RobotPosition.VPW1;                }                else if (waferRobotTAction == WaferRobotTAction.VPW2)                {                    CurrentRobotPosition = EFEM.RobotPosition.VPW2;                }                else if (waferRobotTAction == WaferRobotTAction.PlatingCell1)                {                    CurrentRobotPosition = EFEM.RobotPosition.PlatingCell1;                }                else if (waferRobotTAction == WaferRobotTAction.PlatingCell2)                {                    CurrentRobotPosition = EFEM.RobotPosition.PlatingCell2;                }                else if (waferRobotTAction == WaferRobotTAction.PlatingCell3)                {                    CurrentRobotPosition = EFEM.RobotPosition.PlatingCell3;                }                else if (waferRobotTAction == WaferRobotTAction.PlatingCell4)                {                    CurrentRobotPosition = EFEM.RobotPosition.PlatingCell4;                }                else                {                    CurrentRobotPosition = EFEM.RobotPosition.Origin;                }            }            await Task.Delay(600);        }        /// <summary>        /// 计算最大值最小值        /// </summary>        /// <param name="Puf1RotationAxis"></param>        /// <returns></returns>        private (double right, double left) CalculatePufMaxMin(BeckhoffStationAxis pufAxis)        {            if (pufAxis == null || pufAxis.Stations.Count == 0) return (-1,-1);            double max = double.Parse(pufAxis.Stations[0].Position);            double min = double.Parse(pufAxis.Stations[0].Position);            double home = 0;            double pickup = 0;            foreach (Station item in pufAxis.Stations)            {                if (item.Name.ToLower().Contains("home")) home = double.Parse(item.Position);                if (item.Name.ToLower().Contains("pickup")) pickup = double.Parse(item.Position);                double position = double.Parse(item.Position);                if (position > max)                {                    max = position;                }                if (position < min)                {                    min = position;                }            }                        return pickup < home ? (min, max):(max, min);        }        /// <summary>        /// 计算PufFlip差值        /// </summary>        /// <param name="pufAxis"></param>        /// <returns></returns>        private double CalculatePufFlipDiff(BeckhoffStationAxis pufAxis)        {            double sideAangle = 0;            double sideBangle = 0; ;            return sideAangle > sideBangle ? 180 : 0;        }        /// <summary>        /// 判定是否在station位置        /// </summary>        private bool JudgeAtStation(double targetPosition, double currentPosition, double tolerance)        {                        if (Math.Abs(currentPosition - targetPosition) <= tolerance)            {                return true;            }            else            {                return false;            }        }                #endregion    }}
 |