DMReservoirViewModel.cs 11 KB

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