VPWCellViewModel.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. using Aitex.Core.UI.MVVM;
  2. using MECF.Framework.Common.CommonData.Vpw;
  3. using MECF.Framework.Common.DataCenter;
  4. using MECF.Framework.Common.OperationCenter;
  5. using MECF.Framework.Common.Persistent.VpwCell;
  6. using MECF.Framework.Common.Persistent.VpwMain;
  7. using MECF.Framework.Common.Utilities;
  8. using Prism.Mvvm;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows.Input;
  15. using System.Windows.Threading;
  16. namespace PunkHPX8_MainPages.ViewModels
  17. {
  18. public class VPWCellViewModel:BindableBase
  19. {
  20. #region 常量
  21. private const string COMMONDATA = "CommonData";
  22. private const string VPW = "vpw";
  23. private const string PERSISTENT_VALUE = "PersistentValue";
  24. #endregion
  25. #region 内部变量
  26. #region Common
  27. /// <summary>
  28. /// 模块名称
  29. /// </summary>
  30. private string _module;
  31. /// <summary>
  32. /// StateMachine
  33. /// </summary>
  34. private string _stateMachine;
  35. /// <summary>
  36. /// Status
  37. /// </summary>
  38. private string _status;
  39. /// <summary>
  40. /// 数据
  41. /// </summary>
  42. private VpwCellCommonData _vpwCellCommonData;
  43. /// <summary>
  44. /// VPW Main数据
  45. /// </summary>
  46. private VpwMainCommonData _vpwMainCommonData;
  47. /// <summary>
  48. /// Threshold
  49. /// </summary>
  50. private VpwCellPersistentValue _vpwCellPersistent;
  51. /// <summary>
  52. /// 是否是Manual模式
  53. /// </summary>
  54. private bool _isManualOperationMode;
  55. #endregion
  56. #region VPW recipe
  57. /// <summary>
  58. /// RecipeModuleName
  59. /// </summary>
  60. private string _recipeModuleName;
  61. /// <summary>
  62. /// RecipeType
  63. /// </summary>
  64. private string _recipeType;
  65. /// <summary>
  66. /// AchievedRunRecipeCycle
  67. /// </summary>
  68. private int _achievedRunRecipeCycle;
  69. /// <summary>
  70. /// 当前Recipe
  71. /// </summary>
  72. private string _currentRecipe;
  73. /// <summary>
  74. /// RecipeContent
  75. /// </summary>
  76. private string _recipeContent;
  77. /// <summary>
  78. /// TimeRemaining
  79. /// </summary>
  80. private int _timeRemaining;
  81. /// <summary>
  82. /// OfTotalTime
  83. /// </summary>
  84. private int _totalTime;
  85. /// <summary>
  86. /// OperatingMode
  87. /// </summary>
  88. private string _operatingMode;
  89. /// <summary>
  90. /// State Machine
  91. /// </summary>
  92. private string _state;
  93. /// <summary>
  94. /// RecipeMode
  95. /// </summary>
  96. private string _recipeMode;
  97. #endregion
  98. #region UI
  99. /// <summary>
  100. /// IsErrorState 用于腔体变红
  101. /// </summary>
  102. private bool _isErrorState;
  103. /// <summary>
  104. /// 页面功能启用
  105. /// </summary>
  106. private bool _isEnabled;
  107. /// <summary>
  108. /// AutoMode页面功能启用
  109. /// </summary>
  110. private bool _isAutoEnabled;
  111. #endregion
  112. #endregion
  113. #region 系统数据
  114. /// <summary>
  115. /// 定时器
  116. /// </summary>
  117. DispatcherTimer _timer;
  118. /// <summary>
  119. /// 查询后台数据集合
  120. /// </summary>
  121. private List<string> _rtDataKeys = new List<string>();
  122. /// <summary>
  123. /// rt查询key数值字典
  124. /// </summary>
  125. private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
  126. #endregion
  127. #region 属性
  128. #region Common
  129. /// <summary>
  130. /// 模块名称
  131. /// </summary>
  132. public string Module { get { return _module; } set { SetProperty(ref _module, value); } }
  133. /// <summary>
  134. /// StateMachine
  135. /// </summary>
  136. public string StateMachine { get { return _stateMachine; } set { SetProperty(ref _stateMachine, value); } }
  137. /// <summary>
  138. /// Status
  139. /// </summary>
  140. public string Status { get { return _status; } set { SetProperty(ref _status, value); } }
  141. /// <summary>
  142. /// Commondata
  143. /// </summary>
  144. public VpwMainCommonData VpwMainCommonData
  145. {
  146. get { return _vpwMainCommonData; }
  147. set { SetProperty(ref _vpwMainCommonData, value); }
  148. }
  149. /// <summary>
  150. /// Commondata
  151. /// </summary>
  152. public VpwCellCommonData VpwCellCommonData
  153. {
  154. get { return _vpwCellCommonData; }
  155. set { SetProperty(ref _vpwCellCommonData, value); }
  156. }
  157. /// <summary>
  158. /// Persistent
  159. /// </summary>
  160. public VpwCellPersistentValue VpwCellPersistent
  161. {
  162. get { return _vpwCellPersistent; }
  163. set { SetProperty(ref _vpwCellPersistent, value); }
  164. }
  165. /// <summary>
  166. /// 是否是Manual模式
  167. /// </summary>
  168. public bool IsManualOperationMode { get { return _isManualOperationMode; } set { SetProperty(ref _isManualOperationMode, value); } }
  169. #endregion
  170. #region VPW recipe
  171. /// <summary>
  172. /// RecipeModuleName
  173. /// </summary>
  174. public string RecipeModuleName
  175. {
  176. get { return _recipeModuleName; }
  177. set { SetProperty(ref _recipeModuleName, value); }
  178. }
  179. /// <summary>
  180. /// RecipeType
  181. /// </summary>
  182. public string RecipeType
  183. {
  184. get { return _recipeType; }
  185. set { SetProperty(ref _recipeType, value); }
  186. }
  187. public int AchievedRunRecipeCycle
  188. {
  189. get { return _achievedRunRecipeCycle; }
  190. set { SetProperty(ref _achievedRunRecipeCycle, value); }
  191. }
  192. /// <summary>
  193. /// 当前运行的Recipe
  194. /// </summary>
  195. public string CurrentRecipe
  196. {
  197. get { return _currentRecipe; }
  198. set { SetProperty(ref _currentRecipe, value); }
  199. }
  200. /// <summary>
  201. /// RecipeContent
  202. /// </summary>
  203. public string RecipeContent
  204. {
  205. get { return _recipeContent; }
  206. set { SetProperty(ref _recipeContent, value); }
  207. }
  208. /// <summary>
  209. /// TimeRemaining
  210. /// </summary>
  211. public int TimeRemaining
  212. {
  213. get { return _timeRemaining; }
  214. set { SetProperty(ref _timeRemaining, value); }
  215. }
  216. /// <summary>
  217. /// TotalTime
  218. /// </summary>
  219. public int TotalTime
  220. {
  221. get { return _totalTime; }
  222. set { SetProperty(ref _totalTime, value); }
  223. }
  224. /// <summary>
  225. /// OperatingMode
  226. /// </summary>
  227. public string OperatingMode
  228. {
  229. get { return _operatingMode; }
  230. set { SetProperty(ref _operatingMode, value); }
  231. }
  232. /// <summary>
  233. /// State
  234. /// </summary>
  235. public string State
  236. {
  237. get { return _state; }
  238. set { SetProperty(ref _state, value); }
  239. }
  240. /// <summary>
  241. /// RecipeMode
  242. /// </summary>
  243. public string RecipeMode
  244. {
  245. get { return _recipeMode; }
  246. set { SetProperty(ref _recipeMode, value); }
  247. }
  248. #endregion
  249. #region UI
  250. /// <summary>
  251. /// IsErrorState
  252. /// </summary>
  253. public bool IsErrorState { get { return _isErrorState; } set { SetProperty(ref _isErrorState, value); } }
  254. /// <summary>
  255. /// 页面功能启用
  256. /// </summary>
  257. public bool IsEnabled
  258. {
  259. get { return _isEnabled; }
  260. set { SetProperty(ref _isEnabled, value); }
  261. }
  262. /// <summary>
  263. /// AutoMode页面功能启用
  264. /// </summary>
  265. public bool IsAutoEnabled
  266. {
  267. get { return _isAutoEnabled; }
  268. set { SetProperty(ref _isAutoEnabled, value); }
  269. }
  270. #endregion
  271. #endregion
  272. #region Command指令
  273. public ICommand InitializeCommand { get; set; }
  274. public ICommand HomeCommand { get; set; }
  275. #endregion
  276. public VPWCellViewModel()
  277. {
  278. InitializeCommand = new DelegateCommand<object>(InitializeAction);
  279. HomeCommand = new DelegateCommand<object>(HomeAction);
  280. }
  281. /// <summary>
  282. /// 加载数据
  283. /// </summary>
  284. public void LoadData(string systemName)
  285. {
  286. Module = systemName;
  287. RecipeModuleName = "VPW Recipe";
  288. RecipeType = "vpw";
  289. _rtDataKeys.Clear();
  290. List<string> lst = new List<string>();
  291. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(lst);
  292. _rtDataKeys.Add($"{Module}.{PERSISTENT_VALUE}");
  293. _rtDataKeys.Add($"{Module}.{COMMONDATA}");
  294. _rtDataKeys.Add($"{Module}.FsmState");
  295. _rtDataKeys.Add($"VPWMain1.{COMMONDATA}");
  296. _rtDataKeys.Add($"{Module}.AchievedCycle");
  297. if (_timer == null)
  298. {
  299. _timer = new DispatcherTimer();
  300. _timer.Interval = TimeSpan.FromMilliseconds(200);
  301. _timer.Tick += Timer_Tick;
  302. }
  303. _timer.Start();
  304. }
  305. /// <summary>
  306. /// 定时器执行
  307. /// </summary>
  308. /// <param name="sender"></param>
  309. /// <param name="e"></param>
  310. private void Timer_Tick(object sender, EventArgs e)
  311. {
  312. if (_rtDataKeys.Count != 0)
  313. {
  314. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  315. if (_rtDataValueDic != null)
  316. {
  317. VpwCellCommonData = CommonFunction.GetValue<VpwCellCommonData>(_rtDataValueDic, $"{Module}.{COMMONDATA}");
  318. VpwMainCommonData = CommonFunction.GetValue<VpwMainCommonData>(_rtDataValueDic, $"VPWMain1.{COMMONDATA}");
  319. VpwCellPersistent = CommonFunction.GetValue<VpwCellPersistentValue>(_rtDataValueDic, $"{Module}.{PERSISTENT_VALUE}");
  320. StateMachine = CommonFunction.GetValue<string>(_rtDataValueDic, $"{Module}.FsmState");
  321. if ("Manual".Equals(VpwCellPersistent.OperatingMode))
  322. {
  323. IsEnabled = true;
  324. IsAutoEnabled = true;
  325. }
  326. else if ("Auto".Equals(VpwCellPersistent.OperatingMode))
  327. {
  328. IsAutoEnabled = true;
  329. IsEnabled = false;
  330. }
  331. else
  332. {
  333. State = "Stopped";
  334. IsEnabled = false;
  335. IsAutoEnabled = false;
  336. }
  337. AchievedRunRecipeCycle = CommonFunction.GetValue<int>(_rtDataValueDic, $"{Module}.AchievedCycle");
  338. }
  339. }
  340. }
  341. /// <summary>
  342. /// 隐藏
  343. /// </summary>
  344. public void Hide()
  345. {
  346. if (_timer != null)
  347. {
  348. _timer.Stop();
  349. }
  350. }
  351. #region 指令Action
  352. /// <summary>
  353. /// Initialize Action
  354. /// </summary>
  355. /// <param name="param"></param>
  356. private void InitializeAction(object param)
  357. {
  358. InvokeClient.Instance.Service.DoOperation($"{Module}.InitializeAll");
  359. }
  360. /// <summary>
  361. /// Home Action
  362. /// </summary>
  363. /// <param name="param"></param>
  364. private void HomeAction(object param)
  365. {
  366. InvokeClient.Instance.Service.DoOperation($"{Module}.Home");
  367. }
  368. #endregion
  369. }
  370. }