RouteManager.cs 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552
  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. }
  633. private void Lp_ActionDone(bool obj)
  634. {
  635. if (fsm.State == (int)RtState.Cycle)
  636. {
  637. EV.PostInfoLog("System", "Notified LoadPort action done");
  638. CheckToPostMsg(MSG.LoadPortActionDone);
  639. }
  640. }
  641. private void Robot_ActionDone(bool obj)
  642. {
  643. if (fsm.State == (int) RtState.Cycle)
  644. {
  645. EV.PostInfoLog("System", "Notified robot action done");
  646. CheckToPostMsg(MSG.RobotActionDone);
  647. }
  648. if (obj == false && (fsm.State == (int) RtState.Picking || fsm.State == (int) RtState.Placing))
  649. {
  650. CheckToPostMsg(MSG.ERROR);
  651. }
  652. }
  653. void SubscribeOperation()
  654. {
  655. OP.Subscribe(OperationName.CreatWafer, InvokeCreateWafer);
  656. OP.Subscribe(OperationName.DeleteWafer, InvokeDeleteWafer);
  657. OP.Subscribe(OperationName.ResetRouteManager, InvokeResetRouteManager);
  658. //OP.Subscribe(OperationName.SetSpeed, InvokeSetSpeed);
  659. OP.Subscribe(OperationName.HomeUnit, InvokeHomeUnit);
  660. OP.Subscribe(OperationName.LoadFoup, InvokeLoadFoup);
  661. OP.Subscribe(OperationName.UnloadFoup, InvokeUnloadFoup);
  662. OP.Subscribe(OperationName.ReadFoupID, InvokeReadFoupID);
  663. OP.Subscribe(OperationName.WriteFoupID, InvokeWriteFoupID);
  664. OP.Subscribe(OperationName.MoveWafer, InvokeMoveWafer);
  665. OP.Subscribe(OperationName.ReturnWafer, InvokeReturnWafer);
  666. OP.Subscribe(OperationName.MultiMoveWafer, InvokeMultiMoveWafer);
  667. OP.Subscribe(OperationName.Stop, InvokeStop);
  668. OP.Subscribe("Benchmark", InvokeBenchmark);
  669. OP.Subscribe("System.StartCycle", InvokeCycle);
  670. OP.Subscribe(OperationName.SetAutoMode, InvokeSetAutoMode);
  671. OP.Subscribe(OperationName.SetManualMode, InvokeSetManualMode);
  672. OP.Subscribe(OperationName.HomeAll, InvokeHomeAll);
  673. OP.Subscribe(OperationName.AbortHomeAll, InvokeAbortHomeAll);
  674. OP.Subscribe(OperationName.SelectRecipe, InvokeSelectRecipe);
  675. OP.Subscribe(OperationName.StartRecipe, (string cmd, object[] args) =>
  676. {
  677. if (args.Length > 1)
  678. {
  679. return CheckToPostMsg(MSG.StartRecipe, args[0], args[1]);
  680. }
  681. return CheckToPostMsg(MSG.StartRecipe, args[0]);
  682. });
  683. OP.Subscribe(OperationName.PauseRecipe, InvokePauseRecipe);
  684. OP.Subscribe(OperationName.ResumeRecipe, InvokeResumeRecipe);
  685. OP.Subscribe(OperationName.StopRecipe, InvokeStopRecipe);
  686. OP.Subscribe("MapWafer", InvokeMapWafer);
  687. OP.Subscribe(ParamName.System.OPName.Reset, (string cmd, object[] args) =>
  688. {
  689. EV.ClearAlarmEvent();
  690. Singleton<DeviceEntity>.Instance.PostMsg(DeviceEntity.MSG.RESET);
  691. Singleton<EfemEntity>.Instance.PostMsg(EfemEntity.MSG.Reset);
  692. return CheckToPostMsg(MSG.RESET);
  693. });
  694. OP.Subscribe("System.SetWaferSize3", (string cmd, object[] args) =>
  695. {
  696. string module = (string)args[0];
  697. if (module == "Lower")
  698. {
  699. WaferManager.Instance.UpdateWaferSize(ModuleName.Robot, 0, WaferSize.WS3);
  700. return true;
  701. }
  702. if (module == "Upper")
  703. {
  704. WaferManager.Instance.UpdateWaferSize(ModuleName.Robot, 1, WaferSize.WS3);
  705. return true;
  706. }
  707. if (ModuleHelper.IsBuffer(ModuleHelper.Converter(module)))
  708. {
  709. var buffer = DEVICE.GetDevice<BufferStation>(module);
  710. if (buffer != null)
  711. {
  712. for (int i = 0; i < buffer.ValidSlotsNumber; i++)
  713. {
  714. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), i, WaferSize.WS3);
  715. }
  716. }
  717. SC.SetItemValue($"System.{module}WaferSize", 3);
  718. return true;
  719. }
  720. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS3);
  721. //string module = (string) args[0];
  722. //WaferManager.Instance.CheckWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS3);
  723. //if (ModuleHelper.Converter(module) == ModuleName.Robot)
  724. //{
  725. // WaferManager.Instance.CheckWaferSize(ModuleHelper.Converter(module), 1, WaferSize.WS3);
  726. //}
  727. return true;
  728. });
  729. OP.Subscribe("System.SetWaferSize4", (string cmd, object[] args) =>
  730. {
  731. string module = (string)args[0];
  732. if (module == "Lower")
  733. {
  734. WaferManager.Instance.UpdateWaferSize(ModuleName.Robot, 0, WaferSize.WS4);
  735. return true;
  736. }
  737. if (module == "Upper")
  738. {
  739. WaferManager.Instance.UpdateWaferSize(ModuleName.Robot, 1, WaferSize.WS4);
  740. return true;
  741. }
  742. if(ModuleHelper.IsBuffer(ModuleHelper.Converter(module)))
  743. {
  744. var buffer = DEVICE.GetDevice<BufferStation>(module);
  745. if (buffer != null)
  746. {
  747. for (int i=0;i<buffer.ValidSlotsNumber;i++)
  748. {
  749. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), i, WaferSize.WS4);
  750. }
  751. }
  752. SC.SetItemValue($"System.{module}WaferSize", 4);
  753. return true;
  754. }
  755. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS4);
  756. //WaferManager.Instance.CheckWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS4);
  757. //if(ModuleHelper.Converter(module) == ModuleName.Robot)
  758. //{
  759. // WaferManager.Instance.CheckWaferSize(ModuleHelper.Converter(module), 1, WaferSize.WS4);
  760. //}
  761. return true;
  762. });
  763. OP.Subscribe("System.SetWaferSize6", (string cmd, object[] args) =>
  764. {
  765. string module = (string)args[0];
  766. if (module == "Lower")
  767. {
  768. WaferManager.Instance.UpdateWaferSize(ModuleName.Robot, 0, WaferSize.WS6);
  769. return true;
  770. }
  771. if (module == "Upper")
  772. {
  773. WaferManager.Instance.UpdateWaferSize(ModuleName.Robot, 1, WaferSize.WS6);
  774. return true;
  775. }
  776. if (ModuleHelper.IsBuffer(ModuleHelper.Converter(module)))
  777. {
  778. var buffer = DEVICE.GetDevice<BufferStation>(module);
  779. if (buffer != null)
  780. {
  781. for (int i = 0; i < buffer.ValidSlotsNumber; i++)
  782. {
  783. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), i, WaferSize.WS6);
  784. }
  785. }
  786. SC.SetItemValue($"System.{module}WaferSize", 6);
  787. return true;
  788. }
  789. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS6);
  790. //string module = (string)args[0];
  791. //WaferManager.Instance.CheckWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS6);
  792. //if (ModuleHelper.Converter(module) == ModuleName.Robot)
  793. //{
  794. // WaferManager.Instance.CheckWaferSize(ModuleHelper.Converter(module), 1, WaferSize.WS6);
  795. //}
  796. return true;
  797. });
  798. OP.Subscribe("System.SetWaferSize8", (string cmd, object[] args) =>
  799. {
  800. string module = (string)args[0];
  801. if (module == "Lower")
  802. {
  803. WaferManager.Instance.UpdateWaferSize(ModuleName.Robot, 0, WaferSize.WS8);
  804. return true;
  805. }
  806. if (module == "Upper")
  807. {
  808. WaferManager.Instance.UpdateWaferSize(ModuleName.Robot, 1, WaferSize.WS8);
  809. return true;
  810. }
  811. if (ModuleHelper.IsBuffer(ModuleHelper.Converter(module)))
  812. {
  813. var buffer = DEVICE.GetDevice<BufferStation>(module);
  814. if (buffer != null)
  815. {
  816. for (int i = 0; i < buffer.ValidSlotsNumber; i++)
  817. {
  818. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), i, WaferSize.WS8);
  819. }
  820. }
  821. return true;
  822. SC.SetItemValue($"System.{module}WaferSize", 8);
  823. }
  824. WaferManager.Instance.UpdateWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS8);
  825. //string module = (string)args[0];
  826. //WaferManager.Instance.CheckWaferSize(ModuleHelper.Converter(module), 0, WaferSize.WS6);
  827. //if (ModuleHelper.Converter(module) == ModuleName.Robot)
  828. //{
  829. // WaferManager.Instance.CheckWaferSize(ModuleHelper.Converter(module), 1, WaferSize.WS6);
  830. //}
  831. return true;
  832. });
  833. OP.Subscribe("System.SetWaferThick", (string cmd, object[] args) =>
  834. {
  835. string module = (string)args[0];
  836. SC.SetItemValueFromString($"CarrierInfo.{module}ThicknessType", "THICK");
  837. return true;
  838. });
  839. OP.Subscribe("System.SetWaferThin", (string cmd, object[] args) =>
  840. {
  841. string module = (string)args[0];
  842. SC.SetItemValueFromString($"CarrierInfo.{module}ThicknessType", "THIN");
  843. return true;
  844. });
  845. OP.Subscribe("System.SetSlot13", (string cmd, object[] args) =>
  846. {
  847. string module = (string)args[0];
  848. //SC.SetItemValue($"CarrierInfo.Carrier0.CarrierSlotsNumber", 13);
  849. SC.SetItemValue($"LoadPort.{module}.SlotsNumber", 13);
  850. return true;
  851. });
  852. OP.Subscribe("System.SetSlot25", (string cmd, object[] args) =>
  853. {
  854. string module = (string)args[0];
  855. // SC.SetItemValue($"CarrierInfo.Carrier0.CarrierSlotsNumber", 25);
  856. SC.SetItemValue($"LoadPort.{module}.SlotsNumber", 25);
  857. return true;
  858. });
  859. OP.Subscribe("System.ClearEventLogEnable", (string cmd, object[] args) =>
  860. {
  861. ClearEventLogEnable = false;
  862. return true;
  863. });
  864. }
  865. private bool InvokeMapWafer(string arg1, object[] arg2)
  866. {
  867. return CheckToPostMsg(MSG.MapWafer, arg2[0].ToString());
  868. }
  869. private bool InvokeStopRecipe(string arg1, object[] arg2)
  870. {
  871. return CheckToPostMsg(MSG.StopRecipe);
  872. }
  873. private bool InvokeResumeRecipe(string arg1, object[] arg2)
  874. {
  875. //ret = PostMsg<RouteManager, RouteManager.MSG>(RouteManager.MSG.ResumeRecipe, out reason);
  876. return true;
  877. }
  878. private bool InvokePauseRecipe(string arg1, object[] arg2)
  879. {
  880. //ret = PostMsg<RouteManager, RouteManager.MSG>(RouteManager.MSG.PauseRecipe, out reason);
  881. return true;
  882. }
  883. private bool InvokeSelectRecipe(string arg1, object[] arg2)
  884. {
  885. //JobManager.Instance.SelectRecipe(arg2[0].ToString());
  886. //ret = true;
  887. return true;
  888. }
  889. private bool InvokeAbortHomeAll(string arg1, object[] arg2)
  890. {
  891. return CheckToPostMsg(MSG.ABORT);
  892. }
  893. private bool InvokeHomeAll(string arg1, object[] arg2)
  894. {
  895. return CheckToPostMsg(MSG.HOME);
  896. }
  897. private bool InvokeSetManualMode(string arg1, object[] arg2)
  898. {
  899. return CheckToPostMsg(MSG.SetManualMode);
  900. }
  901. private bool InvokeSetAutoMode(string arg1, object[] arg2)
  902. {
  903. if (!CheckEnableAuto())
  904. {
  905. return false;
  906. }
  907. return CheckToPostMsg(MSG.SetAutoMode); ;
  908. }
  909. private bool InvokeCycle(string arg1, object[] arg2)
  910. {
  911. string reason;
  912. if (!checkCycle(out reason))
  913. {
  914. EV.PostWarningLog("System", $"Can not start cycle, {reason}");
  915. return false;
  916. }
  917. return CheckToPostMsg(MSG.StartCycle, arg2[0], arg2[1], arg2[2]);
  918. }
  919. private bool InvokeBenchmark(string arg1, object[] arg2)
  920. {
  921. string reason;
  922. if (!checkCycle(out reason))
  923. {
  924. EV.PostWarningLog("System", $"Can not start cycle, {reason}");
  925. return false;
  926. }
  927. return CheckToPostMsg(MSG.StartCycle, arg2[0], arg2[1], arg2[2], "Benchmark");
  928. }
  929. private bool InvokeStop(string arg1, object[] arg2)
  930. {
  931. return CheckToPostMsg(MSG.Stop);
  932. }
  933. private bool InvokeMultiMoveWafer(string arg1, object[] arg2)
  934. {
  935. Running = false;
  936. string reason = "";
  937. bool ret = CheckMultiMove(out reason, arg2);
  938. if (ret)
  939. {
  940. MoveType type = (MoveType)arg2[0];
  941. MoveOption option = (MoveOption)arg2[1];
  942. Hand blade = (Hand)arg2[2];
  943. ModuleName schamber1 = (ModuleName)arg2[3];
  944. int sslot1 = (int)arg2[4];
  945. ModuleName dchamber1 = (ModuleName)arg2[5];
  946. int dslot1 = (int)arg2[6];
  947. ModuleName schamber2 = (ModuleName)arg2[3];
  948. int sslot2 = (int)arg2[4];
  949. ModuleName dchamber2 = (ModuleName)arg2[5];
  950. int dslot2 = (int)arg2[6];
  951. if (type != MoveType.Move)
  952. {
  953. schamber2 = (ModuleName)arg2[7];
  954. sslot2 = (int)arg2[8];
  955. dchamber2 = (ModuleName)arg2[9];
  956. dslot2 = (int)arg2[10];
  957. }
  958. _taskState[arg1] = Result.RUN;
  959. PostMsg(RouteManager.MSG.MoveWafer, type, option, blade,
  960. schamber1, sslot1, dchamber1, dslot1,
  961. schamber2, sslot2, dchamber2, dslot2
  962. );
  963. }
  964. else
  965. {
  966. _taskState[arg1] = Result.FAIL;
  967. return false;
  968. }
  969. return true;
  970. }
  971. private bool InvokeReturnWafer(string arg1, object[] arg2)
  972. {
  973. return CheckToPostMsg(MSG.ReturnWafer);
  974. }
  975. public bool InvokeMoveWafer(string arg1, object[] args)
  976. {
  977. Running = false;
  978. string reason = "";
  979. bool ret = checkMove(out reason, args);
  980. if (ret)
  981. {
  982. MoveType type = (MoveType)args[0];
  983. MoveOption option = (MoveOption)args[1];
  984. Hand blade = (Hand)args[2];
  985. ModuleName schamber1 = (ModuleName)args[3];
  986. int sslot1 = (int)args[4];
  987. ModuleName dchamber1 = (ModuleName)args[5];
  988. int dslot1 = (int)args[6];
  989. ModuleName schamber2 = (ModuleName)args[3];
  990. int sslot2 = (int)args[4];
  991. ModuleName dchamber2 = (ModuleName)args[5];
  992. int dslot2 = (int)args[6];
  993. if (type != MoveType.Move)
  994. {
  995. schamber2 = (ModuleName)args[7];
  996. sslot2 = (int)args[8];
  997. dchamber2 = (ModuleName)args[9];
  998. dslot2 = (int)args[10];
  999. }
  1000. _taskState[arg1] = Result.RUN;
  1001. PostMsg(RouteManager.MSG.MoveWafer, type, option, blade,
  1002. schamber1, sslot1, dchamber1, dslot1,
  1003. schamber2, sslot2, dchamber2, dslot2
  1004. );
  1005. }
  1006. else
  1007. {
  1008. _taskState[arg1] = Result.FAIL;
  1009. }
  1010. return true;
  1011. }
  1012. private bool InvokeWriteFoupID(string arg1, object[] arg2)
  1013. {
  1014. //{
  1015. // ret = true;
  1016. // ret = PostMsg<RouteManager, RouteManager.MSG>(RouteManager.MSG.WriteID, out reason, args);
  1017. //}
  1018. return true;
  1019. }
  1020. private bool InvokeReadFoupID(string arg1, object[] arg2)
  1021. {
  1022. return CheckToPostMsg(MSG.ReadID, arg2[0]);
  1023. }
  1024. private bool InvokeUnloadFoup(string arg1, object[] arg2)
  1025. {
  1026. return CheckToPostMsg(MSG.UNLOAD, arg2[0]);
  1027. }
  1028. private bool InvokeLoadFoup(string arg1, object[] arg2)
  1029. {
  1030. return CheckToPostMsg(MSG.LOAD, arg2[0]);
  1031. //var lp = DEVICE.GetDevice<LoadPortBaseDevice>(arg2[0].ToString());
  1032. //return lp.Load(out _);
  1033. }
  1034. private bool InvokeHomeUnit(string arg1, object[] arg2)
  1035. {
  1036. var lp = DEVICE.GetDevice<LoadPortBaseDevice>(arg2[0].ToString());
  1037. return lp.Unload(out _);
  1038. }
  1039. private bool InvokeSetSpeed(string arg1, object[] args)
  1040. {
  1041. int speed = 3;
  1042. string reason;
  1043. if (int.TryParse((string)args[0], out speed))
  1044. {
  1045. if (!(speed <= 3 || speed >= 1))
  1046. {
  1047. EV.PostWarningLog(ModuleName.Robot.ToString(), "Error Parameter,speed should be range in 1, 3");
  1048. }
  1049. PostMsg(MSG.SetSpeed, int.Parse((string)args[0]));
  1050. return true;
  1051. }
  1052. EV.PostWarningLog(ModuleName.Robot.ToString(), $"invalid parameters. {args[0]}");
  1053. return false;
  1054. }
  1055. private bool InvokeResetRouteManager(string arg1, object[] arg2)
  1056. {
  1057. PostMsg(MSG.RESET);
  1058. return true;
  1059. }
  1060. private bool InvokeDeleteWafer(string arg1, object[] args)
  1061. {
  1062. ModuleName chamber = (ModuleName)args[0];
  1063. int slot = (int)args[1];
  1064. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  1065. {
  1066. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  1067. {
  1068. WaferManager.Instance.DeleteWafer(chamber, slot);
  1069. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferDelete, chamber.ToString(), slot + 1);
  1070. }
  1071. else
  1072. {
  1073. EV.PostInfoLog("System", string.Format("No wafer at {0} {1}, delete not valid", chamber.ToString(), slot + 1));
  1074. }
  1075. }
  1076. else
  1077. {
  1078. EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  1079. return false;
  1080. }
  1081. return true;
  1082. }
  1083. private bool InvokeCreateWafer(string arg1, object[] args)
  1084. {
  1085. ModuleName chamber = (ModuleName)args[0];
  1086. int slot = (int)args[1];
  1087. WaferStatus state = (WaferStatus)args[2];
  1088. if (WaferManager.Instance.IsWaferSlotLocationValid(chamber, slot))
  1089. {
  1090. if (WaferManager.Instance.CheckHasWafer(chamber, slot))
  1091. {
  1092. EV.PostInfoLog("System", string.Format("{0} slot {1} already has wafer.create wafer is not valid", chamber, slot));
  1093. }
  1094. else
  1095. {
  1096. if (ModuleHelper.IsLoadPort(chamber))
  1097. {
  1098. var lp = DEVICE.GetDevice<LoadPortBaseDevice>(chamber.ToString());
  1099. if (WaferManager.Instance.CreateWafer(chamber, slot, state, lp.GetCurrentWaferSize()) != null)
  1100. {
  1101. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferCreate, chamber.ToString(), slot + 1, state.ToString());
  1102. }
  1103. }
  1104. else if (WaferManager.Instance.CreateWafer(chamber, slot, state, WaferSize.WS8) != null)
  1105. {
  1106. EV.PostMessage(ModuleName.System.ToString(), EventEnum.WaferCreate, chamber.ToString(), slot + 1, state.ToString());
  1107. }
  1108. }
  1109. }
  1110. else
  1111. {
  1112. EV.PostWarningLog("System", string.Format("Invalid position,{0},{1}", chamber.ToString(), slot.ToString()));
  1113. return false;
  1114. }
  1115. return true;
  1116. }
  1117. #endregion
  1118. protected override bool Init()
  1119. {
  1120. for (var i = 0; i < LoadPortQuantity; i++)
  1121. {
  1122. _loadportEntities[i].Initialize();
  1123. }
  1124. if(!FlipperIsDisable) _flp.Initialize();
  1125. _cycle.Initialize();
  1126. setspeedRoutine = new SetSpeedRoutine("System", "Set Speed");
  1127. setspeedRoutine.Initalize();
  1128. initRoutine = _isInterferencePrevent
  1129. ? (IEfemRoutine)new InitRoutine2Step("System", "Init")
  1130. : (IEfemRoutine)new InitRoutine("System", "Init");
  1131. initRoutine.Initalize();
  1132. _waferMapRoutine = new WaferMappingRoutine();
  1133. _waferMapRoutine.Initalize();
  1134. _staticTransfer.Initialize();
  1135. _dualMover.Initialize();
  1136. _singleMover.Initialize();
  1137. _loadFoupRoutine = new LoadFoupRoutine(ModuleName.LP1.ToString(), "Load");
  1138. _loadFoupRoutine.Initalize();
  1139. _pickRoutine = new PickRoutine("System", "Pick");
  1140. _pickRoutine.Initalize();
  1141. _placeRoutine = new PlaceRoutine("System", "Place");
  1142. _placeRoutine.Initalize();
  1143. _pickExtendRoutine = new PickExtendRoutine("System", "PickExtend");
  1144. _pickExtendRoutine.Initalize();
  1145. _placeExtendRoutine = new PlaceExtendRoutine("System", "PlaceExtend");
  1146. _placeExtendRoutine.Initalize();
  1147. return true;
  1148. }
  1149. protected override void Term()
  1150. {
  1151. //_loadportA.Terminate();
  1152. //_loadportB.Terminate();
  1153. }
  1154. #region Mode change
  1155. private bool fSetAutoMode(object[] objs)
  1156. {
  1157. IsAutoMode = true;
  1158. EV.PostMessage(ChamberSetString.System, EventEnum.RunningModeChanged, "AutoMode");
  1159. return true;
  1160. }
  1161. private bool fSetManualMode(object[] objs)
  1162. {
  1163. IsAutoMode = false;
  1164. EV.PostMessage(ChamberSetString.System, EventEnum.RunningModeChanged, "ManualMode");
  1165. return true;
  1166. }
  1167. private bool fSetMaintenanceMode(object[] param)
  1168. {
  1169. IsAutoMode = false;
  1170. EV.PostMessage(ChamberSetString.System, EventEnum.RunningModeChanged, "Maintenance");
  1171. return true;
  1172. }
  1173. #endregion
  1174. #region Init
  1175. private bool fStartInit(object[] objs)
  1176. {
  1177. Result ret = initRoutine.Start(objs);
  1178. if (ret == Result.DONE)
  1179. {
  1180. return false;
  1181. }
  1182. else if (ret == Result.FAIL)
  1183. {
  1184. return false; //do noting
  1185. }
  1186. return true;
  1187. }
  1188. private bool fInit(object[] objs)
  1189. {
  1190. Result ret = initRoutine.Monitor();
  1191. if (ret == Result.DONE)
  1192. {
  1193. //state = (int)STATE.IDLE;
  1194. return true;
  1195. }
  1196. else if (ret == Result.FAIL)
  1197. {
  1198. //do nothing
  1199. //state = (int)STATE.ERROR;
  1200. PostMsg(MSG.ERROR);
  1201. return false;
  1202. }
  1203. return false; ;
  1204. }
  1205. private bool fError(object[] objs)
  1206. {
  1207. for (int i = 0; i < _taskState.Count; i++)
  1208. {
  1209. _taskState[_taskState.ElementAt(i).Key] = Result.FAIL;
  1210. }
  1211. return true;
  1212. }
  1213. private bool fIdle(object[] objs)
  1214. {
  1215. _taskState.Clear();
  1216. return true;
  1217. }
  1218. #endregion
  1219. #region setspeed
  1220. private bool fStartSetSpeed(object[] objs)
  1221. {
  1222. Result ret = setspeedRoutine.Start(objs);
  1223. setspeedRoutine.Speed = (int)objs[0];
  1224. if (ret == Result.DONE)
  1225. {
  1226. return false;
  1227. }
  1228. else if (ret == Result.FAIL)
  1229. {
  1230. return false; //do noting
  1231. }
  1232. return true;
  1233. }
  1234. private bool fSetSpeed(object[] objs)
  1235. {
  1236. Result ret = setspeedRoutine.Monitor();
  1237. if (ret == Result.DONE)
  1238. {
  1239. //state = (int)STATE.IDLE;
  1240. return true;
  1241. }
  1242. else if (ret == Result.FAIL)
  1243. {
  1244. //do nothing
  1245. //state = (int)STATE.ERROR;
  1246. return true;
  1247. }
  1248. return false;
  1249. }
  1250. #endregion
  1251. #region Transfer
  1252. private bool fStartTransfer(object[] objs)
  1253. {
  1254. Running = true;
  1255. return _staticTransfer.Start(objs);
  1256. }
  1257. private bool fStartReturn(object[] objs)
  1258. {
  1259. return _staticTransfer.Return(objs);
  1260. }
  1261. private bool fTransfer(object[] objs)
  1262. {
  1263. return _staticTransfer.Monitor(objs);
  1264. }
  1265. private bool fExitTransfer(object[] objs)
  1266. {
  1267. _staticTransfer.Clear();
  1268. _taskState.Remove("MoveWafer");
  1269. return true;
  1270. }
  1271. private void ProcessFinished()
  1272. {
  1273. }
  1274. private IMoveManager GetMoveManager(bool bAligner)
  1275. {
  1276. if (!_robot.Blade1Enable)
  1277. {
  1278. EV.PostMessage(ModuleName.System.ToString(), EventEnum.DefaultWarning, "Robot arm1 is disable, can't execute transfer");
  1279. return null;
  1280. }
  1281. if (bAligner)
  1282. {
  1283. _singleMover.Blade = Hand.Blade1;
  1284. return _singleMover;
  1285. }
  1286. if (_robot.Blade1Enable && _robot.Blade2Enable && SC.GetValue<bool>(SorterCommon.ScPathName.Robot_DualBlade1TransferEnable))
  1287. return _dualMover;
  1288. _singleMover.Blade = Hand.Blade1;
  1289. return _singleMover;
  1290. }
  1291. private bool fAbortTransfer(object[] objs)
  1292. {
  1293. return true;
  1294. }
  1295. private bool FsmStartRobotPick(object[] param)
  1296. {
  1297. Result ret = Result.DONE;
  1298. if (param.Length == 3)
  1299. {
  1300. _pickRoutine.Source = ModuleHelper.Converter((string)param[0]);
  1301. _pickRoutine.Slot = (int)param[1];
  1302. _pickRoutine.Blade = (Hand)param[2];
  1303. ret = _pickRoutine.Start();
  1304. }
  1305. else
  1306. {
  1307. return false;
  1308. }
  1309. if (ret == Result.FAIL || ret == Result.DONE)
  1310. return false;
  1311. return ret == Result.RUN;
  1312. }
  1313. private bool FsmStartRobotMpntPick(object[] param)
  1314. {
  1315. Result ret = Result.DONE;
  1316. if (param.Length == 4)
  1317. {
  1318. _pickExtendRoutine.Source = ModuleHelper.Converter((string)param[0]);
  1319. _pickExtendRoutine.Slot = (int)param[1];
  1320. _pickExtendRoutine.Blade = (Hand)param[2];
  1321. _pickExtendRoutine.TaskEnum = (MpntTaskEnum)param[3];
  1322. ret = _pickExtendRoutine.Start();
  1323. }
  1324. else
  1325. {
  1326. return false;
  1327. }
  1328. if (ret == Result.FAIL || ret == Result.DONE)
  1329. return false;
  1330. return ret == Result.RUN;
  1331. }
  1332. private bool FsmStartRobotPlace(object[] param)
  1333. {
  1334. Result ret = Result.DONE;
  1335. if (param.Length == 3)
  1336. {
  1337. _placeRoutine.Station = ModuleHelper.Converter((string)param[0]);
  1338. _placeRoutine.Slot = (int)param[1];
  1339. _placeRoutine.Blade = (Hand)param[2];
  1340. ret = _placeRoutine.Start();
  1341. }
  1342. else
  1343. {
  1344. return false;
  1345. }
  1346. if (ret == Result.FAIL || ret == Result.DONE)
  1347. return false;
  1348. return ret == Result.RUN;
  1349. }
  1350. private bool FsmStartRobotMpntPlace(object[] param)
  1351. {
  1352. Result ret = Result.DONE;
  1353. if (param.Length == 4)
  1354. {
  1355. _placeExtendRoutine.Station = ModuleHelper.Converter((string)param[0]);
  1356. _placeExtendRoutine.Slot = (int)param[1];
  1357. _placeExtendRoutine.Blade = (Hand)param[2];
  1358. _placeExtendRoutine.TaskEnum = (MpntTaskEnum)param[3];
  1359. ret = _placeExtendRoutine.Start();
  1360. }
  1361. else
  1362. {
  1363. return false;
  1364. }
  1365. if (ret == Result.FAIL || ret == Result.DONE)
  1366. return false;
  1367. return ret == Result.RUN;
  1368. }
  1369. private bool FsmChangeCassette(object[] param)
  1370. {
  1371. var lp = param[0].ToString();
  1372. switch (fsm.State)
  1373. {
  1374. case (int)RtState.Cycle when lp == _cycle.OriginStation.ToString() || lp == _cycle.ToStation.ToString():
  1375. _transferManager.Clear();
  1376. IsTransferMode = false;
  1377. _robot.Stop();
  1378. EV.PostWarningLog("System", "Cassette changed during cycle");
  1379. return true;
  1380. case (int)RtState.Transfer when lp == _staticTransfer.TargetStation.ToString() || lp == _staticTransfer.SourceStation.ToString():
  1381. _transferManager.Clear();
  1382. _staticTransfer.Clear();
  1383. IsTransferMode = false;
  1384. _robot.Stop();
  1385. EV.PostWarningLog("System", "Cassette changed during transfer");
  1386. return true;
  1387. case (int)RtState.WaferMapping when lp == _waferMapRoutine.Source.ToString():
  1388. _transferManager.Clear();
  1389. _staticTransfer.Clear();
  1390. IsTransferMode = false;
  1391. _robot.Stop();
  1392. EV.PostWarningLog("System", "Cassette changed during wafer mapping");
  1393. return true;
  1394. case (int)RtState.Picking when lp == _pickRoutine.Source.ToString():
  1395. case (int)RtState.Placing when lp == _placeRoutine.Station.ToString():
  1396. _transferManager.Clear();
  1397. IsTransferMode = false;
  1398. _robot.Stop();
  1399. EV.PostWarningLog("System", "Cassette changed during transfer");
  1400. return true;
  1401. default:
  1402. return false;
  1403. }
  1404. }
  1405. private bool FsmAbortTask(object[] param)
  1406. {
  1407. return true;
  1408. }
  1409. private bool FsmMonitorPick(object[] param)
  1410. {
  1411. Result ret = _pickRoutine.Monitor();
  1412. if (ret == Result.FAIL)
  1413. {
  1414. PostMsg(MSG.ERROR);
  1415. return false;
  1416. }
  1417. return ret == Result.DONE;
  1418. }
  1419. private bool FsmMonitorMpntPick(object[] param)
  1420. {
  1421. Result ret = _pickExtendRoutine.Monitor();
  1422. if (ret == Result.FAIL)
  1423. {
  1424. PostMsg(MSG.ERROR);
  1425. return false;
  1426. }
  1427. return ret == Result.DONE;
  1428. }
  1429. private bool FsmMonitorPlace(object[] param)
  1430. {
  1431. Result ret = _placeRoutine.Monitor();
  1432. if (ret == Result.FAIL)
  1433. {
  1434. PostMsg(MSG.ERROR);
  1435. return false;
  1436. }
  1437. return ret == Result.DONE;
  1438. }
  1439. private bool FsmMonitorMpntPlace(object[] param)
  1440. {
  1441. Result ret = _placeExtendRoutine.Monitor();
  1442. if (ret == Result.FAIL)
  1443. {
  1444. PostMsg(MSG.ERROR);
  1445. return false;
  1446. }
  1447. return ret == Result.DONE;
  1448. }
  1449. #endregion
  1450. #region reset
  1451. private bool fStartReset(object[] objs)
  1452. {
  1453. Singleton<EfemEntity>.Instance.EventError?.Clear();
  1454. if(DEVICE.GetDevice<LoadPortBaseDevice>(ModuleName.LP1.ToString())!=null&& DEVICE.GetDevice<LoadPortBaseDevice>(ModuleName.LP1.ToString()).State==DeviceState.Error)
  1455. DEVICE.GetDevice<LoadPortBaseDevice>(ModuleName.LP1.ToString()).CheckToPostMessage((int)LoadPortMsg.Reset, null); ;
  1456. if (DEVICE.GetDevice<LoadPortBaseDevice>(ModuleName.LP2.ToString()) != null && DEVICE.GetDevice<LoadPortBaseDevice>(ModuleName.LP2.ToString()).State == DeviceState.Error)
  1457. DEVICE.GetDevice<LoadPortBaseDevice>(ModuleName.LP2.ToString()).CheckToPostMessage((int)LoadPortMsg.Reset, null); ;
  1458. if (fsm.State == (int)RtState.Error)
  1459. return true;
  1460. return false;
  1461. }
  1462. #endregion
  1463. #region cycle
  1464. private bool bCycle = false;
  1465. private bool bReturn = false;
  1466. private ModuleName _cycleSource;
  1467. private ModuleName _cycleTarget;
  1468. private bool bMappingSource = false;
  1469. private bool _bUnload = false;
  1470. private MoveOption _moveOption;
  1471. private bool fStartCycle(object[] objs)
  1472. {
  1473. if (objs.Length < 2)
  1474. {
  1475. EV.PostWarningLog("System", "Cycle parameter is not valid, should be 2 LP modules");
  1476. return false;
  1477. }
  1478. if (!Enum.TryParse((string)objs[0], out ModuleName from) || !Enum.TryParse((string)objs[1], out ModuleName to))
  1479. {
  1480. EV.PostWarningLog(ChamberSetString.System,
  1481. ("Cycle parameter error, please check source and destination."));
  1482. return false;
  1483. }
  1484. Result ret = Result.FAIL;
  1485. if (objs.Length >= 3)
  1486. {
  1487. string[] _moveOption = (string[])objs[2];
  1488. ret = _cycle.Start(from, to, (string[])objs[2]);
  1489. }
  1490. if (ret == Result.FAIL)
  1491. {
  1492. EV.PostWarningLog(ChamberSetString.System,
  1493. ("There is wafer on the passing route"));
  1494. return false;
  1495. }
  1496. return ret == Result.RUN;
  1497. }
  1498. private bool fCycle(object[] objs)
  1499. {
  1500. Result ret = _cycle.Monitor();
  1501. if (ret == Result.DONE)
  1502. return true;
  1503. if (ret == Result.FAIL)
  1504. {
  1505. PostMsg(MSG.ERROR);
  1506. return false;
  1507. }
  1508. return false; //continue
  1509. }
  1510. private bool fAbortRunProcess(object[] objs)
  1511. {
  1512. if (fsm.State == (int)RtState.Cycle)
  1513. {
  1514. bool _swapHand = false;
  1515. if (SC.ContainsItem("Process.CycleSwapHand"))
  1516. {
  1517. _swapHand = SC.GetValue<bool>("Process.CycleSwapHand");
  1518. }
  1519. if (_swapHand &&
  1520. ((_moveOption & MoveOption.LoadLock1) == MoveOption.LoadLock1 ||
  1521. (_moveOption & MoveOption.LoadLock2) == MoveOption.LoadLock2 ||
  1522. (_moveOption & MoveOption.LoadLock3) == MoveOption.LoadLock3 ||
  1523. (_moveOption & MoveOption.LoadLock4) == MoveOption.LoadLock4 ||
  1524. (_moveOption & MoveOption.LoadLock5) == MoveOption.LoadLock5 ||
  1525. (_moveOption & MoveOption.LoadLock6) == MoveOption.LoadLock6 ||
  1526. (_moveOption & MoveOption.LoadLock7) == MoveOption.LoadLock7 ||
  1527. (_moveOption & MoveOption.LoadLock8) == MoveOption.LoadLock8 ||
  1528. (_moveOption & MoveOption.Buffer) == MoveOption.Buffer))
  1529. {
  1530. SC.SetItemValue(ScPathName.Robot_Blade1Enable, true);
  1531. SC.SetItemValue(ScPathName.Robot_Blade2Enable, true);
  1532. }
  1533. _moveOption = MoveOption.None;
  1534. }
  1535. _transferManager.Clear();
  1536. IsTransferMode = false;
  1537. return true;
  1538. }
  1539. private bool fCycleStop(object[] objs)
  1540. {
  1541. _cycle.Stop();
  1542. bool _swapHand = false;
  1543. if (SC.ContainsItem("Process.CycleSwapHand"))
  1544. {
  1545. _swapHand = SC.GetValue<bool>("Process.CycleSwapHand");
  1546. }
  1547. if (_swapHand &&
  1548. ((_moveOption & MoveOption.LoadLock1) == MoveOption.LoadLock1 ||
  1549. (_moveOption & MoveOption.LoadLock2) == MoveOption.LoadLock2 ||
  1550. (_moveOption & MoveOption.LoadLock3) == MoveOption.LoadLock3 ||
  1551. (_moveOption & MoveOption.LoadLock4) == MoveOption.LoadLock4 ||
  1552. (_moveOption & MoveOption.LoadLock5) == MoveOption.LoadLock5 ||
  1553. (_moveOption & MoveOption.LoadLock6) == MoveOption.LoadLock6 ||
  1554. (_moveOption & MoveOption.LoadLock7) == MoveOption.LoadLock7 ||
  1555. (_moveOption & MoveOption.LoadLock8) == MoveOption.LoadLock8 ||
  1556. (_moveOption & MoveOption.Buffer) == MoveOption.Buffer))
  1557. {
  1558. SC.SetItemValue(ScPathName.Robot_Blade1Enable, true);
  1559. SC.SetItemValue(ScPathName.Robot_Blade2Enable, true);
  1560. }
  1561. _moveOption = MoveOption.None;
  1562. return true;
  1563. }
  1564. private bool FsmExitCycle(object[] param)
  1565. {
  1566. _cycle.Stop();
  1567. EV.PostInfoLog("System", "Stop Cycle");
  1568. bool _swapHand = false;
  1569. if (SC.ContainsItem("Process.CycleSwapHand"))
  1570. {
  1571. _swapHand = SC.GetValue<bool>("Process.CycleSwapHand");
  1572. }
  1573. if (_swapHand &&
  1574. ((_moveOption & MoveOption.LoadLock1) == MoveOption.LoadLock1 ||
  1575. (_moveOption & MoveOption.LoadLock2) == MoveOption.LoadLock2 ||
  1576. (_moveOption & MoveOption.LoadLock3) == MoveOption.LoadLock3 ||
  1577. (_moveOption & MoveOption.LoadLock4) == MoveOption.LoadLock4 ||
  1578. (_moveOption & MoveOption.LoadLock5) == MoveOption.LoadLock5 ||
  1579. (_moveOption & MoveOption.LoadLock6) == MoveOption.LoadLock6 ||
  1580. (_moveOption & MoveOption.LoadLock7) == MoveOption.LoadLock7 ||
  1581. (_moveOption & MoveOption.LoadLock8) == MoveOption.LoadLock8 ||
  1582. (_moveOption & MoveOption.Buffer) == MoveOption.Buffer))
  1583. {
  1584. SC.SetItemValue(ScPathName.Robot_Blade1Enable, true);
  1585. SC.SetItemValue(ScPathName.Robot_Blade2Enable, true);
  1586. }
  1587. _moveOption = MoveOption.None;
  1588. return true;
  1589. }
  1590. private bool FsmEnterCycle(object[] param)
  1591. {
  1592. EV.PostInfoLog("System", "Start Cycle");
  1593. return true;
  1594. }
  1595. #endregion
  1596. #region Loadport
  1597. private bool fHome(object[] objs)
  1598. {
  1599. ModuleName chamber = (ModuleName)(objs[0]);
  1600. Post(chamber, LoadPortEntity.MSG.HOME);
  1601. return true;
  1602. }
  1603. private bool fLoad(object[] objs)
  1604. {
  1605. ModuleName chamber = (ModuleName)(objs[0]);
  1606. Post(chamber, LoadPortEntity.MSG.Load);
  1607. return true;
  1608. }
  1609. private bool fReadAndLoad(object[] objs)
  1610. {
  1611. ModuleName chamber = (ModuleName)(objs[0]);
  1612. Post(chamber, LoadPortEntity.MSG.ReadAndLoad);
  1613. return true;
  1614. }
  1615. private bool fUnload(object[] objs)
  1616. {
  1617. ModuleName chamber = (ModuleName)(objs[0]);
  1618. Post(chamber, LoadPortEntity.MSG.Unload);
  1619. return true;
  1620. }
  1621. private bool fReadID(object[] objs)
  1622. {
  1623. ModuleName chamber = (ModuleName)(objs[0]);
  1624. Post(chamber, LoadPortEntity.MSG.ReadRFID);
  1625. return true;
  1626. }
  1627. private bool fWriteID(object[] objs)
  1628. {
  1629. ModuleName chamber = (ModuleName)(objs[0]);
  1630. Post(chamber, LoadPortEntity.MSG.WriteRFID);
  1631. return true;
  1632. }
  1633. private bool Post(ModuleName chamber, LoadPortEntity.MSG msg, params object[] objs)
  1634. {
  1635. string pattern = "[1-9]\\d*";
  1636. Regex rgx = new Regex(pattern);
  1637. var match = int.Parse(rgx.Match(chamber.ToString()).ToString());
  1638. if (match <= LoadPortQuantity)
  1639. _loadportEntities[match - 1].PostMsg(msg, objs);
  1640. return true;
  1641. }
  1642. #endregion
  1643. #region validation
  1644. /// <summary>
  1645. ///
  1646. /// </summary>
  1647. /// <param name="msg"></param>
  1648. /// <param name="reason"></param>
  1649. /// <param name="args"></param>
  1650. /// <returns></returns>
  1651. public bool CheckMsg(int msg, out string reason, bool eventOutReason, params object[] args)
  1652. {
  1653. Running = true;
  1654. if (!fsm.FindTransition(fsm.State, msg))
  1655. {
  1656. reason = String.Format("{0} is in {1} state,can not do {2}", Name, (RtState)fsm.State, (MSG)msg);
  1657. if (eventOutReason)
  1658. {
  1659. EV.PostMessage("System", EventEnum.DefaultWarning, reason);
  1660. }
  1661. Running = false;
  1662. return false;
  1663. }
  1664. if (msg == (int)MSG.StartRecipe || msg == (int)MSG.StartCycle)
  1665. {
  1666. if (!IsAutoMode)
  1667. {
  1668. reason = String.Format("can not do {0}, isn't auto mode.", msg.ToString());
  1669. if (eventOutReason)
  1670. {
  1671. EV.PostMessage("System", EventEnum.DefaultWarning, reason);
  1672. }
  1673. Running = false;
  1674. return false;
  1675. }
  1676. }
  1677. reason = "";
  1678. return true;
  1679. }
  1680. public bool CheckToPostMsg(MSG msg)
  1681. {
  1682. if (!fsm.FindTransition(fsm.State, (int)msg))
  1683. {
  1684. EV.PostMessage("System", EventEnum.DefaultWarning,
  1685. string.Format("{0} is in {1} state,can not do {2}", Name, (RtState)fsm.State, (MSG)msg));
  1686. return false;
  1687. }
  1688. PostMsg(msg);
  1689. return true;
  1690. }
  1691. public bool CheckToPostMsg(MSG msg, object param1)
  1692. {
  1693. if (!fsm.FindTransition(fsm.State, (int)msg))
  1694. {
  1695. EV.PostMessage("System", EventEnum.DefaultWarning,
  1696. string.Format("{0} is in {1} state,can not do {2}", Name, (RtState)fsm.State, (MSG)msg));
  1697. return false;
  1698. }
  1699. PostMsg(msg, param1);
  1700. return true;
  1701. }
  1702. public bool CheckToPostMsg(MSG msg, object param1, object param2)
  1703. {
  1704. if (!fsm.FindTransition(fsm.State, (int)msg))
  1705. {
  1706. EV.PostMessage("System", EventEnum.DefaultWarning,
  1707. string.Format("{0} is in {1} state,can not do {2}", Name, (RtState)fsm.State, (MSG)msg));
  1708. return false;
  1709. }
  1710. PostMsg(msg, param1, param2);
  1711. return true;
  1712. }
  1713. public bool CheckToPostMsg(MSG msg, object param1, object param2, object param3)
  1714. {
  1715. if (!fsm.FindTransition(fsm.State, (int)msg))
  1716. {
  1717. EV.PostMessage("System", EventEnum.DefaultWarning,
  1718. string.Format("{0} is in {1} state,can not do {2}", Name, (RtState)fsm.State, (MSG)msg));
  1719. return false;
  1720. }
  1721. PostMsg(msg, param1, param2, param3);
  1722. return true;
  1723. }
  1724. public bool CheckToPostMsg(MSG msg, object param1, object param2, object param3, object param4)
  1725. {
  1726. if (!fsm.FindTransition(fsm.State, (int)msg))
  1727. {
  1728. EV.PostMessage("System", EventEnum.DefaultWarning,
  1729. string.Format("{0} is in {1} state,can not do {2}", Name, (RtState)fsm.State, (MSG)msg));
  1730. return false;
  1731. }
  1732. PostMsg(msg, param1, param2, param3, param4);
  1733. return true;
  1734. }
  1735. private bool check(ModuleName source, int slot, ModuleName dest, int dslot, Hand blade, MoveOption option, out string reason)
  1736. {
  1737. reason = string.Empty;
  1738. if (!checkFoup(source, out reason))
  1739. {
  1740. return false;
  1741. }
  1742. if (!checkFoup(dest, out reason))
  1743. {
  1744. return false;
  1745. }
  1746. if (!WaferManager.Instance.IsWaferSlotLocationValid(source, slot))
  1747. {
  1748. reason = string.Format("Invalid source parameter, {0}:{1:D2}", source.ToString(), slot);
  1749. return false;
  1750. }
  1751. if (!WaferManager.Instance.IsWaferSlotLocationValid(dest, dslot))
  1752. {
  1753. reason = string.Format("Invalid destination parameter, {0}:{1:D2}", dest.ToString(), dslot);
  1754. return false;
  1755. }
  1756. if (!WaferManager.Instance.CheckWafer(source, slot, WaferStatus.Normal))
  1757. {
  1758. if (ModuleHelper.IsLoadLock(source) && Singleton<EfemEntity>.Instance.IsOnlineMode)
  1759. {
  1760. //online mode, CreateWafer in LoadLock
  1761. WaferManager.Instance.CreateWafer(source, slot, WaferStatus.Normal);
  1762. }
  1763. else
  1764. {
  1765. reason = string.Format("Source no normal wafer, {0}:{1:D2}", source.ToString(), slot);
  1766. return false;
  1767. }
  1768. }
  1769. if (!WaferManager.Instance.CheckWafer(dest, dslot, WaferStatus.Empty))
  1770. {
  1771. reason = string.Format("destination has wafer, {0}:{1:D2}", dest.ToString(), dslot);
  1772. return false;
  1773. }
  1774. if (source != ModuleName.Robot && dest != ModuleName.Robot)
  1775. {
  1776. if (!WaferManager.Instance.CheckWafer(ModuleName.Robot, (int)blade, WaferStatus.Empty))
  1777. {
  1778. reason = string.Format("robot has wafer on arm");
  1779. return false;
  1780. }
  1781. }
  1782. bool bAligner = ((option & MoveOption.Align) == MoveOption.Align) ||
  1783. ((option & MoveOption.ReadID) == MoveOption.ReadID) ||
  1784. ((option & MoveOption.ReadID2) == MoveOption.ReadID2);
  1785. if (bAligner)
  1786. {
  1787. if (source != ModuleName.Aligner && dest != ModuleName.Aligner)
  1788. {
  1789. if (!WaferManager.Instance.CheckWafer(ModuleName.Aligner, 0, WaferStatus.Empty))
  1790. {
  1791. reason = string.Format("aligner has wafer on");
  1792. return false;
  1793. }
  1794. }
  1795. }
  1796. return true;
  1797. }
  1798. private bool check(ModuleName source, int slot, ModuleName dest, int dslot, out string reason)
  1799. {
  1800. reason = string.Empty;
  1801. if (!checkFoup(source, out reason))
  1802. {
  1803. return false;
  1804. }
  1805. if (!checkFoup(dest, out reason))
  1806. {
  1807. return false;
  1808. }
  1809. if (!WaferManager.Instance.IsWaferSlotLocationValid(source, slot))
  1810. {
  1811. reason = string.Format("非法的参数。{0}:{1:D2}", source.ToString(), slot);
  1812. return false;
  1813. }
  1814. if (!WaferManager.Instance.IsWaferSlotLocationValid(dest, dslot))
  1815. {
  1816. reason = string.Format("非法的参数。{0}:{1:D2}", dest.ToString(), dslot);
  1817. return false;
  1818. }
  1819. if (!WaferManager.Instance.CheckWafer(source, slot, WaferStatus.Normal))
  1820. {
  1821. reason = string.Format("源位置没有wafer。{0}:{1:D2}", source.ToString(), slot);
  1822. return false;
  1823. }
  1824. if (!WaferManager.Instance.CheckWafer(dest, dslot, WaferStatus.Empty))
  1825. {
  1826. reason = string.Format("目标位置有wafer。{0}:{1:D2}", dest.ToString(), dslot);
  1827. return false;
  1828. }
  1829. return true;
  1830. }
  1831. private bool checkCycle(out string reason, params object[] args)
  1832. {
  1833. reason = string.Empty;
  1834. //bool isAutoMode = (bool)DATA.Poll(ModuleName.System.ToString(), ParamName.IsAutoMode);
  1835. //if (!isAutoMode)
  1836. //{
  1837. // reason = String.Format("can not cycle, isn't auto mode.");
  1838. // return false;
  1839. //}
  1840. if (!WaferManager.Instance.CheckWafer(ModuleName.Robot, 0, WaferStatus.Empty))
  1841. {
  1842. reason = string.Format("Upper arm has wafer");
  1843. return false;
  1844. }
  1845. if (!WaferManager.Instance.CheckWafer(ModuleName.Robot, 1, WaferStatus.Empty))
  1846. {
  1847. reason = string.Format("Lower arm has wafer");
  1848. return false;
  1849. }
  1850. if (DeviceModel.SensorRBupperArmhavewafer != null && !DeviceModel.SensorRBupperArmhavewafer.Value)
  1851. {
  1852. reason = string.Format("Upper arm has wafer");
  1853. return false;
  1854. }
  1855. if (DeviceModel.SensorRBlowerArmhavewafer != null && !DeviceModel.SensorRBlowerArmhavewafer.Value)
  1856. {
  1857. reason = string.Format("Lower arm has wafer");
  1858. return false;
  1859. }
  1860. return true;
  1861. }
  1862. private bool CheckEnableAuto()
  1863. {
  1864. string reason = string.Empty;
  1865. DeviceState state = (DeviceState)DATA.Poll(ModuleName.Robot.ToString(), ParamName.RobotState);
  1866. if (state != DeviceState.Idle)
  1867. {
  1868. EV.PostMessage("System", EventEnum.DefaultWarning, "can not change auto mode, Robot isn't ready.");
  1869. return false;
  1870. }
  1871. if (!Singleton<DeviceManager>.Instance.IsAnyLPIdle())
  1872. {
  1873. EV.PostMessage("System", EventEnum.DefaultWarning, "can not change auto mode, no loadport is ready.");
  1874. return false;
  1875. }
  1876. if (!WaferManager.Instance.CheckWafer(ModuleName.Robot, 0, WaferStatus.Empty))
  1877. {
  1878. EV.PostMessage("System", EventEnum.DefaultWarning, "Upper arm has wafer");
  1879. return false;
  1880. }
  1881. if (!WaferManager.Instance.CheckWafer(ModuleName.Robot, 1, WaferStatus.Empty))
  1882. {
  1883. EV.PostMessage("System", EventEnum.DefaultWarning, "Lower arm has wafer");
  1884. return false;
  1885. }
  1886. if (!SC.GetValue<bool>(SorterCommon.ScPathName.System_IsSimulatorMode))
  1887. {
  1888. if (!DeviceModel.SensorRBupperArmhavewafer.Value)
  1889. {
  1890. EV.PostMessage("System", EventEnum.DefaultWarning, "Upper arm has wafer");
  1891. return false;
  1892. }
  1893. if (!DeviceModel.SensorRBlowerArmhavewafer.Value)
  1894. {
  1895. EV.PostMessage("System", EventEnum.DefaultWarning, "Lower arm has wafer");
  1896. return false;
  1897. }
  1898. }
  1899. return true;
  1900. }
  1901. private bool checkMove(out string reason, params object[] args)
  1902. {
  1903. MoveType type = (MoveType)args[0];
  1904. MoveOption option = (MoveOption)args[1];
  1905. Hand blade = (Hand)args[2];
  1906. ModuleName schamber1 = (ModuleName)args[3];
  1907. int sslot1 = (int)args[4];
  1908. ModuleName dchamber1 = (ModuleName)args[5];
  1909. int dslot1 = (int)args[6];
  1910. ModuleName schamber2 = (ModuleName)args[3];
  1911. int sslot2 = (int)args[4];
  1912. ModuleName dchamber2 = (ModuleName)args[5];
  1913. int dslot2 = (int)args[6];
  1914. if (type != MoveType.Move)
  1915. {
  1916. schamber2 = (ModuleName)args[7];
  1917. sslot2 = (int)args[8];
  1918. dchamber2 = (ModuleName)args[9];
  1919. dslot2 = (int)args[10];
  1920. }
  1921. if (!check(type, blade, out reason))
  1922. {
  1923. EV.PostWarningLog("System", "Can not move wafer, " + reason);
  1924. return false;
  1925. }
  1926. if (!check(schamber1, sslot1, dchamber1, dslot1, blade, option, out reason))
  1927. {
  1928. EV.PostWarningLog("System", "Can not move wafer, " + reason);
  1929. return false;
  1930. }
  1931. if (type != MoveType.Move)
  1932. {
  1933. if (!check(schamber2, sslot2, dchamber2, dslot2, out reason))
  1934. {
  1935. EV.PostWarningLog("System", "Can not move wafer, " + reason);
  1936. return false;
  1937. }
  1938. }
  1939. return true;
  1940. }
  1941. private bool CheckMultiMove(out string reason, params object[] args)
  1942. {
  1943. MoveType type = (MoveType)args[0];
  1944. MoveOption option = (MoveOption)args[1];
  1945. Hand blade = (Hand)args[2];
  1946. ModuleName schamber1 = (ModuleName)args[3];
  1947. int sslot1 = (int)args[4];
  1948. ModuleName dchamber1 = (ModuleName)args[5];
  1949. int dslot1 = (int)args[6];
  1950. ModuleName schamber2 = (ModuleName)args[3];
  1951. int sslot2 = (int)args[4];
  1952. ModuleName dchamber2 = (ModuleName)args[5];
  1953. int dslot2 = (int)args[6];
  1954. if (type != MoveType.Move)
  1955. {
  1956. schamber2 = (ModuleName)args[7];
  1957. sslot2 = (int)args[8];
  1958. dchamber2 = (ModuleName)args[9];
  1959. dslot2 = (int)args[10];
  1960. }
  1961. if (!check(type, blade, out reason))
  1962. {
  1963. EV.PostWarningLog("System", "Can not move wafer, " + reason);
  1964. return false;
  1965. }
  1966. //检查双臂, *若该机器人类型为下手臂1上手臂2
  1967. if (!check(schamber1, sslot1, dchamber1, dslot1, Hand.Blade1, option, out reason))
  1968. {
  1969. EV.PostWarningLog("System", "Can not move wafer, " + reason);
  1970. return false;
  1971. }
  1972. if (!check(schamber1, sslot1 + 1, dchamber1, dslot1 + 1, Hand.Blade2, option, out reason))
  1973. {
  1974. EV.PostWarningLog("System", "Can not move wafer, " + reason);
  1975. return false;
  1976. }
  1977. if (type != MoveType.Move)
  1978. {
  1979. if (!check(schamber2, sslot2, dchamber2, dslot2, out reason))
  1980. {
  1981. EV.PostWarningLog("System", "Can not move wafer, " + reason);
  1982. return false;
  1983. }
  1984. }
  1985. return true;
  1986. }
  1987. private bool check(MoveType type, Hand blade, out string reason)
  1988. {
  1989. reason = string.Empty;
  1990. if (type != MoveType.Move && blade == Hand.Both)
  1991. {
  1992. reason = string.Format("非法的参数。单片传盘时,不能指定Both blade");
  1993. return false;
  1994. }
  1995. return true;
  1996. }
  1997. private bool checkFoup(ModuleName chamber, out string reason)
  1998. {
  1999. reason = string.Empty;
  2000. if (ModuleHelper.IsLoadPort(chamber))
  2001. {
  2002. LoadPortBaseDevice loadport = DEVICE.GetDevice<LoadPortBaseDevice>(chamber.ToString());
  2003. if (!loadport.IsEnableTransferWafer(out reason))
  2004. {
  2005. reason = string.Format("{0} isn't Ready, {1}", chamber.ToString(), reason);
  2006. return false;
  2007. }
  2008. return true;
  2009. }
  2010. //reason = string.Format("Not Foup, parameter {0} is not valid.", chamber.ToString());
  2011. return true;
  2012. }
  2013. public bool Check(int msg, out string reason, params object[] args)
  2014. {
  2015. if (!fsm.FindTransition(fsm.State, msg))
  2016. {
  2017. reason = String.Format("{0} is in {1} state,can not do {2}", Name, (RtState)fsm.State, (MSG)msg);
  2018. return false;
  2019. }
  2020. if (msg == (int)MSG.StartRecipe || msg == (int)MSG.StartCycle)
  2021. {
  2022. if (!IsAutoMode)
  2023. {
  2024. reason = String.Format("can not do {0}, isn't auto mode.", msg.ToString());
  2025. return false;
  2026. }
  2027. }
  2028. reason = "";
  2029. return true;
  2030. }
  2031. #endregion
  2032. #region Map Wafer
  2033. private bool FsmStartMapWafer(object[] param)
  2034. {
  2035. Running = false;
  2036. Result ret = _waferMapRoutine.Start(param);
  2037. if (ret == Result.DONE || (ret == Result.FAIL))
  2038. {
  2039. return false; //do noting
  2040. }
  2041. return true;
  2042. }
  2043. private bool FsmMonitorWaferMapping(object[] param)
  2044. {
  2045. Result ret = _waferMapRoutine.Monitor();
  2046. if (ret == Result.DONE)
  2047. {
  2048. return true;
  2049. }
  2050. else if (ret == Result.FAIL)
  2051. {
  2052. return true;
  2053. }
  2054. return false;
  2055. }
  2056. public void MapBuffer()
  2057. {
  2058. var sensors = new List<bool>
  2059. {
  2060. false,false,false,false,false,
  2061. //DeviceModel.SensorCoolingStageSLOT2WaferON.Value,
  2062. //DeviceModel.SensorCoolingStageSLOT3WaferON.Value,
  2063. //DeviceModel.SensorCoolingStageSLOT4WaferON.Value,
  2064. //DeviceModel.SensorCoolingStageSLOT5WaferON.Value,
  2065. //DeviceModel.SensorCoolingStageSLOT6WaferON.Value
  2066. };
  2067. var index = 0;
  2068. foreach (var sensor in sensors)
  2069. {
  2070. if (!sensor && WaferManager.Instance.CheckNoWafer(ModuleName.Buffer, index))
  2071. {
  2072. WaferManager.Instance.CreateWafer(ModuleName.Buffer, index, WaferStatus.Normal);
  2073. }
  2074. else if (sensor && WaferManager.Instance.CheckHasWafer(ModuleName.Buffer, index))
  2075. {
  2076. WaferManager.Instance.DeleteWafer(ModuleName.Buffer, index);
  2077. }
  2078. index++;
  2079. }
  2080. var robotSensors = new List<bool>
  2081. {
  2082. DeviceModel.SensorRBlowerArmhavewafer.Value,
  2083. DeviceModel.SensorRBupperArmhavewafer.Value
  2084. };
  2085. index = 0;
  2086. foreach (var sensor in robotSensors)
  2087. {
  2088. if (!sensor && WaferManager.Instance.CheckNoWafer(ModuleName.Robot, index))
  2089. {
  2090. WaferManager.Instance.CreateWafer(ModuleName.Robot, index, WaferStatus.Normal);
  2091. }
  2092. else if (sensor && WaferManager.Instance.CheckHasWafer(ModuleName.Robot, index))
  2093. {
  2094. WaferManager.Instance.DeleteWafer(ModuleName.Robot, index);
  2095. }
  2096. index++;
  2097. }
  2098. }
  2099. public int Invoke(string function, params object[] args)
  2100. {
  2101. switch (function)
  2102. {
  2103. case "Place":
  2104. CheckToPostMsg(MSG.Place, args[0], args[1], args[2]);
  2105. return (int)MSG.Place;
  2106. case "Pick":
  2107. CheckToPostMsg(MSG.Pick, args[0], args[1], args[2]);
  2108. return (int)MSG.Pick;
  2109. case "MPNTPick":
  2110. CheckToPostMsg(MSG.MPNTPick, args[0], args[1], args[2], args[3]);
  2111. return (int)MSG.MPNTPick;
  2112. case "MPNTPlace":
  2113. CheckToPostMsg(MSG.MPNTPlace, args[0], args[1], args[2], args[3]);
  2114. return (int)MSG.MPNTPlace;
  2115. case "Reset":
  2116. CheckToPostMsg(MSG.RESET );
  2117. return (int)MSG.RESET;
  2118. }
  2119. return (int)FSM_MSG.NONE;
  2120. }
  2121. public bool CheckAcked(int msg)
  2122. {
  2123. return fsm.CheckExecuted(msg);
  2124. }
  2125. #endregion
  2126. }
  2127. }