VPWCellViewModel.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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. /// <summary>
  112. /// 水阻值
  113. /// </summary>
  114. private double _diwLoopDo;
  115. #endregion
  116. #endregion
  117. #region 系统数据
  118. /// <summary>
  119. /// 定时器
  120. /// </summary>
  121. DispatcherTimer _timer;
  122. /// <summary>
  123. /// 查询后台数据集合
  124. /// </summary>
  125. private List<string> _rtDataKeys = new List<string>();
  126. /// <summary>
  127. /// rt查询key数值字典
  128. /// </summary>
  129. private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
  130. #endregion
  131. #region 属性
  132. #region Common
  133. /// <summary>
  134. /// 模块名称
  135. /// </summary>
  136. public string Module { get { return _module; } set { SetProperty(ref _module, value); } }
  137. /// <summary>
  138. /// StateMachine
  139. /// </summary>
  140. public string StateMachine { get { return _stateMachine; } set { SetProperty(ref _stateMachine, value); } }
  141. /// <summary>
  142. /// Status
  143. /// </summary>
  144. public string Status { get { return _status; } set { SetProperty(ref _status, value); } }
  145. /// <summary>
  146. /// Commondata
  147. /// </summary>
  148. public VpwMainCommonData VpwMainCommonData
  149. {
  150. get { return _vpwMainCommonData; }
  151. set { SetProperty(ref _vpwMainCommonData, value); }
  152. }
  153. /// <summary>
  154. /// Commondata
  155. /// </summary>
  156. public VpwCellCommonData VpwCellCommonData
  157. {
  158. get { return _vpwCellCommonData; }
  159. set { SetProperty(ref _vpwCellCommonData, value); }
  160. }
  161. /// <summary>
  162. /// Persistent
  163. /// </summary>
  164. public VpwCellPersistentValue VpwCellPersistent
  165. {
  166. get { return _vpwCellPersistent; }
  167. set { SetProperty(ref _vpwCellPersistent, value); }
  168. }
  169. /// <summary>
  170. /// 是否是Manual模式
  171. /// </summary>
  172. public bool IsManualOperationMode { get { return _isManualOperationMode; } set { SetProperty(ref _isManualOperationMode, value); } }
  173. #endregion
  174. #region VPW recipe
  175. /// <summary>
  176. /// RecipeModuleName
  177. /// </summary>
  178. public string RecipeModuleName
  179. {
  180. get { return _recipeModuleName; }
  181. set { SetProperty(ref _recipeModuleName, value); }
  182. }
  183. /// <summary>
  184. /// RecipeType
  185. /// </summary>
  186. public string RecipeType
  187. {
  188. get { return _recipeType; }
  189. set { SetProperty(ref _recipeType, value); }
  190. }
  191. public int AchievedRunRecipeCycle
  192. {
  193. get { return _achievedRunRecipeCycle; }
  194. set { SetProperty(ref _achievedRunRecipeCycle, value); }
  195. }
  196. /// <summary>
  197. /// 当前运行的Recipe
  198. /// </summary>
  199. public string CurrentRecipe
  200. {
  201. get { return _currentRecipe; }
  202. set { SetProperty(ref _currentRecipe, value); }
  203. }
  204. /// <summary>
  205. /// RecipeContent
  206. /// </summary>
  207. public string RecipeContent
  208. {
  209. get { return _recipeContent; }
  210. set { SetProperty(ref _recipeContent, value); }
  211. }
  212. /// <summary>
  213. /// TimeRemaining
  214. /// </summary>
  215. public int TimeRemaining
  216. {
  217. get { return _timeRemaining; }
  218. set { SetProperty(ref _timeRemaining, value); }
  219. }
  220. /// <summary>
  221. /// TotalTime
  222. /// </summary>
  223. public int TotalTime
  224. {
  225. get { return _totalTime; }
  226. set { SetProperty(ref _totalTime, value); }
  227. }
  228. /// <summary>
  229. /// OperatingMode
  230. /// </summary>
  231. public string OperatingMode
  232. {
  233. get { return _operatingMode; }
  234. set { SetProperty(ref _operatingMode, value); }
  235. }
  236. /// <summary>
  237. /// State
  238. /// </summary>
  239. public string State
  240. {
  241. get { return _state; }
  242. set { SetProperty(ref _state, value); }
  243. }
  244. /// <summary>
  245. /// RecipeMode
  246. /// </summary>
  247. public string RecipeMode
  248. {
  249. get { return _recipeMode; }
  250. set { SetProperty(ref _recipeMode, value); }
  251. }
  252. #endregion
  253. #region UI
  254. /// <summary>
  255. /// IsErrorState
  256. /// </summary>
  257. public bool IsErrorState { get { return _isErrorState; } set { SetProperty(ref _isErrorState, value); } }
  258. /// <summary>
  259. /// 页面功能启用
  260. /// </summary>
  261. public bool IsEnabled
  262. {
  263. get { return _isEnabled; }
  264. set { SetProperty(ref _isEnabled, value); }
  265. }
  266. /// <summary>
  267. /// AutoMode页面功能启用
  268. /// </summary>
  269. public bool IsAutoEnabled
  270. {
  271. get { return _isAutoEnabled; }
  272. set { SetProperty(ref _isAutoEnabled, value); }
  273. }
  274. /// <summary>
  275. /// 水阻值
  276. /// </summary>
  277. public double DiwLoopDo
  278. {
  279. get { return _diwLoopDo; }
  280. set { SetProperty(ref _diwLoopDo, value); }
  281. }
  282. #endregion
  283. #endregion
  284. #region Command指令
  285. public ICommand InitializeCommand { get; set; }
  286. public ICommand HomeCommand { get; set; }
  287. #endregion
  288. public VPWCellViewModel()
  289. {
  290. InitializeCommand = new DelegateCommand<object>(InitializeAction);
  291. HomeCommand = new DelegateCommand<object>(HomeAction);
  292. }
  293. /// <summary>
  294. /// 加载数据
  295. /// </summary>
  296. public void LoadData(string systemName)
  297. {
  298. Module = systemName;
  299. RecipeModuleName = "VPW Recipe";
  300. RecipeType = "vpw";
  301. _rtDataKeys.Clear();
  302. List<string> lst = new List<string>();
  303. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(lst);
  304. _rtDataKeys.Add($"{Module}.{PERSISTENT_VALUE}");
  305. _rtDataKeys.Add($"{Module}.{COMMONDATA}");
  306. _rtDataKeys.Add($"{Module}.FsmState");
  307. _rtDataKeys.Add($"VPWMain1.{COMMONDATA}");
  308. _rtDataKeys.Add($"{Module}.AchievedCycle");
  309. _rtDataKeys.Add($"{Module}.LoopDoValue");
  310. if (_timer == null)
  311. {
  312. _timer = new DispatcherTimer();
  313. _timer.Interval = TimeSpan.FromMilliseconds(200);
  314. _timer.Tick += Timer_Tick;
  315. }
  316. _timer.Start();
  317. }
  318. /// <summary>
  319. /// 定时器执行
  320. /// </summary>
  321. /// <param name="sender"></param>
  322. /// <param name="e"></param>
  323. private void Timer_Tick(object sender, EventArgs e)
  324. {
  325. if (_rtDataKeys.Count != 0)
  326. {
  327. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  328. if (_rtDataValueDic != null)
  329. {
  330. VpwCellCommonData = CommonFunction.GetValue<VpwCellCommonData>(_rtDataValueDic, $"{Module}.{COMMONDATA}");
  331. VpwMainCommonData = CommonFunction.GetValue<VpwMainCommonData>(_rtDataValueDic, $"VPWMain1.{COMMONDATA}");
  332. VpwCellPersistent = CommonFunction.GetValue<VpwCellPersistentValue>(_rtDataValueDic, $"{Module}.{PERSISTENT_VALUE}");
  333. StateMachine = CommonFunction.GetValue<string>(_rtDataValueDic, $"{Module}.FsmState");
  334. if ("Manual".Equals(VpwCellPersistent.OperatingMode))
  335. {
  336. IsEnabled = true;
  337. IsAutoEnabled = true;
  338. }
  339. else if ("Auto".Equals(VpwCellPersistent.OperatingMode))
  340. {
  341. IsAutoEnabled = true;
  342. IsEnabled = false;
  343. }
  344. else
  345. {
  346. State = "Stopped";
  347. IsEnabled = false;
  348. IsAutoEnabled = false;
  349. }
  350. AchievedRunRecipeCycle = CommonFunction.GetValue<int>(_rtDataValueDic, $"{Module}.AchievedCycle");
  351. DiwLoopDo = CommonFunction.GetValue<double>(_rtDataValueDic, $"{Module}.LoopDoValue");
  352. }
  353. }
  354. }
  355. /// <summary>
  356. /// 隐藏
  357. /// </summary>
  358. public void Hide()
  359. {
  360. if (_timer != null)
  361. {
  362. _timer.Stop();
  363. }
  364. }
  365. #region 指令Action
  366. /// <summary>
  367. /// Initialize Action
  368. /// </summary>
  369. /// <param name="param"></param>
  370. private void InitializeAction(object param)
  371. {
  372. InvokeClient.Instance.Service.DoOperation($"{Module}.InitializeAll");
  373. }
  374. /// <summary>
  375. /// Home Action
  376. /// </summary>
  377. /// <param name="param"></param>
  378. private void HomeAction(object param)
  379. {
  380. InvokeClient.Instance.Service.DoOperation($"{Module}.Home");
  381. }
  382. #endregion
  383. }
  384. }