DMReservoirViewModel.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. /// CellModuleName集合
  82. /// </summary>
  83. private ObservableCollection<string> _cellModuleNameCollection = new ObservableCollection<string>();
  84. /// <summary>
  85. /// Cell A面Flow集合
  86. /// </summary>
  87. private ObservableCollection<double> _cellModuleNameFlowCollection = new ObservableCollection<double>();
  88. /// <summary>
  89. /// MetalData
  90. /// </summary>
  91. private ObservableCollection<CompactMembranMetalDeviceData> _metalDatas = new ObservableCollection<CompactMembranMetalDeviceData>();
  92. /// <summary>
  93. /// MetalData的CellFlow集合
  94. /// </summary>
  95. private ObservableCollection<double> _metalCellFlowDatas = new ObservableCollection<double>();
  96. /// <summary>
  97. /// Meatl UI数据
  98. /// </summary>
  99. private ObservableCollection<ReservoirsUIData> _reservoirsUIDatas = new ObservableCollection<ReservoirsUIData>();
  100. #endregion
  101. #region 属性
  102. public string Module
  103. {
  104. get { return _module; }
  105. set { SetProperty(ref _module, value); }
  106. }
  107. public bool IsEnabled
  108. {
  109. get { return _isEnabled; }
  110. set { SetProperty(ref _isEnabled, value); }
  111. }
  112. public bool IsError
  113. {
  114. get { return _isError; }
  115. set { SetProperty(ref _isError, value); }
  116. }
  117. public bool IsAutoEnabled
  118. {
  119. get { return _isAutoEnabled; }
  120. set { SetProperty(ref _isAutoEnabled, value); }
  121. }
  122. public SafetyData CommonSafetyData
  123. {
  124. get { return _commonSafetyData; }
  125. set { SetProperty(ref _commonSafetyData, value); }
  126. }
  127. public string State
  128. {
  129. get { return _state; }
  130. set { SetProperty(ref _state, value); }
  131. }
  132. public ResRecipe CurrentRecipe
  133. {
  134. get { return _currentRecipe; }
  135. set { SetProperty(ref _currentRecipe, value); }
  136. }
  137. public ReservoirsPersistentValue ReservoirsPersistent
  138. {
  139. get { return _reservoirsPersistent; }
  140. set { SetProperty(ref _reservoirsPersistent, value); }
  141. }
  142. public string RecipeType
  143. {
  144. get { return _recipeType; }
  145. set { SetProperty(ref _recipeType, value); }
  146. }
  147. public int InputCAPumpSpeed
  148. {
  149. get { return _inputCAPumpSpeed; }
  150. set
  151. {
  152. SetProperty(ref _inputCAPumpSpeed, value);
  153. }
  154. }
  155. public int InputANPumpSpeed
  156. {
  157. get { return _inputANPumpSpeed; }
  158. set
  159. {
  160. SetProperty(ref _inputANPumpSpeed, value);
  161. }
  162. }
  163. public int InputRetrunFlowOpenPercent
  164. {
  165. get { return _inputReturnFlowOpenPercent; }
  166. set
  167. {
  168. SetProperty(ref _inputReturnFlowOpenPercent, value);
  169. }
  170. }
  171. public TemperatureControllerData TemperatureControlData
  172. {
  173. get { return _temperatureControlData; }
  174. set { SetProperty(ref _temperatureControlData, value); }
  175. }
  176. public string TCEnableStatus
  177. {
  178. get { return _tcEnableStatus; }
  179. set { SetProperty(ref _tcEnableStatus, value); }
  180. }
  181. public ReservoirData ReservoirData
  182. {
  183. get { return _reservoirData; }
  184. set { SetProperty(ref _reservoirData, value); }
  185. }
  186. public bool IsCAHighLevel
  187. {
  188. get { return _isCAHighLevel; }
  189. set { SetProperty(ref _isCAHighLevel, value); }
  190. }
  191. public bool IsCALowLevel
  192. {
  193. get { return _isCALowLevel; }
  194. set { SetProperty(ref _isCALowLevel, value); }
  195. }
  196. #endregion
  197. #region 指令
  198. public ICommand InitializeCommand { get; set; }
  199. public ICommand CAPumpSpeedSetCommand { get; set; }
  200. public ICommand ANPumpSpeedSetCommand { get; set; }
  201. public ICommand ReturnFlowOpenPercentSetCommand { get; set; }
  202. #endregion
  203. public DMReservoirViewModel()
  204. {
  205. InitializeCommand = new DelegateCommand<object>(InitializeAction);
  206. CAPumpSpeedSetCommand = new DelegateCommand<object>(CAPumpSpeedSetAction);
  207. ANPumpSpeedSetCommand = new DelegateCommand<object>(ANPumpSpeedSetAction);
  208. ReturnFlowOpenPercentSetCommand = new DelegateCommand<object>(ReturnFlowOpenPercentSetAction);
  209. }
  210. #region 命令方法
  211. /// <summary>
  212. /// 初始化
  213. /// </summary>
  214. /// <param name="param"></param>
  215. private void InitializeAction(object param)
  216. {
  217. InvokeClient.Instance.Service.DoOperation($"{Module}.InitializeAll");
  218. }
  219. /// <summary>
  220. /// 设置CA pump泵速
  221. /// </summary>
  222. /// <param name="param"></param>
  223. private void CAPumpSpeedSetAction(object param)
  224. {
  225. InvokeClient.Instance.Service.DoOperation($"{Module}.CAPumpSpeed",InputCAPumpSpeed);
  226. }
  227. /// <summary>
  228. /// 设置AN pump泵速
  229. /// </summary>
  230. /// <param name="param"></param>
  231. private void ANPumpSpeedSetAction(object param)
  232. {
  233. InvokeClient.Instance.Service.DoOperation($"{Module}.ANPumpSpeed", InputANPumpSpeed);
  234. }
  235. /// <summary>
  236. /// 设置return flow valve开闭的程度
  237. /// </summary>
  238. /// <param name="param"></param>
  239. private void ReturnFlowOpenPercentSetAction(object param)
  240. {
  241. InvokeClient.Instance.Service.DoOperation($"{Module}.ReturnValvePercent", InputRetrunFlowOpenPercent);
  242. }
  243. #endregion
  244. public void LoadData(string systemName)
  245. {
  246. RecipeType = "res";
  247. Module = systemName;
  248. _rtDataKeys.Clear();
  249. _rtDataKeys.Add($"{Module}.{PERSISTENT_VALUE}");
  250. _rtDataKeys.Add($"{Module}.CurrentRecipe");
  251. _rtDataKeys.Add($"{Module}.FsmState");
  252. _rtDataKeys.Add($"Safety.SafetyData");
  253. _rtDataKeys.Add($"{Module}.ReservoirData");
  254. _rtDataKeys.Add($"{Module}.IsCAHighLevel");
  255. _rtDataKeys.Add($"{Module}.IsCALowLevel");
  256. _rtDataKeys.Add($"{Module}.TemperatureControllerData");
  257. if (_timer == null)
  258. {
  259. _timer = new DispatcherTimer();
  260. _timer.Interval = TimeSpan.FromMilliseconds(200);
  261. _timer.Tick += Timer_Tick;
  262. }
  263. _timer.Start();
  264. }
  265. private void Timer_Tick(object sender, EventArgs e)
  266. {
  267. if (_rtDataKeys.Count != 0)
  268. {
  269. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  270. if (_rtDataValueDic != null)
  271. {
  272. State = CommonFunction.GetValue<string>(_rtDataValueDic, $"{Module}.FsmState");
  273. ReservoirData = CommonFunction.GetValue<ReservoirData>(_rtDataValueDic, $"{Module}.ReservoirData");
  274. CommonSafetyData = CommonFunction.GetValue<SafetyData>(_rtDataValueDic, $"Safety.SafetyData");
  275. ReservoirsPersistent = CommonFunction.GetValue<ReservoirsPersistentValue>(_rtDataValueDic, $"{Module}.{PERSISTENT_VALUE}");
  276. if (ReservoirsPersistent!= null && "Manual".Equals(ReservoirsPersistent.OperatingMode))
  277. {
  278. IsEnabled = true;
  279. IsAutoEnabled = true;
  280. }
  281. else if (ReservoirsPersistent != null && "Auto".Equals(ReservoirsPersistent.OperatingMode))
  282. {
  283. IsAutoEnabled = true;
  284. IsEnabled = false;
  285. }
  286. else
  287. {
  288. State = "Stopped";
  289. IsEnabled = false;
  290. IsAutoEnabled = false;
  291. }
  292. CurrentRecipe = CommonFunction.GetValue<ResRecipe>(_rtDataValueDic, $"{Module}.CurrentRecipe");
  293. TemperatureControlData = CommonFunction.GetValue<TemperatureControllerData>(_rtDataValueDic, $"{Module}.TemperatureControllerData");
  294. TCEnableStatus = TemperatureControlData.ControlOperationModel == 0 ? "Disable" : "Enable";
  295. _tcName = TemperatureControlData.Name;
  296. IsCAHighLevel = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsCAHighLevel");
  297. IsCALowLevel = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsCALowLevel");
  298. }
  299. }
  300. }
  301. /// <summary>
  302. /// 隐藏
  303. /// </summary>
  304. public void Hide()
  305. {
  306. if (_timer != null)
  307. {
  308. _timer.Stop();
  309. }
  310. }
  311. }
  312. }