DMReservoirViewModel.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. using Aitex.Core.UI.MVVM;
  2. using MECF.Framework.Common.CommonData.Reservoir;
  3. using MECF.Framework.Common.CommonData.TemperatureControl;
  4. using MECF.Framework.Common.DataCenter;
  5. using MECF.Framework.Common.Device.Safety;
  6. using MECF.Framework.Common.Equipment;
  7. using MECF.Framework.Common.OperationCenter;
  8. using MECF.Framework.Common.Persistent.Reservoirs;
  9. using MECF.Framework.Common.RecipeCenter;
  10. using MECF.Framework.Common.Utilities;
  11. using Prism.Mvvm;
  12. using PunkHPX8_Core;
  13. using PunkHPX8_MainPages.Model;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Collections.ObjectModel;
  17. using System.Linq;
  18. using System.Text;
  19. using System.Threading.Tasks;
  20. using System.Windows;
  21. using System.Windows.Input;
  22. using System.Windows.Threading;
  23. namespace PunkHPX8_MainPages.ViewModels
  24. {
  25. public class DMReservoirViewModel : BindableBase
  26. {
  27. #region 常量
  28. private const string RESERVOIRS_DATA = "ReservoirsData";
  29. private const string RESERVOIRS = "reservoirs";
  30. private const string PERSISTENT_VALUE = "PersistentValue";
  31. #endregion
  32. #region 内部变量
  33. private List<string> _rtDataKeys = new List<string>();
  34. private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
  35. DispatcherTimer _timer;
  36. private bool _isEnabled;
  37. private bool _isError;
  38. private bool _isAutoEnabled;
  39. private SafetyData _commonSafetyData;
  40. private string _module;
  41. private string _state;
  42. private ResRecipe _currentRecipe;
  43. private ReservoirsPersistentValue _reservoirsPersistent;
  44. private string _recipeType;
  45. private int _inputCAPumpSpeed;
  46. private int _inputANPumpSpeed;
  47. private int _inputReturnFlowOpenPercent;
  48. private TemperatureControllerData _temperatureControlData;
  49. private string _tcEnableStatus;
  50. private string _tcName;
  51. private ReservoirData _reservoirData;
  52. private bool _isCAHighLevel;
  53. private bool _isCALowLevel;
  54. private double _avgCaLevel;
  55. private ObservableCollection<RecipeNode> _recipeNodes;
  56. private string _currentRecipeFileName;
  57. /// <summary>
  58. /// 是否配置Exhaust
  59. /// </summary>
  60. private bool _isEvaporatorConfig;
  61. /// <summary>
  62. /// 阴极是否正在手动注水
  63. /// </summary>
  64. private bool _isManualReplen;
  65. /// <summary>
  66. /// 阳极是否正在手动注水
  67. /// </summary>
  68. private bool _isANManualReplen;
  69. /// <summary>
  70. /// 阴极手动注水时长(秒)
  71. /// </summary>
  72. private int _manualFillSeconds;
  73. /// <summary>
  74. /// 阳极手动注水时长(秒)
  75. /// </summary>
  76. private int _manualANFillSeconds;
  77. /// <summary>
  78. /// DIValveMaxOnTime
  79. /// </summary>
  80. private double _diValveMaxOnTime;
  81. /// <summary>
  82. /// 是否补水异常
  83. /// </summary>
  84. private bool _isDIReplenFault;
  85. #endregion
  86. #region 属性
  87. public string Module
  88. {
  89. get { return _module; }
  90. set { SetProperty(ref _module, value); }
  91. }
  92. public bool IsEnabled
  93. {
  94. get { return _isEnabled; }
  95. set { SetProperty(ref _isEnabled, value); }
  96. }
  97. public bool IsError
  98. {
  99. get { return _isError; }
  100. set { SetProperty(ref _isError, value); }
  101. }
  102. public bool IsAutoEnabled
  103. {
  104. get { return _isAutoEnabled; }
  105. set { SetProperty(ref _isAutoEnabled, value); }
  106. }
  107. public SafetyData CommonSafetyData
  108. {
  109. get { return _commonSafetyData; }
  110. set { SetProperty(ref _commonSafetyData, value); }
  111. }
  112. public string State
  113. {
  114. get { return _state; }
  115. set { SetProperty(ref _state, value); }
  116. }
  117. public ResRecipe CurrentRecipe
  118. {
  119. get { return _currentRecipe; }
  120. set { SetProperty(ref _currentRecipe, value); }
  121. }
  122. public ReservoirsPersistentValue ReservoirsPersistent
  123. {
  124. get { return _reservoirsPersistent; }
  125. set { SetProperty(ref _reservoirsPersistent, value); }
  126. }
  127. public string RecipeType
  128. {
  129. get { return _recipeType; }
  130. set { SetProperty(ref _recipeType, value); }
  131. }
  132. public int InputCAPumpSpeed
  133. {
  134. get { return _inputCAPumpSpeed; }
  135. set
  136. {
  137. SetProperty(ref _inputCAPumpSpeed, value);
  138. }
  139. }
  140. public int InputANPumpSpeed
  141. {
  142. get { return _inputANPumpSpeed; }
  143. set
  144. {
  145. SetProperty(ref _inputANPumpSpeed, value);
  146. }
  147. }
  148. public int InputRetrunFlowOpenPercent
  149. {
  150. get { return _inputReturnFlowOpenPercent; }
  151. set
  152. {
  153. SetProperty(ref _inputReturnFlowOpenPercent, value);
  154. }
  155. }
  156. public TemperatureControllerData TemperatureControlData
  157. {
  158. get { return _temperatureControlData; }
  159. set { SetProperty(ref _temperatureControlData, value); }
  160. }
  161. public string TCEnableStatus
  162. {
  163. get { return _tcEnableStatus; }
  164. set { SetProperty(ref _tcEnableStatus, value); }
  165. }
  166. public ReservoirData ReservoirData
  167. {
  168. get { return _reservoirData; }
  169. set { SetProperty(ref _reservoirData, value); }
  170. }
  171. public bool IsCAHighLevel
  172. {
  173. get { return _isCAHighLevel; }
  174. set { SetProperty(ref _isCAHighLevel, value); }
  175. }
  176. public bool IsCALowLevel
  177. {
  178. get { return _isCALowLevel; }
  179. set { SetProperty(ref _isCALowLevel, value); }
  180. }
  181. /// <summary>
  182. /// Ca Level采样周期内平均值
  183. /// </summary>
  184. public double AvgCALevel
  185. {
  186. get { return _avgCaLevel; }
  187. set { SetProperty(ref _avgCaLevel, value); }
  188. }
  189. /// <summary>
  190. /// 单次注水最大时长
  191. /// </summary>
  192. public double DIValveMaxOnTime
  193. {
  194. get { return _diValveMaxOnTime; }
  195. set { SetProperty(ref _diValveMaxOnTime, value); }
  196. }
  197. /// <summary>
  198. /// 阴极手动注水时长
  199. /// </summary>
  200. public int ManualFillSeconds
  201. {
  202. get { return _manualFillSeconds; }
  203. set { SetProperty(ref _manualFillSeconds, value); }
  204. }
  205. /// <summary>
  206. /// 阳极手动注水时长
  207. /// </summary>
  208. public int ManualANFillSeconds
  209. {
  210. get { return _manualANFillSeconds; }
  211. set { SetProperty(ref _manualANFillSeconds, value); }
  212. }
  213. /// <summary>
  214. /// 阴极正在手动注水
  215. /// </summary>
  216. public bool IsManualReplen
  217. {
  218. get { return _isManualReplen; }
  219. set { SetProperty(ref _isManualReplen, value); }
  220. }
  221. /// <summary>
  222. /// 阳极正在手动注水
  223. /// </summary>
  224. public bool IsANManualReplen
  225. {
  226. get { return _isANManualReplen; }
  227. set { SetProperty(ref _isANManualReplen, value); }
  228. }
  229. /// <summary>
  230. /// 是否补水异常
  231. /// </summary>
  232. public bool IsDIReplenFault
  233. {
  234. get { return _isDIReplenFault; }
  235. set { SetProperty(ref _isDIReplenFault, value); }
  236. }
  237. #endregion
  238. #region 指令
  239. public ICommand InitializeCommand { get; set; }
  240. public ICommand CAPumpSpeedSetCommand { get; set; }
  241. public ICommand ANPumpSpeedSetCommand { get; set; }
  242. public ICommand ReturnFlowOpenPercentSetCommand { get; set; }
  243. public ICommand ResetTotalCommand { get; set; }
  244. public ICommand ManualDireplenCommand { get; set; }
  245. public ICommand ManualANDireplenCommand { get; set; }
  246. public ICommand JumpToPlatingCellCommand { get; set; }
  247. #endregion
  248. public DMReservoirViewModel()
  249. {
  250. InitializeCommand = new DelegateCommand<object>(InitializeAction);
  251. CAPumpSpeedSetCommand = new DelegateCommand<object>(CAPumpSpeedSetAction);
  252. ANPumpSpeedSetCommand = new DelegateCommand<object>(ANPumpSpeedSetAction);
  253. ReturnFlowOpenPercentSetCommand = new DelegateCommand<object>(ReturnFlowOpenPercentSetAction);
  254. ResetTotalCommand = new DelegateCommand<object>(ResetTotalAction);
  255. ManualDireplenCommand = new DelegateCommand<object>(ManualDireplenAction);
  256. ManualANDireplenCommand = new DelegateCommand<object>(ManualANDireplenAction);
  257. JumpToPlatingCellCommand = new DelegateCommand<object>(JumpToPlatingCellAction);
  258. }
  259. #region 命令方法
  260. /// <summary>
  261. /// 初始化
  262. /// </summary>
  263. /// <param name="param"></param>
  264. private void InitializeAction(object param)
  265. {
  266. InvokeClient.Instance.Service.DoOperation($"{Module}.InitializeAll");
  267. }
  268. /// <summary>
  269. /// 设置CA pump泵速
  270. /// </summary>
  271. /// <param name="param"></param>
  272. private void CAPumpSpeedSetAction(object param)
  273. {
  274. if (InputCAPumpSpeed>100 || InputCAPumpSpeed < 0)
  275. {
  276. MessageBox.Show($"Input CAPumpSpeed value in 0~100", "Error",
  277. MessageBoxButton.OK, MessageBoxImage.Error);
  278. return;
  279. }
  280. InvokeClient.Instance.Service.DoOperation($"{Module}.CAPumpSpeed",InputCAPumpSpeed);
  281. }
  282. /// <summary>
  283. /// 设置AN pump泵速
  284. /// </summary>
  285. /// <param name="param"></param>
  286. private void ANPumpSpeedSetAction(object param)
  287. {
  288. if (InputANPumpSpeed > 100 || InputANPumpSpeed < 0)
  289. {
  290. MessageBox.Show($"Input ANPumpSpeed value in 0~100", "Error",
  291. MessageBoxButton.OK, MessageBoxImage.Error);
  292. return;
  293. }
  294. InvokeClient.Instance.Service.DoOperation($"{Module}.ANPumpSpeed", InputANPumpSpeed);
  295. }
  296. /// <summary>
  297. /// 设置return flow valve开闭的程度
  298. /// </summary>
  299. /// <param name="param"></param>
  300. private void ReturnFlowOpenPercentSetAction(object param)
  301. {
  302. if (InputRetrunFlowOpenPercent > 100 || InputRetrunFlowOpenPercent < 0)
  303. {
  304. MessageBox.Show($"Input RetrunFlowOpenPercent value in 0~100", "Error",
  305. MessageBoxButton.OK, MessageBoxImage.Error);
  306. return;
  307. }
  308. InvokeClient.Instance.Service.DoOperation($"{Module}.ReturnValvePercent", InputRetrunFlowOpenPercent);
  309. }
  310. /// <summary>
  311. /// 重置TotalTime
  312. /// </summary>
  313. private void ResetTotalAction(object param)
  314. {
  315. InvokeClient.Instance.Service.DoOperation($"{Module}.ResetTotalTime");
  316. }
  317. /// <summary>
  318. /// 手动阴极注水
  319. /// </summary>
  320. /// <param name="param"></param>
  321. private void ManualDireplenAction(object param)
  322. {
  323. InvokeClient.Instance.Service.DoOperation($"{Module}.ManualCADiReplen", ManualFillSeconds);
  324. }
  325. /// <summary>
  326. /// 手动阳极注水
  327. /// </summary>
  328. /// <param name="param"></param>
  329. private void ManualANDireplenAction(object param)
  330. {
  331. InvokeClient.Instance.Service.DoOperation($"{Module}.ManualANDiReplen", ManualANFillSeconds);
  332. }
  333. private void JumpToPlatingCellAction(object param)
  334. {
  335. GlobalEvents.OnSwitchFixedTabItem("HardWare", "PlatingCells", $"Platingcell{Module.Substring(Module.Length-1)}");
  336. }
  337. #endregion
  338. public void LoadData(string systemName)
  339. {
  340. RecipeType = "res";
  341. Module = systemName;
  342. _rtDataKeys.Clear();
  343. _rtDataKeys.Add($"{Module}.{PERSISTENT_VALUE}");
  344. _rtDataKeys.Add($"{Module}.CurrentRecipe");
  345. _rtDataKeys.Add($"{Module}.FsmState");
  346. _rtDataKeys.Add($"Safety.SafetyData");
  347. _rtDataKeys.Add($"{Module}.ReservoirData");
  348. _rtDataKeys.Add($"{Module}.IsCAHighLevel");
  349. _rtDataKeys.Add($"{Module}.IsCALowLevel");
  350. _rtDataKeys.Add($"{Module}.TemperatureControllerData");
  351. _rtDataKeys.Add($"{Module}.DIValveMaxOnTime");
  352. _rtDataKeys.Add($"{Module}.IsManualCAReplen");
  353. _rtDataKeys.Add($"{Module}.IsManualANReplen");
  354. _rtDataKeys.Add($"{Module}.IsDIReplenPerfillTimeOut");
  355. _rtDataKeys.Add($"{Module}.IsDIReplenMaxTimeOut");
  356. _rtDataKeys.Add($"{Module}.AvgCALevel");
  357. if (_timer == null)
  358. {
  359. _timer = new DispatcherTimer();
  360. _timer.Interval = TimeSpan.FromMilliseconds(200);
  361. _timer.Tick += Timer_Tick;
  362. }
  363. _timer.Start();
  364. }
  365. private void Timer_Tick(object sender, EventArgs e)
  366. {
  367. if (_rtDataKeys.Count != 0)
  368. {
  369. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  370. if (_rtDataValueDic != null)
  371. {
  372. State = CommonFunction.GetValue<string>(_rtDataValueDic, $"{Module}.FsmState");
  373. //Error时UI腔体变红
  374. IsError = "Error".Equals(State) ? true : false;
  375. ReservoirData = CommonFunction.GetValue<ReservoirData>(_rtDataValueDic, $"{Module}.ReservoirData");
  376. CommonSafetyData = CommonFunction.GetValue<SafetyData>(_rtDataValueDic, $"Safety.SafetyData");
  377. ReservoirsPersistent = CommonFunction.GetValue<ReservoirsPersistentValue>(_rtDataValueDic, $"{Module}.{PERSISTENT_VALUE}");
  378. if (ReservoirsPersistent!= null && "Manual".Equals(ReservoirsPersistent.OperatingMode))
  379. {
  380. IsEnabled = true;
  381. IsAutoEnabled = true;
  382. }
  383. else if (ReservoirsPersistent != null && "Auto".Equals(ReservoirsPersistent.OperatingMode))
  384. {
  385. IsAutoEnabled = true;
  386. IsEnabled = false;
  387. }
  388. else
  389. {
  390. State = "Stopped";
  391. IsEnabled = false;
  392. IsAutoEnabled = false;
  393. }
  394. CurrentRecipe = CommonFunction.GetValue<ResRecipe>(_rtDataValueDic, $"{Module}.CurrentRecipe");
  395. TemperatureControlData = CommonFunction.GetValue<TemperatureControllerData>(_rtDataValueDic, $"{Module}.TemperatureControllerData");
  396. TCEnableStatus = TemperatureControlData.ControlOperationModel == 0 ? "Disable" : "Enable";
  397. _tcName = TemperatureControlData.Name;
  398. IsCAHighLevel = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsCAHighLevel");
  399. IsCALowLevel = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsCALowLevel");
  400. AvgCALevel = CommonFunction.GetValue<double>(_rtDataValueDic, $"{Module}.AvgCALevel");
  401. DIValveMaxOnTime = CommonFunction.GetValue<double>(_rtDataValueDic, $"{Module}.DIValveMaxOnTime");
  402. IsManualReplen = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsManualCAReplen");
  403. IsDIReplenFault = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsDIReplenPerfillTimeOut")
  404. || CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsDIReplenMaxTimeOut");
  405. IsANManualReplen = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsManualANReplen");
  406. }
  407. }
  408. }
  409. /// <summary>
  410. /// 隐藏
  411. /// </summary>
  412. public void Hide()
  413. {
  414. if (_timer != null)
  415. {
  416. _timer.Stop();
  417. }
  418. }
  419. }
  420. }