123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- 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 VPWStationSetupViewModel : BindableBase
- {
- #region 常量
- private const string MOTION_DATA = "MotionData";
- private const string IS_SWITCH_ON = "IsSwitchOn";
- private const string CURRENT_STATION = "CurrentStation";
- #endregion
- #region 内部变量
- #region VPW1Rotation
- /// <summary>
- /// VPW1Rotation模块名称
- /// </summary>
- private string _vPW1RotationModuleName;
- /// <summary>
- /// VPW1Rotation运动数据
- /// </summary>
- private CommandMotionData _vPW1RotationMotionData;
- /// <summary>
- /// VPW1Rotation当前位置
- /// </summary>
- private string _vPW1RotationCurrentStation;
- #endregion
- #region VPW2Rotation
- /// <summary>
- /// VPW2Rotation模块名称
- /// </summary>
- private string _vPW2RotationModuleName;
- /// <summary>
- /// VPW1Rotation运动数据
- /// </summary>
- private CommandMotionData _vPW2RotationMotionData;
- /// <summary>
- /// VPW1Rotation当前位置
- /// </summary>
- private string _vPW2RotationCurrentStation;
- #endregion
- #region 系统数据
- /// <summary>
- /// 定时器
- /// </summary>
- DispatcherTimer _timer;
- /// <summary>
- /// 查询后台数据集合
- /// </summary>
- private List<string> _rtDataKeys = new List<string>();
- /// <summary>
- /// rt查询key数值字典
- /// </summary>
- private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
- #endregion
- #endregion
- #region 属性
- #region VPW1Rotation
- /// <summary>
- /// VPW1Rotation名称
- /// </summary>
- public string VPW1RotationModuleName
- {
- get { return _vPW1RotationModuleName; }
- set { SetProperty(ref _vPW1RotationModuleName, value); }
- }
- /// <summary>
- /// VPW1Rotation运动数据
- /// </summary>
- public CommandMotionData VPW1RotationMotionData
- {
- get { return _vPW1RotationMotionData; }
- set { SetProperty(ref _vPW1RotationMotionData, value); }
- }
- /// <summary>
- /// VPW1Rotation当前位置
- /// </summary>
- public string VPW1RotationCurrentStation
- {
- get { return _vPW1RotationCurrentStation; }
- set { SetProperty(ref _vPW1RotationCurrentStation, value); }
- }
- #endregion
- #region VPW2Rotation
- /// <summary>
- /// VPW2Rotation名称
- /// </summary>
- public string VPW2RotationModuleName
- {
- get { return _vPW2RotationModuleName; }
- set { SetProperty(ref _vPW2RotationModuleName, value); }
- }
- /// <summary>
- /// VPW2Rotation运动数据
- /// </summary>
- public CommandMotionData VPW2RotationMotionData
- {
- get { return _vPW2RotationMotionData; }
- set { SetProperty(ref _vPW2RotationMotionData, value); }
- }
- /// <summary>
- /// VPW1Rotation当前位置
- /// </summary>
- public string VPW2RotationCurrentStation
- {
- get { return _vPW2RotationCurrentStation; }
- set { SetProperty(ref _vPW2RotationCurrentStation, value); }
- }
- #endregion
- #endregion
- /// <summary>
- /// 加载数据
- /// </summary>
- public void LoadData(string systemName)
- {
- VPW1RotationModuleName = $"{ModuleName.VpwCell1}.Rotation";
- VPW2RotationModuleName = $"{ModuleName.VpwCell2}.Rotation";
- AddDataKeys();
- if (_timer == null)
- {
- _timer = new DispatcherTimer();
- _timer.Interval = TimeSpan.FromMilliseconds(200);
- _timer.Tick += Timer_Tick; ;
- }
- _timer.Start();
- }
- /// <summary>
- /// 定时器执行
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Timer_Tick(object sender, EventArgs e)
- {
- OnTimer();
- }
- /// <summary>
- /// 隐藏
- /// </summary>
- public void Hide()
- {
- if (_timer != null)
- {
- _timer.Stop();
- }
- }
- /// <summary>
- /// 初始化查询数据集合
- /// </summary>
- private void AddDataKeys()
- {
- _rtDataKeys.Clear();
- _rtDataKeys.Add($"{VPW1RotationModuleName}.{MOTION_DATA}");
- _rtDataKeys.Add($"{VPW1RotationModuleName}.{IS_SWITCH_ON}");
- _rtDataKeys.Add($"{VPW1RotationModuleName}.{CURRENT_STATION}");
- _rtDataKeys.Add($"{VPW2RotationModuleName}.{MOTION_DATA}");
- _rtDataKeys.Add($"{VPW2RotationModuleName}.{IS_SWITCH_ON}");
- _rtDataKeys.Add($"{VPW2RotationModuleName}.{CURRENT_STATION}");
- _rtDataKeys.Add($"{VPW2RotationModuleName}.{CURRENT_STATION}");
- }
- /// <summary>
- /// 定时器
- /// </summary>
- /// <returns></returns>
- private Boolean OnTimer()
- {
- if (_rtDataKeys.Count != 0)
- {
- _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
- if (_rtDataValueDic != null)
- {
- VPW1RotationMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{VPW1RotationModuleName}.{MOTION_DATA}");
- VPW1RotationCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{VPW1RotationModuleName}.{CURRENT_STATION}"), VPW1RotationModuleName);
- VPW2RotationMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{VPW2RotationModuleName}.{MOTION_DATA}");
- VPW2RotationCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{VPW2RotationModuleName}.{CURRENT_STATION}"), VPW2RotationModuleName);
- }
- }
- return true;
- }
- }
- }
|