RouteManager.cs 88 KB

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