using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Data; using System.Windows.Input; using System.Windows.Threading; using MECF.Framework.Common.OperationCenter; using Prism.Mvvm; using Prism.Commands; using MECF.Framework.Common.CommonData.SRD; using MECF.Framework.Common.Persistent.SRD; using Aitex.Core.RT.DataCenter; using MECF.Framework.Common.CommonData.PUF; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.Utilities; using MECF.Framework.Common.RecipeCenter; using System.Collections.ObjectModel; using CyberX8_MainPages.PMs; using Aitex.Core.Utilities; using CyberX8_Core; using System.Windows.Documents; using System.Windows; using Aitex.Core.Common; using Aitex.Core.Util; using MECF.Framework.Common.WaferHolder; using OpenSEMI.ClientBase; using MECF.Framework.Common.Beckhoff.Station; using CyberX8_MainPages.Unity; using WaferInfo = OpenSEMI.ClientBase.WaferInfo; using MECF.Framework.Common.Equipment; namespace CyberX8_MainPages.ViewModels { internal class SRDHomePageViewModel:BindableBase { #region 常量 private const string COMMON_DATA = "CommonData"; private const string PERSISTENT_VALUE = "PersistentValue"; private const string WAFER_PRESENCE_STATUS = "WaferPresenceStatus"; private const string SRD = "srd"; private const string WAFER_HOLDER= "WaferHolder"; private const string LOADER_DI_ENABLE = "LoaderDiEnable"; private const string FACILITIES = "Facilities"; private const string MOTION_DATA = "MotionData"; private const double ARM_UI_HOME_POSITION = 25.682; private const double ARM_UI_CENTER_POSITION = -15; private const double ROTATION_UI_HOME_POSITION = 0; #endregion #region 内部变量 #region SRD /// /// SRDRecipeContent /// private string _recipeContent; /// /// TimeRemaining /// private double _timeRemaining; /// /// OfTotalTime /// private double _totalTime; /// /// OperatingMode /// private string _operatingMode; /// /// State /// private string _state; /// /// RecipeMode /// private string _recipeMode; /// /// AchievedRunRecipeCycle /// private int _achievedRunRecipeCycle; /// /// Loader DI /// private bool _loaderDiEnable; #endregion #region wafer /// /// WaferID /// private string _waferID = ""; /// /// SeqRecipe /// private string _seqRecipe; /// /// Wafer信息 /// private WaferInfo _waferInfo; #endregion #region SRD recipe /// /// RecipeModuleName /// private string _recipeModuleName; /// /// RecipeType /// private string _recipeType; /// /// 当前选择Recipe节点 /// private RecipeNode _selectedRecipeNode; /// /// Recipe节点 /// private ObservableCollection _recipeNodes; // /// 当前Recipe /// private string _currentRecipe; #endregion #region Common /// /// 模块名称 /// private string _module; /// /// State Machine /// private string _stateMachine; /// /// Status /// private string _status; /// /// 数据 /// private SrdCommonData _sRDCommonData; /// /// Threshold /// private SRDPersistentValue _sRDPersistent; /// /// WaferPresence /// private string _waferPresence; /// /// PresenceTest是否进行中 /// private bool _isPresenceTesting; /// /// Test Without Wafers /// private bool _isWaferPresence; /// /// sRDArm运动数据 /// private CommandMotionData _sRDArmMotionData; /// /// sRDRotation运动数据 /// private CommandMotionData _sRDRotationMotionData; /// /// 页面功能启用 /// private bool _isEnabled; /// /// AutoMode页面功能启用 /// private bool _isAutoEnabled; #endregion #region 系统数据 /// /// 定时器 /// DispatcherTimer _timer; /// /// 查询后台数据集合 /// private List _rtDataKeys = new List(); /// /// rt查询key数值字典 /// private Dictionary _rtDataValueDic = new Dictionary(); /// /// UiRecipeManager /// private UiRecipeManager _uiRecipeManager = new UiRecipeManager(); #endregion #region UI related /// /// SRD Arm UI位置 /// private double _srdArmUIPosition = ARM_UI_HOME_POSITION; /// /// SRD Rotation UI位置 /// private double _srdRotationUIPosition = ROTATION_UI_HOME_POSITION; /// /// Arm Axis位置数据 /// private BeckhoffStationAxis _armAxis; /// /// Arm UI位置比例 /// private double _armUIRatio; #endregion #endregion #region 属性 #region SRD /// /// SRDRecipeContent /// public string SRDRecipeContent { get { return _recipeContent; } set { SetProperty(ref _recipeContent, value); } } /// /// TimeRemaining /// public double TimeRemaining { get { return _timeRemaining; } set { SetProperty(ref _timeRemaining, value); } } /// /// TotalTime /// public double TotalTime { get { return _totalTime; } set { SetProperty(ref _totalTime, value); } } /// /// OperatingMode /// public string OperatingMode { get { return _operatingMode; } set { SetProperty(ref _operatingMode, value); } } /// /// State /// public string State { get { return _state; } set { SetProperty(ref _state, value); } } /// /// RecipeMode /// public string RecipeMode { get { return _recipeMode; } set { SetProperty(ref _recipeMode, value); } } /// /// Run Recipe已经完成的次数 /// public int AchievedRunRecipeCycle { get { return _achievedRunRecipeCycle; } set { SetProperty(ref _achievedRunRecipeCycle, value); } } /// /// Loader DI /// public bool LoaderDiEnable { get { return _loaderDiEnable; } set { SetProperty(ref _loaderDiEnable, value); } } #endregion #region wafer /// /// WaferID /// public string WaferID { get { return _waferID; } set { SetProperty(ref _waferID, value); } } /// /// SeqRecipe /// public string SeqRecipe { get { return _seqRecipe; } set { SetProperty(ref _seqRecipe, value); } } /// /// Wafer信息 /// public WaferInfo WaferInfo { get { return _waferInfo; } set { SetProperty(ref _waferInfo, value); } } #endregion #region SRD recipe /// /// RecipeModuleName /// public string RecipeModuleName { get { return _recipeModuleName; } set { SetProperty(ref _recipeModuleName, value); } } /// /// RecipeType /// public string RecipeType { get { return _recipeType; } set { SetProperty(ref _recipeType, value); } } /// /// 当前运行的Recipe /// public string CurrentRecipe { get { return _currentRecipe; } set { SetProperty(ref _currentRecipe, value); } } #endregion #region Common /// /// 模块名称 /// public string Module { get { return _module; } set { SetProperty(ref _module, value); } } /// /// StateMachine /// public string StateMachine { get { return _stateMachine; } set { SetProperty(ref _stateMachine, value); } } /// /// StateMachine /// public string Status { get { return _status; } set { SetProperty(ref _status, value); } } /// /// Commondata /// public SrdCommonData SRDCommonData { get { return _sRDCommonData; } set { SetProperty(ref _sRDCommonData, value); } } /// /// WaferPresence /// public string WaferPresence { get { return _waferPresence; } set { SetProperty(ref _waferPresence, value); } } /// /// Threshold /// public SRDPersistentValue SRDPersistent { get { return _sRDPersistent; } set { SetProperty(ref _sRDPersistent, value); } } /// /// Selected Recipe Node /// public RecipeNode SelectedRecipeNode { get { return _selectedRecipeNode; } set { SetProperty(ref _selectedRecipeNode, value); } } /// /// PresenceTest是否进行中 /// public bool IsPresenceTesting { get { return _isPresenceTesting; } set { SetProperty(ref _isPresenceTesting, value); } } /// /// Test Without Wafers /// public bool IsWaferPresence { get { return _isWaferPresence; } set { SetProperty(ref _isWaferPresence, value); } } /// /// SRDArm运动数据 /// public CommandMotionData SRDArmMotionData { get { return _sRDArmMotionData; } set { SetProperty(ref _sRDArmMotionData, value); } } /// /// SRDRotation运动数据 /// public CommandMotionData SRDRotationMotionData { get { return _sRDRotationMotionData; } set { SetProperty(ref _sRDRotationMotionData, value); } } /// /// 页面功能启用 /// public bool IsEnabled { get { return _isEnabled; } set { SetProperty(ref _isEnabled, value); } } /// /// AutoMode页面功能启用 /// public bool IsAutoEnabled { get { return _isAutoEnabled; } set { SetProperty(ref _isAutoEnabled, value); } } #endregion #region UI related /// /// SRD ARM UI位置 /// public double SRDArmUIPosition { get { return _srdArmUIPosition; } set { SetProperty(ref _srdArmUIPosition, value); } } /// /// SRD Rotation UI位置 /// public double SRDRotationUIPosition { get { return _srdRotationUIPosition; } set { SetProperty(ref _srdRotationUIPosition, value); } } #endregion #endregion #region Command指令 /// /// Initialize Command /// public ICommand InitializeCommand { get; set; } /// /// SwitchOn Command /// public ICommand SwitchOnCommand { get; set; } /// /// SwitchOff Command /// public ICommand SwitchOffCommand { get; set; } #endregion /// /// 构造函数 /// public SRDHomePageViewModel() { InitializeCommand = new DelegateCommand(InitializeAction); SwitchOnCommand = new DelegateCommand(SwitchOnAction); SwitchOffCommand = new DelegateCommand(SwitchOffAction); } /// /// 加载数据 /// public void LoadData(string systemName) { Module = systemName; RecipeType = "srd"; RecipeModuleName = "SRD Recipe"; _rtDataKeys.Clear(); _rtDataKeys.Add($"{Module}.IsHomed"); _rtDataKeys.Add($"{Module}.{COMMON_DATA}"); _rtDataKeys.Add($"{Module}.{PERSISTENT_VALUE}"); _rtDataKeys.Add($"{Module}.{WAFER_PRESENCE_STATUS}"); _rtDataKeys.Add($"{Module}.AchievedCycle"); _rtDataKeys.Add($"{Module}.FsmState"); _rtDataKeys.Add($"{Module}.CurrentStateMachine"); _rtDataKeys.Add($"{Module}.CurrentStatus"); _rtDataKeys.Add($"{Module}.WaferInfo"); _rtDataKeys.Add($"{Module}.IsPresenceTesting"); _rtDataKeys.Add($"{Module}.IsWaferPresence"); _rtDataKeys.Add($"System.{FACILITIES}.{LOADER_DI_ENABLE}"); _rtDataKeys.Add($"{Module}.Arm.{MOTION_DATA}"); _rtDataKeys.Add($"{Module}.Rotation.{MOTION_DATA}"); _rtDataKeys.Add($"Station.{Module}.Arm"); _rtDataKeys.Add($"{Module}.CurrentRecipe"); _rtDataKeys.Add($"{Module}.TotalTime"); _rtDataKeys.Add($"{Module}.TimeRemain"); if (_timer == null) { _timer = new DispatcherTimer(); _timer.Interval = TimeSpan.FromMilliseconds(200); _timer.Tick += Timer_Tick; } _timer.Start(); _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys); if (_rtDataValueDic != null) { _armAxis = CommonFunction.GetValue(_rtDataValueDic, $"Station.{Module}.Arm"); //计算Arm位置比例 if (_armAxis != null) { double armHomePos = double.Parse(_armAxis.Stations[0].Position); double armCenterPos = double.Parse(_armAxis.Stations[1].Position); _armUIRatio = (ARM_UI_HOME_POSITION - ARM_UI_CENTER_POSITION) / (armHomePos - armCenterPos); } } } /// /// 定时器执行 /// /// /// private void Timer_Tick(object sender, EventArgs e) { if (_rtDataKeys.Count != 0) { _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys); if (_rtDataValueDic != null) { SRDCommonData = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.{COMMON_DATA}"); SRDPersistent = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.{PERSISTENT_VALUE}"); LoaderDiEnable = CommonFunction.GetValue(_rtDataValueDic, $"System.{FACILITIES}.{LOADER_DI_ENABLE}"); AchievedRunRecipeCycle = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.AchievedCycle"); WaferPresence = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.{WAFER_PRESENCE_STATUS}"); State = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.FsmState"); CurrentRecipe = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.CurrentRecipe"); IsWaferPresence = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.IsWaferPresence"); if (SRDPersistent != null) { if ("Manual".Equals(SRDPersistent.OperatingMode)) { IsEnabled = true; IsAutoEnabled = true; } else if ("Auto".Equals(SRDPersistent.OperatingMode)) { if (!IsWaferPresence) { InvokeClient.Instance.Service.DoOperation($"{Module}.UpdateIsWaferPresenceAction", true); } IsAutoEnabled = true; IsEnabled = false; } else { State = "Stopped"; IsEnabled = false; IsAutoEnabled = false; } } StateMachine = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.CurrentStateMachine"); Status = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.CurrentStatus"); IsPresenceTesting = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.IsPresenceTesting"); SRDArmMotionData = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.Arm.{MOTION_DATA}"); SRDRotationMotionData = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.Rotation.{MOTION_DATA}"); //SRD Wafer信息 if (ModuleManager.ModuleInfos[Module].WaferManager.Wafers.Count != 0) { WaferInfo = ModuleManager.ModuleInfos[Module].WaferManager.Wafers[0]; } //计算ARM UI位置 if (SRDArmMotionData != null) { SRDArmUIPosition = ARM_UI_HOME_POSITION + _armUIRatio * SRDArmMotionData.MotorPosition; } //计算Rotation UI位置 if (SRDRotationMotionData != null) { SRDRotationUIPosition = SRDRotationMotionData.MotorPosition; } TotalTime = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.TotalTime"); TimeRemaining = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.TimeRemain"); if (State == "Idle") { TimeRemaining = 0; } } } } /// /// 隐藏 /// public void Hide() { if (_timer != null) { _timer.Stop(); } } #region 指令Action /// /// Home Action /// /// private void HomeAction(object param) { InvokeClient.Instance.Service.DoOperation($"{Module}.HomeAll"); } /// /// Initialize Action /// /// private void InitializeAction(object param) { InvokeClient.Instance.Service.DoOperation($"{Module}.InitializeHome"); } /// /// Switch On Action /// /// private void SwitchOnAction(object param) { InvokeClient.Instance.Service.DoOperation($"{Module}.SwitchOnAll"); } /// /// Switch Off Action /// /// private void SwitchOffAction(object param) { InvokeClient.Instance.Service.DoOperation($"{Module}.SwitchOffAll"); } #endregion } }