123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356 |
- 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:
- if (DeviceModel.SensorVACPressureSW != null)
- data1 |= (DeviceModel.SensorVACPressureSW.Value ? 0x00000001u : 0x0);
- //1:
- if (DeviceModel.SensorIONCDAPressureSW != null)
- data1 |= (DeviceModel.SensorIONCDAPressureSW.Value ? 0x00000002u : 0x0);
- //2:
- if (DeviceModel.SensorCDAPressureSW != null)
- data1 |= (DeviceModel.SensorCDAPressureSW.Value ? 0x00000004u : 0x0);
- //3:
- //data1 |= 0x00000800u; //data1 |= (DeviceModel.SensorAirPressureErrorForRobot.Value ? 0x00000004u : 0x0);
- //4 Flow gauge Sensor Warning (默认bit=1 Normal)
- data1 |= (DeviceModel.SensorWaterFlowSW != null ? (DeviceModel.SensorWaterFlowSW.Value ? 0x00000010u : 0x0) : 0x00000010u);
- //5 Leakage Sensor Warning (默认bit=1 Normal)
- data1 |= (DeviceModel.SensorWaterLeakSW != null ? (DeviceModel.SensorWaterLeakSW.Value ? 0x00000020u : 0x0) : 0x00000020u);
- //6:Door switch Door close
- if (DeviceModel.SensorEFEMSideDoorClosed != null)
- data1 |= (_EfemDoorOpen? !DeviceModel.SensorEFEMSideDoorClosed.Value : DeviceModel.SensorEFEMSideDoorClosed.Value) ? 0x00000040u : 0x0;
- //7 Drive power Normal
- if (DeviceModel.SensorFFUalarm != null)
- 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
- if (DeviceModel.TrigIonizerInterrupt != null)
- data1 |= (DeviceModel.TrigIonizerInterrupt != null ? (DeviceModel.TrigIonizerInterrupt.Value? 0x00000400u : (DeviceModel.SensorIONAlarmSIGNAL.Value ? 0x00000400u : 0x0)) : (DeviceModel.SensorIONAlarmSIGNAL.Value ? 0x00000400u : 0x0));
- //11 FFU alarm Normal
- if (DeviceModel.SensorFFUalarm != null)
- data1 |= (DeviceModel.SensorFFUalarm.Value ? 0x00000800u : 0x0);
- //12
- data1 |= 0x00001000u;//(!DeviceModel.SensorRBlowerArmhavewafer.Value ? 0x00001000u : 0x0);
- //13 Mode switch RUN
- if (DeviceModel.SensorMaintenanceMode != null)
- {
- 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 |= ( buffer2 != 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;
- }
- }
- }
|