| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229 | 
							- using Aitex.Core.Common;
 
- using Aitex.Core.RT.DataCenter;
 
- using Aitex.Core.RT.Event;
 
- using Aitex.Core.RT.OperationCenter;
 
- using Aitex.Core.RT.SCCore;
 
- using Aitex.Core.Util;
 
- using Aitex.Sorter.Common;
 
- using MECF.Framework.Common.Equipment;
 
- using MECF.Framework.Common.SubstrateTrackings;
 
- using System;
 
- using System.Collections;
 
- using System.Collections.Generic;
 
- using System.Diagnostics;
 
- using VirgoCommon;
 
- using VirgoRT.Device;
 
- using VirgoRT.Device.YASKAWA;
 
- using VirgoRT.Devices.YASKAWA;
 
- using VirgoRT.HostWrapper;
 
- using VirgoRT.Modules;
 
- namespace VirgoRT.Devices.EFEM
 
- {
 
-     sealed class Loadport : ILoadport
 
-     {
 
-         private readonly Efem _controller;
 
-         //---------------------------------Properties------------------------------------
 
-         // 
 
-         public OnlineFlag OnlineFlag { get; set; }
 
-         public ModuleName Module { get; set; }
 
-         public DeviceState Status { get; set; }
 
-         public WaferSize WaferSize { get; set; }
 
-         public WaferStatus[] WaferInfo { get; set; }
 
-         public bool HasCassette { get; set; }
 
-         public bool Protrusion { get; set; }
 
-         public bool IsMapped { get; set; }
 
-         public bool JobDone { get; set; }
 
-         public bool HasPlacementError { get; set; }
 
-         public Stopwatch TimerNotifyJobDone { get; set; }
 
-         public bool IsThicknessValid
 
-         {
 
-             get
 
-             {
 
-                 return !_enableThickness || !string.IsNullOrEmpty(_waferThicknessType);
 
-             }
 
-         }
 
-         public string ThicknessType
 
-         {
 
-             get
 
-             {
 
-                 return _waferThicknessType;
 
-             }
 
-         }
 
-         public bool IsClamped { get; set; }
 
-         public bool IsLoaded { get; set; }
 
-         public bool IsDocked { get; set; }
 
-         public string CarrierId { get; set; }
 
-         public string SmartTag { get; set; }
 
-         public string LotId { get; set; }
 
-         public bool IsBusy { get; set; }
 
-         public bool IsError { get; set; }
 
-         private string[] _slotMap;
 
-         public string SlotMap
 
-         {
 
-             get
 
-             {
 
-                 if (_slotMap == null)
 
-                 {
 
-                     _slotMap = new string[SC.GetValue<int>($"EFEM.{(ModuleHelper.IsBuffer(Module) ? "Buffer" : "LoadPort")}.SlotNumber")];
 
-                 }
 
-                 if (!ModuleHelper.IsInstalled(Module))
 
-                 {
 
-                     return string.Join("", _slotMap);
 
-                 }
 
-                 for (int i = 0; i < _slotMap.Length; i++)
 
-                 {
 
-                     _slotMap[i] = ((int)WaferManager.Instance.GetWafer(Module, i)?.Status).ToString();
 
-                 }
 
-                 return string.Join("", _slotMap);
 
-             }
 
-         }
 
-         private string Port1CassetteArrive = "Port1CassetteArrive";
 
-         private string Port1CassetteRemoved = "Port1CassetteRemoved";
 
-         private string Port1MappingComplete = "Port1MappingComplete";
 
-         private string Port1MappingFailed = "Port1MappingFailed";
 
-         private string Port2CassetteArrive = "Port2CassetteArrive";
 
-         private string Port2CassetteRemoved = "Port2CassetteRemoved";
 
-         private string Port2MappingComplete = "Port2MappingComplete";
 
-         private string Port2MappingFailed = "Port2MappingFailed";
 
-         private string _waferThicknessType;
 
-         private bool _enableThickness;
 
-         private string AlarmWaferProtrude = "WaferProtrude";
 
-         private LoadPortFACallback _faCallback = new LoadPortFACallback();
 
-         // Constructor
 
-         //
 
-         public Loadport(ModuleName mod, Efem efem)
 
-         {
 
-             Module = mod;
 
-             _controller = efem;
 
- 			
 
- 			TimerNotifyJobDone = new Stopwatch();
 
-             _enableThickness = false;// SC.GetValue<bool>("System.WaferThickness.EnableThickness");
 
-             HasPlacementError = false;
 
-             EV.Subscribe(new EventItem("Event", Port1CassetteArrive, "Port1CassetteArrive"));
 
-             EV.Subscribe(new EventItem("Event", Port1CassetteRemoved, "Port1CassetteRemoved"));
 
-             EV.Subscribe(new EventItem("Event", Port1MappingComplete, "Port1MappingComplete"));
 
-             EV.Subscribe(new EventItem("Event", Port1MappingFailed, "Port1MappingFailed"));
 
-             EV.Subscribe(new EventItem("Event", Port2CassetteArrive, "Port2CassetteArrive"));
 
-             EV.Subscribe(new EventItem("Event", Port2CassetteRemoved, "Port2CassetteRemoved"));
 
-             EV.Subscribe(new EventItem("Event", Port2MappingComplete, "Port2MappingComplete"));
 
-             EV.Subscribe(new EventItem("Event", Port2MappingFailed, "Port2MappingFailed"));
 
-             EV.Subscribe(new EventItem("Event", AlarmWaferProtrude, "Wafer protrude", EventLevel.Alarm, EventType.HostNotification));
 
-             DATA.Subscribe($"{mod}.WaferSize", () => WaferSize.ToString());
 
-             DATA.Subscribe($"{mod}.CassetteState", () => HasCassette ? LoadportCassetteState.Normal : LoadportCassetteState.Absent);
 
-             DATA.Subscribe($"{mod}.CassettePresent", () => HasCassette ? 1 : 0);
 
-             DATA.Subscribe($"{mod}.CassettePlaced", () => HasCassette);
 
-             DATA.Subscribe($"{mod}.SlotMap", () => SlotMap);
 
-             DATA.Subscribe($"{mod}.IsWaferProtrude", () => Protrusion ? 1 : 0);
 
-             DATA.Subscribe($"{mod}.IsMapped", () => IsMapped);
 
-             DATA.Subscribe($"{mod}.IsLoaded", () => IsLoaded);
 
-             DATA.Subscribe($"{mod}.IsClamped", () => IsClamped);
 
-             DATA.Subscribe($"{mod}.IsDocked", () => IsDocked);
 
-             DATA.Subscribe($"{mod}.CarrierId", () => CarrierId);
 
-             DATA.Subscribe($"{mod}.SmartTag", () => SmartTag);
 
-             DATA.Subscribe($"{Module}.WaferThicknessType", () => _waferThicknessType);
 
-             OP.Subscribe($"{Module}.SetThick", (cmd, args) => { SetThick(); return true; });
 
-             OP.Subscribe($"{Module}.SetThin", (cmd, args) => { SetThin(); return true; });
 
-             OP.Subscribe($"{Module}.CarrierIDScanned", (cmd, args) =>
 
-             {
 
-                 OnCarrierIDScanned(args[0].ToString());
 
-                 return true;
 
-             });
 
-         }
 
-         // Methods
 
-         //
 
-         public void OnError()
 
-         {
 
-             IsError = true;
 
-             IsBusy = false;
 
-         }
 
-         public void SetThick()
 
-         {
 
-             _waferThicknessType = "Thick";
 
-             SC.SetItemValue($"System.WaferThickness.{Module}WaferThicknessType", _waferThicknessType);
 
-             _controller.SetThick(Module);
 
-         }
 
-         public void SetThin()
 
-         {
 
-             _waferThicknessType = "Thin";
 
-             SC.SetItemValue($"System.WaferThickness.{Module}WaferThicknessType", _waferThicknessType);
 
-             _controller.SetThin(Module);
 
-         }
 
-         #region Home
 
-         public void Home()
 
-         {
 
-             if (IsBusy)
 
-             {
 
-                 EV.PostInfoLog(Module.ToString(), $"{Module} is busy can not home");
 
-                 return;
 
-             }
 
-             IsBusy = true;
 
-             _controller.Home(Module, Module.ToString());
 
-         }
 
-         public void SIGSTAT()
 
-         {
 
-             if (IsBusy)
 
-             {
 
-                 EV.PostInfoLog(Module.ToString(), $"{Module} is busy can not SIGSTAT");
 
-                 return;
 
-             }
 
-             IsBusy = true;
 
-             _controller.SIGSTAT(Module, Module.ToString());
 
-         }
 
-         public void NoteJobStart()
 
-         {
 
-             JobDone = false;
 
-         }
 
- 		
 
-         public void NoteJobComplete()
 
-         {
 
-             TimerNotifyJobDone.Restart();
 
-             JobDone = true;
 
-         }
 
-         public void OnHomeFailed(string data)
 
-         {
 
-             IsError = true;
 
-             IsBusy = false;
 
-         }
 
-         public void OnHomed()
 
-         {
 
-             IsError = false;
 
-             IsBusy = false;
 
-             IsClamped = false;
 
-             IsLoaded = false;
 
-             IsMapped = false;
 
-             IsDocked = false;
 
-         }
 
-         #endregion
 
-         #region Load
 
-         public void Load()
 
-         {
 
-             if (IsLoaded)
 
-             {
 
-                 EV.PostWarningLog(Module.ToString(), $"{Module} is loaded, can not load");
 
-                 return;
 
-             }
 
-             if (IsBusy)
 
-             {
 
-                 EV.PostInfoLog(Module.ToString(), $"{Module} is busy, can not load");
 
-                 return;
 
-             }
 
-             if (IsError)
 
-             {
 
-                 EV.PostInfoLog(Module.ToString(), $"{Module} is error, can not load");
 
-                 return;
 
-             }
 
-             IsBusy = true;
 
-             _controller.Load(Module);
 
-         }
 
-         public void OnLoadFailed(string data)
 
-         {
 
-             IsError = true;
 
-             IsBusy = false;
 
-             _faCallback.LoadFailed(this);
 
-         }
 
-         public void OnLoaded()
 
-         {
 
-             IsError = false;
 
-             IsBusy = false;
 
-             IsLoaded = true;
 
-             IsMapped = true;
 
-             _faCallback.LoadComplete(this);
 
-         }
 
-         public void OnCancel()
 
-         {
 
-             IsBusy = false;
 
-         }
 
-         #endregion
 
-         #region unload
 
-         public void Unload()
 
-         {
 
-             if (!IsLoaded)
 
-             {
 
-                 EV.PostWarningLog(Module.ToString(), $"{Module} is not loaded, can not unload");
 
-                 return;
 
-             }
 
-             if (IsBusy)
 
-             {
 
-                 EV.PostInfoLog(Module.ToString(), $"{Module} is busy can not unload");
 
-                 return;
 
-             }
 
-             if (IsError)
 
-             {
 
-                 EV.PostInfoLog(Module.ToString(), $"{Module} is error can not unload");
 
-                 return;
 
-             }
 
-             IsBusy = true;
 
-             _controller.Unload(Module);
 
-         }
 
-         public void OnUnloadFailed(string data)
 
-         {
 
-             IsError = true;
 
-             IsBusy = false;
 
-             _faCallback.UnloadFailed(this);
 
-         }
 
-         public void OnUnloaded()
 
-         {
 
-             IsBusy = false;
 
-             IsError = false;
 
-             IsLoaded = false;
 
-             IsMapped = false;
 
-             if (SC.GetValue<bool>("EFEM.AutoUnlockAfterUnload"))
 
-             {
 
-                 _faCallback.UnloadComplete(this);
 
-             }
 
-             else
 
-             {
 
-                  
 
-             }
 
-  
 
-         }
 
-         #endregion
 
-         #region Dock
 
-         public void Dock()
 
-         {
 
-             if (IsBusy)
 
-             {
 
-                 EV.PostInfoLog(Module.ToString(), $"{Module} is busy can not dock");
 
-                 return;
 
-             }
 
-             if (IsError)
 
-             {
 
-                 EV.PostInfoLog(Module.ToString(), $"{Module} is error can not dock");
 
-                 return;
 
-             }
 
-             IsBusy = true;
 
-             _controller.Dock(Module);
 
-         }
 
-         public void OnDocked()
 
-         {
 
-             IsBusy = false;
 
-             IsError = false;
 
-             IsDocked = true;
 
-         }
 
-         public void OnDockFailed(string data)
 
-         {
 
-             IsError = true;
 
-             IsBusy = false;
 
-         }
 
-         #endregion
 
-         #region Undock
 
-         public void Undock()
 
-         {
 
-             if (IsBusy)
 
-             {
 
-                 EV.PostInfoLog(Module.ToString(), $"{Module} is busy can not undock");
 
-                 return;
 
-             }
 
-             if (IsError)
 
-             {
 
-                 EV.PostInfoLog(Module.ToString(), $"{Module} is error can not undock");
 
-                 return;
 
-             }
 
-             IsBusy = true;
 
-             _controller.Undock(Module);
 
-         }
 
-         public void OnUndocked()
 
-         {
 
-             IsBusy = false;
 
-             IsError = false;
 
-             IsDocked = false;
 
-         }
 
-         public void OnUndockFailed(string data)
 
-         {
 
-             IsError = true;
 
-             IsBusy = false;
 
-         }
 
-         #endregion
 
-         #region Clamp
 
-         public void Clamp(bool isUnloadClamp)
 
-         {
 
-             if (IsBusy)
 
-             {
 
-                 EV.PostInfoLog(Module.ToString(), $"{Module} is busy can not clamp");
 
-                 return;
 
-             }
 
-             if (IsError)
 
-             {
 
-                 EV.PostInfoLog(Module.ToString(), $"{Module} is error can not clamp");
 
-                 return;
 
-             }
 
-             IsBusy = true;
 
-             _controller.Clamp(Module, isUnloadClamp);
 
-         }
 
-         public void OnClamped(bool isUnloadClamp)
 
-         {
 
-             IsBusy = false;
 
-             IsError = false;
 
-             IsClamped = true;
 
-             if (isUnloadClamp)
 
-             {
 
-                 _faCallback.UnloadComplete(this);
 
-                 
 
-             }
 
-             else
 
-             {
 
-                 _faCallback.Clamped(this);
 
-             }
 
-             
 
-         }
 
-         public void OnClampFailed(string data)
 
-         {
 
-             IsError = true;
 
-             IsBusy = false;
 
-         }
 
-         #endregion
 
-         #region Unclamp
 
-         public void Unclamp()
 
-         {
 
-             if (IsBusy)
 
-             {
 
-                 EV.PostInfoLog(Module.ToString(), $"{Module} is busy can not unclamp");
 
-                 return;
 
-             }
 
-             if (IsError)
 
-             {
 
-                 EV.PostInfoLog(Module.ToString(), $"{Module} is error can not unclamp");
 
-                 return;
 
-             }
 
-             IsBusy = true;
 
-             _controller.Unclamp(Module);
 
-         }
 
-         public void OnUnclamped()
 
-         {
 
-             IsBusy = false;
 
-             IsError = false;
 
-             IsClamped = false;
 
-             _faCallback.Unclamped(this);
 
-         }
 
-         public void OnUnclampFailed(string data)
 
-         {
 
-         }
 
-         #endregion
 
-         #region map
 
-         public void Map()
 
-         {
 
-             _controller.AddAction(new MapAction(_controller, Module));
 
-         }
 
-         #endregion
 
-         #region carrierID
 
-         public void ReadCarrierID()
 
-         {
 
-             if (IsBusy)
 
-             {
 
-                 EV.PostInfoLog(Module.ToString(), $"{Module} is busy can not read carrier ID");
 
-                 return;
 
-             }
 
-             if (IsError)
 
-             {
 
-                 EV.PostInfoLog(Module.ToString(), $"{Module} is error can not read carrier ID");
 
-                 return;
 
-             }
 
-             IsBusy = true;
 
-             _controller.ReadCarrierId(Module);
 
-         }
 
-         public void OnCarrierIDScanned(string data)
 
-         {
 
-  
 
-                 CarrierId = data;
 
-  
 
-             _faCallback.IDRead(this);
 
-         }
 
-         public void OnCarrierIDRead(string data)
 
-         {
 
-             IsBusy = false;
 
-             IsError = false;
 
-             //Regex rg = new Regex("(?<=(" + "LOT :" + "))[.\\s\\S]*?(?=(" + "QTY :" + "))", RegexOptions.Multiline | RegexOptions.Singleline);
 
-             //string carrierID = rg.Match(data).Value.Replace(":", "").Trim();
 
-             //data =
 
-             //    "CST:C082259     TYPE:CST25_AU   LOT:AF2403      QTY:24          FLOW:033000     STATUS:HOLD     PRI:3-1         PD:0418A        CSRLOT:         CLEAN:2021/11/14 19:57:50       EQPGRP:DUMMY    STAGE:CP-TEST1  RECIPE:DUMMY    EMP:N           ";
 
-             var items = data.Split(new string[] { " ", "\t", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
 
-             CarrierId = "";
 
-             foreach (var item in items)
 
-             {
 
-                 if (item.StartsWith("CST:") && item.Length > 4)
 
-                     CarrierId = item.Substring(4).Trim();
 
-                 if (item.StartsWith("LOT:") && item.Length > 4)
 
-                     LotId = item.Substring(4).Trim();
 
-             }
 
-             if (string.IsNullOrEmpty(CarrierId))
 
-             {
 
-                 CarrierId = data;
 
-             }
 
-             SmartTag = data;
 
-             _faCallback.IDRead(this);
 
-         }
 
-         public void OnCarrierIDReadFailed(string data)
 
-         {
 
-             IsError = true;
 
-             IsBusy = false;
 
-             _faCallback.ReadIDFailed(this);
 
-         }
 
-         public void WriteCarrierID(string id)
 
-         {
 
-             if (IsBusy)
 
-             {
 
-                 EV.PostInfoLog(Module.ToString(), $"{Module} is busy can not write carrier ID");
 
-                 return;
 
-             }
 
-             if (IsError)
 
-             {
 
-                 EV.PostInfoLog(Module.ToString(), $"{Module} is error can not write carrier ID");
 
-                 return;
 
-             }
 
-             IsBusy = true;
 
-             _controller.WriteCarrierId(Module, id);
 
-         }
 
-         public void OnCarrierIDWrite(string data)
 
-         {
 
-             IsBusy = false;
 
-             IsError = false;
 
-             var items = data.Split(new string[] { " ", "\t", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
 
-             CarrierId = "";
 
-             foreach (var item in items)
 
-             {
 
-                 if (item.StartsWith("CST:") && item.Length > 4)
 
-                     CarrierId = item.Substring(4);
 
-             }
 
-             if (string.IsNullOrEmpty(CarrierId))
 
-             {
 
-                 CarrierId = data;
 
-             }
 
-             SmartTag = data;
 
-             _faCallback.IDWrite(this);
 
-         }
 
-         public void OnCarrierIDWriteFailed(string data)
 
-         {
 
-             IsError = true;
 
-             IsBusy = false;
 
-             _faCallback.WriteIDFailed(this);
 
-         }
 
-         #endregion
 
-         #region event
 
-         public void HandleEvent(EfemEventArgs eArg)
 
-         {
 
-             switch (eArg.CommandType)
 
-             {
 
-                 case EfemOperation.GetWaferInfo:
 
-                     string sWaferInfo = eArg.DataList[0];
 
-                     bool resultNormal = true;
 
-                     if ((EfemEntity.EfemType)SC.GetValue<int>($"EFEM.EfemType") == EfemEntity.EfemType.BrooksEFEM)
 
-                     {
 
-                         resultNormal = !(sWaferInfo.Contains("3") || sWaferInfo.Contains("7"));
 
-                     }
 
-                     else
 
-                     {
 
-                         for (byte index = 0; index < sWaferInfo.Length; index++)
 
-                         {
 
-                             int waferState = int.Parse(sWaferInfo.Substring(index, 1));
 
-                             //合理的映射到内部支持的叠片/交叉片
 
-                             if (waferState >= 7) waferState = 7;
 
-                             else if (waferState >= 2) waferState = 3;
 
-                             WaferStatus st = (WaferStatus)waferState;
 
-                             WaferManager.Instance.UpdateWaferSize(this.Module, index, WaferSize);
 
-                             if (st != WaferStatus.Empty)
 
-                             {
 
-                                 WaferManager.Instance.CreateWafer(this.Module, index, st);
 
-                                 if (st == WaferStatus.Normal)
 
-                                 {
 
-                                     EV.PostInfoLog(this.Module.ToString(), $"Found Wafer on Slot {index + 1} {WaferSize}");
 
-                                 }
 
-                                 else
 
-                                 {
 
-                                     resultNormal = false;
 
-                                     EV.PostWarningLog(this.Module.ToString(), $"Found {st} Wafer on Slot {index + 1} {WaferSize}");
 
-                                 }
 
-                             }
 
-                             else
 
-                             {
 
-                                 WaferManager.Instance.DeleteWafer(this.Module, index);
 
-                             }
 
-                         }
 
-                     }
 
-                         
 
-                     var dvidMap = new SerializableDictionary<string, string>();
 
-                     dvidMap[DVIDName.SlotMap] = sWaferInfo;
 
-                     dvidMap[DVIDName.PortID] = Module == ModuleName.LP1 ? "1" : "2";
 
-                     dvidMap[DVIDName.CarrierID] = CarrierId??"";
 
-                     if (resultNormal)
 
-                     {
 
-                         EV.Notify(Module == ModuleName.LP1 ? Port1MappingComplete : Port2MappingComplete, dvidMap);
 
-                         EV.PostInfoLog(Module.ToString(), $"Report {Module} Mapping complete event, CarrierID:{CarrierId}");
 
-                     }
 
-                     else
 
-                     {
 
-                         EV.Notify(Module == ModuleName.LP1 ? Port1MappingFailed : Port2MappingFailed, dvidMap);
 
-                         EV.PostAlarmLog(Module == ModuleName.LP1 ? "Port1" : "Port2", " MappingFailed");
 
-                     }
 
-                     this.IsMapped = true;
 
-                     break;
 
-                 case EfemOperation.SigStatus:
 
-                     // EVT: SIGSTAT/P2/00000381/00000000;
 
-                     string sParam = eArg.DataList[0];
 
-                     ModuleName mod = sParam.ToModule();
 
-                     if (!ModuleHelper.IsLoadPort(mod))
 
-                         return;
 
-                     // DATA1 & DATA2
 
-                     int nData1 = Convert.ToInt32(eArg.DataList[1], 16);
 
-                     int nData2 = Convert.ToInt32(eArg.DataList[2], 16);
 
-                     BitArray baData1 = new BitArray(new int[] { nData1 });
 
-                     BitArray baData2 = new BitArray(new int[] { nData2 });
 
-                     // wafer size
 
-                     if ((EfemEntity.EfemType)SC.GetValue<int>($"EFEM.EfemType") == EfemEntity.EfemType.BrooksEFEM ||
 
-                         (EfemEntity.EfemType)SC.GetValue<int>($"EFEM.EfemType") == EfemEntity.EfemType.BeamSUNWAY)
 
-                     {
 
-                         if (SC.GetValue<int>($"System.BigWafer") == 8)
 
-                             WaferSize = WaferSize.WS8;
 
-                         else
 
-                             WaferSize = WaferSize.WS12;
 
-                     }
 
-                     else
 
-                     {
 
-                         this.WaferSize = !baData1[6] ? WaferSize.WS3 :
 
-                                          !baData1[7] ? WaferSize.WS4 :
 
-                                          !baData1[8] ? WaferSize.WS6 : WaferSize.WS0;
 
-                     }
 
-                         
 
-                     // placement & present
 
-                     bool bPlacement = baData1[0]; // bit 0
 
-                     bool bPresence = !baData1[1]; // bit 1
 
-                     bool bArrived = bPlacement && bPresence;
 
-                     if (HasCassette)
 
-                     {
 
-                         if (!bArrived)
 
-                         {
 
-                             this.HasCassette = false;
 
-                             this.IsMapped = false;
 
-                             this.HasPlacementError = false;
 
-                             EV.PostInfoLog(mod.ToString(), "Cassette removed");
 
-                             OP.DoOperation("System.CassetteLeave");     //For unload light control off afer job done
 
-                             CarrierManager.Instance.DeleteCarrier(Module.ToString());
 
-                             WaferManager.Instance.DeleteWafer(this.Module, 0, SC.GetValue<int>("EFEM.LoadPort.SlotNumber"));
 
-                             SerializableDictionary<string, string> dvid = new SerializableDictionary<string, string>();
 
-                             dvid["PortID"] = mod == ModuleName.LP1 ? "1" : "2";
 
-                             EV.Notify(mod == ModuleName.LP1 ? Port1CassetteRemoved : Port2CassetteRemoved, dvid);
 
-                             JobDone = false;
 
-                             _waferThicknessType = "";
 
-                         }
 
-                     }
 
-                     else
 
-                     {
 
-                         if (bArrived)
 
-                         {
 
-                             this.HasCassette = true;
 
-                             CarrierManager.Instance.CreateCarrier(Module.ToString());
 
-                             EV.PostInfoLog(mod.ToString(), $"Cassette {WaferSize} arrived");
 
-                             var dvid1 = new SerializableDictionary<string, string>();
 
-                             dvid1["PortID"] = mod == ModuleName.LP1 ? "1" : "2";
 
-                             EV.Notify(mod == ModuleName.LP1 ? Port1CassetteArrive : Port2CassetteArrive, dvid1);
 
-                             JobDone = false;
 
-                             _waferThicknessType = "";
 
-                         }
 
-                     }
 
-                     this.Protrusion = !baData1[9];
 
-                     if (Protrusion)
 
-                     {
 
-                         EV.PostAlarmLog(Module.ToString(), "wafer protrusion");
 
-                         EV.Notify(AlarmWaferProtrude);
 
-                         Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
 
-                     }
 
-                     // DATA2, loadport上面的LED 灯, 暂时不需要用到
 
-                     break;
 
-                 default:
 
-                     break;
 
-             }
 
-         }
 
-         #endregion
 
-         #region TagData
 
-         public void ReadTagData()
 
-         {
 
-             if (IsBusy)
 
-             {
 
-                 EV.PostInfoLog(Module.ToString(), $"{Module} is busy can not read tag data");
 
-                 return;
 
-             }
 
-             if (IsError)
 
-             {
 
-                 EV.PostInfoLog(Module.ToString(), $"{Module} is error can not read tag data");
 
-                 return;
 
-             }
 
-             IsBusy = true;
 
-             _controller.ReadTagData(Module);
 
-         }
 
-         public void OnTagDataRead(string data)
 
-         {
 
-             IsBusy = false;
 
-             IsError = false;
 
-             //Regex rg = new Regex("(?<=(" + "LOT :" + "))[.\\s\\S]*?(?=(" + "QTY :" + "))", RegexOptions.Multiline | RegexOptions.Singleline);
 
-             //string carrierID = rg.Match(data).Value.Replace(":", "").Trim();
 
-             //data =
 
-             //    "CST:C082259     TYPE:CST25_AU   LOT:AF2403      QTY:24          FLOW:033000     STATUS:HOLD     PRI:3-1         PD:0418A        CSRLOT:         CLEAN:2021/11/14 19:57:50       EQPGRP:DUMMY    STAGE:CP-TEST1  RECIPE:DUMMY    EMP:N           ";
 
-             var items = data.Split(new string[] { " ", "\t", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
 
-             CarrierId = "";
 
-             foreach (var item in items)
 
-             {
 
-                 if (item.StartsWith("CST:") && item.Length > 4)
 
-                     CarrierId = item.Substring(4);
 
-                 if (item.StartsWith("LOT:") && item.Length > 4)
 
-                     LotId = item.Substring(4).Trim();
 
-             }
 
-             if (string.IsNullOrEmpty(CarrierId))
 
-             {
 
-                 CarrierId = data;
 
-             }
 
-             SmartTag = data;
 
-             _faCallback.TagDataRead(this);
 
-         }
 
-         public void OnTagDataReadFailed(string data)
 
-         {
 
-             IsError = true;
 
-             IsBusy = false;
 
-             _faCallback.ReadTagDataFailed(this);
 
-         }
 
-         public void WriteTagData(string tagData)
 
-         {
 
-             if (IsBusy)
 
-             {
 
-                 EV.PostInfoLog(Module.ToString(), $"{Module} is busy can not write tag data");
 
-                 return;
 
-             }
 
-             if (IsError)
 
-             {
 
-                 EV.PostInfoLog(Module.ToString(), $"{Module} is error can not write tag data");
 
-                 return;
 
-             }
 
-             IsBusy = true;
 
-             _controller.WriteTagData(Module, tagData);
 
-         }
 
-         public void OnTagDataWrite(string data)
 
-         {
 
-             IsBusy = false;
 
-             IsError = false;
 
-             var items = data.Split(new string[] { " ", "\t", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
 
-             CarrierId = "";
 
-             foreach (var item in items)
 
-             {
 
-                 if (item.StartsWith("CST:") && item.Length > 4)
 
-                     CarrierId = item.Substring(4);
 
-             }
 
-             if (string.IsNullOrEmpty(CarrierId))
 
-             {
 
-                 CarrierId = data;
 
-             }
 
-             SmartTag = data;
 
-             _faCallback.TagDataWrite(this);
 
-         }
 
-         public void OnTagDataWriteFailed(string data)
 
-         {
 
-             IsError = true;
 
-             IsBusy = false;
 
-             _faCallback.WriteTagDataFailed( this);
 
-         }
 
-         #endregion
 
-         public void SetOnline(bool online)
 
-         {
 
-             OnlineFlag = online ? OnlineFlag.Online : OnlineFlag.Offline;
 
-         }
 
-         sealed class LoadPortFACallback
 
-         {
 
-             private const string Port1LoadComplete = "Port1LoadComplete";
 
-             private const string Port1LoadFailed = "Port1LoadFailed";
 
-             private const string Port1UnloadComplete = "Port1UnloadComplete";
 
-             private const string Port1UnloadFailed = "Port1UnloadFailed";
 
-             private const string Port1Clamped = "Port1Clamped";
 
-             private const string Port1Unclamped = "Port1Unclamped";
 
-             private const string Port1IDRead = "Port1IDRead";
 
-             private const string Port1ReadIDFailed = "Port1ReadIDFailed";
 
-             private const string Port1IDWrite = "Port1IDWrite";
 
-             private const string Port1WriteIDFailed = "Port1WriteIDFailed";
 
-             private const string Port1TagDataRead = "Port1TagDataRead";
 
-             private const string Port1ReadTagDataFailed = "Port1ReadTagDataFailed";
 
-             private const string Port1TagDataWrite = "Port1TagDataWrite";
 
-             private const string Port1WriteTagDataFailed = "Port1WriteTagDataFailed";
 
-             private const string Port2LoadComplete = "Port2LoadComplete";
 
-             private const string Port2LoadFailed = "Port2LoadFailed";
 
-             private const string Port2UnloadComplete = "Port2UnloadComplete";
 
-             private const string Port2UnloadFailed = "Port2UnloadFailed";
 
-             private const string Port2Clamped = "Port2Clamped";
 
-             private const string Port2Unclamped = "Port2Unclamped";
 
-             private const string Port2IDRead = "Port2IDRead";
 
-             private const string Port2ReadIDFailed = "Port2ReadIDFailed";
 
-             private const string Port2IDWrite = "Port2IDWrite";
 
-             private const string Port2WriteIDFailed = "Port2WriteIDFailed";
 
-             private const string Port2TagDataRead = "Port2TagDataRead";
 
-             private const string Port2ReadTagDataFailed = "Port2ReadTagDataFailed";
 
-             private const string Port2TagDataWrite = "Port2TagDataWrite";
 
-             private const string Port2WriteTagDataFailed = "Port2WriteTagDataFailed";
 
-             private Dictionary<ModuleName, string> PortLoadComplete = new Dictionary<ModuleName, string>()
 
-         {
 
-             {ModuleName.LP1, Port1LoadComplete},
 
-             {ModuleName.LP2, Port2LoadComplete},
 
-         };
 
-             private Dictionary<ModuleName, string> PortLoadFailed = new Dictionary<ModuleName, string>()
 
-         {
 
-             {ModuleName.LP1, Port1LoadFailed},
 
-             {ModuleName.LP2, Port2LoadFailed},
 
-         };
 
-             private Dictionary<ModuleName, string> PortUnloadComplete = new Dictionary<ModuleName, string>()
 
-         {
 
-             {ModuleName.LP1, Port1UnloadComplete},
 
-             {ModuleName.LP2, Port2UnloadComplete},
 
-         };
 
-             private Dictionary<ModuleName, string> PortUnloadFailed = new Dictionary<ModuleName, string>()
 
-         {
 
-             {ModuleName.LP1, Port1UnloadFailed},
 
-             {ModuleName.LP2, Port2UnloadFailed},
 
-         };
 
-             private Dictionary<ModuleName, string> PortClamped = new Dictionary<ModuleName, string>()
 
-         {
 
-             {ModuleName.LP1, Port1Clamped},
 
-             {ModuleName.LP2, Port2Clamped},
 
-         };
 
-             private Dictionary<ModuleName, string> PortUnclamped = new Dictionary<ModuleName, string>()
 
-         {
 
-             {ModuleName.LP1, Port1Unclamped},
 
-             {ModuleName.LP2, Port2Unclamped},
 
-         };
 
-             private Dictionary<ModuleName, string> PortIDRead = new Dictionary<ModuleName, string>()
 
-         {
 
-             {ModuleName.LP1, Port1IDRead},
 
-             {ModuleName.LP2, Port2IDRead},
 
-         };
 
-             private Dictionary<ModuleName, string> PortReadIDFailed = new Dictionary<ModuleName, string>()
 
-         {
 
-             {ModuleName.LP1, Port1ReadIDFailed},
 
-             {ModuleName.LP2, Port2ReadIDFailed},
 
-         };
 
-             private Dictionary<ModuleName, string> PortIDWrite = new Dictionary<ModuleName, string>()
 
-             {
 
-                 {ModuleName.LP1, Port1IDWrite},
 
-                 {ModuleName.LP2, Port2IDWrite},
 
-             };
 
-             private Dictionary<ModuleName, string> PortWriteIDFailed = new Dictionary<ModuleName, string>()
 
-             {
 
-                 {ModuleName.LP1, Port1WriteIDFailed},
 
-                 {ModuleName.LP2, Port2WriteIDFailed},
 
-             };
 
-             private Dictionary<ModuleName, string> PortTagDataRead = new Dictionary<ModuleName, string>()
 
-             {
 
-                 {ModuleName.LP1, Port1TagDataRead},
 
-                 {ModuleName.LP2, Port2TagDataRead},
 
-             };
 
-             private Dictionary<ModuleName, string> PortReadTagDataFailed = new Dictionary<ModuleName, string>()
 
-             {
 
-                 {ModuleName.LP1, Port1ReadTagDataFailed},
 
-                 {ModuleName.LP2, Port2ReadTagDataFailed},
 
-             };
 
-             private Dictionary<ModuleName, string> PortTagDataWrite = new Dictionary<ModuleName, string>()
 
-             {
 
-                 {ModuleName.LP1, Port1TagDataWrite},
 
-                 {ModuleName.LP2, Port2TagDataWrite},
 
-             };
 
-             private Dictionary<ModuleName, string> PortWriteTagDataFailed = new Dictionary<ModuleName, string>()
 
-             {
 
-                 {ModuleName.LP1, Port1WriteTagDataFailed},
 
-                 {ModuleName.LP2, Port2WriteTagDataFailed},
 
-             };
 
-             private Dictionary<ModuleName, string> PortId = new Dictionary<ModuleName, string>()
 
-         {
 
-             {ModuleName.LP1, "1"},
 
-             {ModuleName.LP2, "2"},
 
-         };
 
-             public LoadPortFACallback()
 
-             {
 
-                 EV.Subscribe(new EventItem("Event", Port1LoadComplete, Port1LoadComplete));
 
-                 EV.Subscribe(new EventItem("Event", Port1LoadFailed, Port1LoadFailed));
 
-                 EV.Subscribe(new EventItem("Event", Port1UnloadComplete, Port1UnloadComplete));
 
-                 EV.Subscribe(new EventItem("Event", Port1UnloadFailed, Port1UnloadFailed));
 
-                 EV.Subscribe(new EventItem("Event", Port1Clamped, Port1Clamped));
 
-                 EV.Subscribe(new EventItem("Event", Port1Unclamped, Port1Unclamped));
 
-                 EV.Subscribe(new EventItem("Event", Port1IDRead, Port1IDRead));
 
-                 EV.Subscribe(new EventItem("Event", Port1ReadIDFailed, Port1ReadIDFailed));
 
-                 EV.Subscribe(new EventItem("Event", Port1IDWrite, Port1IDWrite));
 
-                 EV.Subscribe(new EventItem("Event", Port1WriteIDFailed, Port1WriteIDFailed));
 
-                 EV.Subscribe(new EventItem("Event", Port1TagDataRead, Port1TagDataRead));
 
-                 EV.Subscribe(new EventItem("Event", Port1ReadTagDataFailed, Port1ReadTagDataFailed));
 
-                 EV.Subscribe(new EventItem("Event", Port1TagDataWrite, Port1TagDataWrite));
 
-                 EV.Subscribe(new EventItem("Event", Port1WriteTagDataFailed, Port1WriteTagDataFailed));
 
-                 EV.Subscribe(new EventItem("Event", Port2LoadComplete, Port2LoadComplete));
 
-                 EV.Subscribe(new EventItem("Event", Port2LoadFailed, Port2LoadFailed));
 
-                 EV.Subscribe(new EventItem("Event", Port2UnloadComplete, Port2UnloadComplete));
 
-                 EV.Subscribe(new EventItem("Event", Port2UnloadFailed, Port2UnloadFailed));
 
-                 EV.Subscribe(new EventItem("Event", Port2Clamped, Port2Clamped));
 
-                 EV.Subscribe(new EventItem("Event", Port2Unclamped, Port2Unclamped));
 
-                 EV.Subscribe(new EventItem("Event", Port2IDRead, Port2IDRead));
 
-                 EV.Subscribe(new EventItem("Event", Port2ReadIDFailed, Port2ReadIDFailed));
 
-                 EV.Subscribe(new EventItem("Event", Port2IDWrite, Port2IDWrite));
 
-                 EV.Subscribe(new EventItem("Event", Port2WriteIDFailed, Port2WriteIDFailed));
 
-                 EV.Subscribe(new EventItem("Event", Port2TagDataRead, Port2TagDataRead));
 
-                 EV.Subscribe(new EventItem("Event", Port2ReadTagDataFailed, Port2ReadTagDataFailed));
 
-                 EV.Subscribe(new EventItem("Event", Port2TagDataWrite, Port2TagDataWrite));
 
-                 EV.Subscribe(new EventItem("Event", Port2WriteTagDataFailed, Port2WriteTagDataFailed));
 
-             }
 
-             public void LoadComplete(Loadport lp)
 
-             {
 
-                 ModuleName moduleName = lp.Module;
 
-                 EV.Notify(PortLoadComplete[moduleName], new SerializableDictionary<string, string>()
 
-             {
 
-                 {DVIDName.PortID, PortId[lp.Module] },
 
-                 {DVIDName.CarrierID, lp.CarrierId??"" },
 
-             });
 
-             }
 
-             public void LoadFailed(Loadport lp)
 
-             {
 
-                 ModuleName moduleName = lp.Module;
 
-                 EV.Notify(PortLoadFailed[moduleName], new SerializableDictionary<string, string>()
 
-             {
 
-                 {DVIDName.PortID, PortId[lp.Module] },
 
-                 {DVIDName.CarrierID, lp.CarrierId??"" },
 
-             });
 
-             }
 
-             public void UnloadComplete(Loadport lp)
 
-             {
 
-                 ModuleName moduleName = lp.Module;
 
-                 EV.Notify(PortUnloadComplete[moduleName], new SerializableDictionary<string, string>()
 
-             {
 
-                 {DVIDName.PortID, PortId[lp.Module] },
 
-                 {DVIDName.CarrierID, lp.CarrierId??"" },
 
-             });
 
-             }
 
-             public void UnloadFailed(Loadport lp)
 
-             {
 
-                 ModuleName moduleName = lp.Module;
 
-                 EV.Notify(PortUnloadFailed[moduleName], new SerializableDictionary<string, string>()
 
-             {
 
-                 {DVIDName.PortID, PortId[lp.Module] },
 
-                 {DVIDName.CarrierID, lp.CarrierId??"" },
 
-             });
 
-             }
 
-             public void Clamped(Loadport lp)
 
-             {
 
-                 ModuleName moduleName = lp.Module;
 
-                 EV.Notify(PortClamped[moduleName], new SerializableDictionary<string, string>()
 
-             {
 
-                 {DVIDName.PortID, PortId[lp.Module] },
 
-             });
 
-             }
 
-             public void Unclamped(Loadport lp)
 
-             {
 
-                 ModuleName moduleName = lp.Module;
 
-                 EV.Notify(PortUnclamped[moduleName], new SerializableDictionary<string, string>()
 
-             {
 
-                 {DVIDName.PortID, PortId[lp.Module] },
 
-             });
 
-             }
 
-             public void IDRead(Loadport lp)
 
-             {
 
-                 ModuleName moduleName = lp.Module;
 
-                 EV.Notify(PortIDRead[moduleName], new SerializableDictionary<string, string>()
 
-             {
 
-                 {DVIDName.PortID, PortId[lp.Module] },
 
-                 {DVIDName.CarrierID, lp.CarrierId },
 
-                 {DVIDName.LotID, lp.LotId },
 
-             });
 
-             }
 
-             public void ReadIDFailed(Loadport lp)
 
-             {
 
-                 ModuleName moduleName = lp.Module;
 
-                 EV.Notify(PortReadIDFailed[moduleName], new SerializableDictionary<string, string>()
 
-             {
 
-                 {DVIDName.PortID, PortId[lp.Module] },
 
-             });
 
-             }
 
-             public void IDWrite(Loadport lp)
 
-             {
 
-                 ModuleName moduleName = lp.Module;
 
-                 EV.Notify(PortIDWrite[moduleName], new SerializableDictionary<string, string>()
 
-                 {
 
-                     {DVIDName.PortID, PortId[lp.Module] },
 
-                     {DVIDName.CarrierID, lp.CarrierId },
 
-                 });
 
-             }
 
-             public void WriteIDFailed(Loadport lp)
 
-             {
 
-                 ModuleName moduleName = lp.Module;
 
-                 EV.Notify(PortWriteIDFailed[moduleName], new SerializableDictionary<string, string>()
 
-                 {
 
-                     {DVIDName.PortID, PortId[lp.Module] },
 
-                 });
 
-             }
 
-             public void TagDataRead(Loadport lp)
 
-             {
 
-                 ModuleName moduleName = lp.Module;
 
-                 EV.Notify(PortTagDataRead[moduleName], new SerializableDictionary<string, string>()
 
-                 {
 
-                     {DVIDName.PortID, PortId[lp.Module] },
 
-                     {DVIDName.TagData, lp.SmartTag },
 
-                     {DVIDName.CarrierID, lp.CarrierId },
 
-                     {DVIDName.LotID, lp.LotId },
 
-                 });
 
-             }
 
-             public void ReadTagDataFailed(Loadport lp)
 
-             {
 
-                 ModuleName moduleName = lp.Module;
 
-                 EV.Notify(PortReadTagDataFailed[moduleName], new SerializableDictionary<string, string>()
 
-                 {
 
-                     {DVIDName.PortID, PortId[lp.Module] },
 
-                 });
 
-             }
 
-             public void TagDataWrite(Loadport lp)
 
-             {
 
-                 ModuleName moduleName = lp.Module;
 
-                 EV.Notify(PortTagDataWrite[moduleName], new SerializableDictionary<string, string>()
 
-                 {
 
-                     {DVIDName.PortID, PortId[lp.Module] },
 
-                     {DVIDName.CarrierID, lp.CarrierId },
 
-                     {DVIDName.TagData, lp.SmartTag },
 
-                 });
 
-             }
 
-             public void WriteTagDataFailed(Loadport lp)
 
-             {
 
-                 ModuleName moduleName = lp.Module;
 
-                 EV.Notify(PortWriteTagDataFailed[moduleName], new SerializableDictionary<string, string>()
 
-                 {
 
-                     {DVIDName.PortID, PortId[lp.Module] },
 
-                 });
 
-             }
 
-         }
 
-     }
 
- }
 
 
  |