1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.Linq;
- using System.Threading;
- using Aitex.Core.Common;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Device.Unit;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Fsm;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.OperationCenter;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Util;
- using EFEM.RT.Devices;
- using EFEM.RT.Modules;
- using EFEM.RT.Tasks;
- using Aitex.Sorter.Common;
- using Efem;
- using Efem.Protocol;
- using EFEMSC;
- using MECF.Framework.Common.Device.Bases;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.SubstrateTrackings;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
- using IEntity = Aitex.Core.RT.Fsm.IEntity;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.BufferStations;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots;
- namespace EFEM.RT
- {
- public class EfemModuleStatus
- {
- private bool _isInitialized;
- public bool IsInitialized
- {
- get
- {
- return _isInitialized;
- }
- set
- {
- _isInitialized = value;
- TrigInitialized.CLK = value;
- }
- }
- public R_TRIG TrigInitialized { get; set; }
- public ModuleName Module { get; set; }
- public EfemModuleStatus(ModuleName module)
- {
- Module = module;
- TrigInitialized = new R_TRIG();
- }
- }
- public class EfemEntity : Entity, IEntity, IServerCallback
- {
- public enum ServerState
- {
- Init,
- Listening,
- Connected,
- }
- public enum MSG
- {
- Online,
- Offline,
- NewSessionConnected,
- Listening,
- Reset,
- Error,
- Disconnect,
- ReceiveData,
- SendData,
- }
- private SocketServer _socket = null;
- private string _sessionId;
- private List<ITaskT> _activeTaskList = new List<ITaskT>();
- private TaskFactory _factory = new TaskFactory();
- public string Name { get; set; }
- public bool IsCommunicationOk { get; set; }
- public bool IsOnlineMode { get; private set; }
- private bool IsSystemHold { get; set; }
- DeviceTimer _sendReadyTimer = new DeviceTimer();
- private List<ModuleName> LPs;
- private List<string> LLs;
- private Dictionary<ModuleName, RD_TRIG> _trigLpPresent = new Dictionary<ModuleName, RD_TRIG>();
- private Dictionary<string, Tuple<uint, uint>> _sigData = new Dictionary<string, Tuple<uint, uint>>();
- private Dictionary<ModuleName, EfemModuleStatus> _efemModuleStatus = new Dictionary<ModuleName, EfemModuleStatus>();
- private readonly bool _MaintenanceMode = DeviceDefineManager.Instance.GetValue<bool>("MaintenanceSignal") ?? false;
- private readonly bool _EfemDoorOpen = DeviceDefineManager.Instance.GetValue<bool>("EfemDoorOpenSignal") ?? false;
- public EfemEntity()
- {
- Name = "Efem";
- IsOnlineMode = true;
- LPs = new List<ModuleName>(Singleton<DeviceManager>.Instance.LpNames);
- foreach (var moduleName in LPs)
- {
- _trigLpPresent[moduleName] = new RD_TRIG();
- }
- LLs = new List<string>(Singleton<DeviceManager>.Instance.LLNames);
- int port = 13000;
- if (!SC.ContainsItem("System.EfemPortNumber"))
- {
- LOG.Write("Not define System.EfemPortNumber");
- }
- else
- {
- port = SC.GetValue<int>("System.EfemPortNumber");
- }
- _socket = new SocketServer(this, port);
- fsm = new StateMachine<EfemEntity>(Name, (int)ServerState.Init, 50);
- Singleton<EventManager>.Instance.OnEvent += Instance_OnEvent;
- _eventError = new FixSizeQueue<EventItem>(100);
- BuildTransitionTable();
- Subscribe();
- }
- public FixSizeQueue<EventItem> EventError
- {
- get { return _eventError;}
- }
- private bool IsErrorReportEnable
- {
- get
- {
- if (SC.ContainsItem("System.IsErrorReportEnable"))
- return SC.GetValue<bool>("System.IsErrorReportEnable");
- return false;
- }
- }
- public string EFemNum
- {
- get
- {
- if (SC.ContainsItem("System.EFEMNUM"))
- return SC.GetStringValue("System.EFEMNUM");
- return "001";
- }
- }
- public bool IsEnableMultiWaferSize
- {
- get
- {
- if (SC.ContainsItem("System.IsEnableMultiWaferSize"))
- return SC.GetValue<bool>("System.IsEnableMultiWaferSize");
- return false;
- }
- }
- private FixSizeQueue<EventItem> _eventError;
- private void Instance_OnEvent(EventItem obj)
- {
- if (obj.Level == EventLevel.Alarm) // (obj.Level == EventLevel.Warning ||
- {
- _eventError.Enqueue(obj);
- }
- }
- public void SetEfemData()
- {
- foreach (var module in GetInstallModules())
- {
- _efemModuleStatus[module] = new EfemModuleStatus(module);
- }
- }
- public IEnumerable<ModuleName> GetInstallModules()
- {
- return new List<ModuleName>()
- {
- ModuleName.System, ModuleName.Robot, ModuleName.Buffer1,
- ModuleName.LP1, ModuleName.LP2, ModuleName.LP3, ModuleName.LP4,
- ModuleName.LL1, ModuleName.LL2,
- };
- }
- public void SetInitialize(ModuleName module, bool initialized)
- {
- if (_efemModuleStatus.ContainsKey(module))
- {
- _efemModuleStatus[module].IsInitialized = initialized;
- }
- }
- private void Subscribe()
- {
- DATA.Subscribe("Efem.IsCommunicationReady", () => fsm.State == (int)ServerState.Connected);
- DATA.Subscribe("System.IsHold", () => IsSystemHold);
- DATA.Subscribe("System.IsOnlineMode", () => IsOnlineMode);
- DATA.Subscribe("System.ServerStatus", () => ((ServerState)fsm.State).ToString());
- OP.Subscribe(OperationName.Online, (cmd, param) =>
- {
- if (IsOnlineMode)
- return true;
- if (Singleton<RouteManager>.Instance.IsRunning)
- {
- EV.PostWarningLog("Server", "System is busy, can not switch to online");
- return true;
- }
- return CheckToPostMsg(MSG.Online);
- });
- OP.Subscribe(OperationName.Offline, (cmd, param) =>
- {
- if (!IsOnlineMode)
- return true;
- return CheckToPostMsg(MSG.Offline);
- });
- }
- private void BuildTransitionTable()
- {
- //online offline
- AnyStateTransition(MSG.Offline, FsmSetOffline, FSM_STATE.SAME);
- AnyStateTransition(MSG.Online, FsmSetOnline, FSM_STATE.SAME);
- //init
- EnterExitTransition<ServerState, FSM_MSG>(ServerState.Init, FsmEnterInit, FSM_MSG.NONE, null);
- Transition(ServerState.Init, MSG.Listening, null, ServerState.Listening);
- Transition(ServerState.Init, MSG.Reset, FsmEnterInit, ServerState.Init);
- //listening
- Transition(ServerState.Listening, MSG.Error, null, ServerState.Init);
- Transition(ServerState.Listening, MSG.NewSessionConnected, FsmNewSessionConnected, ServerState.Connected);
- //Connected
- Transition(ServerState.Connected, MSG.Disconnect, FsmDisconnect, ServerState.Listening);
- Transition(ServerState.Connected, MSG.Error, null, ServerState.Init);
- Transition(ServerState.Connected, MSG.NewSessionConnected, FsmNewSessionConnected, ServerState.Connected);
- Transition(ServerState.Connected, MSG.ReceiveData, FsmReceiveData, ServerState.Connected);
- Transition(ServerState.Connected, MSG.SendData, FsmSendData, ServerState.Connected);
- Transition(ServerState.Connected, FSM_MSG.TIMER, FsmMonitor, ServerState.Connected);
- }
- ~EfemEntity()
- {
- _socket?.Stop();
- }
- public bool SetSystemHold()
- {
- if (IsSystemHold)
- {
- return false;
- }
- IsSystemHold = true;
- return true;
- }
- public bool SetSystemUnHold()
- {
- if (!IsSystemHold)
- {
- return true;
- }
- IsSystemHold = false;
- return true;
- }
- #region FSM Functions
- public bool CheckToPostMsg(MSG msg)
- {
- if (!fsm.FindTransition(fsm.State, (int)msg))
- {
- EV.PostWarningLog("System", string.Format("{0} is in {1} state,can not do {2}", Name, (ServerState)fsm.State, (MSG)msg));
- return false;
- }
- PostMsg(msg);
- return true;
- }
- public bool CheckToPostMsg(MSG msg, object param1)
- {
- if (!fsm.FindTransition(fsm.State, (int)msg))
- {
- EV.PostWarningLog("System", string.Format("{0} is in {1} state,can not do {2}", Name, (ServerState)fsm.State, (MSG)msg));
- return false;
- }
- PostMsg(msg, param1);
- return true;
- }
- private bool FsmNewSessionConnected(object[] param)
- {
- _sessionId = (string)param[0];
- _activeTaskList.Clear();
- IsCommunicationOk = false;
- if (IsOnlineMode)
- {
- IoSignalTower tower = DEVICE.GetDevice<IoSignalTower>(DeviceName.SignalTower);
- tower.HostControl = true;
- }
-
- return true;
- }
- private bool FsmDisconnect(object[] param)
- {
- var sessionId = (string)param[0];
- if (sessionId != _sessionId)
- return false;
- return true;
- }
- private bool FsmEnterInit(object[] param)
- {
- string ip = SC.GetStringValue("System.EfemServerLocalIp");
- int port = SC.GetValue<int>("System.EfemPortNumber");
- _sendReadyTimer.Start(0);
- if (string.IsNullOrEmpty(ip))
- ip = "127.0.0.1";
- if (_socket.Start(ip, port))
- {
- PostMsg(MSG.Listening);
- return true;
- }
- return false;
- }
- private bool FsmSendData(object[] param)
- {
- _socket.Send((string)param[0]);
- return true;
- }
- public string commandrecive = null;
- private bool FsmReceiveData(object[] param)
- {
- try
- {
- commandrecive= (string)param[0];
- string rawMessage = (string)param[0];
- string[] words = rawMessage.Split(new char[5] { ':', '/', '>', '|', ';' }, StringSplitOptions.RemoveEmptyEntries);
- if (rawMessage.Contains("SET:CSTID"))
- {
- words = new string[] { words[0], words[1], words[2], rawMessage.Remove(0, 13) };
- }
- if (!Enum.TryParse<EfemCommandType>(words[0], out EfemCommandType type))
- {
- LOG.Write($"{rawMessage} is not a valid EFEM message format");
- SendMessage("NAK:" + rawMessage.Split(':')[1]);
- return true;
- }
- if (!Enum.TryParse<EfemCommand>(words[1], out EfemCommand cmd))
- {
- LOG.Write($"{rawMessage} is not a valid EFEM message format");
- SendMessage("NAK:" + rawMessage.Split(':')[1]);
- return true;
- }
- string commandData = rawMessage.Substring(rawMessage.IndexOf(':'));
-
- if (type == EfemCommandType.ACK)
- {
- //special for handshake
- if (!IsCommunicationOk && (rawMessage == "ACK:READY/COMM"))
- {
- IsCommunicationOk = true;
- return true;
- }
- foreach (ITaskT active in _activeTaskList)
- {
- if (active.CommandData == commandData && active.CommandType == type && active.CommandName == cmd)
- {
- active.Ack(type, cmd, words.Skip(2).Take(words.Length).ToArray());
- }
- }
- return true;
- }
- if (_factory.UnSupport(type, cmd))
- {
- LOG.Write($"{rawMessage} is not a valid EFEM message format");
- SendMessage("NAK:" + rawMessage.Split(':')[1]);
- return true;
- }
- ITaskT task = _factory.Create(type, cmd);
- task.CommandData = commandData;
- foreach (ITaskT active in _activeTaskList)
- {
- if (active.CommandData == commandData && active.CommandType == type && active.CommandName == cmd)
- {
- EV.PostWarningLog("EFEM", $"ignored {rawMessage}, already active");
- return true;
- }
- }
- if (task.Execute(out string resp, rawMessage, words.Skip(2).Take(words.Length).ToArray()))
- {
- _activeTaskList.Add(task);
- }
- SendMessage(resp);
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- }
- return true;
- }
- private bool FsmSetOnline(object[] param)
- {
- IsOnlineMode = true;
- IoSignalTower tower = DEVICE.GetDevice<IoSignalTower>(DeviceName.SignalTower);
- tower.HostControl = true;
- tower.Reset();
- return true;
- }
- private bool FsmSetOffline(object[] param)
- {
- IsOnlineMode = false;
- IoSignalTower tower = DEVICE.GetDevice<IoSignalTower>(DeviceName.SignalTower);
- tower.HostControl = false;
- tower.Reset();
- return true;
- }
- #endregion
- #region Server Callback
- public void OnConnected(string sessionId)
- {
- CheckToPostMsg(MSG.NewSessionConnected, sessionId);
- }
- public void OnDisconnected(string sessionId)
- {
- CheckToPostMsg(MSG.Disconnect, sessionId);
- }
- public void OnReceived(string msg)
- {
- CheckToPostMsg(MSG.ReceiveData, msg);
- }
- #endregion
- #region Server Monitor
- public void SendMessage(string msg)
- {
- if (IsCommunicationOk || msg == "INF:READY/COMM")
- {
- CheckToPostMsg(MSG.SendData, msg);
- }
- }
- private bool FsmMonitor(object[] objs)
- {
- if (!IsCommunicationOk)
- {
- if (_sendReadyTimer.GetElapseTime() > SC.GetValue<int>(ScPathName.Server_SendReadyInterval))
- {
- _sendReadyTimer.Start(0);
- SendMessage("INF:READY/COMM");
- }
- return true;
- }
- MonitorRunningTask();
- MonitorEvent();
- return true;
- }
- private void MonitorRunningTask()
- {
- List<ITaskT> tobeRemoved = new List<ITaskT>();
- foreach (ITaskT task in _activeTaskList)
- {
- if (!task.HasInfoMessage)
- {
- tobeRemoved.Add(task);
- continue;
- }
- string msg = string.Empty;
- bool? ret = task.Monitor(out msg);
- if (ret.HasValue)
- {
- SendMessage(msg);
- tobeRemoved.Add(task);
- break;
- }
- }
- if (tobeRemoved.Any())
- {
- foreach (var task in tobeRemoved)
- {
- _activeTaskList.Remove(task);
- }
- }
- }
- private void MonitorEvent()
- {
- // if (_efemData.IsSigStatEventMode)
- // {
- MonitorSigStatEvent();
-
- MonitorErrorEvent();
- return;
- //}
- //if (LPs.Any() && ((SystemServerModule)Singleton<EntityFactory>.Instance.GetEntity(DeviceName.System)).IsEventEnabled(EfemEventType.PORT))
- //{
- // foreach (var lpName in LPs)
- // {
- // var lp = DEVICE.GetDevice<LoadPortBaseDevice>(lpName.ToString());
- // _trigLpPresent[lpName].CLK = lp.IsPresent && lp.IsPlacement;
- // if (_trigLpPresent[lpName].T || _trigLpPresent[lpName].R)
- // {
- // Thread.Sleep(300);
- // SendSigStatEvent(lpName);
- // }
- // }
- //}
- }
- private void MonitorErrorEvent()
- {
- if (IsErrorReportEnable && _eventError != null && _eventError.Count > 0)
- {
- EventItem ev;
- //while (_eventError.TryDequeue(out ev))
- if (_eventError.TryDequeue(out ev))
- {
- string source = "System";
- if (ev.Source.Contains("Robot"))
- source = "ROB";
- if (ev.Source.Contains("LP"))
- source = ev.Source.Replace("L","");
-
- SendMessage($"INF:ERROR/{ev.Description}/{source}");// Level: ({ ev.Level}),
- }
- // SendMessage($"EVT:ERROR/{ev.Source}/{ev.Level}/{ev.Description}");
- }
- }
- private void MonitorSigStatEvent()
- {
- bool allEnable = ((SystemServerModule)Singleton<EntityFactory>.Instance.GetEntity(DeviceName.System)).IsEventEnabled(EfemEventType.ALL);
- if (!allEnable)
- return;
- bool lpEnable = ((SystemServerModule)Singleton<EntityFactory>.Instance.GetEntity(DeviceName.System)).IsEventEnabled(EfemEventType.PORT);
- bool sysEnable = ((SystemServerModule)Singleton<EntityFactory>.Instance.GetEntity(DeviceName.System)).IsEventEnabled(EfemEventType.SYSTEM);
- Dictionary<string, Tuple<uint, uint>> sigDatas = GetSigStatData();
- if (sigDatas == null)
- return;
- foreach (var sigData in sigDatas)
- {
- if (sigData.Key.StartsWith("P") && !lpEnable)
- continue;
- if (sigData.Key.StartsWith(EfemParameter.SYS) && !sysEnable)
- continue;
- ModuleName module = ProtocolName2ModuleName(sigData.Key);
-
- if ((!_efemModuleStatus[module].IsInitialized))
- continue;
- if (_efemModuleStatus[module].TrigInitialized.Q)
- {
- _efemModuleStatus[module].TrigInitialized.CLK = true;
- _sigData.Remove(sigData.Key);
- continue;
- }
- if (_sigData.ContainsKey(sigData.Key)
- && _sigData[sigData.Key].Item1 == sigData.Value.Item1
- && _sigData[sigData.Key].Item2 == sigData.Value.Item2)
- {
- continue;
- }
- _sigData[sigData.Key] = sigData.Value;
- if((!commandrecive.Contains("INIT/SYSTEM")&& (sigData.Key.Equals("P1")|| sigData.Key.Equals("P2")) || sigData.Key.Equals("System")))
- SendMessage($"EVT:SIGSTAT/{sigData.Key}/{_sigData[sigData.Key].Item1:X8}/{_sigData[sigData.Key].Item2:X8}");
-
- //if(commandrecive.Contains("INIT/SYSTEM"))
- //commandrecive = "";
- }
- }
- #endregion
- public Dictionary<string, Tuple<uint, uint>> GetSigStatData()
- {
- var result = new Dictionary<string, Tuple<uint, uint>>();
- ModuleName[] lstModule = new ModuleName[] { ModuleName.System, ModuleName.LP1, ModuleName.LP2 };
- foreach (var moduleName in lstModule)
- {
- if (DeviceDefineManager.Instance.GetValue<int>("LoadPortQuantity") == 1)
- {
- if(moduleName != ModuleName.LP2)
- result[ModuleName2ProtocolName(moduleName)] = Tuple.Create(GetSigStatData1(moduleName), GetSigStatData2(moduleName));
- }
- else
- {
- result[ModuleName2ProtocolName(moduleName)] = Tuple.Create(GetSigStatData1(moduleName), GetSigStatData2(moduleName));
- }
- }
- return result;
- }
- private ModuleName ProtocolName2ModuleName(string protocol)
- {
- ModuleName module = ModuleName.System;
- Dictionary<string, ModuleName> map = new Dictionary<string, ModuleName>()
- {
- {"P1", ModuleName.LP1},{"P2", ModuleName.LP2},
- {"SYS", ModuleName.System},
- };
- if (map.ContainsKey(protocol))
- module = map[protocol];
- return module;
- }
- protected override bool Init()
- {
- return true;
- }
- protected override void Term()
- {
- if (_socket != null)
- _socket.Stop();
- }
- public bool Check(int msg, out string reason, params object[] args)
- {
- if (!fsm.FindTransition(fsm.State, msg))
- {
- reason = String.Format("{0} is in {1} state,can not do {2}", Name, (ServerState)fsm.State, (MSG)msg);
- return false;
- }
- reason = "";
- return true;
- }
- public void Reset()
- {
- if (fsm.State == (int)ServerState.Init)
- {
- string ip = SC.GetStringValue("System.EfemServerLocalIp");
- int port = SC.GetValue<int>("System.EfemPortNumber");
- _sendReadyTimer.Start(0);
- if (_socket.Start(ip, port))
- {
- PostMsg(MSG.Listening);
- }
- }
- }
- public bool IsSlotShowOpposite
- {
- get
- {
- if (SC.ContainsItem("System.IsSlotShowOpposite"))
- return SC.GetValue<bool>("System.IsSlotShowOpposite");
- return false;
- }
- }
- public void SendMapEvent(LoadPortBaseDevice lp)
- {
- WaferInfo[] wafers = WaferManager.Instance.GetWafers(ModuleHelper.Converter(lp.Name));
- string slot = "";
- for (int i = 0; i < lp.ValidSlotsNumber; i++)
- {
- switch (wafers[i].Status)//IsSlotShowOpposite? wafers[lp.ValidSlotsNumber - i - 1].Status:
- {
- case WaferStatus.Empty:
- slot += "0";
- break;
- case WaferStatus.Normal:
- slot += "1";
- break;
- case WaferStatus.Crossed:
- slot += "3";
- break;
- case WaferStatus.Double:
- slot += "7";
- break;
- case WaferStatus.Unknown:
- slot += "8";
- break;
- case WaferStatus.Dummy:
- slot += "4";
- break;
- }
- }
- var slotmap = slot;
- if (lp.IsError)
- {
- slotmap = string.Empty;
- }
- string message = string.Format("EVT:MAPDT/{0}/{1}", ModuleName2ProtocolName(ModuleHelper.Converter(lp.Name)), slotmap);
- SendMessage(message);
- }
- public void SendMapEvent(BufferStation lp)
- {
- WaferInfo[] wafers = WaferManager.Instance.GetWafers(ModuleHelper.Converter(lp.Name));
- string slot = "";
- for (int i = 0; i < lp.ValidSlotsNumber; i++)
- {
- switch (wafers[i].Status)
- {
- case WaferStatus.Empty:
- slot += "0";
- break;
- case WaferStatus.Normal:
- slot += "1";
- break;
- case WaferStatus.Crossed:
- slot += "3";
- break;
- case WaferStatus.Double:
- slot += "7";
- break;
- case WaferStatus.Unknown:
- slot += "8";
- break;
- case WaferStatus.Dummy:
- slot += "4";
- break;
- }
- }
- var slotmap = slot;
- //if (lp.IsError)
- //{
- // slotmap = string.Empty;
- //}
- string message = string.Format("EVT:MAPDT/{0}/{1}", ModuleName2ProtocolName(ModuleHelper.Converter(lp.Name)), slotmap);
- SendMessage(message);
- }
- public void SendSigStatEvent(ModuleName module)
- {
- uint data1 = GetSigStatData1(module);
- uint data2 = GetSigStatData2(module);
- string message = message = string.Format("EVT:SIGSTAT/{0}/{1:X8}/{2:X8}", ModuleName2ProtocolName(module), data1, data2);
- SendMessage(message);
- }
- public uint GetSigStatData1(string device)
- {
- uint data1 = 0x0u;
- if (IsLoadPort(device))
- {
- //Loadport inputs
- var lp = DEVICE.GetDevice<LoadPortBaseDevice>(device);
- if (lp != null)
- {
- data1 |= GetLpData1(lp);
- }
- var e84Lp = DEVICE.GetDevice<E84Passiver>(GetE84LpName(device));
- if (e84Lp != null)
- {
- data1 |= GetE84Data1(e84Lp);
- }
- }
- else if (ModuleHelper.IsLoadLock(ModuleHelper.Converter(device)))
- {
- data1 = GetLlData1();
- }
- else
- {
- data1 = GetSystemData1();
- }
- return data1;
- }
- public uint GetSigStatData1(ModuleName module)
- {
- uint data1 = 0x0u;
- if (ModuleHelper.IsLoadPort(module))
- {
- //Loadport inputs
- var lp = DEVICE.GetDevice<LoadPortBaseDevice>(module.ToString());
- if (lp != null)
- {
- //if(!commandrecive.Contains("INIT/SYSTEM"))
- data1 |= GetLpData1(lp);
- }
- var e84Lp = DEVICE.GetDevice<E84Passiver>(GetE84LpName(module.ToString()));
- if (e84Lp != null)
- {
- // if (!commandrecive.Contains("INIT/SYSTEM"))
- data1 |= GetE84Data1(e84Lp);
- }
- }
- else if (ModuleHelper.IsLoadLock(module))
- {
- data1 = GetLlData1();
- }
- else
- {
- data1 = GetSystemData1();
- }
- return data1;
- }
- public uint GetSigStatData2(string device)
- {
- uint data2 = 0x0u;
- if (IsLoadPort(device))
- {
- // Loadport outputs
- var lp = DEVICE.GetDevice<LoadPortBaseDevice>(device);
- if (lp != null)
- {
- //if (!commandrecive.Contains("INIT/SYSTEM"))
- data2 |= GetLpData2(lp);
- }
- var e84Lp = DEVICE.GetDevice<E84Passiver>(GetE84LpName(device));
- if (e84Lp != null)
- {
- //if (!commandrecive.Contains("INIT/SYSTEM"))
- data2 |= GetE84Data2(e84Lp);
- }
- }
- else if (ModuleHelper.IsLoadLock(ModuleHelper.Converter(device)))
- {
- data2 = GetLlData2();
- }
- else
- {
- data2 = GetSystemData2();
- }
- return data2;
- }
- public uint GetSigStatData2(ModuleName module)
- {
- uint data2 = 0x0u;
- if (ModuleHelper.IsLoadPort(module))
- {
- // Loadport outputs
- var lp = DEVICE.GetDevice<LoadPortBaseDevice>(module.ToString());
- if (lp != null)
- {
- data2 |= GetLpData2(lp);
- }
- var e84Lp = DEVICE.GetDevice<E84Passiver>(GetE84LpName(module.ToString()));
- if (e84Lp != null)
- {
- data2 |= GetE84Data2(e84Lp);
- }
- }
- else if (ModuleHelper.IsLoadLock(module))
- {
- data2 = GetLlData2();
- }
- else
- {
- data2 = GetSystemData2();
- }
- return data2;
- }
- private uint GetLpData1(LoadPortBaseDevice lp)
- {
- uint data1 = 0x0u;
- if (lp != null)
- {
- //if(lp is OpenStageWithWaferSizeLoadPort)
- {
- data1 |= (lp.IsPlacement ? 0x00000001u : 0x0);
- data1 |= (!lp.IsPresent ? 0x00000002u : 0x0);
- data1 |= (lp.ClampState == FoupClampState.Close ? 0x00000008u : 0x0);
- switch (IsEnableMultiWaferSize?lp.GetCurrentWaferSize():WaferSize.WS6)
- {
- case WaferSize.WS3:
- //data1 |= 0x00000040u;
- data1 |= 0x00000080u;
- data1 |= 0x00000100u;
- break;
- case WaferSize.WS4:
- data1 |= 0x00000040u;
- //data1 |= 0x00000080u;
- data1 |= 0x00000100u;
- break;
- case WaferSize.WS6:
- data1 |= 0x00000040u;
- data1 |= 0x00000080u;
- //data1 |= 0x00000100u;
- break;
- case WaferSize.WS8:
- data1 |= 0x00000040u;
- data1 |= 0x00000080u;
- data1 |= 0x00000100u;
- break;
- }
-
- data1 |= (!lp.IsWaferProtrude) ? 0x00000200u : 0x0;
- data1 |= (lp.IsError||lp.CurrentState==LoadPortStateEnum.Error) ? 0x00000400u : 0x0;
- data1 |=(lp.Name=="LP1"? (DeviceModel.SensorSMIF1PODOPEN==null?0x0:(DeviceModel.SensorSMIF1PODOPEN.Value ? 0x00000800u : 0x0)) :(DeviceModel.SensorSMIF2PODOPEN==null?0x0:(DeviceModel.SensorSMIF2PODOPEN.Value? 0x00000800u : 0x0)));
- data1 |= (lp.Name == "LP1" ? (DeviceModel.SensorSMIF1READY == null ? 0x0 : (DeviceModel.SensorSMIF1READY.Value ? 0x00001000u : 0x0)) : (DeviceModel.SensorSMIF2READY == null ? 0x0 : (DeviceModel.SensorSMIF2READY.Value ? 0x00001000u : 0x0)));
- }
- }
- return data1;
- }
- private uint GetLpData2(LoadPortBaseDevice lp)
- {
- uint data2 = 0x0u;
- if (lp != null)
- {
- // if (!(lp is OpenStageWithWaferSizeLoadPort))
- // if (!(lp is OpenStageWithWaferSizeLoadPort))
- {
- data2 |= (lp.IndicatiorPresence == IndicatorState.ON ? 0x00000001U : 0x0);
- data2 |= (lp.IndicatiorPlacement == IndicatorState.ON ? 0x00000002U : 0x0);
- data2 |= (lp.IndicatiorLoad == IndicatorState.ON ? 0x00000004U : 0x0);
- data2 |= (lp.IndicatiorUnload == IndicatorState.ON ? 0x00000008U : 0x0);
- data2 |= (lp.IndicatiorManualMode == IndicatorState.ON ? 0x00000010U : 0x0);
- data2 |= (lp.IndicatorAlarm == IndicatorState.ON ? 0x00000020U : 0x0);
- data2 |= (lp.IndicatiorClampUnclamp == IndicatorState.ON ? 0x00000040U : 0x0);
- data2 |= (lp.IndicatiorDockUndock == IndicatorState.ON ? 0x00000080U : 0x0);
- data2 |= (lp.IndicatiorOpAccess == IndicatorState.ON ? 0x00000100U : 0x0);
- }
- }
- return data2;
- }
- private uint GetE84Data1(E84Passiver e84Lp)
- {
- uint data1 = 0x0u;
- if (e84Lp != null)
- {
- data1 |= (e84Lp.DiValid ? 0x01000000u : 0x0);
- data1 |= (e84Lp.DiCS0 ? 0x02000000u : 0x0);
- data1 |= (e84Lp.DiCS1 ? 0x04000000u : 0x0);
- data1 |= (e84Lp.DiTrReq ? 0x10000000u : 0x0);
- data1 |= (e84Lp.DiBusy ? 0x20000000u : 0x0);
- data1 |= (e84Lp.DiCompt ? 0x40000000u : 0x0);
- data1 |= (e84Lp.DiCont ? 0x80000000u : 0x0);
- }
- return data1;
- }
- private uint GetE84Data2(E84Passiver e84Lp)
- {
- uint data2 = 0x0u;
- if (e84Lp != null)
- {
- data2 |= (e84Lp.DoLoadReq ? 0x01000000U : 0x0);
- data2 |= (e84Lp.DoUnloadReq ? 0x02000000U : 0x0);
- data2 |= (e84Lp.DoReady ? 0x08000000U : 0x0);
- data2 |= (e84Lp.DoHOAvbl ? 0x40000000U : 0x0);
- data2 |= (e84Lp.DoES ? 0x80000000U : 0x0);
- }
- return data2;
- }
- //a 1 for SIGSTAT/SYSTEM
- //Bit Name of Input Signal Signal ON Signal OFF Initial Value
- //0 System vacuum source pressure 1 Normal
- //1
- //2 System compressed air pressure 1 Normal
- //3
- //4 Flow gauge Sensor Warning
- //5 Leakage Sensor Warning
- //6 Door switch Door close
- //7 Drive power Normal
- //8 Differential pressure sensor setting 1 Normal
- //9 Differential pressure sensor setting 2 Normal
- //10 Ionizer alarm Normal
- //11 FFU alarm Normal
- //12 Area sensor(Reserved) Not blocked
- //13 Mode switch RUN
- //14 Robot Wafer Present No presence
- //15 Cassette Door Door Closed
- private uint GetSystemData1()
- {
- uint data1 = 0x0u;
- //0:
- data1 |= (DeviceModel.SensorVACPressureSW.Value ? 0x00000001u : 0x0);
- //1:
- data1 |= (DeviceModel.SensorIONCDAPressureSW.Value ? 0x00000002u : 0x0);
- //2:
- data1 |= (DeviceModel.SensorCDAPressureSW.Value ? 0x00000004u : 0x0);
- //3:
- //data1 |= 0x00000800u; //data1 |= (DeviceModel.SensorAirPressureErrorForRobot.Value ? 0x00000004u : 0x0);
- //4 Flow gauge Sensor Warning
- data1 |= (DeviceModel.SensorWaterFlowSW.Value ? 0x00000010u : 0x0);
- //5 Leakage Sensor Warning
- data1 |= (DeviceModel.SensorWaterLeakSW.Value ? 0x00000020u : 0x0);
- //6:Door switch Door close
- data1 |= (_EfemDoorOpen? !DeviceModel.SensorEFEMSideDoorClosed.Value : DeviceModel.SensorEFEMSideDoorClosed.Value) ? 0x00000040u : 0x0;
- //7 Drive power Normal
- data1 |= (DeviceModel.SensorFFUalarm.Value ? 0x00000080u : 0x0);
- //8 Differential pressure sensor setting 1 Normal
- //data1 |= (DeviceModel.SensorIONAlarmSIGNAL.Value ? 0x00000100u : 0x0);
- //9 Differential pressure sensor setting 1 Normal
- // data1 |= (DeviceModel.SensorEFEMPowerON.Value ? 0x00000400u : 0x0);
- //10 Ionizer alarm Normal
- data1 |= (DeviceModel.TrigIonizerInterrupt!=null? (DeviceModel.TrigIonizerInterrupt.Value? 0x00000400u : (DeviceModel.SensorIONAlarmSIGNAL.Value ? 0x00000400u : 0x0)) : (DeviceModel.SensorIONAlarmSIGNAL.Value ? 0x00000400u : 0x0));
- //11 FFU alarm Normal
- data1 |= (DeviceModel.SensorFFUalarm.Value ? 0x00000800u : 0x0);
- //12
- data1 |= 0x00001000u;//(!DeviceModel.SensorRBlowerArmhavewafer.Value ? 0x00001000u : 0x0);
- //13 Mode switch RUN
- bool isRun =( _MaintenanceMode? !DeviceModel.SensorMaintenanceMode.Value : DeviceModel.SensorMaintenanceMode.Value )&& IsOnlineMode;
- data1 |= (isRun ? 0x00002000u : 0x0);
- //14 Robot Wafer Present No presence
- data1 |= 0x00004000u; //data1 |= (DeviceModel.SensorRobotFork1WaferOn.Value ? 0x00004000u : 0x0);
- // 15 Sensor Grating SensorIN
- data1 |= DeviceModel.SensorGratingSensorIN1==null?0x0:(DeviceModel.SensorGratingSensorIN1.Value ? 0x00008000u : 0x0);
- // 16 robot IsError
- var robot = DEVICE.GetDevice<RobotBaseDevice>(ModuleName.Robot.ToString());
- data1 |= (robot.IsError || robot.RobotState == RobotStateEnum.Error ? 0x00010000u : 0x0);
- // 17 buffer1 MapError
- var buffer1 = DEVICE.GetDevice<BufferStation>(ModuleName.Buffer1.ToString());
- data1 |= (buffer1!=null&& buffer1.MapError) ? 0x00020000u : 0x0;
- // 18 buffer2 MapError
- var buffer2 = DEVICE.GetDevice<BufferStation>(ModuleName.Buffer2.ToString());
- data1 |=( buffer1 != null && buffer2.MapError) ? 0x00040000u : 0x0;
- // 19 Cassette Door Door Closed
- data1 |= DeviceModel.SensorCstDoorClosed == null ? 0x00080000u : (DeviceModel.SensorCstDoorClosed.Value ? 0x00080000u : 0x0);
- // 20 PMA System Interlock
- data1 |= DeviceModel.SensorPMASystemInterlock == null ? 0x0 : (DeviceModel.SensorPMASystemInterlock.Value ? 0x00100000u : 0x0);
- // 21 PMB System Interlock
- data1 |= DeviceModel.SensorPMBSystemInterlock == null ? 0x0 : (DeviceModel.SensorPMBSystemInterlock.Value ? 0x00200000u : 0x0);
- data1 |= DeviceModel.SensorRBNotExtendPMA == null ? 0x0 : (DeviceModel.SensorRBNotExtendPMA.Value ? 0x00400000u : 0x0);
- data1 |= DeviceModel.SensorRBNotExtendPMB == null ? 0x0 : (DeviceModel.SensorRBNotExtendPMB.Value ? 0x00800000u : 0x0);
- return data1;
- }
- private uint GetSystemData2()
- {
- uint data2 = 0x0u;
- if (DeviceModel.SignalTower != null)
- {
- if (DeviceModel.SignalTower.Red != null)
- data2 |= (DeviceModel.SignalTower.Red.StateSetPoint == TowerLightStatus.On ? 0x00000001u : 0);
- if (DeviceModel.SignalTower.Green != null)
- data2 |= (DeviceModel.SignalTower.Green.StateSetPoint == TowerLightStatus.On ? 0x00000002u : 0);
- if (DeviceModel.SignalTower.Yellow != null)
- data2 |= (DeviceModel.SignalTower.Yellow.StateSetPoint == TowerLightStatus.On ? 0x00000004u : 0);
- if (DeviceModel.SignalTower.Blue != null)
- data2 |= (DeviceModel.SignalTower.Blue.StateSetPoint == TowerLightStatus.On ? 0x00000008u : 0);
- if (DeviceModel.SignalTower.White != null)
- data2 |= (DeviceModel.SignalTower.White.StateSetPoint == TowerLightStatus.On ? 0x00000010u : 0);
- if (DeviceModel.SignalTower.Red != null)
- data2 |= (DeviceModel.SignalTower.Red.StateSetPoint == TowerLightStatus.Blinking ? 0x00000020u : 0);
- if (DeviceModel.SignalTower.Green != null)
- data2 |= (DeviceModel.SignalTower.Green.StateSetPoint == TowerLightStatus.Blinking ? 0x00000040u : 0);
- if (DeviceModel.SignalTower.Yellow != null)
- data2 |= (DeviceModel.SignalTower.Yellow.StateSetPoint == TowerLightStatus.Blinking ? 0x00000080u : 0);
- if (DeviceModel.SignalTower.Blue != null)
- data2 |= (DeviceModel.SignalTower.Blue.StateSetPoint == TowerLightStatus.Blinking ? 0x00000100u : 0);
- if (DeviceModel.SignalTower.White != null)
- data2 |= (DeviceModel.SignalTower.White.StateSetPoint == TowerLightStatus.Blinking ? 0x00000200u : 0);
- if (DeviceModel.SignalTower.Buzzer1 != null)
- data2 |= (DeviceModel.SignalTower.Buzzer1.StateSetPoint == TowerLightStatus.On ? 0x00000400u : 0);
- if (DeviceModel.SignalTower.Buzzer2 != null)
- data2 |= (DeviceModel.SignalTower.Buzzer2.StateSetPoint == TowerLightStatus.On ? 0x00000800u : 0);
- }
- return data2;
- }
- private uint GetLlData1()
- {
- //DIW1 meter pulse bit 0
- //DIW2 meter pulse bit 1
- //DIW3 meter pulse bit 2
- //DIW4 meter pulse bit 3
- //In Shutter Opened bit 4
- //Out Shutter Opened bit 5
- //Leak Sensor bit 6
- uint data1 = 0x0u;
- data1 |= (LoadLockDevice.LoadLockAtmDoorState == LoadLockDoorState.Opened ? 0x00000010u : 0x0);
- data1 |= (LoadLockDevice.LoadLockVtmDoorState == LoadLockDoorState.Opened ? 0x00000020u : 0x0);
- return data1;
- }
- private uint GetLlData2()
- {
- uint data2 = 0x0u;
- return data2;
- }
- private bool IsLoadPort(string device)
- {
- if (device == "P1" || device == "P2" || device == "P3" || device == "P4"|| device == "LP1" || device == "LP2" || device == "LP3" || device == "LP4")
- {
- return true;
- }
- return false;
- }
- public string GetE84LpName(string device)
- {
- string e84 = string.Empty;
- switch (device)
- {
- case "P1":
- case "LP1":
- e84 = "Loadport1E84";
- break;
- case "P2":
- case "LP2":
- e84 = "Loadport2E84";
- break;
- case "P3":
- case "LP3":
- e84 = "Loadport3E84";
- break;
- case "P4":
- case "LP4":
- e84 = "Loadport4E84";
- break;
- case "P5":
- case "LP5":
- e84 = "Loadport5E84";
- break;
- case "P6":
- case "LP6":
- e84 = "Loadport6E84";
- break;
- case "P7":
- case "LP7":
- e84 = "Loadport7E84";
- break;
- case "P8":
- case "LP8":
- e84 = "Loadport8E84";
- break;
- case "P9":
- case "LP9":
- e84 = "Loadport9E84";
- break;
- case "P10":
- case "LP10":
- e84 = "Loadport10E84";
- break;
- }
- return e84;
- }
- private string ModuleName2ProtocolName(ModuleName module)
- {
- string protocol = "System";
- switch (module)
- {
- case ModuleName.LP1:
- protocol = "P1";
- break;
- case ModuleName.LP2:
- protocol = "P2";
- break;
- case ModuleName.LP3:
- protocol = "P3";
- break;
- case ModuleName.LP4:
- protocol = "P4";
- break;
- case ModuleName.LP5:
- protocol = "P5";
- break;
- case ModuleName.LP6:
- protocol = "P6";
- break;
- case ModuleName.LP7:
- protocol = "P7";
- break;
- case ModuleName.LP8:
- protocol = "P8";
- break;
- case ModuleName.LP9:
- protocol = "P9";
- break;
- case ModuleName.LP10:
- protocol = "P10";
- break;
- case ModuleName.LL1:
- protocol = "LLA";
- break;
- case ModuleName.LL2:
- protocol = "LLB";
- break;
- case ModuleName.LL3:
- protocol = "LLC";
- break;
- case ModuleName.LL4:
- protocol = "LLD";
- break;
- case ModuleName.LL5:
- protocol = "LLE";
- break;
- case ModuleName.LL6:
- protocol = "LLF";
- break;
- case ModuleName.LL7:
- protocol = "LLG";
- break;
- case ModuleName.LL8:
- protocol = "LLH";
- break;
- }
- return protocol;
- }
- }
- }
|