VPWMainViewModel.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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 = "CommonData";
  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. /// <summary>
  56. /// 是否在purge
  57. /// </summary>
  58. private bool _isPurge;
  59. #endregion
  60. #region UI
  61. /// <summary>
  62. /// IsErrorState 用于腔体变红
  63. /// </summary>
  64. private bool _isErrorState;
  65. /// <summary>
  66. /// 页面功能启用
  67. /// </summary>
  68. private bool _isEnabled;
  69. /// <summary>
  70. /// AutoMode页面功能启用
  71. /// </summary>
  72. private bool _isAutoEnabled;
  73. /// <summary>
  74. /// cell 1 flow
  75. /// </summary>
  76. private double _vpw1CellFlow;
  77. /// <summary>
  78. /// cell 2 flow
  79. /// </summary>
  80. private double _vpw2CellFlow;
  81. #endregion
  82. #endregion
  83. #region 系统数据
  84. /// <summary>
  85. /// 定时器
  86. /// </summary>
  87. DispatcherTimer _timer;
  88. /// <summary>
  89. /// 查询后台数据集合
  90. /// </summary>
  91. private List<string> _rtDataKeys = new List<string>();
  92. /// <summary>
  93. /// rt查询key数值字典
  94. /// </summary>
  95. private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
  96. #endregion
  97. #region 属性
  98. #region Common
  99. /// <summary>
  100. /// 模块名称
  101. /// </summary>
  102. public string Module { get { return _module; } set { SetProperty(ref _module, value); } }
  103. /// <summary>
  104. /// StateMachine
  105. /// </summary>
  106. public string StateMachine { get { return _stateMachine; } set { SetProperty(ref _stateMachine, value); } }
  107. /// <summary>
  108. /// Status
  109. /// </summary>
  110. public string Status { get { return _status; } set { SetProperty(ref _status, value); } }
  111. /// <summary>
  112. /// Commondata
  113. /// </summary>
  114. public VpwMainCommonData VpwMainCommonData
  115. {
  116. get { return _vpwMainCommonData; }
  117. set { SetProperty(ref _vpwMainCommonData, value); }
  118. }
  119. /// <summary>
  120. /// Persistent
  121. /// </summary>
  122. public VpwMainPersistentValue VpwMainPersistent
  123. {
  124. get { return _vpwMainPersistent; }
  125. set { SetProperty(ref _vpwMainPersistent, value); }
  126. }
  127. /// <summary>
  128. /// 是否是Manual模式
  129. /// </summary>
  130. public bool IsManualOperationMode { get { return _isManualOperationMode; } set { SetProperty(ref _isManualOperationMode, value); } }
  131. /// <summary>
  132. /// 是否在purge
  133. /// </summary>
  134. public bool IsPurge { get { return _isPurge; } set { SetProperty(ref _isPurge, value); } }
  135. #endregion
  136. #region UI
  137. /// <summary>
  138. /// IsErrorState
  139. /// </summary>
  140. public bool IsErrorState { get { return _isErrorState; } set { SetProperty(ref _isErrorState, value); } }
  141. /// <summary>
  142. /// 页面功能启用
  143. /// </summary>
  144. public bool IsEnabled
  145. {
  146. get { return _isEnabled; }
  147. set { SetProperty(ref _isEnabled, value); }
  148. }
  149. /// <summary>
  150. /// AutoMode页面功能启用
  151. /// </summary>
  152. public bool IsAutoEnabled
  153. {
  154. get { return _isAutoEnabled; }
  155. set { SetProperty(ref _isAutoEnabled, value); }
  156. }
  157. /// <summary>
  158. ///cell 1 flow
  159. /// </summary>
  160. public double Vpw1CellFlow
  161. {
  162. get { return _vpw1CellFlow; }
  163. set { SetProperty(ref _vpw1CellFlow, value); }
  164. }
  165. /// <summary>
  166. ///cell 2 flow
  167. /// </summary>
  168. public double Vpw2CellFlow
  169. {
  170. get { return _vpw2CellFlow; }
  171. set { SetProperty(ref _vpw2CellFlow, value); }
  172. }
  173. #endregion
  174. #endregion
  175. #region Command指令
  176. public ICommand InitializeCommand { get; set; }
  177. public ICommand HomeCommand { get; set; }
  178. #endregion
  179. public VPWMainViewModel()
  180. {
  181. InitializeCommand = new DelegateCommand<object>(InitializeAction);
  182. HomeCommand = new DelegateCommand<object>(HomeAction);
  183. }
  184. /// <summary>
  185. /// 加载数据
  186. /// </summary>
  187. public void LoadData(string systemName)
  188. {
  189. Module = systemName;
  190. _rtDataKeys.Clear();
  191. List<string> lst = new List<string>();
  192. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(lst);
  193. _rtDataKeys.Add($"{Module}.{PERSISTENT_VALUE}");
  194. _rtDataKeys.Add($"{Module}.{COMMONDATA}");
  195. _rtDataKeys.Add($"{Module}.FsmState");
  196. _rtDataKeys.Add($"VPW1.DiwCellFlow");
  197. _rtDataKeys.Add($"VPW2.DiwCellFlow");
  198. if (_timer == null)
  199. {
  200. _timer = new DispatcherTimer();
  201. _timer.Interval = TimeSpan.FromMilliseconds(200);
  202. _timer.Tick += Timer_Tick;
  203. }
  204. _timer.Start();
  205. }
  206. /// <summary>
  207. /// 定时器执行
  208. /// </summary>
  209. /// <param name="sender"></param>
  210. /// <param name="e"></param>
  211. private void Timer_Tick(object sender, EventArgs e)
  212. {
  213. if (_rtDataKeys.Count != 0)
  214. {
  215. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  216. if (_rtDataValueDic != null)
  217. {
  218. VpwMainCommonData = CommonFunction.GetValue<VpwMainCommonData>(_rtDataValueDic, $"{Module}.{COMMONDATA}");
  219. VpwMainPersistent = CommonFunction.GetValue<VpwMainPersistentValue>(_rtDataValueDic, $"{Module}.{PERSISTENT_VALUE}");
  220. Status = CommonFunction.GetValue<string>(_rtDataValueDic, $"{Module}.FsmState");
  221. IsPurge = "Purgeing".Equals(Status) ? true : false;
  222. Vpw1CellFlow = CommonFunction.GetValue<double>(_rtDataValueDic, $"VPW1.DiwCellFlow");
  223. Vpw2CellFlow = CommonFunction.GetValue<double>(_rtDataValueDic, $"VPW2.DiwCellFlow");
  224. }
  225. }
  226. }
  227. /// <summary>
  228. /// 隐藏
  229. /// </summary>
  230. public void Hide()
  231. {
  232. if (_timer != null)
  233. {
  234. _timer.Stop();
  235. }
  236. }
  237. #region 指令Action
  238. /// <summary>
  239. /// Initialize Action
  240. /// </summary>
  241. /// <param name="param"></param>
  242. private void InitializeAction(object param)
  243. {
  244. InvokeClient.Instance.Service.DoOperation($"{Module}.InitializeAll");
  245. }
  246. /// <summary>
  247. /// Home Action
  248. /// </summary>
  249. /// <param name="param"></param>
  250. private void HomeAction(object param)
  251. {
  252. InvokeClient.Instance.Service.DoOperation($"{Module}.HomeAllRotation");
  253. }
  254. #endregion
  255. }
  256. }