EdwardsPump.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Xml;
  8. using Aitex.Core.Common.DeviceData;
  9. using Aitex.Core.RT.DataCenter;
  10. using Aitex.Core.RT.Device;
  11. using Aitex.Core.RT.Event;
  12. using Aitex.Core.RT.IOCore;
  13. using Aitex.Core.RT.Log;
  14. using Aitex.Core.RT.OperationCenter;
  15. using Aitex.Core.RT.SCCore;
  16. using Aitex.Core.RT.Tolerance;
  17. using Aitex.Core.Util;
  18. using MECF.Framework.Common.Communications;
  19. using MECF.Framework.Common.DataCenter;
  20. using MECF.Framework.Common.Device.Bases;
  21. using MECF.Framework.Common.Equipment;
  22. using Venus_Core;
  23. namespace Venus_RT.Devices
  24. {
  25. static class EdwardsPumpErrorInformation
  26. {
  27. public static Dictionary<int, string> EdwardsPumpParameters = new Dictionary<int, string>()
  28. {
  29. { 1,"System Node status"},
  30. { 3,"Pump Current"},
  31. { 4,"Pump Power"},
  32. { 7,"Booster Current"},
  33. { 8,"Booster Power"},
  34. { 11,"Dry Pump Control"},
  35. { 12,"Booster Control"},
  36. { 14,"Pump Run hours"},
  37. { 16,"Pcocess hours"},
  38. { 21,"Time to Stop"},
  39. { 34,"N2 flow state"},
  40. { 35,"N2 flow rate"},
  41. { 39,"Exhaust pressure"},
  42. { 46,"Gas ballast"},
  43. { 47,"Inlet/cleaning purge (valve 2)"},
  44. { 48,"Zero Sensors Countdown"},
  45. { 50,"System Run Hours"},
  46. { 52,"Analogue water flow rate"},
  47. { 53,"Active gauge voltage input"},
  48. { 54,"MB Stator temperature"},
  49. { 55,"TCS Reference Temperature"},
  50. { 56,"Exhaust temperature"},
  51. { 57,"DP end cover temperature"},
  52. { 60,"Discrete water flow OK switch"},
  53. { 62,"MB end cover temperature"},
  54. { 68,"On/Off Process"},
  55. { 70,"DP stator temperature 2"},
  56. { 72,"Pump speed demand"},
  57. { 84,"Exhaust pipe temperature"},
  58. { 85,"Accessories Module Cold Junction Temperature"},
  59. { 89,"Purge Gas Heater control"},
  60. { 116,"Pump Power (iXL120 only)"},
  61. { 152,"Gate Valve ls Closed"},
  62. { 153,"Gate Valve ls Open"},
  63. { 161,"Gate Valve Control"},
  64. { 170,"Booster inverter powered elapsed days"},
  65. { 173,"Booster inverter heatsink temperature"},
  66. { 174,"Booster Actual Speed"},
  67. { 175,"Booster Actual Speed Percent"},
  68. { 177,"Booster Speed Reference"},
  69. { 178,"Booster Off Process Speed Reference"},
  70. { 180,"Pump Inverter powered elapsed days"},
  71. { 183,"Pump inverter heatsink temperature"},
  72. { 184,"Pump Actual Speed Hz"},
  73. { 185,"Pump Actual Speed Percent"},
  74. { 187,"Pump Speed Reference"},
  75. { 188,"Pump Off Process Speed Reference"},
  76. { 211,"Gas -Inlet 1"},
  77. { 212,"Gas - 3rd 8 4th"},
  78. { 213,"Gas -4th or 5th"},
  79. { 214,"Gas -LV"},
  80. { 215,"Gas -Bypass"},
  81. { 216,"Gas -Exhaust 1"},
  82. { 217,"Gas - Exhaust 2"},
  83. { 219,"Gas - Seals"},
  84. { 222,"Both Pumps Start"},
  85. { 224,"Dry Pump Start"},
  86. { 226,"Run Til Crash"},
  87. { 227,"Auto/Fast Shutdown"},
  88. { 228,"Open Gate Valve"},
  89. { 230,"Process ON/AUC"},
  90. { 231,"Remote/Local Control (Relay)"},
  91. { 233,"Booster Running (Relay)"},
  92. { 234,"Pump Running (Relay)"},
  93. { 235,"Final Valve Signal (Relay)'Qualification inhibit'"},
  94. { 236,"General Warning (Relay)"},
  95. { 237,"Gas Flow Warning (Relay)"},
  96. { 239,"Exhaust Pressure Warning (Relay)"},
  97. { 240,"Water Flow Warning (Relay)"},
  98. { 241,"Alarm (Relay)"},
  99. { 242,"MicroTim in control LED"},
  100. { 245,"Pump inverter Controller Temperature"},
  101. { 246,"Booster inverter Controller Temperature"},
  102. };
  103. public static Dictionary<int, string> EdwardsPumpPriorityLevel = new Dictionary<int, string>
  104. {
  105. { 0,"Indication only; no warning or alarm."},
  106. { 1,"Warning condition exists."},
  107. { 2,"Alarm condition exists: shut down the pump unless run til crash is set."},
  108. { 3,"Alarm condition exists: shut down the pump."}
  109. };
  110. public static Dictionary<int, string> EdwardsPumpAlarmType = new Dictionary<int, string>
  111. {
  112. { 0,"No alarm"},
  113. { 1,"Digital alarm"},
  114. { 9,"Low warning"},
  115. { 10,"Low alarm"},
  116. { 11,"High warning"},
  117. { 12,"High alarm"},
  118. { 13,"Device error"},
  119. { 14,"Device not present"}
  120. };
  121. public static Dictionary<int, string> EdwardsPumpBitFieldStatus = new Dictionary<int, string>()
  122. {
  123. { 0,"Module missing"},
  124. { 1,"Sensor present at switch-on, but now disconnected"},
  125. { 2,"Wrong gas module fitted"},
  126. { 3,"Voltage above valid maximum voltage"},
  127. { 4,"Voltage below valid minimum voltage"},
  128. { 5,"ADC(analogue to digital convertor) not operating"},
  129. { 6,"Electrical supply has been interrupted"},
  130. { 7,"Watchdog reset has occurred"},
  131. { 8,"Sensor missing at switch on"},
  132. { 9,"Module switching on"},
  133. { 10,"No current consumption at pump switch-on"},
  134. { 11,"Wrong phase input to pump"},
  135. { 12,"EMS (emergency stop) has been activated"},
  136. { 13,"Flow sensor zero out of range"},
  137. { 14,"cannot zero sensors"},
  138. { 15,"Configuration set read error"},
  139. };
  140. }
  141. public enum EdwardsPumpState { ON = 0, OFF, Connected, Disconnected, Unknown, ERROR }
  142. static class EdwardsPumpControlSystemParameters
  143. {
  144. public const int System_Node = 1;
  145. public const int Dry_Pump_Current = 3;
  146. public const int Dry_Pump_Power = 4;
  147. public const int Booster_Current = 7;
  148. public const int Booster_Power = 8;
  149. public const int Dry_Pump_Control = 11;
  150. public const int Dry_Pump_Run_hours = 14;
  151. public const int Number_of_pump_starts = 20;
  152. }
  153. static class EdwardsPumpMessage
  154. {
  155. public const string EOF = "\r\n";
  156. public const string RESET = "/";
  157. public const string QUERY_Alarm_Status = "?A";
  158. public const string QUERY_Bitfield_Status = "?B";
  159. public const string QUERY_Control_Status = "?C";
  160. public const string QUERY_Gas_ballast_Status = "?D";
  161. public const string QUERY_Gate_valve_Status = "?G";
  162. public const string QUERY_Nitrogen_supply_Status = "?N";
  163. public const string QUERY_On_process_Status = "?O";
  164. public const string QUERY_Pump_Status = "?P";
  165. public const string QUERY_Run_til_crash_Status = "?R";
  166. public const string QUERY_Inlet_purge_Status = "?U";
  167. public const string QUERY_Pump_node_type = "?T";
  168. public const string QUERY_Value = "?V";
  169. public const string QUERY_Serial_Number = "?S";
  170. public const string QUERY_Information = "?I";
  171. public const string QUERY_Format_mode = "?F";
  172. public const string COMMAND_Release_Control = "!C0";
  173. public const string COMMAND_Take_Control = "!C1";
  174. public const string COMMAND_Gas_ballast = "!D";
  175. public const string COMMAND_Equipment = "!E";
  176. public const string COMMAND_Format_mode = "!F";
  177. public const string COMMAND_Gate_valve = "!G";
  178. public const string COMMAND_Reserved = "!L";
  179. public const string COMMAND_Simulation_mode = "!M";
  180. public const string COMMAND_Nitrogen_supply = "!N";
  181. public const string COMMAND_On_process = "!O";
  182. public const string COMMAND_Switch_on_Pump = "!P1";
  183. public const string COMMAND_Switch_off_Pump_Auto_shut_down = "!P0";
  184. public const string COMMAND_Switch_off_Pump_Fast_shut_down = "!P2";
  185. public const string COMMAND_Run_til_crash = "!R";
  186. public const string COMMAND_Reserved_do_not_use = "!T";
  187. public const string COMMAND_Inlet_purge = "!U";
  188. public const string COMMAND_Terminate_protocol = "!XO";
  189. public const string SET_SHORT_REPLY = "!F0";
  190. public const string SET_LONG_REPLY = "!F1";
  191. }
  192. class EdwardsPump : PumpBase
  193. {
  194. // ----------------------------Fields--------------------------
  195. //
  196. private const ushort CHK_ST_INTERVAL = 1000;
  197. private const ushort CHK_CONTROL_INTERVAL = 3 * 1000;
  198. private const ushort CHK_REC_INTERVAL = 20 * 1000;
  199. private const ushort CHK_PUMP_REC_INTERVAL = 10 * 1000;
  200. private double _total;
  201. private double _fromLast;
  202. private const string EOF = "\r";
  203. private const char MSG_DELIMITER = ' ';
  204. private readonly string _PortNum = "COM91";
  205. private const int _counterMax = 30;
  206. //private int _counter = 0;
  207. private static string SendData;
  208. private readonly AsyncSerialPort _serial;
  209. private readonly DeviceTimer _timerQueryStatus = new DeviceTimer();
  210. private readonly DeviceTimer _timerControlStatus = new DeviceTimer();
  211. private readonly DeviceTimer _timerReceiveStatus = new DeviceTimer();
  212. private readonly DeviceTimer _timerPumpOn = new DeviceTimer();
  213. private readonly DeviceTimer _timerPumpOff = new DeviceTimer();
  214. private readonly DeviceTimer _timerTotal = new DeviceTimer();
  215. private readonly DeviceTimer _timerFromLast = new DeviceTimer();
  216. private readonly R_TRIG _trigPumpOn = new R_TRIG();
  217. private readonly R_TRIG _trigPumpOff = new R_TRIG();
  218. private readonly R_TRIG _trigReceiveStatus = new R_TRIG();
  219. private readonly RD_TRIG _trigOnOff = new RD_TRIG();
  220. private readonly R_TRIG _trigPMNeeded = new R_TRIG();
  221. private StatsDataItemRFAndPump _statPumpOnTime;
  222. // --------------------------Properties------------------------
  223. //
  224. private Stopwatch _pumpOnTimeWatch = new Stopwatch();
  225. public EdwardsPumpState StatusDry { get; set; }
  226. private string oldAlarm;
  227. public string LastPMTime
  228. {
  229. get
  230. {
  231. return _statPumpOnTime != null ? _statPumpOnTime.LastPMTime.ToString() : "";
  232. }
  233. }
  234. public float DaysFromLastPM
  235. {
  236. get
  237. {
  238. return _statPumpOnTime == null ? 0 : _statPumpOnTime.fromLastPM;
  239. }
  240. set
  241. {
  242. if (_statPumpOnTime != null)
  243. _statPumpOnTime.fromLastPM = value;
  244. }
  245. }
  246. public float TotalDays
  247. {
  248. get
  249. {
  250. return _statPumpOnTime != null ? _statPumpOnTime.Total : 0;
  251. }
  252. set
  253. {
  254. if (_statPumpOnTime != null)
  255. _statPumpOnTime.Total = value;
  256. }
  257. }
  258. public double PMIntervalDays
  259. {
  260. get
  261. {
  262. return _statPumpOnTime != null ? _statPumpOnTime.PMInterval : 0;
  263. }
  264. }
  265. public bool IsPMNeeded
  266. {
  267. get
  268. {
  269. return DaysFromLastPM > PMIntervalDays;
  270. }
  271. }
  272. public bool EnableAlarm
  273. {
  274. get
  275. {
  276. return _statPumpOnTime == null || _statPumpOnTime.AlarmEnable;
  277. }
  278. }
  279. [Subscription(AITPumpProperty.IsRunning)]
  280. public override bool IsRunning
  281. {
  282. get
  283. {
  284. return StatusDry == EdwardsPumpState.ON;
  285. }
  286. }
  287. [Subscription(AITPumpProperty.IsError)]
  288. public override bool IsError
  289. {
  290. get
  291. {
  292. return StatusDry == EdwardsPumpState.ERROR || StatusDry == EdwardsPumpState.Disconnected;
  293. }
  294. }
  295. public override AITPumpData DeviceData
  296. {
  297. get
  298. {
  299. AITPumpData deviceData = new AITPumpData
  300. {
  301. DeviceName = Name,
  302. DeviceModule = Module,
  303. DeviceSchematicId = DeviceID,
  304. DisplayName = Display,
  305. IsError = false,
  306. IsWarning = false,
  307. IsOn = IsRunning,
  308. //WaterFlow = WaterFlowValue,
  309. IsDryPumpEnable = true,
  310. IsN2PressureEnable = false,
  311. IsWaterFlowEnable = false,
  312. //WaterFlowWarning = WaterFlowWarning,
  313. //WaterFlowAlarm = WaterFlowAlarm,
  314. //N2PressureAlarm = N2PressureAlarm,
  315. //N2PressureWarning = N2PressureWarning,
  316. };
  317. return deviceData;
  318. }
  319. }
  320. private List<string> searchList = new List<string>()
  321. {
  322. EdwardsPumpMessage.QUERY_Pump_Status,
  323. EdwardsPumpMessage.QUERY_Information
  324. };
  325. private int i = 0;
  326. // --------------------------Constructor-----------------------
  327. //
  328. public EdwardsPump(ModuleName mod) : base(mod.ToString(), VenusDevice.MainPump.ToString(), "Edwards Pump", "")
  329. {
  330. _PortNum = SC.GetStringValue($"{mod}.DryPump.Port");
  331. StatusDry = EdwardsPumpState.Unknown;
  332. _serial = new AsyncSerialPort(_PortNum, 9600, 8, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.One, "\r\n", true);
  333. }
  334. public EdwardsPump(ModuleName mod, string name) : base(mod.ToString(), VenusDevice.MainPump.ToString(), "Edwards Pump", "")
  335. {
  336. _PortNum = SC.GetStringValue($"{mod.ToString()}.{name}.Port");
  337. StatusDry = EdwardsPumpState.Unknown;
  338. _serial = new AsyncSerialPort(_PortNum, 9600, 8, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.One, "\r\n", true);
  339. }
  340. public override bool Initialize()
  341. {
  342. base.Initialize();
  343. if (!_serial.Open())
  344. {
  345. StatusDry = EdwardsPumpState.Disconnected;
  346. LOG.Write(eEvent.ERR_DRY_PUMP, Module, "Edwards Pump串口无法打开");
  347. return false;
  348. }
  349. _statPumpOnTime = StatsDataManager.Instance.GetItemRFAndPump($"{Module}.PumpOnTime");
  350. StatusDry = EdwardsPumpState.Connected;
  351. _trigPumpOn.RST = true;
  352. _trigPumpOff.RST = true;
  353. _trigReceiveStatus.RST = true;
  354. _serial.OnDataChanged += OnPortDataChanged;
  355. _serial.OnErrorHappened += OnErrorOccurred;
  356. SendCmd(EdwardsPumpMessage.RESET);
  357. SendCmd(EdwardsPumpMessage.SET_LONG_REPLY);
  358. SendCmd(EdwardsPumpMessage.COMMAND_Take_Control);
  359. _timerQueryStatus.Start(CHK_ST_INTERVAL);
  360. _timerControlStatus.Start(CHK_CONTROL_INTERVAL);
  361. _timerReceiveStatus.Start(CHK_REC_INTERVAL);
  362. DATA.Subscribe($"{Module}.PumpOnTime", () => StatsDataManager.Instance.GetRFPumpTotalTime($"{Module}.PumpOnTime"));
  363. return true;
  364. }
  365. private void OnErrorOccurred(string obj)
  366. {
  367. //StatusDry = EdwardsPumpState.ERROR;
  368. LOG.Write(eEvent.WARN_DEVICE_INFO, Module, $"[{Module}] edwards pump error: [{obj}]");
  369. }
  370. private void OnPortDataChanged(string obj)
  371. {
  372. if (string.IsNullOrEmpty(obj))
  373. LOG.Write(eEvent.WARN_DEVICE_INFO, Module, "edwards pump message IsNullOrEmpty");
  374. try
  375. {
  376. _timerReceiveStatus.Stop();
  377. _timerReceiveStatus.Start(CHK_REC_INTERVAL);
  378. string cmd = obj.ToString().Split('\n')[0].Split('\r')[0];
  379. switch (SendData)
  380. {
  381. case EdwardsPumpMessage.RESET:
  382. break;
  383. case EdwardsPumpMessage.COMMAND_Take_Control:
  384. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"Take Control Edwards Pump {QueryCmdReply(cmd)}");
  385. break;
  386. case EdwardsPumpMessage.COMMAND_Release_Control:
  387. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"Release Control Edwards Pump {QueryCmdReply(cmd)}");
  388. break;
  389. case EdwardsPumpMessage.COMMAND_Switch_on_Pump:
  390. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"Switch on Edwards Pump {QueryCmdReply(cmd)}");
  391. break;
  392. case EdwardsPumpMessage.COMMAND_Switch_off_Pump_Fast_shut_down:
  393. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"Switch off Edwards Pump {QueryCmdReply(cmd)}");
  394. break;
  395. case EdwardsPumpMessage.QUERY_Pump_Status:
  396. string[] cmds = cmd.Split(',');
  397. if (cmds[0] == "0")
  398. {
  399. StatusDry = EdwardsPumpState.OFF;
  400. if (_trigPumpOn.Q && _timerPumpOn.IsTimeout())
  401. {
  402. _trigPumpOn.RST = true;
  403. LOG.Write(eEvent.WARN_DEVICE_INFO, Module, "Edwards Pump 无法打开");
  404. }
  405. if (_trigPumpOff.Q)
  406. {
  407. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"Edwards Pump关闭");
  408. }
  409. _trigPumpOff.RST = true;
  410. }
  411. else if (cmds[0] == "4")
  412. {
  413. StatusDry = EdwardsPumpState.ON;
  414. if (_trigPumpOff.Q && _timerPumpOff.IsTimeout())
  415. {
  416. _trigPumpOff.RST = true;
  417. LOG.Write(eEvent.WARN_DEVICE_INFO, Module, "Edwards Pump 无法关闭");
  418. }
  419. if (_trigPumpOn.Q)
  420. {
  421. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"Edwards Pump打开");
  422. }
  423. _trigPumpOn.RST = true;
  424. }
  425. break;
  426. case EdwardsPumpMessage.QUERY_Information:
  427. if (oldAlarm == cmd)
  428. {
  429. break;
  430. }
  431. oldAlarm = cmd;
  432. string[] infos = cmd.Split(';');
  433. int number = int.Parse(infos[0]);
  434. if (number > 0 && infos.Length > 1)
  435. {
  436. for (int i = 1; i < infos.Length; i++)
  437. {
  438. string detail = infos[i];
  439. string[] details = detail.Split(',');
  440. if (details.Length == 4)
  441. {
  442. int parameterCode = int.Parse(details[0]);
  443. int priorityCode = int.Parse(details[1]);
  444. int alarmTypeCode = int.Parse(details[2]);
  445. int bitStatusCode = int.Parse(details[3]);
  446. string parameterDesc = EdwardsPumpErrorInformation.EdwardsPumpParameters.ContainsKey(parameterCode) ? EdwardsPumpErrorInformation.EdwardsPumpParameters[parameterCode] : "UnKnowParameter";
  447. string priorityDesc = EdwardsPumpErrorInformation.EdwardsPumpPriorityLevel.ContainsKey(priorityCode) ? EdwardsPumpErrorInformation.EdwardsPumpPriorityLevel[priorityCode] : "UnknowPriority";
  448. string alarmTypeDesc = EdwardsPumpErrorInformation.EdwardsPumpAlarmType.ContainsKey(alarmTypeCode) ? EdwardsPumpErrorInformation.EdwardsPumpAlarmType[alarmTypeCode] : "UnknowAlarmType";
  449. var bitStatus = ConvertIntToBitArray(bitStatusCode);
  450. string bitbitStatusDesc = "";
  451. for (int j = 0; j < 16; j++)
  452. {
  453. if (bitStatus[j] == true)
  454. {
  455. bitbitStatusDesc += EdwardsPumpErrorInformation.EdwardsPumpBitFieldStatus.ContainsKey(j) ? EdwardsPumpErrorInformation.EdwardsPumpBitFieldStatus[j] : "UnKnowStatus";
  456. bitbitStatusDesc += " ";
  457. }
  458. }
  459. if (priorityCode == 0 ||priorityCode == 1)
  460. {
  461. LOG.Write(eEvent.WARN_DEFAULT_WARN, Module, $"Code:{detail},Parameter:{parameterDesc},Priority:{priorityDesc},Alarm Type:{alarmTypeDesc},Status:{bitbitStatusDesc}]");
  462. }
  463. else
  464. {
  465. LOG.Write(eEvent.ERR_DRY_PUMP, Module, $"Code:{detail},Parameter:{parameterDesc},Priority:{priorityDesc},Alarm Type:{alarmTypeDesc},Status:{bitbitStatusDesc}]");
  466. }
  467. }
  468. }
  469. }
  470. break;
  471. default:
  472. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"Edwards Pump {SendData} {QueryCmdReply(cmd)}");
  473. break;
  474. }
  475. }
  476. catch (Exception ex)
  477. {
  478. LOG.WriteExeption($"[{Module}] edwards pump error: ", ex);
  479. }
  480. }
  481. public string QueryCmdReply(string cmd)
  482. {
  483. if (cmd == "ERR 0")
  484. {
  485. return "No error";
  486. }
  487. else if (cmd == "ERR 1")
  488. {
  489. return "Invalid message";
  490. }
  491. else if (cmd == "ERR 2")
  492. {
  493. return "Number not found";
  494. }
  495. else if (cmd == "ERR 3")
  496. {
  497. return "Number Invalid";
  498. }
  499. else if (cmd == "ERR 4")
  500. {
  501. return "Parameter’s value not received";
  502. }
  503. else if (cmd == "ERR 5")
  504. {
  505. return "Command not possible";
  506. }
  507. else
  508. {
  509. return cmd;
  510. }
  511. }
  512. public override void Monitor()
  513. {
  514. try
  515. {
  516. // 状态查询
  517. if (_timerQueryStatus.IsTimeout())
  518. {
  519. string cmd = searchList[i];
  520. this.SendCmd(cmd);
  521. _timerQueryStatus.Start(CHK_ST_INTERVAL);
  522. i = (i + 1) % searchList.Count;
  523. }
  524. //if (_timerReceiveStatus.IsTimeout())
  525. //{
  526. // _trigReceiveStatus.CLK = true;
  527. // if (_trigReceiveStatus.Q)
  528. // {
  529. // //EV.PostMessage(Module, EventEnum.DefaultWarning, "Edwards Pump 没有回复");
  530. // //EV.PostAlarmLog(Module, "Edwards Pump 没有回复",)
  531. // }
  532. //}
  533. _trigOnOff.CLK = IsRunning;
  534. //第一次检测到打开了,开始计时
  535. if (_trigOnOff.R)
  536. {
  537. _total = TotalDays;
  538. _fromLast = DaysFromLastPM;
  539. _timerTotal.Start(0);
  540. _timerFromLast.Start(0);
  541. _pumpOnTimeWatch.Start();
  542. }
  543. //第一次检测到从打开到关闭状态
  544. if (_trigOnOff.T)
  545. {
  546. }
  547. //如果开着,就更新SC
  548. if (_trigOnOff.M && _pumpOnTimeWatch.ElapsedMilliseconds > 1000)
  549. {
  550. TotalDays = (float)1 / 60 / 60;
  551. DaysFromLastPM = (float)1 / 60 / 60;
  552. _pumpOnTimeWatch.Restart();
  553. //_timerTotal.Restart(0);
  554. //_timerFromLast.Restart(0);
  555. if (ModuleHelper.IsPm(Module))
  556. {
  557. StatsDataManager.Instance.Increase($"{Module}.PumpOnTime", $"{Module} PumpOnTime", DaysFromLastPM, TotalDays);
  558. }
  559. }
  560. if (PMIntervalDays > 0)
  561. {
  562. _trigPMNeeded.CLK = IsPMNeeded;
  563. if (_trigPMNeeded.Q)
  564. {
  565. if (EnableAlarm)
  566. {
  567. EV.PostAlarmLog(Module, "pump on time value larger than setting interval days");
  568. }
  569. }
  570. }
  571. //if (ModuleHelper.IsPm(Module))
  572. // StatsDataManager.Instance.Increase($"{Module}.PumpOnTime", $"{Module} PumpOnTime", DaysFromLastPM, TotalDays);
  573. }
  574. catch (Exception ex)
  575. {
  576. throw ex;
  577. }
  578. }
  579. private bool SendCmd(string str)
  580. {
  581. SendData = str;
  582. if (SendData == "!P1")
  583. {
  584. _trigPumpOn.CLK = true;
  585. _timerPumpOn.Start(CHK_PUMP_REC_INTERVAL);
  586. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"[{Module}] Switch on Edwards Pump");
  587. }
  588. else if (SendData == "!P2")
  589. {
  590. _trigPumpOff.CLK = true;
  591. _timerPumpOff.Start(CHK_PUMP_REC_INTERVAL);
  592. LOG.Write(eEvent.EV_DEVICE_INFO, Module, $"[{Module}] Switch off Edwards Pump");
  593. }
  594. return _serial.Write(str + "\r");
  595. }
  596. public override void Reset()
  597. {
  598. _trigPumpOn.RST = true;
  599. _trigPumpOff.RST = true;
  600. _trigReceiveStatus.RST = true;
  601. _trigPMNeeded.RST = true;
  602. SendCmd(EdwardsPumpMessage.RESET);
  603. }
  604. public override void Terminate()
  605. {
  606. //if (StatusDry == EdwardsPumpState.ON)
  607. // SetPumpOnOff(false);
  608. _serial?.Close();
  609. }
  610. public override void ResetPumpStats()
  611. {
  612. _statPumpOnTime = StatsDataManager.Instance.GetItemRFAndPump($"{Module}.PumpOnTime");
  613. }
  614. public override void SetPumpOnOff(bool on)
  615. {
  616. SendCmd(on ? EdwardsPumpMessage.COMMAND_Switch_on_Pump : EdwardsPumpMessage.COMMAND_Switch_off_Pump_Fast_shut_down);
  617. }
  618. public override bool ReConnect()
  619. {
  620. return _serial.ReConnect();
  621. }
  622. private bool[] ConvertIntToBitArray(int number)
  623. {
  624. bool[] bits = new bool[sizeof(int) * 8];
  625. for (int i = 0; i < bits.Length; i++)
  626. {
  627. bits[i] = (number & (1 << i)) != 0;
  628. }
  629. return bits;
  630. }
  631. }
  632. }