123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Collections;
- using CyberX8_Core;
- using CyberX8_RT.Modules;
- using MECF.Framework.Common.CommonData;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.SubstrateTrackings;
- using Aitex.Sorter.Common;
- using Aitex.Core.Common;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.RT.Log;
- using Aitex.Core.Util;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
- using CyberX8_RT.Devices.YASKAWA;
- using System.Collections.Concurrent;
- using System.Diagnostics;
- using System.Data.SqlTypes;
- using System.Windows.Media.Media3D;
- using System.ComponentModel;
- using MECF.Framework.Common.Beckhoff.Station;
- using System.Runtime.Remoting.Contexts;
- using System.Windows.Markup;
- using CyberX8_RT.Modules.LPs;
- using MECF.Framework.Common.ToolLayout;
- namespace CyberX8_RT.Devices.EFEM
- {
- public class SunWayRobot : EfemBase
- {
- #region 常量
- private const string NONE = "None";
- #endregion
- private RState _status;
- private bool _IsHomed;
- private bool _bIsUnloadClamp;
- private RobotMoveInfo _robotMoveInfo = new RobotMoveInfo();
- private readonly SignalTower _signalT = new SignalTower();
- private readonly AsyncSocket _socket;
- private EfemMessage _currentMessage;
- private string _error;
- private bool _LiftIsUp = false;
- private bool _LiftIsDown = false;
- private R_TRIG _busyTrig = new R_TRIG();
- private Stopwatch _busyWatch = new Stopwatch();
- private Dictionary<string, int> _moduleStationNumberDictionary = new Dictionary<string, int>();
- private Dictionary<Hand, string> _armString = new Dictionary<Hand, string>
- {
- [Hand.Blade1] = "A",
- [Hand.Blade2] = "B"
- };
- public override RState Status
- {
- get
- {
- _busyTrig.CLK = _status == RState.Running;
- if (_busyTrig.Q)
- {
- _busyWatch.Restart();
- }
- else if (_busyTrig.M)
- {
- int timeOut = 5000;
- if (
- _currentMessage.Operation == EfemOperation.Home ||
- _currentMessage.Operation == EfemOperation.Map ||
- _currentMessage.Operation == EfemOperation.Pick ||
- _currentMessage.Operation == EfemOperation.Place)
- {
- timeOut = 30000;
- }
- if (_busyWatch.ElapsedMilliseconds > timeOut)
- {
- _busyWatch.Stop();
- _status = RState.Timeout;
- }
- }
- return _status;
- }
- }
- public override bool IsHomed { get { return _IsHomed; } }
- public override RobotMoveInfo TMRobotMoveInfo { get { return _robotMoveInfo; } }
- public override bool LiftIsUp { get { return _LiftIsUp; } }
- public override bool LiftIsDown { get { return _LiftIsDown; } }
- private BlockingCollection<RobotAnimationData> blockingCollection = new BlockingCollection<RobotAnimationData>();
- private string _address = "";
- public SunWayRobot()
- {
- _socket = new AsyncSocket("","",DataType.Ascii,true);
- try
- {
- _address = SC.GetStringValue($"EFEM.IPAddress");
- _socket.Connect(_address);
- _socket.OnConnect += Socket_OnConnect;
- _socket.OnDataChanged += OnReceiveMessage;
- _socket.OnErrorHappened += OnErrorHappen;
- }
- catch(Exception ex)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, "EFEM", ex.Message);
- }
- _status = RState.Init;
- _IsHomed = false;
- _busyTrig.RST = true;
- InitializeModuleStation(ModuleName.LP1);
- InitializeModuleStation(ModuleName.LP2);
- InitializeModuleStation(ModuleName.LP3);
- InitializeModuleStation(ModuleName.Dummy1);
- InitializeModuleStation(ModuleName.Dummy2);
- CarrierManager.Instance.SubscribeLocation(ModuleName.LP1.ToString(), 1);
- CarrierManager.Instance.SubscribeLocation(ModuleName.LP2.ToString(), 1);
- CarrierManager.Instance.SubscribeLocation(ModuleName.LP3.ToString(), 1);
- WaferManager.Instance.SubscribeLocation(ModuleName.EfemRobot, 2);
- WaferManager.Instance.SubscribeLocation(ModuleName.Aligner1, 1);
- WaferManager.Instance.SubscribeLocation(ModuleName.LP1, SC.GetValue<int>("EFEM.LoadPort.SlotNumber"));
- WaferManager.Instance.SubscribeLocation(ModuleName.LP2, SC.GetValue<int>("EFEM.LoadPort.SlotNumber"));
- WaferManager.Instance.SubscribeLocation(ModuleName.LP3, SC.GetValue<int>("EFEM.LoadPort.SlotNumber"));
- Task.Run(() =>
- {
- foreach (var data in blockingCollection.GetConsumingEnumerable())
- {
- _robotMoveInfo.Action = data.Action;
- _robotMoveInfo.ArmTarget = data.Hand == Hand.Blade1 ? RobotArm.ArmA : (data.Hand == Hand.Both ? RobotArm.Both : RobotArm.ArmB);
- _robotMoveInfo.BladeTarget = $"{_robotMoveInfo.ArmTarget}.{data.Target}";
- System.Threading.Thread.Sleep(600);
- }
- });
- }
- /// <summary>
- /// 初始化Module Station
- /// </summary>
- /// <param name="module"></param>
- private void InitializeModuleStation(ModuleName module)
- {
- int cassete200Station = SC.GetValue<int>($"EFEM.{module}.Cassete200Station");
- _moduleStationNumberDictionary[$"{module}_200"] = cassete200Station;
- int cassete150Station = SC.GetValue<int>($"EFEM.{module}.Cassete150Station");
- _moduleStationNumberDictionary[$"{module}_150"] = cassete150Station;
- int cassete100Station = SC.GetValue<int>($"EFEM.{module}.Cassete100Station");
- _moduleStationNumberDictionary[$"{module}_100"]=cassete100Station;
- }
- private void Socket_OnConnect()
- {
- Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.CommReady);
- LOG.WriteBackgroundLog(eEvent.EV_EFEM_COMMON_INFO, Module.ToString(), $"connect {_address} success");
- }
- private void OnErrorHappen(ErrorEventArgs args)
- {
- _status = RState.Failed;
- if (_error != args.Reason)
- {
- _error = args.Reason;
- LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, Module, $"{Module} {_error}");
- }
- Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error);
- }
- public override void Monitor()
- {
- }
- public override void Terminate()
- {
- }
- public override void Reset()
- {
- _status = RState.End;
- _currentMessage = null;
- }
- public override void SetOnline(bool online)
- {
- }
- public override void SetOnline(ModuleName mod, bool online)
- {
- }
- public override void SetBusy(ModuleName mod, bool online)
- {
- _status = RState.Running;
- }
- public override bool HomeAll()
- {
- if (_status == RState.Running&&_currentMessage!=null)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot home All");
- return false;
- }
- //判断socket是否链接
- if (!_socket.IsConnected)
- {
- LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
- return false ;
- }
- _status = RState.Running;
- string data = "HOME ALL\r";
- _currentMessage =new EfemMessage(){
- Operation= EfemOperation.Home,
- Module=ModuleName.EFEM
- };
- SetRobotMovingInfo(RobotAction.Homing, Hand.Both, ModuleName.EFEM);
- return WriteCommand(data);
- }
- public override bool Home(ModuleName mod)
- {
- if (_status == RState.Running && _currentMessage!= null)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot home {mod}");
- return false;
- }
- if (mod != ModuleName.Aligner)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{mod} can not support home method");
- return false;
- }
- //判断socket是否链接
- if (!_socket.IsConnected)
- {
- LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
- return false;
- }
- if(mod == ModuleName.EfemRobot) SetRobotMovingInfo(RobotAction.Homing, Hand.Blade1, ModuleName.EfemRobot);
- _status = RState.Running;
- string cmd = "ALIGNER HOME\r";
- _currentMessage = new EfemMessage()
- {
- Operation = EfemOperation.Home,
- Module = ModuleName.Aligner1
- };
- return WriteCommand(cmd);
- }
- public override bool OriginalSearch(ModuleName mod)
- {
- return true;
- }
- public override bool CheckWaferPresence()
- {
- if (_status == RState.Running && _currentMessage != null)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot check wafer");
- return false;
- }
- //判断socket是否链接
- if (!_socket.IsConnected)
- {
- LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
- return false;
- }
- if (!CheckEfemStatus())
- return false;
- _currentMessage = new EfemMessage()
- {
- Operation = EfemOperation.StateTrack,
- Module = ModuleName.EfemRobot
- };
- _status = RState.Running;
- string cmd = $"RQ LOAD {_armString[Hand.Blade1]}\r";
- return WriteCommand(cmd);
- }
- public override string GetWaferPresence()
- {
- return "";
- }
- public override bool Halt()
- {
- if (_status == RState.Running && _currentMessage != null)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot halt");
- return false;
- }
- //判断socket是否链接
- if (!_socket.IsConnected)
- {
- LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
- return false;
- }
- _currentMessage = new EfemMessage()
- {
- Operation = EfemOperation.Abort,
- Module = ModuleName.EfemRobot
- };
- string cmd = "HALT\r";
- return WriteCommand(cmd);
- }
- public override bool ClearError()
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.ClearError]}");
- return false;
- }
- public override bool CloseBuzzer()
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.TurnOffBuzzer]}");
- return false;
- }
- public override bool PickExtend(ModuleName chamber, int slot, Hand hand)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Extend]}");
- return false;
- }
- public override bool PickRetract(ModuleName chamber, int slot, Hand hand)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Extend]}");
- return false;
- }
- public override bool PlaceExtend(ModuleName chamber, int slot, Hand hand)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Extend]}");
- return false;
- }
- public override bool PlaceRetract(ModuleName chamber, int slot, Hand hand)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Extend]}");
- return false;
- }
- public override bool Pick(ModuleName station, int slot, Hand hand)
- {
- if (_status == RState.Running && _currentMessage != null)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot pick");
- return false;
- }
- //判断socket是否链接
- if (!_socket.IsConnected)
- {
- LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
- return false;
- }
-
- //判断Loadport的门是否打开
- //if (ModuleHelper.IsLoadPort(station) && !GetLoadPort(station).IsDoorOpened)
- //{
- // LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{station}'s Door is Closed, Cannot Execute Pick Action");
- // return false;
- //}
- if (!CheckEfemStatus())
- return false;
- int waferSize = GetModuleNameWaferSize(station);
- if (waferSize == 0)
- {
- return false;
- }
- string strModuleWaferSize = $"{station}_{waferSize}";
- if (!_moduleStationNumberDictionary.ContainsKey(strModuleWaferSize))
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{station}'s number is not exist, Cannot Execute Pick Action");
- return false;
- }
- int stationNumber= _moduleStationNumberDictionary[strModuleWaferSize];
- string cmd = $"PICK {stationNumber} SLOT {slot+1} ARM {_armString[hand]}\r";
- _currentMessage = new EfemMessage()
- {
- Operation=EfemOperation.Pick
- };
- _status = RState.Running;
- SetRobotMovingInfo(RobotAction.Picking, hand, station);
- return WriteCommand(cmd);
- }
- private Loadport GetLoadPort(ModuleName station)
- {
- LoadPortModule loadPortModule = Singleton<RouteManager>.Instance.EFEM.GetLoadportModule(station - ModuleName.LP1);
- return loadPortModule.LPDevice;
- }
- public override bool Place(ModuleName station, int slot, Hand hand)
- {
- if (_status == RState.Running && _currentMessage != null)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot place");
- return false;
- }
- //判断socket是否链接
- if (!_socket.IsConnected)
- {
- LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
- return false;
- }
- //判断Loadport的门是否打开
- //if (ModuleHelper.IsLoadPort(station) && !GetLoadPort(station).IsDoorOpened)
- //{
- // LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{station}'s Door is Closed, Cannot Execute Pick Action");
- // return false;
- //}
- if (!CheckEfemStatus())
- return false;
- int waferSize = GetModuleNameWaferSize(station);
- if (waferSize == 0)
- {
- return false;
- }
- string strModuleWaferSize = $"{station}_{waferSize}";
- _currentMessage = new EfemMessage()
- {
- Operation = EfemOperation.Place
- };
- _status = RState.Running;
- int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
- string cmd = $"PLACE {stationNumber} SLOT {slot+1} ARM {_armString[hand]}\r";
- SetRobotMovingInfo(RobotAction.Placing, hand, station);
- return WriteCommand(cmd);
- }
- public override bool Goto(ModuleName station, Hand hand, string updown = "UP")
- {
- if (_status == RState.Running && _currentMessage != null)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot goto");
- return false;
- }
- if (!CheckEfemStatus())
- return false;
- //判断socket是否链接
- if (!_socket.IsConnected)
- {
- LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
- return false;
- }
- _currentMessage = new EfemMessage()
- {
- Operation = EfemOperation.Goto
- };
- int waferSize = GetModuleNameWaferSize(station);
- if (waferSize == 0)
- {
- return false;
- }
- string strModuleWaferSize = $"{station}_{waferSize}";
- int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
- string cmd = $"GOTO N {stationNumber} R EX Z {updown} ARM SLOT 1 {_armString[hand]}\r";
- _status = RState.Running;
- return WriteCommand(cmd);
- }
- public override bool Grip(Hand blade, bool isGrip)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Grip]}");
- return false;
- }
- public override bool GotoMap(ModuleName mod,Hand hand,string extend="EX")
- {
- if (_status == RState.Running && _currentMessage != null)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot goto map");
- return false;
- }
- //判断socket是否链接
- if (!_socket.IsConnected)
- {
- LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
- return false;
- }
- if (!CheckEfemStatus())
- return false;
- int waferSize = GetModuleNameWaferSize(mod);
- if (waferSize == 0)
- {
- return false;
- }
- string strModuleWaferSize = $"{mod}_{waferSize}";
- int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
- string cmd = $"GOTO N {stationNumber} MAP {extend} ARM {_armString[hand]}\r";
- _currentMessage = new EfemMessage()
- {
- Operation = EfemOperation.Goto,
- Module= mod
- };
- _status = RState.Running;
- return WriteCommand(cmd);
- }
- public override bool Map(ModuleName mod)
- {
- if (_status == RState.Running && _currentMessage != null)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot map");
- return false;
- }
- //判断socket是否链接
- if (!_socket.IsConnected)
- {
- LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
- return false;
- }
- if (!CheckEfemStatus())
- return false;
- int waferSize = GetModuleNameWaferSize(mod);
- if (waferSize == 0)
- {
- return false;
- }
- string strModuleWaferSize = $"{mod}_{waferSize}";
- int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
- _currentMessage = new EfemMessage()
- {
- Operation = EfemOperation.Home,
- Module = mod
- };
- string cmd = $"MAP {stationNumber} ARM {_armString[Hand.Blade1]}\r";
- _status = RState.Running;
- return WriteCommand(cmd);
- }
- public override bool RequestMapResult(ModuleName mod)
- {
- if (_status == RState.Running && _currentMessage != null)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot request map");
- return false;
- }
- //判断socket是否链接
- if (!_socket.IsConnected)
- {
- LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
- return false;
- }
- if (!CheckEfemStatus())
- return false;
- int waferSize = GetModuleNameWaferSize(mod);
- if (waferSize == 0)
- {
- return false;
- }
- string strModuleWaferSize = $"{mod}_{waferSize}";
- int stationNumber = _moduleStationNumberDictionary[strModuleWaferSize];
- _currentMessage = new EfemMessage()
- {
- Operation = EfemOperation.RequestMapResult,
- Module = mod
- };
- string cmd = $"RSR {stationNumber} ARM {_armString[Hand.Blade1]}\r";
- _status = RState.Running;
- return WriteCommand(cmd);
- }
- public override bool Vacuum(ModuleName mod,bool VacuumState)
- {
- if (_status == RState.Running && _currentMessage != null)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot vacuum");
- return false;
- }
- //判断socket是否链接
- if (!_socket.IsConnected)
- {
- LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
- return false;
- }
- _currentMessage = new EfemMessage()
- {
- Operation = EfemOperation.Vacuum,
- Module = mod
- };
- _status = RState.Running;
- string strVacuum = VacuumState ? "ON" : "OFF";
- string cmd = $"VAC {strVacuum} ARM {_armString[Hand.Blade1]}";
- return WriteCommand(cmd);
- }
- public override bool GetWaferSize(ModuleName mod)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support GetWaferSize");
- return false;
- }
- public override bool SetWaferSize(ModuleName mod, int WaferSize)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support SetWaferSize");
- return false;
- }
- public override bool SetPinUp(ModuleName mod)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Lift]}");
- return false;
- }
- public override bool SetPinDown(ModuleName mod)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.Lift]}");
- return false;
- }
- public override bool SetAlignAngle(ModuleName mod, double angle)
- {
- if (_status == RState.Running && _currentMessage != null)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot Align Angle");
- return false;
- }
- if (!CheckEfemStatus())
- return false;
- //判断socket是否链接
- if (!_socket.IsConnected)
- {
- LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
- return false;
- }
- _currentMessage = new EfemMessage()
- {
- Operation = EfemOperation.Align,
- };
- string cmd = $"SET ALIGNER CCDPOS {angle}\r";
- _status = RState.Running;
- return WriteCommand(cmd);
- }
- public override bool SetRobotSpeed(ModuleName mod, int speed)
- {
- if (_status == RState.Running && _currentMessage != null)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot Speed");
- return false;
- }
- //判断socket是否链接
- if (!_socket.IsConnected)
- {
- LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
- return false;
- }
- _currentMessage = new EfemMessage()
- {
- Operation = EfemOperation.Speed
- };
- string cmd = $"SET ACTION SPEEDS {speed}\r";
- _status = RState.Running;
- return WriteCommand(cmd);
- }
- public override bool RobotPowerOn(ModuleName mod, bool Status)
- {
- if (_status == RState.Running && _currentMessage != null)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot PowerOn");
- return false;
- }
- //判断socket是否链接
- if (!_socket.IsConnected)
- {
- LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
- return false;
- }
- string status = "ON";
- if (!Status)
- {
- status = "OFF";
- }
- _currentMessage = new EfemMessage()
- {
- Operation = EfemOperation.PowerOn
- };
- string cmd = $"SET SERVOS {status}\r";
- _status = RState.Running;
- return WriteCommand(cmd);
- }
- public override bool Align(ModuleName mod, double angle, float delayTime, WaferSize size)
- {
- if (_status == RState.Running && _currentMessage != null)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"Current Msg {_currentMessage.Operation} is Running,cannot Align");
- return false;
- }
- //判断socket是否链接
- if (!_socket.IsConnected)
- {
- LOG.WriteLog(eEvent.ERROR_EFEM_COMMUNICATION, Module.ToString(), $"Socket is not Conntected");
- return false;
- }
- if (!CheckEfemStatus())
- return false;
- _currentMessage = new EfemMessage()
- {
- Operation = EfemOperation.Align
- };
- _status = RState.Running;
- string cmd = "ALIGNER ALGN\r";
- return WriteCommand(cmd);
- }
- public override bool SetLamp(LightType light, LightStatus status)
- {
- return false;
- }
- public override bool Load(ModuleName mod)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Load");
- return false;
- }
- public override bool Unload(ModuleName mod)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Unload");
- return false;
- }
- public override bool ReadCarrierId(ModuleName mod)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support ReadCarrierId");
- return false;
- }
- public override bool WriteCarrierId(ModuleName mod, string id)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support WriteCarrierId");
- return false;
- }
- public override bool ReadTagData(ModuleName mod)
- {
- return ReadCarrierId(mod);
- }
- public override bool WriteTagData(ModuleName mod, string tagData)
- {
- return WriteCarrierId(mod, tagData);
- }
- public override bool Dock(ModuleName mod)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Dock");
- return false;
- }
- public override bool Undock(ModuleName mod)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Undock");
- return false;
- }
- public override bool Clamp(ModuleName mod, bool isUnloadClamp)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Clamp");
- return false;
- }
- public override bool Unclamp(ModuleName mod)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support Unclamp");
- return false;
- }
- public override bool SetThickness(ModuleName mod, string thickness)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"System cannot support {EfemConstant.OperationString[EfemOperation.SetThickness]}");
- return false;
- }
- public override void SetRobotMovingInfo(RobotAction action, Hand hand, ModuleName target)
- {
- blockingCollection.Add(new RobotAnimationData(action, hand, target));
- }
- private void OnReceiveMessage(string msg)
- {
- LOG.WriteBackgroundLog(eEvent.EV_EFEM_COMMON_INFO, Module.ToString(), msg.Replace("\r",""));
- if (_currentMessage == null)
- {
- return;
- }
- if(msg.StartsWith("_ERR"))
- {
- string error = msg.Replace("_ERR", "").Trim();
- OnErrorOccurred(error);
- _currentMessage = null;
- return;
- }
- else if(msg.StartsWith("_RDY"))
- {
- _status = RState.End;
- switch (_currentMessage.Operation)
- {
- case EfemOperation.Home:
- SetRobotMovingInfo(RobotAction.Homing, Hand.Both, ModuleName.EFEM);
- break;
- case EfemOperation.Map:
- case EfemOperation.GotoMap:
- if (ModuleHelper.IsLoadPort(_currentMessage.Module))
- {
- GetLoadPort(_currentMessage.Module).OnMaped();
- }
- break;
- }
- }
- else
- {
- switch (_currentMessage.Operation)
- {
- case EfemOperation.StateTrack:
- DealStateTrack(msg);
- break;
- case EfemOperation.RequestMapResult:
- DealMapResult(msg);
- break;
- }
- _status = RState.End;
- _currentMessage = null;
- }
- }
- /// <summary>
- /// 处理StateTrack结果
- /// </summary>
- /// <param name="msg"></param>
- private void DealStateTrack(string msg)
- {
- if (msg.StartsWith("LOAD"))
- {
- string[] strAry = msg.Trim().Split(' ');
- if (strAry.Length >= 2)
- {
- bool hasWafer = strAry[2] == "ON" ? true : false;
- if (strAry[1] == _armString[Hand.Blade1])
- {
- if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0)&& hasWafer)
- {
- WaferManager.Instance.CreateWafer(ModuleName.EfemRobot, 0, WaferStatus.Normal);
- }
- }
- else if (strAry[1] == _armString[Hand.Blade2])
- {
- if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1) && hasWafer)
- {
- WaferManager.Instance.CreateWafer(ModuleName.EfemRobot, 1, WaferStatus.Normal);
- }
- }
- }
- }
- }
- /// <summary>
- /// 处理Map结果
- /// </summary>
- /// <param name="msg"></param>
- private void DealMapResult(string msg)
- {
- if (_currentMessage.Operation != EfemOperation.RequestMapResult)
- {
- return;
- }
- if(!msg.StartsWith("MAP"))
- {
- return;
- }
- string[] sWaferInfo = msg.Split(new char[] { ' ', '\r', '\n' });
- if (sWaferInfo.Length <= 2)
- {
- return;
- }
- int slotMap = SC.GetValue<int>("EFEM.LoadPort.SlotNumber");
- if (ModuleHelper.IsDummy(_currentMessage.Module))
- {
- DummyCassetteItem item = DummyCasseteItemManager.Instance.GetDummyCassetteItem(_currentMessage.Module.ToString());
- if (item != null)
- {
- slotMap = item.MaxNumberOfSlots;
- }
- }
- //Map 结果(1 1 1 1 1 1 1 ...0)
- int startIndex = 1;
- int count = slotMap >= sWaferInfo.Length-startIndex? sWaferInfo.Length-startIndex : slotMap;
- bool result = true;
- for (int index = startIndex; index <= count; index++)
- {
- int waferState = int.Parse(sWaferInfo[index]);
- //合理的映射到内部支持的叠片/交叉片
- if (waferState >= 7) waferState = 7;
- else if (waferState >= 2) waferState = 3;
- WaferStatus st = (WaferStatus)waferState;
- if (st != WaferStatus.Empty)
- {
- WaferManager.Instance.CreateWafer(_currentMessage.Module, index-startIndex, st);
- if (st != WaferStatus.Normal)
- {
- result = false;
- }
- }
- else
- {
- WaferManager.Instance.DeleteWafer(_currentMessage.Module, index-startIndex);
- }
- }
- if (ModuleHelper.IsLoadPort(_currentMessage.Module))
- {
- GetLoadPort(_currentMessage.Module).UpdateMapResult(result);
- }
- }
- private void OnErrorOccurred(string errorCode)
- {
- _status = RState.Failed;
- string description = errorCode;
- if (SumWayRobotErrorCode.ErrorCodeDescription.ContainsKey(errorCode))
- {
- description=SumWayRobotErrorCode.ErrorCodeDescription[errorCode];
- }
- Singleton<RouteManager>.Instance.EFEM.PostMsg(EfemEntity.MSG.Error, description);
- if (_currentMessage != null)
- {
- LOG.Write(eEvent.ERR_EFEM_COMMON_FAILED, ModuleName.EFEM, $"current operation {_currentMessage.Operation} failed,{description}");
- }
- _currentMessage=null;
- }
- private bool WriteCommand(string cmd)
- {
- LOG.WriteBackgroundLog(eEvent.EV_EFEM_COMMON_INFO, Module.ToString(), cmd.Replace("\r", ""));
- return _socket.Write(cmd);
- }
- /// <summary>
- /// 获取模块尺寸
- /// </summary>
- /// <param name="moduleName"></param>
- /// <returns></returns>
- private int GetModuleNameWaferSize(ModuleName moduleName)
- {
- if (ModuleHelper.IsLoadPort(moduleName))
- {
- Loadport loadport = GetLoadPort(moduleName);
- if (!loadport.HasCassette)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{moduleName} does not have cassete.");
- return 0;
- }
- return (int)loadport.WaferSize;
- }
- else if (ModuleHelper.IsDummy(moduleName))
- {
- DummyDevice dummyDevice = Singleton<RouteManager>.Instance.EFEM.GetDummyDevice(moduleName - ModuleName.Dummy1);
- if (!dummyDevice.HasCassette)
- {
- LOG.WriteLog(eEvent.ERR_EFEM_COMMON_FAILED, Module.ToString(), $"{moduleName} does not have cassete.");
- return 0;
- }
- return (int)dummyDevice.WaferSize;
- }
- return 0;
- }
- }
- }
|