RouteManager.cs 92 KB

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