123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- using Aitex.Core.UI.MVVM;
- using MECF.Framework.Common.CommonData.Prewet;
- using MECF.Framework.Common.CommonData.PUF;
- using MECF.Framework.Common.CommonData.Vpw;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.Common.Device.LinMot;
- using MECF.Framework.Common.OperationCenter;
- using MECF.Framework.Common.Persistent.Prewet;
- using MECF.Framework.Common.Persistent.VpwMain;
- using MECF.Framework.Common.RecipeCenter;
- 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.Input;
- using System.Windows.Threading;
- namespace PunkHPX8_MainPages.ViewModels
- {
- public class VPWMainViewModel : BindableBase
- {
- #region 常量
- private const string COMMONDATA = "CommonData1";
- private const string VPW = "vpw";
- private const string PERSISTENT_VALUE = "PersistentValue";
- #endregion
- #region 内部变量
- #region Common
- /// <summary>
- /// 模块名称
- /// </summary>
- private string _module;
- /// <summary>
- /// StateMachine
- /// </summary>
- private string _stateMachine;
- /// <summary>
- /// Status
- /// </summary>
- private string _status;
- /// <summary>
- /// 数据
- /// </summary>
- private VpwMainCommonData _vpwMainCommonData;
- /// <summary>
- /// Threshold
- /// </summary>
- private VpwMainPersistentValue _vpwMainPersistent;
- /// <summary>
- /// 是否是Manual模式
- /// </summary>
- private bool _isManualOperationMode;
- #endregion
- #region UI
- /// <summary>
- /// IsErrorState 用于腔体变红
- /// </summary>
- private bool _isErrorState;
- /// <summary>
- /// 页面功能启用
- /// </summary>
- private bool _isEnabled;
- /// <summary>
- /// AutoMode页面功能启用
- /// </summary>
- private bool _isAutoEnabled;
- #endregion
- #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
- #region 属性
- #region Common
- /// <summary>
- /// 模块名称
- /// </summary>
- public string Module { get { return _module; } set { SetProperty(ref _module, value); } }
- /// <summary>
- /// StateMachine
- /// </summary>
- public string StateMachine { get { return _stateMachine; } set { SetProperty(ref _stateMachine, value); } }
- /// <summary>
- /// Status
- /// </summary>
- public string Status { get { return _status; } set { SetProperty(ref _status, value); } }
- /// <summary>
- /// Commondata
- /// </summary>
- public VpwMainCommonData VpwMainCommonData
- {
- get { return _vpwMainCommonData; }
- set { SetProperty(ref _vpwMainCommonData, value); }
- }
- /// <summary>
- /// Persistent
- /// </summary>
- public VpwMainPersistentValue VpwMainPersistent
- {
- get { return _vpwMainPersistent; }
- set { SetProperty(ref _vpwMainPersistent, value); }
- }
- /// <summary>
- /// 是否是Manual模式
- /// </summary>
- public bool IsManualOperationMode { get { return _isManualOperationMode; } set { SetProperty(ref _isManualOperationMode, value); } }
- #endregion
- #region UI
- /// <summary>
- /// IsErrorState
- /// </summary>
- public bool IsErrorState { get { return _isErrorState; } set { SetProperty(ref _isErrorState, value); } }
- /// <summary>
- /// 页面功能启用
- /// </summary>
- public bool IsEnabled
- {
- get { return _isEnabled; }
- set { SetProperty(ref _isEnabled, value); }
- }
- /// <summary>
- /// AutoMode页面功能启用
- /// </summary>
- public bool IsAutoEnabled
- {
- get { return _isAutoEnabled; }
- set { SetProperty(ref _isAutoEnabled, value); }
- }
- #endregion
- #endregion
- #region Command指令
- public ICommand InitializeCommand { get; set; }
- public ICommand HomeCommand { get; set; }
- #endregion
- public VPWMainViewModel()
- {
- InitializeCommand = new DelegateCommand<object>(InitializeAction);
- HomeCommand = new DelegateCommand<object>(HomeAction);
- }
- /// <summary>
- /// 加载数据
- /// </summary>
- public void LoadData(string systemName)
- {
- Module = systemName;
-
- _rtDataKeys.Clear();
- List<string> lst = new List<string>();
- _rtDataValueDic = QueryDataClient.Instance.Service.PollData(lst);
- _rtDataKeys.Add($"{Module}.{PERSISTENT_VALUE}");
- _rtDataKeys.Add($"{Module}.{COMMONDATA}");
- _rtDataKeys.Add($"{Module}.MachineState");
- 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)
- {
- if (_rtDataKeys.Count != 0)
- {
- _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
- if (_rtDataValueDic != null)
- {
- VpwMainCommonData = CommonFunction.GetValue<VpwMainCommonData>(_rtDataValueDic, $"{Module}.{COMMONDATA}");
- }
- }
- }
- /// <summary>
- /// 隐藏
- /// </summary>
- public void Hide()
- {
- if (_timer != null)
- {
- _timer.Stop();
- }
- }
- #region 指令Action
- /// <summary>
- /// Initialize Action
- /// </summary>
- /// <param name="param"></param>
- private void InitializeAction(object param)
- {
- InvokeClient.Instance.Service.DoOperation($"{Module}.InitializeAll");
- }
- /// <summary>
- /// Home Action
- /// </summary>
- /// <param name="param"></param>
- private void HomeAction(object param)
- {
- InvokeClient.Instance.Service.DoOperation($"{Module}.Home");
- }
- #endregion
- }
- }
|