RouteManager.cs 92 KB

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