DMReservoirViewModel.cs 15 KB

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