DMReservoirViewModel.cs 17 KB

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