PMAlarmCondition.cs 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  1. using Aitex.Core.Common.DeviceData;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Device.Unit;
  5. using Aitex.Core.RT.Event;
  6. using Aitex.Core.RT.IOCore;
  7. using Aitex.Core.RT.Log;
  8. using Aitex.Core.RT.OperationCenter;
  9. using Aitex.Core.RT.ParameterCenter;
  10. using Aitex.Core.RT.SCCore;
  11. using Aitex.Core.RT.Tolerance;
  12. using Aitex.Core.Util;
  13. using DocumentFormat.OpenXml.Drawing.Charts;
  14. using FurnaceRT.Equipments.PMs.RecipeExecutions;
  15. using FurnaceRT.Equipments.Systems;
  16. using MECF.Framework.Common.CommonData.EnumData;
  17. using MECF.Framework.Common.Device.Bases;
  18. using MECF.Framework.Common.Equipment;
  19. using MECF.Framework.Common.Event;
  20. using MECF.Framework.Common.FAServices;
  21. using MECF.Framework.Common.OperationCenter;
  22. using MECF.Framework.Common.Tolerance;
  23. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  24. using System;
  25. using System.Collections;
  26. using System.Collections.Generic;
  27. using System.Diagnostics;
  28. using System.Linq;
  29. using System.Web.ApplicationServices;
  30. using System.Xml;
  31. namespace FurnaceRT.Equipments.PMs
  32. {
  33. public partial class PMModule
  34. {
  35. private string _currentAlarmConditionFileName;
  36. private int _currentAlarmConditionIndex;
  37. private Dictionary<int, AlarmConditionTableParameter> _alarmConditionDic;
  38. private List<AlarmConditionChecker> _heaterChecker;
  39. private List<AlarmConditionChecker> _mfcChecker;
  40. private List<AlarmConditionChecker> _apcChecker;
  41. private List<AlarmConditionChecker> _auxChecker;
  42. private List<AlarmConditionChecker> _hwILKChecker;
  43. private object _alarmConditionLocker = new object();
  44. private bool _isAlarmConditionHasRecipeCommand;//End,Reset,Hold,JumpStep,CallAlarmRecipe,CallAbortRecipe
  45. private Dictionary<string, string> _hardwareInterlockAlarmConditionDic;
  46. private Dictionary<string, string> _clnAlarmConditionDic;
  47. private AlarmEventItem _lastAlarmInAlarmCondition;
  48. private void SetAlarmConditionTableIndex(int index)
  49. {
  50. if (_alarmConditionDic == null)
  51. return;
  52. var ret = _alarmConditionDic.TryGetValue(index, out var currentParameter);
  53. if (!ret)
  54. return;
  55. _currentAlarmConditionIndex = index;
  56. SC.SetItemValueFromString("PM1.AlarmConditionIndex", index.ToString());
  57. //ResetAlarmCondition();
  58. for (int i = 0; i < _heaterChecker.Count; i++)
  59. {
  60. var checker = _heaterChecker[i];
  61. //checker.Parameter = checker.Parameter.Clone(currentParameter.HeaterParameterLst.Find(x => x.Name == checker.Heater.Display));
  62. checker.Parameter = currentParameter.HeaterParameterLst[i];
  63. //checker.ToleranceCheckerWarning.Reset(checker.Parameter.WarningTime);
  64. //checker.ToleranceCheckerAlarm.Reset(checker.Parameter.AlarmTime);
  65. }
  66. for (int i = 0; i < _mfcChecker.Count && i < currentParameter.MFCParameterLst.Count; i++)
  67. {
  68. var checker = _mfcChecker[i];
  69. checker.Parameter = currentParameter.MFCParameterLst[i];
  70. }
  71. for (int i = 0; i < _apcChecker.Count && i < currentParameter.APCParameterLst.Count; i++)
  72. {
  73. var checker = _apcChecker[i];
  74. checker.Parameter = currentParameter.APCParameterLst[i];
  75. }
  76. for (int i = 0; i < _auxChecker.Count && i < currentParameter.AUXParameterLst.Count; i++)
  77. {
  78. var checker = _auxChecker[i];
  79. checker.Parameter = currentParameter.AUXParameterLst[i];
  80. }
  81. for (int i = 0; i < _hwILKChecker.Count && i < currentParameter.InterlockParameterLst.Count; i++)
  82. {
  83. var checker = _hwILKChecker[i];
  84. checker.DIParameter = currentParameter.InterlockParameterLst[i];
  85. }
  86. }
  87. public void ResetAlarmCondition()
  88. {
  89. for (int i = 0; i < _heaterChecker.Count; i++)
  90. {
  91. var checker = _heaterChecker[i];
  92. checker.ToleranceCheckerWarning.RST = true;
  93. checker.ToleranceCheckerAlarm.RST = true;
  94. checker?.DelayTimer.Restart();
  95. }
  96. for (int i = 0; i < _mfcChecker.Count; i++)
  97. {
  98. var checker = _mfcChecker[i];
  99. checker.ToleranceCheckerWarning.RST = true;
  100. checker.ToleranceCheckerAlarm.RST = true;
  101. checker?.DelayTimer.Restart();
  102. }
  103. for (int i = 0; i < _apcChecker.Count; i++)
  104. {
  105. var checker = _apcChecker[i];
  106. checker.ToleranceCheckerWarning.RST = true;
  107. checker.ToleranceCheckerAlarm.RST = true;
  108. checker?.DelayTimer.Restart();
  109. }
  110. for (int i = 0; i < _auxChecker.Count; i++)
  111. {
  112. var checker = _auxChecker[i];
  113. if (checker == null)
  114. continue;
  115. checker.ToleranceCheckerWarning.RST = true;
  116. checker.ToleranceCheckerAlarm.RST = true;
  117. checker?.DelayTimer.Restart();
  118. }
  119. for (int i = 0; i < _hwILKChecker.Count; i++)
  120. {
  121. var checker = _hwILKChecker[i];
  122. checker?.FilterCheckerAlarm?.Restart();
  123. }
  124. }
  125. private void InitAlarmConditionChecker()
  126. {
  127. InitHeaterChecker();
  128. InitMFCChecker();
  129. InitAPCChecker();
  130. InitAUXChecker();
  131. InitHWILKChecker();
  132. //_hardwareInterlockAlarmConditionDic = new Dictionary<string, string>()
  133. //{
  134. // {"AlarmSignalOPBoxPS11Out1", "Air/N2-7 Pressure Too Low"},//deviceModel的名称和AlarmCondition ParameterFormat.xml的名称
  135. // {"AlarmSignalGLBoxPG1CNT1Alarm", "N2-1 Pressure Too Low"},
  136. // {"AlarmSignalGLBoxPG1CNT2Alarm", "N2-1 Pressure Too High"},
  137. // {"AlarmSignalGLBoxPG2CNT1Alarm", "SiH2Cl2 Pressure Too Low"},
  138. // {"AlarmSignalGLBoxPG2CNT2Alarm", "SiH2Cl2 Pressure Too High"},
  139. // {"AlarmSignalGLBoxPG3CNT1Alarm", "NH3-1 Pressure To Low"},
  140. // {"AlarmSignalGLBoxPG3CNT2Alarm", "NH3-1 Pressure Too High"},
  141. // {"AlarmSignalGLBoxPG4CNT1Alarm", "NH3-2 Pressure Too Low"},
  142. // {"AlarmSignalGLBoxPG4CNT2Alarm", "NH3-2 Pressure Too High"},
  143. // {"AlarmSignalGLBoxPG5CNT1Alarm", "N2-2 Pressure Too Low"},
  144. // {"AlarmSignalGLBoxPG5CNT2Alarm", "N2-2 Pressure Too High"},
  145. // {"AlarmSignalGLBoxPG6CNT1Alarm", "20% F2/N2 Pressure Too Low"},
  146. // {"AlarmSignalGLBoxPG6CNT2Alarm", "20% F2/N2 Pressure Too High"},
  147. // {"AlarmSignalPG12OUT1", "N2-8-1 Pressure Too Low"},
  148. // {"AlarmSignalPG12OUT2", "N2-8-1 Pressure Too High"},
  149. // {"AlarmSignalPG13OUT1", "N2-8-2 Pressure Too Low"},
  150. // {"AlarmSignalPS14OUT1", "O.PRS-PS14 Pressure Too High"},
  151. // {"AlarmSignalPS14OUT2", "O.PRS-PS14 Pressure Too High"},
  152. // {"AlarmSignalN2PurgeBOXPG16CNT1", "N2-6 Pressure Too Low"},
  153. // {"AlarmSignalN2PurgeBOXPG70CNT2", "N2-70 Pressure Too Low"},
  154. // {"AlarmSignalPS17ValueLowLimitAlarm", "Air/N2-1 Pressure Too Low"},
  155. // {"AlarmSignalHeatingExhaust1stAlarmMS1", "Heater Exhaust Pressure Too Low"},
  156. // {"AlarmSignalScavengeExhaust1stAlarmMS3", "Scavenge Exhaust Pressure Too Low"},
  157. // {"AlarmSignalValveBoxExhaust1stAlarmMS4", "ValveBox Exhaust Pressure Too Low"},
  158. // {"AlarmSignalGasBoxExhaust1stAlarmMS2", "GasBox Exhaust Pressure Too Low"},
  159. // {"AlarmSignalLAExhaust1stAlarmMS7", "LA Exhaust Pressure Too Low"},
  160. // {"AlarmSignalRHC1stAlarmMS8", "RHC Exhaust Pressure Too Low"},
  161. // {"AlarmSignalLoadingAreaExhaust1stAlarmMS5", "Loading Area Exhaust Abnormal"},
  162. // {"AlarmSignalFrontBodyExhaust1stAlarmMS6", "FrontBody Exhaust Pressure Too Low"},
  163. // {"AlarmSignalMainFurnaceCellingTS306", "TEMP1 HTR Abnormal"},
  164. // {"AlarmSignalT101TempStatus", "TEMP3 TR1 Abnormal"},
  165. // {"AlarmSignalT102TempStatus", "TEMP4 TR2 Abnormal"},
  166. // {"AlarmSignalT103TempStatus", "TEMP5 TR3 Abnormal"},
  167. // {"AlarmSignalMagneticFluidLeak", "Magnetic Water Leak"},
  168. // {"AlarmSignalCoolingWaterLeak", "Cooling Water Leak"},
  169. // {"AlarmSignalFBFrontDoorSwitch", "Front Panel Abnormal"},
  170. // {"AlarmSignalFilterBox1DoorSwitch", "Filter Box Cover Abnormal"},
  171. // {"AlarmSignalLABacksideDoorSwitch", "Transfer Room Panel Abnormal"},
  172. // {"AlarmSignalHeaterRoomSWS11S12", "Heater Room Panel Abnormal"},
  173. // {"AlarmSignalGasBoxLowerDoorSW", "GasBox Lower Door Abnormal"},
  174. // {"AlarmSignalGasBoxUpperDoorSW", "GasBox Upper Door Abnormal"},
  175. // {"AlarmSignalRHCTS305", "RHC Abnormal Radiator"},
  176. // {"AlarmSignalRHCFlowAlarmFL901", "RHC Flow Abnormal"},
  177. // {"AlarmSignalCoolingWaterFlowAlarmOfFurnaceFL902", "Cooling Water Flow Of Furnace Abnormal"},
  178. // {"AlarmSignalCoolingWaterFlowAlarmOfShuttleFL903", "Cooling Water Flow Of Shuttle Abnormal"},
  179. // {"AlarmSignalCoolingWaterFlowAlarmOfBoatRotationFL904", "Cooling Water Flow Of BoatRotation Abnormal"},
  180. // {"AlarmSignalCoolingWaterFlowAlarmOfFlangeFL905", "Cooling Water Flow Of Flange Abnormal"},
  181. // {"AlarmSignalCoolingWaterFlowAlarmOfLoadingAreaFL906", "Cooling Water Flow Of Loading Area Abnormal"},
  182. // {"AlarmSignalRFAlarm", "RF Alarm"},
  183. // {"AlarmSignalAirFlowFL70", "RF N2 Flow Abnormal"},
  184. // {"AlarmSignalAirFlowFL71", "RF N2 Flow Abnormal"},
  185. // {"AlarmSignalFilterBox1Fan1Alarm", "Filter Box Fan Abnormal"},
  186. // {"AlarmSignalFilterBox1Fan2Alarm", "Filter Box Fan Abnormal"},
  187. // {"AlarmSignalHCLGasLeak1stAlarm", "SiH2CL2 Gas Leak"},
  188. // {"AlarmSignalHCLGasLeak2ndAlarm", "SiH2CL2 Gas Leak"},
  189. // {"AlarmSignalNH3GasLeak1stAlarm", "NH3 Gas Leak"},
  190. // {"AlarmSignalNH3GasLeak2ndAlarm", "NH3 Gas Leak"},
  191. // {"AlarmSignalF2GasLeak1stAlarm", "F2 Gas Leak"},
  192. // {"AlarmSignalF2GasLeak2ndAlarm", "F2 Gas Leak"},
  193. // {"AlarmSignalGasLeakFault", "Gas Leak Fault"},
  194. // //{"AlarmSignalFurnaceMainCircuitBreakerStatusMonitor", "Heater Power Down"},
  195. // {"AlarmSignalVaccumPumpWarning", "Vacuum Pump Warning"},
  196. // {"AlarmSignalVaccumPumpAlarm", "Vacuum Pump Alarm"},
  197. // {"AlarmSignalPS13HStatus", "O.PRS Too High"},
  198. // {"AlarmSignalPS13LStatus", "CK.PRS Too Low"},
  199. // {"AlarmSignalDG1Output1", "P.CNT Pressure NG"},
  200. // {"AlarmSignalDG1Output2", "P.CNT Pressure NG"},
  201. // {"AlarmSignalAV91_1RHCAirInOpened", "RHC.DMR Abnormal"},
  202. // {"AlarmSignalAV91_2RHCAirInOpened", "RHC.DMR Abnormal"},
  203. // {"AlarmSignalAV91_3RHCAirInOpened", "RHC.DMR Abnormal"},
  204. // {"AlarmSignalAV91_4RHCAirInOpened", "RHC.DMR Abnormal"},
  205. // {"AlarmSignalBlowerPower", "BlowerPower Overload"},
  206. // {"AlarmSignalRFSetPowerReached", "RF Output Abnormal"},
  207. // {"AlarmSignalN2FlowInFOUPAbnormal", "N2 Flow in FOUP Abnormal"},
  208. // {"AlarmSignalCapHeaterAbnormal", "Cap Heater Abnormal"},
  209. // {"AlarmSignalHeaterUOverTemp", "Tube Heater OverTemp"},
  210. // {"AlarmSignalHeaterCUOverTemp", "Tube Heater OverTemp"},
  211. // {"AlarmSignalHeaterCOverTemp", "Tube Heater OverTemp"},
  212. // {"AlarmSignalHeaterCLOverTemp", "Tube Heater OverTemp"},
  213. // {"AlarmSignalHeaterLOverTemp", "Tube Heater OverTemp"},
  214. // {"InterlockAlarm", "Valve Interlock"},
  215. // {"GasLine1AlarmSignalTempOutRange", "temp range alarm"},
  216. // {"GasLine2AlarmSignalTempOutRange", "temp range alarm"},
  217. // {"GasLine3AlarmSignalTempOutRange", "temp range alarm"},
  218. // {"GasLine4AlarmSignalTempOutRange", "temp range alarm"},
  219. // {"GasLine5AlarmSignalTempOutRange", "temp range alarm"},
  220. // {"GasLine6AlarmSignalTempOutRange", "temp range alarm"},
  221. // {"GasLine7AlarmSignalTempOutRange", "temp range alarm"},
  222. // {"GasLine1AlarmSignalCLN", "CLN alarm"},
  223. // {"GasLine2AlarmSignalCLN", "CLN alarm"},
  224. // {"GasLine3AlarmSignalCLN", "CLN alarm"},
  225. // {"GasLine4AlarmSignalCLN", "CLN alarm"},
  226. // {"GasLine5AlarmSignalCLN", "CLN alarm"},
  227. // {"GasLine6AlarmSignalCLN", "CLN alarm"},
  228. // {"GasLine7AlarmSignalCLN", "CLN alarm"},
  229. //};
  230. _clnAlarmConditionDic = new Dictionary<string, string>()
  231. {
  232. {"AlarmSignalOPBoxPS11Out1", "temp range warning"},//deviceModel的名称和AlarmCondition ParameterFormat.xml的名称
  233. {"AlarmSignalTempOutRange", "temp range alarm"},
  234. {"AlarmSignalGLBoxPG1CNT2Alarm", "CLN warning"},
  235. {"AlarmSignalCLN", "CLN alarm"},
  236. };
  237. if (!string.IsNullOrEmpty(SC.GetStringValue("PM1.AlarmCondition")))
  238. {
  239. InitAlarmCondition(SC.GetStringValue("PM1.AlarmCondition"));
  240. int.TryParse(SC.GetStringValue("PM1.AlarmConditionIndex"), out int index);
  241. SetAlarmConditionTableIndex(index);
  242. }
  243. }
  244. private void InitHWILKChecker()
  245. {
  246. _hwILKChecker = new List<AlarmConditionChecker>();
  247. foreach (var item in _sensors)
  248. {
  249. if (item.Value == null)
  250. continue;
  251. if (item.Value.SensorCategoryKey != ((int)SensorCategoryEnum.HWILK).ToString())
  252. continue;
  253. var checker = new AlarmConditionChecker()
  254. {
  255. Name = item.Value.Name,
  256. FilterCheckerAlarm = new FilterChecker(),
  257. Parameter = new AlarmConditionAIParameter(),
  258. };
  259. _hwILKChecker.Add(checker);
  260. }
  261. }
  262. private void InitAUXChecker()
  263. {
  264. _auxChecker = new List<AlarmConditionChecker>();
  265. for (int index = 0; index < 512; index++)
  266. {
  267. if (!SC.ContainsItem($"PM1.RecipeEditParameter.AUX.{index}.AI"))
  268. continue;
  269. var checker = new AlarmConditionChecker()
  270. {
  271. AUXIOName = SC.GetStringValue($"PM1.RecipeEditParameter.AUX.{index}.AI"),
  272. AUXIndex = index,
  273. ToleranceCheckerWarning = new ToleranceChecker(),
  274. ToleranceCheckerAlarm = new ToleranceChecker(),
  275. Parameter = new AlarmConditionAIParameter(),
  276. DelayTimer = new Stopwatch(),
  277. };
  278. _auxChecker.Add(checker);
  279. }
  280. }
  281. private void InitAPCChecker()
  282. {
  283. _apcChecker = new List<AlarmConditionChecker>()
  284. {
  285. new AlarmConditionChecker()
  286. {
  287. APC = APC,
  288. ToleranceCheckerWarning = new ToleranceChecker(),
  289. ToleranceCheckerAlarm = new ToleranceChecker(),
  290. Parameter = new AlarmConditionAIParameter(),
  291. DelayTimer = new Stopwatch(),
  292. },
  293. new AlarmConditionChecker()
  294. {
  295. APC = APC,
  296. ToleranceCheckerWarning = new ToleranceChecker(),
  297. ToleranceCheckerAlarm = new ToleranceChecker(),
  298. Parameter = new AlarmConditionAIParameter(),
  299. DelayTimer = new Stopwatch(),
  300. },
  301. new AlarmConditionChecker()
  302. {
  303. APC = APC,
  304. ToleranceCheckerWarning = new ToleranceChecker(),
  305. ToleranceCheckerAlarm = new ToleranceChecker(),
  306. Parameter = new AlarmConditionAIParameter(),
  307. DelayTimer = new Stopwatch(),
  308. },
  309. };
  310. }
  311. private void InitMFCChecker()
  312. {
  313. _mfcChecker = new List<AlarmConditionChecker>()
  314. {
  315. new AlarmConditionChecker()
  316. {
  317. MFC = MFC1,
  318. ToleranceCheckerWarning = new ToleranceChecker(),
  319. ToleranceCheckerAlarm = new ToleranceChecker(),
  320. Parameter = new AlarmConditionAIParameter(),
  321. DelayTimer = new Stopwatch(),
  322. },
  323. new AlarmConditionChecker()
  324. {
  325. MFC = MFC2,
  326. ToleranceCheckerWarning = new ToleranceChecker(),
  327. ToleranceCheckerAlarm = new ToleranceChecker(),
  328. Parameter = new AlarmConditionAIParameter(),
  329. DelayTimer = new Stopwatch(),
  330. },
  331. new AlarmConditionChecker()
  332. {
  333. MFC = MFC3,
  334. ToleranceCheckerWarning = new ToleranceChecker(),
  335. ToleranceCheckerAlarm = new ToleranceChecker(),
  336. Parameter = new AlarmConditionAIParameter(),
  337. DelayTimer = new Stopwatch(),
  338. },
  339. new AlarmConditionChecker()
  340. {
  341. MFC = MFC4,
  342. ToleranceCheckerWarning = new ToleranceChecker(),
  343. ToleranceCheckerAlarm = new ToleranceChecker(),
  344. Parameter = new AlarmConditionAIParameter(),
  345. DelayTimer = new Stopwatch(),
  346. },
  347. new AlarmConditionChecker()
  348. {
  349. MFC = MFC5,
  350. ToleranceCheckerWarning = new ToleranceChecker(),
  351. ToleranceCheckerAlarm = new ToleranceChecker(),
  352. Parameter = new AlarmConditionAIParameter(),
  353. DelayTimer = new Stopwatch(),
  354. },
  355. new AlarmConditionChecker()
  356. {
  357. MFC = MFC6,
  358. ToleranceCheckerWarning = new ToleranceChecker(),
  359. ToleranceCheckerAlarm = new ToleranceChecker(),
  360. Parameter = new AlarmConditionAIParameter(),
  361. DelayTimer = new Stopwatch(),
  362. },
  363. new AlarmConditionChecker()
  364. {
  365. MFC = MFC7,
  366. ToleranceCheckerWarning = new ToleranceChecker(),
  367. ToleranceCheckerAlarm = new ToleranceChecker(),
  368. Parameter = new AlarmConditionAIParameter(),
  369. DelayTimer = new Stopwatch(),
  370. },
  371. new AlarmConditionChecker()
  372. {
  373. MFC = MFC8,
  374. ToleranceCheckerWarning = new ToleranceChecker(),
  375. ToleranceCheckerAlarm = new ToleranceChecker(),
  376. Parameter = new AlarmConditionAIParameter(),
  377. DelayTimer = new Stopwatch(),
  378. },
  379. new AlarmConditionChecker()
  380. {
  381. MFC = MFC9,
  382. ToleranceCheckerWarning = new ToleranceChecker(),
  383. ToleranceCheckerAlarm = new ToleranceChecker(),
  384. Parameter = new AlarmConditionAIParameter(),
  385. DelayTimer = new Stopwatch(),
  386. },
  387. new AlarmConditionChecker()
  388. {
  389. MFC = MFC10,
  390. ToleranceCheckerWarning = new ToleranceChecker(),
  391. ToleranceCheckerAlarm = new ToleranceChecker(),
  392. Parameter = new AlarmConditionAIParameter(),
  393. DelayTimer = new Stopwatch(),
  394. },
  395. new AlarmConditionChecker()
  396. {
  397. MFC = MFC11,
  398. ToleranceCheckerWarning = new ToleranceChecker(),
  399. ToleranceCheckerAlarm = new ToleranceChecker(),
  400. Parameter = new AlarmConditionAIParameter(),
  401. DelayTimer = new Stopwatch(),
  402. },
  403. new AlarmConditionChecker()
  404. {
  405. MFC = MFC12,
  406. ToleranceCheckerWarning = new ToleranceChecker(),
  407. ToleranceCheckerAlarm = new ToleranceChecker(),
  408. Parameter = new AlarmConditionAIParameter(),
  409. DelayTimer = new Stopwatch(),
  410. },
  411. };
  412. if (MFC13 != null)
  413. {
  414. _mfcChecker.Add(new AlarmConditionChecker()
  415. {
  416. MFC = MFC13,
  417. ToleranceCheckerWarning = new ToleranceChecker(),
  418. ToleranceCheckerAlarm = new ToleranceChecker(),
  419. Parameter = new AlarmConditionAIParameter(),
  420. DelayTimer = new Stopwatch(),
  421. });
  422. }
  423. if (MFC14 != null)
  424. {
  425. _mfcChecker.Add(new AlarmConditionChecker()
  426. {
  427. MFC = MFC14,
  428. ToleranceCheckerWarning = new ToleranceChecker(),
  429. ToleranceCheckerAlarm = new ToleranceChecker(),
  430. Parameter = new AlarmConditionAIParameter(),
  431. DelayTimer = new Stopwatch(),
  432. });
  433. }
  434. if (MFC15 != null)
  435. {
  436. _mfcChecker.Add(new AlarmConditionChecker()
  437. {
  438. MFC = MFC15,
  439. ToleranceCheckerWarning = new ToleranceChecker(),
  440. ToleranceCheckerAlarm = new ToleranceChecker(),
  441. Parameter = new AlarmConditionAIParameter(),
  442. DelayTimer = new Stopwatch(),
  443. });
  444. }
  445. if (MFC16 != null)
  446. {
  447. _mfcChecker.Add(new AlarmConditionChecker()
  448. {
  449. MFC = MFC16,
  450. ToleranceCheckerWarning = new ToleranceChecker(),
  451. ToleranceCheckerAlarm = new ToleranceChecker(),
  452. Parameter = new AlarmConditionAIParameter(),
  453. DelayTimer = new Stopwatch(),
  454. });
  455. }
  456. }
  457. private void InitHeaterChecker()
  458. {
  459. _heaterChecker = new List<AlarmConditionChecker>()
  460. {
  461. new AlarmConditionChecker()
  462. {
  463. Heater = HeaterU,
  464. ToleranceCheckerWarning = new ToleranceChecker(),
  465. ToleranceCheckerAlarm = new ToleranceChecker(),
  466. Parameter = new AlarmConditionAIParameter(),
  467. DelayTimer = new Stopwatch(),
  468. },
  469. new AlarmConditionChecker()
  470. {
  471. Heater = HeaterCU,
  472. ToleranceCheckerWarning = new ToleranceChecker(),
  473. ToleranceCheckerAlarm = new ToleranceChecker(),
  474. Parameter = new AlarmConditionAIParameter(),
  475. DelayTimer = new Stopwatch(),
  476. },
  477. new AlarmConditionChecker()
  478. {
  479. Heater = HeaterC,
  480. ToleranceCheckerWarning = new ToleranceChecker(),
  481. ToleranceCheckerAlarm = new ToleranceChecker(),
  482. Parameter = new AlarmConditionAIParameter(),
  483. DelayTimer = new Stopwatch(),
  484. },
  485. new AlarmConditionChecker()
  486. {
  487. Heater = HeaterCL,
  488. ToleranceCheckerWarning = new ToleranceChecker(),
  489. ToleranceCheckerAlarm = new ToleranceChecker(),
  490. Parameter = new AlarmConditionAIParameter(),
  491. DelayTimer = new Stopwatch(),
  492. },
  493. new AlarmConditionChecker()
  494. {
  495. Heater = HeaterL,
  496. ToleranceCheckerWarning = new ToleranceChecker(),
  497. ToleranceCheckerAlarm = new ToleranceChecker(),
  498. Parameter = new AlarmConditionAIParameter(),
  499. DelayTimer = new Stopwatch(),
  500. },
  501. };
  502. }
  503. public void InitAlarmCondition(string fileName)
  504. {
  505. if (string.IsNullOrEmpty(fileName))
  506. {
  507. //EV.PostWarningLog(ModuleName.PM1.ToString(), $"Heater temperature correct file is empty");
  508. return;
  509. }
  510. _currentAlarmConditionFileName = fileName;
  511. //_currentAlarmConditionIndex = index;
  512. var content = ParameterFileManager.Instance.LoadParameter("Parameter\\AlarmCondition", fileName, false);
  513. if (string.IsNullOrEmpty(content))
  514. {
  515. //EV.PostWarningLog(ModuleName.PM1.ToString(), $"{fileNameAndPath} heater temperature correct file is empty");
  516. return;
  517. }
  518. var doc = new XmlDocument();
  519. doc.LoadXml(content);
  520. XmlNodeList nodeSteps = doc.SelectNodes($"Aitex/TableParameterData/Module[@Name='']/Step");
  521. if (nodeSteps == null)
  522. nodeSteps = doc.SelectNodes($"Aitex/TableParameterData/Step");
  523. if (nodeSteps == null)
  524. {
  525. EV.PostWarningLog(ModuleName.PM1.ToString(), $"Invalid alarm condition file {fileName}");
  526. return;
  527. }
  528. SC.SetItemValueFromString("PM1.AlarmCondition", fileName);
  529. _alarmConditionDic = new Dictionary<int, AlarmConditionTableParameter>();
  530. for (int i = 0; i < nodeSteps.Count; i++)
  531. {
  532. var step = nodeSteps[i];
  533. XmlElement stepNode = step as XmlElement;
  534. int tableIndex = i + 1;
  535. AlarmConditionTableParameter table = new AlarmConditionTableParameter();
  536. List<AlarmConditionDIParameter> valveInterlockParameterLst = null;
  537. List<AlarmConditionDIParameter> clnParameterLst = null;
  538. foreach (XmlAttribute att in stepNode.Attributes)
  539. {
  540. switch (att.Name)
  541. {
  542. case "StepNo":
  543. int.TryParse(att.Value, out int no);
  544. table.No = no;
  545. break;
  546. case "Name":
  547. table.Name = att.Value;
  548. break;
  549. case "TempHeater":
  550. table.HeaterParameterLst = InitAlarmConditionItem(att.Value);
  551. break;
  552. case "TempBoat":
  553. break;
  554. case "FlowDeviation":
  555. table.MFCParameterLst = InitAlarmConditionItem(att.Value);
  556. break;
  557. case "Press":
  558. table.APCParameterLst = InitAlarmConditionItem(att.Value);
  559. break;
  560. case "AUX":
  561. table.AUXParameterLst = InitAlarmConditionItem(att.Value);
  562. break;
  563. case "HWILK":
  564. table.InterlockParameterLst = InitAlarmConditionDIItem(att.Value);
  565. break;
  566. case "ValveILK":
  567. valveInterlockParameterLst = InitAlarmConditionDIItem(att.Value);
  568. break;
  569. case "TempController":
  570. break;
  571. case "APCController":
  572. break;
  573. case "TransferError":
  574. break;
  575. case "SerialLineDown":
  576. break;
  577. case "LanLineDown":
  578. break;
  579. case "DeviceNetLineDown":
  580. break;
  581. case "Sensor":
  582. break;
  583. case "CLNAlarmList":
  584. clnParameterLst = InitAlarmConditionDIItem(att.Value);
  585. break;
  586. }
  587. }
  588. if (table.InterlockParameterLst != null && valveInterlockParameterLst != null)
  589. table.InterlockParameterLst.AddRange(valveInterlockParameterLst);
  590. if (table.InterlockParameterLst != null && clnParameterLst != null)
  591. table.InterlockParameterLst.AddRange(clnParameterLst);
  592. if (!_alarmConditionDic.ContainsKey(table.No))
  593. _alarmConditionDic.Add(table.No, table);
  594. _alarmConditionDic[table.No] = table;
  595. }
  596. }
  597. public void MonitorAlarmCondition()
  598. {
  599. if (_alarmConditionDic == null)
  600. return;
  601. _isAlarmConditionHasRecipeCommand = false;
  602. MonitorHeaterAlarmCondition();
  603. MonitorMFCAlarmCondition();
  604. MonitorAUXAlarmCondition();
  605. MonitorAPCAlarmCondition();
  606. MonitorInterlockAlarmCondition();
  607. }
  608. private void MonitorInterlockAlarmCondition()
  609. {
  610. if (_alarmConditionDic == null || !_alarmConditionDic.ContainsKey(_currentAlarmConditionIndex) || _alarmConditionDic[_currentAlarmConditionIndex].InterlockParameterLst == null || HWILKAlarmDic == null)
  611. return;
  612. foreach (var item in _hwILKChecker)
  613. {
  614. if (item.DIParameter == null || item.DIParameter.IsEnable == false)
  615. continue;
  616. if (!_sensors.TryGetValue(item.Name, out var sensorItem))
  617. continue;
  618. if (!HWILKAlarmDic.TryGetValue(sensorItem, out var alarmItem))
  619. continue;
  620. item.FilterCheckerAlarm.CheckInterval = 0.1;
  621. item.FilterCheckerAlarm.Monitor(sensorItem.Value);
  622. if (item.FilterCheckerAlarm.Trig)
  623. ProcessAlarmConditionErrorCommand(item.DIParameter.Command, () => alarmItem.Set(), sensorItem.Name);
  624. }
  625. }
  626. private void MonitorAPCAlarmCondition()
  627. {
  628. for (int i = 0; i < _apcChecker.Count; i++)
  629. {
  630. var checker = _apcChecker[i];
  631. if (checker.Parameter.Unit == null)
  632. continue;
  633. var warningLow = checker.Parameter.WarningLow;
  634. var warningHigh = checker.Parameter.WarningHigh;
  635. var alarmLow = checker.Parameter.AlarmLow;
  636. var alarmHigh = checker.Parameter.AlarmHigh;
  637. var unit = checker.Parameter.Unit;
  638. if (checker.Parameter.Unit.ToLower().Contains("%"))
  639. {
  640. unit = "%";
  641. //angle
  642. if (checker.Parameter.Unit.ToLower() == "%d")
  643. {
  644. //do nothing
  645. }
  646. else
  647. {
  648. warningLow = (float)checker.APC.DeviceData.PositionSetPoint * warningLow;
  649. warningHigh = (float)checker.APC.DeviceData.PositionSetPoint * warningHigh;
  650. alarmLow = (float)checker.APC.DeviceData.PositionSetPoint * alarmLow;
  651. alarmHigh = (float)checker.APC.DeviceData.PositionSetPoint * alarmHigh;
  652. }
  653. if (checker.Parameter.IsWarningEnable && checker.Parameter.WarningTime > 0 && checker.DelayTimer.IsRunning && checker.DelayTimer.ElapsedMilliseconds >= checker.Parameter.WarningDelayDetectTimeS * 1000)
  654. checker.ToleranceCheckerWarning.Monitor(checker.APC.DeviceData.PositionFeedback,
  655. checker.APC.DeviceData.PositionSetPoint - warningLow, checker.APC.DeviceData.PositionSetPoint + warningHigh, checker.Parameter.WarningTime);
  656. if (checker.Parameter.IsAlarmEnable && checker.Parameter.AlarmTime > 0 && checker.DelayTimer.IsRunning && checker.DelayTimer.ElapsedMilliseconds >= checker.Parameter.AlarmDelayDetectTimeS * 1000)
  657. checker.ToleranceCheckerAlarm.Monitor(checker.APC.DeviceData.PositionFeedback,
  658. checker.APC.DeviceData.PositionSetPoint - alarmLow, checker.APC.DeviceData.PositionSetPoint + alarmHigh, checker.Parameter.AlarmTime);
  659. if (checker.ToleranceCheckerAlarm.Trig || checker.ToleranceCheckerWarning.Trig)
  660. {
  661. var range = "";
  662. var time = "";
  663. var command = checker.Parameter.AlarmCommand;
  664. if (checker.ToleranceCheckerAlarm.Trig)
  665. {
  666. range = $"({checker.APC.DeviceData.PositionSetPoint - alarmLow},{checker.APC.DeviceData.PositionSetPoint + alarmHigh})";
  667. time = $"{checker.Parameter.AlarmTime:F1}";
  668. checker.APC.APCAngleToleranceAlarm.Set($"APC angle out of range {range} {unit} in {time} seconds");
  669. command = checker.Parameter.AlarmCommand;
  670. }
  671. else if (checker.ToleranceCheckerWarning.Trig)
  672. {
  673. range = $"({checker.APC.DeviceData.PositionSetPoint - warningLow},{checker.APC.DeviceData.PositionSetPoint + warningHigh})";
  674. time = $"{checker.Parameter.WarningTime:F1}";
  675. checker.APC.APCAngleToleranceWarning.Set($"APC angle out of range {range} {unit} in {time} seconds");
  676. command = checker.Parameter.WarningCommand;
  677. }
  678. ProcessAlarmConditionErrorCommand(command);
  679. }
  680. }
  681. else
  682. {
  683. warningLow = (float)checker.APC.DeviceData.PressureSetPoint * warningLow;
  684. warningHigh = (float)checker.APC.DeviceData.PressureSetPoint * warningHigh;
  685. alarmLow = (float)checker.APC.DeviceData.PressureSetPoint * alarmLow;
  686. alarmHigh = (float)checker.APC.DeviceData.PressureSetPoint * alarmHigh;
  687. var alarmToleranceAlarm = checker.APC.APCPressure2ToleranceAlarm;
  688. var alarmToleranceWarning = checker.APC.APCPressure2ToleranceWarning;
  689. var pressureFeedback = checker.APC.DeviceData.Pressure2Feedback;
  690. if (i == 0)
  691. {
  692. alarmToleranceAlarm = checker.APC.APCPressure1ToleranceAlarm;
  693. alarmToleranceWarning = checker.APC.APCPressure1ToleranceWarning;
  694. pressureFeedback = checker.APC.DeviceData.Pressure1Feedback;
  695. }
  696. if (checker.Parameter.IsWarningEnable && checker.Parameter.WarningTime > 0)
  697. checker.ToleranceCheckerWarning.Monitor(pressureFeedback,
  698. checker.APC.DeviceData.PressureSetPoint - warningLow, checker.APC.DeviceData.PressureSetPoint + warningHigh, checker.Parameter.WarningTime);
  699. if (checker.Parameter.IsAlarmEnable && checker.Parameter.AlarmTime > 0)
  700. checker.ToleranceCheckerAlarm.Monitor(pressureFeedback,
  701. checker.APC.DeviceData.PressureSetPoint - alarmLow, checker.APC.DeviceData.PressureSetPoint + alarmHigh, checker.Parameter.AlarmTime);
  702. if (checker.ToleranceCheckerAlarm.Trig || checker.ToleranceCheckerWarning.Trig)
  703. {
  704. var range = "";
  705. var time = "";
  706. var command = checker.Parameter.AlarmCommand;
  707. if (checker.ToleranceCheckerAlarm.Trig)
  708. {
  709. range = $"({checker.APC.DeviceData.PressureSetPoint - alarmLow},{checker.APC.DeviceData.PressureSetPoint + alarmHigh})";
  710. time = $"{checker.Parameter.AlarmTime:F1}";
  711. alarmToleranceAlarm.Set($"APC Press{i + 1} out of range {range} {unit} in {time} seconds");
  712. command = checker.Parameter.AlarmCommand;
  713. }
  714. else if (checker.ToleranceCheckerWarning.Trig)
  715. {
  716. range = $"({checker.APC.DeviceData.PressureSetPoint - warningLow},{checker.APC.DeviceData.PressureSetPoint + warningHigh})";
  717. time = $"{checker.Parameter.WarningTime:F1}";
  718. alarmToleranceWarning.Set($"APC Press{i + 1} out of range {range} {unit} in {time} seconds");
  719. command = checker.Parameter.WarningCommand;
  720. }
  721. ProcessAlarmConditionErrorCommand(command);
  722. }
  723. }
  724. }
  725. }
  726. private void MonitorAUXAlarmCondition()
  727. {
  728. if (SC.ContainsItem("Minics.EnableMinics") && SC.GetValue<bool>("Minics.EnableMinics"))
  729. { return; }
  730. for (int i = 0; i < _auxChecker.Count; i++)
  731. {
  732. var checker = _auxChecker[i];
  733. if (checker.Parameter.Unit == null)
  734. continue;
  735. var warningLow = checker.Parameter.WarningLow;
  736. var warningHigh = checker.Parameter.WarningHigh;
  737. var alarmLow = checker.Parameter.AlarmLow;
  738. var alarmHigh = checker.Parameter.AlarmHigh;
  739. var unit = "";
  740. var setpoint = 0.0f;
  741. var feedback = 0.0f;
  742. var display = "";
  743. if (_auxDic != null && _auxDic.ContainsKey(_currentAuxTable))
  744. {
  745. foreach (var item in _auxDic[_currentAuxTable])
  746. {
  747. if (item == null || checker.AUXIOName != item.IOName)
  748. continue;
  749. setpoint = (float)item.SetPointConfig.DoubleValue;
  750. unit = item.Unit;
  751. display = item.DisplayNameConfig.StringValue;
  752. feedback = IO.AI[$"{Module}.{item.IOName}"] != null ? IO.AI[$"{Module}.{item.IOName}"].FloatValue : 0;
  753. break;
  754. }
  755. }
  756. if (checker.Parameter.Unit.ToLower() == "%sv")
  757. {
  758. warningLow = (float)setpoint * warningLow / 100.0f;
  759. warningHigh = (float)setpoint * warningHigh / 100.0f;
  760. alarmLow = (float)setpoint * alarmLow / 100.0f;
  761. alarmHigh = (float)setpoint * alarmHigh / 100.0f;
  762. }
  763. else if (checker.Parameter.Unit.ToLower() == "%fs")
  764. {
  765. //后续改为scale
  766. warningLow = (float)setpoint * warningLow / 100.0f;
  767. warningHigh = (float)setpoint * warningHigh / 100.0f;
  768. alarmLow = (float)setpoint * alarmLow / 100.0f;
  769. alarmHigh = (float)setpoint * alarmHigh / 100.0f;
  770. }
  771. if (checker.Parameter.IsWarningEnable && checker.Parameter.WarningTime > 0 && checker.DelayTimer.IsRunning && checker.DelayTimer.ElapsedMilliseconds >= checker.Parameter.WarningDelayDetectTimeS * 1000)
  772. checker.ToleranceCheckerWarning.Monitor(feedback,
  773. setpoint - warningLow, setpoint + warningHigh, checker.Parameter.WarningTime);
  774. if (checker.Parameter.IsAlarmEnable && checker.Parameter.AlarmTime > 0 && checker.DelayTimer.IsRunning && checker.DelayTimer.ElapsedMilliseconds >= checker.Parameter.AlarmDelayDetectTimeS * 1000)
  775. checker.ToleranceCheckerAlarm.Monitor(feedback,
  776. setpoint - alarmLow, setpoint + alarmHigh, checker.Parameter.AlarmTime);
  777. if (checker.ToleranceCheckerAlarm.Trig || checker.ToleranceCheckerWarning.Trig)
  778. {
  779. var range = "";
  780. var time = "";
  781. var ret = AUXAlarmDic.TryGetValue(checker.AUXIndex, out var AUXAlarm);
  782. if (ret)
  783. {
  784. var command = checker.Parameter.AlarmCommand;
  785. if (checker.ToleranceCheckerAlarm.Trig)
  786. {
  787. range = $"({(setpoint - alarmLow).ToString("f3")},{(setpoint + alarmHigh).ToString("f3")})";
  788. time = $"{checker.Parameter.AlarmTime:F1}";
  789. AUXAlarm.Item2.Set($"AUX {display} value out of range {range} {unit} in {time} seconds");
  790. command = checker.Parameter.AlarmCommand;
  791. }
  792. else if (checker.ToleranceCheckerWarning.Trig)
  793. {
  794. range = $"({(setpoint - warningLow).ToString("f3")},{(setpoint + warningHigh).ToString("f3")})";
  795. time = $"{checker.Parameter.WarningTime:F1}";
  796. AUXAlarm.Item1.Set($"AUX {display} value out of range {range} {unit} in {time} seconds");
  797. command = checker.Parameter.WarningCommand;
  798. }
  799. ProcessAlarmConditionErrorCommand(command);
  800. }
  801. }
  802. }
  803. }
  804. private void MonitorMFCAlarmCondition()
  805. {
  806. for (int i = 0; i < _mfcChecker.Count; i++)
  807. {
  808. var checker = _mfcChecker[i];
  809. if (checker.Parameter.Unit == null)
  810. continue;
  811. var warningLow = checker.Parameter.WarningLow;
  812. var warningHigh = checker.Parameter.WarningHigh;
  813. var alarmLow = checker.Parameter.AlarmLow;
  814. var alarmHigh = checker.Parameter.AlarmHigh;
  815. var unit = checker.MFC.Unit;
  816. if (checker.Parameter.Unit.ToLower() == "%sv")
  817. {
  818. warningLow = (float)checker.MFC.SetPoint * warningLow / 100.0f;
  819. warningHigh = (float)checker.MFC.SetPoint * warningHigh / 100.0f;
  820. alarmLow = (float)checker.MFC.SetPoint * alarmLow / 100.0f;
  821. alarmHigh = (float)checker.MFC.SetPoint * alarmHigh / 100.0f;
  822. }
  823. else if (checker.Parameter.Unit.ToLower() == "%fs")
  824. {
  825. warningLow = (float)checker.MFC.Scale * warningLow / 100.0f;
  826. warningHigh = (float)checker.MFC.Scale * warningHigh / 100.0f;
  827. alarmLow = (float)checker.MFC.Scale * alarmLow / 100.0f;
  828. alarmHigh = (float)checker.MFC.Scale * alarmHigh / 100.0f;
  829. }
  830. if (checker.Parameter.IsWarningEnable && checker.Parameter.WarningTime > 0 && checker.DelayTimer.IsRunning && checker.DelayTimer.ElapsedMilliseconds >= checker.Parameter.WarningDelayDetectTimeS * 1000)
  831. checker.ToleranceCheckerWarning.Monitor(checker.MFC.FeedBack,
  832. checker.MFC.SetPoint - warningLow, checker.MFC.SetPoint + warningHigh, checker.Parameter.WarningTime);
  833. if (checker.Parameter.IsAlarmEnable && checker.Parameter.AlarmTime > 0 && checker.DelayTimer.IsRunning && checker.DelayTimer.ElapsedMilliseconds >= checker.Parameter.AlarmDelayDetectTimeS * 1000)
  834. checker.ToleranceCheckerAlarm.Monitor(checker.MFC.FeedBack,
  835. checker.MFC.SetPoint - alarmLow, checker.MFC.SetPoint + alarmHigh, checker.Parameter.AlarmTime);
  836. if (checker.ToleranceCheckerAlarm.Trig || checker.ToleranceCheckerWarning.Trig)
  837. {
  838. var range = "";
  839. var time = "";
  840. var command = checker.Parameter.AlarmCommand;
  841. if (checker.ToleranceCheckerAlarm.Trig)
  842. {
  843. range = $"({(checker.MFC.SetPoint - alarmLow).ToString("f3")},{(checker.MFC.SetPoint + alarmHigh).ToString("f3")})";
  844. time = $"{checker.Parameter.AlarmTime:F1}";
  845. checker.MFC.AlarmToleranceAlarm.Set($"{Display} flow out of range {range} {unit} in {time} seconds");
  846. command = checker.Parameter.AlarmCommand;
  847. }
  848. else if (checker.ToleranceCheckerWarning.Trig)
  849. {
  850. range = $"({(checker.MFC.SetPoint - warningLow).ToString("f3")},{(checker.MFC.SetPoint + warningHigh).ToString("f3")})";
  851. time = $"{checker.Parameter.WarningTime:F1}";
  852. checker.MFC.AlarmToleranceWarning.Set($"{Display} flow out of range {range} {unit} in {time} seconds");
  853. command = checker.Parameter.WarningCommand;
  854. }
  855. ProcessAlarmConditionErrorCommand(command);
  856. }
  857. }
  858. }
  859. private void MonitorHeaterAlarmCondition()
  860. {
  861. for (int i = 0; i < _heaterChecker.Count; i++)
  862. {
  863. var checker = _heaterChecker[i];
  864. if (checker.Parameter.Unit == null)
  865. continue;
  866. if (checker.Parameter.IsWarningEnable && checker.Parameter.WarningTime > 0 && checker.DelayTimer.IsRunning && checker.DelayTimer.ElapsedMilliseconds >= checker.Parameter.WarningDelayDetectTimeS * 1000)
  867. checker.ToleranceCheckerWarning.Monitor(checker.Heater.TempFeedback,
  868. checker.Heater.TempSetPoint - checker.Parameter.WarningLow, checker.Heater.TempSetPoint + checker.Parameter.WarningHigh, checker.Parameter.WarningTime);
  869. if (checker.Parameter.IsAlarmEnable && checker.Parameter.AlarmTime > 0 && checker.DelayTimer.IsRunning && checker.DelayTimer.ElapsedMilliseconds >= checker.Parameter.AlarmDelayDetectTimeS * 1000)
  870. checker.ToleranceCheckerAlarm.Monitor(checker.Heater.TempFeedback,
  871. checker.Heater.TempSetPoint - checker.Parameter.AlarmLow, checker.Heater.TempSetPoint + checker.Parameter.AlarmHigh, checker.Parameter.AlarmTime);
  872. if (checker.ToleranceCheckerAlarm.Trig || checker.ToleranceCheckerWarning.Trig)
  873. {
  874. var range = "";
  875. var time = "";
  876. var command = checker.Parameter.AlarmCommand;
  877. if (checker.ToleranceCheckerAlarm.Trig)
  878. {
  879. range = $"({checker.Heater.TempSetPoint - checker.Parameter.AlarmLow},{checker.Heater.TempSetPoint + checker.Parameter.AlarmHigh})";
  880. time = $"{checker.Parameter.AlarmTime:F1}";
  881. checker.Heater.AlarmToleranceAlarm.Set($"{Display} temperature out of range {range} °C in {time} seconds");
  882. command = checker.Parameter.AlarmCommand;
  883. }
  884. else if (checker.ToleranceCheckerWarning.Trig)
  885. {
  886. range = $"({checker.Heater.TempSetPoint - checker.Parameter.WarningLow},{checker.Heater.TempSetPoint + checker.Parameter.WarningHigh})";
  887. time = $"{checker.Parameter.WarningTime:F1}";
  888. checker.Heater.AlarmToleranceWarning.Set($"{Display} temperature out of range {range} °C in {time} seconds");
  889. command = checker.Parameter.WarningCommand;
  890. }
  891. ProcessAlarmConditionErrorCommand(command);
  892. }
  893. }
  894. }
  895. private void ProcessAlarmConditionErrorCommand(string command, Action eventHandler = null, string sensorName = "")
  896. {
  897. var recipe = "";
  898. var recipeType = "";
  899. var recipeTable = "";
  900. switch (command)
  901. {
  902. case "Reset":
  903. if (_isAlarmConditionHasRecipeCommand)
  904. break;
  905. _isAlarmConditionHasRecipeCommand = true;
  906. recipe = SC.GetStringValue("System.Recipe.Reset Recipe");
  907. recipeType = "Reset";
  908. RecipeExecEntryEnumValue = RecipeExecEntryEnum.AlarmConditonTrigger;
  909. CheckToPostMessage((int)MSG.RunOtherRecipe, recipe, recipeType);
  910. var log = $"Alarm condition: command={command} recipe={recipe}";
  911. if (!string.IsNullOrEmpty(sensorName))
  912. log = $"{log} ,sensorName={sensorName}";
  913. LOG.Write(log);
  914. break;
  915. case "End":
  916. if (_isAlarmConditionHasRecipeCommand)
  917. break;
  918. _isAlarmConditionHasRecipeCommand = true;
  919. if (IsProcessing)
  920. {
  921. //因为要跳到执行最后一步,所以stepNumber需要减一
  922. _processRoutine.JumpCurrentRecipeStep(RecipeRunningInfo.RecipeStepList.Count - 1, RecipeRunningInfo.RecipeStepList[RecipeRunningInfo.RecipeStepList.Count - 1].StepName);
  923. }
  924. else
  925. {
  926. if (!RecipeParser.Parse(SC.GetStringValue("PM1.ProcessRecipe"), Module, out var recipeHead, out var recipeSteps, out var reason, "Process"))
  927. {
  928. PreprocessStartFailedWarning.Set($"Load process recipe {SC.GetStringValue("PM1.ProcessRecipe")} failed, {reason}");
  929. return;
  930. }
  931. RecipeRunningInfo.MainRecipeName = SC.GetStringValue("PM1.ProcessRecipe");
  932. RecipeRunningInfo.Head = recipeHead;
  933. RecipeRunningInfo.RecipeStepList = recipeSteps;
  934. CheckToPostMessage((int)MSG.AlarmConditionJumpStep, RecipeRunningInfo.RecipeStepList.Count - 1);
  935. }
  936. log = $"Alarm condition: command={command} step name={RecipeRunningInfo.RecipeStepList[RecipeRunningInfo.RecipeStepList.Count - 1].StepName}";
  937. if (!string.IsNullOrEmpty(sensorName))
  938. log = $"{log} ,sensorName={sensorName}";
  939. LOG.Write(log);
  940. break;
  941. case "Hold":
  942. if (_isAlarmConditionHasRecipeCommand)
  943. break;
  944. _isAlarmConditionHasRecipeCommand = true;
  945. _processRoutine.PauseRecipe();
  946. log = $"Alarm condition: command={command}";
  947. if (!string.IsNullOrEmpty(sensorName))
  948. log = $"{log} ,sensorName={sensorName}";
  949. LOG.Write(log);
  950. break;
  951. case "Monitor"://蜂鸣器不需要响
  952. eventHandler?.Invoke();
  953. DEVICE.GetDevice<SignalTowerBase>("System.SignalTower")?.SwitchOffBuzzer(true);
  954. Singleton<EquipmentManager>.Instance.IsAlarmConditionBuzzerOn = false;
  955. log = $"Alarm condition: command={command}";
  956. if (!string.IsNullOrEmpty(sensorName))
  957. log = $"{log} ,sensorName={sensorName}";
  958. LOG.Write(log);
  959. break;
  960. case "Buzzer"://蜂鸣器需要响且报警
  961. eventHandler?.Invoke();
  962. DEVICE.GetDevice<SignalTowerBase>("System.SignalTower")?.SwitchOffBuzzer(false);
  963. Singleton<EquipmentManager>.Instance.IsAlarmConditionBuzzerOn = true;
  964. log = $"Alarm condition: command={command}";
  965. if (!string.IsNullOrEmpty(sensorName))
  966. log = $"{log} ,sensorName={sensorName}";
  967. LOG.Write(log);
  968. break;
  969. default:
  970. if (_isAlarmConditionHasRecipeCommand)
  971. break;
  972. _isAlarmConditionHasRecipeCommand = true;
  973. if (command.StartsWith("JUMP"))
  974. {
  975. //Jump step
  976. //Jump 1:
  977. var stepName = command.Replace("JUMP ", "");
  978. if (IsProcessing)
  979. {
  980. var jumpStepNumber = RecipeRunningInfo.RecipeStepList.FindIndex(x => x.StepName == stepName);
  981. if (jumpStepNumber > 0)
  982. {
  983. _processRoutine.JumpCurrentRecipeStep(jumpStepNumber, stepName);
  984. }
  985. }
  986. else
  987. {
  988. if (!RecipeParser.Parse(SC.GetStringValue("PM1.ProcessRecipe"), Module, out var recipeHead, out var recipeSteps, out var reason, "Process"))
  989. {
  990. PreprocessStartFailedWarning.Set($"Load process recipe {SC.GetStringValue("PM1.ProcessRecipe")} failed, {reason}");
  991. return;
  992. }
  993. RecipeRunningInfo.MainRecipeName = SC.GetStringValue("PM1.ProcessRecipe");
  994. RecipeRunningInfo.Head = recipeHead;
  995. RecipeRunningInfo.RecipeStepList = recipeSteps;
  996. var jumpStepNumber = RecipeRunningInfo.RecipeStepList.FindIndex(x => x.StepName == stepName);
  997. if (jumpStepNumber > 0)
  998. {
  999. CheckToPostMessage((int)MSG.AlarmConditionJumpStep, jumpStepNumber);
  1000. }
  1001. }
  1002. LOG.Write($"Alarm condition: command={command} step name={stepName}");
  1003. }
  1004. else if (command.StartsWith("CALL"))
  1005. {
  1006. //call Alarm recipe
  1007. //Call 1:
  1008. var paras = command.Split(':');
  1009. if (paras.Length > 0)
  1010. {
  1011. RecipeExecEntryEnumValue = RecipeExecEntryEnum.AlarmConditonTrigger;
  1012. recipe = RecipeRunningInfo.Head.AlarmRecipe;
  1013. recipeType = "Alarm";
  1014. recipeTable = paras[0].Replace("CALL", "").Replace(" ", "").Replace(":", "").Replace(":", "");
  1015. CheckToPostMessage((int)MSG.RunOtherRecipe, recipe, recipeType, recipeTable);
  1016. LOG.Write($"Alarm condition: command={command} recipe={recipe}");
  1017. }
  1018. }
  1019. else if (command.StartsWith("ABORT"))
  1020. {
  1021. //call Abort recipe
  1022. //Abort 1:
  1023. var paras = command.Split(':');
  1024. if (paras.Length > 0)
  1025. {
  1026. RecipeExecEntryEnumValue = RecipeExecEntryEnum.AlarmConditonTrigger;
  1027. recipe = RecipeRunningInfo.Head.AbortRecipe;
  1028. recipeType = "Abort";
  1029. recipeTable = paras[0].Replace("ABORT", "").Replace(" ", "").Replace(":", "").Replace(":", "");
  1030. CheckToPostMessage((int)MSG.RunOtherRecipe, recipe, recipeType, recipeTable);
  1031. LOG.Write($"Alarm condition: command={command} recipe={recipe}");
  1032. }
  1033. }
  1034. break;
  1035. }
  1036. }
  1037. private List<AlarmConditionAIParameter> InitAlarmConditionItem(string content)
  1038. {
  1039. List<AlarmConditionAIParameter> items = new List<AlarmConditionAIParameter>();
  1040. if (string.IsNullOrEmpty(content))
  1041. return items;
  1042. var zoneParas = content.Split('|');
  1043. foreach (var zonePara in zoneParas)
  1044. {
  1045. //U;Alert,True,0,0,℃,5,Monitor;Alarm,True,0,0,℃,6,Buzzer
  1046. //1;C1-N2-1;Alert,True,0,0,%fs,5,Buzzer;Alarm,True,0,0,%fs,6,Buzzer
  1047. //1;MS1;Alert,True,0,0,%fs,5,Monitor;Alarm,True,0,0,%fs,6,Monitor
  1048. AlarmConditionAIParameter item = new AlarmConditionAIParameter();
  1049. var array = zonePara.Split(';');
  1050. if (array.Length > 2)
  1051. {
  1052. item.Name = array[0];
  1053. var warningParas = array[array.Length - 2].Split(',');
  1054. var alarmParas = array[array.Length - 1].Split(',');
  1055. if (warningParas.Length > 6)
  1056. {
  1057. bool.TryParse(warningParas[1], out bool isEnable);
  1058. float.TryParse(warningParas[2], out float high);
  1059. float.TryParse(warningParas[3], out float low);
  1060. item.Unit = warningParas[4];
  1061. float.TryParse(warningParas[5], out float time);
  1062. item.WarningCommand = warningParas[6];
  1063. item.IsWarningEnable = isEnable;
  1064. item.WarningHigh = high;
  1065. item.WarningLow = low;
  1066. item.WarningTime = time;
  1067. }
  1068. if (warningParas.Length > 7)
  1069. {
  1070. float.TryParse(warningParas[7], out float time);
  1071. item.WarningDelayDetectTimeS = time;
  1072. }
  1073. if (alarmParas.Length > 6)
  1074. {
  1075. bool.TryParse(alarmParas[1], out bool isEnable);
  1076. float.TryParse(alarmParas[2], out float high);
  1077. float.TryParse(alarmParas[3], out float low);
  1078. item.Unit = alarmParas[4];
  1079. float.TryParse(alarmParas[5], out float time);
  1080. item.AlarmCommand = alarmParas[6];
  1081. item.IsAlarmEnable = isEnable;
  1082. item.AlarmHigh = high;
  1083. item.AlarmLow = low;
  1084. item.AlarmTime = time;
  1085. }
  1086. if (alarmParas.Length > 7)
  1087. {
  1088. float.TryParse(alarmParas[7], out float time);
  1089. item.AlarmDelayDetectTimeS = time;
  1090. }
  1091. }
  1092. items.Add(item);
  1093. }
  1094. return items;
  1095. }
  1096. private List<AlarmConditionDIParameter> InitAlarmConditionDIItem(string content)
  1097. {
  1098. List<AlarmConditionDIParameter> items = new List<AlarmConditionDIParameter>();
  1099. if (string.IsNullOrEmpty(content))
  1100. return items;
  1101. var zoneParas = content.Split('|');
  1102. foreach (var zonePara in zoneParas)
  1103. {
  1104. //1,Air/N2-7 Pressure Too Low,Alert,False,Buzzer|2,N2-1 Pressure Too Low,Alert,False,End
  1105. AlarmConditionDIParameter item = new AlarmConditionDIParameter();
  1106. var array = zonePara.Split(',');
  1107. if (array.Length > 4)
  1108. {
  1109. item.Name = array[1];
  1110. item.IsAlarm = array[2].ToLower() == "alarm";
  1111. bool.TryParse(array[3], out bool isEnable);
  1112. item.IsEnable = isEnable;
  1113. item.Command = array[4];
  1114. }
  1115. items.Add(item);
  1116. }
  1117. return items;
  1118. }
  1119. class AlarmConditionChecker
  1120. {
  1121. public FurnaceRT.Devices.IoHeater Heater { get; set; }
  1122. public FurnaceRT.Devices.IoAPC APC { get; set; }
  1123. public FurnaceRT.Equipments.PMs.Devices.IoMFC MFC { get; set; }
  1124. public string AUXIOName { get; set; }
  1125. public int AUXIndex { get; set; }
  1126. public string Name { get; set; }
  1127. public ToleranceChecker ToleranceCheckerWarning { get; set; }
  1128. public ToleranceChecker ToleranceCheckerAlarm { get; set; }
  1129. public AlarmConditionAIParameter Parameter { get; set; }
  1130. public AlarmConditionDIParameter DIParameter { get; set; }
  1131. public Stopwatch DelayTimer { get; set; }//N秒过后才检测
  1132. public FilterChecker FilterCheckerAlarm { get; set; }
  1133. }
  1134. class AlarmConditionTableParameter
  1135. {
  1136. public int No { get; set; }
  1137. public string Name { get; set; }
  1138. public List<AlarmConditionAIParameter> HeaterParameterLst { get; set; }
  1139. public List<AlarmConditionAIParameter> MFCParameterLst { get; set; }
  1140. public List<AlarmConditionAIParameter> APCParameterLst { get; set; }
  1141. public List<AlarmConditionAIParameter> AUXParameterLst { get; set; }
  1142. public List<AlarmConditionDIParameter> InterlockParameterLst { get; set; }
  1143. }
  1144. class AlarmConditionAIParameter
  1145. {
  1146. //类似AI的
  1147. public string Name { get; set; }
  1148. public string Unit { get; set; }
  1149. public string DataPoll { get; set; }
  1150. public float WarningHigh { get; set; }
  1151. public float WarningLow { get; set; }
  1152. public float WarningTime { get; set; }
  1153. public string WarningCommand { get; set; }
  1154. public bool IsWarningEnable { get; set; }
  1155. public float AlarmHigh { get; set; }
  1156. public float AlarmLow { get; set; }
  1157. public float AlarmTime { get; set; }
  1158. public string AlarmCommand { get; set; }
  1159. public bool IsAlarmEnable { get; set; }
  1160. public float WarningDelayDetectTimeS { get; set; } = 0;//N秒过后才检测
  1161. public float AlarmDelayDetectTimeS { get; set; } = 0;//N秒过后才检测
  1162. public AlarmConditionAIParameter Clone(AlarmConditionAIParameter source)
  1163. {
  1164. AlarmConditionAIParameter clone = new AlarmConditionAIParameter();
  1165. clone.Name = source.Name;
  1166. clone.Unit = source.Unit;
  1167. clone.DataPoll = source.DataPoll;
  1168. clone.WarningHigh = source.WarningHigh;
  1169. clone.WarningLow = source.WarningLow;
  1170. clone.WarningTime = source.WarningTime;
  1171. clone.WarningCommand = source.WarningCommand;
  1172. clone.IsWarningEnable = source.IsWarningEnable;
  1173. clone.AlarmHigh = source.AlarmHigh;
  1174. clone.AlarmLow = source.AlarmLow;
  1175. clone.AlarmTime = source.AlarmTime;
  1176. clone.AlarmCommand = source.AlarmCommand;
  1177. clone.IsAlarmEnable = source.IsAlarmEnable;
  1178. return clone;
  1179. }
  1180. }
  1181. class AlarmConditionDIParameter
  1182. {
  1183. //类似DI的
  1184. public string Name { get; set; }
  1185. public string DataPoll { get; set; }
  1186. public bool IsAlarm { get; set; }
  1187. public bool IsEnable { get; set; }
  1188. public string Command { get; set; }
  1189. }
  1190. class AlarmConditionBoatParameter
  1191. {
  1192. //Boat load,unload温度判断
  1193. public string Name { get; set; }
  1194. public string DataPoll { get; set; }
  1195. public bool IsAlarm { get; set; }
  1196. public bool IsEnable { get; set; }
  1197. public float AlarmHighLimit { get; set; }
  1198. }
  1199. }
  1200. }