SimulatorTriton160.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Aitex.Core.RT.Device.Unit;
  6. using Aitex.Core.RT.IOCore;
  7. using Aitex.Core.RT.Log;
  8. using Aitex.Core.RT.Simulator;
  9. using Aitex.Core.Util;
  10. using Aitex.Triton160.RT.PLC;
  11. using Aitex.Triton160.RT.Simulator;
  12. namespace Aitex.Jet.RT.Simulator
  13. {
  14. class SimulatorTriton160 : ISimulatorManager
  15. {
  16. private Random _rd = new Random();
  17. private PeriodicJob _thread;
  18. SimulatorBuffer _bufferLocal = new SimulatorBuffer();
  19. public SimulatorTriton160()
  20. {
  21. _bufferLocal.Initialize(Singleton<IOGroupManager>.Instance.GetIONameList("local", IOType.DI),
  22. Singleton<IOGroupManager>.Instance.GetIONameList("local", IOType.DO),
  23. Singleton<IOGroupManager>.Instance.GetIONameList("local", IOType.AI),
  24. Singleton<IOGroupManager>.Instance.GetIONameList("local", IOType.AO));
  25. SimulatorCaseManager.Instance.Initialize();
  26. SetDefaultValue();
  27. _thread = new PeriodicJob(200, Monitor, "SimulatorTriton160", true);
  28. }
  29. public object Read(string type)
  30. {
  31. if (type == "local")
  32. return _bufferLocal.Input;
  33. return null;
  34. }
  35. public bool Write(string type, PLC_OUTPUT_DATA buffer)
  36. {
  37. if (type == "local")
  38. return _bufferLocal.Write(buffer);
  39. return true;
  40. }
  41. private bool Monitor()
  42. {
  43. foreach (var forces in DiForce.Instance.ForceValues)
  44. {
  45. _bufferLocal.SetDI(forces.Key, forces.Value ? (byte)1 : (byte)0);
  46. }
  47. foreach (var forces in AiForce.Instance.ForceValues)
  48. {
  49. _bufferLocal.SetAI(forces.Key, forces.Value);
  50. }
  51. try
  52. {
  53. MonitorValve();
  54. MonitorRf();
  55. MonitorPressure();
  56. MonitorFlowRamp();
  57. MonitorDryPump();
  58. MonitorSensor();
  59. MonitorSystem();
  60. }
  61. catch (Exception ex)
  62. {
  63. LOG.Write(ex);
  64. }
  65. return true;
  66. }
  67. private void MonitorSystem()
  68. {
  69. if (!ExceptionCase.ExLostHeartBeat)
  70. {
  71. _bufferLocal.SetAI(IoNameTriton160.AI_heartbeat_fb, _bufferLocal.GetAO(IoNameTriton160.AO_heartbeat));
  72. }
  73. //_bufferLocal.SetDI(IoNameTriton160.DI_pump_door_sw, ExceptionCase.ExPumpDoorOpened ? (byte)0 : (byte)1);
  74. //_bufferLocal.SetDI(IoNameTriton160.DI_back_panle_door_sw, ExceptionCase.ExBackPanelDoorOpened ? (byte)0 : (byte)1);
  75. _bufferLocal.SetDI(IoNameTriton160.DI_Chamber_door_sw, ExceptionCase.ExChamberDoorOpend ? (byte)0 : (byte)1);
  76. _bufferLocal.SetDI(IoNameTriton160.DI_Main_conctactor, ExceptionCase.ExMainContactorOff ? (byte)0 : (byte)1);
  77. _bufferLocal.SetDI(IoNameTriton160.DI_EMG_stop_botton, ExceptionCase.ExEmoButtonPushed ? (byte)1 : (byte)0);
  78. var signalLight = new List<Tuple<string, string>>
  79. {
  80. new Tuple<string, string>(IoNameTriton160.DI_Red_light_fb, IoNameTriton160.DO_Red_light),
  81. new Tuple<string, string>(IoNameTriton160.DI_Green_light_fb, IoNameTriton160.DO_Green_light),
  82. new Tuple<string, string>(IoNameTriton160.DI_Yellow_light_fb, IoNameTriton160.DO_Yellow_light),
  83. new Tuple<string, string>(IoNameTriton160.DI_Buzzer_fb, IoNameTriton160.DO_Buzzer),
  84. };
  85. foreach (var s in signalLight)
  86. {
  87. _bufferLocal.SetDI(s.Item1, _bufferLocal.GetDO(s.Item2));
  88. }
  89. _bufferLocal.SetAI(IoNameTriton160.AI_Time, DateTime.Now.Hour);
  90. _bufferLocal.SetAI(IoNameTriton160.AI_Minute, DateTime.Now.Minute);
  91. _bufferLocal.SetAI(IoNameTriton160.AI_Second, DateTime.Now.Second);
  92. }
  93. void SetDefaultValue()
  94. {
  95. _bufferLocal.SetAI(IoNameTriton160.AI_Thorttle_valve_real_position_fb, 100);
  96. _bufferLocal.SetAI(IoNameTriton160.AI_Chamber_real_pressure_fb_, 50000);
  97. _bufferLocal.SetAI(IoNameTriton160.AI_Year, DateTime.Now.Year - IoPlcDateTime.YEAR_OFFSET);
  98. _bufferLocal.SetAI(IoNameTriton160.AI_Month, DateTime.Now.Month);
  99. _bufferLocal.SetAI(IoNameTriton160.AI_Day, DateTime.Now.Day);
  100. _bufferLocal.SetDI(IoNameTriton160.DI_Main_conctactor, 1);
  101. _bufferLocal.SetDI(IoNameTriton160.DI_RF_hardware_interlock, 1);
  102. _bufferLocal.SetDI(IoNameTriton160.DI_Chamber_door_sw, 1);
  103. //_bufferLocal.SetDI(IoNameTriton160.DI_pump_door_sw, 1);
  104. //_bufferLocal.SetDI(IoNameTriton160.DI_back_panle_door_sw, 1);
  105. _bufferLocal.SetAI(IoNameTriton160.AI_thorttle_valve_state, 1);
  106. _bufferLocal.SetDI(IoNameTriton160.DI_Lever1_pump_running, 1);
  107. _bufferLocal.SetAI(IoNameTriton160.AI_Lever1_pump__water_flow_fb, 30);
  108. _bufferLocal.SetAI(IoNameTriton160.AI_match_work_mode_fb, 0);
  109. _bufferLocal.SetAI(IoNameTriton160.AI_match_hold_or_preset_fb, 0);
  110. }
  111. #region valve
  112. void MonitorValve()
  113. {
  114. var valveList = new List<Tuple<string, string>>
  115. {
  116. new Tuple<string, string>(
  117. IoNameTriton160.DI_MFC1_valve_state_fb,
  118. IoNameTriton160.DO_MFC1_valve__
  119. ),
  120. new Tuple<string, string>(
  121. IoNameTriton160.DI_MFC2_valve_state_fb,
  122. IoNameTriton160.DO_MFC2_valve
  123. ),
  124. new Tuple<string, string>(
  125. IoNameTriton160.DI_MFC3_valve_state_fb,
  126. IoNameTriton160.DO_MFC3_valve
  127. ),
  128. new Tuple<string, string>(
  129. IoNameTriton160.DI_MFC4_valve_state_fb,
  130. IoNameTriton160.DO_MFC4_valve
  131. ),
  132. new Tuple<string, string>(
  133. IoNameTriton160.DI_MFC5_valve_state_fb,
  134. IoNameTriton160.DO_MFC5_valve
  135. ),
  136. new Tuple<string, string>(
  137. IoNameTriton160.DI_Chamber_purge_valve_state_fb,
  138. IoNameTriton160.DO_Chamber_purge_valve
  139. ),
  140. new Tuple<string, string>(
  141. IoNameTriton160.DI_Process_gas_final_valve_state_fb,
  142. IoNameTriton160.DO_Process_gas_final_valve
  143. ),
  144. new Tuple<string, string>(
  145. IoNameTriton160.DI_Pumping_valve_state_fb,
  146. IoNameTriton160.DO_Pumping_valve_
  147. ),
  148. new Tuple<string, string>(
  149. IoNameTriton160.DI_Chamber_vent_valve_state_fb,
  150. IoNameTriton160.DO_Chamber_vent_valve
  151. ),
  152. };
  153. foreach (var valve in valveList)
  154. {
  155. _bufferLocal.SetDI(valve.Item1, _bufferLocal.GetDO(valve.Item2));
  156. }
  157. }
  158. #endregion
  159. void MonitorPressure()
  160. {
  161. bool IsPumpingValveOpen = _bufferLocal.GetDI(IoNameTriton160.DI_Pumping_valve_state_fb) == 1;
  162. bool IsPurgeValveOpen = _bufferLocal.GetDI(IoNameTriton160.DI_Chamber_purge_valve_state_fb) == 1;
  163. bool IsGasFinalValveOpen = _bufferLocal.GetDI(IoNameTriton160.DI_Process_gas_final_valve_state_fb) == 1;
  164. bool IsVentValveOpen = _bufferLocal.GetDI(IoNameTriton160.DI_Chamber_vent_valve_state_fb) == 1;
  165. bool IsPumpOn = _bufferLocal.GetDI(IoNameTriton160.DI_Lever1_pump_running) == 1;
  166. double pressureStep = (750000.0 / 5.0) / 30.0;
  167. if (IsPumpOn && IsPumpingValveOpen)
  168. {
  169. double pressure = _bufferLocal.GetAI(IoNameTriton160.AI_Chamber_real_pressure_fb_);
  170. pressure -= pressureStep;
  171. if (pressure < 100)
  172. pressure = 100;
  173. pressure += (_rd.Next(0, 20) - 10);
  174. _bufferLocal.SetAI(IoNameTriton160.AI_Chamber_real_pressure_fb_, (float)pressure);
  175. }
  176. if ((IsPurgeValveOpen && IsGasFinalValveOpen) || IsVentValveOpen)
  177. {
  178. double pressure = _bufferLocal.GetAI(IoNameTriton160.AI_Chamber_real_pressure_fb_);
  179. pressure += pressureStep;
  180. if (pressure > 756000)
  181. pressure = 756000;
  182. pressure += (_rd.Next(0, 20) - 10);
  183. _bufferLocal.SetAI(IoNameTriton160.AI_Chamber_real_pressure_fb_, (float)pressure);
  184. }
  185. }
  186. void MonitorFlowRamp()
  187. {
  188. var rampList = new List<Tuple<string, string>>
  189. {
  190. new Tuple<string, string>(
  191. IoNameTriton160.AI_MFC1_real_flow__fb,
  192. IoNameTriton160.AO_MFC1_flow_setpoint
  193. ),
  194. new Tuple<string, string>(
  195. IoNameTriton160.AI_MFC2_real_flow_fb,
  196. IoNameTriton160.AO_MFC2_flow_setpoint
  197. ),
  198. new Tuple<string, string>(
  199. IoNameTriton160.AI_MFC3_real_flow_fb,
  200. IoNameTriton160.AO_MFC3_flow_setpoint
  201. ),
  202. new Tuple<string, string>(
  203. IoNameTriton160.AI_MFC4_real_flow_fb,
  204. IoNameTriton160.AO_MFC4_flow_setpoint
  205. ),
  206. new Tuple<string, string>(
  207. IoNameTriton160.AI_MFC5_real_flow_fb,
  208. IoNameTriton160.AO_MFC5_flow_setpoint
  209. ),
  210. };
  211. foreach (var item in rampList)
  212. {
  213. float setpoint = 0;
  214. float result = 0;
  215. float current = 0;
  216. if (_bufferLocal.FindAI(item.Item1) != null)
  217. {
  218. current = _bufferLocal.GetAI(item.Item1);
  219. setpoint = _bufferLocal.GetAO(item.Item2);
  220. }
  221. else if (_bufferLocal.FindAI(item.Item1) != null)
  222. {
  223. current = _bufferLocal.GetAI(item.Item1);
  224. setpoint = _bufferLocal.GetAO(item.Item2);
  225. }
  226. if (current > setpoint)
  227. {
  228. result = current - 20;
  229. if (result < setpoint)
  230. result = setpoint;
  231. }
  232. if (current < setpoint)
  233. {
  234. result = current + 20;
  235. if (result > setpoint)
  236. result = setpoint;
  237. }
  238. result = result + (float)_rd.NextDouble();
  239. _bufferLocal.SetAI(item.Item1, result);
  240. _bufferLocal.SetAI(item.Item1, result);
  241. }
  242. }
  243. #region RF
  244. void MonitorRf()
  245. {
  246. _bufferLocal.SetDI(IoNameTriton160.DI_RF_power_state_fb, _bufferLocal.GetDO(IoNameTriton160.DO_RF_on_off));
  247. _bufferLocal.SetAI(IoNameTriton160.AI_match_work_mode_fb, _bufferLocal.GetAO(IoNameTriton160.AO_match_work_mode_setpoint));
  248. _bufferLocal.SetAI(IoNameTriton160.AI_match_hold_or_preset_fb, _bufferLocal.GetAO(IoNameTriton160.AO_match_hold_or_preset_setpoint));
  249. _bufferLocal.SetAI(IoNameTriton160.AI_match_c1_positon_fb, _bufferLocal.GetAO(IoNameTriton160.AO_match_C1_position_setpoint));
  250. _bufferLocal.SetAI(IoNameTriton160.AI_match_c2_positon_fb, _bufferLocal.GetAO(IoNameTriton160.AO_match_C2_position_setpoint));
  251. float setpoint = _bufferLocal.GetAO(IoNameTriton160.AO_RF_power_setpoint);
  252. bool isOn = _bufferLocal.GetDI(IoNameTriton160.DI_RF_power_state_fb) == 1;
  253. if (!isOn)
  254. {
  255. _bufferLocal.SetAI(IoNameTriton160.AI_RF_forward_power_fb, 0);
  256. _bufferLocal.SetAI(IoNameTriton160.AI_RF_reflect_power_fb, 0);
  257. return;
  258. }
  259. double step = (900.0 / 5.0) / 10.0;
  260. double feedback = _bufferLocal.GetAI(IoNameTriton160.AI_RF_forward_power_fb);
  261. feedback += step;
  262. if (feedback > setpoint * 0.9)
  263. feedback = (setpoint * 0.9);
  264. _bufferLocal.SetAI(IoNameTriton160.AI_RF_forward_power_fb, (float)feedback);
  265. double step1 = (100.0 / 5.0) / 10.0;
  266. feedback = _bufferLocal.GetAI(IoNameTriton160.AI_RF_reflect_power_fb);
  267. feedback = feedback + step1;
  268. if (feedback > setpoint * 0.1)
  269. feedback = (float)(setpoint * 0.1);
  270. _bufferLocal.SetAI(IoNameTriton160.AI_RF_reflect_power_fb, (float)feedback);
  271. }
  272. #endregion
  273. void MonitorDryPump()
  274. {
  275. _bufferLocal.SetDI(IoNameTriton160.DI_Lever1_pump_start_bt, 1);
  276. _bufferLocal.SetDI(IoNameTriton160.DI_Lever1_pump_stop_bt, 0);
  277. _bufferLocal.SetAI(IoNameTriton160.AI_Lever1_N2_pressure_fb, (float)(_rd.NextDouble()));
  278. _bufferLocal.SetAI(IoNameTriton160.AI_Lever1_pump__water_flow_fb, (float)(80 + _rd.Next(5) + _rd.NextDouble()));
  279. }
  280. private void MonitorSensor()
  281. {
  282. int simValue = (int)_bufferLocal.GetAO(IoNameTriton160.AO_match_C1_position_setpoint);
  283. if (simValue == 51)
  284. {
  285. _bufferLocal.SetDI(IoNameTriton160.DI_Lever1_pump_overload, 1);
  286. }
  287. if (simValue == 52)
  288. {
  289. //_bufferLocal.SetDI(IoNameTriton160.DI_booster_inv_alarm, 1);
  290. }
  291. if (simValue == 59)
  292. {
  293. _bufferLocal.SetDI(IoNameTriton160.DI_Pump_N2_pressure_alam, 1);
  294. _bufferLocal.SetDI(IoNameTriton160.DI_Pump_water_flow_alam, 1);
  295. }
  296. }
  297. }
  298. }