DMReservoirViewModel.cs 17 KB

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