ReservoirsAnolyteViewModel.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Core.RT.Routine;
  3. using Aitex.Core.UI.MVVM;
  4. using CyberX8_Core;
  5. using CyberX8_MainPages.Model;
  6. using CyberX8_Themes.CustomControls;
  7. using MECF.Framework.Common.CommonData.Metal;
  8. using MECF.Framework.Common.CommonData.Reservoir;
  9. using MECF.Framework.Common.DataCenter;
  10. using MECF.Framework.Common.OperationCenter;
  11. using MECF.Framework.Common.Persistent.Reservoirs;
  12. using MECF.Framework.Common.RecipeCenter;
  13. using MECF.Framework.Common.Utilities;
  14. using Prism.Mvvm;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Collections.ObjectModel;
  18. using System.Linq;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. using System.Windows.Input;
  22. using System.Windows.Threading;
  23. namespace CyberX8_MainPages.ViewModels
  24. {
  25. public class ReservoirsAnolyteViewModel : BindableBase
  26. {
  27. #region 常量
  28. private const string RESERVOIRS_DATA = "ReservoirsData";
  29. private const string RESERVOIRS = "reservoirs";
  30. private const string PERSISTENT_VALUE = "PersistentValue";
  31. #endregion
  32. #region 变量
  33. private bool m_IsAutoMode;
  34. private bool m_IsManualMode;
  35. private string _module;
  36. private string _recipeContent;
  37. private string _operatingMode;
  38. private string _state;
  39. private string _recipeMode;
  40. private List<string> _rtDataKeys = new List<string>();
  41. DispatcherTimer _timer;
  42. private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
  43. private ObservableCollection<RecipeNode> _recipeNodes;
  44. private string _currentRecipeFileName;
  45. private string _recipeType;
  46. private bool _aNpumpEnable = false;
  47. private bool _aNADrainpumpEnable = false;
  48. private bool _aNBDrainpumpEnable = false;
  49. private double _maxFlowDelta;
  50. private bool _isHighLevel;
  51. private bool _isLowLevel;
  52. private double _avgANLevel;
  53. private double _inputANBaselineLevel;
  54. private double _flowAdjustDelta;
  55. private bool _isFolwDeltaUnBlance = false;
  56. private double _inputCrossDoseRequest;
  57. private bool _isLeakDetected;
  58. private bool _isDIReplenFault;
  59. private bool _isError;
  60. //用于当作参数传给device判断是否进行leaktest(reservoir是否初始化,阳极是否有flow)
  61. private bool _isInitialized = false;
  62. private bool _isHasANFlow = false;
  63. /// <summary>
  64. /// 是否正在手动注水
  65. /// </summary>
  66. private bool _isManualReplen;
  67. /// <summary>
  68. /// 手动注水时长(秒)
  69. /// </summary>
  70. private int _manualFillSeconds;
  71. /// <summary>
  72. /// DIValveMaxOnTime
  73. /// </summary>
  74. private double _diValveMaxOnTime;
  75. /// CellModuleName集合
  76. /// </summary>
  77. private ObservableCollection<string> _cellModuleNameCollection = new ObservableCollection<string>();
  78. /// <summary>
  79. /// Cell A面Flow集合
  80. /// </summary>
  81. private ObservableCollection<double> _cellModuleNameSideAFlowCollection = new ObservableCollection<double>();
  82. /// <summary>
  83. /// Cell A面Flow状态集合
  84. /// </summary>
  85. private ObservableCollection<string> _cellModuleNameSideAFlowStatusCollection = new ObservableCollection<string>();
  86. /// <summary>
  87. /// Cell B面Flow集合
  88. /// </summary>
  89. private ObservableCollection<double> _cellModuleNameSideBFlowCollection = new ObservableCollection<double>();
  90. /// <summary>
  91. /// Cell B面Flow状态集合
  92. /// </summary>
  93. private ObservableCollection<string> _cellModuleNameSideBFlowStatusCollection = new ObservableCollection<string>();
  94. /// <summary>
  95. /// Persistent
  96. /// </summary>
  97. private ReservoirsPersistentValue _reservoirsPersistent;
  98. /// <summary>
  99. /// Reservoir数据
  100. /// </summary>
  101. private CompactMembranReservoirData _reservoirData;
  102. #region Valve Flag
  103. /// <summary>
  104. /// ANDiReplenValveIsOpen
  105. /// </summary>
  106. private bool _ANDiReplenValveIsOpen;
  107. /// <summary>
  108. /// AN Pump Speed
  109. /// </summary>
  110. private double _anPumpSpped;
  111. /// <summary>
  112. /// MetalData
  113. /// </summary>
  114. private ObservableCollection<CompactMembranMetalDeviceData> _metalDatas = new ObservableCollection<CompactMembranMetalDeviceData>();
  115. /// <summary>
  116. /// MetalData的CellFlow集合
  117. /// </summary>
  118. private ObservableCollection<double> _metalCellFlowDatas = new ObservableCollection<double>();
  119. /// <summary>
  120. /// 页面功能启用
  121. /// </summary>
  122. private bool _isEnabled;
  123. /// <summary>
  124. /// AutoMode页面功能启用
  125. /// </summary>
  126. private bool _isAutoEnabled;
  127. /// <summary>
  128. /// Meatl UI数据
  129. /// </summary>
  130. private ObservableCollection<ReservoirsUIData> _reservoirsUIDatas = new ObservableCollection<ReservoirsUIData>();
  131. #endregion
  132. /// <summary>
  133. /// CrossDose是否Enabled
  134. /// </summary>
  135. private bool _isCrossDoseEnabled;
  136. #region CrossDose
  137. /// <summary>
  138. /// AN Transfer Flow
  139. /// </summary>
  140. private double _anTransferFlow;
  141. /// <summary>
  142. /// Calibrate是否启用
  143. /// </summary>
  144. private bool _isCalibrateEnable;
  145. /// <summary>
  146. /// 是否有CrossDoseType
  147. /// </summary>
  148. private bool _isCroseDoseTypeConfig;
  149. #endregion
  150. #endregion
  151. #region 属性
  152. /// <summary>
  153. /// 是否有CrossDoseType
  154. /// </summary>
  155. public bool IsCrossDoseTypeConfig
  156. {
  157. get { return _isCroseDoseTypeConfig; }
  158. set { SetProperty(ref _isCroseDoseTypeConfig, value); }
  159. }
  160. public double AvgANLevel
  161. {
  162. get { return _avgANLevel; }
  163. set { SetProperty(ref _avgANLevel, value); }
  164. }
  165. public bool IsAutoMode
  166. {
  167. get { return m_IsAutoMode; }
  168. set { SetProperty(ref m_IsAutoMode, value); }
  169. }
  170. public bool IsManualMode
  171. {
  172. get { return m_IsManualMode; }
  173. set { SetProperty(ref m_IsManualMode, value); }
  174. }
  175. public bool IsError
  176. {
  177. get { return _isError; }
  178. set { SetProperty(ref _isError, value); }
  179. }
  180. public bool ANPumpEnable
  181. {
  182. get { return _aNpumpEnable; }
  183. set { SetProperty(ref _aNpumpEnable, value); }
  184. }
  185. public bool ANADrainPumpEnable
  186. {
  187. get { return _aNADrainpumpEnable; }
  188. set { SetProperty(ref _aNADrainpumpEnable, value); }
  189. }
  190. public bool ANBDrainPumpEnable
  191. {
  192. get { return _aNBDrainpumpEnable; }
  193. set { SetProperty(ref _aNBDrainpumpEnable, value); }
  194. }
  195. public string CurrentRecipeFileName
  196. {
  197. get { return _currentRecipeFileName; }
  198. set { SetProperty(ref _currentRecipeFileName, value); }
  199. }
  200. public ObservableCollection<RecipeNode> RecipeNodes
  201. {
  202. get { return _recipeNodes; }
  203. set { SetProperty(ref _recipeNodes, value); }
  204. }
  205. public string Module { get { return _module; } set { SetProperty(ref _module, value); } }
  206. public string ReservoirRecipeContent
  207. {
  208. get { return _recipeContent; }
  209. set { SetProperty(ref _recipeContent, value); }
  210. }
  211. public string OperatingMode
  212. {
  213. get { return _operatingMode; }
  214. set { SetProperty(ref _operatingMode, value); }
  215. }
  216. public string State
  217. {
  218. get { return _state; }
  219. set { SetProperty(ref _state, value); }
  220. }
  221. public string RecipeMode
  222. {
  223. get { return _recipeMode; }
  224. set { SetProperty(ref _recipeMode, value); }
  225. }
  226. public string RecipeType
  227. {
  228. get { return _recipeType; }
  229. set { SetProperty(ref _recipeType, value); }
  230. }
  231. /// <summary>
  232. /// CellModuleName集合
  233. /// </summary>
  234. public ObservableCollection<string> CellModuleNameCollection
  235. {
  236. get { return _cellModuleNameCollection; }
  237. set { SetProperty(ref _cellModuleNameCollection, value); }
  238. }
  239. /// <summary>
  240. /// 模块A面Flow集合
  241. /// </summary>
  242. public ObservableCollection<double> CellModuleNameSideAFlowCollection
  243. {
  244. get { return _cellModuleNameSideAFlowCollection; }
  245. set { SetProperty(ref _cellModuleNameSideAFlowCollection, value); }
  246. }
  247. /// <summary>
  248. /// 模块A面Flow状态集合
  249. /// </summary>
  250. public ObservableCollection<string> CellModuleNameSideAFlowStatusCollection
  251. {
  252. get { return _cellModuleNameSideAFlowStatusCollection; }
  253. set { SetProperty(ref _cellModuleNameSideAFlowStatusCollection, value); }
  254. }
  255. /// <summary>
  256. /// 模块B面Flow集合
  257. /// </summary>
  258. public ObservableCollection<double> CellModuleNameSideBFlowCollection
  259. {
  260. get { return _cellModuleNameSideBFlowCollection; }
  261. set { SetProperty(ref _cellModuleNameSideBFlowCollection, value); }
  262. }
  263. /// <summary>
  264. /// 模块B面Flow状态集合
  265. /// </summary>
  266. public ObservableCollection<string> CellModuleNameSideBFlowStatusCollection
  267. {
  268. get { return _cellModuleNameSideBFlowStatusCollection; }
  269. set { SetProperty(ref _cellModuleNameSideBFlowStatusCollection, value); }
  270. }
  271. /// <summary>
  272. /// Threshold
  273. /// </summary>
  274. public ReservoirsPersistentValue ReservoirsPersistent
  275. {
  276. get { return _reservoirsPersistent; }
  277. set { SetProperty(ref _reservoirsPersistent, value); }
  278. }
  279. /// <summary>
  280. /// Reservoir 数据
  281. /// </summary>
  282. public CompactMembranReservoirData ReservoirData
  283. {
  284. get { return _reservoirData; }
  285. set { SetProperty(ref _reservoirData, value); }
  286. }
  287. public double ANPumpSpeed
  288. {
  289. get { return _anPumpSpped; }
  290. set
  291. {
  292. SetProperty(ref _anPumpSpped, value);
  293. }
  294. }
  295. public bool IsHighLevel
  296. {
  297. get { return _isHighLevel; }
  298. set { SetProperty(ref _isHighLevel, value); }
  299. }
  300. public bool IsLowLevel
  301. {
  302. get { return _isLowLevel; }
  303. set { SetProperty(ref _isLowLevel, value); }
  304. }
  305. #region Valve Flag
  306. public bool ANDiReplenValveIsOpen
  307. {
  308. get { return _ANDiReplenValveIsOpen; }
  309. set { SetProperty(ref _ANDiReplenValveIsOpen, value); }
  310. }
  311. #endregion
  312. /// <summary>
  313. /// MetalData
  314. /// </summary>
  315. public ObservableCollection<CompactMembranMetalDeviceData> MetalDatas
  316. {
  317. get { return _metalDatas; }
  318. set { SetProperty(ref _metalDatas, value); }
  319. }
  320. /// <summary>
  321. /// MetalDataCellFlow
  322. /// </summary>
  323. public ObservableCollection<double> MetalCellFlowDatas
  324. {
  325. get { return _metalCellFlowDatas; }
  326. set { SetProperty(ref _metalCellFlowDatas, value); }
  327. }
  328. /// <summary>
  329. /// 正在手动注水
  330. /// </summary>
  331. public bool IsManualReplen
  332. {
  333. get { return _isManualReplen; }
  334. set { SetProperty(ref _isManualReplen, value); }
  335. }
  336. /// <summary>
  337. /// 手动注水时长
  338. /// </summary>
  339. public int ManualFillSeconds
  340. {
  341. get { return _manualFillSeconds; }
  342. set { SetProperty(ref _manualFillSeconds, value); }
  343. }
  344. /// <summary>
  345. /// 单次注水最大时长
  346. /// </summary>
  347. public double DIValveMaxOnTime
  348. {
  349. get { return _diValveMaxOnTime; }
  350. set { SetProperty(ref _diValveMaxOnTime, value); }
  351. }
  352. /// <summary>
  353. /// Input Fast Leak test Baseline
  354. /// </summary>
  355. public double InputANBaselineLevel
  356. {
  357. get { return _inputANBaselineLevel; }
  358. set { SetProperty(ref _inputANBaselineLevel, value); }
  359. }
  360. /// <summary>
  361. /// 不同cell流量差值
  362. /// </summary>
  363. public double FlowAdjustDelta
  364. {
  365. get { return _flowAdjustDelta; }
  366. set { SetProperty(ref _flowAdjustDelta, value); }
  367. }
  368. /// <summary>
  369. /// 流量误差是否超过0.5
  370. /// </summary>
  371. public bool IsFolwDeltaUnBlance
  372. {
  373. get { return _isFolwDeltaUnBlance; }
  374. set { SetProperty(ref _isFolwDeltaUnBlance, value); }
  375. }
  376. /// <summary>
  377. /// Input Cross Dose Request
  378. /// </summary>
  379. public double InputCrossDoseRequest
  380. {
  381. get { return _inputCrossDoseRequest; }
  382. set { SetProperty(ref _inputCrossDoseRequest, value); }
  383. }
  384. /// <summary>
  385. /// 是否检测到泄露
  386. /// </summary>
  387. public bool IsLeakDetected
  388. {
  389. get { return _isLeakDetected; }
  390. set { SetProperty(ref _isLeakDetected, value); }
  391. }
  392. /// <summary>
  393. /// 是否补水异常
  394. /// </summary>
  395. public bool IsDIReplenFault
  396. {
  397. get { return _isDIReplenFault; }
  398. set { SetProperty(ref _isDIReplenFault, value); }
  399. }
  400. /// <summary>
  401. /// 页面功能启用
  402. /// </summary>
  403. public bool IsEnabled
  404. {
  405. get { return _isEnabled; }
  406. set { SetProperty(ref _isEnabled, value); }
  407. }
  408. /// <summary>
  409. /// AutoMode页面功能启用
  410. /// </summary>
  411. public bool IsAutoEnabled
  412. {
  413. get { return _isAutoEnabled; }
  414. set { SetProperty(ref _isAutoEnabled, value); }
  415. }
  416. /// <summary>
  417. /// metal ui数据
  418. /// </summary>
  419. public ObservableCollection<ReservoirsUIData> ReservoirsUIDatas
  420. {
  421. get { return _reservoirsUIDatas; }
  422. set { SetProperty(ref _reservoirsUIDatas, value); }
  423. }
  424. /// <summary>
  425. /// CrossDose是否Enabled
  426. /// </summary>
  427. public bool IsCrossDoseEnabled
  428. {
  429. get { return _isCrossDoseEnabled; }
  430. set { SetProperty(ref _isCrossDoseEnabled, value); }
  431. }
  432. #region CrossDose
  433. /// <summary>
  434. /// AN Transfer Flow
  435. /// </summary>
  436. public double ANTransferFlow
  437. {
  438. get { return _anTransferFlow; }
  439. set { SetProperty(ref _anTransferFlow, value); }
  440. }
  441. /// <summary>
  442. /// Calibrate是否启用
  443. /// </summary>
  444. public bool IsCalibrateEnable
  445. {
  446. get { return _isCalibrateEnable; }
  447. set { SetProperty(ref _isCalibrateEnable, value); }
  448. }
  449. #endregion
  450. #endregion
  451. #region 命令
  452. public ICommand ControlValveCommand { get; private set; }
  453. public ICommand AnPumpSpeedCommand { get; private set; }
  454. public ICommand ManualDireplenCommand { get; set; }
  455. public ICommand ResetTotalCommand { get; set; }
  456. public ICommand ClearSlowLeakCommand { get; set; }
  457. public ICommand NavigatetoPumpCartCommand { get; set; }
  458. public ICommand CrossDoseStartCommand { get; set; }
  459. public ICommand CrossDoseHaltCommand { get; set; }
  460. public ICommand CalibrateCommand { get; set; }
  461. public ICommand BaseLineKeyDownCommand { get; set; }
  462. public ICommand StartLeakTestCommand { get; set; }
  463. public ICommand BackCommand { get; set; }
  464. #endregion
  465. #region 构造函数
  466. /// <summary>
  467. /// 构造函数
  468. /// </summary>
  469. public ReservoirsAnolyteViewModel()
  470. {
  471. IsAutoMode = false;
  472. ControlValveCommand = new DelegateCommand<object>(OnControlValve);
  473. AnPumpSpeedCommand = new DelegateCommand<object>(AnPumpSpeedAction);
  474. ManualDireplenCommand = new DelegateCommand<object>(ManualDireplenAction);
  475. ResetTotalCommand = new DelegateCommand<object>(ResetTotalAction);
  476. ClearSlowLeakCommand = new DelegateCommand<object>(ClearSlowLeakAction);
  477. NavigatetoPumpCartCommand = new DelegateCommand<object>(NavigatetoPumpCartAction);
  478. BaseLineKeyDownCommand = new DelegateCommand<object[]>(BaseLineKeyDownAction);
  479. StartLeakTestCommand = new DelegateCommand<object[]>(StartLeakTestAction);
  480. BackCommand = new DelegateCommand<object>(BackAction);
  481. }
  482. #endregion
  483. #region 命令方法
  484. /// <summary>
  485. /// 回到Reservoir主页面
  486. /// </summary>
  487. /// <param name="param"></param>
  488. private void BackAction(object param)
  489. {
  490. GlobalEvents.OnSwitchFixedChildSubItem(Module, Module);
  491. }
  492. /// <summary>
  493. /// Control Valve
  494. /// </summary>
  495. /// <param name="obj"></param>
  496. private void OnControlValve(object obj)
  497. {
  498. CommonValveControl commonValveControl = (CommonValveControl)obj;
  499. if (commonValveControl.IsCanEdit == true)
  500. {
  501. string cmd = commonValveControl.OperationName;
  502. if (!commonValveControl.Status)
  503. {
  504. commonValveControl.Status = !commonValveControl.Status;
  505. InvokeClient.Instance.Service.DoOperation($"{cmd}On");
  506. }
  507. else
  508. {
  509. commonValveControl.Status = !commonValveControl.Status;
  510. InvokeClient.Instance.Service.DoOperation($"{cmd}Off");
  511. }
  512. }
  513. }
  514. /// <summary>
  515. /// AN Pump调速
  516. /// </summary>
  517. /// <param name="obj"></param>
  518. private void AnPumpSpeedAction(object obj)
  519. {
  520. object[] objects = (object[])obj;
  521. if (objects.Length >= 2)
  522. {
  523. InvokeClient.Instance.Service.DoOperation($"{Module}.ANPumpSpeed", objects[1]);
  524. }
  525. }
  526. /// <summary>
  527. /// 手动注水
  528. /// </summary>
  529. /// <param name="param"></param>
  530. private void ManualDireplenAction(object param)
  531. {
  532. InvokeClient.Instance.Service.DoOperation($"{Module}.ManualANDiReplen", ManualFillSeconds);
  533. }
  534. /// <summary>
  535. /// 重置TotalTime
  536. /// </summary>
  537. private void ResetTotalAction(object param)
  538. {
  539. InvokeClient.Instance.Service.DoOperation($"{Module}.ResetTotalTime");
  540. }
  541. /// <summary>
  542. /// clear slow leak
  543. /// </summary>
  544. private void ClearSlowLeakAction(object param)
  545. {
  546. InvokeClient.Instance.Service.DoOperation($"{Module}.ClearSlowLeak");
  547. }
  548. private void NavigatetoPumpCartAction(object param)
  549. {
  550. }
  551. private void BaseLineKeyDownAction(object[] param)
  552. {
  553. if (param.Length >= 2)
  554. {
  555. if (double.TryParse(param[1].ToString(), out double result))
  556. {
  557. InvokeClient.Instance.Service.DoOperation($"{Module}.BaseLineKeyDown", param[0].ToString(), result);
  558. }
  559. }
  560. }
  561. private void StartLeakTestAction(object[] param)
  562. {
  563. InvokeClient.Instance.Service.DoOperation($"{Module}.StartLeakTest",_isInitialized, _isHasANFlow);
  564. }
  565. #endregion
  566. /// <summary>
  567. /// 进入UI加载数据
  568. /// </summary>
  569. /// <param name="systemName"></param>
  570. public void LoadData(string systemName)
  571. {
  572. RecipeType = "res";
  573. Module = systemName;
  574. _isHasANFlow = false;
  575. _rtDataKeys.Clear();
  576. CellModuleNameSideAFlowCollection.Clear();
  577. CellModuleNameSideBFlowCollection.Clear();
  578. CellModuleNameSideAFlowStatusCollection.Clear();
  579. CellModuleNameSideBFlowStatusCollection.Clear();
  580. MetalDatas.Clear();
  581. MetalCellFlowDatas.Clear();
  582. ReservoirsUIDatas.Clear();
  583. _rtDataKeys.Add($"{Module}.Metals");
  584. Dictionary<string, object> tmpMetals = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  585. if (tmpMetals != null)
  586. {
  587. List<string> strMetals = CommonFunction.GetValue<List<string>>(tmpMetals, $"{Module}.Metals");
  588. int cellsCount = strMetals.Count;
  589. if (strMetals != null)
  590. {
  591. CellModuleNameCollection.Clear();
  592. for (int i = 0; i < cellsCount; i++)
  593. {
  594. CellModuleNameCollection.Add(strMetals[i]);
  595. CellModuleNameSideAFlowCollection.Add(0);
  596. CellModuleNameSideBFlowCollection.Add(0);
  597. CellModuleNameSideAFlowStatusCollection.Add("");
  598. CellModuleNameSideBFlowStatusCollection.Add("");
  599. MetalDatas.Add(null);
  600. MetalCellFlowDatas.Add(0);
  601. ReservoirsUIData reservoirsUIData = new ReservoirsUIData();
  602. reservoirsUIData.Name = strMetals[i];
  603. ReservoirsUIDatas.Add(reservoirsUIData);
  604. }
  605. }
  606. }
  607. _rtDataKeys.Clear();
  608. for (int i = 0; i < CellModuleNameCollection.Count; i++)
  609. {
  610. _rtDataKeys.Add($"{CellModuleNameCollection[i]}.SideAFlow");
  611. _rtDataKeys.Add($"{CellModuleNameCollection[i]}.SideAFlowStatus");
  612. _rtDataKeys.Add($"{CellModuleNameCollection[i]}.SideBFlow");
  613. _rtDataKeys.Add($"{CellModuleNameCollection[i]}.SideBFlowStatus");
  614. _rtDataKeys.Add($"{CellModuleNameCollection[i]}.MetalData");
  615. }
  616. _rtDataKeys.Add($"{Module}.{PERSISTENT_VALUE}");
  617. _rtDataKeys.Add($"{Module}.ReservoirData");
  618. _rtDataKeys.Add($"{Module}.ANPumpSpeed");
  619. _rtDataKeys.Add($"{Module}.IsManualANReplen");
  620. _rtDataKeys.Add($"{Module}.DIValveMaxOnTime");
  621. _rtDataKeys.Add($"{Module}.IsANHighLevel");
  622. _rtDataKeys.Add($"{Module}.IsANLowLevel");
  623. _rtDataKeys.Add($"{Module}.IsLeakDetected");
  624. _rtDataKeys.Add($"{Module}.FsmState");
  625. _rtDataKeys.Add($"{Module}.IsCrossDoseInstalled");
  626. _rtDataKeys.Add($"{Module}.ANTransferFlow");
  627. _rtDataKeys.Add($"{Module}.ANBypassCounterFlow");
  628. _rtDataKeys.Add($"{Module}.IsCalibrateEnable");
  629. _rtDataKeys.Add($"{Module}.ReservoirAverageANLevel");
  630. _rtDataKeys.Add($"{Module}.CroseDoseType");
  631. if (_timer == null)
  632. {
  633. _timer = new DispatcherTimer();
  634. _timer.Interval = TimeSpan.FromMilliseconds(200);
  635. _timer.Tick += Timer_Tick;
  636. }
  637. _timer.Start();
  638. }
  639. /// <summary>
  640. /// 定时器执行
  641. /// </summary>
  642. /// <param name="sender"></param>
  643. /// <param name="e"></param>
  644. private void Timer_Tick(object sender, EventArgs e)
  645. {
  646. if (_rtDataKeys.Count != 0)
  647. {
  648. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  649. if (_rtDataValueDic != null)
  650. {
  651. ReservoirData = CommonFunction.GetValue<CompactMembranReservoirData>(_rtDataValueDic, $"{Module}.ReservoirData");
  652. if(ReservoirData.ANBypassFlow == 0)
  653. {
  654. ReservoirData.ANBypassFlow = CommonFunction.GetValue<double>(_rtDataValueDic, $"{Module}.ANBypassCounterFlow");
  655. }
  656. AvgANLevel = CommonFunction.GetValue<double>(_rtDataValueDic, $"{Module}.ReservoirAverageANLevel");
  657. IsCrossDoseEnabled = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsCrossDoseInstalled");
  658. IsCrossDoseTypeConfig = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.CroseDoseType");
  659. IsCalibrateEnable = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsCalibrateEnable");
  660. State = CommonFunction.GetValue<string>(_rtDataValueDic, $"{Module}.FsmState");
  661. if ("Idle".Equals(State))
  662. {
  663. _isInitialized = true;
  664. }
  665. IsError = "Error".Equals(State) ? true : false;
  666. if (ReservoirData != null)
  667. {
  668. //ANPump状态
  669. ANPumpEnable = ReservoirData.ANPump > 0 ? true : false;
  670. //ANADrainPump状态
  671. ANADrainPumpEnable = ReservoirData.ANADrainPump > 0 ? true : false;
  672. //ANBDrainPump状态
  673. ANBDrainPumpEnable = ReservoirData.ANBDrainPump > 0 ? true : false;
  674. }
  675. IsManualReplen = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsManualANReplen");
  676. DIValveMaxOnTime = CommonFunction.GetValue<double>(_rtDataValueDic, $"{Module}.DIValveMaxOnTime");
  677. ANPumpSpeed = CommonFunction.GetValue<double>(_rtDataValueDic, $"{Module}.ANPumpSpeed");
  678. ReservoirsPersistent = CommonFunction.GetValue<ReservoirsPersistentValue>(_rtDataValueDic, $"{Module}.{PERSISTENT_VALUE}");
  679. InputANBaselineLevel = ReservoirsPersistent.ANBaseLineLevel;
  680. IsManualMode = "Manual".Equals(ReservoirsPersistent.OperatingMode) ? true : false;
  681. for (int i = 0; i < CellModuleNameCollection.Count; i++)
  682. {
  683. CellModuleNameSideAFlowCollection[i] = CommonFunction.GetValue<double>(_rtDataValueDic, $"{CellModuleNameCollection[i]}.SideAFlow");
  684. CellModuleNameSideAFlowStatusCollection[i] = CommonFunction.GetValue<string>(_rtDataValueDic, $"{CellModuleNameCollection[i]}.SideAFlowStatus");
  685. CellModuleNameSideBFlowCollection[i] = CommonFunction.GetValue<double>(_rtDataValueDic, $"{CellModuleNameCollection[i]}.SideBFlow");
  686. CellModuleNameSideBFlowStatusCollection[i] = CommonFunction.GetValue<string>(_rtDataValueDic, $"{CellModuleNameCollection[i]}.SideBFlowStatus");
  687. MetalDatas[i] = CommonFunction.GetValue<CompactMembranMetalDeviceData>(_rtDataValueDic, $"{CellModuleNameCollection[i]}.MetalData");
  688. MetalCellFlowDatas[i] = MetalDatas[i].CellFlow;
  689. if (CellModuleNameSideAFlowCollection[i] > 0 || CellModuleNameSideBFlowCollection[i] > 0)
  690. {
  691. _isHasANFlow = true;
  692. }
  693. ReservoirsUIDatas[i].IsEnable = IsEnabled;
  694. ReservoirsUIDatas[i].ANPumpEnable = ANPumpEnable;
  695. ReservoirsUIDatas[i].MetalSideAFlow = CellModuleNameSideAFlowCollection[i];
  696. ReservoirsUIDatas[i].MetalSideBFlow = CellModuleNameSideBFlowCollection[i];
  697. ReservoirsUIDatas[i].MetalSideAStatus = CellModuleNameSideAFlowStatusCollection[i];
  698. ReservoirsUIDatas[i].MetalSideBStatus = CellModuleNameSideBFlowStatusCollection[i];
  699. ReservoirsUIDatas[i].MetalDatas = MetalDatas[i];
  700. if ("Full".Equals(CellModuleNameSideAFlowStatusCollection[i]) && MetalDatas[i].ANAPinEnable)
  701. {
  702. ReservoirsUIDatas[i].IsSideAFull = true;
  703. }
  704. else
  705. {
  706. ReservoirsUIDatas[i].IsSideAFull = false;
  707. }
  708. if ("Full".Equals(CellModuleNameSideBFlowStatusCollection[i]) && MetalDatas[i].ANBPinEnable)
  709. {
  710. ReservoirsUIDatas[i].IsSideBFull = true;
  711. }
  712. else
  713. {
  714. ReservoirsUIDatas[i].IsSideBFull = false;
  715. }
  716. ReservoirsUIDatas[i].IsManualOperationMode = IsManualMode;
  717. }
  718. //list记录参与循环的metal的A/B面的流量情况
  719. List<double> list = new List<double>();
  720. for (int i = 0; i < CellModuleNameSideAFlowCollection.Count; i++)
  721. {
  722. if (MetalDatas[i].ANAPinEnable)
  723. {
  724. list.Add(CellModuleNameSideAFlowCollection[i]);
  725. }
  726. }
  727. for (int i = 0; i < CellModuleNameSideBFlowCollection.Count; i++)
  728. {
  729. if (MetalDatas[i].ANBPinEnable)
  730. {
  731. list.Add(CellModuleNameSideBFlowCollection[i]);
  732. }
  733. }
  734. //如果参与循环的流量全是0或者没有参与循环的metal,直接跳过流量差相关判断逻辑
  735. if (list.All(num => num == 0) || list.Count == 0)
  736. {
  737. for (int i = 0; i < CellModuleNameCollection.Count; i++)
  738. {
  739. ReservoirsUIDatas[i].IsMetalCellSideAHigh = false;
  740. ReservoirsUIDatas[i].IsMetalCellSideALow = false;
  741. ReservoirsUIDatas[i].IsMetalCellSideBHigh = false;
  742. ReservoirsUIDatas[i].IsMetalCellSideBLow = false;
  743. }
  744. }
  745. else
  746. {
  747. FlowAdjustDelta = list.Max() - list.Min();
  748. IsFolwDeltaUnBlance = FlowAdjustDelta > 0.3 ? true : false;
  749. if (IsFolwDeltaUnBlance)
  750. {
  751. for (int i = 0; i < CellModuleNameSideAFlowCollection.Count; i++)
  752. {
  753. if (ReservoirsUIDatas[i].MetalSideAFlow == list.Max() && MetalDatas[i].ANAPinEnable)
  754. {
  755. ReservoirsUIDatas[i].IsMetalCellSideAHigh = true;
  756. }
  757. else
  758. {
  759. ReservoirsUIDatas[i].IsMetalCellSideAHigh = false;
  760. }
  761. if (ReservoirsUIDatas[i].MetalSideAFlow == list.Min() && MetalDatas[i].ANAPinEnable)
  762. {
  763. ReservoirsUIDatas[i].IsMetalCellSideALow = true;
  764. }
  765. else
  766. {
  767. ReservoirsUIDatas[i].IsMetalCellSideALow = false;
  768. }
  769. }
  770. for (int i = 0; i < CellModuleNameSideBFlowCollection.Count; i++)
  771. {
  772. if (ReservoirsUIDatas[i].MetalSideBFlow == list.Max() && MetalDatas[i].ANBPinEnable)
  773. {
  774. ReservoirsUIDatas[i].IsMetalCellSideBHigh = true;
  775. }
  776. else
  777. {
  778. ReservoirsUIDatas[i].IsMetalCellSideBHigh = false;
  779. }
  780. if (ReservoirsUIDatas[i].MetalSideBFlow == list.Min() && MetalDatas[i].ANBPinEnable)
  781. {
  782. ReservoirsUIDatas[i].IsMetalCellSideBLow = true;
  783. }
  784. else
  785. {
  786. ReservoirsUIDatas[i].IsMetalCellSideBLow = false;
  787. }
  788. }
  789. }
  790. else
  791. {
  792. for (int i = 0; i < CellModuleNameCollection.Count; i++)
  793. {
  794. ReservoirsUIDatas[i].IsMetalCellSideAHigh = false;
  795. ReservoirsUIDatas[i].IsMetalCellSideALow = false;
  796. ReservoirsUIDatas[i].IsMetalCellSideBHigh = false;
  797. ReservoirsUIDatas[i].IsMetalCellSideBLow = false;
  798. }
  799. }
  800. }
  801. list.Clear();
  802. IsHighLevel = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsANHighLevel");
  803. IsLowLevel = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsANLowLevel");
  804. IsLeakDetected = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{Module}.IsLeakDetected");
  805. if ("Manual".Equals(ReservoirsPersistent.OperatingMode))
  806. {
  807. IsEnabled = true;
  808. IsAutoEnabled = true;
  809. IsAutoMode = false;
  810. }
  811. else if ("Auto".Equals(ReservoirsPersistent.OperatingMode))
  812. {
  813. IsAutoEnabled = true;
  814. IsEnabled = false;
  815. IsAutoMode = true;
  816. }
  817. else
  818. {
  819. State = "Stopped";
  820. IsEnabled = false;
  821. IsAutoEnabled = false;
  822. IsAutoMode = false;
  823. }
  824. //CrossDose
  825. ANTransferFlow = CommonFunction.GetValue<double>(_rtDataValueDic, $"{Module}.ANTransferFlow");
  826. }
  827. }
  828. }
  829. }
  830. }