SimulatorSystem.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. using System;
  2. using System.Collections.Generic;
  3. using Aitex.Core.RT.DataCenter;
  4. using Aitex.Core.RT.IOCore;
  5. using Aitex.Core.RT.Log;
  6. using Aitex.Core.Util;
  7. using Aitex.Core.WCF;
  8. using EfemDualSimulator.Devices;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.Simulator.Core.Driver;
  11. namespace EfemDualSimulator.Instances
  12. {
  13. public class SimulatorSystem : Singleton<SimulatorSystem>
  14. {
  15. private PeriodicJob _thread;
  16. private Random _rd = new Random();
  17. private RD_TRIG _trigATM = new RD_TRIG();
  18. private RD_TRIG _trigVAC = new RD_TRIG();
  19. private readonly float ATM_THRESHOLD = 750000;
  20. private readonly float ATM_PRESSURE = 760000;
  21. private readonly uint VAC_SW_PRESSURE = 9500;
  22. private readonly uint PROCESS_GAUGE = 10000;
  23. private Dictionary<ModuleName, DeviceSimulator> _MockDevices = new Dictionary<ModuleName, DeviceSimulator>();
  24. public SimulatorSystem()
  25. {
  26. //_MockDevices.Add(ModuleName.PMB, new SkyPumpMock());
  27. //_MockDevices.Add(ModuleName.PMB, new AdTecGeneratorMock());
  28. //_MockDevices.Add(ModuleName.PMB, new AdTecMatchMock());
  29. // TODO
  30. }
  31. ~SimulatorSystem()
  32. {
  33. _thread?.Stop();
  34. }
  35. public void Initialize()
  36. {
  37. SetDefaultValue(ModuleName.PMA);
  38. SetDefaultValue(ModuleName.PMB);
  39. Singleton<DataManager>.Instance.Initialize(false);
  40. WcfServiceManager.Instance.Initialize(new Type[] { typeof(SimulatorPlc0) });
  41. WcfServiceManager.Instance.Initialize(new Type[] { typeof(SimulatorPlc1) });
  42. WcfServiceManager.Instance.Initialize(new Type[] { typeof(SimulatorPlc2) });
  43. _thread = new PeriodicJob(500, OnMonitor, nameof(SimulatorSystem), true);
  44. }
  45. private void SetDefaultValue(ModuleName mod)
  46. {
  47. // TM
  48. IO.DI[$"System.DI_EFEMRBNotExtendBFA"].Value = true;
  49. IO.DI[$"System.DI_EFEMRBNotExtendBFB"].Value = true;
  50. IO.DI[$"System.DI_TMRBNotExtendBFA"].Value = true;
  51. IO.DI[$"System.DI_TMRBNotExtendBFB"].Value = true;
  52. IO.DI[$"System.DI_TMPowerOn"].Value = true;
  53. IO.DI[$"System.DI_TMSideDoorClosed"].Value = true;
  54. IO.DI[$"System.DI_TMInSafety"].Value = true;
  55. IO.DI[$"System.DI_TMBufferOTSW"].Value = true;
  56. IO.DI[$"System.DI_WaterFlowSW"].Value = true;
  57. IO.DI[$"System.DI_WaterLeakSW"].Value = true;
  58. IO.DI[$"System.DI_TMFFUNormal"].Value = true;
  59. IO.DI[$"System.DI_EFEMSidePlanClosed"].Value = true;
  60. IO.DI[$"System.DI_CDAPressureSW"].Value = true;
  61. IO.DI[$"System.DI_VaccumPressureSW"].Value = true;
  62. IO.DI[$"System.DI_Buffer_ASmallWaferProtrusion"].Value = false;
  63. IO.DI[$"System.DI_Buffer_ABigWaferProtrusion"].Value = false;
  64. IO.DI[$"System.DI_Buffer_BSmallWaferProtrusion"].Value = false;
  65. IO.DI[$"System.DI_Buffer_BBigWaferProtrusion"].Value = false;
  66. IO.DI[$"System.DI_INONormal"].Value = true;
  67. IO.DI[$"System.DI_TMRobotAlarm"].Value = true;
  68. IO.DI[$"System.DI_Buffer_ATCDeviationOutOfRange"].Value = false;
  69. IO.DI[$"System.DI_Buffer_AControlTCBrokenAlarm"].Value = false;
  70. IO.DI[$"System.DI_Buffer_AMonitorTCBrokenAlarm"].Value = false;
  71. // chamber
  72. IO.DI[$"{mod}.DI_LidClosed"].Value = true;
  73. IO.DI[$"{mod}.DI_ATMSW"].Value = true;
  74. IO.DI[$"{mod}.DI_SouceFan"].Value = true;
  75. IO.DI[$"{mod}.DI_1_CoolingWaterFlowSW"].Value = true;
  76. IO.DI[$"{mod}.DI_2_CoolingWaterFlowSW"].Value = true;
  77. IO.DI[$"{mod}.DI_1_CoolantInletTCBrokenAlarm"].Value = false;
  78. IO.DI[$"{mod}.DI_1_CoolantOutletTCBrokenAlarm"].Value = false;
  79. IO.DI[$"{mod}.DI_2_CoolantInletTCBrokenAlarm"].Value = false;
  80. IO.DI[$"{mod}.DI_2_CoolantOutletTCBrokenAlarm"].Value = false;
  81. IO.DI[$"{mod}.DI_WaterLeak"].Value = true;
  82. IO.DI[$"{mod}.DI_TMRBNotExtendToPM1"].Value = true;
  83. IO.DI[$"{mod}.DI_TMRBNotExtendToPM2"].Value = true;
  84. IO.DI[$"{mod}.DI_TMInSafety"].Value = true;
  85. IO.DI[$"{mod}.DI_MFC1PressureSW"].Value = true;
  86. IO.DI[$"{mod}.DI_MFC2PressureSW"].Value = true;
  87. IO.DI[$"{mod}.DI_MFC3PressureSW"].Value = true;
  88. IO.DI[$"{mod}.DI_MFC4PressureSW"].Value = true;
  89. IO.DI[$"{mod}.DI_MFC5PressureSW"].Value = true;
  90. IO.DI[$"{mod}.DI_MFC6PressureSW"].Value = true;
  91. IO.DI[$"{mod}.DI_GeneratorHardwareInterlock"].Value = true;
  92. IO.DI[$"{mod}.DI_N2PressureSW"].Value = true;
  93. // slit door
  94. IO.DI[$"{mod}.DI_1_SlitDoorOpenPos"].Value = false;
  95. IO.DI[$"{mod}.DI_1_SlitDoorClosePos"].Value = true;
  96. IO.DI[$"{mod}.DI_2_SlitDoorOpenPos"].Value = false;
  97. IO.DI[$"{mod}.DI_2_SlitDoorClosePos"].Value = true;
  98. // lift pin
  99. IO.DI[$"{mod}.DI_1_LiftPinUp"].Value = false;
  100. IO.DI[$"{mod}.DI_1_LiftPinDown"].Value = true;
  101. IO.DI[$"{mod}.DI_2_LiftPinUp"].Value = false;
  102. IO.DI[$"{mod}.DI_2_LiftPinDown"].Value = true;
  103. //
  104. IO.DI[$"{mod}.DI_1_LEOTSW"].Value = false;
  105. IO.DI[$"{mod}.DI_2_LEOTSW"].Value = false;
  106. IO.DI[$"{mod}.DI_GB_Interlock"].Value = true;
  107. //Guide pin
  108. IO.DI[$"{mod}.DI_1_GuidePinLifterUpPos"].Value = false;
  109. IO.DI[$"{mod}.DI_1_GuidePinLifterDownPos"].Value = true;
  110. IO.DI[$"{mod}.DI_2_GuidePinLifterUpPos"].Value = false;
  111. IO.DI[$"{mod}.DI_2_GuidePinLifterDownPos"].Value = true;
  112. // pressure
  113. SetAiValue($"{mod}.AI_ForelinePressure", 5000);
  114. SetAiValue($"{mod}.AI_ChamberPressure", ATM_PRESSURE);
  115. SetAiValue($"{mod}.AI_ProcessPressure", PROCESS_GAUGE);
  116. //SetAiValue($"{mod}.AI_Throttle_Valve_State", 1);
  117. //IO.AI[$"{mod}.AI_Throttle_Valve_State"].Value = 1;
  118. IO.AI[$"{mod}.AI_ThrottleValveRealPosition"].Value = 10;
  119. // Temperature
  120. SetAiValue($"{mod}.AI_CHBControlTCTemp", 28);
  121. SetAiValue($"{mod}.AI_CHBMonitorTCTemp", 27);
  122. SetAiValue($"{mod}.AI_ForelineControlTCTemp", 28);
  123. SetAiValue($"{mod}.AI_ForelineMonitorTCTemp", 27);
  124. SetAiValue($"{mod}.AI_1_LEControlTCTemp", 28);
  125. SetAiValue($"{mod}.AI_1_LEMonitorTCTemp", 27);
  126. SetAiValue($"{mod}.AI_2_LEControlTCTemp", 28);
  127. SetAiValue($"{mod}.AI_2_LEMonitorTCTemp", 27);
  128. SetAiValue($"{mod}.AI_1_CoolantInletTemp", 28);
  129. SetAiValue($"{mod}.AI_2_CoolantInletTemp", 28);
  130. if (mod == ModuleName.PMA)
  131. {
  132. SetAiValue($"{mod}.AI_1_CoolantOutletTemp", 29);
  133. SetAiValue($"{mod}.AI_2_CoolantOutletTemp", 29);
  134. }
  135. else if (mod == ModuleName.PMB)
  136. {
  137. SetAiValue($"{mod}.AI_1_CoolantOutletTemp", 29);
  138. SetAiValue($"{mod}.AI_2_CoolantOutletTemp", 29);
  139. }
  140. // Datetime
  141. SetAiValue($"{mod}.AI_Year", DateTime.Today.Year);
  142. SetAiValue($"{mod}.AI_Month", DateTime.Today.Month);
  143. SetAiValue($"{mod}.AI_Day", DateTime.Today.Day);
  144. SetAiValue($"{mod}.AI_Time", DateTime.Today.Hour);
  145. SetAiValue($"{mod}.AI_Minute", DateTime.Today.Minute);
  146. SetAiValue($"{mod}.AI_Second", DateTime.Today.Second);
  147. }
  148. private bool OnMonitor()
  149. {
  150. try
  151. {
  152. // Buffer
  153. IO.DI[$"System.DI_Buffer_AHeatPIDATStart_Fb"].Value = IO.DO[$"System.DO_Buffer_AHeatPIDATStart"].Value;
  154. IO.DI[$"System.DI_Buffer_AHeatPIDATStop_Fb"].Value = IO.DO[$"System.DO_Buffer_AHeatPIDATStop"].Value;
  155. IO.DI[$"System.DI_WaterInletValve"].Value = IO.DO[$"System.DO_WaterInletValve"].Value;
  156. IO.DI[$"System.DI_Buffer_AHeatOn_Fb"].Value = IO.DO[$"System.DO_BufferHeatOn"].Value;
  157. if (IO.DO[$"System.DO_BufferHeatOn"].Value &&
  158. GetAiValue($"System.AI_Buffer_AControlTCTemp") < GetAoValue($"System.AO_Buffer_ATemperatureSetpoint"))
  159. {
  160. SetAiValue($"System.AI_Buffer_AControlTCTemp", GetAiValue($"System.AI_Buffer_AControlTCTemp") + _rd.Next(1, 2));
  161. SetAiValue($"System.AI_Buffer_AMonitorTCTemp", GetAiValue($"System.AI_Buffer_AMonitorTCTemp") + _rd.Next(1, 2));
  162. }
  163. else if (IO.DO[$"System.DO_BufferHeatOn"].Value &&
  164. GetAiValue($"System.AI_Buffer_AControlTCTemp") > GetAoValue($"System.AO_Buffer_ATemperatureSetpoint"))
  165. {
  166. SetAiValue($"System.AI_Buffer_AControlTCTemp", GetAiValue($"System.AI_Buffer_AControlTCTemp") - _rd.Next(1, 2));
  167. SetAiValue($"System.AI_Buffer_AMonitorTCTemp", GetAiValue($"System.AI_Buffer_AMonitorTCTemp") - _rd.Next(1, 2));
  168. }
  169. ChangeTime(ModuleName.System);
  170. // PMA
  171. MonitorPID(ModuleName.PMA);
  172. MonitorSlitDoor(ModuleName.PMA);
  173. MonitorPin(ModuleName.PMA);
  174. MonitorPressure(ModuleName.PMA);
  175. MonitorTemperature(ModuleName.PMA);
  176. MonitorGas(ModuleName.PMA);
  177. //MonitorRF(ModuleName.PMA);
  178. ChangeTime(ModuleName.PMA);
  179. // PMB
  180. MonitorPID(ModuleName.PMB);
  181. MonitorSlitDoor(ModuleName.PMB);
  182. MonitorPin(ModuleName.PMB);
  183. MonitorPressure(ModuleName.PMB);
  184. MonitorTemperature(ModuleName.PMB);
  185. MonitorGas(ModuleName.PMB);
  186. //MonitorRF(ModuleName.PMB);
  187. ChangeTime(ModuleName.PMB);
  188. }
  189. catch (Exception e)
  190. {
  191. LOG.Write(e);
  192. }
  193. return true;
  194. }
  195. private void MonitorPID(ModuleName mod)
  196. {
  197. IO.DI[$"{mod}.DI_CHBHeatPIDATStart_Fb"].Value = IO.DO[$"{mod}.DO_CHBHeatPIDATStart"].Value;
  198. IO.DI[$"{mod}.DI_CHBHeatPIDATStop_Fb"].Value = IO.DO[$"{mod}.DO_CHBHeatPIDATStop"].Value;
  199. IO.DI[$"{mod}.DI_ForelineHeatPIDATStart_Fb"].Value = IO.DO[$"{mod}.DO_ForelineHeatPIDATStart"].Value;
  200. IO.DI[$"{mod}.DI_ForelineHeatPIDATStop_Fb"].Value = IO.DO[$"{mod}.DO_ForelineHeatPIDATStop"].Value;
  201. IO.DI[$"{mod}.DI_1_LEHeatPIDATStart_Fb"].Value = IO.DO[$"{mod}.DO_1_LEHeatPIDATStart"].Value;
  202. IO.DI[$"{mod}.DI_1_LEHeatPIDATStop_Fb"].Value = IO.DO[$"{mod}.DO_1_LEHeatPIDATStop"].Value;
  203. IO.DI[$"{mod}.DI_2_LEHeatPIDATStart_Fb"].Value = IO.DO[$"{mod}.DO_2_LEHeatPIDATStart"].Value;
  204. IO.DI[$"{mod}.DI_2_LEHeatPIDATStop_Fb"].Value = IO.DO[$"{mod}.DO_2_LEHeatPIDATStop"].Value;
  205. }
  206. private void ChangeTime(ModuleName mod)
  207. {
  208. // Heartbeat with PLC
  209. SetAiValue($"{mod}.AI_HeartbeatFB", GetAoValue($"{mod}.AO_Heartbeat"));
  210. SetAiValue($"{mod}.AI_Time", DateTime.Now.Hour);
  211. SetAiValue($"{mod}.AI_Minute", DateTime.Now.Minute);
  212. SetAiValue($"{mod}.AI_Second", DateTime.Now.Second);
  213. }
  214. void MonitorSlitDoor(ModuleName mod)
  215. {
  216. // slit door 1 open
  217. if (IO.DO[$"{mod}.DO_1_SlitDoorOpen"].Value)
  218. {
  219. IO.DI[$"{mod}.DI_1_SlitDoorOpenPos"].Value = true;
  220. IO.DI[$"{mod}.DI_1_SlitDoorClosePos"].Value = false;
  221. }
  222. // slit door 1 close
  223. if (IO.DO[$"{mod}.DO_1_SlitDoorClose"].Value)
  224. {
  225. IO.DI[$"{mod}.DI_1_SlitDoorOpenPos"].Value = false;
  226. IO.DI[$"{mod}.DI_1_SlitDoorClosePos"].Value = true;
  227. }
  228. // slit door 2 open
  229. if (IO.DO[$"{mod}.DO_2_SlitDoorOpen"].Value)
  230. {
  231. IO.DI[$"{mod}.DI_2_SlitDoorOpenPos"].Value = true;
  232. IO.DI[$"{mod}.DI_2_SlitDoorClosePos"].Value = false;
  233. }
  234. // slit door 2 close
  235. if (IO.DO[$"{mod}.DO_2_SlitDoorClose"].Value)
  236. {
  237. IO.DI[$"{mod}.DI_2_SlitDoorOpenPos"].Value = false;
  238. IO.DI[$"{mod}.DI_2_SlitDoorClosePos"].Value = true;
  239. }
  240. }
  241. void MonitorPin(ModuleName mod)
  242. {
  243. // lift pin 1 up
  244. if (IO.DO[$"{mod}.DO_1_LiftPinUp"].Value != IO.DO[$"{mod}.DO_1_LiftPinDown"].Value)
  245. {
  246. IO.DI[$"{mod}.DI_1_LiftPinUp"].Value = IO.DO[$"{mod}.DO_1_LiftPinUp"].Value;
  247. IO.DI[$"{mod}.DI_1_LiftPinDown"].Value = IO.DO[$"{mod}.DO_1_LiftPinDown"].Value;
  248. }
  249. // lift pin 2 up
  250. if (IO.DO[$"{mod}.DO_2_LiftPinUp"].Value != IO.DO[$"{mod}.DO_2_LiftPinDown"].Value)
  251. {
  252. IO.DI[$"{mod}.DI_2_LiftPinUp"].Value = IO.DO[$"{mod}.DO_2_LiftPinUp"].Value;
  253. IO.DI[$"{mod}.DI_2_LiftPinDown"].Value = IO.DO[$"{mod}.DO_2_LiftPinDown"].Value;
  254. }
  255. // upper guide pin up
  256. if (IO.DO[$"{mod}.DO_1_GuidePinLifterUp"].Value)
  257. {
  258. IO.DI[$"{mod}.DI_1_GuidePinLifterUpPos"].Value = true;
  259. IO.DI[$"{mod}.DI_1_GuidePinLifterDownPos"].Value = false;
  260. }
  261. // upper guide pin down
  262. if (IO.DO[$"{mod}.DO_1_GuidePinLifterDown"].Value)
  263. {
  264. IO.DI[$"{mod}.DI_1_GuidePinLifterUpPos"].Value = false;
  265. IO.DI[$"{mod}.DI_1_GuidePinLifterDownPos"].Value = true;
  266. }
  267. // upper guide pin up
  268. if (IO.DO[$"{mod}.DO_2_GuidePinLifterUp"].Value)
  269. {
  270. IO.DI[$"{mod}.DI_2_GuidePinLifterUpPos"].Value = true;
  271. IO.DI[$"{mod}.DI_2_GuidePinLifterDownPos"].Value = false;
  272. }
  273. // upper guide pin down
  274. if (IO.DO[$"{mod}.DO_2_GuidePinLifterDown"].Value)
  275. {
  276. IO.DI[$"{mod}.DI_2_GuidePinLifterUpPos"].Value = false;
  277. IO.DI[$"{mod}.DI_2_GuidePinLifterDownPos"].Value = true;
  278. }
  279. }
  280. void MonitorPressure(ModuleName mod)
  281. {
  282. // pressure
  283. string sAI_Foreline = "AI_ForelinePressure";
  284. // Foreline
  285. if (SkyPumpMockPMA._simPumpStatus == SkyPumpMockPMA.SimPumpStatus.Open || EdwardsPumpMockPMA._simPumpStatus == EdwardsPumpMockPMA.SimEdwardsPumpStatus.Open)
  286. {
  287. SetAiValue($"{mod}.{sAI_Foreline}", GetAiValue($"{mod}.{sAI_Foreline}") - _rd.Next(500, 600));
  288. }
  289. else
  290. {
  291. SetAiValue($"{mod}.{sAI_Foreline}", GetAiValue($"{mod}.{sAI_Foreline}") + _rd.Next(500, 600));
  292. }
  293. // PLC 模拟量范围[0,4000], 电压[0, 10V], 压力[0, 760Torr]
  294. string sAI_ChamberPressure = "AI_ChamberPressure";
  295. string sAI_ProcessPressure = "AI_ProcessPressure";
  296. //float chamber_pressure = GetMockChamberPressure(mod);
  297. //float process_pressure = GetAiValue($"{mod}.AI_Process_pressure");
  298. // soft pump & fast pump
  299. DOAccessor fast_pump_vlv = IO.DO[$"{mod}.DO_FastPumpingValve"];
  300. DOAccessor soft_pump_vlv = IO.DO[$"{mod}.DO_SoftPumpingValve"];
  301. if (fast_pump_vlv.Value || soft_pump_vlv.Value)
  302. {
  303. if (fast_pump_vlv.Value && soft_pump_vlv.Value)
  304. {
  305. float getAiValue_ChamberPressure = GetAiValue($"{mod}.{sAI_ChamberPressure}");
  306. float getAiValue_ProcessPressure = GetAiValue($"{mod}.{sAI_ProcessPressure}");
  307. if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure > 10000)
  308. {
  309. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") - 30000);
  310. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 150);
  311. }
  312. else if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure <= 10000)
  313. {
  314. getAiValue_ProcessPressure = getAiValue_ChamberPressure;
  315. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 1500);
  316. SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 1500);
  317. }
  318. //SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") - _rd.Next(15000, 16000));
  319. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - _rd.Next(150, 160));
  320. }
  321. else if (fast_pump_vlv.Value)
  322. {
  323. float getAiValue_ChamberPressure = GetAiValue($"{mod}.{sAI_ChamberPressure}");
  324. float getAiValue_ProcessPressure = GetAiValue($"{mod}.{sAI_ProcessPressure}");
  325. if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure > 10000)
  326. {
  327. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") - 25000);
  328. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 150);
  329. }
  330. else if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure <= 10000)
  331. {
  332. getAiValue_ProcessPressure = getAiValue_ChamberPressure;
  333. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 1300);
  334. SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 1300);
  335. }
  336. //SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") - _rd.Next(12000, 13000));
  337. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - _rd.Next(120, 130));
  338. }
  339. else if (soft_pump_vlv.Value)
  340. {
  341. float getAiValue_ChamberPressure = GetAiValue($"{mod}.{sAI_ChamberPressure}");
  342. float getAiValue_ProcessPressure = GetAiValue($"{mod}.{sAI_ProcessPressure}");
  343. if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure > 10000)
  344. {
  345. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") - 22000);
  346. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 150);
  347. }
  348. else if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure <= 10000)
  349. {
  350. getAiValue_ProcessPressure = getAiValue_ChamberPressure;
  351. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 1100);
  352. SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 1100);
  353. }
  354. //SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") - _rd.Next(13000, 14000));
  355. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - _rd.Next(100, 110));
  356. }
  357. }
  358. // fast vent & purge
  359. DOAccessor vent_vlv = IO.DO[$"{mod}.DO_ChamberVentValve"];
  360. DOAccessor purge_vlv = IO.DO[$"{mod}.DO_ChamberPurgeValve"];
  361. if (vent_vlv.Value || purge_vlv.Value)
  362. {
  363. if (vent_vlv.Value && purge_vlv.Value)
  364. {
  365. float getAiValue_ChamberPressure = GetAiValue($"{mod}.{sAI_ChamberPressure}");
  366. float getAiValue_ProcessPressure = GetAiValue($"{mod}.{sAI_ProcessPressure}");
  367. if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure > 10000)
  368. {
  369. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") + 30000);
  370. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 150);
  371. }
  372. else if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure <= 10000)
  373. {
  374. getAiValue_ProcessPressure = getAiValue_ChamberPressure;
  375. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") + 1500);
  376. SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") + 1500);
  377. }
  378. //SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") + _rd.Next(45000, 50000));
  379. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") + _rd.Next(150, 160));
  380. }
  381. else if (vent_vlv.Value)
  382. {
  383. float getAiValue_ChamberPressure = GetAiValue($"{mod}.{sAI_ChamberPressure}");
  384. float getAiValue_ProcessPressure = GetAiValue($"{mod}.{sAI_ProcessPressure}");
  385. if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure > 10000)
  386. {
  387. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") + 25000);
  388. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 150);
  389. }
  390. else if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure <= 10000)
  391. {
  392. getAiValue_ProcessPressure = getAiValue_ChamberPressure;
  393. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") + 1300);
  394. SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") + 1300);
  395. }
  396. //SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") + _rd.Next(25000, 30000));
  397. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") + _rd.Next(130, 150));
  398. }
  399. else if (purge_vlv.Value)
  400. {
  401. float getAiValue_ChamberPressure = GetAiValue($"{mod}.{sAI_ChamberPressure}");
  402. float getAiValue_ProcessPressure = GetAiValue($"{mod}.{sAI_ProcessPressure}");
  403. if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure > 10000)
  404. {
  405. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") + 30000);
  406. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 150);
  407. }
  408. else if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure <= 10000)
  409. {
  410. getAiValue_ProcessPressure = getAiValue_ChamberPressure;
  411. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") + 3100);
  412. SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") + 3100);
  413. }
  414. //SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") + _rd.Next(15000, 20000));
  415. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") + _rd.Next(100, 120));
  416. }
  417. }
  418. // 压力值越界,复位
  419. float chamber_pressure1 = GetAiValue($"{mod}.{sAI_ChamberPressure}");
  420. if (chamber_pressure1 > ATM_PRESSURE)
  421. {
  422. SetAiValue($"{mod}.AI_ChamberPressure", ATM_PRESSURE);
  423. }
  424. else if (chamber_pressure1 < 20)
  425. {
  426. SetAiValue($"{mod}.AI_ChamberPressure", 20);
  427. }
  428. float process_pressure1 = GetAiValue($"{mod}.{sAI_ProcessPressure}");
  429. if (process_pressure1 > PROCESS_GAUGE)
  430. {
  431. SetAiValue($"{mod}.AI_ProcessPressure", PROCESS_GAUGE);
  432. }
  433. else if (process_pressure1 < 20)
  434. {
  435. SetAiValue($"{mod}.AI_ProcessPressure", 20);
  436. }
  437. float foreline_pressure = GetAiValue($"{mod}.{sAI_Foreline}");
  438. if (foreline_pressure > 10000)
  439. {
  440. SetAiValue($"{mod}.AI_ForelinePressure", 10000);
  441. }
  442. else if (foreline_pressure < 150)
  443. {
  444. SetAiValue($"{mod}.AI_ForelinePressure", 150);
  445. }
  446. // 模拟压力计漂移
  447. //int p1 = (int)GetMockChamberPressure(mod);
  448. //int new_p1 = _rd.Next(p1 - 2, p1 + 2);
  449. //SetAiValue($"{mod}.AI_Chamber_pressure", new_p1);
  450. //int p2 = (int)GetAiValue($"{mod}.AI_Foreline_pressure");
  451. //int new_p2 = _rd.Next(p2 - 1, p2 + 1);
  452. //SetAiValue($"{mod}.AI_Foreline_pressure", new_p2);
  453. //int p3 = (int)GetAiValue($"{mod}.AI_Process_pressure");
  454. //int new_p3 = _rd.Next(p3 - 1, p3 + 1);
  455. //SetAiValue($"{mod}.AI_Process_pressure", new_p3);
  456. // 根据当前压力值设定信号
  457. //float chamber_pressure2 = GetMockChamberPressure(mod);
  458. // ATM switch
  459. IO.DI[$"{mod}.DI_ATMSW"].Value = GetAiValue($"{mod}.{sAI_ChamberPressure}") > ATM_THRESHOLD;
  460. // VAC switch
  461. IO.DI[$"{mod}.DI_VACSW"].Value = GetAiValue($"{mod}.{sAI_ChamberPressure}") < VAC_SW_PRESSURE;
  462. // Throttle valve
  463. //var pos_sp = IO.AO[$"{mod}.AO_ThrottleValvePressureSetpoint"].Value;
  464. //var mock_pos_fb = _rd.Next(pos_sp - 2, pos_sp + 2);
  465. ////IO.AI[$"{mod}.AI_ThrottleValveRealPressure"].Value = (short)mock_pos_fb;
  466. //SetAiValue($"{mod}.AI_ThrottleValveRealPressure", mock_pos_fb);
  467. // 压力值
  468. if (GetAiValue($"{mod}.AI_ThrottleValveRealPressure") < GetAoValue($"{mod}.AO_ThrottleValvePressureSetpoint"))
  469. {
  470. short increase = (short)_rd.Next(20, 30);
  471. SetAiValue($"{mod}.AI_ThrottleValveRealPressure", GetAiValue($"{mod}.AI_ThrottleValveRealPressure") + increase);
  472. if (GetAiValue($"{mod}.AI_ThrottleValveRealPressure") > GetAoValue($"{mod}.AO_ThrottleValvePressureSetpoint"))
  473. {
  474. SetAiValue($"{mod}.AI_ThrottleValveRealPressure", GetAoValue($"{mod}.AO_ThrottleValvePressureSetpoint"));
  475. }
  476. }
  477. else
  478. {
  479. short increase = (short)_rd.Next(20, 30);
  480. SetAiValue($"{mod}.AI_ThrottleValveRealPressure", GetAiValue($"{mod}.AI_ThrottleValveRealPressure") - increase);
  481. if (GetAiValue($"{mod}.AI_ThrottleValveRealPressure") < GetAoValue($"{mod}.AO_ThrottleValvePressureSetpoint"))
  482. {
  483. SetAiValue($"{mod}.AI_ThrottleValveRealPressure", GetAoValue($"{mod}.AO_ThrottleValvePressureSetpoint"));
  484. }
  485. }
  486. // 位置值
  487. if (GetAiValue($"{mod}.AI_ThrottleValveRealPosition") < GetAoValue($"{mod}.AO_ThrottleValvePositionSetpoint"))
  488. {
  489. short increase = (short)_rd.Next(20, 30);
  490. SetAiValue($"{mod}.AI_ThrottleValveRealPosition", GetAiValue($"{mod}.AI_ThrottleValveRealPosition") + increase);
  491. if (GetAiValue($"{mod}.AI_ThrottleValveRealPosition") > GetAoValue($"{mod}.AO_ThrottleValvePositionSetpoint"))
  492. {
  493. SetAiValue($"{mod}.AI_ThrottleValveRealPosition", GetAoValue($"{mod}.AO_ThrottleValvePositionSetpoint"));
  494. }
  495. }
  496. else
  497. {
  498. short increase = (short)_rd.Next(20, 30);
  499. SetAiValue($"{mod}.AI_ThrottleValveRealPosition", GetAiValue($"{mod}.AI_ThrottleValveRealPosition") - increase);
  500. if (GetAiValue($"{mod}.AI_ThrottleValveRealPosition") < GetAoValue($"{mod}.AO_ThrottleValvePositionSetpoint"))
  501. {
  502. SetAiValue($"{mod}.AI_ThrottleValveRealPosition", GetAoValue($"{mod}.AO_ThrottleValvePositionSetpoint"));
  503. }
  504. }
  505. }
  506. //float GetMockChamberPressure(ModuleName mod)
  507. //{
  508. // return GetAiValue($"{mod}.AI_Chamber_pressure");
  509. //}
  510. //void SetMockChamberPressure(ModuleName mod, float val)
  511. //{
  512. // SetAiValue($"{mod}.AI_Chamber_pressure", val);
  513. //}
  514. void SetAiValue(string name, float value)
  515. {
  516. IO.AI[name].FloatValue = value;
  517. //byte[] flow = BitConverter.GetBytes(value);
  518. //short high1 = BitConverter.ToInt16(flow, 0);
  519. //short low1 = BitConverter.ToInt16(flow, 2);
  520. //IO.AI[name].Buffer[IO.AI[name].Index] = BitConverter.ToInt16(flow, 0);
  521. //IO.AI[name].Buffer[IO.AI[name].Index + 1] = BitConverter.ToInt16(flow, 2);
  522. //byte[] high = BitConverter.GetBytes(IO.AI[name].Buffer[IO.AI[name].Index]);
  523. //byte[] low = BitConverter.GetBytes(IO.AI[name].Buffer[IO.AI[name].Index + 1]);
  524. //float readback = BitConverter.ToSingle(new[] { high[0], high[1], low[0], low[1] }, 0);
  525. }
  526. float GetAiValue(string name)
  527. {
  528. return IO.AI[name].FloatValue;
  529. //byte[] high = BitConverter.GetBytes(IO.AI[name].Buffer[IO.AI[name].Index]);
  530. //byte[] low = BitConverter.GetBytes(IO.AI[name].Buffer[IO.AI[name].Index + 1]);
  531. //float flow = BitConverter.ToSingle(new[] { high[0], high[1], low[0], low[1] }, 0);
  532. //return flow;
  533. }
  534. float GetAoValue(string name)
  535. {
  536. return IO.AO[name].FloatValue;
  537. //byte[] high = BitConverter.GetBytes(IO.AO[name].Buffer[IO.AO[name].Index]);
  538. //byte[] low = BitConverter.GetBytes(IO.AO[name].Buffer[IO.AO[name].Index + 1]);
  539. //float flow = BitConverter.ToSingle(new[] { high[0], high[1], low[0], low[1] }, 0);
  540. //return flow;
  541. }
  542. void MonitorTemperature(ModuleName mod)
  543. {
  544. SetAiValue($"{mod}.AI_1_CoolantInletTemp", 50);
  545. SetAiValue($"{mod}.AI_2_CoolantInletTemp", 50);
  546. SetAiValue($"{mod}.AI_1_CoolantOutletTemp", 50);
  547. SetAiValue($"{mod}.AI_2_CoolantOutletTemp", 50);
  548. IO.DI[$"{mod}.DI_CHBHeaterOn_FB"].Value = IO.DO[$"{mod}.DO_CHBHeaterOn"].Value;
  549. IO.DI[$"{mod}.DI_ForelineHeaterOn_FB"].Value = IO.DO[$"{mod}.DO_ForelineHeaterOn"].Value;
  550. IO.DI[$"{mod}.DI_1_LEHeaterOn_FB"].Value = IO.DO[$"{mod}.DO_1_LEHeaterOn"].Value;
  551. IO.DI[$"{mod}.DI_2_LEHeaterOn_FB"].Value = IO.DO[$"{mod}.DO_2_LEHeaterOn"].Value;
  552. IO.DI[$"{mod}.DI_ForelineTCDeviationOutOfRange"].Value = false;
  553. IO.DI[$"{mod}.DI_CHBTCDeviationOutOfRange"].Value = false;
  554. IO.DI[$"{mod}.DI_1_LETCDeviationOutOfRange"].Value = false;
  555. IO.DI[$"{mod}.DI_2_LETCDeviationOutOfRange"].Value = false;
  556. // 底座
  557. if (IO.DO[$"{mod}.DO_CHBHeaterOn"].Value &&
  558. GetAiValue($"{mod}.AI_CHBControlTCTemp") < GetAoValue($"{mod}.AO_CHBTemperatureSetpoint"))
  559. {
  560. SetAiValue($"{mod}.AI_CHBControlTCTemp", GetAiValue($"{mod}.AI_CHBControlTCTemp") + _rd.Next(1, 2));
  561. SetAiValue($"{mod}.AI_CHBMonitorTCTemp", GetAiValue($"{mod}.AI_CHBMonitorTCTemp") + _rd.Next(1, 2));
  562. }
  563. else if (IO.DO[$"{mod}.DO_CHBHeaterOn"].Value &&
  564. GetAiValue($"{mod}.AI_CHBControlTCTemp") > GetAoValue($"{mod}.AO_CHBTemperatureSetpoint"))
  565. {
  566. SetAiValue($"{mod}.AI_CHBControlTCTemp", GetAiValue($"{mod}.AI_CHBControlTCTemp") - _rd.Next(1, 2));
  567. SetAiValue($"{mod}.AI_CHBMonitorTCTemp", GetAiValue($"{mod}.AI_CHBMonitorTCTemp") - _rd.Next(1, 2));
  568. }
  569. // Foreline
  570. if (IO.DO[$"{mod}.DO_ForelineHeaterOn"].Value &&
  571. GetAiValue($"{mod}.AI_ForelineControlTCTemp") < GetAoValue($"{mod}.AO_ForelineTemperatureSetpoint"))
  572. {
  573. SetAiValue($"{mod}.AI_ForelineControlTCTemp", GetAiValue($"{mod}.AI_ForelineControlTCTemp") + _rd.Next(1, 2));
  574. SetAiValue($"{mod}.AI_ForelineMonitorTCTemp", GetAiValue($"{mod}.AI_ForelineMonitorTCTemp") + _rd.Next(1, 2));
  575. }
  576. else if (IO.DO[$"{mod}.DO_ForelineHeaterOn"].Value &&
  577. GetAiValue($"{mod}.AI_ForelineControlTCTemp") > GetAoValue($"{mod}.AO_ForelineTemperatureSetpoint"))
  578. {
  579. SetAiValue($"{mod}.AI_ForelineControlTCTemp", GetAiValue($"{mod}.AI_ForelineControlTCTemp") - _rd.Next(1, 2));
  580. SetAiValue($"{mod}.AI_ForelineMonitorTCTemp", GetAiValue($"{mod}.AI_ForelineMonitorTCTemp") - _rd.Next(1, 2));
  581. }
  582. // LE1
  583. if (IO.DO[$"{mod}.DO_1_LEHeaterOn"].Value &&
  584. GetAiValue($"{mod}.AI_1_LEControlTCTemp") < GetAoValue($"{mod}.AO_1_LETemperatureSetpoint"))
  585. {
  586. SetAiValue($"{mod}.AI_1_LEControlTCTemp", GetAiValue($"{mod}.AI_1_LEControlTCTemp") + _rd.Next(1, 2));
  587. SetAiValue($"{mod}.AI_1_LEMonitorTCTemp", GetAiValue($"{mod}.AI_1_LEMonitorTCTemp") + _rd.Next(1, 2));
  588. }
  589. else if (IO.DO[$"{mod}.DO_1_LEHeaterOn"].Value &&
  590. GetAiValue($"{mod}.AI_1_LEControlTCTemp") > GetAoValue($"{mod}.AO_1_LETemperatureSetpoint"))
  591. {
  592. SetAiValue($"{mod}.AI_1_LEControlTCTemp", GetAiValue($"{mod}.AI_1_LEControlTCTemp") - _rd.Next(1, 2));
  593. SetAiValue($"{mod}.AI_1_LEMonitorTCTemp", GetAiValue($"{mod}.AI_1_LEMonitorTCTemp") - _rd.Next(1, 2));
  594. }
  595. // LE2
  596. if (IO.DO[$"{mod}.DO_2_LEHeaterOn"].Value &&
  597. GetAiValue($"{mod}.AI_2_LEControlTCTemp") < GetAoValue($"{mod}.AO_2_LETemperatureSetpoint"))
  598. {
  599. SetAiValue($"{mod}.AI_2_LEControlTCTemp", GetAiValue($"{mod}.AI_2_LEControlTCTemp") + _rd.Next(1, 2));
  600. SetAiValue($"{mod}.AI_2_LEMonitorTCTemp", GetAiValue($"{mod}.AI_2_LEMonitorTCTemp") + _rd.Next(1, 2));
  601. }
  602. else if (IO.DO[$"{mod}.DO_2_LEHeaterOn"].Value &&
  603. GetAiValue($"{mod}.AI_2_LEControlTCTemp") > GetAoValue($"{mod}.AO_2_LETemperatureSetpoint"))
  604. {
  605. SetAiValue($"{mod}.AI_2_LEControlTCTemp", GetAiValue($"{mod}.AI_2_LEControlTCTemp") - _rd.Next(1, 2));
  606. SetAiValue($"{mod}.AI_2_LEMonitorTCTemp", GetAiValue($"{mod}.AI_2_LEMonitorTCTemp") - _rd.Next(1, 2));
  607. }
  608. }
  609. void MonitorGas(ModuleName mod)
  610. {
  611. // gas
  612. this.SimulateMFC(ModuleName.PMA, 1);
  613. this.SimulateMFC(ModuleName.PMA, 2);
  614. this.SimulateMFC(ModuleName.PMA, 3);
  615. this.SimulateMFC(ModuleName.PMA, 4);
  616. this.SimulateMFC(ModuleName.PMA, 5);
  617. this.SimulateMFC(ModuleName.PMA, 6);
  618. this.SimulateMFC(ModuleName.PMB, 1);
  619. this.SimulateMFC(ModuleName.PMB, 2);
  620. this.SimulateMFC(ModuleName.PMB, 3);
  621. this.SimulateMFC(ModuleName.PMB, 4);
  622. this.SimulateMFC(ModuleName.PMB, 5);
  623. this.SimulateMFC(ModuleName.PMB, 6);
  624. }
  625. private void SimulateMFC(ModuleName mod, byte gasNum)
  626. {
  627. var sp = GetAoValue($"{mod}.AO_MFC{gasNum}FlowSetpoint");
  628. var mock_fb = _rd.Next((int)sp - 3, (int)sp + 3) + _rd.NextDouble();
  629. SetAiValue($"{mod}.AI_MFC{gasNum}Flow", (float)mock_fb);
  630. }
  631. //void MonitorRF(ModuleName mod)
  632. //{
  633. // // RF generator
  634. // var sp = GetAoValue($"{mod}.AO_BaisRFEnable");
  635. // var mock_fb = _rd.Next((int)sp - 3, (int)sp + 3) + _rd.NextDouble();
  636. // //var mock_sp = _rd.Next(sp - 3, sp + 3);
  637. // SetAiValue($"{mod}.AI_Generator_Forward_Power", (float)mock_fb);
  638. // //IO.DI[$"{mod}.DI_Generator_Power_Status"].Value = IO.DO[$"{mod}.DO_Generator_Power_ON"].Value;
  639. //}
  640. public void Terminate()
  641. {
  642. _thread.Stop();
  643. }
  644. }
  645. }