VPWMainViewModel.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. using Aitex.Core.UI.MVVM;
  2. using MECF.Framework.Common.CommonData.Prewet;
  3. using MECF.Framework.Common.CommonData.PUF;
  4. using MECF.Framework.Common.CommonData.Vpw;
  5. using MECF.Framework.Common.DataCenter;
  6. using MECF.Framework.Common.Device.LinMot;
  7. using MECF.Framework.Common.OperationCenter;
  8. using MECF.Framework.Common.Persistent.Prewet;
  9. using MECF.Framework.Common.Persistent.VpwMain;
  10. using MECF.Framework.Common.RecipeCenter;
  11. using MECF.Framework.Common.Utilities;
  12. using Prism.Mvvm;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. using System.Windows.Input;
  19. using System.Windows.Threading;
  20. namespace PunkHPX8_MainPages.ViewModels
  21. {
  22. public class VPWMainViewModel : BindableBase
  23. {
  24. #region 常量
  25. private const string COMMONDATA = "CommonData1";
  26. private const string VPW = "vpw";
  27. private const string PERSISTENT_VALUE = "PersistentValue";
  28. #endregion
  29. #region 内部变量
  30. #region Common
  31. /// <summary>
  32. /// 模块名称
  33. /// </summary>
  34. private string _module;
  35. /// <summary>
  36. /// StateMachine
  37. /// </summary>
  38. private string _stateMachine;
  39. /// <summary>
  40. /// Status
  41. /// </summary>
  42. private string _status;
  43. /// <summary>
  44. /// 数据
  45. /// </summary>
  46. private VpwMainCommonData _vpwMainCommonData;
  47. /// <summary>
  48. /// Threshold
  49. /// </summary>
  50. private VpwMainPersistentValue _vpwMainPersistent;
  51. /// <summary>
  52. /// 是否是Manual模式
  53. /// </summary>
  54. private bool _isManualOperationMode;
  55. #endregion
  56. #region UI
  57. /// <summary>
  58. /// IsErrorState 用于腔体变红
  59. /// </summary>
  60. private bool _isErrorState;
  61. /// <summary>
  62. /// 页面功能启用
  63. /// </summary>
  64. private bool _isEnabled;
  65. /// <summary>
  66. /// AutoMode页面功能启用
  67. /// </summary>
  68. private bool _isAutoEnabled;
  69. #endregion
  70. #endregion
  71. #region 系统数据
  72. /// <summary>
  73. /// 定时器
  74. /// </summary>
  75. DispatcherTimer _timer;
  76. /// <summary>
  77. /// 查询后台数据集合
  78. /// </summary>
  79. private List<string> _rtDataKeys = new List<string>();
  80. /// <summary>
  81. /// rt查询key数值字典
  82. /// </summary>
  83. private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
  84. #endregion
  85. #region 属性
  86. #region Common
  87. /// <summary>
  88. /// 模块名称
  89. /// </summary>
  90. public string Module { get { return _module; } set { SetProperty(ref _module, value); } }
  91. /// <summary>
  92. /// StateMachine
  93. /// </summary>
  94. public string StateMachine { get { return _stateMachine; } set { SetProperty(ref _stateMachine, value); } }
  95. /// <summary>
  96. /// Status
  97. /// </summary>
  98. public string Status { get { return _status; } set { SetProperty(ref _status, value); } }
  99. /// <summary>
  100. /// Commondata
  101. /// </summary>
  102. public VpwMainCommonData VpwMainCommonData
  103. {
  104. get { return _vpwMainCommonData; }
  105. set { SetProperty(ref _vpwMainCommonData, value); }
  106. }
  107. /// <summary>
  108. /// Persistent
  109. /// </summary>
  110. public VpwMainPersistentValue VpwMainPersistent
  111. {
  112. get { return _vpwMainPersistent; }
  113. set { SetProperty(ref _vpwMainPersistent, value); }
  114. }
  115. /// <summary>
  116. /// 是否是Manual模式
  117. /// </summary>
  118. public bool IsManualOperationMode { get { return _isManualOperationMode; } set { SetProperty(ref _isManualOperationMode, value); } }
  119. #endregion
  120. #region UI
  121. /// <summary>
  122. /// IsErrorState
  123. /// </summary>
  124. public bool IsErrorState { get { return _isErrorState; } set { SetProperty(ref _isErrorState, value); } }
  125. /// <summary>
  126. /// 页面功能启用
  127. /// </summary>
  128. public bool IsEnabled
  129. {
  130. get { return _isEnabled; }
  131. set { SetProperty(ref _isEnabled, value); }
  132. }
  133. /// <summary>
  134. /// AutoMode页面功能启用
  135. /// </summary>
  136. public bool IsAutoEnabled
  137. {
  138. get { return _isAutoEnabled; }
  139. set { SetProperty(ref _isAutoEnabled, value); }
  140. }
  141. #endregion
  142. #endregion
  143. #region Command指令
  144. public ICommand InitializeCommand { get; set; }
  145. public ICommand HomeCommand { get; set; }
  146. #endregion
  147. public VPWMainViewModel()
  148. {
  149. InitializeCommand = new DelegateCommand<object>(InitializeAction);
  150. HomeCommand = new DelegateCommand<object>(HomeAction);
  151. }
  152. /// <summary>
  153. /// 加载数据
  154. /// </summary>
  155. public void LoadData(string systemName)
  156. {
  157. Module = systemName;
  158. _rtDataKeys.Clear();
  159. List<string> lst = new List<string>();
  160. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(lst);
  161. _rtDataKeys.Add($"{Module}.{PERSISTENT_VALUE}");
  162. _rtDataKeys.Add($"{Module}.{COMMONDATA}");
  163. _rtDataKeys.Add($"{Module}.MachineState");
  164. if (_timer == null)
  165. {
  166. _timer = new DispatcherTimer();
  167. _timer.Interval = TimeSpan.FromMilliseconds(200);
  168. _timer.Tick += Timer_Tick;
  169. }
  170. _timer.Start();
  171. }
  172. /// <summary>
  173. /// 定时器执行
  174. /// </summary>
  175. /// <param name="sender"></param>
  176. /// <param name="e"></param>
  177. private void Timer_Tick(object sender, EventArgs e)
  178. {
  179. if (_rtDataKeys.Count != 0)
  180. {
  181. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  182. if (_rtDataValueDic != null)
  183. {
  184. VpwMainCommonData = CommonFunction.GetValue<VpwMainCommonData>(_rtDataValueDic, $"{Module}.{COMMONDATA}");
  185. }
  186. }
  187. }
  188. /// <summary>
  189. /// 隐藏
  190. /// </summary>
  191. public void Hide()
  192. {
  193. if (_timer != null)
  194. {
  195. _timer.Stop();
  196. }
  197. }
  198. #region 指令Action
  199. /// <summary>
  200. /// Initialize Action
  201. /// </summary>
  202. /// <param name="param"></param>
  203. private void InitializeAction(object param)
  204. {
  205. InvokeClient.Instance.Service.DoOperation($"{Module}.InitializeAll");
  206. }
  207. /// <summary>
  208. /// Home Action
  209. /// </summary>
  210. /// <param name="param"></param>
  211. private void HomeAction(object param)
  212. {
  213. InvokeClient.Instance.Service.DoOperation($"{Module}.Home");
  214. }
  215. #endregion
  216. }
  217. }