PMModuleInterlock.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Event;
  3. using Aitex.Core.RT.IOCore;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.OperationCenter;
  6. using Aitex.Core.RT.SCCore;
  7. using Aitex.Core.Util;
  8. using MECF.Framework.Common.OperationCenter;
  9. using System;
  10. using System.Collections;
  11. using System.Diagnostics;
  12. using System.Linq;
  13. namespace FurnaceRT.Equipments.PMs
  14. {
  15. public partial class PMModule
  16. {
  17. private SCConfigItem _configAutoControlCoolingValve;
  18. private SCConfigItem _configVacuumSensorPressure;
  19. private SCConfigItem _configAutoControlChiller;
  20. private SCConfigItem _chillerTurnOffIfTempBelow;
  21. private SCConfigItem _chillerTurnOnIfTempAbove;
  22. private PeriodicJob _threadMonitor;
  23. private bool _vac1;
  24. private bool _vac2;
  25. private bool _vac3;
  26. private Stopwatch _vac1Timer = new Stopwatch();
  27. private Stopwatch _vac2Timer = new Stopwatch();
  28. private Stopwatch _vac3Timer = new Stopwatch();
  29. private int _vac1PumpTimeS = 120;
  30. private int _vac2PumpTimeS = 120;
  31. private int _vac3PumpTimeS = 120;
  32. private void InitInterlock()
  33. {
  34. OP.AddCheck($"{Module}.{Name}.Disconnect", new CheckPlcConnect(this));
  35. //OP.AddCheck($"{ChamberDoor.Module}.{ChamberDoor.Name}.Open", new CheckOpenDoor(this));
  36. _configAutoControlCoolingValve = SC.GetConfigItem($"PM.{Module}.AutoControlCoolingValve");
  37. _configVacuumSensorPressure = SC.GetConfigItem($"PM.{Module}.VacuumSensorPressure");
  38. _configAutoControlChiller = SC.GetConfigItem($"PM.{Module}.Chiller.EnableAutoAdjust");
  39. _chillerTurnOffIfTempBelow = SC.GetConfigItem($"PM.{Module}.Chiller.TurnOffIfTempBelow");
  40. _chillerTurnOnIfTempAbove = SC.GetConfigItem($"PM.{Module}.Chiller.TurnOnIfTempAbove");
  41. _threadMonitor = new PeriodicJob(100, OnTimer, "interlock thread", true);
  42. }
  43. private void InitUserDefineInterlock()
  44. {
  45. //DATA.Subscribe($"{Module}.Heater1", () => 100);//自定义的Interlock limit
  46. InterlockManager.Instance.UserDefineInterlockHandler += UserDefineInterlockHandler;
  47. InterlockManager.Instance.UserDefineInterlocks += UserDefineInterlocks;
  48. //DATA.Subscribe("UserDefineInterlock", () => InterlockManager.Instance.UserDefineFlagCurrentValues);
  49. //DATA.Subscribe("UserDefineCurrent", () => InterlockManager.Instance.UserDefineCurrentValues);
  50. }
  51. //自定义的interlock action
  52. private bool UserDefineInterlocks(string name)
  53. {
  54. switch (name)
  55. {
  56. case "PM1.Heater1":
  57. return true;
  58. }
  59. return false;
  60. }
  61. //设置自定义的interlock action
  62. private bool UserDefineInterlockHandler(string name, object value)
  63. {
  64. switch(name)
  65. {
  66. case "PM1.Heater1":
  67. //设置Heater的值
  68. return true;
  69. }
  70. return false;
  71. }
  72. private class CheckOpenDoor : IInterlockChecker
  73. {
  74. private PMModule _pm;
  75. public CheckOpenDoor(PMModule pm)
  76. {
  77. _pm = pm;
  78. }
  79. public bool CanDo(out string reason, object[] args)
  80. {
  81. if (_pm.ChamberPressure < SC.GetValue<double>("PM.AtmPressureBase"))
  82. {
  83. reason = $"{_pm.Module} chamber pressure {_pm.ChamberPressure:F3} Torr less than {SC.GetValue<double>("PM.AtmPressureBase")} [PM.AtmPressureBase], can not open door";
  84. return false;
  85. }
  86. reason = string.Empty;
  87. return true;
  88. }
  89. }
  90. private class CheckPlcConnect : IInterlockChecker
  91. {
  92. private PMModule _pm;
  93. public CheckPlcConnect(PMModule pm)
  94. {
  95. _pm = pm;
  96. }
  97. public bool CanDo(out string reason, object[] args)
  98. {
  99. if (_pm.IsBusy)
  100. {
  101. reason = $"{_pm.Module} is in {_pm.StringFsmStatus} status, can not disconnect, should be idle";
  102. return false;
  103. }
  104. reason = string.Empty;
  105. return true;
  106. }
  107. }
  108. public bool OnTimer()
  109. {
  110. try
  111. {
  112. MonitorN2Purge();
  113. MonitorHTR2ILK();
  114. MonitorAux();
  115. MonitorFfu();
  116. lock (_alarmConditionLocker)
  117. {
  118. MonitorAlarmCondition();
  119. }
  120. if (!IsProcessing && TrigVGUnitConversion != null && SC.GetStringValue($"{Module}.APC.PressureUnit").ToLower() == "pa")
  121. {
  122. TrigVGUnitConversion.SetTrigger(SC.GetStringValue($"{Module}.APC.PressureUnit").ToLower() == "pa", out _);
  123. }
  124. //MonitorVAC1();
  125. //MonitorVAC2();
  126. //MonitorVAC3();
  127. //foreach (var item in _inCommandLst)
  128. //{
  129. // if (item == null)
  130. // continue;
  131. // if (!_inCommandTirgs.ContainsKey(item.Name))
  132. // {
  133. // _inCommandTirgs.Add(item.Name, new RD_TRIG());
  134. // }
  135. // _inCommandTirgs[item.Name].CLK = item.Value;
  136. //}
  137. //if (_inCommandTirgs[SensorHECPowerONSW.Name].R)
  138. //{
  139. // _trigTHPowerEN.SetTrigger(true, out _);
  140. // _trigHECPowerONLamp.SetTrigger(true, out _);
  141. //}
  142. //if (_inCommandTirgs[SensorHECPowerONSW.Name].T)
  143. //{
  144. //}
  145. //if (_inCommandTirgs[SensorTHBreakOK.Name].R)
  146. //{
  147. //}
  148. //if (_inCommandTirgs[SensorTHBreakOK.Name].T)
  149. //{
  150. // _trigTHPowerEN.SetTrigger(false, out _);
  151. // _trigHECPowerONLamp.SetTrigger(false, out _);
  152. //}
  153. ProcessAlarmSignal();
  154. //if (IV2Valve.Status != SensorVG2LOW.Value)
  155. // IV2Valve.TurnValve(SensorVG2LOW.Value, out _);
  156. //if (IV2Valve.Status != SensorVG2LOW.Value)
  157. // VV2Valve.TurnValve(SensorTubeOverPressure.Value, out _);
  158. if (IsInit || !IsInstalled)
  159. return true;
  160. //cooling 阀门
  161. if (_configAutoControlCoolingValve == null || _configAutoControlCoolingValve.BoolValue)
  162. {
  163. //if (ElectricalCoolingValve.Status != MainChiller.IsRunning)
  164. // ElectricalCoolingValve.TurnValve(MainChiller.IsRunning, out _);
  165. //if (MicrowaveCoolingValve.Status != MainChiller.IsRunning)
  166. // MicrowaveCoolingValve.TurnValve(MainChiller.IsRunning, out _);
  167. //if (ChamberLidCoolingValve.Status != MainChiller.IsRunning)
  168. // ChamberLidCoolingValve.TurnValve(MainChiller.IsRunning, out _);
  169. }
  170. //auto control chiller
  171. if (_configAutoControlChiller != null && _configAutoControlChiller.BoolValue && _chillerTurnOffIfTempBelow != null && _chillerTurnOnIfTempAbove != null)
  172. {
  173. //if (!MainChiller.HasAlarm)
  174. //{
  175. // if (MainChiller.IsRunning && (ChamberHeater1.Feedback < _chillerTurnOffIfTempBelow.DoubleValue))
  176. // {
  177. // if (!MainChiller.SetMainPowerOnOff(false, out string reason))
  178. // {
  179. // LOG.Write(reason);
  180. // }
  181. // }else if (!MainChiller.IsRunning && (ChamberHeater1.Feedback > _chillerTurnOnIfTempAbove.DoubleValue))
  182. // {
  183. // if (!MainChiller.SetMainPowerOnOff(true, out string reason))
  184. // {
  185. // LOG.Write(reason);
  186. // }
  187. // }
  188. //}
  189. }
  190. //压力保护计
  191. double pressure = 3.0;
  192. if (_configVacuumSensorPressure != null)
  193. pressure = _configVacuumSensorPressure.DoubleValue;
  194. if (pressure > 30.0)
  195. pressure = 30.0;
  196. //bool canOpen = ChamberMonitorPressureGauge.Value < pressure;
  197. //if (VacuumSensorValve.Status != canOpen)
  198. //{
  199. // VacuumSensorValve.TurnValve(canOpen, out _);
  200. //}
  201. ////interlock ignore
  202. //SignalExhaustAlarm.SetIgnoreError(SC.GetValue<bool>($"PM.{Module}.Signal.IgnoreExhaustAlarm"));
  203. }
  204. catch (Exception ex)
  205. {
  206. LOG.Write(ex);
  207. }
  208. return true;
  209. }
  210. private void ProcessAlarmSignal()
  211. {
  212. bool isTrig = false;
  213. foreach (var signal in _alarmSignals)
  214. {
  215. if (signal.RrigSignalOn.T && signal.IsAlarmAutoRecovery)
  216. {
  217. var item = _triggeredAlarmList.FirstOrDefault(x => x.EventEnum == signal.AlarmTriggered.EventEnum);
  218. if (item != null)
  219. {
  220. item.Reset();
  221. _triggeredAlarmList.Remove(item);
  222. EV.ClearAlarmEvent(item.EventEnum);
  223. }
  224. isTrig = true;
  225. signal.AlarmRecovery?.Set();
  226. }
  227. }
  228. if (isTrig)
  229. {
  230. int count = 0;
  231. var alarms = EV.GetAlarmEvent();
  232. foreach (var alarm in alarms)
  233. {
  234. if (alarm.Level == EventLevel.Alarm && alarm.Source == Name)
  235. count++;
  236. }
  237. if (count == 0)
  238. CheckToPostMessage((int)MSG.Reset);
  239. }
  240. }
  241. private void MonitorVAC1()
  242. {
  243. if (_vac1Timer == null)
  244. _vac1Timer = new Stopwatch();
  245. if (ValveAV24.Status)
  246. {
  247. _vac1 = false;
  248. if (_vac1Timer.IsRunning)
  249. _vac1Timer.Stop();
  250. }
  251. if(!ValveAV9.Status &&
  252. !ValveAV16.Status &&
  253. !ValveAV20.Status &&
  254. !ValveAV24.Status &&
  255. ValveAV26.Status &&
  256. (ValveAV33.Status || ValveAV35.Status) &&
  257. ValveAV83.Status &&
  258. ValveAV71.Status &&
  259. (APC.ModeFeedback == 0 || APC.ModeFeedback == 6) &&//0=idle;6=full open
  260. SensorVG11Status.Value && !AlarmSignalVG11HighAlarm.Value)
  261. {
  262. if (!_vac1Timer.IsRunning)
  263. _vac1Timer.Restart();
  264. if(_vac1Timer.ElapsedMilliseconds > _vac1PumpTimeS * 1000)
  265. _vac1 = true;
  266. }
  267. else
  268. {
  269. if (_vac1Timer.IsRunning)
  270. _vac1Timer.Stop();
  271. }
  272. }
  273. private void MonitorVAC2()
  274. {
  275. if (_vac2Timer == null)
  276. _vac2Timer = new Stopwatch();
  277. if (ValveAV9.Status)
  278. {
  279. _vac2 = false;
  280. if (_vac2Timer.IsRunning)
  281. _vac2Timer.Stop();
  282. }
  283. if (!ValveAV9.Status &&
  284. !ValveAV16.Status &&
  285. !ValveAV20.Status &&
  286. !ValveAV24.Status &&
  287. ValveAV12.Status &&
  288. ValveAV14.Status &&
  289. ValveAV28.Status &&
  290. ValveAV29.Status &&
  291. ValveAV36.Status &&
  292. ValveAV37.Status &&
  293. ValveAV81.Status &&
  294. ValveAV71.Status &&
  295. (APC.ModeFeedback == 0 || APC.ModeFeedback == 6) &&//0=idle;6=full open
  296. SensorVG11Status.Value && !AlarmSignalVG11HighAlarm.Value)
  297. {
  298. if (!_vac2Timer.IsRunning)
  299. _vac2Timer.Restart();
  300. if (_vac2Timer.ElapsedMilliseconds > _vac2PumpTimeS * 1000)
  301. _vac2 = true;
  302. }
  303. else
  304. {
  305. if (_vac2Timer.IsRunning)
  306. _vac2Timer.Stop();
  307. }
  308. }
  309. private void MonitorVAC3()
  310. {
  311. if (_vac3Timer == null)
  312. _vac3Timer = new Stopwatch();
  313. if (ValveAV16.Status || ValveAV20.Status)
  314. {
  315. _vac3 = false;
  316. if (_vac3Timer.IsRunning)
  317. _vac3Timer.Stop();
  318. }
  319. if (!ValveAV9.Status &&
  320. !ValveAV16.Status &&
  321. !ValveAV20.Status &&
  322. !ValveAV24.Status &&
  323. ValveAV18.Status &&
  324. ValveAV22.Status &&
  325. ValveAV38.Status &&
  326. ValveAV39.Status &&
  327. ValveAV82.Status &&
  328. ValveAV71.Status &&
  329. (APC.ModeFeedback == 0 || APC.ModeFeedback == 6) &&//0=idle;6=full open
  330. SensorVG11Status.Value && !AlarmSignalVG11HighAlarm.Value)
  331. {
  332. if (!_vac3Timer.IsRunning)
  333. _vac3Timer.Restart();
  334. if (_vac3Timer.ElapsedMilliseconds > _vac3PumpTimeS * 1000)
  335. _vac3 = true;
  336. }
  337. else
  338. {
  339. if (_vac3Timer.IsRunning)
  340. _vac3Timer.Stop();
  341. }
  342. }
  343. }
  344. }