123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384 |
- 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<RTEntity>
- {
- private RouteManager rm = null;
- public RTEntity()
- {
- }
- public bool Initialize()
- {
- rm = Singleton<RouteManager>.Instance;
- rm.Initialize();
- RegisterMethod();
- Singleton<EventManager>.Instance.OnAlarmEvent += new Action<EventItem>(Instance_OnAlarmEvent);
- Singleton<EventManager>.Instance.FireEvent += InstanceOnOnEvent;
- TestSuit();
- return true;
- }
- private void InstanceOnOnEvent(EventItem obj)
- {
- Singleton<FaManager>.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<PMEntity, FSM_MSG>(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<PMEntity>.Instance.IsAutoMode;
- string reason = String.Empty;
- if (isAutoMode)
- {
- List<TritonOperation> lstMustInManual = new List<TritonOperation>()
- {
- 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, PMEntity.MSG>(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, PMEntity.MSG>(PMEntity.MSG.StopPumpDown, out reason);
- }
- break;
- case TritonOperation.GasFlow:
- {
- ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.GasFlow, out reason, args);
- }
- break;
- case TritonOperation.StopGasFlow:
- {
- ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.StopGasFlow, out reason);
- }
- break;
- case TritonOperation.RfPower:
- {
- ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.RfPower, out reason, args);
- }
- break;
- case TritonOperation.Purge:
- {
- ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.CyclePurge, out reason);
- }
- break;
- case TritonOperation.Vent:
- {
- ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.Vent, out reason);
- }
- break;
- case TritonOperation.SetAutoMode:
- {
- ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.SetAutoMode, out reason);
- }
- break;
- case TritonOperation.SetManualMode:
- {
- ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.SetManualMode, out reason);
- }
- break;
- case TritonOperation.Abort:
- {
- ret = PostMsg<PMEntity, PMEntity.MSG>(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<string> 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, PMEntity.MSG>(PMEntity.MSG.RunRecipe, out reason, recipeName, recipeContent, lotName, operation, operatorId);
- }
- break;
- case TritonOperation.SkipCurrentStep:
- {
- ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.RecipeSkipStep, out reason);
- }
- break;
- case TritonOperation.AbortRecipe:
- {
- ret = PostMsg<PMEntity, PMEntity.MSG>(PMEntity.MSG.RciepeAbort, out reason);
- }
- break;
- case TritonOperation.LeakCheck:
- {
- ret = PostMsg<PMEntity, PMEntity.MSG>(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, PMEntity.MSG>(PMEntity.MSG.Reset, out reason);
- ret = PostMsg<DeviceEntity, DeviceEntity.MSG>(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<TEntity, TMsg>(TMsg msg, params object[] objs)
- where TEntity : class, IEntity, new()
- where TMsg : struct
- {
- Singleton<TEntity>.Instance.PostMsg(msg, objs);
- }
- private bool PostMsg<TEntity, TMsg>(TMsg msg, out string reason, params object[] objs)
- where TEntity : class, IEntity, new()
- where TMsg : struct
- {
- if (!Singleton<TEntity>.Instance.Check(Convert.ToInt32(msg), out reason, objs))
- {
- EV.PostMessage(ModuleName.System.ToString(), EventEnum.DefaultWarning, reason);
- return false;
- }
- Singleton<TEntity>.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;
- //}
- }
- }
- }
|