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 Venus_MainPages.Unity; using Venus_MainPages.Views; using Venus_Themes.CustomControls; using Venus_Themes.Unity; namespace Venus_MainPages.ViewModels { public class OperationOverViewModel : BindableBase { #region 私有字段 private bool m_TabIsChecked=true; private ModuleInfo m_LP1ModuleInfo; private ModuleInfo m_LP2ModuleInfo; private ModuleInfo m_LLAModuleInfo; private ModuleInfo m_LLBModuleInfo; private ModuleInfo m_LP3ModuleInfo; private ModuleInfo m_EFEMModuleInfo; private ModuleInfo m_TMModuleInfo; private WaferRobotTAction m_Robot1TAction; private WaferRobotXAction m_Robot1XAction; private WaferRobotTAction m_Robot2TAction; private WaferRobotXAction m_Robot2XAction; private RobotMoveInfo m_robotMoveInfo; int arm1oldWaferStatus = 100; int arm2oldWaferStatus = 100; private WaferInfo m_PMAWafer; private WaferInfo m_PMBWafer; private WaferInfo m_PMCWafer; private WaferInfo m_PMDWafer; private WaferInfo m_LLAWafer; private WaferInfo m_LLBWafer; private WaferInfo m_TMBladeAWafer; private WaferInfo m_TMBladeBWafer; private List m_RtDataKeys = new List(); private Dictionary m_RtDataValues; private bool m_PMAIsInstalled; private bool m_PMBIsInstalled; private bool m_PMCIsInstalled; private bool m_PMDIsInstalled; private bool m_LLAIsInstalled; private bool m_LLBIsInstalled; private bool m_TMIsInstalled; private bool m_EFEMIsInstalled; private WaferInfo m_EFEMBladeAWafer; private WaferInfo m_EFEMBladeBWafer; private WaferInfo m_Aligner1Wafer; private int m_LP1WaferCount; private int m_LP2WaferCount; private int m_LP3WaferCount; private WaferAssociationInfo _lp1WaferAssociation; private WaferAssociationInfo _lp2WaferAssociation; private WaferAssociationInfo _lp3WaferAssociation; #endregion #region 属性 public bool TabIsChecked { get { return m_TabIsChecked; } set { SetProperty(ref m_TabIsChecked, value); } } public ModuleInfo LP1ModuleInfo { get { return m_LP1ModuleInfo; } set { SetProperty(ref m_LP1ModuleInfo, value); } } public ModuleInfo LLAModuleInfo { get { return m_LLAModuleInfo; } set { SetProperty(ref m_LLAModuleInfo, value); } } public ModuleInfo LLBModuleInfo { get { return m_LLBModuleInfo; } set { SetProperty(ref m_LLBModuleInfo, value); } } public ModuleInfo EFEMModuleInfo { get { return m_EFEMModuleInfo; } set { SetProperty(ref m_EFEMModuleInfo, value); } } public ModuleInfo TMModuleInfo { get { return m_TMModuleInfo; } set { SetProperty(ref m_TMModuleInfo, value); } } public ModuleInfo LP2ModuleInfo { get { return m_LP2ModuleInfo; } set { SetProperty(ref m_LP2ModuleInfo, value); } } public ModuleInfo LP3ModuleInfo { get { return m_LP3ModuleInfo; } set { SetProperty(ref m_LP3ModuleInfo, 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 RobotMoveInfo RobotMoveInfo { get { return m_robotMoveInfo; } set { RobotMoveInfoChanged(m_robotMoveInfo, value); m_robotMoveInfo = value; } } public WaferInfo LLAWafer { get { return m_LLAWafer; } set { SetProperty(ref m_LLAWafer, value); } } public WaferInfo LLBWafer { get { return m_LLBWafer; } set { SetProperty(ref m_LLBWafer, value); } } public WaferInfo PMAWafer { get { return m_PMAWafer; } set { SetProperty(ref m_PMAWafer, value); } } public WaferInfo PMBWafer { get { return m_PMBWafer; } set { SetProperty(ref m_PMBWafer, value); } } public WaferInfo PMCWafer { get { return m_PMCWafer; } set { SetProperty(ref m_PMCWafer, value); } } public WaferInfo PMDWafer { get { return m_PMDWafer; } set { SetProperty(ref m_PMDWafer, value); } } public WaferInfo TMBladeAWafer { get { return m_TMBladeAWafer; } set { SetProperty(ref m_TMBladeAWafer, value); } } public WaferInfo TMBladeBWafer { get { return m_TMBladeBWafer; } set { SetProperty(ref m_TMBladeBWafer, value); } } public Dictionary RtDataValues { get { return m_RtDataValues; } set { SetProperty(ref m_RtDataValues, value); } } public bool PMAIsInstalled { get { return m_PMAIsInstalled; } set { SetProperty(ref m_PMAIsInstalled, value); } } public bool PMBIsInstalled { get { return m_PMBIsInstalled; } set { SetProperty(ref m_PMBIsInstalled, value); } } public bool PMCIsInstalled { get { return m_PMCIsInstalled; } set { SetProperty(ref m_PMCIsInstalled, value); } } public bool PMDIsInstalled { get { return m_PMDIsInstalled; } set { SetProperty(ref m_PMDIsInstalled, value); } } public bool LLAIsInstalled { get { return m_LLAIsInstalled; } set { SetProperty(ref m_LLAIsInstalled, value); } } public bool LLBIsInstalled { get { return m_LLBIsInstalled; } set { SetProperty(ref m_LLBIsInstalled, value); } } public bool TMIsInstalled { get { return m_TMIsInstalled; } set { SetProperty(ref m_TMIsInstalled, 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 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 LP3WaferCount { get { return m_LP3WaferCount; } set { SetProperty(ref m_LP3WaferCount, value); } } public WaferAssociationInfo LP1WaferAssociation { get { return _lp1WaferAssociation; } set { SetProperty(ref _lp1WaferAssociation, value); } } public WaferAssociationInfo LP2WaferAssociation { get { return _lp2WaferAssociation; } set { SetProperty(ref _lp2WaferAssociation, value); } } public WaferAssociationInfo LP3WaferAssociation { get { return _lp3WaferAssociation; } set { SetProperty(ref _lp3WaferAssociation, value); } } #endregion #region 命令 private DelegateCommand _LoadCommand; public DelegateCommand LoadCommand => _LoadCommand ?? (_LoadCommand = new DelegateCommand(OnLoad)); private DelegateCommand _LoadWaferCommand; public DelegateCommand LoadWaferCommand => _LoadWaferCommand ?? (_LoadWaferCommand = new DelegateCommand(OnLoadWafer)); private DelegateCommand _UnLoadWaferCommand; public DelegateCommand UnLoadWaferCommand => _UnLoadWaferCommand ?? (_UnLoadWaferCommand = new DelegateCommand(OnUnLoadWafer)); private DelegateCommand _SelectAllCommand; public DelegateCommand SelectAllCommand => _SelectAllCommand ?? (_SelectAllCommand = new DelegateCommand(OnSelectAll)); private DelegateCommand _UnSelectAllCommand; public DelegateCommand UnSelectAllCommand => _UnSelectAllCommand ?? (_UnSelectAllCommand = new DelegateCommand(OnUnSelectAll)); private DelegateCommand _StartCommand; public DelegateCommand StartCommand => _StartCommand ?? (_StartCommand = new DelegateCommand(OnStart)); private DelegateCommand _StopCommand; public DelegateCommand StopCommand => _StopCommand ?? (_StopCommand = new DelegateCommand(OnStop)); private DelegateCommand _AbortCommand; public DelegateCommand AbortCommand => _AbortCommand ?? (_AbortCommand = new DelegateCommand(OnAbort)); private DelegateCommand _HomeAllCommand; public DelegateCommand HomeAllCommand => _HomeAllCommand ?? (_HomeAllCommand = new DelegateCommand(OnHomeAll)); private DelegateCommand _PauseAllJobCommand; public DelegateCommand PauseAllJobCommand => _PauseAllJobCommand ?? (_PauseAllJobCommand = new DelegateCommand(OnPauseAllJob)); private DelegateCommand _AbortAllCommand; public DelegateCommand AbortAllCommand => _AbortAllCommand ?? (_AbortAllCommand = new DelegateCommand(OnAbortAll)); private DelegateCommand _ReturnAllWaferCommand; public DelegateCommand ReturnAllWaferCommand => _ReturnAllWaferCommand ?? (_ReturnAllWaferCommand = new DelegateCommand(OnReturnAllWafer)); private DelegateCommand _SetSequenceCommand; public DelegateCommand SetSequenceCommand => _SetSequenceCommand ?? (_SetSequenceCommand = new DelegateCommand(OnSetSequence)); private DelegateCommand _CreateJobCommand; public DelegateCommand CreateJobCommand => _CreateJobCommand ?? (_CreateJobCommand = new DelegateCommand(OnCreateJob)); private DelegateCommand _EnableAutoCommand; public DelegateCommand EnableAutoCommand => _EnableAutoCommand ?? (_EnableAutoCommand = new DelegateCommand(OnEnableAuto)); private DelegateCommand _EnableManualCommand; public DelegateCommand EnableManualCommand => _EnableManualCommand ?? (_EnableManualCommand = new DelegateCommand(OnEnableManual)); #endregion #region 构造函数 public OperationOverViewModel() { DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(0.5); timer.Tick += Timer_Tick; timer.Start(); addDataKeys(); string allModules = QueryDataClient.Instance.Service.GetConfig($"System.InstalledModules").ToString(); PMAIsInstalled = allModules.Contains("PMA"); PMBIsInstalled = allModules.Contains("PMB"); PMCIsInstalled = allModules.Contains("PMC"); PMDIsInstalled = allModules.Contains("PMD"); LLAIsInstalled = allModules.Contains("LLA"); LLBIsInstalled = allModules.Contains("LLB"); EFEMIsInstalled = allModules.Contains("EFEM"); TMIsInstalled = allModules.Contains("TM"); UIEvents.PMDoorRaiseChangedEvent += UIEvents_PMDoorRaiseChangedEvent; UIEvents.LLTDoorRaiseChangedEvent += UIEvents_LLTDoorRaiseChangedEvent; UIEvents.LLEDoorRaiseChangedEvent += UIEvents_LLEDoorRaiseChangedEvent; } #endregion #region 命令方法 private void OnLoad() { LP1WaferAssociation = new WaferAssociationInfo(); LP1WaferAssociation.ModuleData = ModuleManager.ModuleInfos["LP1"]; LP2WaferAssociation = new WaferAssociationInfo(); LP2WaferAssociation.ModuleData = ModuleManager.ModuleInfos["LP2"]; LP3WaferAssociation = new WaferAssociationInfo(); LP3WaferAssociation.ModuleData = ModuleManager.ModuleInfos["LP3"]; } private void OnLoadWafer(object obj) { InvokeClient.Instance.Service.DoOperation($"{obj.ToString()}.Load", ModuleManager.ModuleInfos[obj.ToString()].ModuleID); } private void OnUnLoadWafer(object obj) { InvokeClient.Instance.Service.DoOperation($"{obj.ToString()}.UnLoad", ModuleManager.ModuleInfos[obj.ToString()].ModuleID); } private void OnSelectAll(object obj) { var info=obj as WaferAssociationInfo; info.SlotFrom = 1; info.SlotTo = 25; AssociateSequence(info, true); } private void OnUnSelectAll(object obj) { var info = obj as WaferAssociationInfo; info.SlotFrom = 1; info.SlotTo = 25; AssociateSequence(info, false); } private void OnStart(object obj) { var info = obj as WaferAssociationInfo; InvokeClient.Instance.Service.DoOperation("System.StartJob", info.LotId); } private void OnStop(object obj) { InvokeClient.Instance.Service.DoOperation("System.PauseJob", obj.ToString()); } private void OnAbort(object obj) { InvokeClient.Instance.Service.DoOperation("System.ResumeJob", obj.ToString()); } private void OnHomeAll() { InvokeClient.Instance.Service.DoOperation("System.HomeAll"); } private void OnPauseAllJob() { InvokeClient.Instance.Service.DoOperation("System.PauseJob", LP1WaferAssociation.JobID); InvokeClient.Instance.Service.DoOperation("System.PauseJob", LP2WaferAssociation.JobID); InvokeClient.Instance.Service.DoOperation("System.PauseJob", LP3WaferAssociation.JobID); } private void OnAbortAll() { InvokeClient.Instance.Service.DoOperation("System.Abort"); } private void OnReturnAllWafer() { //Dialog WaferDialogView dialog = new WaferDialogView() { Owner = Application.Current.MainWindow, }; dialog.Left = Application.Current.MainWindow.Width / 2 - 150; dialog.Top = Application.Current.MainWindow.Height / 2 - 200; dialog.Height = 300; dialog.Width = 400; double angel = 0; double coolingtime = 0; 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() { //var info = obj as WaferAssociationInfo; } private void OnCreateJob(object obj) { var info = obj as WaferAssociationInfo; List slotSequence = new List(); info.ModuleData.WaferManager.Wafers.ForEach(key => { slotSequence.Insert(0, key.SequenceName); }); string jobId = info.LotId.Trim(); if (string.IsNullOrEmpty(jobId)) jobId = "CJ_Local_" + info.ModuleData.ModuleID; info.LotId = jobId; info.JobID = jobId; info.JobStatus = "WaitingForStart"; info.LotIdSaved = true; Dictionary param = new Dictionary() { {"JobId", jobId}, {"Module", info.ModuleData.ModuleID}, {"SlotSequence", slotSequence.ToArray()}, {"AutoStart", true}, }; InvokeClient.Instance.Service.DoOperation("System.CreateJob", param); } private void OnEnableAuto() { InvokeClient.Instance.Service.DoOperation("System.SetAutoMode"); } private void OnEnableManual() { InvokeClient.Instance.Service.DoOperation("System.SetManualMode"); } #endregion #region 私有方法 private void Timer_Tick(object sender, EventArgs e) { LP1ModuleInfo = ModuleManager.ModuleInfos["LP1"]; LP2ModuleInfo = ModuleManager.ModuleInfos["LP2"]; LP3ModuleInfo = ModuleManager.ModuleInfos["LP3"]; EFEMModuleInfo = ModuleManager.ModuleInfos["EfemRobot"]; TMModuleInfo = ModuleManager.ModuleInfos["TMRobot"]; if (LLAIsInstalled == true) { LLAModuleInfo = ModuleManager.ModuleInfos["LLA"]; LLAWafer = ModuleManager.ModuleInfos["LLA"].WaferManager.Wafers.FirstOrDefault(x => x.WaferStatus != 0); } if (LLBIsInstalled == true) { LLBModuleInfo = ModuleManager.ModuleInfos["LLB"]; LLBWafer = ModuleManager.ModuleInfos["LLB"].WaferManager.Wafers.FirstOrDefault(x => x.WaferStatus != 0); } if (PMAIsInstalled == true) { PMAWafer = ModuleManager.ModuleInfos["PMA"].WaferManager.Wafers[0]; } if (PMBIsInstalled == true) { PMBWafer = ModuleManager.ModuleInfos["PMB"].WaferManager.Wafers[0]; } if (PMCIsInstalled == true) { PMCWafer = ModuleManager.ModuleInfos["PMC"].WaferManager.Wafers[0]; } if (PMDIsInstalled == true) { PMDWafer = ModuleManager.ModuleInfos["PMD"].WaferManager.Wafers[0]; } if (TMIsInstalled == true) { TMBladeAWafer = ModuleManager.ModuleInfos["TMRobot"].WaferManager.Wafers[0]; TMBladeBWafer = ModuleManager.ModuleInfos["TMRobot"].WaferManager.Wafers[1]; } if (EFEMIsInstalled == true) { EFEMBladeAWafer = ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers[0]; EFEMBladeBWafer = ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers[1]; Aligner1Wafer = ModuleManager.ModuleInfos["Aligner1"].WaferManager.Wafers[0]; } RobotMoveInfo = (RobotMoveInfo)QueryDataClient.Instance.Service.GetData("TM.RobotMoveAction"); RtDataValues = QueryDataClient.Instance.Service.PollData(m_RtDataKeys); LP1WaferCount = LP1ModuleInfo.WaferManager.Wafers.Where(x=>x.WaferStatus!=0).Count(); LP2WaferCount = LP2ModuleInfo.WaferManager.Wafers.Where(x => x.WaferStatus != 0).Count(); LP3WaferCount = LP3ModuleInfo.WaferManager.Wafers.Where(x => x.WaferStatus != 0).Count(); } private async void RobotMoveInfoChanged(RobotMoveInfo oldValue, RobotMoveInfo newValue) { string RobotTarget; if (oldValue == null || newValue == null) { return; } #region pick 和 place LL if (oldValue.Action == RobotAction.None && (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") { Robot1TAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true); await Task.Delay(1500); Robot1XAction = WaferRobotXAction.Extend; await Task.Delay(3000); Robot1XAction = WaferRobotXAction.Retract; } else if (arm == "ArmB") { Robot2TAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true); await Task.Delay(1500); Robot2XAction = WaferRobotXAction.Extend; await Task.Delay(3000); Robot2XAction = WaferRobotXAction.Retract; } } #endregion #region pick 和 place pm if (oldValue.Action == RobotAction.None && 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") { Robot1TAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true); await Task.Delay(1500); Robot1XAction = WaferRobotXAction.Extend; } else if (arm == "ArmB") { Robot2TAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true); await Task.Delay(1500); Robot2XAction = WaferRobotXAction.Extend; } } if (oldValue.Action == RobotAction.None && 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 arm1oldWaferStatus = ModuleManager.ModuleInfos["TMRobot"].WaferManager.Wafers[0].WaferStatus; arm2oldWaferStatus = ModuleManager.ModuleInfos["TMRobot"].WaferManager.Wafers[1].WaferStatus; } private void addDataKeys() { m_RtDataKeys.Add("PMA.IsSlitDoorClosed"); m_RtDataKeys.Add("PMB.IsSlitDoorClosed"); m_RtDataKeys.Add("PMC.IsSlitDoorClosed"); m_RtDataKeys.Add("PMD.IsSlitDoorClosed"); m_RtDataKeys.Add("TM.LLATSlitDoor.IsClosed"); m_RtDataKeys.Add("TM.LLBTSlitDoor.IsClosed"); m_RtDataKeys.Add("TM.LLAESlitDoor.IsClosed"); m_RtDataKeys.Add("TM.LLBESlitDoor.IsClosed"); m_RtDataKeys.Add("System.IsAutoMode"); } private void AssociateSequence(WaferAssociationInfo info, bool flag, int slot = -1) { List wafers = info.ModuleData.WaferManager.Wafers; if (slot >= 0) //by wafer { int index = wafers.Count - slot - 1; if (index < wafers.Count) { if (flag && HasWaferOnSlot(wafers, index)) wafers[index].SequenceName = info.SequenceName; else wafers[index].SequenceName = string.Empty; } } else //by from-to { for (int i = info.SlotFrom - 1; i < info.SlotTo; i++) { int index = wafers.Count - i - 1; if (index < wafers.Count) { if (flag && HasWaferOnSlot(wafers, index)) wafers[index].SequenceName = info.SequenceName; else wafers[index].SequenceName = string.Empty; } } } switch (info.ModuleData.ModuleID) { case "LP1": LP1WaferAssociation = info; break; case "LP2": LP2WaferAssociation = info; break; case "LP3": LP3WaferAssociation = info; break; } } private bool HasWaferOnSlot(List wafers, int index) { if (wafers[index].WaferStatus == 0) return false; return true; } private void UIEvents_PMDoorRaiseChangedEvent(DoorPara obj) { InvokeClient.Instance.Service.DoOperation($"{obj?.ModuleName}.SlitDoor.{obj?.IsOpen}"); } private void UIEvents_LLTDoorRaiseChangedEvent(DoorPara obj) { InvokeClient.Instance.Service.DoOperation($"TM.{obj.ModuleName}TSlitDoor.{obj?.IsOpen}"); } private void UIEvents_LLEDoorRaiseChangedEvent(DoorPara obj) { InvokeClient.Instance.Service.DoOperation($"TM.{obj.ModuleName}ESlitDoor.{obj?.IsOpen}"); } #endregion } }