RTEntity.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. using System;
  2. using System.Collections.Generic;
  3. using Aitex.Core.Common.DeviceData;
  4. using Aitex.Core.RT.Device;
  5. using Aitex.Core.RT.Event;
  6. using Aitex.Core.RT.Fsm;
  7. using Aitex.Core.RT.Log;
  8. using Aitex.Core.RT.OperationCenter;
  9. using Aitex.Core.RT.RecipeCenter;
  10. using Aitex.Core.RT.SCCore;
  11. using Aitex.Core.Util;
  12. using Aitex.RT.FactoryAutomation;
  13. using Aitex.RT.Module;
  14. using Aitex.RT.Properties;
  15. using Aitex.Triton160.Common;
  16. using Aitex.Triton160.RT.Device;
  17. using Aitex.Triton160.RT.Module;
  18. namespace Aitex.RT
  19. {
  20. public class RTEntity : Singleton<RTEntity>
  21. {
  22. private RouteManager rm = null;
  23. public RTEntity()
  24. {
  25. }
  26. public bool Initialize()
  27. {
  28. rm = Singleton<RouteManager>.Instance;
  29. rm.Initialize();
  30. RegisterMethod();
  31. Singleton<EventManager>.Instance.OnAlarmEvent += new Action<EventItem>(Instance_OnAlarmEvent);
  32. Singleton<EventManager>.Instance.FireEvent += InstanceOnOnEvent;
  33. TestSuit();
  34. return true;
  35. }
  36. private void InstanceOnOnEvent(EventItem obj)
  37. {
  38. Singleton<FaManager>.Instance.NotifyEvent(obj.EventEnum, obj.dvid);
  39. }
  40. void Instance_OnAlarmEvent(EventItem obj)
  41. {
  42. FSM_MSG msg = FSM_MSG.NONE;
  43. if (obj.Level == EventLevel.Warning)
  44. msg = FSM_MSG.WARNING;
  45. else if (obj.Level == EventLevel.Alarm)
  46. msg = FSM_MSG.ALARM;
  47. PostMsg<PMEntity, FSM_MSG>(msg, obj.Id, obj.Description);
  48. }
  49. void RegisterMethod()
  50. {
  51. foreach (string s in Enum.GetNames(typeof(TritonOperation)))
  52. OP.Subscribe(s, this.Invoke);
  53. }
  54. public void Terminate()
  55. {
  56. if (rm != null)
  57. {
  58. rm.Terminate();
  59. }
  60. }
  61. public bool Invoke(string cmd, params object[] args)
  62. {
  63. bool ret = true;
  64. string parameter = "";
  65. if (args.Length == 0)
  66. parameter = "()";
  67. else
  68. {
  69. parameter += "(";
  70. foreach (object o in args)
  71. {
  72. if (o == null)
  73. {
  74. parameter += "NULL,";
  75. continue;
  76. }
  77. parameter += o.ToString();
  78. parameter += ", ";
  79. }
  80. if (parameter.Length > 2)
  81. parameter = parameter.Remove(parameter.Length - 2, 2);
  82. parameter += ")";
  83. }
  84. if (cmd != TritonOperation.Reset.ToString())
  85. EV.PostMessage(ModuleName.System.ToString(), EventEnum.GeneralInfo, string.Format(Resources.RTEntity_Invoke_Operation01, cmd, parameter));
  86. TritonOperation opType;
  87. if (!Enum.TryParse(cmd, true, out opType))
  88. {
  89. EV.PostMessage(ModuleName.System.ToString(), EventEnum.GeneralInfo, string.Format(Resources.RTEntity_Invoke_UndefinedOperation0, cmd));
  90. return false;
  91. }
  92. try
  93. {
  94. bool isAutoMode = Singleton<PMEntity>.Instance.IsAutoMode;
  95. string reason = String.Empty;
  96. if (isAutoMode)
  97. {
  98. List<TritonOperation> lstMustInManual = new List<TritonOperation>()
  99. {
  100. TritonOperation.DeviceOperation,
  101. TritonOperation.GasFlow,
  102. TritonOperation.LeakCheck,
  103. TritonOperation.Pump,
  104. TritonOperation.Purge,
  105. TritonOperation.RfPower,
  106. TritonOperation.StopGasFlow,
  107. TritonOperation.StopPump,
  108. TritonOperation.Vent,
  109. };
  110. reason = string.Format("System in auto mode, can not do {0}", opType.ToString());
  111. if (lstMustInManual.Contains(opType))
  112. {
  113. EV.PostMessage(ModuleName.System.ToString(), EventEnum.DefaultWarning, reason);
  114. return false;
  115. }
  116. }
  117. switch (opType)
  118. {
  119. case TritonOperation.DeviceOperation:
  120. {
  121. string name = (string)args[0];
  122. string func = (string)args[1];
  123. object[] param = new object[args.Length - 2];
  124. for (int i = 2; i < args.Length; i++)
  125. param[i - 2] = args[i].ToString();
  126. DeviceCmd(name, func, param);
  127. }
  128. break;
  129. case TritonOperation.Pump:
  130. {
  131. ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.PumpDown, out reason);
  132. }
  133. break;
  134. case TritonOperation.WaterFlowAlarm:
  135. {
  136. DEVICE.Do(string.Format("{0}.{1}", "MainPump", AITPumpOperation.WaterFlowAlarm), 0, true, args);
  137. }
  138. break;
  139. case TritonOperation.StopPump:
  140. {
  141. ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.StopPumpDown, out reason);
  142. }
  143. break;
  144. case TritonOperation.GasFlow:
  145. {
  146. ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.GasFlow, out reason, args);
  147. }
  148. break;
  149. case TritonOperation.StopGasFlow:
  150. {
  151. ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.StopGasFlow, out reason);
  152. }
  153. break;
  154. case TritonOperation.RfPower:
  155. {
  156. ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.RfPower, out reason, args);
  157. }
  158. break;
  159. case TritonOperation.Purge:
  160. {
  161. ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.CyclePurge, out reason);
  162. }
  163. break;
  164. case TritonOperation.Vent:
  165. {
  166. ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.Vent, out reason);
  167. }
  168. break;
  169. case TritonOperation.SetAutoMode:
  170. {
  171. ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.SetAutoMode, out reason);
  172. }
  173. break;
  174. case TritonOperation.SetManualMode:
  175. {
  176. ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.SetManualMode, out reason);
  177. }
  178. break;
  179. case TritonOperation.Abort:
  180. {
  181. ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.Abort, out reason);
  182. }
  183. break;
  184. case TritonOperation.SetConfig:
  185. {
  186. SC.SetItemValue((string)args[0], args[1]);
  187. if ((string)args[0] == SCName.System_Language)
  188. {
  189. RtApplication.UpdateCultureResource(((int)SC.GetItemValue(SCName.System_Language)) == 2 ? "zh-CN" : "en-US");
  190. }
  191. }
  192. break;
  193. case TritonOperation.RunRecipe:
  194. {
  195. string recipeName = (string)args[0];
  196. string lotName = (string)args[1];
  197. string operation = args.Length > 2 ? (string)args[2] : "";
  198. string operatorId= args.Length > 3 ? (string)args[3] : "";
  199. var recipeContent = RecipeFileManager.Instance.LoadRecipe(ModuleName.System.ToString(), recipeName, true);
  200. if (string.IsNullOrEmpty(recipeContent))
  201. {
  202. EV.PostMessage(ModuleName.System.ToString(), EventEnum.PrepareProcessErr, ModuleName.System.ToString(), string.Format(Resources.RTEntity_Invoke_ErrorDuringReadRecipeFile0, recipeName));
  203. return false; // The recipe is invalide.
  204. }
  205. List<string> reasons;
  206. if (!RecipeFileManager.Instance.CheckRecipe(ModuleName.System.ToString(), recipeContent, out reasons))
  207. {
  208. EV.PostMessage(ModuleName.System.ToString(), EventEnum.PrepareProcessErr, ModuleName.System.ToString(), string.Format(Resources.RTEntity_Invoke_RecipeFileContentNotValid0, recipeName));
  209. string info = "";
  210. foreach (var item in reasons)
  211. info += item;
  212. EV.PostPopDialogMessage(EventLevel.Alarm, String.Format(Resources.RTEntity_Invoke_RecipeFileNotValid0, recipeName), info);
  213. return false; //Recipe content check.
  214. }
  215. ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.RunRecipe, out reason, recipeName, recipeContent, lotName, operation, operatorId);
  216. }
  217. break;
  218. case TritonOperation.SkipCurrentStep:
  219. {
  220. ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.RecipeSkipStep, out reason);
  221. }
  222. break;
  223. case TritonOperation.AbortRecipe:
  224. {
  225. ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.RciepeAbort, out reason);
  226. }
  227. break;
  228. case TritonOperation.LeakCheck:
  229. {
  230. ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.LeakCheck, out reason, args);
  231. }
  232. break;
  233. case TritonOperation.DeleteLeakCheck:
  234. {
  235. LeakCheckResultManager.Instance.Delete(args[0].ToString());
  236. }
  237. break;
  238. case TritonOperation.Reset:
  239. {
  240. EV.ClearAlarmEvent();
  241. ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.Reset, out reason);
  242. ret = PostMsg<DeviceEntity, DeviceEntity.MSG>(DeviceEntity.MSG.RESET, out reason);
  243. }
  244. break;
  245. case TritonOperation.BuzzerOFF:
  246. {
  247. DeviceModel.SignalTower.BuzzerStop();
  248. }
  249. break;
  250. }
  251. }
  252. catch (Exception ex)
  253. {
  254. LOG.Error(String.Format(Resources.RTEntity_Invoke_Invoke0Exception, cmd), ex);
  255. ret = false;
  256. }
  257. if (!ret)
  258. {
  259. return false;
  260. }
  261. return true;
  262. }
  263. private void PostMsg<TEntity, TMsg>(TMsg msg, params object[] objs)
  264. where TEntity : class, IEntity, new()
  265. where TMsg : struct
  266. {
  267. Singleton<TEntity>.Instance.PostMsg(msg, objs);
  268. }
  269. private bool PostMsg<TEntity, TMsg>(TMsg msg, out string reason, params object[] objs)
  270. where TEntity : class, IEntity, new()
  271. where TMsg : struct
  272. {
  273. if (!Singleton<TEntity>.Instance.Check(Convert.ToInt32(msg), out reason, objs))
  274. {
  275. EV.PostMessage(ModuleName.System.ToString(), EventEnum.DefaultWarning, reason);
  276. return false;
  277. }
  278. Singleton<TEntity>.Instance.PostMsg(msg, objs);
  279. return true;
  280. }
  281. private void DeviceCmd(string name, string cmd, params object[] args)
  282. {
  283. DEVICE.Do(string.Format("{0}.{1}", name, cmd), 0, true, args);
  284. }
  285. private void TestSuit()
  286. {
  287. // string[] AOName = {
  288. // IOName.AO_Throttle_Vavle_work_mode_set,
  289. //IOName.AO_Throttle_valve_Pressure_setpoint ,
  290. //IOName.AO_Throttle_valve_Position_setpoint ,
  291. //IOName.AO_RF_work_mode_set,
  292. //IOName.AO_RF_power_setpoint,
  293. //IOName.AO_RF_Pulsing_Frequency_setpoint ,
  294. //IOName.AO_RF_Pulsing_duty_cycle_setpoint ,
  295. //IOName.AO_MFC1_flow_setpoint ,
  296. //IOName.AO_MFC2_flow_setpoint ,
  297. //IOName.AO_MFC3_flow_setpoint ,
  298. //IOName.AO_MFC4_flow_setpoint ,
  299. //IOName.AO_MFC5_flow_setpoint ,
  300. //IOName.AO_Vapor_MFC_flow_setpoint ,
  301. //IOName.AO_precursor_temp_setpoint ,
  302. //IOName.AO_pump_line_temp_setpoint ,
  303. //};
  304. //for (int i = 0; i < AOName.Length; i++)
  305. //{
  306. // string name = AOName[i];
  307. // IO.AO[name].Value = 1.0f * i;
  308. //}
  309. }
  310. }
  311. }