DMReservoirViewModel.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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.Input;
  20. using System.Windows.Threading;
  21. namespace PunkHPX8_MainPages.ViewModels
  22. {
  23. public class DMReservoirViewModel : BindableBase
  24. {
  25. #region 常量
  26. private const string RESERVOIRS_DATA = "ReservoirsData";
  27. private const string RESERVOIRS = "reservoirs";
  28. private const string PERSISTENT_VALUE = "PersistentValue";
  29. #endregion
  30. #region 内部变量
  31. private List<string> _rtDataKeys = new List<string>();
  32. private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
  33. DispatcherTimer _timer;
  34. private bool _isEnabled;
  35. private bool _isError;
  36. private bool _isAutoEnabled;
  37. private SafetyData _commonSafetyData;
  38. private string _module;
  39. private string _state;
  40. private ResRecipe _currentRecipe;
  41. private ReservoirsPersistentValue _reservoirsPersistent;
  42. private string _recipeType;
  43. private int _inputCAPumpSpeed;
  44. private int _inputANPumpSpeed;
  45. private int _inputReturnFlowOpenPercent;
  46. private TemperatureControllerData _temperatureControlData;
  47. private string _tcEnableStatus;
  48. private string _tcName;
  49. private ReservoirData _reservoirData;
  50. private bool _isCAHighLevel;
  51. private bool _isCALowLevel;
  52. private ObservableCollection<RecipeNode> _recipeNodes;
  53. private string _currentRecipeFileName;
  54. private double _returnValveOpenPerccent;
  55. private bool _isCADIReplenFault;
  56. private bool _isANDIReplenFault;
  57. private double _flowAdjustDelta;
  58. private double _maxFlowDelta;
  59. private bool _isFolwDeltaUnBlance = false;
  60. private bool _isHighLevel;
  61. private bool _isLowLevel;
  62. private bool _isLeakDetected;
  63. private bool _cdaOn;
  64. /// <summary>
  65. /// 是否配置Exhaust
  66. /// </summary>
  67. private bool _isEvaporatorConfig;
  68. /// <summary>
  69. /// 是否正在手动注水
  70. /// </summary>
  71. private bool _isManualReplen;
  72. /// <summary>
  73. /// 手动注水时长(秒)
  74. /// </summary>
  75. private int _manualFillSeconds;
  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. /// 单次注水最大时长
  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. InvokeClient.Instance.Service.DoOperation($"{Module}.CAPumpSpeed",InputCAPumpSpeed);
  266. }
  267. /// <summary>
  268. /// 设置AN pump泵速
  269. /// </summary>
  270. /// <param name="param"></param>
  271. private void ANPumpSpeedSetAction(object param)
  272. {
  273. InvokeClient.Instance.Service.DoOperation($"{Module}.ANPumpSpeed", InputANPumpSpeed);
  274. }
  275. /// <summary>
  276. /// 设置return flow valve开闭的程度
  277. /// </summary>
  278. /// <param name="param"></param>
  279. private void ReturnFlowOpenPercentSetAction(object param)
  280. {
  281. InvokeClient.Instance.Service.DoOperation($"{Module}.ReturnValvePercent", InputRetrunFlowOpenPercent);
  282. }
  283. /// <summary>
  284. /// 重置TotalTime
  285. /// </summary>
  286. private void ResetTotalAction(object param)
  287. {
  288. InvokeClient.Instance.Service.DoOperation($"{Module}.ResetTotalTime");
  289. }
  290. /// <summary>
  291. /// 手动注水
  292. /// </summary>
  293. /// <param name="param"></param>
  294. private void ManualDireplenAction(object param)
  295. {
  296. InvokeClient.Instance.Service.DoOperation($"{Module}.ManualCADiReplen", ManualFillSeconds);
  297. }
  298. #endregion
  299. public void LoadData(string systemName)
  300. {
  301. RecipeType = "res";
  302. Module = systemName;
  303. _rtDataKeys.Clear();
  304. _rtDataKeys.Add($"{Module}.{PERSISTENT_VALUE}");
  305. _rtDataKeys.Add($"{Module}.CurrentRecipe");
  306. _rtDataKeys.Add($"{Module}.FsmState");
  307. _rtDataKeys.Add($"Safety.SafetyData");
  308. _rtDataKeys.Add($"{Module}.ReservoirData");
  309. _rtDataKeys.Add($"{Module}.IsCAHighLevel");
  310. _rtDataKeys.Add($"{Module}.IsCALowLevel");
  311. _rtDataKeys.Add($"{Module}.TemperatureControllerData");
  312. _rtDataKeys.Add($"{Module}.DIValveMaxOnTime");
  313. _rtDataKeys.Add($"{Module}.IsManualCAReplen");
  314. _rtDataKeys.Add($"{Module}.IsDIReplenPerfillTimeOut");
  315. _rtDataKeys.Add($"{Module}.IsDIReplenMaxTimeOut");
  316. if (_timer == null)
  317. {
  318. _timer = new DispatcherTimer();
  319. _timer.Interval = TimeSpan.FromMilliseconds(200);
  320. _timer.Tick += Timer_Tick;
  321. }
  322. _timer.Start();
  323. }
  324. private void Timer_Tick(object sender, EventArgs e)
  325. {
  326. if (_rtDataKeys.Count != 0)
  327. {
  328. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  329. if (_rtDataValueDic != null)
  330. {
  331. State = CommonFunction.GetValue<string>(_rtDataValueDic, $"{Module}.FsmState");
  332. ReservoirData = CommonFunction.GetValue<ReservoirData>(_rtDataValueDic, $"{Module}.ReservoirData");
  333. CommonSafetyData = CommonFunction.GetValue<SafetyData>(_rtDataValueDic, $"Safety.SafetyData");
  334. ReservoirsPersistent = CommonFunction.GetValue<ReservoirsPersistentValue>(_rtDataValueDic, $"{Module}.{PERSISTENT_VALUE}");
  335. if (ReservoirsPersistent!= null && "Manual".Equals(ReservoirsPersistent.OperatingMode))
  336. {
  337. IsEnabled = true;
  338. IsAutoEnabled = true;
  339. }
  340. else if (ReservoirsPersistent != null && "Auto".Equals(ReservoirsPersistent.OperatingMode))
  341. {
  342. IsAutoEnabled = true;
  343. IsEnabled = false;
  344. }
  345. else
  346. {
  347. State = "Stopped";
  348. IsEnabled = false;
  349. IsAutoEnabled = false;
  350. }
  351. CurrentRecipe = CommonFunction.GetValue<ResRecipe>(_rtDataValueDic, $"{Module}.CurrentRecipe");
  352. TemperatureControlData = CommonFunction.GetValue<TemperatureControllerData>(_rtDataValueDic, $"{Module}.TemperatureControllerData");
  353. TCEnableStatus = TemperatureControlData.ControlOperationModel == 0 ? "Disable" : "Enable";
  354. _tcName = TemperatureControlData.Name;
  355. IsCAHighLevel = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsCAHighLevel");
  356. IsCALowLevel = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsCALowLevel");
  357. DIValveMaxOnTime = CommonFunction.GetValue<double>(_rtDataValueDic, $"{Module}.DIValveMaxOnTime");
  358. IsManualReplen = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsManualCAReplen");
  359. IsDIReplenFault = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsDIReplenPerfillTimeOut")
  360. || CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsDIReplenMaxTimeOut");
  361. }
  362. }
  363. }
  364. /// <summary>
  365. /// 隐藏
  366. /// </summary>
  367. public void Hide()
  368. {
  369. if (_timer != null)
  370. {
  371. _timer.Stop();
  372. }
  373. }
  374. }
  375. }