RouteManager.cs 94 KB

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