SimulatorSystem.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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 MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Simulator.Core.Driver;
  9. using Virgo_DSimulator.Devices;
  10. namespace Virgo_DSimulator.Instances
  11. {
  12. public class SimulatorSystem : Singleton<SimulatorSystem>
  13. {
  14. private PeriodicJob _thread;
  15. private Random _rd = new Random();
  16. private RD_TRIG _trigATM = new RD_TRIG();
  17. private RD_TRIG _trigVAC = new RD_TRIG();
  18. private readonly float ATM_THRESHOLD = 750000;
  19. private readonly float ATM_PRESSURE = 760000;
  20. private readonly uint VAC_SW_PRESSURE = 9500;
  21. private readonly uint PROCESS_GAUGE = 10000;
  22. private Dictionary<ModuleName, DeviceSimulator> _MockDevices = new Dictionary<ModuleName, DeviceSimulator>();
  23. public SimulatorSystem()
  24. {
  25. //_MockDevices.Add(ModuleName.PMB, new SkyPumpMock());
  26. //_MockDevices.Add(ModuleName.PMB, new AdTecGeneratorMock());
  27. //_MockDevices.Add(ModuleName.PMB, new AdTecMatchMock());
  28. // TODO
  29. }
  30. ~SimulatorSystem()
  31. {
  32. _thread?.Stop();
  33. }
  34. public void Initialize()
  35. {
  36. SetDefaultValue(ModuleName.PMA);
  37. //SetDefaultValue(ModuleName.PMB);
  38. Singleton<DataManager>.Instance.Initialize(false);
  39. _thread = new PeriodicJob(500, OnMonitor, nameof(SimulatorSystem), true);
  40. }
  41. private void SetDefaultValue(ModuleName mod)
  42. {
  43. // chamber
  44. IO.DI[$"{mod}.DI_Lid_Closed"].Value = true;
  45. IO.DI[$"{mod}.DI_PM_ATM_SW"].Value = true;
  46. IO.DI[$"{mod}.DI_CDA_Pressure"].Value = true;
  47. IO.DI[$"{mod}.DI_SourceFan1"].Value = true;
  48. IO.DI[$"{mod}.DI_SourceFan2"].Value = true;
  49. IO.DI[$"{mod}.DI_Factory_Scrubber_SYS_Normal"].Value = false;
  50. IO.DI[$"{mod}.DI_Cooling_Water_Flow_SW"].Value = true;
  51. IO.DI[$"{mod}.DI_Water_Leak"].Value = true;
  52. //IO.DI[$"{mod}.DI_ARM_Not_Extend_to_PM"].Value = true;
  53. IO.DI[$"{mod}.DI_MFC1_Pressure"].Value = true;
  54. IO.DI[$"{mod}.DI_MFC2_Pressure"].Value = true;
  55. IO.DI[$"{mod}.DI_MFC3_Pressure"].Value = true;
  56. IO.DI[$"{mod}.DI_MFC4_Pressure"].Value = true;
  57. //IO.DI[$"{mod}.DI_MFC5_Pressure"].Value = true;
  58. IO.DI[$"{mod}.DI_N2_Pressure"].Value = true;
  59. //IO.DI[$"{mod}.DI_EFEM_Side_Panel_Closed"].Value = true;
  60. IO.DI[$"{mod}.DI_Generator_Hardware_Interlock"].Value = true;
  61. //// slit door
  62. //IO.DI[$"{mod}.DI_Slit_Door_Open_Pos"].Value = false;
  63. //IO.DI[$"{mod}.DI_Slit_Door_Close_Pos"].Value = true;
  64. // lift pin
  65. IO.DI[$"{mod}.DI_Lift_Pin_Up"].Value = false;
  66. IO.DI[$"{mod}.DI_Lift_Pin_Down"].Value = true;
  67. //// Guide pin
  68. //IO.DI[$"{mod}.DI_Guide_Pin_Inch_3_Lifter_Up_Pos"].Value = false;
  69. //IO.DI[$"{mod}.DI_Guide_Pin_Inch_3_Lifter_Down_Pos"].Value = true;
  70. //IO.DI[$"{mod}.DI_Guide_Pin_Inch_4_Lifter_Up_Pos"].Value = false;
  71. //IO.DI[$"{mod}.DI_Guide_Pin_Inch_4_Lifter_Down_Pos"].Value = true;
  72. // pressure
  73. SetAiValue($"{mod}.AI_Foreline_pressure", 5000);
  74. SetAiValue($"{mod}.AI_Chamber_pressure", ATM_PRESSURE);
  75. SetAiValue($"{mod}.AI_Process_pressure", PROCESS_GAUGE);
  76. //SetAiValue($"{mod}.AI_Throttle_Valve_State", 1);
  77. //IO.AI[$"{mod}.AI_Throttle_Valve_State"].Value = 1;
  78. IO.AI[$"{mod}.AI_Throttle_Valve_Real_Position"].Value = 10;
  79. // Temperature
  80. SetAiValue($"{mod}.AI_Substrate_Control_TC_Temp", 28);
  81. SetAiValue($"{mod}.AI_Substrate_Monitor_TC_Temp", 27);
  82. SetAiValue($"{mod}.AI_Foreline_Control_TC_Temp", 28);
  83. SetAiValue($"{mod}.AI_Foreline_Monitor_TC_Temp", 27);
  84. // Datetime
  85. SetAiValue($"{mod}.AI_Year", DateTime.Today.Year);
  86. SetAiValue($"{mod}.AI_Month", DateTime.Today.Month);
  87. SetAiValue($"{mod}.AI_Day", DateTime.Today.Day);
  88. }
  89. private bool OnMonitor()
  90. {
  91. try
  92. {
  93. // PMA
  94. //MonitorSlitDoor(ModuleName.PMA);
  95. MonitorPin(ModuleName.PMA);
  96. MonitorPressure(ModuleName.PMA);
  97. MonitorTemperature(ModuleName.PMA);
  98. MonitorGas(ModuleName.PMA);
  99. MonitorRF(ModuleName.PMA);
  100. ChangeTime(ModuleName.PMA);
  101. //// PMB
  102. //MonitorSlitDoor(ModuleName.PMB);
  103. //MonitorPin(ModuleName.PMB);
  104. //MonitorPressure(ModuleName.PMB);
  105. //MonitorTemperature(ModuleName.PMB);
  106. //MonitorGas(ModuleName.PMB);
  107. //MonitorRF(ModuleName.PMB);
  108. //ChangeTime(ModuleName.PMB);
  109. }
  110. catch (Exception e)
  111. {
  112. LOG.Write(e);
  113. }
  114. return true;
  115. }
  116. private void ChangeTime(ModuleName mod)
  117. {
  118. // Heartbeat with PLC
  119. SetAiValue($"{mod}.AI_Heartbeat_FB", GetAoValue($"{mod}.AO_Heartbeat"));
  120. SetAiValue($"{mod}.AI_Time", DateTime.Now.Hour);
  121. SetAiValue($"{mod}.AI_Minute", DateTime.Now.Minute);
  122. SetAiValue($"{mod}.AI_Second", DateTime.Now.Second);
  123. }
  124. void MonitorSlitDoor(ModuleName mod)
  125. {
  126. // slit door open
  127. if (IO.DO[$"{mod}.DO_Slit_Door_Open"].Value)
  128. {
  129. IO.DI[$"{mod}.DI_Slit_Door_Open_Pos"].Value = true;
  130. IO.DI[$"{mod}.DI_Slit_Door_Close_Pos"].Value = false;
  131. }
  132. // slit door close
  133. if (IO.DO[$"{mod}.DO_Slit_Door_Close"].Value)
  134. {
  135. IO.DI[$"{mod}.DI_Slit_Door_Open_Pos"].Value = false;
  136. IO.DI[$"{mod}.DI_Slit_Door_Close_Pos"].Value = true;
  137. }
  138. }
  139. void MonitorPin(ModuleName mod)
  140. {
  141. // lift pin up
  142. if (IO.DO[$"{mod}.DO_Lift_Pin_Up"].Value != IO.DO[$"{mod}.DO_Lift_Pin_Down"].Value)
  143. {
  144. IO.DI[$"{mod}.DI_Lift_Pin_Up"].Value = IO.DO[$"{mod}.DO_Lift_Pin_Up"].Value;
  145. IO.DI[$"{mod}.DI_Lift_Pin_Down"].Value = IO.DO[$"{mod}.DO_Lift_Pin_Down"].Value;
  146. }
  147. //// upper guide pin up
  148. //if (IO.DO[$"{mod}.DO_Guide_Pin_Inch_3_Lifter_Up"].Value)
  149. //{
  150. // IO.DI[$"{mod}.DI_Guide_Pin_Inch_3_Lifter_Up_Pos"].Value = true;
  151. // IO.DI[$"{mod}.DI_Guide_Pin_Inch_3_Lifter_Down_Pos"].Value = false;
  152. //}
  153. //// upper guide pin down
  154. //if (IO.DO[$"{mod}.DO_Guide_Pin_Inch_3_Lifter_Down"].Value)
  155. //{
  156. // IO.DI[$"{mod}.DI_Guide_Pin_Inch_3_Lifter_Up_Pos"].Value = false;
  157. // IO.DI[$"{mod}.DI_Guide_Pin_Inch_3_Lifter_Down_Pos"].Value = true;
  158. //}
  159. //// lower guide pin up
  160. //if (IO.DO[$"{mod}.DO_Guide_Pin_Inch_4_Lifter_Up"].Value)
  161. //{
  162. // IO.DI[$"{mod}.DI_Guide_Pin_Inch_4_Lifter_Up_Pos"].Value = true;
  163. // IO.DI[$"{mod}.DI_Guide_Pin_Inch_4_Lifter_Down_Pos"].Value = false;
  164. //}
  165. //// lower guide pin down
  166. //if (IO.DO[$"{mod}.DO_Guide_Pin_Inch_4_Lifter_Down"].Value)
  167. //{
  168. // IO.DI[$"{mod}.DI_Guide_Pin_Inch_4_Lifter_Up_Pos"].Value = false;
  169. // IO.DI[$"{mod}.DI_Guide_Pin_Inch_4_Lifter_Down_Pos"].Value = true;
  170. //}
  171. }
  172. void MonitorPressure(ModuleName mod)
  173. {
  174. //if (IO.DO[$"{mod}.DO_Pump_Stop"].Value != IO.DO[$"{mod}.DO_Pump_Start"].Value)
  175. //{
  176. // IO.DI[$"{mod}.DI_Pump_Running"].Value = IO.DO[$"{mod}.DO_Pump_Start"].Value;
  177. //}
  178. // pressure
  179. string sAI_Foreline = "AI_Foreline_pressure";
  180. // Foreline
  181. if (SkyPumpMock._simPumpStatus == SkyPumpMock.SimPumpStatus.Open)
  182. {
  183. SetAiValue($"{mod}.{sAI_Foreline}", GetAiValue($"{mod}.{sAI_Foreline}") - _rd.Next(500, 600));
  184. }
  185. else
  186. {
  187. SetAiValue($"{mod}.{sAI_Foreline}", GetAiValue($"{mod}.{sAI_Foreline}") + _rd.Next(500, 600));
  188. }
  189. // PLC 模拟量范围[0,4000], 电压[0, 10V], 压力[0, 760Torr]
  190. string sAI_ChamberPressure = "AI_Chamber_pressure";
  191. string sAI_ProcessPressure = "AI_Process_pressure";
  192. //float chamber_pressure = GetMockChamberPressure(mod);
  193. //float process_pressure = GetAiValue($"{mod}.AI_Process_pressure");
  194. // soft pump & fast pump
  195. DOAccessor fast_pump_vlv = IO.DO[$"{mod}.DO_Fast_Pumping_Valve"];
  196. DOAccessor soft_pump_vlv = IO.DO[$"{mod}.DO_Soft_Pumping_Valve"];
  197. if (fast_pump_vlv.Value || soft_pump_vlv.Value)
  198. {
  199. if (fast_pump_vlv.Value && soft_pump_vlv.Value)
  200. {
  201. float getAiValue_ChamberPressure = GetAiValue($"{mod}.{sAI_ChamberPressure}");
  202. float getAiValue_ProcessPressure = GetAiValue($"{mod}.{sAI_ProcessPressure}");
  203. if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure > 10000 )
  204. {
  205. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") - 30000);
  206. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 150);
  207. }
  208. else if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure <= 10000 )
  209. {
  210. getAiValue_ProcessPressure = getAiValue_ChamberPressure;
  211. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 1500);
  212. SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 1500);
  213. }
  214. //SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") - _rd.Next(15000, 16000));
  215. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - _rd.Next(150, 160));
  216. }
  217. else if (fast_pump_vlv.Value)
  218. {
  219. float getAiValue_ChamberPressure = GetAiValue($"{mod}.{sAI_ChamberPressure}");
  220. float getAiValue_ProcessPressure = GetAiValue($"{mod}.{sAI_ProcessPressure}");
  221. if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure > 10000)
  222. {
  223. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") - 25000);
  224. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 150);
  225. }
  226. else if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure <= 10000)
  227. {
  228. getAiValue_ProcessPressure = getAiValue_ChamberPressure;
  229. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 1300);
  230. SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 1300);
  231. }
  232. //SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") - _rd.Next(12000, 13000));
  233. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - _rd.Next(120, 130));
  234. }
  235. else if (soft_pump_vlv.Value)
  236. {
  237. float getAiValue_ChamberPressure = GetAiValue($"{mod}.{sAI_ChamberPressure}");
  238. float getAiValue_ProcessPressure = GetAiValue($"{mod}.{sAI_ProcessPressure}");
  239. if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure > 10000)
  240. {
  241. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") - 22000);
  242. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 150);
  243. }
  244. else if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure <= 10000 )
  245. {
  246. getAiValue_ProcessPressure = getAiValue_ChamberPressure;
  247. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 1100);
  248. SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 1100);
  249. }
  250. //SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") - _rd.Next(13000, 14000));
  251. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - _rd.Next(100, 110));
  252. }
  253. }
  254. // fast vent & purge
  255. DOAccessor vent_vlv = IO.DO[$"{mod}.DO_Chamber_vent_valve"];
  256. DOAccessor purge_vlv = IO.DO[$"{mod}.DO_Chamber_purge_valve"];
  257. if (vent_vlv.Value || purge_vlv.Value)
  258. {
  259. if (vent_vlv.Value && purge_vlv.Value)
  260. {
  261. float getAiValue_ChamberPressure = GetAiValue($"{mod}.{sAI_ChamberPressure}");
  262. float getAiValue_ProcessPressure = GetAiValue($"{mod}.{sAI_ProcessPressure}");
  263. if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure > 10000 )
  264. {
  265. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") + 30000);
  266. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 150);
  267. }
  268. else if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure <= 10000 )
  269. {
  270. getAiValue_ProcessPressure = getAiValue_ChamberPressure;
  271. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") + 1500);
  272. SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") + 1500);
  273. }
  274. //SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") + _rd.Next(45000, 50000));
  275. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") + _rd.Next(150, 160));
  276. }
  277. else if (vent_vlv.Value)
  278. {
  279. float getAiValue_ChamberPressure = GetAiValue($"{mod}.{sAI_ChamberPressure}");
  280. float getAiValue_ProcessPressure = GetAiValue($"{mod}.{sAI_ProcessPressure}");
  281. if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure > 10000)
  282. {
  283. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") + 25000);
  284. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 150);
  285. }
  286. else if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure <= 10000)
  287. {
  288. getAiValue_ProcessPressure = getAiValue_ChamberPressure;
  289. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") + 1300);
  290. SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") + 1300);
  291. }
  292. //SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") + _rd.Next(25000, 30000));
  293. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") + _rd.Next(130, 150));
  294. }
  295. else if (purge_vlv.Value)
  296. {
  297. float getAiValue_ChamberPressure = GetAiValue($"{mod}.{sAI_ChamberPressure}");
  298. float getAiValue_ProcessPressure = GetAiValue($"{mod}.{sAI_ProcessPressure}");
  299. if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure > 10000)
  300. {
  301. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") + 30000);
  302. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") - 150);
  303. }
  304. else if (getAiValue_ProcessPressure <= 10000 && getAiValue_ChamberPressure <= 10000 )
  305. {
  306. getAiValue_ProcessPressure = getAiValue_ChamberPressure;
  307. SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") + 3100);
  308. SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") + 3100);
  309. }
  310. //SetAiValue($"{mod}.{sAI_ChamberPressure}", GetAiValue($"{mod}.{sAI_ChamberPressure}") + _rd.Next(15000, 20000));
  311. //SetAiValue($"{mod}.{sAI_ProcessPressure}", GetAiValue($"{mod}.{sAI_ProcessPressure}") + _rd.Next(100, 120));
  312. }
  313. }
  314. // 压力值越界,复位
  315. float chamber_pressure1 = GetAiValue($"{mod}.{sAI_ChamberPressure}");
  316. if (chamber_pressure1 > ATM_PRESSURE)
  317. {
  318. SetAiValue($"{mod}.AI_Chamber_pressure", ATM_PRESSURE);
  319. }
  320. else if (chamber_pressure1 < 20)
  321. {
  322. SetAiValue($"{mod}.AI_Chamber_pressure", 20);
  323. }
  324. float process_pressure1 = GetAiValue($"{mod}.{sAI_ProcessPressure}");
  325. if (process_pressure1 > PROCESS_GAUGE)
  326. {
  327. SetAiValue($"{mod}.AI_Process_pressure", PROCESS_GAUGE);
  328. }
  329. else if (process_pressure1 < 20)
  330. {
  331. SetAiValue($"{mod}.AI_Process_pressure", 20);
  332. }
  333. float foreline_pressure = GetAiValue($"{mod}.{sAI_Foreline}");
  334. if (foreline_pressure > 10000)
  335. {
  336. SetAiValue($"{mod}.AI_Foreline_pressure", 10000);
  337. }
  338. else if (foreline_pressure < 150)
  339. {
  340. SetAiValue($"{mod}.AI_Foreline_pressure", 150);
  341. }
  342. // 模拟压力计漂移
  343. //int p1 = (int)GetMockChamberPressure(mod);
  344. //int new_p1 = _rd.Next(p1 - 2, p1 + 2);
  345. //SetAiValue($"{mod}.AI_Chamber_pressure", new_p1);
  346. //int p2 = (int)GetAiValue($"{mod}.AI_Foreline_pressure");
  347. //int new_p2 = _rd.Next(p2 - 1, p2 + 1);
  348. //SetAiValue($"{mod}.AI_Foreline_pressure", new_p2);
  349. //int p3 = (int)GetAiValue($"{mod}.AI_Process_pressure");
  350. //int new_p3 = _rd.Next(p3 - 1, p3 + 1);
  351. //SetAiValue($"{mod}.AI_Process_pressure", new_p3);
  352. // 根据当前压力值设定信号
  353. //float chamber_pressure2 = GetMockChamberPressure(mod);
  354. // ATM switch
  355. IO.DI[$"{mod}.DI_PM_ATM_SW"].Value = GetAiValue($"{mod}.{sAI_ChamberPressure}") > ATM_THRESHOLD;
  356. // VAC switch
  357. IO.DI[$"{mod}.DI_PM_VAC_SW"].Value = GetAiValue($"{mod}.{sAI_ChamberPressure}") < VAC_SW_PRESSURE;
  358. // Throttle valve
  359. //var pos_sp = IO.AO[$"{mod}.AO_Throttle_Valve_Pressure_Setpoint"].Value;
  360. //var mock_pos_fb = _rd.Next(pos_sp - 2, pos_sp + 2);
  361. ////IO.AI[$"{mod}.AI_Throttle_Valve_Real_Pressure"].Value = (short)mock_pos_fb;
  362. //SetAiValue($"{mod}.AI_Throttle_Valve_Real_Pressure", mock_pos_fb);
  363. // 压力值
  364. if (GetAiValue($"{mod}.AI_Throttle_Valve_Real_Pressure") < GetAoValue($"{mod}.AO_Throttle_Valve_Pressure_Setpoint"))
  365. {
  366. short increase = (short)_rd.Next(20, 30);
  367. SetAiValue($"{mod}.AI_Throttle_Valve_Real_Pressure", GetAiValue($"{mod}.AI_Throttle_Valve_Real_Pressure") + increase);
  368. if (GetAiValue($"{mod}.AI_Throttle_Valve_Real_Pressure") > GetAoValue($"{mod}.AO_Throttle_Valve_Pressure_Setpoint"))
  369. {
  370. SetAiValue($"{mod}.AI_Throttle_Valve_Real_Pressure", GetAoValue($"{mod}.AO_Throttle_Valve_Pressure_Setpoint"));
  371. }
  372. }
  373. else
  374. {
  375. short increase = (short)_rd.Next(20, 30);
  376. SetAiValue($"{mod}.AI_Throttle_Valve_Real_Pressure", GetAiValue($"{mod}.AI_Throttle_Valve_Real_Pressure") - increase);
  377. if (GetAiValue($"{mod}.AI_Throttle_Valve_Real_Pressure") < GetAoValue($"{mod}.AO_Throttle_Valve_Pressure_Setpoint"))
  378. {
  379. SetAiValue($"{mod}.AI_Throttle_Valve_Real_Pressure", GetAoValue($"{mod}.AO_Throttle_Valve_Pressure_Setpoint"));
  380. }
  381. }
  382. // 位置值
  383. if (GetAiValue($"{mod}.AI_Throttle_Valve_Real_Position") < GetAoValue($"{mod}.AO_Throttle_Valve_Position_Setpoint"))
  384. {
  385. short increase = (short)_rd.Next(20, 30);
  386. SetAiValue($"{mod}.AI_Throttle_Valve_Real_Position", GetAiValue($"{mod}.AI_Throttle_Valve_Real_Position") + increase);
  387. if (GetAiValue($"{mod}.AI_Throttle_Valve_Real_Position") > GetAoValue($"{mod}.AO_Throttle_Valve_Position_Setpoint"))
  388. {
  389. SetAiValue($"{mod}.AI_Throttle_Valve_Real_Position", GetAoValue($"{mod}.AO_Throttle_Valve_Position_Setpoint"));
  390. }
  391. }
  392. else
  393. {
  394. short increase = (short)_rd.Next(20, 30);
  395. SetAiValue($"{mod}.AI_Throttle_Valve_Real_Position", GetAiValue($"{mod}.AI_Throttle_Valve_Real_Position") - increase);
  396. if (GetAiValue($"{mod}.AI_Throttle_Valve_Real_Position") < GetAoValue($"{mod}.AO_Throttle_Valve_Position_Setpoint"))
  397. {
  398. SetAiValue($"{mod}.AI_Throttle_Valve_Real_Position", GetAoValue($"{mod}.AO_Throttle_Valve_Position_Setpoint"));
  399. }
  400. }
  401. }
  402. //float GetMockChamberPressure(ModuleName mod)
  403. //{
  404. // return GetAiValue($"{mod}.AI_Chamber_pressure");
  405. //}
  406. //void SetMockChamberPressure(ModuleName mod, float val)
  407. //{
  408. // SetAiValue($"{mod}.AI_Chamber_pressure", val);
  409. //}
  410. void SetAiValue(string name, float value)
  411. {
  412. byte[] flow = BitConverter.GetBytes(value);
  413. short high1 = BitConverter.ToInt16(flow, 0);
  414. short low1 = BitConverter.ToInt16(flow, 2);
  415. IO.AI[name].Buffer[IO.AI[name].Index] = BitConverter.ToInt16(flow, 0);
  416. IO.AI[name].Buffer[IO.AI[name].Index + 1] = BitConverter.ToInt16(flow, 2);
  417. byte[] high = BitConverter.GetBytes(IO.AI[name].Buffer[IO.AI[name].Index]);
  418. byte[] low = BitConverter.GetBytes(IO.AI[name].Buffer[IO.AI[name].Index + 1]);
  419. float readback = BitConverter.ToSingle(new[] { high[0], high[1], low[0], low[1] }, 0);
  420. }
  421. float GetAiValue(string name)
  422. {
  423. byte[] high = BitConverter.GetBytes(IO.AI[name].Buffer[IO.AI[name].Index]);
  424. byte[] low = BitConverter.GetBytes(IO.AI[name].Buffer[IO.AI[name].Index + 1]);
  425. float flow = BitConverter.ToSingle(new[] { high[0], high[1], low[0], low[1] }, 0);
  426. return flow;
  427. }
  428. float GetAoValue(string name)
  429. {
  430. byte[] high = BitConverter.GetBytes(IO.AO[name].Buffer[IO.AO[name].Index]);
  431. byte[] low = BitConverter.GetBytes(IO.AO[name].Buffer[IO.AO[name].Index + 1]);
  432. float flow = BitConverter.ToSingle(new[] { high[0], high[1], low[0], low[1] }, 0);
  433. return flow;
  434. }
  435. void MonitorTemperature(ModuleName mod)
  436. {
  437. IO.DI[$"{mod}.DI_Substrate_Heater_On_FB"].Value = IO.DO[$"{mod}.DO_Substrate_Heater_On"].Value;
  438. IO.DI[$"{mod}.DI_Foreline_Heater_On_FB"].Value = IO.DO[$"{mod}.DO_Forline_Heater_On"].Value;
  439. IO.DI[$"{mod}.DI_Foreline_TC_Deviation_out_of_range"].Value = false;
  440. IO.DI[$"{mod}.DI_Substrate_TC_Deviation_out_of_range"].Value = false;
  441. // 底座
  442. if (IO.DO[$"{mod}.DO_Substrate_Heater_On"].Value &&
  443. GetAiValue($"{mod}.AI_Substrate_Control_TC_Temp") < GetAoValue($"{mod}.AO_Substrate_Temperature_Setpoint"))
  444. {
  445. SetAiValue($"{mod}.AI_Substrate_Control_TC_Temp", GetAiValue($"{mod}.AI_Substrate_Control_TC_Temp") + _rd.Next(1, 2));
  446. SetAiValue($"{mod}.AI_Substrate_Monitor_TC_Temp", GetAiValue($"{mod}.AI_Substrate_Monitor_TC_Temp") + _rd.Next(1, 2));
  447. }
  448. else if (IO.DO[$"{mod}.DO_Substrate_Heater_On"].Value &&
  449. GetAiValue($"{mod}.AI_Substrate_Control_TC_Temp") > GetAoValue($"{mod}.AO_Substrate_Temperature_Setpoint"))
  450. {
  451. SetAiValue($"{mod}.AI_Substrate_Control_TC_Temp", GetAiValue($"{mod}.AI_Substrate_Control_TC_Temp") - _rd.Next(1, 2));
  452. SetAiValue($"{mod}.AI_Substrate_Monitor_TC_Temp", GetAiValue($"{mod}.AI_Substrate_Monitor_TC_Temp") - _rd.Next(1, 2));
  453. }
  454. // Foreline
  455. if (IO.DO[$"{mod}.DO_Forline_Heater_On"].Value &&
  456. GetAiValue($"{mod}.AI_Foreline_Control_TC_Temp") < GetAoValue($"{mod}.AO_Foreline_Temperature_Setpoint"))
  457. {
  458. SetAiValue($"{mod}.AI_Foreline_Control_TC_Temp", GetAiValue($"{mod}.AI_Foreline_Control_TC_Temp") + _rd.Next(1, 2));
  459. SetAiValue($"{mod}.AI_Foreline_Monitor_TC_Temp", GetAiValue($"{mod}.AI_Foreline_Monitor_TC_Temp") + _rd.Next(1, 2));
  460. }
  461. else if (IO.DO[$"{mod}.DO_Forline_Heater_On"].Value &&
  462. GetAiValue($"{mod}.AI_Foreline_Control_TC_Temp") > GetAoValue($"{mod}.AO_Foreline_Temperature_Setpoint"))
  463. {
  464. SetAiValue($"{mod}.AI_Foreline_Control_TC_Temp", GetAiValue($"{mod}.AI_Foreline_Control_TC_Temp") - _rd.Next(1, 2));
  465. SetAiValue($"{mod}.AI_Foreline_Monitor_TC_Temp", GetAiValue($"{mod}.AI_Foreline_Monitor_TC_Temp") - _rd.Next(1, 2));
  466. }
  467. }
  468. void MonitorGas(ModuleName mod)
  469. {
  470. // gas
  471. this.SimulateMFC(ModuleName.PMA, 1);
  472. this.SimulateMFC(ModuleName.PMA, 2);
  473. this.SimulateMFC(ModuleName.PMA, 3);
  474. this.SimulateMFC(ModuleName.PMA, 4);
  475. //this.SimulateMFC(ModuleName.PMB, 1);
  476. //this.SimulateMFC(ModuleName.PMB, 2);
  477. //this.SimulateMFC(ModuleName.PMB, 3);
  478. //this.SimulateMFC(ModuleName.PMB, 4);
  479. }
  480. private void SimulateMFC(ModuleName mod, byte gasNum)
  481. {
  482. var sp = GetAoValue($"{mod}.AO_MFC{gasNum}_Flow_Setpoint");
  483. var mock_fb = _rd.Next((int)sp - 3, (int)sp + 3) + _rd.NextDouble();
  484. SetAiValue($"{mod}.AI_MFC{gasNum}_Flow", (float)mock_fb);
  485. }
  486. void MonitorRF(ModuleName mod)
  487. {
  488. // RF generator
  489. //var sp = GetAoValue($"{mod}.AO_Generator_Power_Setpoint");
  490. //var mock_fb = _rd.Next((int)sp - 3, (int)sp + 3) + _rd.NextDouble();
  491. //var mock_sp = _rd.Next(sp - 3, sp + 3);
  492. //SetAiValue($"{mod}.AI_Generator_Forward_Power", (float)mock_fb);
  493. //IO.DI[$"{mod}.DI_Generator_Power_Status"].Value = IO.DO[$"{mod}.DO_Generator_Power_ON"].Value;
  494. }
  495. public void Terminate()
  496. {
  497. _thread.Stop();
  498. }
  499. }
  500. }