using MECF.Framework.Common.CommonData.PUF; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.Equipment; using MECF.Framework.Common.Utilities; using Prism.Mvvm; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Threading; namespace PunkHPX8_MainPages.ViewModels { public class PlatingCellSetupViewModel : BindableBase { #region 常量 private const string MOTION_DATA = "MotionData"; private const string IS_SWITCH_ON = "IsSwitchOn"; private const string CURRENT_STATION = "CurrentStation"; #endregion #region 内部变量 #region PlatingCell1_2Vertical /// /// 模块名称 /// private string _platingCell1_2VerticalName; /// /// 运动数据 /// private CommandMotionData _platingCell1_2VerticalMotionData; /// /// 当前位置 /// private string _platingCell1_2VerticalCurrentStation; #endregion #region PlatingCell3_4Vertical /// /// 模块名称 /// private string _platingCell3_4VerticalName; /// /// 运动数据 /// private CommandMotionData _platingCell3_4VerticalMotionData; /// /// 当前位置 /// private string _platingCell3_4VerticalCurrentStation; #endregion #region PlatingCell1Rotation /// /// 模块名称 /// private string _platingCell1RotationName; /// /// 运动数据 /// private CommandMotionData _platingCell1RotationMotionData; /// /// 当前位置 /// private string _platingCell1RotationCurrentStation; #endregion #region PlatingCell2Rotation /// /// 模块名称 /// private string _platingCell2RotationName; /// /// 运动数据 /// private CommandMotionData _platingCell2RotationMotionData; /// /// 当前位置 /// private string _platingCell2RotationCurrentStation; #endregion #region PlatingCell3Rotation /// /// 模块名称 /// private string _platingCell3RotationName; /// /// 运动数据 /// private CommandMotionData _platingCell3RotationMotionData; /// /// 当前位置 /// private string _platingCell3RotationCurrentStation; #endregion #region PlatingCell4Rotation /// /// 模块名称 /// private string _platingCell4RotationName; /// /// 运动数据 /// private CommandMotionData _platingCell4RotationMotionData; /// /// 当前位置 /// private string _platingCell4RotationCurrentStation; #endregion #endregion #region 系统数据 /// /// 定时器 /// DispatcherTimer _timer; /// /// 查询后台数据集合 /// private List _rtDataKeys = new List(); /// /// rt查询key数值字典 /// private Dictionary _rtDataValueDic = new Dictionary(); #endregion #region 属性 #region PlatingCell1_2Vertical /// ///名称 /// public string PlatingCell1_2VerticalName { get { return _platingCell1_2VerticalName; } set { SetProperty(ref _platingCell1_2VerticalName, value); } } /// /// 运动数据 /// public CommandMotionData PlatingCell1_2VerticalMotionData { get { return _platingCell1_2VerticalMotionData; } set { SetProperty(ref _platingCell1_2VerticalMotionData, value); } } /// ///当前位置 /// public string PlatingCell1_2VerticalCurrentStation { get { return _platingCell1_2VerticalCurrentStation; } set { SetProperty(ref _platingCell1_2VerticalCurrentStation, value); } } #endregion #region PlatingCell3_4Vertical /// ///名称 /// public string PlatingCell3_4VerticalName { get { return _platingCell3_4VerticalName; } set { SetProperty(ref _platingCell3_4VerticalName, value); } } /// /// 运动数据 /// public CommandMotionData PlatingCell3_4VerticalMotionData { get { return _platingCell3_4VerticalMotionData; } set { SetProperty(ref _platingCell3_4VerticalMotionData, value); } } /// /// 当前位置 /// public string PlatingCell3_4VerticalCurrentStation { get { return _platingCell3_4VerticalCurrentStation; } set { SetProperty(ref _platingCell3_4VerticalCurrentStation, value); } } #endregion #region PlatingCell1Rotation /// ///名称 /// public string PlatingCell1RotationName { get { return _platingCell1RotationName; } set { SetProperty(ref _platingCell1RotationName, value); } } /// /// 运动数据 /// public CommandMotionData PlatingCell1RotationMotionData { get { return _platingCell1RotationMotionData; } set { SetProperty(ref _platingCell1RotationMotionData, value); } } /// /// 当前位置 /// public string PlatingCell1RotationCurrentStation { get { return _platingCell1RotationCurrentStation; } set { SetProperty(ref _platingCell1RotationCurrentStation, value); } } #endregion #region PlatingCell2Rotation /// ///名称 /// public string PlatingCell2RotationName { get { return _platingCell2RotationName; } set { SetProperty(ref _platingCell2RotationName, value); } } /// /// 运动数据 /// public CommandMotionData PlatingCell2RotationMotionData { get { return _platingCell2RotationMotionData; } set { SetProperty(ref _platingCell2RotationMotionData, value); } } /// /// 当前位置 /// public string PlatingCell2RotationCurrentStation { get { return _platingCell2RotationCurrentStation; } set { SetProperty(ref _platingCell2RotationCurrentStation, value); } } #endregion #region PlatingCell3Rotation /// ///名称 /// public string PlatingCell3RotationName { get { return _platingCell3RotationName; } set { SetProperty(ref _platingCell3RotationName, value); } } /// /// 运动数据 /// public CommandMotionData PlatingCell3RotationMotionData { get { return _platingCell3RotationMotionData; } set { SetProperty(ref _platingCell3RotationMotionData, value); } } /// /// 当前位置 /// public string PlatingCell3RotationCurrentStation { get { return _platingCell3RotationCurrentStation; } set { SetProperty(ref _platingCell3RotationCurrentStation, value); } } #endregion #region PlatingCell4Rotation /// ///名称 /// public string PlatingCell4RotationName { get { return _platingCell4RotationName; } set { SetProperty(ref _platingCell4RotationName, value); } } /// /// 运动数据 /// public CommandMotionData PlatingCell4RotationMotionData { get { return _platingCell4RotationMotionData; } set { SetProperty(ref _platingCell4RotationMotionData, value); } } /// /// 当前位置 /// public string PlatingCell4RotationCurrentStation { get { return _platingCell4RotationCurrentStation; } set { SetProperty(ref _platingCell4RotationCurrentStation, value); } } #endregion #endregion /// /// 构造函数 /// public PlatingCellSetupViewModel() { } /// /// 加载数据 /// public void LoadData(string systemName) { PlatingCell1_2VerticalName = $"PlatingCell1_2.Vertical"; PlatingCell3_4VerticalName = $"PlatingCell3_4.Vertical"; PlatingCell1RotationName = $"PlatingCell1.Rotation"; PlatingCell2RotationName = $"PlatingCell2.Rotation"; PlatingCell3RotationName = $"PlatingCell3.Rotation"; PlatingCell4RotationName = $"PlatingCell4.Rotation"; AddDataKeys(); if (_timer == null) { _timer = new DispatcherTimer(); _timer.Interval = TimeSpan.FromMilliseconds(200); _timer.Tick += Timer_Tick; } _timer.Start(); } /// /// 定时器执行 /// /// /// private void Timer_Tick(object sender, EventArgs e) { OnTimer(); } /// /// 隐藏 /// public void Hide() { if (_timer != null) { _timer.Stop(); } } /// /// 初始化查询数据集合 /// private void AddDataKeys() { _rtDataKeys.Clear(); _rtDataKeys.Add($"{PlatingCell1_2VerticalName}.{MOTION_DATA}"); _rtDataKeys.Add($"{PlatingCell1_2VerticalName}.{IS_SWITCH_ON}"); _rtDataKeys.Add($"{PlatingCell1_2VerticalName}.{CURRENT_STATION}"); _rtDataKeys.Add($"{PlatingCell3_4VerticalName}.{MOTION_DATA}"); _rtDataKeys.Add($"{PlatingCell3_4VerticalName}.{IS_SWITCH_ON}"); _rtDataKeys.Add($"{PlatingCell3_4VerticalName}.{CURRENT_STATION}"); _rtDataKeys.Add($"{PlatingCell1RotationName}.{MOTION_DATA}"); _rtDataKeys.Add($"{PlatingCell1RotationName}.{IS_SWITCH_ON}"); _rtDataKeys.Add($"{PlatingCell1RotationName}.{CURRENT_STATION}"); _rtDataKeys.Add($"{PlatingCell2RotationName}.{MOTION_DATA}"); _rtDataKeys.Add($"{PlatingCell2RotationName}.{IS_SWITCH_ON}"); _rtDataKeys.Add($"{PlatingCell2RotationName}.{CURRENT_STATION}"); _rtDataKeys.Add($"{PlatingCell3RotationName}.{MOTION_DATA}"); _rtDataKeys.Add($"{PlatingCell3RotationName}.{IS_SWITCH_ON}"); _rtDataKeys.Add($"{PlatingCell3RotationName}.{CURRENT_STATION}"); _rtDataKeys.Add($"{PlatingCell4RotationName}.{MOTION_DATA}"); _rtDataKeys.Add($"{PlatingCell4RotationName}.{IS_SWITCH_ON}"); _rtDataKeys.Add($"{PlatingCell4RotationName}.{CURRENT_STATION}"); } /// /// 定时器 /// /// private Boolean OnTimer() { if (_rtDataKeys.Count != 0) { _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys); if (_rtDataValueDic != null) { PlatingCell1_2VerticalMotionData = CommonFunction.GetValue(_rtDataValueDic, $"{PlatingCell1_2VerticalName}.{MOTION_DATA}"); PlatingCell1_2VerticalCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue(_rtDataValueDic, $"{PlatingCell1_2VerticalName}.{CURRENT_STATION}"), PlatingCell1_2VerticalName); PlatingCell3_4VerticalMotionData = CommonFunction.GetValue(_rtDataValueDic, $"{PlatingCell3_4VerticalName}.{MOTION_DATA}"); PlatingCell3_4VerticalCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue(_rtDataValueDic, $"{PlatingCell3_4VerticalName}.{CURRENT_STATION}"), PlatingCell3_4VerticalName); PlatingCell1RotationMotionData = CommonFunction.GetValue(_rtDataValueDic, $"{PlatingCell1RotationName}.{MOTION_DATA}"); PlatingCell1RotationCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue(_rtDataValueDic, $"{PlatingCell1RotationName}.{CURRENT_STATION}"), PlatingCell1RotationName); PlatingCell2RotationMotionData = CommonFunction.GetValue(_rtDataValueDic, $"{PlatingCell2RotationName}.{MOTION_DATA}"); PlatingCell2RotationCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue(_rtDataValueDic, $"{PlatingCell2RotationName}.{CURRENT_STATION}"), PlatingCell2RotationName); PlatingCell3RotationMotionData = CommonFunction.GetValue(_rtDataValueDic, $"{PlatingCell3RotationName}.{MOTION_DATA}"); PlatingCell3RotationCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue(_rtDataValueDic, $"{PlatingCell3RotationName}.{CURRENT_STATION}"), PlatingCell3RotationName); PlatingCell3RotationMotionData = CommonFunction.GetValue(_rtDataValueDic, $"{PlatingCell4RotationName}.{MOTION_DATA}"); PlatingCell3RotationCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue(_rtDataValueDic, $"{PlatingCell4RotationName}.{CURRENT_STATION}"), PlatingCell4RotationName); } } return true; } } }