RouteManager.cs 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using Aitex.Core.Common;
  6. using Aitex.Core.RT.DataCenter;
  7. using Aitex.Core.RT.Device;
  8. using Aitex.Core.RT.Event;
  9. using Aitex.Core.RT.Fsm;
  10. using Aitex.Core.RT.OperationCenter;
  11. using Aitex.Core.RT.Routine;
  12. using Aitex.Core.RT.SCCore;
  13. using Aitex.Core.Util;
  14. using EFEM.RT.Devices;
  15. using EFEM.RT.Routines;
  16. using EFEM.RT.Routines.LP;
  17. using EFEM.RT.Tasks;
  18. using Aitex.Sorter.Common;
  19. using EFEMSC;
  20. using MECF.Framework.Common.Equipment;
  21. using MECF.Framework.Common.SubstrateTrackings;
  22. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  23. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  24. using IEntity = Aitex.Core.RT.Fsm.IEntity;
  25. using Aitex.Sorter.RT.Module;
  26. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
  27. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
  28. using Aitex.Core.RT.Log;
  29. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.BufferStations;
  30. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Flipper.FlipperBase;
  31. using static EFEM.RT.Devices.FlipperEntity;
  32. namespace EFEM.RT.Modules
  33. {
  34. public class RouteManager : Entity, IEntity, IModuleEntity
  35. {
  36. public enum MSG
  37. {
  38. MultiMoveWafer,
  39. MoveWafer,
  40. ReturnWafer,
  41. SetSpeed,
  42. HomeUnit,
  43. ReadID,
  44. WriteID,
  45. ReadAndLoad,
  46. LOAD,
  47. UNLOAD,
  48. Pause,
  49. Resume,
  50. Stop,
  51. StartCycle,
  52. Init,
  53. HOME,
  54. RESET,
  55. ABORT,
  56. ERROR,
  57. StartRecipe,
  58. StopRecipe,
  59. PauseRecipe,
  60. ResumeRecipe,
  61. SetAutoMode,
  62. SetManualMode,
  63. //SetLocalMode,
  64. //SetRemoteMode,
  65. SetMaintenanceMode,
  66. MapWafer,
  67. Pick,
  68. Place,
  69. MPNTPick,
  70. MPNTPlace,
  71. RobotActionDone,
  72. LoadPortActionDone,
  73. ChangeCassette
  74. }
  75. //routine
  76. private readonly bool _isInterferencePrevent =
  77. DeviceDefineManager.Instance.GetValue<bool>("InterferencePrevent") ?? false;
  78. private IEfemRoutine initRoutine = null;
  79. private SetSpeedRoutine setspeedRoutine = null;
  80. private WaferMappingRoutine _waferMapRoutine;
  81. private LoadFoupRoutine _loadFoupRoutine;
  82. private PickRoutine _pickRoutine;
  83. private PickExtendRoutine _pickExtendRoutine;
  84. private PlaceRoutine _placeRoutine;
  85. private PlaceExtendRoutine _placeExtendRoutine;
  86. private SorterCycleManager _cycle = new SorterCycleManager();
  87. //TrigRobotSafetyToLP1 Locker
  88. //private static readonly object _robotSafetyToLP1Locker = new object();
  89. //TrigRobotSafetyToLP2 Locker
  90. //private static readonly object _robotSafetyToLP2Locker = new object();
  91. private int LoadPortQuantity = DeviceDefineManager.Instance.GetValue<int>("LoadPortQuantity") ?? 0;
  92. //private int LoadLockQuantity = DeviceDefineManager.Instance.GetValue<int>("LoadLockQuantity") ?? 0;
  93. private static readonly bool FlipperIsDisable = SC.ContainsItem("System.FlipperDisable") ? SC.GetValue<bool>("System.FlipperDisable") : true;
  94. public bool IsTransferMode { get; private set; }
  95. public bool IsAutoMode { get; private set; }
  96. public bool IsFFUOk { get; set; }
  97. public bool IsEMSStop { get; set; }
  98. public string Name { get; set; }
  99. public bool IsInit
  100. {
  101. get { return fsm.State == (int)RtState.Init; }
  102. }
  103. public bool IsIdle
  104. {
  105. get { return fsm.State == (int)RtState.Idle; }
  106. }
  107. public bool IsError
  108. {
  109. get { return fsm.State == (int)RtState.Error; }
  110. }
  111. public bool IsMaintenanceMode
  112. {
  113. get { return fsm.State == (int)RtState.Maintenance; }
  114. }
  115. public bool IsCycle
  116. {
  117. get { return fsm.State == (int)RtState.Cycle; }
  118. }
  119. public bool Initializing
  120. {
  121. get { return fsm.State == (int)RtState.Initializing; }
  122. }
  123. public bool IsRunning
  124. {
  125. get
  126. {
  127. return !IsIdle && !IsInit && !IsError && !IsMaintenanceMode;
  128. }
  129. }
  130. public int RTStatus { get { return fsm.State; } }
  131. private double lastTime = 0;
  132. private double elapsedTime = 0;
  133. public double TransferTime
  134. {
  135. get
  136. {
  137. elapsedTime = 0;
  138. if (!_timerTransfer.IsIdle())
  139. {
  140. elapsedTime = (_timerTransfer.GetElapseTime() / 1000);
  141. }
  142. return lastTime + elapsedTime;
  143. }
  144. }
  145. private static LoadPortEntity _lp1 = new LoadPortEntity(ModuleName.LP1.ToString());
  146. private static LoadPortEntity _lp2 = new LoadPortEntity(ModuleName.LP2.ToString());
  147. private static LoadPortEntity _lp3 = new LoadPortEntity(ModuleName.LP3.ToString());
  148. private static LoadPortEntity _lp4 = new LoadPortEntity(ModuleName.LP4.ToString());
  149. private static LoadPortEntity _lp5 = new LoadPortEntity(ModuleName.LP5.ToString());
  150. private static LoadPortEntity _lp6 = new LoadPortEntity(ModuleName.LP6.ToString());
  151. private static LoadPortEntity _lp7 = new LoadPortEntity(ModuleName.LP7.ToString());
  152. private static LoadPortEntity _lp8 = new LoadPortEntity(ModuleName.LP8.ToString());
  153. private static LoadPortEntity _lp9 = new LoadPortEntity(ModuleName.LP9.ToString());
  154. private static LoadPortEntity _lp10 = new LoadPortEntity(ModuleName.LP10.ToString());
  155. private static FlipperEntity _flp = new FlipperEntity(ModuleName.Flipper);
  156. private LoadPortEntity[] _loadportEntities =
  157. {
  158. _lp1,
  159. _lp2,
  160. _lp3,
  161. _lp4,
  162. _lp5,
  163. _lp6,
  164. _lp7,
  165. _lp8,
  166. _lp9,
  167. _lp10
  168. };
  169. public bool IsBusy
  170. {
  171. get { return !IsInit && !IsError && !IsIdle; }
  172. }
  173. public bool IsOnline { get; set; }
  174. private DeviceTimer _timerTransfer = new DeviceTimer();
  175. private TransferManager _transferManager = new TransferManager();
  176. private StaticTransfer _staticTransfer = new StaticTransfer();
  177. private IMoveManager _mover = null;
  178. private DualArmMoveManager _dualMover = new DualArmMoveManager();
  179. private SingleArmMoveManager _singleMover = new SingleArmMoveManager();
  180. private RobotBaseDevice _robot = null;
  181. public bool ClearEventLogEnable;
  182. public Result GetTaskState(string task)
  183. {
  184. if (_taskState.ContainsKey(task))
  185. return _taskState[task];
  186. return Result.DONE;
  187. }
  188. public string EFemNum
  189. {
  190. get
  191. { if(SC.ContainsItem("System.EFEMNUM"))
  192. return SC.GetStringValue("System.EFEMNUM");
  193. return "001";
  194. }
  195. }
  196. public string DeviceType
  197. {
  198. get
  199. {
  200. if (SC.ContainsItem("System.DeviceType"))
  201. return SC.GetStringValue("System.DeviceType").Remove(0, 6);
  202. return "001";
  203. }
  204. }
  205. Dictionary<string, Result> _taskState = new Dictionary<string, Result>();
  206. #region Module Insatlled
  207. public bool IsLP1Disable { get; set; }
  208. public bool IsLP2Disable { get; set; }
  209. public bool IsAligner1Disable { get; set; }
  210. public bool IsAligner2Disable { get; set; }
  211. public bool IsPMADisable { get; set; }
  212. public bool IsPMBDisable { get; set; }
  213. public bool IsBufferDisable { get; set; }
  214. public bool IsBuffer1Disable { get; set; }
  215. public bool IsBuffer2Disable { get; set; }
  216. public bool IsCoolingBuffer1Disable { get; set; }
  217. public bool IsCoolingBuffer2Disable { get; set; }
  218. public bool IsFlipperDisable { get; set; }
  219. #endregion
  220. #region Flipper
  221. /// <summary>
  222. /// Flipper Entity
  223. /// </summary>
  224. public FlipperEntity FLPEntity => _flp;
  225. #endregion
  226. public RouteManager()
  227. {
  228. Name = "System";
  229. switch(EFemNum)
  230. {
  231. case "001":
  232. {
  233. DeviceModel.SensorPMASystemInterlock.OnSignalChanged += SensorPMASystemInterlock_OnSignalChanged;
  234. DeviceModel.SensorPMBSystemInterlock.OnSignalChanged += SensorPMBSystemInterlock_OnSignalChanged;
  235. DeviceModel.SensorRBNotExtendSIMF1.OnSignalChanged += SensorRBNotExtendSIMF1_OnSignalChanged;
  236. DeviceModel.SensorRBNotExtendSIMF2.OnSignalChanged += SensorRBNotExtendSIMF2_OnSignalChanged;
  237. DeviceModel.SensorSMIF1PODOPEN.OnSignalChanged += SensorSMIF1PODOPEN_OnSignalChanged;
  238. DeviceModel.SensorSMIF2PODOPEN.OnSignalChanged += SensorSMIF2PODOPEN_OnSignalChanged;
  239. DeviceModel.SensorWaterLeakSW.OnSignalChanged += SensorWaterLeakSW_OnSignalChanged;
  240. DeviceModel.SensorGratingSensorIN1.OnSignalChanged += SensorGratingSensorIN1_OnSignalChanged;
  241. }
  242. break;
  243. case "002":
  244. {
  245. DeviceModel.SensorSMIF1PODOPEN.OnSignalChanged += SensorSMIF1PODOPEN_OnSignalChanged;
  246. DeviceModel.SensorSMIF2PODOPEN.OnSignalChanged += SensorSMIF2PODOPEN_OnSignalChanged;
  247. DeviceModel.SensorWaterLeakSW.OnSignalChanged += SensorWaterLeakSW_OnSignalChanged;
  248. DeviceModel.SensorGratingSensorIN1.OnSignalChanged += SensorGratingSensorIN1_OnSignalChanged;
  249. }
  250. break;
  251. case "003":
  252. {
  253. DeviceModel.SensorSMIF1PODOPEN.OnSignalChanged += SensorSMIF1PODOPEN_OnSignalChanged;
  254. DeviceModel.SensorSMIF2PODOPEN.OnSignalChanged += SensorSMIF2PODOPEN_OnSignalChanged;
  255. DeviceModel.SensorWaterLeakSW.OnSignalChanged += SensorWaterLeakSW_OnSignalChanged;
  256. DeviceModel.SensorGratingSensorIN1.OnSignalChanged += SensorGratingSensorIN1_OnSignalChanged;
  257. }
  258. break;
  259. case "004":
  260. {
  261. DeviceModel.SensorSMIF1PODOPEN.OnSignalChanged += SensorSMIF1PODOPEN_OnSignalChanged;
  262. DeviceModel.SensorSMIF2PODOPEN.OnSignalChanged += SensorSMIF2PODOPEN_OnSignalChanged;
  263. DeviceModel.SensorWaterLeakSW.OnSignalChanged += SensorWaterLeakSW_OnSignalChanged;
  264. DeviceModel.SensorGratingSensorIN1.OnSignalChanged += SensorGratingSensorIN1_OnSignalChanged;
  265. }
  266. break;
  267. case "005":
  268. {
  269. DeviceModel.SensorWaterLeakSW.OnSignalChanged += SensorWaterLeakSW_OnSignalChanged;
  270. DeviceModel.SensorCDAPressureSW.OnSignalChanged += SensorCDAPressureSW_OnSignalChanged;
  271. ///DeviceModel.SensorRBNotExtendSIMF1.OnSignalChanged += SensorRBNotExtendSIMF1_OnSignalChanged1;
  272. }
  273. break;
  274. case "006":
  275. {
  276. ;
  277. }
  278. break;
  279. default:
  280. {
  281. DeviceModel.SensorPMASystemInterlock.OnSignalChanged += SensorPMASystemInterlock_OnSignalChanged;
  282. DeviceModel.SensorPMBSystemInterlock.OnSignalChanged += SensorPMBSystemInterlock_OnSignalChanged;
  283. DeviceModel.SensorRBNotExtendSIMF1.OnSignalChanged += SensorRBNotExtendSIMF1_OnSignalChanged;
  284. DeviceModel.SensorRBNotExtendSIMF2.OnSignalChanged += SensorRBNotExtendSIMF2_OnSignalChanged;
  285. DeviceModel.SensorSMIF1PODOPEN.OnSignalChanged += SensorSMIF1PODOPEN_OnSignalChanged;
  286. DeviceModel.SensorSMIF2PODOPEN.OnSignalChanged += SensorSMIF2PODOPEN_OnSignalChanged;
  287. DeviceModel.SensorWaterLeakSW.OnSignalChanged += SensorWaterLeakSW_OnSignalChanged;
  288. DeviceModel.SensorGratingSensorIN1.OnSignalChanged += SensorGratingSensorIN1_OnSignalChanged;
  289. }
  290. break;
  291. }
  292. Singleton<EventManager>.Instance.OnAlarmEvent += Instance_OnAlarmEvent;
  293. InitRouterManager();
  294. }
  295. private void SensorRBNotExtendSIMF1_OnSignalChanged1(Aitex.Core.RT.Device.Unit.IoSensor arg1, bool arg2)
  296. {
  297. if (arg2)
  298. DeviceModel.TrigSafetytoSMIF1.SetTrigger(true, out _);
  299. else
  300. DeviceModel.TrigSafetytoSMIF1.SetTrigger(false, out _);
  301. }
  302. private void SensorCDAPressureSW_OnSignalChanged(Aitex.Core.RT.Device.Unit.IoSensor arg1, bool arg2)
  303. {
  304. if (arg2)
  305. DeviceModel.TrigCDAPressureOkToPM.SetTrigger(true,out _);
  306. else
  307. DeviceModel.TrigCDAPressureOkToPM.SetTrigger(false, out _);
  308. }
  309. private void Instance_OnAlarmEvent(EventItem obj)
  310. {
  311. //if (obj.Level == EventLevel.Alarm && !obj.Source.StartsWith("LP"))
  312. //{
  313. // if (!obj.Description.Contains("Has c Error.")|| obj.Description.Contains("PLM Error"))
  314. // {
  315. // CheckToPostMsg(MSG.ERROR);
  316. // }
  317. // //if (fsm.State == (int)RtState.Cycle||fsm.State==(int)RtState.Transfer || fsm.State == (int)RtState.Picking || fsm.State == (int)RtState.Placing)
  318. // //{
  319. // // _tazmoRobot.Stop();
  320. // //}
  321. //}
  322. if (obj.Level == EventLevel.Alarm)
  323. {
  324. if(!CheckIsLpAlarmInfo(obj))//||!obj.Description.Contains("obj.Source.StartsWith("LP")"))!string.IsNullOrEmpty(obj.Source) &&
  325. CheckToPostMsg(MSG.ERROR);
  326. }
  327. }
  328. public bool CheckIsLpAlarmInfo(EventItem obj)
  329. {
  330. try
  331. {
  332. if (string.IsNullOrEmpty(obj.Source))
  333. {
  334. if (obj.EventEnum.Equals("UnloadFOUPFailed"))
  335. return true;
  336. else if (obj.EventEnum.Equals("LoadFOUPFailed"))
  337. return true;
  338. }
  339. else if (obj.Source.StartsWith("LP"))
  340. return true;
  341. else if (obj.Source.Contains("LoadPort"))
  342. return true;
  343. }
  344. catch(Exception ex)
  345. {
  346. LOG.Write(ex);
  347. return false;
  348. }
  349. return false;
  350. }
  351. private void SensorRBNotExtendSIMF2_OnSignalChanged(Aitex.Core.RT.Device.Unit.IoSensor arg1, bool arg2)
  352. {
  353. if (!arg2)
  354. {
  355. DeviceModel.TrigRBbusytoSIMF2.SetTrigger(true, out _);
  356. LOG.Write("SensorRBNotExtendSIMF2 signal change,set TrigRBbusytoSIMF2 signal on.");
  357. }
  358. else
  359. {
  360. DeviceModel.TrigRBbusytoSIMF2.SetTrigger(false, out _);
  361. LOG.Write("SensorRBNotExtendSIM2 signal change,set TrigRBbusytoSIMF2 signal off.");
  362. }
  363. }
  364. private void SensorRBNotExtendSIMF1_OnSignalChanged(Aitex.Core.RT.Device.Unit.IoSensor arg1, bool arg2)
  365. {
  366. if (!arg2)
  367. {
  368. DeviceModel.TrigRBbusytoSIMF1.SetTrigger(true, out _);
  369. LOG.Write("SensorRBNotExtendSIMF1 signal change,set TrigRBbusytoSIMF1 signal on.");
  370. }
  371. else
  372. {
  373. DeviceModel.TrigRBbusytoSIMF1.SetTrigger(false, out _);
  374. LOG.Write("SensorRBNotExtendSIMF1 signal change,set TrigRBbusytoSIMF1 signal off.");
  375. }
  376. }
  377. private void SensorGratingSensorIN1_OnSignalChanged(Aitex.Core.RT.Device.Unit.IoSensor arg1, bool arg2)
  378. {
  379. if (!arg2)
  380. {
  381. if(fsm.State==(int)RtState.Cycle|| fsm.State == (int)RtState.Transfer
  382. || fsm.State == (int)RtState.Placing||fsm.State == (int)RtState.Picking)
  383. DeviceModel.TrigPauseResumetoRobot.SetTrigger(true, out _);
  384. }
  385. else
  386. {
  387. DeviceModel.TrigPauseResumetoRobot.SetTrigger(false, out _);
  388. }
  389. }
  390. private void SensorWaterLeakSW_OnSignalChanged(Aitex.Core.RT.Device.Unit.IoSensor arg1, bool arg2)
  391. {
  392. if (!arg2)
  393. {
  394. if (EFemNum != "005")
  395. {
  396. if (fsm.State == (int)RtState.Cycle || fsm.State == (int)RtState.Transfer
  397. || fsm.State == (int)RtState.Placing || fsm.State == (int)RtState.Picking)
  398. DeviceModel.TrigPauseResumetoRobot.SetTrigger(true, out _);
  399. }
  400. else
  401. {
  402. DeviceModel.TrigWaterLeakOkToPM.SetTrigger(false, out _);
  403. }
  404. }
  405. else
  406. {
  407. if (EFemNum != "005")
  408. {
  409. DeviceModel.TrigPauseResumetoRobot.SetTrigger(false, out _);
  410. }
  411. else
  412. {
  413. DeviceModel.TrigWaterLeakOkToPM.SetTrigger(true, out _);
  414. }
  415. }
  416. }
  417. private void SensorSMIF2PODOPEN_OnSignalChanged(Aitex.Core.RT.Device.Unit.IoSensor arg1, bool arg2)
  418. {
  419. if (arg2)
  420. {
  421. DeviceModel.TrigSafetytoSMIF2.SetTrigger(true, out _);
  422. LOG.Write("SensorSMIF2PODOPEN signal change,set TrigSafetytoSMIF2 signal on.");
  423. }
  424. else
  425. {
  426. DeviceModel.TrigSafetytoSMIF2.SetTrigger(false, out _);
  427. LOG.Write("SensorSMIF2PODOPEN signal change,set TrigSafetytoSMIF2 signal off.");
  428. }
  429. }
  430. private void SensorSMIF1PODOPEN_OnSignalChanged(Aitex.Core.RT.Device.Unit.IoSensor arg1, bool arg2)
  431. {
  432. if (arg2)
  433. {
  434. DeviceModel.TrigSafetytoSMIF1.SetTrigger(true, out _);
  435. LOG.Write("SensorSMIF1PODOPEN signal change,set TrigSafetytoSMIF1 signal on.");
  436. }
  437. else
  438. {
  439. DeviceModel.TrigSafetytoSMIF1.SetTrigger(false, out _);
  440. LOG.Write("SensorSMIF1PODOPEN signal change,set TrigSafetytoSMIF1 signal off.");
  441. }
  442. }
  443. private void SensorPMBSystemInterlock_OnSignalChanged(Aitex.Core.RT.Device.Unit.IoSensor arg1, bool arg2)
  444. {
  445. if (arg2)
  446. {
  447. DeviceModel.TrigSafetytoPMB.SetTrigger(true, out _);
  448. LOG.Write("SensorPMBSystemInterlock signal change,set TrigSafetytoPMB signal on.");
  449. }
  450. else
  451. {
  452. DeviceModel.TrigSafetytoPMB.SetTrigger(false, out _);
  453. LOG.Write("SensorPMBSystemInterlock signal change,set TrigSafetytoPMA signal off.");
  454. }
  455. }
  456. private void SensorPMASystemInterlock_OnSignalChanged(Aitex.Core.RT.Device.Unit.IoSensor arg1, bool arg2)
  457. {
  458. if (arg2)
  459. {
  460. DeviceModel.TrigSafetytoPMA.SetTrigger(true, out _);
  461. LOG.Write("SensorPMASystemInterlock signal change,set TrigSafetytoPMB signal on.");
  462. }
  463. else
  464. {
  465. DeviceModel.TrigSafetytoPMA.SetTrigger(false, out _);
  466. LOG.Write("SensorPMASystemInterlock signal change,set TrigSafetytoPMB signal off.");
  467. }
  468. }
  469. public void InitRouterManager()
  470. {
  471. BuildTransitionTable();
  472. InitModuleInstallment();
  473. SubscribeDataVariable();
  474. SubscribeOperation();
  475. _robot = DEVICE.GetDevice<RobotBaseDevice>(DeviceName.Robot);
  476. Running = false;
  477. IsAutoMode = false;
  478. }
  479. #region Initialization
  480. private void BuildTransitionTable()
  481. {
  482. fsm = new StateMachine<RouteManager>(Name, (int)RtState.Init, 50);
  483. //Init sequence
  484. Transition(RtState.Init, MSG.Init, null, RtState.Idle);
  485. //Init sequence
  486. Transition(RtState.Init, MSG.HOME, fStartInit, RtState.Initializing);
  487. Transition(RtState.Idle, MSG.HOME, fStartInit, RtState.Initializing);
  488. Transition(RtState.Error, MSG.HOME, fStartInit, RtState.Initializing);
  489. // EnterExitTransition<RtState, FSM_MSG>(RtState.Initializing, fStartInit, FSM_MSG.NONE, null);
  490. Transition(RtState.Initializing, FSM_MSG.TIMER, fInit, RtState.Idle);
  491. Transition(RtState.Initializing, MSG.ERROR, fError, RtState.Error);
  492. Transition(RtState.Initializing, MSG.ABORT, null, RtState.Init);
  493. EnterExitTransition<RtState, FSM_MSG>(RtState.Idle, fIdle, FSM_MSG.NONE, null);
  494. //Reset
  495. AnyStateTransition(MSG.RESET, fStartReset, RtState.Idle);
  496. AnyStateTransition(MSG.ERROR, fError, RtState.Error);
  497. AnyStateTransition((int)FSM_MSG.ALARM, fError, (int)RtState.Error);
  498. //MaintanceMode
  499. Transition(RtState.Maintenance, MSG.SetManualMode, null, RtState.Idle);
  500. AnyStateTransition(MSG.SetMaintenanceMode, fSetMaintenanceMode, RtState.Maintenance);
  501. //Auto/manual sequence
  502. Transition(RtState.Idle, MSG.SetAutoMode, fSetAutoMode, RtState.Idle);
  503. Transition(RtState.Idle, MSG.SetManualMode, fSetManualMode, RtState.Idle);
  504. //Loadport operation
  505. Transition(RtState.Idle, MSG.LOAD, fLoad, RtState.Idle);
  506. Transition(RtState.Idle, MSG.ReadAndLoad, fReadAndLoad, RtState.Idle);
  507. Transition(RtState.Idle, MSG.UNLOAD, fUnload, RtState.Idle);
  508. Transition(RtState.Idle, MSG.ReadID, fReadID, RtState.Idle);
  509. Transition(RtState.Idle, MSG.WriteID, fWriteID, RtState.Idle);
  510. //SetSpeed
  511. Transition(RtState.Idle, MSG.SetSpeed, fStartSetSpeed, RtState.SetSpeed);
  512. Transition(RtState.SetSpeed, FSM_MSG.TIMER, fSetSpeed, RtState.Idle);
  513. //Wafer Map Routine
  514. Transition(RtState.Init, MSG.MapWafer, FsmStartMapWafer, RtState.WaferMapping);
  515. Transition(RtState.Idle, MSG.MapWafer, FsmStartMapWafer, RtState.WaferMapping);
  516. Transition(RtState.WaferMapping, FSM_MSG.TIMER, FsmMonitorWaferMapping, RtState.Idle);
  517. Transition(RtState.WaferMapping, MSG.ChangeCassette, FsmChangeCassette, RtState.Error);
  518. //Transfer sequence
  519. Transition(RtState.Idle, MSG.MoveWafer, fStartTransfer, RtState.Transfer);
  520. Transition(RtState.Transfer, FSM_MSG.TIMER, fTransfer, RtState.Idle);
  521. Transition(RtState.Transfer, MSG.ABORT, fAbortTransfer, RtState.Idle);
  522. EnterExitTransition<RtState, FSM_MSG>(RtState.Transfer, null, FSM_MSG.NONE, fExitTransfer);
  523. //Return sequence
  524. Transition(RtState.Idle, MSG.ReturnWafer, fStartReturn, RtState.Transfer);
  525. Transition(RtState.Transfer, FSM_MSG.TIMER, fTransfer, RtState.Idle);
  526. Transition(RtState.Transfer, MSG.ChangeCassette, FsmChangeCassette, RtState.Error);
  527. //Cycle sequence
  528. Transition(RtState.Idle, MSG.StartCycle, fStartCycle, RtState.Cycle);
  529. Transition(RtState.Cycle, FSM_MSG.TIMER, fCycle, RtState.Idle);
  530. Transition(RtState.Cycle, MSG.Stop, fCycleStop, RtState.Cycle);
  531. EnterExitTransition<RtState, FSM_MSG>(RtState.Cycle, FsmEnterCycle, FSM_MSG.NONE, FsmExitCycle);
  532. Transition(RtState.Cycle, MSG.ABORT, fAbortRunProcess, RtState.Idle);
  533. Transition(RtState.Cycle, MSG.ChangeCassette, FsmChangeCassette, RtState.Error);
  534. Transition(RtState.Cycle, MSG.RobotActionDone, fCycle, RtState.Cycle);
  535. //robot pick
  536. Transition(RtState.Idle, MSG.Pick, FsmStartRobotPick, RtState.Picking);
  537. Transition(RtState.Picking, FSM_MSG.TIMER, FsmMonitorPick, RtState.Idle);
  538. Transition(RtState.Picking, MSG.ABORT, FsmAbortTask, RtState.Idle);
  539. Transition(RtState.Picking, MSG.ChangeCassette, FsmChangeCassette, RtState.Error);
  540. //robot place
  541. Transition(RtState.Idle, MSG.Place, FsmStartRobotPlace, RtState.Placing);
  542. Transition(RtState.Placing, FSM_MSG.TIMER, FsmMonitorPlace, RtState.Idle);
  543. Transition(RtState.Placing, MSG.ABORT, FsmAbortTask, RtState.Idle);
  544. Transition(RtState.Placing, MSG.ChangeCassette, FsmChangeCassette, RtState.Error);
  545. //robot mpnt pick
  546. Transition(RtState.Idle, MSG.MPNTPick, FsmStartRobotMpntPick, RtState.PickingPM);
  547. Transition(RtState.PickingPM, FSM_MSG.TIMER, FsmMonitorMpntPick, RtState.Idle);
  548. Transition(RtState.PickingPM, MSG.ABORT, FsmAbortTask, RtState.Idle);
  549. //robot mpnt place
  550. Transition(RtState.Idle, MSG.MPNTPlace, FsmStartRobotMpntPlace, RtState.PlacingPM);
  551. Transition(RtState.PlacingPM, FSM_MSG.TIMER, FsmMonitorMpntPlace, RtState.Idle);
  552. Transition(RtState.PlacingPM, MSG.ABORT, FsmAbortTask, RtState.Idle);
  553. }
  554. void InitModuleInstallment()
  555. {
  556. IsBufferDisable = SC.ContainsItem("System.BufferDisable") ? SC.GetValue<bool>("System.BufferDisable") : true;
  557. IsBuffer1Disable = SC.ContainsItem("System.Buffer1Disable") ? SC.GetValue<bool>("System.Buffer1Disable") : true;
  558. IsBuffer2Disable = SC.ContainsItem("System.Buffer2Disable") ? SC.GetValue<bool>("System.Buffer2Disable") : true;
  559. IsAligner1Disable = SC.ContainsItem("System.Aligner1Disable") ? SC.GetValue<bool>("System.Aligner1Disable") : true;
  560. IsAligner2Disable = SC.ContainsItem("System.Aligner2Disable") ? SC.GetValue<bool>("System.Aligner2Disable") : true;
  561. IsPMADisable = SC.ContainsItem("System.PMADisable") ? SC.GetValue<bool>("System.PMADisable") : true;
  562. IsPMBDisable = SC.ContainsItem("System.PMBDisable") ? SC.GetValue<bool>("System.PMBDisable") : true;
  563. IsCoolingBuffer1Disable = SC.ContainsItem("System.CoolingBuffer1Disable") ? SC.GetValue<bool>("System.CoolingBuffer1Disable") : true;
  564. IsCoolingBuffer2Disable = SC.ContainsItem("System.CoolingBuffer2Disable") ? SC.GetValue<bool>("System.CoolingBuffer2Disable") : true;
  565. IsLP1Disable = SC.ContainsItem("LoadPort.LP1.Disable") ? SC.GetValue<bool>("LoadPort.LP1.Disable") : true;
  566. IsLP2Disable = SC.ContainsItem("LoadPort.LP2.Disable") ? SC.GetValue<bool>("LoadPort.LP2.Disable") : true;
  567. IsFlipperDisable = SC.ContainsItem("System.FlipperDisable") ? SC.GetValue<bool>("System.FlipperDisable") : true;
  568. }
  569. void SubscribeDataVariable()
  570. {
  571. //Parameter Register
  572. DATA.Subscribe(ModuleName.System.ToString(), ParamName.RTStatus, () => fsm.State);
  573. DATA.Subscribe(ModuleName.System.ToString(), ParamName.SystemIdle, () => IsIdle || IsInit);
  574. DATA.Subscribe(ModuleName.System.ToString(), ParamName.SystemRunning, () => IsRunning);
  575. DATA.Subscribe(ModuleName.System.ToString(), ParamName.SystemAlarm, () => IsError);
  576. DATA.Subscribe(ModuleName.System.ToString(), ParamName.IsProcessPaused, () => _mover != null && _mover.IsPaused);
  577. DATA.Subscribe(ModuleName.System.ToString(), ParamName.FFUOk, () => IsFFUOk);
  578. // DATA.Subscribe(ModuleName.System.ToString(), ParamName.TransferCount, () => TransferCount);
  579. // DATA.Subscribe(ModuleName.System.ToString(), ParamName.TransferTime, () => TransferTime);
  580. // DATA.Subscribe(ModuleName.System.ToString(), ParamName.TranserThroughput, () => TranserThroughput);
  581. // DATA.Subscribe(ModuleName.System.ToString(), ParamName.TotalWaferCount, () => SC.GetValue<int>(SorterCommon.ScPathName.System_TotalWaferCount));
  582. DATA.Subscribe(string.Format("{0}.{1}", ChamberSetString.System, ParamName.AlarmEvent), EV.GetAlarmEvent);
  583. // DATA.Subscribe(ModuleName.System.ToString(), ParamName.CycleCount, () => CycleCount);
  584. DATA.Subscribe(ParamName.System.IsAlarm, () => IsError);
  585. DATA.Subscribe(ParamName.System.IsManualMode, () => !IsAutoMode);
  586. DATA.Subscribe(ParamName.System.IsAutoMode, () => IsAutoMode);
  587. DATA.Subscribe(ParamName.System.IsMaintenanceMode, () => IsMaintenanceMode);
  588. DATA.Subscribe(ParamName.System.IsRunning, () => IsRunning);
  589. DATA.Subscribe(ParamName.System.IsIdle, () => IsIdle);
  590. DATA.Subscribe("System.IsNoRunning", () => !IsRunning);
  591. DATA.Subscribe("System.CoolingBuffer1Disable",()=>SC.GetValue<bool>("System.CoolingBuffer1Disable"));
  592. DATA.Subscribe("System.CoolingBuffer2Disable", () => SC.GetValue<bool>("System.CoolingBuffer2Disable"));
  593. DATA.Subscribe("System.Aligner1Disable", () => SC.GetValue<bool>("System.Aligner1Disable"));
  594. DATA.Subscribe("System.Aligner2Disable", () => SC.GetValue<bool>("System.Aligner2Disable"));
  595. DATA.Subscribe("LP1.WaferThickness", () => SC.GetStringValue("CarrierInfo.LP1ThicknessType"));
  596. DATA.Subscribe("LP2.WaferThickness", () => SC.GetStringValue("CarrierInfo.LP2ThicknessType"));
  597. DATA.Subscribe("Cooling1.WaferThickness", () => SC.GetStringValue("CarrierInfo.CoolingBuffer1ThicknessType"));
  598. DATA.Subscribe("Cooling2.WaferThickness", () => SC.GetStringValue("CarrierInfo.CoolingBuffer2ThicknessType"));
  599. DATA.Subscribe("LL1.WaferThickness", () => SC.GetStringValue("CarrierInfo.LL1ThicknessType"));
  600. DATA.Subscribe("LL2.WaferThickness", () => SC.GetStringValue("CarrierInfo.LL2ThicknessType"));
  601. DATA.Subscribe("Buffer1.WaferThickness", () => SC.GetStringValue("CarrierInfo.Buffer1ThicknessType"));
  602. DATA.Subscribe("Buffer2.WaferThickness", () => SC.GetStringValue("CarrierInfo.Buffer2ThicknessType"));
  603. DATA.Subscribe("Aligner1.WaferThickness", () => SC.GetStringValue("CarrierInfo.Aligner1ThicknessType"));
  604. DATA.Subscribe("Aligner2.WaferThickness", () => SC.GetStringValue("CarrierInfo.Aligner2ThicknessType"));
  605. DATA.Subscribe("Upper.WaferThickness", () => SC.GetStringValue("CarrierInfo.UpperThicknessType"));
  606. DATA.Subscribe("Lower.WaferThickness", () => SC.GetStringValue("CarrierInfo.LowerThicknessType"));
  607. DATA.Subscribe($"System.IsEnableBufferMap", () => SC.GetValue<bool>("System.IsEnableBufferMap"));
  608. DATA.Subscribe("System.IsEnableIdentifyThickness", () => SC.GetValue<bool>("System.IsEnableIdentifyThickness"));
  609. DATA.Subscribe("System.IsEnableMultiWaferSize", () => SC.GetValue<bool>("System.IsEnableMultiWaferSize"));
  610. DATA.Subscribe("System.IsEnableMultiWaferSizeShow", () => SC.GetValue<bool>("System.IsEnableMultiWaferSizeShow"));
  611. DATA.Subscribe("System.IsSlotShowOpposite", () => SC.GetValue<bool>("System.IsSlotShowOpposite"));
  612. DATA.Subscribe("System.ClearEventLogEnable", () => ClearEventLogEnable);
  613. var robot = DEVICE.GetDevice<RobotBaseDevice>(DeviceName.Robot);
  614. robot.ActionDone += Robot_ActionDone;
  615. //foreach (var moduleName in Singleton<DeviceManager>.Instance.LpNames)
  616. //{
  617. // LoadPort lp = DEVICE.GetDevice<LoadPort>(moduleName.ToString());
  618. // lp.ActionDone += Lp_ActionDone;
  619. //}
  620. DATA.Subscribe("LP1.IsEnable", () => !IsLP1Disable);
  621. DATA.Subscribe("LP2.IsEnable", () => !IsLP2Disable);
  622. DATA.Subscribe("Aligner1.IsEnable", () => !IsAligner1Disable);
  623. DATA.Subscribe("Aligner2.IsEnable", () => !IsAligner2Disable);
  624. DATA.Subscribe("Buffer.IsEnable", () => !IsBufferDisable);
  625. DATA.Subscribe("Buffer1.IsEnable", () => !IsBuffer1Disable);
  626. DATA.Subscribe("Buffer2.IsEnable", () => !IsBuffer2Disable);
  627. DATA.Subscribe("CoolingBuffer1.IsEnable", () => !IsCoolingBuffer1Disable);
  628. DATA.Subscribe("CoolingBuffer2.IsEnable", () => !IsCoolingBuffer2Disable);
  629. DATA.Subscribe("PMA.IsEnable", () => !IsPMADisable);
  630. DATA.Subscribe("PMB.IsEnable", () => !IsPMBDisable);
  631. DATA.Subscribe("Flipper.IsEnable", () => !IsFlipperDisable);
  632. DATA.Subscribe("System.IsPMADoorOpen", () => DeviceModel.SensorPMASystemInterlock.Value);
  633. DATA.Subscribe("System.IsPMBDoorOpen", () => DeviceModel.SensorPMBSystemInterlock.Value);
  634. }
  635. private void Lp_ActionDone(bool obj)
  636. {
  637. if (fsm.State == (int)RtState.Cycle)
  638. {
  639. EV.PostInfoLog("System", "Notified LoadPort action done");
  640. CheckToPostMsg(MSG.LoadPortActionDone);
  641. }
  642. }
  643. private void Robot_ActionDone(bool obj)
  644. {
  645. if (fsm.State == (int) RtState.Cycle)
  646. {
  647. EV.PostInfoLog("System", "Notified robot action done");
  648. CheckToPostMsg(MSG.RobotActionDone);
  649. }
  650. if (obj == false && (fsm.State == (int) RtState.Picking || fsm.State == (int) RtState.Placing))
  651. {
  652. CheckToPostMsg(MSG.ERROR);
  653. }
  654. }
  655. void SubscribeOperation()
  656. {
  657. OP.Subscribe(OperationName.CreatWafer, InvokeCreateWafer);
  658. OP.Subscribe(OperationName.DeleteWafer, InvokeDeleteWafer);
  659. OP.Subscribe(OperationName.ResetRouteManager, InvokeResetRouteManager);
  660. //OP.Subscribe(OperationName.SetSpeed, InvokeSetSpeed);
  661. OP.Subscribe(OperationName.HomeUnit, InvokeHomeUnit);
  662. OP.Subscribe(OperationName.LoadFoup, InvokeLoadFoup);
  663. OP.Subscribe(OperationName.UnloadFoup, InvokeUnloadFoup);
  664. OP.Subscribe(OperationName.ReadFoupID, InvokeReadFoupID);
  665. OP.Subscribe(OperationName.WriteFoupID, InvokeWriteFoupID);
  666. OP.Subscribe(OperationName.MoveWafer, InvokeMoveWafer);
  667. OP.Subscribe(OperationName.ReturnWafer, InvokeReturnWafer);
  668. OP.Subscribe(OperationName.MultiMoveWafer, InvokeMultiMoveWafer);
  669. OP.Subscribe(OperationName.Stop, InvokeStop);
  670. OP.Subscribe("Benchmark", InvokeBenchmark);
  671. OP.Subscribe("System.StartCycle", InvokeCycle);
  672. OP.Subscribe(OperationName.SetAutoMode, InvokeSetAutoMode);
  673. OP.Subscribe(OperationName.SetManualMode, InvokeSetManualMode);
  674. OP.Subscribe(OperationName.HomeAll, InvokeHomeAll);
  675. OP.Subscribe(OperationName.AbortHomeAll, InvokeAbortHomeAll);
  676. OP.Subscribe(OperationName.SelectRecipe, InvokeSelectRecipe);
  677. OP.Subscribe(OperationName.StartRecipe, (string cmd, object[] args) =>
  678. {
  679. if (args.Length > 1)
  680. {
  681. return CheckToPostMsg(MSG.StartRecipe, args[0], args[1]);
  682. }
  683. return CheckToPostMsg(MSG.StartRecipe, args[0]);
  684. });
  685. OP.Subscribe(OperationName.PauseRecipe, InvokePauseRecipe);
  686. OP.Subscribe(OperationName.ResumeRecipe, InvokeResumeRecipe);
  687. OP.Subscribe(OperationName.StopRecipe, InvokeStopRecipe);
  688. OP.Subscribe("MapWafer", InvokeMapWafer);
  689. OP.Subscribe(ParamName.System.OPName.Reset, (string cmd, object[] args) =>
  690. {
  691. EV.ClearAlarmEvent();
  692. Singleton<DeviceEntity>.Instance.PostMsg(DeviceEntity.MSG.RESET);
  693. Singleton<EfemEntity>.Instance.PostMsg(EfemEntity.MSG.Reset);
  694. return CheckToPostMsg(MSG.RESET);
  695. });
  696. OP.Subscribe("System.SetWaferSize3", (string cmd, object[] args) =>
  697. {
  698. string module = (string)args[0];
  699. if (module == "Lower")
  700. {
  701. WaferManager.Instance.UpdateWaferSize(ModuleName.Robot, 0, WaferSize.WS3);
  702. return true;
  703. }
  704. if (module == "Upper")
  705. {
  706. WaferManager.Instance.UpdateWaferSize(ModuleName.Robot, 1, WaferSize.WS3);
  707. return true;
  708. }
  709. if (ModuleHelper.IsBuffer(ModuleHelper.Converter(module)))
  710. {
  711. var buffer = DEVICE.GetDevice<BufferStation>(module);
  712. if (buffer != null)
  713. {
  714. for (int i = 0; i < buffer.ValidSlotsNumber; i++)
  715. {
  716. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), i, WaferSize.WS3);
  717. }
  718. }
  719. SC.SetItemValue($"System.{module}WaferSize", 3);
  720. return true;
  721. }
  722. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS3);
  723. //string module = (string) args[0];
  724. //WaferManager.Instance.CheckWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS3);
  725. //if (ModuleHelper.Converter(module) == ModuleName.Robot)
  726. //{
  727. // WaferManager.Instance.CheckWaferSize(ModuleHelper.Converter(module), 1, WaferSize.WS3);
  728. //}
  729. return true;
  730. });
  731. OP.Subscribe("System.SetWaferSize4", (string cmd, object[] args) =>
  732. {
  733. string module = (string)args[0];
  734. if (module == "Lower")
  735. {
  736. WaferManager.Instance.UpdateWaferSize(ModuleName.Robot, 0, WaferSize.WS4);
  737. return true;
  738. }
  739. if (module == "Upper")
  740. {
  741. WaferManager.Instance.UpdateWaferSize(ModuleName.Robot, 1, WaferSize.WS4);
  742. return true;
  743. }
  744. if(ModuleHelper.IsBuffer(ModuleHelper.Converter(module)))
  745. {
  746. var buffer = DEVICE.GetDevice<BufferStation>(module);
  747. if (buffer != null)
  748. {
  749. for (int i=0;i<buffer.ValidSlotsNumber;i++)
  750. {
  751. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), i, WaferSize.WS4);
  752. }
  753. }
  754. SC.SetItemValue($"System.{module}WaferSize", 4);
  755. return true;
  756. }
  757. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS4);
  758. //WaferManager.Instance.CheckWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS4);
  759. //if(ModuleHelper.Converter(module) == ModuleName.Robot)
  760. //{
  761. // WaferManager.Instance.CheckWaferSize(ModuleHelper.Converter(module), 1, WaferSize.WS4);
  762. //}
  763. return true;
  764. });
  765. OP.Subscribe("System.SetWaferSize6", (string cmd, object[] args) =>
  766. {
  767. string module = (string)args[0];
  768. if (module == "Lower")
  769. {
  770. WaferManager.Instance.UpdateWaferSize(ModuleName.Robot, 0, WaferSize.WS6);
  771. return true;
  772. }
  773. if (module == "Upper")
  774. {
  775. WaferManager.Instance.UpdateWaferSize(ModuleName.Robot, 1, WaferSize.WS6);
  776. return true;
  777. }
  778. if (ModuleHelper.IsBuffer(ModuleHelper.Converter(module)))
  779. {
  780. var buffer = DEVICE.GetDevice<BufferStation>(module);
  781. if (buffer != null)
  782. {
  783. for (int i = 0; i < buffer.ValidSlotsNumber; i++)
  784. {
  785. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), i, WaferSize.WS6);
  786. }
  787. }
  788. SC.SetItemValue($"System.{module}WaferSize", 6);
  789. return true;
  790. }
  791. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS6);
  792. //string module = (string)args[0];
  793. //WaferManager.Instance.CheckWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS6);
  794. //if (ModuleHelper.Converter(module) == ModuleName.Robot)
  795. //{
  796. // WaferManager.Instance.CheckWaferSize(ModuleHelper.Converter(module), 1, WaferSize.WS6);
  797. //}
  798. return true;
  799. });
  800. OP.Subscribe("System.SetWaferSize8", (string cmd, object[] args) =>
  801. {
  802. string module = (string)args[0];
  803. if (module == "Lower")
  804. {
  805. WaferManager.Instance.UpdateWaferSize(ModuleName.Robot, 0, WaferSize.WS8);
  806. return true;
  807. }
  808. if (module == "Upper")
  809. {
  810. WaferManager.Instance.UpdateWaferSize(ModuleName.Robot, 1, WaferSize.WS8);
  811. return true;
  812. }
  813. if (ModuleHelper.IsBuffer(ModuleHelper.Converter(module)))
  814. {
  815. var buffer = DEVICE.GetDevice<BufferStation>(module);
  816. if (buffer != null)
  817. {
  818. for (int i = 0; i < buffer.ValidSlotsNumber; i++)
  819. {
  820. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), i, WaferSize.WS8);
  821. }
  822. }
  823. return true;
  824. SC.SetItemValue($"System.{module}WaferSize", 8);
  825. }
  826. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS8);
  827. //string module = (string)args[0];
  828. //WaferManager.Instance.CheckWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS6);
  829. //if (ModuleHelper.Converter(module) == ModuleName.Robot)
  830. //{
  831. // WaferManager.Instance.CheckWaferSize(ModuleHelper.Converter(module), 1, WaferSize.WS6);
  832. //}
  833. return true;
  834. });
  835. OP.Subscribe("System.SetWaferThick", (string cmd, object[] args) =>
  836. {
  837. string module = (string)args[0];
  838. SC.SetItemValueFromString($"CarrierInfo.{module}ThicknessType", "THICK");
  839. return true;
  840. });
  841. OP.Subscribe("System.SetWaferThin", (string cmd, object[] args) =>
  842. {
  843. string module = (string)args[0];
  844. SC.SetItemValueFromString($"CarrierInfo.{module}ThicknessType", "THIN");
  845. return true;
  846. });
  847. OP.Subscribe("System.SetSlot13", (string cmd, object[] args) =>
  848. {
  849. string module = (string)args[0];
  850. //SC.SetItemValue($"CarrierInfo.Carrier0.CarrierSlotsNumber", 13);
  851. SC.SetItemValue($"LoadPort.{module}.SlotsNumber", 13);
  852. return true;
  853. });
  854. OP.Subscribe("System.SetSlot25", (string cmd, object[] args) =>
  855. {
  856. string module = (string)args[0];
  857. // SC.SetItemValue($"CarrierInfo.Carrier0.CarrierSlotsNumber", 25);
  858. SC.SetItemValue($"LoadPort.{module}.SlotsNumber", 25);
  859. return true;
  860. });
  861. OP.Subscribe("System.ClearEventLogEnable", (string cmd, object[] args) =>
  862. {
  863. ClearEventLogEnable = false;
  864. return true;
  865. });
  866. }
  867. private bool InvokeMapWafer(string arg1, object[] arg2)
  868. {
  869. return CheckToPostMsg(MSG.MapWafer, arg2[0].ToString());
  870. }
  871. private bool InvokeStopRecipe(string arg1, object[] arg2)
  872. {
  873. return CheckToPostMsg(MSG.StopRecipe);
  874. }
  875. private bool InvokeResumeRecipe(string arg1, object[] arg2)
  876. {
  877. //ret = PostMsg<RouteManager, RouteManager.MSG>(RouteManager.MSG.ResumeRecipe, out reason);
  878. return true;
  879. }
  880. private bool InvokePauseRecipe(string arg1, object[] arg2)
  881. {
  882. //ret = PostMsg<RouteManager, RouteManager.MSG>(RouteManager.MSG.PauseRecipe, out reason);
  883. return true;
  884. }
  885. private bool InvokeSelectRecipe(string arg1, object[] arg2)
  886. {
  887. //JobManager.Instance.SelectRecipe(arg2[0].ToString());
  888. //ret = true;
  889. return true;
  890. }
  891. private bool InvokeAbortHomeAll(string arg1, object[] arg2)
  892. {
  893. return CheckToPostMsg(MSG.ABORT);
  894. }
  895. private bool InvokeHomeAll(string arg1, object[] arg2)
  896. {
  897. return CheckToPostMsg(MSG.HOME);
  898. }
  899. private bool InvokeSetManualMode(string arg1, object[] arg2)
  900. {
  901. return CheckToPostMsg(MSG.SetManualMode);
  902. }
  903. private bool InvokeSetAutoMode(string arg1, object[] arg2)
  904. {
  905. if (!CheckEnableAuto())
  906. {
  907. return false;
  908. }
  909. return CheckToPostMsg(MSG.SetAutoMode); ;
  910. }
  911. private bool InvokeCycle(string arg1, object[] arg2)
  912. {
  913. string reason;
  914. if (!checkCycle(out reason))
  915. {
  916. EV.PostWarningLog("System", $"Can not start cycle, {reason}");
  917. return false;
  918. }
  919. return CheckToPostMsg(MSG.StartCycle, arg2[0], arg2[1], arg2[2]);
  920. }
  921. private bool InvokeBenchmark(string arg1, object[] arg2)
  922. {
  923. string reason;
  924. if (!checkCycle(out reason))
  925. {
  926. EV.PostWarningLog("System", $"Can not start cycle, {reason}");
  927. return false;
  928. }
  929. return CheckToPostMsg(MSG.StartCycle, arg2[0], arg2[1], arg2[2], "Benchmark");
  930. }
  931. private bool InvokeStop(string arg1, object[] arg2)
  932. {
  933. return CheckToPostMsg(MSG.Stop);
  934. }
  935. private bool InvokeMultiMoveWafer(string arg1, object[] arg2)
  936. {
  937. Running = false;
  938. string reason = "";
  939. bool ret = CheckMultiMove(out reason, arg2);
  940. if (ret)
  941. {
  942. MoveType type = (MoveType)arg2[0];
  943. MoveOption option = (MoveOption)arg2[1];
  944. Hand blade = (Hand)arg2[2];
  945. ModuleName schamber1 = (ModuleName)arg2[3];
  946. int sslot1 = (int)arg2[4];
  947. ModuleName dchamber1 = (ModuleName)arg2[5];
  948. int dslot1 = (int)arg2[6];
  949. ModuleName schamber2 = (ModuleName)arg2[3];
  950. int sslot2 = (int)arg2[4];
  951. ModuleName dchamber2 = (ModuleName)arg2[5];
  952. int dslot2 = (int)arg2[6];
  953. if (type != MoveType.Move)
  954. {
  955. schamber2 = (ModuleName)arg2[7];
  956. sslot2 = (int)arg2[8];
  957. dchamber2 = (ModuleName)arg2[9];
  958. dslot2 = (int)arg2[10];
  959. }
  960. _taskState[arg1] = Result.RUN;
  961. PostMsg(RouteManager.MSG.MoveWafer, type, option, blade,
  962. schamber1, sslot1, dchamber1, dslot1,
  963. schamber2, sslot2, dchamber2, dslot2
  964. );
  965. }
  966. else
  967. {
  968. _taskState[arg1] = Result.FAIL;
  969. return false;
  970. }
  971. return true;
  972. }
  973. private bool InvokeReturnWafer(string arg1, object[] arg2)
  974. {
  975. return CheckToPostMsg(MSG.ReturnWafer);
  976. }
  977. public bool InvokeMoveWafer(string arg1, object[] args)
  978. {
  979. Running = false;
  980. string reason = "";
  981. bool ret = checkMove(out reason, args);
  982. if (ret)
  983. {
  984. MoveType type = (MoveType)args[0];
  985. MoveOption option = (MoveOption)args[1];
  986. Hand blade = (Hand)args[2];
  987. ModuleName schamber1 = (ModuleName)args[3];
  988. int sslot1 = (int)args[4];
  989. ModuleName dchamber1 = (ModuleName)args[5];
  990. int dslot1 = (int)args[6];
  991. ModuleName schamber2 = (ModuleName)args[3];
  992. int sslot2 = (int)args[4];
  993. ModuleName dchamber2 = (ModuleName)args[5];
  994. int dslot2 = (int)args[6];
  995. if (type != MoveType.Move)
  996. {
  997. schamber2 = (ModuleName)args[7];
  998. sslot2 = (int)args[8];
  999. dchamber2 = (ModuleName)args[9];
  1000. dslot2 = (int)args[10];
  1001. }
  1002. _taskState[arg1] = Result.RUN;
  1003. PostMsg(RouteManager.MSG.MoveWafer, type, option, blade,
  1004. schamber1, sslot1, dchamber1, dslot1,
  1005. schamber2, sslot2, dchamber2, dslot2
  1006. );
  1007. }
  1008. else
  1009. {
  1010. _taskState[arg1] = Result.FAIL;
  1011. }
  1012. return true;
  1013. }
  1014. private bool InvokeWriteFoupID(string arg1, object[] arg2)
  1015. {
  1016. //{
  1017. // ret = true;
  1018. // ret = PostMsg<RouteManager, RouteManager.MSG>(RouteManager.MSG.WriteID, out reason, args);
  1019. //}
  1020. return true;
  1021. }
  1022. private bool InvokeReadFoupID(string arg1, object[] arg2)
  1023. {
  1024. return CheckToPostMsg(MSG.ReadID, arg2[0]);
  1025. }
  1026. private bool InvokeUnloadFoup(string arg1, object[] arg2)
  1027. {
  1028. return CheckToPostMsg(MSG.UNLOAD, arg2[0]);
  1029. }
  1030. private bool InvokeLoadFoup(string arg1, object[] arg2)
  1031. {
  1032. return CheckToPostMsg(MSG.LOAD, arg2[0]);
  1033. //var lp = DEVICE.GetDevice<LoadPortBaseDevice>(arg2[0].ToString());
  1034. //return lp.Load(out _);
  1035. }
  1036. private bool InvokeHomeUnit(string arg1, object[] arg2)
  1037. {
  1038. var lp = DEVICE.GetDevice<LoadPortBaseDevice>(arg2[0].ToString());
  1039. return lp.Unload(out _);
  1040. }
  1041. private bool InvokeSetSpeed(string arg1, object[] args)
  1042. {
  1043. int speed = 3;
  1044. string reason;
  1045. if (int.TryParse((string)args[0], out speed))
  1046. {
  1047. if (!(speed <= 3 || speed >= 1))
  1048. {
  1049. EV.PostWarningLog(ModuleName.Robot.ToString(), "Error Parameter,speed should be range in 1, 3");
  1050. }
  1051. PostMsg(MSG.SetSpeed, int.Parse((string)args[0]));
  1052. return true;
  1053. }
  1054. EV.PostWarningLog(ModuleName.Robot.ToString(), $"invalid parameters. {args[0]}");
  1055. return false;
  1056. }
  1057. private bool InvokeResetRouteManager(string arg1, object[] arg2)
  1058. {
  1059. PostMsg(MSG.RESET);
  1060. return true;
  1061. }
  1062. private bool InvokeDeleteWafer(string arg1, object[] args)
  1063. {
  1064. ModuleName chamber = (ModuleName)args[0];
  1065. int slot = (int)args[1];
  1066. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  1067. {
  1068. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  1069. {
  1070. WaferManager.Instance.DeleteWafer(chamber, slot);
  1071. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDelete, chamber.ToString(), slot + 1);
  1072. }
  1073. else
  1074. {
  1075. EV.PostInfoLog("System", string.Format("No wafer at {0} {1}, delete not valid", chamber.ToString(), slot + 1));
  1076. }
  1077. }
  1078. else
  1079. {
  1080. EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  1081. return false;
  1082. }
  1083. return true;
  1084. }
  1085. private bool InvokeCreateWafer(string arg1, object[] args)
  1086. {
  1087. ModuleName chamber = (ModuleName)args[0];
  1088. int slot = (int)args[1];
  1089. WaferStatus state = (WaferStatus)args[2];
  1090. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  1091. {
  1092. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  1093. {
  1094. EV.PostInfoLog("System", string.Format("{0} slot {1} already has wafer.create wafer is not valid", chamber, slot));
  1095. }
  1096. else
  1097. {
  1098. if (ModuleHelper.IsLoadPort(chamber))
  1099. {
  1100. var lp = DEVICE.GetDevice<LoadPortBaseDevice>(chamber.ToString());
  1101. if (WaferManager.Instance.CreateWafer(chamber, slot, state, lp.GetCurrentWaferSize()) != null)
  1102. {
  1103. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferCreate, chamber.ToString(), slot + 1, state.ToString());
  1104. }
  1105. }
  1106. else if (WaferManager.Instance.CreateWafer(chamber, slot, state, WaferSize.WS8) != null)
  1107. {
  1108. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferCreate, chamber.ToString(), slot + 1, state.ToString());
  1109. }
  1110. }
  1111. }
  1112. else
  1113. {
  1114. EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  1115. return false;
  1116. }
  1117. return true;
  1118. }
  1119. #endregion
  1120. protected override bool Init()
  1121. {
  1122. for (var i = 0; i < LoadPortQuantity; i++)
  1123. {
  1124. _loadportEntities[i].Initialize();
  1125. }
  1126. if(!FlipperIsDisable) _flp.Initialize();
  1127. _cycle.Initialize();
  1128. setspeedRoutine = new SetSpeedRoutine("System", "Set Speed");
  1129. setspeedRoutine.Initalize();
  1130. initRoutine = _isInterferencePrevent
  1131. ? (IEfemRoutine)new InitRoutine2Step("System", "Init")
  1132. : (IEfemRoutine)new InitRoutine("System", "Init");
  1133. initRoutine.Initalize();
  1134. _waferMapRoutine = new WaferMappingRoutine();
  1135. _waferMapRoutine.Initalize();
  1136. _staticTransfer.Initialize();
  1137. _dualMover.Initialize();
  1138. _singleMover.Initialize();
  1139. _loadFoupRoutine = new LoadFoupRoutine(ModuleName.LP1.ToString(), "Load");
  1140. _loadFoupRoutine.Initalize();
  1141. _pickRoutine = new PickRoutine("System", "Pick");
  1142. _pickRoutine.Initalize();
  1143. _placeRoutine = new PlaceRoutine("System", "Place");
  1144. _placeRoutine.Initalize();
  1145. _pickExtendRoutine = new PickExtendRoutine("System", "PickExtend");
  1146. _pickExtendRoutine.Initalize();
  1147. _placeExtendRoutine = new PlaceExtendRoutine("System", "PlaceExtend");
  1148. _placeExtendRoutine.Initalize();
  1149. return true;
  1150. }
  1151. protected override void Term()
  1152. {
  1153. //_loadportA.Terminate();
  1154. //_loadportB.Terminate();
  1155. }
  1156. #region Mode change
  1157. private bool fSetAutoMode(object[] objs)
  1158. {
  1159. IsAutoMode = true;
  1160. EV.PostMessage(ChamberSetString.System, EventEnum.RunningModeChanged, "AutoMode");
  1161. return true;
  1162. }
  1163. private bool fSetManualMode(object[] objs)
  1164. {
  1165. IsAutoMode = false;
  1166. EV.PostMessage(ChamberSetString.System, EventEnum.RunningModeChanged, "ManualMode");
  1167. return true;
  1168. }
  1169. private bool fSetMaintenanceMode(object[] param)
  1170. {
  1171. IsAutoMode = false;
  1172. EV.PostMessage(ChamberSetString.System, EventEnum.RunningModeChanged, "Maintenance");
  1173. return true;
  1174. }
  1175. #endregion
  1176. #region Init
  1177. private bool fStartInit(object[] objs)
  1178. {
  1179. Result ret = initRoutine.Start(objs);
  1180. if (ret == Result.DONE)
  1181. {
  1182. return false;
  1183. }
  1184. else if (ret == Result.FAIL)
  1185. {
  1186. return false; //do noting
  1187. }
  1188. return true;
  1189. }
  1190. private bool fInit(object[] objs)
  1191. {
  1192. Result ret = initRoutine.Monitor();
  1193. if (ret == Result.DONE)
  1194. {
  1195. //state = (int)STATE.IDLE;
  1196. return true;
  1197. }
  1198. else if (ret == Result.FAIL)
  1199. {
  1200. //do nothing
  1201. //state = (int)STATE.ERROR;
  1202. PostMsg(MSG.ERROR);
  1203. return false;
  1204. }
  1205. return false; ;
  1206. }
  1207. private bool fError(object[] objs)
  1208. {
  1209. for (int i = 0; i < _taskState.Count; i++)
  1210. {
  1211. _taskState[_taskState.ElementAt(i).Key] = Result.FAIL;
  1212. }
  1213. return true;
  1214. }
  1215. private bool fIdle(object[] objs)
  1216. {
  1217. _taskState.Clear();
  1218. return true;
  1219. }
  1220. #endregion
  1221. #region setspeed
  1222. private bool fStartSetSpeed(object[] objs)
  1223. {
  1224. Result ret = setspeedRoutine.Start(objs);
  1225. setspeedRoutine.Speed = (int)objs[0];
  1226. if (ret == Result.DONE)
  1227. {
  1228. return false;
  1229. }
  1230. else if (ret == Result.FAIL)
  1231. {
  1232. return false; //do noting
  1233. }
  1234. return true;
  1235. }
  1236. private bool fSetSpeed(object[] objs)
  1237. {
  1238. Result ret = setspeedRoutine.Monitor();
  1239. if (ret == Result.DONE)
  1240. {
  1241. //state = (int)STATE.IDLE;
  1242. return true;
  1243. }
  1244. else if (ret == Result.FAIL)
  1245. {
  1246. //do nothing
  1247. //state = (int)STATE.ERROR;
  1248. return true;
  1249. }
  1250. return false;
  1251. }
  1252. #endregion
  1253. #region Transfer
  1254. private bool fStartTransfer(object[] objs)
  1255. {
  1256. Running = true;
  1257. return _staticTransfer.Start(objs);
  1258. }
  1259. private bool fStartReturn(object[] objs)
  1260. {
  1261. return _staticTransfer.Return(objs);
  1262. }
  1263. private bool fTransfer(object[] objs)
  1264. {
  1265. return _staticTransfer.Monitor(objs);
  1266. }
  1267. private bool fExitTransfer(object[] objs)
  1268. {
  1269. _staticTransfer.Clear();
  1270. _taskState.Remove("MoveWafer");
  1271. return true;
  1272. }
  1273. private void ProcessFinished()
  1274. {
  1275. }
  1276. private IMoveManager GetMoveManager(bool bAligner)
  1277. {
  1278. if (!_robot.Blade1Enable)
  1279. {
  1280. EV.PostMessage(ModuleName.System.ToString(), EventEnum.DefaultWarning, "Robot arm1 is disable, can't execute transfer");
  1281. return null;
  1282. }
  1283. if (bAligner)
  1284. {
  1285. _singleMover.Blade = Hand.Blade1;
  1286. return _singleMover;
  1287. }
  1288. if (_robot.Blade1Enable && _robot.Blade2Enable && SC.GetValue<bool>(SorterCommon.ScPathName.Robot_DualBlade1TransferEnable))
  1289. return _dualMover;
  1290. _singleMover.Blade = Hand.Blade1;
  1291. return _singleMover;
  1292. }
  1293. private bool fAbortTransfer(object[] objs)
  1294. {
  1295. return true;
  1296. }
  1297. private bool FsmStartRobotPick(object[] param)
  1298. {
  1299. Result ret = Result.DONE;
  1300. if (param.Length == 3)
  1301. {
  1302. _pickRoutine.Source = ModuleHelper.Converter((string)param[0]);
  1303. _pickRoutine.Slot = (int)param[1];
  1304. _pickRoutine.Blade = (Hand)param[2];
  1305. ret = _pickRoutine.Start();
  1306. }
  1307. else
  1308. {
  1309. return false;
  1310. }
  1311. if (ret == Result.FAIL || ret == Result.DONE)
  1312. return false;
  1313. return ret == Result.RUN;
  1314. }
  1315. private bool FsmStartRobotMpntPick(object[] param)
  1316. {
  1317. Result ret = Result.DONE;
  1318. if (param.Length == 4)
  1319. {
  1320. _pickExtendRoutine.Source = ModuleHelper.Converter((string)param[0]);
  1321. _pickExtendRoutine.Slot = (int)param[1];
  1322. _pickExtendRoutine.Blade = (Hand)param[2];
  1323. _pickExtendRoutine.TaskEnum = (MpntTaskEnum)param[3];
  1324. ret = _pickExtendRoutine.Start();
  1325. }
  1326. else
  1327. {
  1328. return false;
  1329. }
  1330. if (ret == Result.FAIL || ret == Result.DONE)
  1331. return false;
  1332. return ret == Result.RUN;
  1333. }
  1334. private bool FsmStartRobotPlace(object[] param)
  1335. {
  1336. Result ret = Result.DONE;
  1337. if (param.Length == 3)
  1338. {
  1339. _placeRoutine.Station = ModuleHelper.Converter((string)param[0]);
  1340. _placeRoutine.Slot = (int)param[1];
  1341. _placeRoutine.Blade = (Hand)param[2];
  1342. ret = _placeRoutine.Start();
  1343. }
  1344. else
  1345. {
  1346. return false;
  1347. }
  1348. if (ret == Result.FAIL || ret == Result.DONE)
  1349. return false;
  1350. return ret == Result.RUN;
  1351. }
  1352. private bool FsmStartRobotMpntPlace(object[] param)
  1353. {
  1354. Result ret = Result.DONE;
  1355. if (param.Length == 4)
  1356. {
  1357. _placeExtendRoutine.Station = ModuleHelper.Converter((string)param[0]);
  1358. _placeExtendRoutine.Slot = (int)param[1];
  1359. _placeExtendRoutine.Blade = (Hand)param[2];
  1360. _placeExtendRoutine.TaskEnum = (MpntTaskEnum)param[3];
  1361. ret = _placeExtendRoutine.Start();
  1362. }
  1363. else
  1364. {
  1365. return false;
  1366. }
  1367. if (ret == Result.FAIL || ret == Result.DONE)
  1368. return false;
  1369. return ret == Result.RUN;
  1370. }
  1371. private bool FsmChangeCassette(object[] param)
  1372. {
  1373. var lp = param[0].ToString();
  1374. switch (fsm.State)
  1375. {
  1376. case (int)RtState.Cycle when lp == _cycle.OriginStation.ToString() || lp == _cycle.ToStation.ToString():
  1377. _transferManager.Clear();
  1378. IsTransferMode = false;
  1379. _robot.Stop();
  1380. EV.PostWarningLog("System", "Cassette changed during cycle");
  1381. return true;
  1382. case (int)RtState.Transfer when lp == _staticTransfer.TargetStation.ToString() || lp == _staticTransfer.SourceStation.ToString():
  1383. _transferManager.Clear();
  1384. _staticTransfer.Clear();
  1385. IsTransferMode = false;
  1386. _robot.Stop();
  1387. EV.PostWarningLog("System", "Cassette changed during transfer");
  1388. return true;
  1389. case (int)RtState.WaferMapping when lp == _waferMapRoutine.Source.ToString():
  1390. _transferManager.Clear();
  1391. _staticTransfer.Clear();
  1392. IsTransferMode = false;
  1393. _robot.Stop();
  1394. EV.PostWarningLog("System", "Cassette changed during wafer mapping");
  1395. return true;
  1396. case (int)RtState.Picking when lp == _pickRoutine.Source.ToString():
  1397. case (int)RtState.Placing when lp == _placeRoutine.Station.ToString():
  1398. _transferManager.Clear();
  1399. IsTransferMode = false;
  1400. _robot.Stop();
  1401. EV.PostWarningLog("System", "Cassette changed during transfer");
  1402. return true;
  1403. default:
  1404. return false;
  1405. }
  1406. }
  1407. private bool FsmAbortTask(object[] param)
  1408. {
  1409. return true;
  1410. }
  1411. private bool FsmMonitorPick(object[] param)
  1412. {
  1413. Result ret = _pickRoutine.Monitor();
  1414. if (ret == Result.FAIL)
  1415. {
  1416. PostMsg(MSG.ERROR);
  1417. return false;
  1418. }
  1419. return ret == Result.DONE;
  1420. }
  1421. private bool FsmMonitorMpntPick(object[] param)
  1422. {
  1423. Result ret = _pickExtendRoutine.Monitor();
  1424. if (ret == Result.FAIL)
  1425. {
  1426. PostMsg(MSG.ERROR);
  1427. return false;
  1428. }
  1429. return ret == Result.DONE;
  1430. }
  1431. private bool FsmMonitorPlace(object[] param)
  1432. {
  1433. Result ret = _placeRoutine.Monitor();
  1434. if (ret == Result.FAIL)
  1435. {
  1436. PostMsg(MSG.ERROR);
  1437. return false;
  1438. }
  1439. return ret == Result.DONE;
  1440. }
  1441. private bool FsmMonitorMpntPlace(object[] param)
  1442. {
  1443. Result ret = _placeExtendRoutine.Monitor();
  1444. if (ret == Result.FAIL)
  1445. {
  1446. PostMsg(MSG.ERROR);
  1447. return false;
  1448. }
  1449. return ret == Result.DONE;
  1450. }
  1451. #endregion
  1452. #region reset
  1453. private bool fStartReset(object[] objs)
  1454. {
  1455. Singleton<EfemEntity>.Instance.EventError?.Clear();
  1456. if(DEVICE.GetDevice<LoadPortBaseDevice>(ModuleName.LP1.ToString())!=null&& DEVICE.GetDevice<LoadPortBaseDevice>(ModuleName.LP1.ToString()).State==DeviceState.Error)
  1457. DEVICE.GetDevice<LoadPortBaseDevice>(ModuleName.LP1.ToString()).CheckToPostMessage((int)LoadPortMsg.Reset, null); ;
  1458. if (DEVICE.GetDevice<LoadPortBaseDevice>(ModuleName.LP2.ToString()) != null && DEVICE.GetDevice<LoadPortBaseDevice>(ModuleName.LP2.ToString()).State == DeviceState.Error)
  1459. DEVICE.GetDevice<LoadPortBaseDevice>(ModuleName.LP2.ToString()).CheckToPostMessage((int)LoadPortMsg.Reset, null); ;
  1460. if (fsm.State == (int)RtState.Error)
  1461. return true;
  1462. return false;
  1463. }
  1464. #endregion
  1465. #region cycle
  1466. private bool bCycle = false;
  1467. private bool bReturn = false;
  1468. private ModuleName _cycleSource;
  1469. private ModuleName _cycleTarget;
  1470. private bool bMappingSource = false;
  1471. private bool _bUnload = false;
  1472. private MoveOption _moveOption;
  1473. private bool fStartCycle(object[] objs)
  1474. {
  1475. if (objs.Length < 2)
  1476. {
  1477. EV.PostWarningLog("System", "Cycle parameter is not valid, should be 2 LP modules");
  1478. return false;
  1479. }
  1480. if (!Enum.TryParse((string)objs[0], out ModuleName from) || !Enum.TryParse((string)objs[1], out ModuleName to))
  1481. {
  1482. EV.PostWarningLog(ChamberSetString.System,
  1483. ("Cycle parameter error, please check source and destination."));
  1484. return false;
  1485. }
  1486. Result ret = Result.FAIL;
  1487. if (objs.Length >= 3)
  1488. {
  1489. string[] _moveOption = (string[])objs[2];
  1490. ret = _cycle.Start(from, to, (string[])objs[2]);
  1491. }
  1492. if (ret == Result.FAIL)
  1493. {
  1494. EV.PostWarningLog(ChamberSetString.System,
  1495. ("There is wafer on the passing route"));
  1496. return false;
  1497. }
  1498. return ret == Result.RUN;
  1499. }
  1500. private bool fCycle(object[] objs)
  1501. {
  1502. Result ret = _cycle.Monitor();
  1503. if (ret == Result.DONE)
  1504. return true;
  1505. if (ret == Result.FAIL)
  1506. {
  1507. PostMsg(MSG.ERROR);
  1508. return false;
  1509. }
  1510. return false; //continue
  1511. }
  1512. private bool fAbortRunProcess(object[] objs)
  1513. {
  1514. if (fsm.State == (int)RtState.Cycle)
  1515. {
  1516. bool _swapHand = false;
  1517. if (SC.ContainsItem("Process.CycleSwapHand"))
  1518. {
  1519. _swapHand = SC.GetValue<bool>("Process.CycleSwapHand");
  1520. }
  1521. if (_swapHand &&
  1522. ((_moveOption & MoveOption.LoadLock1) == MoveOption.LoadLock1 ||
  1523. (_moveOption & MoveOption.LoadLock2) == MoveOption.LoadLock2 ||
  1524. (_moveOption & MoveOption.LoadLock3) == MoveOption.LoadLock3 ||
  1525. (_moveOption & MoveOption.LoadLock4) == MoveOption.LoadLock4 ||
  1526. (_moveOption & MoveOption.LoadLock5) == MoveOption.LoadLock5 ||
  1527. (_moveOption & MoveOption.LoadLock6) == MoveOption.LoadLock6 ||
  1528. (_moveOption & MoveOption.LoadLock7) == MoveOption.LoadLock7 ||
  1529. (_moveOption & MoveOption.LoadLock8) == MoveOption.LoadLock8 ||
  1530. (_moveOption & MoveOption.Buffer) == MoveOption.Buffer))
  1531. {
  1532. SC.SetItemValue(ScPathName.Robot_Blade1Enable, true);
  1533. SC.SetItemValue(ScPathName.Robot_Blade2Enable, true);
  1534. }
  1535. _moveOption = MoveOption.None;
  1536. }
  1537. _transferManager.Clear();
  1538. IsTransferMode = false;
  1539. return true;
  1540. }
  1541. private bool fCycleStop(object[] objs)
  1542. {
  1543. _cycle.Stop();
  1544. bool _swapHand = false;
  1545. if (SC.ContainsItem("Process.CycleSwapHand"))
  1546. {
  1547. _swapHand = SC.GetValue<bool>("Process.CycleSwapHand");
  1548. }
  1549. if (_swapHand &&
  1550. ((_moveOption & MoveOption.LoadLock1) == MoveOption.LoadLock1 ||
  1551. (_moveOption & MoveOption.LoadLock2) == MoveOption.LoadLock2 ||
  1552. (_moveOption & MoveOption.LoadLock3) == MoveOption.LoadLock3 ||
  1553. (_moveOption & MoveOption.LoadLock4) == MoveOption.LoadLock4 ||
  1554. (_moveOption & MoveOption.LoadLock5) == MoveOption.LoadLock5 ||
  1555. (_moveOption & MoveOption.LoadLock6) == MoveOption.LoadLock6 ||
  1556. (_moveOption & MoveOption.LoadLock7) == MoveOption.LoadLock7 ||
  1557. (_moveOption & MoveOption.LoadLock8) == MoveOption.LoadLock8 ||
  1558. (_moveOption & MoveOption.Buffer) == MoveOption.Buffer))
  1559. {
  1560. SC.SetItemValue(ScPathName.Robot_Blade1Enable, true);
  1561. SC.SetItemValue(ScPathName.Robot_Blade2Enable, true);
  1562. }
  1563. _moveOption = MoveOption.None;
  1564. return true;
  1565. }
  1566. private bool FsmExitCycle(object[] param)
  1567. {
  1568. _cycle.Stop();
  1569. EV.PostInfoLog("System", "Stop Cycle");
  1570. bool _swapHand = false;
  1571. if (SC.ContainsItem("Process.CycleSwapHand"))
  1572. {
  1573. _swapHand = SC.GetValue<bool>("Process.CycleSwapHand");
  1574. }
  1575. if (_swapHand &&
  1576. ((_moveOption & MoveOption.LoadLock1) == MoveOption.LoadLock1 ||
  1577. (_moveOption & MoveOption.LoadLock2) == MoveOption.LoadLock2 ||
  1578. (_moveOption & MoveOption.LoadLock3) == MoveOption.LoadLock3 ||
  1579. (_moveOption & MoveOption.LoadLock4) == MoveOption.LoadLock4 ||
  1580. (_moveOption & MoveOption.LoadLock5) == MoveOption.LoadLock5 ||
  1581. (_moveOption & MoveOption.LoadLock6) == MoveOption.LoadLock6 ||
  1582. (_moveOption & MoveOption.LoadLock7) == MoveOption.LoadLock7 ||
  1583. (_moveOption & MoveOption.LoadLock8) == MoveOption.LoadLock8 ||
  1584. (_moveOption & MoveOption.Buffer) == MoveOption.Buffer))
  1585. {
  1586. SC.SetItemValue(ScPathName.Robot_Blade1Enable, true);
  1587. SC.SetItemValue(ScPathName.Robot_Blade2Enable, true);
  1588. }
  1589. _moveOption = MoveOption.None;
  1590. return true;
  1591. }
  1592. private bool FsmEnterCycle(object[] param)
  1593. {
  1594. EV.PostInfoLog("System", "Start Cycle");
  1595. return true;
  1596. }
  1597. #endregion
  1598. #region Loadport
  1599. private bool fHome(object[] objs)
  1600. {
  1601. ModuleName chamber = (ModuleName)(objs[0]);
  1602. Post(chamber, LoadPortEntity.MSG.HOME);
  1603. return true;
  1604. }
  1605. private bool fLoad(object[] objs)
  1606. {
  1607. ModuleName chamber = (ModuleName)(objs[0]);
  1608. Post(chamber, LoadPortEntity.MSG.Load);
  1609. return true;
  1610. }
  1611. private bool fReadAndLoad(object[] objs)
  1612. {
  1613. ModuleName chamber = (ModuleName)(objs[0]);
  1614. Post(chamber, LoadPortEntity.MSG.ReadAndLoad);
  1615. return true;
  1616. }
  1617. private bool fUnload(object[] objs)
  1618. {
  1619. ModuleName chamber = (ModuleName)(objs[0]);
  1620. Post(chamber, LoadPortEntity.MSG.Unload);
  1621. return true;
  1622. }
  1623. private bool fReadID(object[] objs)
  1624. {
  1625. ModuleName chamber = (ModuleName)(objs[0]);
  1626. Post(chamber, LoadPortEntity.MSG.ReadRFID);
  1627. return true;
  1628. }
  1629. private bool fWriteID(object[] objs)
  1630. {
  1631. ModuleName chamber = (ModuleName)(objs[0]);
  1632. Post(chamber, LoadPortEntity.MSG.WriteRFID);
  1633. return true;
  1634. }
  1635. private bool Post(ModuleName chamber, LoadPortEntity.MSG msg, params object[] objs)
  1636. {
  1637. string pattern = "[1-9]\\d*";
  1638. Regex rgx = new Regex(pattern);
  1639. var match = int.Parse(rgx.Match(chamber.ToString()).ToString());
  1640. if (match <= LoadPortQuantity)
  1641. _loadportEntities[match - 1].PostMsg(msg, objs);
  1642. return true;
  1643. }
  1644. #endregion
  1645. #region validation
  1646. /// <summary>
  1647. ///
  1648. /// </summary>
  1649. /// <param name="msg"></param>
  1650. /// <param name="reason"></param>
  1651. /// <param name="args"></param>
  1652. /// <returns></returns>
  1653. public bool CheckMsg(int msg, out string reason, bool eventOutReason, params object[] args)
  1654. {
  1655. Running = true;
  1656. if (!fsm.FindTransition(fsm.State, msg))
  1657. {
  1658. reason = String.Format("{0} is in {1} state,can not do {2}", Name, (RtState)fsm.State, (MSG)msg);
  1659. if (eventOutReason)
  1660. {
  1661. EV.PostMessage("System", EventEnum.DefaultWarning, reason);
  1662. }
  1663. Running = false;
  1664. return false;
  1665. }
  1666. if (msg == (int)MSG.StartRecipe || msg == (int)MSG.StartCycle)
  1667. {
  1668. if (!IsAutoMode)
  1669. {
  1670. reason = String.Format("can not do {0}, isn't auto mode.", msg.ToString());
  1671. if (eventOutReason)
  1672. {
  1673. EV.PostMessage("System", EventEnum.DefaultWarning, reason);
  1674. }
  1675. Running = false;
  1676. return false;
  1677. }
  1678. }
  1679. reason = "";
  1680. return true;
  1681. }
  1682. public bool CheckToPostMsg(MSG msg)
  1683. {
  1684. if (!fsm.FindTransition(fsm.State, (int)msg))
  1685. {
  1686. EV.PostMessage("System", EventEnum.DefaultWarning,
  1687. string.Format("{0} is in {1} state,can not do {2}", Name, (RtState)fsm.State, (MSG)msg));
  1688. return false;
  1689. }
  1690. PostMsg(msg);
  1691. return true;
  1692. }
  1693. public bool CheckToPostMsg(MSG msg, object param1)
  1694. {
  1695. if (!fsm.FindTransition(fsm.State, (int)msg))
  1696. {
  1697. EV.PostMessage("System", EventEnum.DefaultWarning,
  1698. string.Format("{0} is in {1} state,can not do {2}", Name, (RtState)fsm.State, (MSG)msg));
  1699. return false;
  1700. }
  1701. PostMsg(msg, param1);
  1702. return true;
  1703. }
  1704. public bool CheckToPostMsg(MSG msg, object param1, object param2)
  1705. {
  1706. if (!fsm.FindTransition(fsm.State, (int)msg))
  1707. {
  1708. EV.PostMessage("System", EventEnum.DefaultWarning,
  1709. string.Format("{0} is in {1} state,can not do {2}", Name, (RtState)fsm.State, (MSG)msg));
  1710. return false;
  1711. }
  1712. PostMsg(msg, param1, param2);
  1713. return true;
  1714. }
  1715. public bool CheckToPostMsg(MSG msg, object param1, object param2, object param3)
  1716. {
  1717. if (!fsm.FindTransition(fsm.State, (int)msg))
  1718. {
  1719. EV.PostMessage("System", EventEnum.DefaultWarning,
  1720. string.Format("{0} is in {1} state,can not do {2}", Name, (RtState)fsm.State, (MSG)msg));
  1721. return false;
  1722. }
  1723. PostMsg(msg, param1, param2, param3);
  1724. return true;
  1725. }
  1726. public bool CheckToPostMsg(MSG msg, object param1, object param2, object param3, object param4)
  1727. {
  1728. if (!fsm.FindTransition(fsm.State, (int)msg))
  1729. {
  1730. EV.PostMessage("System", EventEnum.DefaultWarning,
  1731. string.Format("{0} is in {1} state,can not do {2}", Name, (RtState)fsm.State, (MSG)msg));
  1732. return false;
  1733. }
  1734. PostMsg(msg, param1, param2, param3, param4);
  1735. return true;
  1736. }
  1737. private bool check(ModuleName source, int slot, ModuleName dest, int dslot, Hand blade, MoveOption option, out string reason)
  1738. {
  1739. reason = string.Empty;
  1740. if (!checkFoup(source, out reason))
  1741. {
  1742. return false;
  1743. }
  1744. if (!checkFoup(dest, out reason))
  1745. {
  1746. return false;
  1747. }
  1748. if (!WaferManager.Instance.IsWaferSlotLocationValid(source, slot))
  1749. {
  1750. reason = string.Format("Invalid source parameter, {0}:{1:D2}", source.ToString(), slot);
  1751. return false;
  1752. }
  1753. if (!WaferManager.Instance.IsWaferSlotLocationValid(dest, dslot))
  1754. {
  1755. reason = string.Format("Invalid destination parameter, {0}:{1:D2}", dest.ToString(), dslot);
  1756. return false;
  1757. }
  1758. if (!WaferManager.Instance.CheckWafer(source, slot, WaferStatus.Normal))
  1759. {
  1760. if (ModuleHelper.IsLoadLock(source) && Singleton<EfemEntity>.Instance.IsOnlineMode)
  1761. {
  1762. //online mode, CreateWafer in LoadLock
  1763. WaferManager.Instance.CreateWafer(source, slot, WaferStatus.Normal);
  1764. }
  1765. else
  1766. {
  1767. reason = string.Format("Source no normal wafer, {0}:{1:D2}", source.ToString(), slot);
  1768. return false;
  1769. }
  1770. }
  1771. if (!WaferManager.Instance.CheckWafer(dest, dslot, WaferStatus.Empty))
  1772. {
  1773. reason = string.Format("destination has wafer, {0}:{1:D2}", dest.ToString(), dslot);
  1774. return false;
  1775. }
  1776. if (source != ModuleName.Robot && dest != ModuleName.Robot)
  1777. {
  1778. if (!WaferManager.Instance.CheckWafer(ModuleName.Robot, (int)blade, WaferStatus.Empty))
  1779. {
  1780. reason = string.Format("robot has wafer on arm");
  1781. return false;
  1782. }
  1783. }
  1784. bool bAligner = ((option & MoveOption.Align) == MoveOption.Align) ||
  1785. ((option & MoveOption.ReadID) == MoveOption.ReadID) ||
  1786. ((option & MoveOption.ReadID2) == MoveOption.ReadID2);
  1787. if (bAligner)
  1788. {
  1789. if (source != ModuleName.Aligner && dest != ModuleName.Aligner)
  1790. {
  1791. if (!WaferManager.Instance.CheckWafer(ModuleName.Aligner, 0, WaferStatus.Empty))
  1792. {
  1793. reason = string.Format("aligner has wafer on");
  1794. return false;
  1795. }
  1796. }
  1797. }
  1798. return true;
  1799. }
  1800. private bool check(ModuleName source, int slot, ModuleName dest, int dslot, out string reason)
  1801. {
  1802. reason = string.Empty;
  1803. if (!checkFoup(source, out reason))
  1804. {
  1805. return false;
  1806. }
  1807. if (!checkFoup(dest, out reason))
  1808. {
  1809. return false;
  1810. }
  1811. if (!WaferManager.Instance.IsWaferSlotLocationValid(source, slot))
  1812. {
  1813. reason = string.Format("非法的参数。{0}:{1:D2}", source.ToString(), slot);
  1814. return false;
  1815. }
  1816. if (!WaferManager.Instance.IsWaferSlotLocationValid(dest, dslot))
  1817. {
  1818. reason = string.Format("非法的参数。{0}:{1:D2}", dest.ToString(), dslot);
  1819. return false;
  1820. }
  1821. if (!WaferManager.Instance.CheckWafer(source, slot, WaferStatus.Normal))
  1822. {
  1823. reason = string.Format("源位置没有wafer。{0}:{1:D2}", source.ToString(), slot);
  1824. return false;
  1825. }
  1826. if (!WaferManager.Instance.CheckWafer(dest, dslot, WaferStatus.Empty))
  1827. {
  1828. reason = string.Format("目标位置有wafer。{0}:{1:D2}", dest.ToString(), dslot);
  1829. return false;
  1830. }
  1831. return true;
  1832. }
  1833. private bool checkCycle(out string reason, params object[] args)
  1834. {
  1835. reason = string.Empty;
  1836. //bool isAutoMode = (bool)DATA.Poll(ModuleName.System.ToString(), ParamName.IsAutoMode);
  1837. //if (!isAutoMode)
  1838. //{
  1839. // reason = String.Format("can not cycle, isn't auto mode.");
  1840. // return false;
  1841. //}
  1842. if (!WaferManager.Instance.CheckWafer(ModuleName.Robot, 0, WaferStatus.Empty))
  1843. {
  1844. reason = string.Format("Upper arm has wafer");
  1845. return false;
  1846. }
  1847. if (!WaferManager.Instance.CheckWafer(ModuleName.Robot, 1, WaferStatus.Empty))
  1848. {
  1849. reason = string.Format("Lower arm has wafer");
  1850. return false;
  1851. }
  1852. if (DeviceModel.SensorRBupperArmhavewafer != null && !DeviceModel.SensorRBupperArmhavewafer.Value)
  1853. {
  1854. reason = string.Format("Upper arm has wafer");
  1855. return false;
  1856. }
  1857. if (DeviceModel.SensorRBlowerArmhavewafer != null && !DeviceModel.SensorRBlowerArmhavewafer.Value)
  1858. {
  1859. reason = string.Format("Lower arm has wafer");
  1860. return false;
  1861. }
  1862. return true;
  1863. }
  1864. private bool CheckEnableAuto()
  1865. {
  1866. string reason = string.Empty;
  1867. DeviceState state = (DeviceState)DATA.Poll(ModuleName.Robot.ToString(), ParamName.RobotState);
  1868. if (state != DeviceState.Idle)
  1869. {
  1870. EV.PostMessage("System", EventEnum.DefaultWarning, "can not change auto mode, Robot isn't ready.");
  1871. return false;
  1872. }
  1873. if (!Singleton<DeviceManager>.Instance.IsAnyLPIdle())
  1874. {
  1875. EV.PostMessage("System", EventEnum.DefaultWarning, "can not change auto mode, no loadport is ready.");
  1876. return false;
  1877. }
  1878. if (!WaferManager.Instance.CheckWafer(ModuleName.Robot, 0, WaferStatus.Empty))
  1879. {
  1880. EV.PostMessage("System", EventEnum.DefaultWarning, "Upper arm has wafer");
  1881. return false;
  1882. }
  1883. if (!WaferManager.Instance.CheckWafer(ModuleName.Robot, 1, WaferStatus.Empty))
  1884. {
  1885. EV.PostMessage("System", EventEnum.DefaultWarning, "Lower arm has wafer");
  1886. return false;
  1887. }
  1888. if (!SC.GetValue<bool>(SorterCommon.ScPathName.System_IsSimulatorMode))
  1889. {
  1890. if (!DeviceModel.SensorRBupperArmhavewafer.Value)
  1891. {
  1892. EV.PostMessage("System", EventEnum.DefaultWarning, "Upper arm has wafer");
  1893. return false;
  1894. }
  1895. if (!DeviceModel.SensorRBlowerArmhavewafer.Value)
  1896. {
  1897. EV.PostMessage("System", EventEnum.DefaultWarning, "Lower arm has wafer");
  1898. return false;
  1899. }
  1900. }
  1901. return true;
  1902. }
  1903. private bool checkMove(out string reason, params object[] args)
  1904. {
  1905. MoveType type = (MoveType)args[0];
  1906. MoveOption option = (MoveOption)args[1];
  1907. Hand blade = (Hand)args[2];
  1908. ModuleName schamber1 = (ModuleName)args[3];
  1909. int sslot1 = (int)args[4];
  1910. ModuleName dchamber1 = (ModuleName)args[5];
  1911. int dslot1 = (int)args[6];
  1912. ModuleName schamber2 = (ModuleName)args[3];
  1913. int sslot2 = (int)args[4];
  1914. ModuleName dchamber2 = (ModuleName)args[5];
  1915. int dslot2 = (int)args[6];
  1916. if (type != MoveType.Move)
  1917. {
  1918. schamber2 = (ModuleName)args[7];
  1919. sslot2 = (int)args[8];
  1920. dchamber2 = (ModuleName)args[9];
  1921. dslot2 = (int)args[10];
  1922. }
  1923. if (!check(type, blade, out reason))
  1924. {
  1925. EV.PostWarningLog("System", "Can not move wafer, " + reason);
  1926. return false;
  1927. }
  1928. if (!check(schamber1, sslot1, dchamber1, dslot1, blade, option, out reason))
  1929. {
  1930. EV.PostWarningLog("System", "Can not move wafer, " + reason);
  1931. return false;
  1932. }
  1933. if (type != MoveType.Move)
  1934. {
  1935. if (!check(schamber2, sslot2, dchamber2, dslot2, out reason))
  1936. {
  1937. EV.PostWarningLog("System", "Can not move wafer, " + reason);
  1938. return false;
  1939. }
  1940. }
  1941. return true;
  1942. }
  1943. private bool CheckMultiMove(out string reason, params object[] args)
  1944. {
  1945. MoveType type = (MoveType)args[0];
  1946. MoveOption option = (MoveOption)args[1];
  1947. Hand blade = (Hand)args[2];
  1948. ModuleName schamber1 = (ModuleName)args[3];
  1949. int sslot1 = (int)args[4];
  1950. ModuleName dchamber1 = (ModuleName)args[5];
  1951. int dslot1 = (int)args[6];
  1952. ModuleName schamber2 = (ModuleName)args[3];
  1953. int sslot2 = (int)args[4];
  1954. ModuleName dchamber2 = (ModuleName)args[5];
  1955. int dslot2 = (int)args[6];
  1956. if (type != MoveType.Move)
  1957. {
  1958. schamber2 = (ModuleName)args[7];
  1959. sslot2 = (int)args[8];
  1960. dchamber2 = (ModuleName)args[9];
  1961. dslot2 = (int)args[10];
  1962. }
  1963. if (!check(type, blade, out reason))
  1964. {
  1965. EV.PostWarningLog("System", "Can not move wafer, " + reason);
  1966. return false;
  1967. }
  1968. //检查双臂, *若该机器人类型为下手臂1上手臂2
  1969. if (!check(schamber1, sslot1, dchamber1, dslot1, Hand.Blade1, option, out reason))
  1970. {
  1971. EV.PostWarningLog("System", "Can not move wafer, " + reason);
  1972. return false;
  1973. }
  1974. if (!check(schamber1, sslot1 + 1, dchamber1, dslot1 + 1, Hand.Blade2, option, out reason))
  1975. {
  1976. EV.PostWarningLog("System", "Can not move wafer, " + reason);
  1977. return false;
  1978. }
  1979. if (type != MoveType.Move)
  1980. {
  1981. if (!check(schamber2, sslot2, dchamber2, dslot2, out reason))
  1982. {
  1983. EV.PostWarningLog("System", "Can not move wafer, " + reason);
  1984. return false;
  1985. }
  1986. }
  1987. return true;
  1988. }
  1989. private bool check(MoveType type, Hand blade, out string reason)
  1990. {
  1991. reason = string.Empty;
  1992. if (type != MoveType.Move && blade == Hand.Both)
  1993. {
  1994. reason = string.Format("非法的参数。单片传盘时,不能指定Both blade");
  1995. return false;
  1996. }
  1997. return true;
  1998. }
  1999. private bool checkFoup(ModuleName chamber, out string reason)
  2000. {
  2001. reason = string.Empty;
  2002. if (ModuleHelper.IsLoadPort(chamber))
  2003. {
  2004. LoadPortBaseDevice loadport = DEVICE.GetDevice<LoadPortBaseDevice>(chamber.ToString());
  2005. if (!loadport.IsEnableTransferWafer(out reason))
  2006. {
  2007. reason = string.Format("{0} isn't Ready, {1}", chamber.ToString(), reason);
  2008. return false;
  2009. }
  2010. return true;
  2011. }
  2012. //reason = string.Format("Not Foup, parameter {0} is not valid.", chamber.ToString());
  2013. return true;
  2014. }
  2015. public bool Check(int msg, out string reason, params object[] args)
  2016. {
  2017. if (!fsm.FindTransition(fsm.State, msg))
  2018. {
  2019. reason = String.Format("{0} is in {1} state,can not do {2}", Name, (RtState)fsm.State, (MSG)msg);
  2020. return false;
  2021. }
  2022. if (msg == (int)MSG.StartRecipe || msg == (int)MSG.StartCycle)
  2023. {
  2024. if (!IsAutoMode)
  2025. {
  2026. reason = String.Format("can not do {0}, isn't auto mode.", msg.ToString());
  2027. return false;
  2028. }
  2029. }
  2030. reason = "";
  2031. return true;
  2032. }
  2033. #endregion
  2034. #region Map Wafer
  2035. private bool FsmStartMapWafer(object[] param)
  2036. {
  2037. Running = false;
  2038. Result ret = _waferMapRoutine.Start(param);
  2039. if (ret == Result.DONE || (ret == Result.FAIL))
  2040. {
  2041. return false; //do noting
  2042. }
  2043. return true;
  2044. }
  2045. private bool FsmMonitorWaferMapping(object[] param)
  2046. {
  2047. Result ret = _waferMapRoutine.Monitor();
  2048. if (ret == Result.DONE)
  2049. {
  2050. return true;
  2051. }
  2052. else if (ret == Result.FAIL)
  2053. {
  2054. return true;
  2055. }
  2056. return false;
  2057. }
  2058. public void MapBuffer()
  2059. {
  2060. var sensors = new List<bool>
  2061. {
  2062. false,false,false,false,false,
  2063. //DeviceModel.SensorCoolingStageSLOT2WaferON.Value,
  2064. //DeviceModel.SensorCoolingStageSLOT3WaferON.Value,
  2065. //DeviceModel.SensorCoolingStageSLOT4WaferON.Value,
  2066. //DeviceModel.SensorCoolingStageSLOT5WaferON.Value,
  2067. //DeviceModel.SensorCoolingStageSLOT6WaferON.Value
  2068. };
  2069. var index = 0;
  2070. foreach (var sensor in sensors)
  2071. {
  2072. if (!sensor && WaferManager.Instance.CheckNoWafer(ModuleName.Buffer, index))
  2073. {
  2074. WaferManager.Instance.CreateWafer(ModuleName.Buffer, index, WaferStatus.Normal);
  2075. }
  2076. else if (sensor && WaferManager.Instance.CheckHasWafer(ModuleName.Buffer, index))
  2077. {
  2078. WaferManager.Instance.DeleteWafer(ModuleName.Buffer, index);
  2079. }
  2080. index++;
  2081. }
  2082. var robotSensors = new List<bool>
  2083. {
  2084. DeviceModel.SensorRBlowerArmhavewafer.Value,
  2085. DeviceModel.SensorRBupperArmhavewafer.Value
  2086. };
  2087. index = 0;
  2088. foreach (var sensor in robotSensors)
  2089. {
  2090. if (!sensor && WaferManager.Instance.CheckNoWafer(ModuleName.Robot, index))
  2091. {
  2092. WaferManager.Instance.CreateWafer(ModuleName.Robot, index, WaferStatus.Normal);
  2093. }
  2094. else if (sensor && WaferManager.Instance.CheckHasWafer(ModuleName.Robot, index))
  2095. {
  2096. WaferManager.Instance.DeleteWafer(ModuleName.Robot, index);
  2097. }
  2098. index++;
  2099. }
  2100. }
  2101. public int Invoke(string function, params object[] args)
  2102. {
  2103. switch (function)
  2104. {
  2105. case "Place":
  2106. CheckToPostMsg(MSG.Place, args[0], args[1], args[2]);
  2107. return (int)MSG.Place;
  2108. case "Pick":
  2109. CheckToPostMsg(MSG.Pick, args[0], args[1], args[2]);
  2110. return (int)MSG.Pick;
  2111. case "MPNTPick":
  2112. CheckToPostMsg(MSG.MPNTPick, args[0], args[1], args[2], args[3]);
  2113. return (int)MSG.MPNTPick;
  2114. case "MPNTPlace":
  2115. CheckToPostMsg(MSG.MPNTPlace, args[0], args[1], args[2], args[3]);
  2116. return (int)MSG.MPNTPlace;
  2117. case "Reset":
  2118. CheckToPostMsg(MSG.RESET );
  2119. return (int)MSG.RESET;
  2120. }
  2121. return (int)FSM_MSG.NONE;
  2122. }
  2123. public bool CheckAcked(int msg)
  2124. {
  2125. return fsm.CheckExecuted(msg);
  2126. }
  2127. #endregion
  2128. }
  2129. }