using System; using System.Collections.Generic; using Aitex.Core.Common.DeviceData; using Aitex.Core.RT.Device; using Aitex.Core.RT.Event; using Aitex.Core.RT.Fsm; using Aitex.Core.RT.Log; using Aitex.Core.RT.OperationCenter; using Aitex.Core.RT.RecipeCenter; using Aitex.Core.RT.SCCore; using Aitex.Core.Util; using Aitex.RT.FactoryAutomation; using Aitex.RT.Module; using Aitex.RT.Properties; using Aitex.Triton160.Common; using Aitex.Triton160.RT.Device; using Aitex.Triton160.RT.Module; namespace Aitex.RT { public class RTEntity : Singleton { private RouteManager rm = null; public RTEntity() { } public bool Initialize() { rm = Singleton.Instance; rm.Initialize(); RegisterMethod(); Singleton.Instance.OnAlarmEvent += new Action(Instance_OnAlarmEvent); Singleton.Instance.FireEvent += InstanceOnOnEvent; TestSuit(); return true; } private void InstanceOnOnEvent(EventItem obj) { Singleton.Instance.NotifyEvent(obj.EventEnum, obj.dvid); } void Instance_OnAlarmEvent(EventItem obj) { FSM_MSG msg = FSM_MSG.NONE; if (obj.Level == EventLevel.Warning) msg = FSM_MSG.WARNING; else if (obj.Level == EventLevel.Alarm) msg = FSM_MSG.ALARM; PostMsg(msg, obj.Id, obj.Description); } void RegisterMethod() { foreach (string s in Enum.GetNames(typeof(TritonOperation))) OP.Subscribe(s, this.Invoke); } public void Terminate() { if (rm != null) { rm.Terminate(); } } public bool Invoke(string cmd, params object[] args) { bool ret = true; string parameter = ""; if (args.Length == 0) parameter = "()"; else { parameter += "("; foreach (object o in args) { if (o == null) { parameter += "NULL,"; continue; } parameter += o.ToString(); parameter += ", "; } if (parameter.Length > 2) parameter = parameter.Remove(parameter.Length - 2, 2); parameter += ")"; } if (cmd != TritonOperation.Reset.ToString()) EV.PostMessage(ModuleName.System.ToString(), EventEnum.GeneralInfo, string.Format(Resources.RTEntity_Invoke_Operation01, cmd, parameter)); TritonOperation opType; if (!Enum.TryParse(cmd, true, out opType)) { EV.PostMessage(ModuleName.System.ToString(), EventEnum.GeneralInfo, string.Format(Resources.RTEntity_Invoke_UndefinedOperation0, cmd)); return false; } try { bool isAutoMode = Singleton.Instance.IsAutoMode; string reason = String.Empty; if (isAutoMode) { List lstMustInManual = new List() { TritonOperation.DeviceOperation, TritonOperation.GasFlow, TritonOperation.LeakCheck, TritonOperation.Pump, TritonOperation.Purge, TritonOperation.RfPower, TritonOperation.StopGasFlow, TritonOperation.StopPump, TritonOperation.Vent, }; reason = string.Format("System in auto mode, can not do {0}", opType.ToString()); if (lstMustInManual.Contains(opType)) { EV.PostMessage(ModuleName.System.ToString(), EventEnum.DefaultWarning, reason); return false; } } switch (opType) { case TritonOperation.DeviceOperation: { string name = (string)args[0]; string func = (string)args[1]; object[] param = new object[args.Length - 2]; for (int i = 2; i < args.Length; i++) param[i - 2] = args[i].ToString(); DeviceCmd(name, func, param); } break; case TritonOperation.Pump: { ret = PostMsg(PMEntity.MSG.PumpDown, out reason); } break; case TritonOperation.WaterFlowAlarm: { DEVICE.Do(string.Format("{0}.{1}", "MainPump", AITPumpOperation.WaterFlowAlarm), 0, true, args); } break; case TritonOperation.StopPump: { ret = PostMsg(PMEntity.MSG.StopPumpDown, out reason); } break; case TritonOperation.GasFlow: { ret = PostMsg(PMEntity.MSG.GasFlow, out reason, args); } break; case TritonOperation.StopGasFlow: { ret = PostMsg(PMEntity.MSG.StopGasFlow, out reason); } break; case TritonOperation.RfPower: { ret = PostMsg(PMEntity.MSG.RfPower, out reason, args); } break; case TritonOperation.Purge: { ret = PostMsg(PMEntity.MSG.CyclePurge, out reason); } break; case TritonOperation.Vent: { ret = PostMsg(PMEntity.MSG.Vent, out reason); } break; case TritonOperation.SetAutoMode: { ret = PostMsg(PMEntity.MSG.SetAutoMode, out reason); } break; case TritonOperation.SetManualMode: { ret = PostMsg(PMEntity.MSG.SetManualMode, out reason); } break; case TritonOperation.Abort: { ret = PostMsg(PMEntity.MSG.Abort, out reason); } break; case TritonOperation.SetConfig: { SC.SetItemValue((string)args[0], args[1]); if ((string)args[0] == SCName.System_Language) { RtApplication.UpdateCultureResource(((int)SC.GetItemValue(SCName.System_Language)) == 2 ? "zh-CN" : "en-US"); } } break; case TritonOperation.RunRecipe: { string recipeName = (string)args[0]; string lotName = (string)args[1]; string operation = args.Length > 2 ? (string)args[2] : ""; string operatorId= args.Length > 3 ? (string)args[3] : ""; var recipeContent = RecipeFileManager.Instance.LoadRecipe(ModuleName.System.ToString(), recipeName, true); if (string.IsNullOrEmpty(recipeContent)) { EV.PostMessage(ModuleName.System.ToString(), EventEnum.PrepareProcessErr, ModuleName.System.ToString(), string.Format(Resources.RTEntity_Invoke_ErrorDuringReadRecipeFile0, recipeName)); return false; // The recipe is invalide. } List reasons; if (!RecipeFileManager.Instance.CheckRecipe(ModuleName.System.ToString(), recipeContent, out reasons)) { EV.PostMessage(ModuleName.System.ToString(), EventEnum.PrepareProcessErr, ModuleName.System.ToString(), string.Format(Resources.RTEntity_Invoke_RecipeFileContentNotValid0, recipeName)); string info = ""; foreach (var item in reasons) info += item; EV.PostPopDialogMessage(EventLevel.Alarm, String.Format(Resources.RTEntity_Invoke_RecipeFileNotValid0, recipeName), info); return false; //Recipe content check. } ret = PostMsg(PMEntity.MSG.RunRecipe, out reason, recipeName, recipeContent, lotName, operation, operatorId); } break; case TritonOperation.SkipCurrentStep: { ret = PostMsg(PMEntity.MSG.RecipeSkipStep, out reason); } break; case TritonOperation.AbortRecipe: { ret = PostMsg(PMEntity.MSG.RciepeAbort, out reason); } break; case TritonOperation.LeakCheck: { ret = PostMsg(PMEntity.MSG.LeakCheck, out reason, args); } break; case TritonOperation.DeleteLeakCheck: { LeakCheckResultManager.Instance.Delete(args[0].ToString()); } break; case TritonOperation.Reset: { EV.ClearAlarmEvent(); ret = PostMsg(PMEntity.MSG.Reset, out reason); ret = PostMsg(DeviceEntity.MSG.RESET, out reason); } break; case TritonOperation.BuzzerOFF: { DeviceModel.SignalTower.BuzzerStop(); } break; } } catch (Exception ex) { LOG.Error(String.Format(Resources.RTEntity_Invoke_Invoke0Exception, cmd), ex); ret = false; } if (!ret) { return false; } return true; } private void PostMsg(TMsg msg, params object[] objs) where TEntity : class, IEntity, new() where TMsg : struct { Singleton.Instance.PostMsg(msg, objs); } private bool PostMsg(TMsg msg, out string reason, params object[] objs) where TEntity : class, IEntity, new() where TMsg : struct { if (!Singleton.Instance.Check(Convert.ToInt32(msg), out reason, objs)) { EV.PostMessage(ModuleName.System.ToString(), EventEnum.DefaultWarning, reason); return false; } Singleton.Instance.PostMsg(msg, objs); return true; } private void DeviceCmd(string name, string cmd, params object[] args) { DEVICE.Do(string.Format("{0}.{1}", name, cmd), 0, true, args); } private void TestSuit() { // string[] AOName = { // IOName.AO_Throttle_Vavle_work_mode_set, //IOName.AO_Throttle_valve_Pressure_setpoint , //IOName.AO_Throttle_valve_Position_setpoint , //IOName.AO_RF_work_mode_set, //IOName.AO_RF_power_setpoint, //IOName.AO_RF_Pulsing_Frequency_setpoint , //IOName.AO_RF_Pulsing_duty_cycle_setpoint , //IOName.AO_MFC1_flow_setpoint , //IOName.AO_MFC2_flow_setpoint , //IOName.AO_MFC3_flow_setpoint , //IOName.AO_MFC4_flow_setpoint , //IOName.AO_MFC5_flow_setpoint , //IOName.AO_Vapor_MFC_flow_setpoint , //IOName.AO_precursor_temp_setpoint , //IOName.AO_pump_line_temp_setpoint , //}; //for (int i = 0; i < AOName.Length; i++) //{ // string name = AOName[i]; // IO.AO[name].Value = 1.0f * i; //} } } }