AutoTransfer.cs 219 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Timers;
  7. using Aitex.Core.Common;
  8. using Aitex.Core.RT.DataCenter;
  9. using Aitex.Core.RT.Device;
  10. using Aitex.Core.RT.Event;
  11. using Aitex.Core.RT.Log;
  12. using Aitex.Core.RT.OperationCenter;
  13. using Aitex.Core.RT.RecipeCenter;
  14. using Aitex.Core.RT.Routine;
  15. using Aitex.Core.RT.SCCore;
  16. using Aitex.Core.Util;
  17. using Aitex.Sorter.Common;
  18. using MECF.Framework.Common.DBCore;
  19. using MECF.Framework.Common.Equipment;
  20. using MECF.Framework.Common.Jobs;
  21. using MECF.Framework.Common.Schedulers;
  22. using MECF.Framework.Common.SubstrateTrackings;
  23. using MECF.Framework.RT.ModuleLibrary.PMModules;
  24. using MECF.Framework.RT.ModuleLibrary.SystemModules;
  25. using MECF.Framework.RT.ModuleLibrary.SystemModules.Routines;
  26. using EfemDualSchedulerLib.Schedulers;
  27. using MECF.Framework.Common.DataCenter;
  28. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadLocks;
  29. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  30. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.PMs;
  31. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots;
  32. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TMs;
  33. using JetVirgoPM.PMs.RecipeExecutors;
  34. namespace EfemDualSchedulerLib
  35. {
  36. /// <summary>
  37. /// 自动传输
  38. /// </summary>
  39. public partial class AutoTransfer : SchedulerModuleFactory, IAutoTransfer
  40. {
  41. //const Hand Hand_Dual = Hand.Blade1;
  42. //const Hand Hand_Single = Hand.Blade2;
  43. //用于避免两爪都有wafer,放了一片就又去LoadPort Pick
  44. private bool EfemRobotPickAllowable = true;
  45. private bool _isRunningInParallelMode;
  46. private List<ModuleName> _mapTarget = new List<ModuleName>();
  47. private List<ControlJobInfo> _lstControlJobs = new List<ControlJobInfo>();
  48. private List<ProcessJobInfo> _lstProcessJobs = new List<ProcessJobInfo>();
  49. //private Object _locker = new Object();
  50. private List<SchedulerPM> _lstPms = new List<SchedulerPM>();
  51. private List<SchedulerLoadPort> _lstLps = new List<SchedulerLoadPort>();
  52. private List<SchedulerLoadLock> _lstLls = new List<SchedulerLoadLock>();
  53. private List<SchedulerBuffer> _lstBuffers = new List<SchedulerBuffer>();
  54. private List<SchedulerPM> _lstPmsCurrentSequence = new List<SchedulerPM>();
  55. private R_TRIG _trigLp1JobComplete = new R_TRIG();
  56. private R_TRIG _trigLp2JobComplete = new R_TRIG();
  57. private R_TRIG _trigLp3JobComplete = new R_TRIG();
  58. private Dictionary<string, float> _temperatureSetpointDic = new Dictionary<string, float>();
  59. private Dictionary<string, R_TRIG> _temperatureTrigDic = new Dictionary<string, R_TRIG>();
  60. private Dictionary<string, List<string>> currentSlotSequenceList = new Dictionary<string, List<string>>()
  61. {
  62. {"LP1",Enumerable.Repeat("",25).ToList()},
  63. {"LP2",Enumerable.Repeat("",25).ToList()},
  64. {"LP3",Enumerable.Repeat("",25).ToList()}
  65. };
  66. private const string LogSource = "Scheduler";
  67. public string LPHadCreateJob { get; set; }
  68. //private bool _isCycleMode;
  69. //private int _cycleSetPoint = 0;
  70. //private int _cycledCount = 0;
  71. //private int _cycledWafer = 0;
  72. private SchedulerFACallback _faCallback;
  73. private SchedulerDBCallback _dbCallback;
  74. //private float _throughput;
  75. //private DeviceTimer _throughputTimer = new DeviceTimer();
  76. //private int _processedWaferCountInFinishedCJ;
  77. class CycleData
  78. {
  79. public DateTime StartTime { get; private set; }
  80. public TimeSpan EscapeTime => StartTime == DateTime.MinValue ? TimeSpan.Zero : DateTime.Now.Subtract(StartTime);
  81. public bool IsCycleMode => SC.GetValue<bool>("System.IsCycleMode");
  82. public string CycleBy => SC.GetStringValue("System.CycleBy");
  83. public int CycleCountSetPoint => SC.GetValue<int>("System.CycleCount");// 设置的循环次数
  84. public int CycledCount { get; private set; } // 已处理的循环次数
  85. public int CycleWaferCountSetPoint => SC.GetValue<int>("System.CycleWaferCount");// 设置的晶圆片数
  86. public int CycledWaferCount { get; private set; } // 已处理的晶圆片数
  87. public void Start()
  88. {
  89. LOG.Info("Cycle: Start cycle data");
  90. StartTime = DateTime.Now;
  91. }
  92. public void Reset()
  93. {
  94. LOG.Info("Cycle: Reset cycle data");
  95. CycledWaferCount = 0;
  96. CycledCount = 0;
  97. }
  98. //public void BeginOrAddCycle(int setpoint)
  99. //{
  100. // if (IsCycleMode) // add
  101. // {
  102. // CycleWaferCountSetPoint += setpoint;
  103. // LOG.Info($"Cycle: Add {setpoint} wafers, total cycle count = {CycleWaferCountSetPoint}");
  104. // }
  105. // else // begin
  106. // {
  107. // IsCycleMode = true;
  108. // StartTime = DateTime.Now;
  109. // CycleWaferCountSetPoint = setpoint;
  110. // CycledWaferCount = 0;
  111. // LOG.Info($"Cycle: Begin {setpoint} wafers");
  112. // }
  113. //}
  114. public bool IsCycleEnd()
  115. {
  116. if (!IsCycleMode)
  117. return true;
  118. if (CycleBy == "WaferCount" && CycledWaferCount >= CycleWaferCountSetPoint)
  119. {
  120. SC.SetItemValue("System.IsCycleMode", false);
  121. Reset();
  122. return true;
  123. }
  124. else if (CycleBy == "LotCount" && CycledCount >= CycleCountSetPoint)
  125. {
  126. SC.SetItemValue("System.IsCycleMode", false);
  127. Reset();
  128. return true;
  129. }
  130. return false;
  131. }
  132. public void Increase(int waferCount, int count = 1)
  133. {
  134. IncreaseWaferCount(waferCount);
  135. IncreaseCount(count);
  136. }
  137. public void IncreaseWaferCount(int waferCount)
  138. {
  139. CycledWaferCount += waferCount;
  140. LOG.Info($"Cycle: finished {CycledWaferCount} wafer(s)");
  141. }
  142. public void IncreaseCount(int count = 1)
  143. {
  144. CycledCount += count;
  145. LOG.Info($"Cycle: finished {CycledCount} Count(s)");
  146. }
  147. }
  148. class ThroughputData
  149. {
  150. public bool IsCalcing { get; private set; } = false;
  151. public DateTime CacledLastTime { get; private set; } = DateTime.MinValue; // 创建时间或者计算时间
  152. public double CalcedTotalTimeSeconds { get; private set; } = 0; // 总的计算时间
  153. public int CalcedProcessedCount { get; private set; } = 0; // 已计算完的总数(control job)
  154. public double TotalTimeSeconds { get; private set; }
  155. public DateTime CaclingLastTime { get; private set; } = DateTime.MinValue; // 创建时间或者计算时间
  156. public int CalcingProcessedCount { get; private set; } = 0;// 正在计算的总数(control job)
  157. public int ProcessedCount => CalcedProcessedCount + CalcingProcessedCount;
  158. public double Throughput { get; private set; }
  159. public double LiveThroughput { get; private set; }
  160. public void BeginCalc()
  161. {
  162. if (IsCalcing) return;
  163. IsCalcing = true;
  164. CalcedTotalTimeSeconds = 0;
  165. CacledLastTime = DateTime.Now;
  166. CaclingLastTime = DateTime.Now;
  167. LOG.Info("Throughput: Begin");
  168. }
  169. public void Pause()
  170. {
  171. if (!IsCalcing)
  172. {
  173. IsCalcing = false;
  174. LOG.Info("Throughput: Pause");
  175. }
  176. }
  177. public void Reset()
  178. {
  179. CacledLastTime = DateTime.Now;
  180. CalcedTotalTimeSeconds = 0;
  181. CalcedProcessedCount = 0;
  182. CaclingLastTime = DateTime.Now;
  183. CalcedProcessedCount = 0;
  184. CalcingProcessedCount = 0;
  185. Throughput = 0;
  186. LiveThroughput = 0;
  187. LOG.Info("Throughput: Reset");
  188. }
  189. public void UpdateCalced(int calcedCount)
  190. {
  191. CalcedProcessedCount += calcedCount;
  192. CalcingProcessedCount -= calcedCount;
  193. if (CalcingProcessedCount < 0) CalcingProcessedCount = 0;
  194. CalcedTotalTimeSeconds += DateTime.Now.Subtract(CacledLastTime).TotalSeconds;
  195. CacledLastTime = DateTime.Now;
  196. }
  197. public void UpdateCalcing(int calcingCount)
  198. {
  199. DateTime now = DateTime.Now;
  200. double seconds_this = now.Subtract(CaclingLastTime).TotalSeconds;
  201. int calcingCount_this = calcingCount - CalcingProcessedCount;
  202. double count_this = ProcessedCount + calcingCount;
  203. LiveThroughput = 3600 / (seconds_this / calcingCount_this);
  204. TotalTimeSeconds = CalcedTotalTimeSeconds + seconds_this;
  205. Throughput = 3600 * count_this / TotalTimeSeconds;
  206. LOG.Info($"Throughput: {Throughput}, Finished {count_this} wafer(s) in {(int)TotalTimeSeconds} seconds;" +
  207. $" {LiveThroughput} last wafer in {(int)seconds_this} seconds");
  208. CaclingLastTime = now;
  209. CalcingProcessedCount = calcingCount;
  210. }
  211. }
  212. private CycleData _CycleData = new CycleData();
  213. private ThroughputData _throughputData = new ThroughputData();
  214. private bool _isAutoUnloadFoup
  215. {
  216. get
  217. {
  218. return SC.GetValue<bool>("EFEM.LoadPort.EnableAutoUnloadFoup");
  219. }
  220. }
  221. private ModuleName _TMRobotBlade1Station = ModuleName.System;
  222. private Dictionary<ModuleName, bool> _loadlockCooling = new Dictionary<ModuleName, bool>();
  223. Queue<Action> tmRobotActions = new Queue<Action>() { };
  224. Queue<Action> efemRobotActions = new Queue<Action>() { };
  225. public AutoTransfer(EquipmentManager equipment)
  226. {
  227. _faCallback = new SchedulerFACallback();
  228. _dbCallback = new SchedulerDBCallback();
  229. if (SC.GetValueOrDefault<bool>("System.SetUp.PMA.IsInstalled"))
  230. _lstPms.Add(_pm1);
  231. if (SC.GetValueOrDefault<bool>("System.SetUp.PMB.IsInstalled"))
  232. _lstPms.Add(_pm2);
  233. //if (SC.GetValueOrDefault<bool>("System.SetUp.PMC.IsInstalled"))
  234. // _lstPms.Add(_pm3);
  235. if (SC.GetValueOrDefault<bool>("System.SetUp.LLA.IsInstalled"))
  236. _lstLls.Add(_loadlockA);
  237. if (SC.GetValueOrDefault<bool>("System.SetUp.LLB.IsInstalled"))
  238. _lstLls.Add(_loadlockB);
  239. if (SC.GetValueOrDefault<bool>("System.SetUp.LP1.IsInstalled"))
  240. _lstLps.Add(_lp1);
  241. if (SC.GetValueOrDefault<bool>("System.SetUp.LP2.IsInstalled"))
  242. _lstLps.Add(_lp2);
  243. if (SC.GetValueOrDefault<bool>("System.SetUp.LP3.IsInstalled"))
  244. _lstLps.Add(_lp3);
  245. //临时办法,设备异常后进行reset,重新home后reset机械手task
  246. OP.Subscribe($"{ModuleName.TM}.ResetTask", (string cmd, object[] args) =>
  247. {
  248. _tmRobot.ResetTask();
  249. return true;
  250. });
  251. OP.Subscribe($"{ModuleName.EFEM}.ResetTask", (string cmd, object[] args) =>
  252. {
  253. _efem.ResetTask();
  254. return true;
  255. });
  256. DATA.Subscribe("Scheduler.IsCycleMode", () => _CycleData.IsCycleMode);
  257. DATA.Subscribe("Scheduler.CycleBy", () => _CycleData.CycleBy);
  258. DATA.Subscribe("Scheduler.CycleCountSetPoint", () => _CycleData.CycleCountSetPoint);
  259. DATA.Subscribe("Scheduler.CycledCount", () => _CycleData.CycledCount);
  260. DATA.Subscribe("Scheduler.CycleWaferCountSetPoint", () => _CycleData.CycleWaferCountSetPoint);
  261. DATA.Subscribe("Scheduler.CycledWaferCount", () => _CycleData.CycledWaferCount);
  262. DATA.Subscribe("Scheduler.CycleEscapeTime", () => _CycleData.EscapeTime);
  263. DATA.Subscribe("Scheduler.Throughput", () => _throughputData.Throughput);
  264. DATA.Subscribe("Scheduler.LiveThroughput", () => _throughputData.LiveThroughput);
  265. DATA.Subscribe("System.Scheduler.RunningRecipeList", () => _GetRunningRecipeList());
  266. DATA.Subscribe("Scheduler.CjIdList", () => _GetRunningCjIdList());
  267. DATA.Subscribe("LP1.LocalJobName", () =>
  268. {
  269. var jb = _lstControlJobs.Find(x => x.Module == "LP1");
  270. if (jb != null)
  271. return jb.Name;
  272. return "";
  273. });
  274. DATA.Subscribe($"LP1.JobLotName", () =>
  275. {
  276. var cj = _lstControlJobs.FirstOrDefault(x => x.Module == "LP1");
  277. if (cj != null)
  278. return cj.LotName;
  279. return "";
  280. });
  281. DATA.Subscribe("LP1.LocalJobStatus", () =>
  282. {
  283. var jb = _lstControlJobs.Find(x => x.Module == "LP1");
  284. if (jb != null)
  285. return jb.State.ToString();
  286. return "";
  287. });
  288. DATA.Subscribe("LP1.CurrentRecipeList", () =>
  289. {
  290. List<string> result = Enumerable.Repeat("", 25).ToList();
  291. for (int i = 0; i < _lstProcessJobs.Count; i++)
  292. {
  293. foreach (var wafers in _lstProcessJobs[i].SlotWafers)
  294. {
  295. if (wafers.Item1 == ModuleName.LP1)
  296. {
  297. result[wafers.Item2] = _lstProcessJobs[i].Sequence.Name;
  298. }
  299. }
  300. }
  301. return result;
  302. });
  303. DATA.Subscribe("LP2.LocalJobName", () =>
  304. {
  305. var jb = _lstControlJobs.Find(x => x.Module == "LP2");
  306. if (jb != null)
  307. return jb.Name;
  308. return "";
  309. });
  310. DATA.Subscribe($"LP2.JobLotName", () =>
  311. {
  312. var cj = _lstControlJobs.FirstOrDefault(x => x.Module == "LP2");
  313. if (cj != null)
  314. return cj.LotName;
  315. return "";
  316. });
  317. DATA.Subscribe("LP2.LocalJobStatus", () =>
  318. {
  319. var jb = _lstControlJobs.Find(x => x.Module == "LP2");
  320. if (jb != null)
  321. return jb.State.ToString();
  322. return "";
  323. });
  324. DATA.Subscribe("LP2.CurrentRecipeList", () =>
  325. {
  326. List<string> result = Enumerable.Repeat("", 25).ToList();
  327. for (int i = 0; i < _lstProcessJobs.Count; i++)
  328. {
  329. foreach (var wafers in _lstProcessJobs[i].SlotWafers)
  330. {
  331. if (wafers.Item1 == ModuleName.LP2)
  332. {
  333. result[wafers.Item2] = _lstProcessJobs[i].Sequence.Name;
  334. }
  335. }
  336. }
  337. return result;
  338. });
  339. DATA.Subscribe("LP3.LocalJobName", () =>
  340. {
  341. var jb = _lstControlJobs.Find(x => x.Module == "LP3");
  342. if (jb != null)
  343. return jb.Name;
  344. return "";
  345. });
  346. DATA.Subscribe($"LP3.JobLotName", () =>
  347. {
  348. var cj = _lstControlJobs.FirstOrDefault(x => x.Module == "LP3");
  349. if (cj != null)
  350. return cj.LotName;
  351. return "";
  352. });
  353. DATA.Subscribe("LP3.LocalJobStatus", () =>
  354. {
  355. var jb = _lstControlJobs.Find(x => x.Module == "LP3");
  356. if (jb != null)
  357. return jb.State.ToString();
  358. return "";
  359. });
  360. DATA.Subscribe("LP3.CurrentRecipeList", () =>
  361. {
  362. List<string> result = Enumerable.Repeat("", 25).ToList();
  363. for (int i = 0; i < _lstProcessJobs.Count; i++)
  364. {
  365. foreach (var wafers in _lstProcessJobs[i].SlotWafers)
  366. {
  367. if (wafers.Item1 == ModuleName.LP3)
  368. {
  369. result[wafers.Item2] = _lstProcessJobs[i].Sequence.Name;
  370. }
  371. }
  372. }
  373. return result;
  374. });
  375. tmRobotActions.Enqueue(MonitorTmRobotLoadLockPickTask);
  376. tmRobotActions.Enqueue(MonitorTmRobotPMAPlaceTask);
  377. tmRobotActions.Enqueue(MonitorTmRobotPMBPlaceTask);
  378. tmRobotActions.Enqueue(MonitorTmRobotPMAPickTask);
  379. tmRobotActions.Enqueue(MonitorTmRobotPMBPickTask);
  380. tmRobotActions.Enqueue(MonitorTmRobotLoadLockPlaceTask);
  381. tmRobotActions.Enqueue(MonitorTmRobotGoToTask);
  382. efemRobotActions.Enqueue(MonitorEfemRobotAlignerPickTask);
  383. efemRobotActions.Enqueue(MonitorEfemRobotAlignerPlaceTask);
  384. efemRobotActions.Enqueue(MonitorEfemRobotLoadLockPlaceTask);
  385. efemRobotActions.Enqueue(MonitorEfemRobotLoadLockPickTask);
  386. efemRobotActions.Enqueue(MonitorEfemRobotLoadPortPickTask);
  387. efemRobotActions.Enqueue(MonitorEfemRobotLoadPortPlaceTask);
  388. }
  389. private List<string> _GetRunningCjIdList()
  390. {
  391. return _lstControlJobs/*.Where(o => o.State == EnumControlJobState.Executing
  392. || o.State == EnumControlJobState.Paused)*/.Select(o => o.InnerId.ToString()).ToList();
  393. }
  394. const string StrProcessRecipe = "ProcessRecipe";
  395. const string StrRecipe = "Recipe";
  396. private List<string> _GetRunningRecipeList()
  397. {
  398. var runningCjList = _lstControlJobs.Where(o => o.State == EnumControlJobState.Executing
  399. || o.State == EnumControlJobState.Paused).Select(o => o.Name).ToList();
  400. return _lstProcessJobs.Where(o => runningCjList.Contains(o.ControlJobName))
  401. .SelectMany(a => a.Sequence.Steps.SelectMany(b => b.StepParameter.Where(c => c.Key == StrProcessRecipe || c.Key == StrRecipe))).Select(d => d.Value as string)
  402. .Where(o => !string.IsNullOrWhiteSpace(o)).ToList();
  403. }
  404. public bool HasJobRunning
  405. {
  406. get { return _lstControlJobs.Count > 0; }
  407. }
  408. public void Clear()
  409. {
  410. _tmRobot.ResetTask();
  411. _efem.ResetTask();
  412. foreach (var pm in _lstPms)
  413. {
  414. pm.ResetTask();
  415. }
  416. //foreach (var lp in _lstLps)
  417. //{
  418. // lp.ResetTask();
  419. //}
  420. _lstControlJobs.Clear();
  421. _lstProcessJobs.Clear();
  422. _temperatureSetpointDic.Clear();
  423. _temperatureTrigDic.Clear();
  424. _CycleData.Reset();
  425. }
  426. #region Job Management
  427. public bool CreateJob(Dictionary<string, object> param)
  428. {
  429. string reason;
  430. string[] slotSequence = (string[])param["SlotSequence"];
  431. string jobId = (string)param["JobId"];
  432. string module = (string)param["Module"];
  433. LPHadCreateJob = (string)param["Module"];
  434. bool autoStart = (bool)param["AutoStart"];
  435. string lotId = jobId;
  436. if (param.ContainsKey("LotId"))
  437. lotId = (string)param["LotId"];
  438. if (!ValidateSequence(slotSequence, out reason))
  439. {
  440. EV.PostWarningLog(LogSource, $"{reason}");
  441. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  442. return false;
  443. }
  444. if (slotSequence.Length != 25)
  445. {
  446. reason = $"slot sequence parameter not valid, length is {slotSequence.Length}, should be 25";
  447. EV.PostWarningLog(LogSource, reason);
  448. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  449. return false;
  450. }
  451. if (!ModuleHelper.IsLoadPort(ModuleHelper.Converter(module)))
  452. {
  453. reason = $"{module} should be LP";
  454. EV.PostWarningLog(LogSource, reason);
  455. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  456. return false;
  457. }
  458. if (string.IsNullOrEmpty(jobId))
  459. {
  460. jobId = "CJ_Local_" + module;
  461. }
  462. if (_lstControlJobs.Exists(x => x.Name == jobId))
  463. {
  464. reason = $"LotID : {jobId} already created";
  465. EV.PostWarningLog(LogSource, reason);
  466. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  467. return false;
  468. }
  469. SchedulerLoadPort lp = GetModule(module) as SchedulerLoadPort;
  470. if (!lp.CheckReadyRunJob())
  471. {
  472. reason = $"{module} not ready";
  473. EV.PostWarningLog(LogSource, reason);
  474. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  475. return false;
  476. }
  477. ControlJobInfo cj = new ControlJobInfo();
  478. cj.Name = jobId;
  479. cj.Module = module;
  480. cj.LotName = jobId;
  481. cj.LotInnerId = Guid.NewGuid();
  482. cj.LotWafers = new List<WaferInfo>();
  483. cj.SetState(EnumControlJobState.WaitingForStart);
  484. Dictionary<string, bool[]> seqSlot = new Dictionary<string, bool[]>();
  485. Dictionary<string, List<Tuple<ModuleName, int>>> seqSlotWafers = new Dictionary<string, List<Tuple<ModuleName, int>>>();
  486. Dictionary<string, string> indexSequence = new Dictionary<string, string>();
  487. bool enableGroupBySequence = SC.GetValue<bool>("System.Scheduler.GroupWaferBySequence");
  488. string WaferAssociationInfo = $"WaferAssociationInfo({module}):";
  489. for (int i = 0; i < 25; i++)
  490. {
  491. WaferAssociationInfo = WaferAssociationInfo + string.Format(" slot{0} -- {1};", i + 1, slotSequence[i]);
  492. if (string.IsNullOrEmpty(slotSequence[i]) || string.IsNullOrEmpty(slotSequence[i].Trim()))
  493. continue;
  494. string groupName = enableGroupBySequence ? slotSequence[i].Trim() : i.ToString();
  495. indexSequence[groupName] = slotSequence[i];
  496. if (!seqSlot.ContainsKey(groupName))
  497. {
  498. seqSlot[groupName] = new bool[25];
  499. }
  500. if (!seqSlotWafers.ContainsKey(groupName))
  501. {
  502. seqSlotWafers[groupName] = new List<Tuple<ModuleName, int>>();
  503. }
  504. seqSlot[groupName][i] = true;
  505. if (!WaferManager.Instance.CheckHasWafer(module, i))
  506. {
  507. reason = $"job wafer: {module} slot {i + 1} not in the carrier";
  508. EV.PostWarningLog(LogSource, reason);
  509. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  510. return false;
  511. }
  512. if (!WaferManager.Instance.CheckWafer(ModuleHelper.Converter(module), i, WaferStatus.Normal))
  513. {
  514. reason = $"job wafer: {module} slot {i + 1} status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Status}";
  515. EV.PostWarningLog(LogSource, reason);
  516. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  517. return false;
  518. }
  519. var wafer = WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i);
  520. if (wafer == null || wafer.IsEmpty)
  521. {
  522. reason = $"specifies wafer: {module} slot {i + 1} not in the carrier";
  523. EV.PostWarningLog(LogSource, reason);
  524. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  525. return false;
  526. }
  527. if (!ModuleHelper.IsLoadPort(ModuleHelper.Converter(wafer.WaferOrigin.Split('.')[0])))
  528. {
  529. reason = $"specifies wafer: {module} slot {i + 1} not origin LP";
  530. EV.PostWarningLog(LogSource, reason);
  531. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  532. return false;
  533. }
  534. if (wafer.ProcessState != EnumWaferProcessStatus.Idle)
  535. {
  536. reason = $"specifies wafer: {module} slot {i + 1} process state is not idle";
  537. EV.PostWarningLog(LogSource, reason);
  538. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  539. return false;
  540. }
  541. seqSlotWafers[groupName].Add(Tuple.Create(ModuleHelper.Converter(module), i));
  542. cj.LotWafers.Add(WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i));
  543. WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).PPID = slotSequence[i];
  544. }
  545. currentSlotSequenceList[module] = slotSequence.Reverse().ToList();
  546. EV.PostInfoLog(LogSource, WaferAssociationInfo);
  547. if (seqSlotWafers.Count == 0)
  548. {
  549. reason = $"Can not create job, no wafer assigned";
  550. EV.PostWarningLog(LogSource, reason);
  551. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  552. return false;
  553. }
  554. List<ProcessJobInfo> pjs = new List<ProcessJobInfo>();
  555. string[] seqs = seqSlot.Keys.ToArray();
  556. for (int i = 0; i < seqs.Length; i++)
  557. {
  558. ProcessJobInfo pj = new ProcessJobInfo();
  559. pj.Name = jobId + "_" + (i + 1);
  560. pj.Sequence = SequenceInfoHelper.GetInfo(indexSequence[seqs[i]]);
  561. pj.ControlJobName = cj.Name;
  562. pj.LotName = lotId;
  563. pj.SlotWafers = seqSlotWafers[seqs[i]];
  564. pj.SetState(EnumProcessJobState.Queued);
  565. if (!CheckSequencePmReady(pj.Sequence, null, out _, out string innerReason))
  566. {
  567. reason = $"no valid chamber for the {innerReason}";
  568. EV.PostWarningLog(LogSource, reason);
  569. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  570. return false;
  571. }
  572. if (!CheckSequenceRecipeFileValid(pj.Sequence, out reason))
  573. {
  574. reason = $"recipe file not valid in the sequence, {reason}";
  575. EV.PostWarningLog(LogSource, reason);
  576. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  577. return false;
  578. }
  579. if (!CheckSequenceOrderOk(pj.Sequence, out reason))
  580. {
  581. reason = $"sequence path not valid, {reason}";
  582. EV.PostWarningLog(LogSource, reason);
  583. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  584. return false;
  585. }
  586. if (CheckSequenceNeedDummyWafer(pj.Sequence))
  587. {
  588. reason = $"create job failed, no valid dummy wafer exist";
  589. EV.PostWarningLog(LogSource, reason);
  590. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  591. return false;
  592. }
  593. pjs.Add(pj);
  594. }
  595. foreach (var pj in pjs)
  596. {
  597. cj.ProcessJobNameList.Add(pj.Name);
  598. _lstProcessJobs.Add(pj);
  599. }
  600. _lstControlJobs.Add(cj);
  601. int totalWafer = 0;
  602. foreach (var pj in pjs)
  603. {
  604. foreach (var pjSlotWafer in pj.SlotWafers)
  605. {
  606. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  607. wafer.ProcessJob = pj;
  608. WaferDataRecorder.SetCjInfo(wafer.InnerId.ToString(), cj.InnerId.ToString());
  609. WaferDataRecorder.SetWaferSequence(wafer.InnerId.ToString(), pj.Sequence.Name);
  610. WaferDataRecorder.SetWaferLotId(wafer.InnerId.ToString(), jobId);
  611. WaferManager.Instance.UpdateWaferLotId(pjSlotWafer.Item1, pjSlotWafer.Item2, jobId);
  612. totalWafer++;
  613. }
  614. }
  615. _faCallback.JobCreated(cj, GetFirstProcessJob(cj));
  616. if (_CycleData.IsCycleMode)
  617. {
  618. _CycleData.Start();
  619. }
  620. CarrierInfo carrier = CarrierManager.Instance.GetCarrier(cj.Module);
  621. JobDataRecorder.StartCJ(cj.InnerId.ToString(), carrier.InnerId.ToString(), cj.Name, cj.Module, cj.Module, totalWafer);
  622. return true;
  623. }
  624. public bool CreateControlJob(string jobId, string module, List<string> pjIDs, bool isAutoStart)
  625. {
  626. if (_lstControlJobs.Exists(x => x.Name == jobId))
  627. {
  628. EV.PostWarningLog(LogSource, $"{jobId} is already created");
  629. return false;
  630. }
  631. if (!ModuleHelper.IsLoadPort(ModuleHelper.Converter(module)))
  632. {
  633. EV.PostWarningLog(LogSource, $"{module} should be LoadPort");
  634. return false;
  635. }
  636. LoadPort lp = DEVICE.GetDevice<LoadPort>($"{module}");
  637. if (!lp.IsIdle)
  638. {
  639. EV.PostWarningLog(LogSource, $"{module} is not idle");
  640. return false;
  641. }
  642. if (!lp.IsMapped)
  643. {
  644. EV.PostWarningLog(LogSource, $"{module} is not mapped");
  645. return false;
  646. }
  647. if (!lp.IsPresent)
  648. {
  649. EV.PostWarningLog(LogSource, $"{module} is not present");
  650. return false;
  651. }
  652. foreach (var _lp in _lstLps)
  653. {
  654. if (_lp.Module.ToString() == module)
  655. {
  656. if (!_lp.IsOnline)
  657. {
  658. EV.PostWarningLog(LogSource, $"{module} is not online");
  659. return false;
  660. }
  661. if (_lp.IsError)
  662. {
  663. EV.PostWarningLog(LogSource, $"{module} is error");
  664. return false;
  665. }
  666. }
  667. }
  668. if (_lstProcessJobs.Count <= 0) //判断上一步ProcessJob是否创建成功
  669. {
  670. EV.PostWarningLog(LogSource, $"process job is not exist");
  671. return false;
  672. }
  673. ControlJobInfo cj = new ControlJobInfo();
  674. cj.Name = jobId;
  675. cj.Module = module;
  676. cj.SetState(EnumControlJobState.WaitingForStart);
  677. cj.LotName = jobId;
  678. cj.LotWafers = new List<WaferInfo>();
  679. int totalWafer = 0;
  680. foreach (var pjName in pjIDs)
  681. {
  682. var pj = _lstProcessJobs.FirstOrDefault(x => x.Name == pjName);
  683. if (pj == null)
  684. {
  685. LOG.Info($"not find {pjName} while create control job");
  686. continue;
  687. }
  688. var slotWafers = new List<Tuple<ModuleName, int>>();
  689. foreach (var slotWafer in pj.SlotWafers)
  690. {
  691. if (!WaferManager.Instance.CheckHasWafer(module, slotWafer.Item2))
  692. {
  693. EV.PostWarningLog(LogSource, $"job wafer: {module} slot {slotWafer.Item2 + 1} not in the carrier");
  694. return false;
  695. }
  696. if (!WaferManager.Instance.CheckWafer(ModuleHelper.Converter(module), slotWafer.Item2, WaferStatus.Normal))
  697. {
  698. EV.PostWarningLog(LogSource, $"job wafer: {module} slot {slotWafer.Item2 + 1} status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), slotWafer.Item2).Status}");
  699. return false;
  700. }
  701. if (WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), slotWafer.Item2).ProcessState != EnumWaferProcessStatus.Idle)
  702. {
  703. EV.PostWarningLog(LogSource, $"job wafer: {module} slot {slotWafer.Item2 + 1} process status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), slotWafer.Item2).ProcessState}");
  704. return false;
  705. }
  706. slotWafers.Add(Tuple.Create(ModuleHelper.Converter(module), slotWafer.Item2));
  707. totalWafer++;
  708. }
  709. pj.ControlJobName = jobId;
  710. cj.ProcessJobNameList.Add(pj.Name);
  711. pj.SlotWafers = slotWafers;
  712. foreach (var pjSlotWafer in pj.SlotWafers)
  713. {
  714. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  715. cj.LotWafers.Add(wafer);
  716. WaferDataRecorder.SetCjInfo(wafer.InnerId.ToString(), cj.InnerId.ToString());
  717. WaferDataRecorder.SetWaferSequence(wafer.InnerId.ToString(), pj.Sequence.Name);
  718. //WaferDataRecorder.SetWaferLotId(wafer.InnerId.ToString(), jobId);
  719. }
  720. }
  721. _lstControlJobs.Add(cj);
  722. CarrierInfo carrier = CarrierManager.Instance.GetCarrier(cj.Module);
  723. JobDataRecorder.StartCJ(cj.InnerId.ToString(), carrier.InnerId.ToString(), cj.Name, cj.Module, cj.Module, totalWafer);
  724. return true;
  725. }
  726. public bool CreateProcessJob(string jobId, string sequenceName, List<int> slotNumbers, bool isAutoStart)
  727. {
  728. var sequenceInfo = SequenceInfoHelper.GetInfo(sequenceName);
  729. #region 模块检查
  730. if (!CheckSequenceAlignerReady(sequenceInfo, out string reason))
  731. {
  732. EV.PostWarningLog(LogSource, $"Aligner is not ready for the {reason}");
  733. return false;
  734. }
  735. if (!CheckSequencePMReady(sequenceInfo, out reason))
  736. {
  737. EV.PostWarningLog(LogSource, $"PM is not ready for the {reason}");
  738. return false;
  739. }
  740. #endregion
  741. #region Sequence检查
  742. if (!CheckSequenceAlignerOrder(sequenceInfo, out reason))
  743. {
  744. EV.PostWarningLog(LogSource, $"Aligner order is not valid for the {reason}");
  745. return false;
  746. }
  747. if (!CheckSequencePMOrder(sequenceInfo, out reason))
  748. {
  749. EV.PostWarningLog(LogSource, $"PM order is not valid, {reason}");
  750. return false;
  751. }
  752. #endregion
  753. var slotWafers = new List<Tuple<ModuleName, int>>();
  754. foreach (var slot in slotNumbers)
  755. {
  756. slotWafers.Add(Tuple.Create(ModuleName.System, slot));
  757. }
  758. ProcessJobInfo pj = new ProcessJobInfo();
  759. pj.Name = jobId;
  760. pj.Sequence = sequenceInfo;
  761. pj.SlotWafers = slotWafers;
  762. pj.SetState(EnumProcessJobState.Queued);
  763. _lstProcessJobs.Add(pj);
  764. return true;
  765. }
  766. private bool CheckSequenceAlignerReady(SequenceInfo seq, out string reason)
  767. {
  768. for (int i = 0; i < seq.Steps.Count; i++)
  769. {
  770. SequenceStepInfo stepInfo = seq.Steps[i];
  771. foreach (var module in stepInfo.StepModules)
  772. {
  773. if (ModuleHelper.IsAligner(module))
  774. {
  775. if (!_aligner.IsOnline)
  776. {
  777. reason = $"Step {i + 1}, {module} is not online";
  778. return false;
  779. }
  780. //if (!_aligner.IsIdle)
  781. //{
  782. // reason = $"Step {i + 1}, {module} is not idle";
  783. // return false;
  784. //}
  785. if (_aligner.IsError)
  786. {
  787. reason = $"Step {i + 1}, {module} is error";
  788. return false;
  789. }
  790. }
  791. }
  792. }
  793. reason = string.Empty;
  794. return true;
  795. }
  796. private bool CheckSequenceAlignerOrder(SequenceInfo seq, out string reason)
  797. {
  798. int alignerCount = 0;
  799. int alignerIndex = -1;
  800. int llIndex = -1;
  801. int pmIndex = -1;
  802. for (int i = 0; i < seq.Steps.Count; i++)
  803. {
  804. SequenceStepInfo stepInfo = seq.Steps[i];
  805. foreach (var module in stepInfo.StepModules)
  806. {
  807. if (ModuleHelper.IsAligner(module))
  808. {
  809. alignerCount++;
  810. alignerIndex = i;
  811. if (i == seq.Steps.Count - 1)
  812. {
  813. reason = $"Step {i + 1}, {module} can not be the last step";
  814. return false;
  815. }
  816. }
  817. if (ModuleHelper.IsLoadLock(module))
  818. {
  819. if (llIndex == -1 || llIndex > i)
  820. llIndex = i;
  821. }
  822. if (ModuleHelper.IsPm(module))
  823. {
  824. pmIndex = i;
  825. }
  826. }
  827. }
  828. if (alignerCount >= 2)
  829. {
  830. reason = $"Step {alignerIndex + 1}, Aligner step can appear once at most in sequence";
  831. return false;
  832. }
  833. else if (alignerCount == 1)
  834. {
  835. if (llIndex != -1 && alignerIndex > llIndex)
  836. {
  837. reason = $"Step {alignerIndex + 1}, Aligner step should be in front of LoadLock step";
  838. return false;
  839. }
  840. if (pmIndex != -1 && alignerIndex > pmIndex)
  841. {
  842. reason = $"Step {alignerIndex + 1}, Aligner step should be in front of PM step";
  843. return false;
  844. }
  845. }
  846. reason = string.Empty;
  847. return true;
  848. }
  849. private bool CheckSequencePMReady(SequenceInfo seq, out string reason)
  850. {
  851. for (int i = 0; i < seq.Steps.Count; i++)
  852. {
  853. SequenceStepInfo stepInfo = seq.Steps[i];
  854. if (stepInfo.StepModules.Count == 0)
  855. {
  856. reason = $"Step {i + 1}, no PM is selected";
  857. return false;
  858. }
  859. foreach (var module in stepInfo.StepModules)
  860. {
  861. if (ModuleHelper.IsPm(module))
  862. {
  863. foreach (var pm in _lstPms)
  864. {
  865. if (pm.Module == module)
  866. {
  867. if (!pm.IsOnline)
  868. {
  869. reason = $"Step {i + 1}, selected {module} is not online";
  870. return false;
  871. }
  872. //if (!pm.IsIdle)
  873. //{
  874. // reason = $"Step {i + 1}, selected {module} is not idle";
  875. // return false;
  876. //}
  877. if (pm.IsError)
  878. {
  879. reason = $"Step {i + 1}, selected {module} is error";
  880. return false;
  881. }
  882. #region Check Recipe File Valid
  883. var recipeContent = RecipeFileManager.Instance.LoadRecipe("", stepInfo.StepParameter[$"{module}Recipe"].ToString(), false);
  884. if (string.IsNullOrEmpty(recipeContent))
  885. {
  886. reason = $"Step {i + 1}, can not find recipe file {stepInfo.RecipeName}";
  887. return false;
  888. }
  889. #endregion
  890. }
  891. }
  892. }
  893. }
  894. }
  895. reason = "";
  896. return true;
  897. }
  898. private bool CheckSequencePMOrder(SequenceInfo seq, out string reason)
  899. {
  900. int pmCount = 0;
  901. for (int i = 0; i < seq.Steps.Count; i++)
  902. {
  903. SequenceStepInfo stepInfo = seq.Steps[i];
  904. foreach (var module in stepInfo.StepModules)
  905. {
  906. if (ModuleHelper.IsPm(module))
  907. {
  908. pmCount++;
  909. break;
  910. }
  911. }
  912. }
  913. if (pmCount == 0)
  914. {
  915. reason = $"Sequence must contains PM step";
  916. return false;
  917. }
  918. if (pmCount >= 2)
  919. {
  920. reason = $"PM step only can appear once in sequence";
  921. return false;
  922. }
  923. reason = string.Empty;
  924. return true;
  925. }
  926. internal ProcessJobInfo GetFirstProcessJob(ControlJobInfo cj)
  927. {
  928. foreach (var pj in _lstProcessJobs)
  929. {
  930. if (pj.ControlJobName == cj.Name)
  931. return pj;
  932. }
  933. return null;
  934. }
  935. public bool StopJob(string jobName)
  936. {
  937. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  938. if (cj == null)
  939. {
  940. EV.PostWarningLog(LogSource, $"stop job rejected, not found job with id {jobName}");
  941. return false;
  942. }
  943. foreach (var pj in _lstProcessJobs)
  944. {
  945. if (pj.ControlJobName == cj.Name)
  946. {
  947. pj.SetState(EnumProcessJobState.Stopping);
  948. }
  949. }
  950. _faCallback.JobStopped(cj, GetFirstProcessJob(cj));
  951. _dbCallback.LotFinished(cj);
  952. return true;
  953. }
  954. public bool AbortJob(string jobName)
  955. {
  956. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  957. if (cj == null)
  958. {
  959. EV.PostWarningLog(LogSource, $"abort job rejected, not found job with id {jobName}");
  960. return false;
  961. }
  962. int unprocessed_cj = 0;
  963. int aborted_cj = 0;
  964. List<ProcessJobInfo> pjAbortList = new List<ProcessJobInfo>();
  965. foreach (var pj in _lstProcessJobs)
  966. {
  967. if (pj.ControlJobName == cj.Name)
  968. {
  969. pj.SetState(EnumProcessJobState.Aborting);
  970. pjAbortList.Add(pj);
  971. int unprocessed = 0;
  972. int aborted = 0;
  973. WaferInfo[] wafers = WaferManager.Instance.GetWaferByProcessJob(pj.Name);
  974. foreach (var waferInfo in wafers)
  975. {
  976. waferInfo.ProcessJob = null;
  977. waferInfo.NextSequenceStep = 0;
  978. if (waferInfo.ProcessState != EnumWaferProcessStatus.Completed)
  979. {
  980. unprocessed++;
  981. unprocessed_cj++;
  982. }
  983. }
  984. JobDataRecorder.EndPJ(pj.InnerId.ToString(), aborted, unprocessed);
  985. }
  986. }
  987. foreach (var pj in pjAbortList)
  988. {
  989. _lstProcessJobs.Remove(pj);
  990. }
  991. _lstControlJobs.Remove(cj);
  992. JobDataRecorder.EndCJ(cj.InnerId.ToString(), aborted_cj, unprocessed_cj);
  993. _faCallback.JobAborted(cj, GetFirstProcessJob(cj));
  994. _dbCallback.LotFinished(cj);
  995. _temperatureSetpointDic.Clear();
  996. _temperatureTrigDic.Clear();
  997. return true;
  998. }
  999. public bool ResumeJob(string jobName)
  1000. {
  1001. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  1002. if (cj == null)
  1003. {
  1004. EV.PostWarningLog(LogSource, $"resume job rejected, not found job with id {jobName}");
  1005. return false;
  1006. }
  1007. if (cj.State == EnumControlJobState.Paused)
  1008. {
  1009. cj.SetState(EnumControlJobState.Executing);
  1010. }
  1011. _faCallback.JobResumed(cj, GetFirstProcessJob(cj));
  1012. return true;
  1013. }
  1014. public bool StartJob(string jobName)
  1015. {
  1016. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  1017. if (cj == null)
  1018. {
  1019. EV.PostWarningLog(LogSource, $"start job rejected, not found job with id {jobName}");
  1020. return false;
  1021. }
  1022. if (cj.State == EnumControlJobState.WaitingForStart)
  1023. {
  1024. cj.SetState(EnumControlJobState.Executing);
  1025. (GetModule(cj.Module) as SchedulerLoadPort).NoteJobStart();
  1026. //if (cj.IsCycleMode)
  1027. //{
  1028. // _CycleData.BeginOrAddCycle(cj.CycleWaferCountSP);
  1029. //}
  1030. cj.BeginTime = DateTime.Now;
  1031. cj.LotInnerId = Guid.NewGuid();
  1032. _dbCallback.LotCreated(cj);
  1033. _faCallback.JobStarted(cj, GetFirstProcessJob(cj));
  1034. //foreach (var pj in _lstProcessJobs)
  1035. //{
  1036. // if (pj.ControlJobName == cj.Name)
  1037. // {
  1038. // pj.SetState(EnumProcessJobState.Processing);
  1039. // }
  1040. //}
  1041. }
  1042. return true;
  1043. }
  1044. public bool PauseJob(string jobName)
  1045. {
  1046. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  1047. if (cj == null)
  1048. {
  1049. EV.PostWarningLog(LogSource, $"pause job rejected, not found job with id {jobName}");
  1050. return false;
  1051. }
  1052. if (cj.State == EnumControlJobState.Executing)
  1053. {
  1054. cj.SetState(EnumControlJobState.Paused);
  1055. }
  1056. _faCallback.JobPaused(cj, GetFirstProcessJob(cj));
  1057. return true;
  1058. }
  1059. public void Abort()
  1060. {
  1061. }
  1062. public bool IsCJExisted(string CJID)
  1063. {
  1064. return _lstControlJobs.Exists(x => x.Name == CJID);
  1065. }
  1066. public void ModuleError(string moduleName)
  1067. {
  1068. GetModule(moduleName).ResetTask();
  1069. PauseJob(string.Empty);
  1070. }
  1071. public void Map(string moduleName)
  1072. {
  1073. ModuleName target = ModuleHelper.Converter(moduleName);
  1074. if (!ModuleHelper.IsLoadPort(target))
  1075. {
  1076. EV.PostWarningLog(LogSource, $"Invalid map target {target}");
  1077. return;
  1078. }
  1079. if (!_mapTarget.Contains(target))
  1080. {
  1081. _mapTarget.Add(target);
  1082. }
  1083. }
  1084. #endregion
  1085. public Result Start(params object[] objs)
  1086. {
  1087. _ValueDict.Clear();
  1088. _CycleData.Reset();
  1089. var waferInfo = "";
  1090. bool hasPmOnline = false;
  1091. foreach (var schedulerPm in _lstPms)
  1092. {
  1093. if (schedulerPm.IsAvailable)
  1094. {
  1095. hasPmOnline = true;
  1096. if (WaferManager.Instance.CheckHasWafer(schedulerPm.Module, 0))
  1097. waferInfo += $"{(waferInfo == "" ? "" : ", ")}{schedulerPm.Module}";
  1098. }
  1099. }
  1100. bool hasTMOnline = false;
  1101. if (_tmRobot.IsAvailable)
  1102. hasTMOnline = true;
  1103. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0))
  1104. waferInfo += $"{(waferInfo == "" ? "" : ", ")}{ModuleName.TMRobot} primary arm";
  1105. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1))
  1106. waferInfo += $"{(waferInfo == "" ? "" : ", ")}{ModuleName.TMRobot} secondly arm";
  1107. if (!hasPmOnline || !hasTMOnline)
  1108. {
  1109. var content = hasPmOnline ? "" : "both process chamber";
  1110. content += hasTMOnline ? "" : $"{(content == "" ? "" : ", ")}TM";
  1111. EV.PostWarningLog("Scheduler", $"can not change to auto mode, {content} is busy or offline");
  1112. return Result.FAIL;
  1113. }
  1114. if (waferInfo != "")
  1115. {
  1116. EV.PostWarningLog("Scheduler", $"can not change to auto mode, {waferInfo} wafer presence.");
  1117. return Result.FAIL;
  1118. }
  1119. if (!_efem.IsOnline)
  1120. {
  1121. EV.PostWarningLog("Scheduler", $"can not change to auto mode, EFEM is offline");
  1122. return Result.FAIL;
  1123. }
  1124. return Result.RUN;
  1125. }
  1126. public Result Monitor()
  1127. {
  1128. for (int i = 0; i < 25; i++)
  1129. {
  1130. ProcessJobInfo pj = WaferManager.Instance.GetWafer(_lp1.Module, i).ProcessJob;
  1131. if (pj == null)
  1132. break;
  1133. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
  1134. if (cj == null)
  1135. break;
  1136. if (_lp1.FirstDetectWaferArrive(i))
  1137. {
  1138. _faCallback.JobWaferEnd(cj, pj, _lp1.Module.ToString(), i);
  1139. }
  1140. }
  1141. for (int i = 0; i < 25; i++)
  1142. {
  1143. ProcessJobInfo pj = WaferManager.Instance.GetWafer(_lp2.Module, i).ProcessJob;
  1144. if (pj == null)
  1145. break;
  1146. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
  1147. if (cj == null)
  1148. break;
  1149. if (_lp2.FirstDetectWaferArrive(i))
  1150. {
  1151. _faCallback.JobWaferEnd(cj, pj, _lp2.Module.ToString(), i);
  1152. }
  1153. }
  1154. MonitorJobTasks();
  1155. MonitorCleanTasks();
  1156. ControlJobInfo cjActive = _lstControlJobs.Find(x => x.State == EnumControlJobState.Executing);
  1157. if (cjActive != null)
  1158. {
  1159. MonitorModuleTasks();
  1160. }
  1161. return Result.RUN;
  1162. }
  1163. #region Job task
  1164. public Result MonitorJobTasks()
  1165. {
  1166. UpdateParallelMode();
  1167. CalcingThroughput();
  1168. UpdateProcessJobStatus();
  1169. UpdateControlJobStatus();
  1170. //if (GetUnprocessedWaferCount() < SC.GetValue<int>("System.Scheduler.WaferCountBelowWhichStartNewProcessJob"))
  1171. {
  1172. StartNewJob();
  1173. }
  1174. return Result.RUN;
  1175. }
  1176. //only for pj in process
  1177. protected int GetUnprocessedWaferCount()
  1178. {
  1179. int count = 0;
  1180. foreach (ProcessJobInfo pj in _lstProcessJobs)
  1181. {
  1182. if (pj.State == EnumProcessJobState.Processing || pj.State == EnumProcessJobState.Paused)
  1183. count += GetUnprocessedWaferCount(pj);
  1184. }
  1185. if (CheckWaferNeedProcess(WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 0)))
  1186. count++;
  1187. if (CheckWaferNeedProcess(WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 1)))
  1188. count++;
  1189. if (CheckWaferNeedProcess(WaferManager.Instance.GetWafer(ModuleName.Aligner, 0)))
  1190. count++;
  1191. return count;
  1192. }
  1193. protected int GetUnprocessedWaferCount(ProcessJobInfo pj)
  1194. {
  1195. int count = 0;
  1196. for (int i = 0; i < pj.SlotWafers.Count; ++i)
  1197. {
  1198. WaferInfo wafer = WaferManager.Instance.GetWafer(pj.SlotWafers[i].Item1, pj.SlotWafers[i].Item2);
  1199. if (wafer.IsEmpty)
  1200. continue;
  1201. if (CheckWaferNeedProcess(pj.SlotWafers[i].Item1, pj.SlotWafers[i].Item2))
  1202. count++;
  1203. }
  1204. return count;
  1205. }
  1206. protected bool CheckAllWaferReturned(ProcessJobInfo pj, bool checkAllProcessed)
  1207. {
  1208. for (int i = 0; i < pj.SlotWafers.Count; ++i)
  1209. {
  1210. WaferInfo wafer = WaferManager.Instance.GetWafer(pj.SlotWafers[i].Item1, pj.SlotWafers[i].Item2);
  1211. if (wafer.IsEmpty)
  1212. return false;
  1213. if (checkAllProcessed && CheckWaferNeedProcess(pj.SlotWafers[i].Item1, pj.SlotWafers[i].Item2))
  1214. return false;
  1215. }
  1216. return true;
  1217. }
  1218. protected bool CheckAllDummyWaferReturned()
  1219. {
  1220. foreach (var schedulerPm in _lstPms)
  1221. {
  1222. if (WaferManager.Instance.CheckWaferIsDummy(schedulerPm.Module, 0))
  1223. return false;
  1224. }
  1225. if (WaferManager.Instance.CheckWaferIsDummy(_tmRobot.Module, 0))
  1226. return false;
  1227. if (WaferManager.Instance.CheckWaferIsDummy(_tmRobot.Module, 1))
  1228. return false;
  1229. return true;
  1230. }
  1231. protected bool CheckAllPmCleaned(ProcessJobInfo pj)
  1232. {
  1233. foreach (var schedulerPm in _lstPms)
  1234. {
  1235. if (CheckNeedRunClean(schedulerPm.Module, out _, out _))
  1236. {
  1237. foreach (var sequenceStepInfo in pj.Sequence.Steps)
  1238. {
  1239. if (sequenceStepInfo.StepModules.Contains(schedulerPm.Module))
  1240. return false;
  1241. }
  1242. }
  1243. }
  1244. return true;
  1245. }
  1246. private void UpdateProcessJobStatus()
  1247. {
  1248. foreach (var pj in _lstProcessJobs)
  1249. {
  1250. if (pj.State == EnumProcessJobState.Processing)
  1251. {
  1252. if (CheckAllWaferReturned(pj, true) && CheckAllPmCleaned(pj) && CheckAllDummyWaferReturned())
  1253. {
  1254. pj.SetState(EnumProcessJobState.ProcessingComplete);
  1255. JobDataRecorder.EndPJ(pj.InnerId.ToString(), 0, 0);
  1256. }
  1257. }
  1258. else if (pj.State == EnumProcessJobState.Stopping)
  1259. {
  1260. if (CheckAllWaferReturned(pj, false) && CheckAllPmCleaned(pj) && CheckAllDummyWaferReturned())
  1261. {
  1262. pj.SetState(EnumProcessJobState.ProcessingComplete);
  1263. JobDataRecorder.EndPJ(pj.InnerId.ToString(), 0, 0);
  1264. }
  1265. }
  1266. }
  1267. }
  1268. private void UpdateParallelMode()
  1269. {
  1270. bool enableParallel = SC.GetValue<bool>("System.Scheduler.IsRunInParallelMode");
  1271. int hasJobLpCount = 0;
  1272. _isRunningInParallelMode = enableParallel;
  1273. List<ModuleName> pmUsed = new List<ModuleName>();
  1274. foreach (var lp in _lstLps)
  1275. {
  1276. var cj = _lstControlJobs.Find(x => x.Module == lp.Module.ToString());
  1277. if (cj != null)
  1278. {
  1279. hasJobLpCount++;
  1280. var pj = _lstProcessJobs.FirstOrDefault(x => x.ControlJobName == cj.Name);
  1281. if (pj != null)
  1282. {
  1283. var seq = pj.Sequence;
  1284. for (int i = 0; i < seq.Steps.Count; i++)
  1285. {
  1286. SequenceStepInfo stepInfo = seq.Steps[i];
  1287. foreach (var module in stepInfo.StepModules)
  1288. {
  1289. if (ModuleHelper.IsPm(module) && !pmUsed.Contains(module))
  1290. pmUsed.Add(module);
  1291. }
  1292. }
  1293. }
  1294. }
  1295. }
  1296. _isRunningInParallelMode = enableParallel && hasJobLpCount > 1 && pmUsed.Count > 1;
  1297. }
  1298. private void UpdateControlJobStatus()
  1299. {
  1300. if (_lstControlJobs.Count == 0)
  1301. return;
  1302. List<ControlJobInfo> cjRemoveList = new List<ControlJobInfo>();
  1303. foreach (var cj in _lstControlJobs)
  1304. {
  1305. if (cj.State == EnumControlJobState.Executing)
  1306. {
  1307. bool allPjCompleted = true;
  1308. foreach (var pjName in cj.ProcessJobNameList)
  1309. {
  1310. var pj = _lstProcessJobs.FirstOrDefault(x => x.Name == pjName);
  1311. if (pj == null) { LOG.Error($"Not find pj named {pjName} in {cj.Name}"); continue; }
  1312. if (pj.State != EnumProcessJobState.Complete &&
  1313. pj.State != EnumProcessJobState.ProcessingComplete)
  1314. {
  1315. allPjCompleted = false; break;
  1316. }
  1317. }
  1318. if (allPjCompleted)
  1319. {
  1320. if (!_CycleData.IsCycleMode || (_CycleData.IsCycleMode && _CycleData.IsCycleEnd()))
  1321. CompleteJobClean(cj);
  1322. _FinishCJ(cj);
  1323. cj.EndTime = DateTime.Now;
  1324. string strInfo = $"{cj.Module} has finished: \r\n\r\nProcessed wafer number: {cj.LotWafers.Count} \r\nStart time: {cj.BeginTime} \r\nEnd time: {cj.EndTime} \r\nDuration: {(cj.EndTime - cj.BeginTime).TotalSeconds:F0} sec";
  1325. EV.PostInfoLog("Scheduler", strInfo);
  1326. if (SC.GetValue<bool>("System.Job.EnablePopDialogWhenJobDone"))
  1327. {
  1328. EV.PostPopDialogMessage(EventLevel.Information, "System Information", strInfo);
  1329. }
  1330. }
  1331. }
  1332. }
  1333. if (_lstControlJobs.Any(cj => cj.State == EnumControlJobState.Completed) && _CycleData.IsCycleMode && !_CycleData.IsCycleEnd())
  1334. {
  1335. var completeCJs = from cj in _lstControlJobs
  1336. where cj.State == EnumControlJobState.Completed
  1337. select cj;
  1338. var otherCJs = from cj in _lstControlJobs
  1339. where cj.State != EnumControlJobState.Completed
  1340. select cj;
  1341. _lstControlJobs = otherCJs.Concat(completeCJs).ToList();
  1342. _lstControlJobs.ForEach(cj =>
  1343. {
  1344. if (cj.State == EnumControlJobState.Completed)
  1345. {
  1346. _CycleData.IncreaseCount();
  1347. if (_CycleData.IsCycleEnd())
  1348. return;
  1349. cj.SetState(EnumControlJobState.Executing);
  1350. cj.BeginTime = DateTime.Now;
  1351. cj.LotWafers.ForEach(x =>
  1352. {
  1353. x.NextSequenceStep = 0;
  1354. x.ProcessState = EnumWaferProcessStatus.Idle;
  1355. });
  1356. foreach (var pjName in cj.ProcessJobNameList)
  1357. {
  1358. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  1359. if (pj == null)
  1360. {
  1361. LOG.Error($"Not find pj named {pjName} in {cj.Name}");
  1362. continue;
  1363. }
  1364. pj.SetState(EnumProcessJobState.Queued);
  1365. }
  1366. }
  1367. });
  1368. }
  1369. foreach (var cj in _lstControlJobs)
  1370. {
  1371. if (cj.State == EnumControlJobState.Completed
  1372. && (!_CycleData.IsCycleMode || _CycleData.IsCycleMode && _CycleData.IsCycleEnd())
  1373. && (!_isAutoUnloadFoup || (_isAutoUnloadFoup && (GetModule(cj.Module.ToString()) as SchedulerLoadPort).IsUnloaded)))
  1374. {
  1375. (GetModule(cj.Module) as SchedulerLoadPort).NoteJobComplete();
  1376. cjRemoveList.Add(cj);
  1377. }
  1378. }
  1379. foreach (var cj in cjRemoveList)
  1380. {
  1381. List<ProcessJobInfo> pjRemoveList = _lstProcessJobs.Where(o => o.ControlJobName == cj.Name).ToList();
  1382. pjRemoveList.ForEach(o => _lstProcessJobs.Remove(o));
  1383. _lstControlJobs.Remove(cj);
  1384. CalcedThroughput(pjRemoveList);
  1385. }
  1386. ControlJobInfo cjActived = null;
  1387. foreach (var cj in _lstControlJobs)
  1388. {
  1389. if (cj.State == EnumControlJobState.Executing)
  1390. {
  1391. cjActived = cj;
  1392. break;
  1393. }
  1394. }
  1395. if (cjActived != null)
  1396. {
  1397. bool allPjResouceOk = true;
  1398. string reason = string.Empty;
  1399. foreach (var pjName in cjActived.ProcessJobNameList)
  1400. {
  1401. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  1402. if (pj == null)
  1403. {
  1404. LOG.Error($"Not find pj named {pjName} in {cjActived.Name}");
  1405. continue;
  1406. }
  1407. if (pj.State != EnumProcessJobState.Complete && pj.State != EnumProcessJobState.ProcessingComplete)
  1408. {
  1409. if (!CheckSequencePmReady(pj.Sequence, null, out _, out reason))
  1410. {
  1411. allPjResouceOk = false;
  1412. break;
  1413. }
  1414. }
  1415. }
  1416. if (!allPjResouceOk)
  1417. {
  1418. cjActived.SetState(EnumControlJobState.Paused);
  1419. EV.PostWarningLog(LogSource, $"{cjActived.Module} paused, {reason}");
  1420. }
  1421. }
  1422. }
  1423. private void _FinishCJ(ControlJobInfo cj)
  1424. {
  1425. cj.SetState(EnumControlJobState.Completed);
  1426. int unprocessed_cj = 0;
  1427. int aborted_cj = 0;
  1428. foreach (var pj in _lstProcessJobs)
  1429. {
  1430. if (pj.ControlJobName == cj.Name)
  1431. {
  1432. int unprocessed = 0;
  1433. int aborted = 0;
  1434. WaferInfo[] wafers = WaferManager.Instance.GetWaferByProcessJob(pj.Name);
  1435. foreach (var waferInfo in wafers)
  1436. {
  1437. waferInfo.ProcessJob = null;
  1438. waferInfo.NextSequenceStep = 0;
  1439. if (waferInfo.ProcessState != EnumWaferProcessStatus.Completed)
  1440. {
  1441. unprocessed++;
  1442. unprocessed_cj++;
  1443. }
  1444. }
  1445. JobDataRecorder.EndPJ(pj.InnerId.ToString(), aborted, unprocessed);
  1446. }
  1447. }
  1448. JobDataRecorder.EndCJ(cj.InnerId.ToString(), aborted_cj, unprocessed_cj);
  1449. _faCallback.JobFinished(cj, GetFirstProcessJob(cj));
  1450. _dbCallback.LotFinished(cj);
  1451. }
  1452. //private bool _HandleFinishedCycleCJ(ControlJobInfo cj)
  1453. //{
  1454. // //if (!cj.IsCycleMode) return false;
  1455. // int countProcessed = 0;
  1456. // foreach (var pjName in cj.ProcessJobNameList)
  1457. // {
  1458. // var pj = _lstProcessJobs.FirstOrDefault(x => x.Name == pjName);
  1459. // if (pj == null) { LOG.Error($"Not find pj named {pjName} in {cj.Name}"); continue; }
  1460. // if (pj.State == EnumProcessJobState.Complete || pj.State == EnumProcessJobState.ProcessingComplete)
  1461. // {
  1462. // foreach (var pjSlotWafer in pj.SlotWafers)
  1463. // {
  1464. // WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1465. // if (!wafer.IsEmpty && !CheckWaferNeedProcess(pjSlotWafer.Item1, pjSlotWafer.Item2))
  1466. // countProcessed++;
  1467. // }
  1468. // }
  1469. // }
  1470. // _CycleData.Increase(countProcessed);
  1471. // int leftCount = _CycleData.CycleWaferCountSetPoint - _CycleData.CycledWaferCount;
  1472. // // finished cycle
  1473. // if (leftCount <= 0) return false;
  1474. // // 移除老的cj
  1475. // var pjList = _lstProcessJobs.Where(o => o.ControlJobName == cj.Name).ToList();
  1476. // CalcedThroughput(pjList);
  1477. // pjList.ForEach(o => _lstProcessJobs.Remove(o));
  1478. // _lstControlJobs.Remove(cj);
  1479. // // 模拟 LP unload / load
  1480. // {
  1481. // ModuleName mName = ModuleHelper.Converter(cj.Module);
  1482. // var wafers_old = WaferManager.Instance.GetWafers(mName).ToList();
  1483. // WaferManager.Instance.DeleteWafer(mName, 0, SC.GetValue<int>($"EFEM.LoadPort.CassetteSlotNumber"));
  1484. // CarrierManager.Instance.DeleteCarrier(cj.Module);
  1485. // CarrierManager.Instance.CreateCarrier(cj.Module);
  1486. // foreach (var wafer in wafers_old)
  1487. // {
  1488. // if (wafer.Status != WaferStatus.Normal) continue;
  1489. // var newWafer = WaferManager.Instance.CreateWafer(mName, wafer.Slot, wafer.Status);
  1490. // newWafer.PPID = wafer.PPID;
  1491. // CarrierManager.Instance.RegisterCarrierWafer(cj.Module, wafer.Slot, newWafer);
  1492. // }
  1493. // }
  1494. // // 产生新的cj
  1495. // ControlJobInfo newCj = new ControlJobInfo();
  1496. // newCj.Name = cj.Name;
  1497. // newCj.Module = cj.Module;
  1498. // newCj.LotName = cj.LotName;
  1499. // //newCj.IsCycleMode = cj.IsCycleMode;
  1500. // //newCj.CycleWaferCountSP = cj.CycleWaferCountSP;
  1501. // //newCj.CycledWaferCount = _CycleData.CycledWaferCount;
  1502. // newCj.LotInnerId = Guid.NewGuid();
  1503. // newCj.LotWafers = cj.LotWafers.Take(leftCount).ToList();
  1504. // int addedCount = 0;
  1505. // List<ProcessJobInfo> newPjList = new List<ProcessJobInfo>();
  1506. // //int toAddCount = Math.Min(leftCount, cj.LotWafers.Count);
  1507. // for (int ii = 0; ii < cj.ProcessJobNameList.Count; ii++)
  1508. // {
  1509. // string pjName = cj.ProcessJobNameList[ii];
  1510. // var pj = pjList.FirstOrDefault(o => o.ControlJobName == cj.Name && o.Name == pjName);
  1511. // if (pj == null) continue;
  1512. // int toAddCount = Math.Min(leftCount - addedCount, cj.LotWafers.Count);
  1513. // if (toAddCount <= 0) break;
  1514. // addedCount += toAddCount;
  1515. // ProcessJobInfo newPj = new ProcessJobInfo();
  1516. // newPj.Name = pj.Name;
  1517. // newPj.Sequence = pj.Sequence;
  1518. // newPj.ControlJobName = pj.ControlJobName;
  1519. // newPj.SlotWafers = pj.SlotWafers.Take(toAddCount).ToList();
  1520. // newPj.SetState(EnumProcessJobState.Queued);
  1521. // _lstProcessJobs.Add(newPj);
  1522. // newCj.ProcessJobNameList.Add(pj.Name);
  1523. // newPjList.Add(newPj);
  1524. // }
  1525. // _lstControlJobs.Add(newCj);
  1526. // // 开始新的cj
  1527. // newCj.SetState(EnumControlJobState.Executing);
  1528. // newCj.LotInnerId = Guid.NewGuid();
  1529. // newCj.BeginTime = DateTime.Now;
  1530. // _dbCallback.LotCreated(newCj);
  1531. // newPjList.ForEach(o => ActiveProcessJob(o));
  1532. // return true;
  1533. //}
  1534. public bool CheckAllJobDone()
  1535. {
  1536. if (_lp1.IsAvailable)
  1537. {
  1538. _trigLp1JobComplete.CLK = CheckJobComplete(ModuleName.LP1.ToString());
  1539. if (_trigLp1JobComplete.Q)
  1540. {
  1541. if (_isAutoUnloadFoup)
  1542. {
  1543. _lp1.Unload();
  1544. }
  1545. EV.Notify("CARRIER_PROCESS_COMPLETE", new SerializableDictionary<string, object>()
  1546. {
  1547. { "PortID", 1},
  1548. { "PORT_ID", 1},
  1549. { "CarrierID", CarrierManager.Instance.GetCarrier(_lp1.Module.ToString()).CarrierId},
  1550. { "CAR_ID", CarrierManager.Instance.GetCarrier(_lp1.Module.ToString()).CarrierId}
  1551. });
  1552. }
  1553. }
  1554. if (_lp2.IsAvailable)
  1555. {
  1556. _trigLp2JobComplete.CLK = CheckJobComplete(ModuleName.LP2.ToString());
  1557. if (_trigLp2JobComplete.Q)
  1558. {
  1559. if (_isAutoUnloadFoup)
  1560. {
  1561. _lp2.Unload();
  1562. }
  1563. EV.Notify("CARRIER_PROCESS_COMPLETE", new SerializableDictionary<string, object>()
  1564. {
  1565. { "PortID", 2},
  1566. { "PORT_ID", 2},
  1567. { "CarrierID", CarrierManager.Instance.GetCarrier(_lp2.Module.ToString()).CarrierId},
  1568. { "CAR_ID", CarrierManager.Instance.GetCarrier(_lp2.Module.ToString()).CarrierId}
  1569. });
  1570. }
  1571. }
  1572. if (_lp3.IsAvailable)
  1573. {
  1574. _trigLp3JobComplete.CLK = CheckJobComplete(ModuleName.LP3.ToString());
  1575. if (_trigLp3JobComplete.Q)
  1576. {
  1577. if (_isAutoUnloadFoup)
  1578. {
  1579. _lp3.Unload();
  1580. }
  1581. EV.Notify("CARRIER_PROCESS_COMPLETE", new SerializableDictionary<string, object>()
  1582. {
  1583. { "PortID", 3 },
  1584. { "PORT_ID", 3 },
  1585. { "CarrierID", CarrierManager.Instance.GetCarrier(_lp3.Module.ToString()).CarrierId },
  1586. { "CAR_ID", CarrierManager.Instance.GetCarrier(_lp3.Module.ToString()).CarrierId }
  1587. });
  1588. }
  1589. }
  1590. foreach (var cj in _lstControlJobs)
  1591. {
  1592. if (cj.State == EnumControlJobState.Executing || cj.State == EnumControlJobState.Paused)
  1593. return false;
  1594. }
  1595. if (!_lp1.IsAvailable || !_lp2.IsAvailable || !_lp3.IsAvailable)
  1596. return false;
  1597. return true;
  1598. }
  1599. private bool CheckJobComplete(string lp = null)
  1600. {
  1601. if (_lstProcessJobs.Count == 0)
  1602. return false;
  1603. if (_lstControlJobs.Count == 0)
  1604. return false;
  1605. if (_CycleData.IsCycleMode && !_CycleData.IsCycleEnd())
  1606. return false;
  1607. if (lp != null)
  1608. {
  1609. var cj = _lstControlJobs.Find(x => x.Module == lp);
  1610. if (cj == null)
  1611. return false;
  1612. }
  1613. foreach (var pj in _lstProcessJobs)
  1614. {
  1615. if (lp == null)
  1616. {
  1617. if (pj.State != EnumProcessJobState.ProcessingComplete)
  1618. {
  1619. return false;
  1620. }
  1621. }
  1622. }
  1623. foreach (var cj in _lstControlJobs)
  1624. {
  1625. if (lp == null)
  1626. {
  1627. if (cj.State != EnumControlJobState.Completed)
  1628. {
  1629. return false;
  1630. }
  1631. }
  1632. else
  1633. {
  1634. if (cj.Module == lp && cj.State != EnumControlJobState.Completed)
  1635. {
  1636. return false;
  1637. }
  1638. }
  1639. }
  1640. return true;
  1641. }
  1642. private void StartNewJob()
  1643. {
  1644. ControlJobInfo cjActived = null;
  1645. bool enableParallel = SC.GetValue<bool>("System.Scheduler.IsRunInParallelMode");
  1646. List<ModuleName> pmOccupied = GetPmUsedInRunningPj();
  1647. var orderedLstCJs = _lstControlJobs.OrderBy(x => x.BeginTime);
  1648. foreach (var cj in orderedLstCJs)
  1649. {
  1650. if (cj.State != EnumControlJobState.Executing)
  1651. continue;
  1652. cjActived = cj;
  1653. foreach (var pjName in cjActived.ProcessJobNameList)
  1654. {
  1655. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  1656. if (pj == null)
  1657. {
  1658. LOG.Error($"Not find pj named {pjName} in {cjActived.Name}");
  1659. continue;
  1660. }
  1661. if (pj.State == EnumProcessJobState.Queued)
  1662. {
  1663. var pmIsReady = CheckSequencePmReady(pj.Sequence, pmOccupied, out var pmUsed, out string reason);
  1664. if (pmUsed.Count > 0)
  1665. {
  1666. var needPreClean = pmUsed.Any(x =>
  1667. {
  1668. return SC.GetValue<bool>($"{x.ToString()}.JobClean.IsEnabled") && SC.GetValue<bool>($"{x.ToString()}.JobClean.EnablePreJobClean");
  1669. });
  1670. if (needPreClean && !pmIsReady)
  1671. break;
  1672. ActiveProcessJob(pj);
  1673. foreach (var moduleName in pmUsed)
  1674. {
  1675. if (!pmOccupied.Contains(moduleName))
  1676. pmOccupied.Add(moduleName);
  1677. }
  1678. break;
  1679. }
  1680. }
  1681. }
  1682. if (!_isRunningInParallelMode)
  1683. break;
  1684. }
  1685. }
  1686. private List<ModuleName> GetPmUsedInRunningPj()
  1687. {
  1688. var pmUsed = new List<ModuleName>();
  1689. foreach (var cj in _lstControlJobs)
  1690. {
  1691. if (cj.State != EnumControlJobState.Executing && cj.State != EnumControlJobState.Paused)
  1692. continue;
  1693. foreach (var pj in _lstProcessJobs)
  1694. {
  1695. if (pj.ControlJobName == cj.Name && (pj.State == EnumProcessJobState.Processing || pj.State == EnumProcessJobState.Paused))
  1696. {
  1697. for (int i = 0; i < pj.Sequence.Steps.Count; i++)
  1698. {
  1699. SequenceStepInfo stepInfo = pj.Sequence.Steps[i];
  1700. foreach (var module in stepInfo.StepModules)
  1701. {
  1702. if (ModuleHelper.IsPm(module) && !pmUsed.Contains(module))
  1703. pmUsed.Add(module);
  1704. }
  1705. }
  1706. }
  1707. }
  1708. }
  1709. return pmUsed;
  1710. }
  1711. //private bool CheckSequencePmReady(SequenceInfo seq, out string reason)
  1712. //{
  1713. // for (int i = 0; i < seq.Steps.Count; i++)
  1714. // {
  1715. // SequenceStepInfo stepInfo = seq.Steps[i];
  1716. // bool hasPm = false;
  1717. // foreach (var module in stepInfo.StepModules)
  1718. // {
  1719. // if (ModuleHelper.IsPm(module))
  1720. // {
  1721. // PM pm = DEVICE.GetDevice<PM>(module.ToString());
  1722. // if (pm.IsInstalled && !pm.IsError)
  1723. // {
  1724. // hasPm = true;
  1725. // break;
  1726. // }
  1727. // }
  1728. // else
  1729. // {
  1730. // hasPm = true; // other modules default ok
  1731. // }
  1732. // }
  1733. // if (!hasPm)
  1734. // {
  1735. // reason = $"Step {i + 1} no valid PM, " + string.Join("|", stepInfo.StepModules);
  1736. // return false;
  1737. // }
  1738. // }
  1739. // reason = "";
  1740. // return true;
  1741. //}
  1742. private bool CheckSequencePmReady(SequenceInfo seq, List<ModuleName> pmOccupied, out List<ModuleName> pmUsed, out string reason)
  1743. {
  1744. pmUsed = new List<ModuleName>();
  1745. reason = "";
  1746. bool pmIsReady = true;
  1747. for (int i = 0; i < seq.Steps.Count; i++)
  1748. {
  1749. SequenceStepInfo stepInfo = seq.Steps[i];
  1750. bool hasPm = false;
  1751. foreach (var module in stepInfo.StepModules)
  1752. {
  1753. if (!ModuleHelper.IsPm(module))
  1754. {
  1755. hasPm = true;
  1756. break;
  1757. }
  1758. PMModuleBase pm = EquipmentManager.Modules[module] as PMModuleBase;
  1759. if (pm.IsInstalled && (pmOccupied == null || !pmOccupied.Contains(module)))
  1760. {
  1761. hasPm = true;
  1762. }
  1763. if (!pmUsed.Contains(module))
  1764. pmUsed.Add(module);
  1765. }
  1766. if (pmIsReady && !hasPm)
  1767. {
  1768. reason = $"Step {i + 1} no valid PM, " + string.Join("|", stepInfo.StepModules);
  1769. pmIsReady = false;
  1770. }
  1771. }
  1772. return pmIsReady;
  1773. }
  1774. private bool CheckSequenceRecipeFileValidTobedone(SequenceInfo seq, out string reason)
  1775. {
  1776. for (int i = 0; i < seq.Steps.Count; i++)
  1777. {
  1778. SequenceStepInfo stepInfo = seq.Steps[i];
  1779. foreach (var module in stepInfo.StepModules)
  1780. {
  1781. if (ModuleHelper.IsPm(module))
  1782. {
  1783. var recipeContent =
  1784. RecipeFileManager.Instance.LoadRecipe($"{module}\\", stepInfo.RecipeName, false);
  1785. if (string.IsNullOrEmpty(recipeContent))
  1786. {
  1787. reason = $"Can not find recipe file {module}\\{stepInfo.RecipeName}";
  1788. return false;
  1789. }
  1790. string cleanRecipeName = "";
  1791. if (stepInfo.CleanInterval > 0
  1792. && stepInfo.StepParameter.ContainsKey("CleanRecipeNoWafer")
  1793. && !string.IsNullOrEmpty((string)stepInfo.StepParameter["CleanRecipeNoWafer"]))
  1794. {
  1795. cleanRecipeName = (string)stepInfo.StepParameter["CleanRecipeNoWafer"];
  1796. if (!string.IsNullOrEmpty(cleanRecipeName))
  1797. {
  1798. recipeContent =
  1799. RecipeFileManager.Instance.LoadRecipe($"{module}\\", cleanRecipeName, false);
  1800. if (string.IsNullOrEmpty(recipeContent))
  1801. {
  1802. reason = $"Can not find recipe file {module}\\{cleanRecipeName}";
  1803. return false;
  1804. }
  1805. }
  1806. }
  1807. if (stepInfo.CleanInterval > 0
  1808. && stepInfo.StepParameter.ContainsKey("CleanRecipeWafer")
  1809. && !string.IsNullOrEmpty((string)stepInfo.StepParameter["CleanRecipeWafer"]))
  1810. {
  1811. cleanRecipeName = (string)stepInfo.StepParameter["CleanRecipeWafer"];
  1812. if (!string.IsNullOrEmpty(cleanRecipeName))
  1813. {
  1814. recipeContent =
  1815. RecipeFileManager.Instance.LoadRecipe($"{module}\\", cleanRecipeName, false);
  1816. if (string.IsNullOrEmpty(recipeContent))
  1817. {
  1818. reason = $"Can not find recipe file {module}\\{cleanRecipeName}";
  1819. return false;
  1820. }
  1821. }
  1822. }
  1823. }
  1824. }
  1825. }
  1826. reason = "";
  1827. return true;
  1828. }
  1829. private bool CheckSequenceRecipeFileValid(SequenceInfo seq, out string reason)
  1830. {
  1831. for (int i = 0; i < seq.Steps.Count; i++)
  1832. {
  1833. SequenceStepInfo stepInfo = seq.Steps[i];
  1834. foreach (var module in stepInfo.StepModules)
  1835. {
  1836. if (ModuleHelper.IsPm(module))
  1837. {
  1838. var recipeContent =
  1839. RecipeFileManager.Instance.LoadRecipe("", stepInfo.StepParameter[$"{module}Recipe"].ToString(), false);
  1840. if (string.IsNullOrEmpty(recipeContent))
  1841. {
  1842. reason = $"Can not find recipe file {stepInfo.StepParameter[$"{module}Recipe"].ToString()}";
  1843. return false;
  1844. }
  1845. }
  1846. }
  1847. }
  1848. reason = "";
  1849. return true;
  1850. }
  1851. private bool CheckSequenceOrderOk(SequenceInfo seq, out string reason)
  1852. {
  1853. reason = "";
  1854. bool foundPm = false;
  1855. bool isLLBeforePm = false;
  1856. bool isLLAfterPm = false;
  1857. bool isAlignerAfterLL = false;
  1858. for (int i = 0; i < seq.Steps.Count; i++)
  1859. {
  1860. SequenceStepInfo stepInfo = seq.Steps[i];
  1861. foreach (var module in stepInfo.StepModules)
  1862. {
  1863. if (ModuleHelper.IsPm(module))
  1864. {
  1865. foundPm = true;
  1866. }
  1867. if (!foundPm && ModuleHelper.IsLoadLock(module))
  1868. {
  1869. isLLBeforePm = true;
  1870. }
  1871. if (foundPm && ModuleHelper.IsLoadLock(module))
  1872. {
  1873. isLLAfterPm = true;
  1874. }
  1875. if (ModuleHelper.IsAligner(module) && (isLLBeforePm || foundPm))
  1876. {
  1877. isAlignerAfterLL = true;
  1878. }
  1879. }
  1880. }
  1881. if (!isLLBeforePm)
  1882. {
  1883. reason = $"not found LL before PM;";
  1884. return false;
  1885. }
  1886. if (!isLLAfterPm)
  1887. {
  1888. reason = $"not found LL after PM;";
  1889. return false;
  1890. }
  1891. if (!foundPm)
  1892. {
  1893. reason = $"not found PM in the sequence file;";
  1894. return false;
  1895. }
  1896. if (isAlignerAfterLL)
  1897. {
  1898. reason = "Aligner after LL not support";
  1899. return false;
  1900. }
  1901. return true;
  1902. }
  1903. private bool CheckSequenceNeedDummyWafer(SequenceInfo seq)
  1904. {
  1905. bool needDummyWafer = false;
  1906. for (int i = 0; i < seq.Steps.Count; i++)
  1907. {
  1908. SequenceStepInfo stepInfo = seq.Steps[i];
  1909. foreach (var module in stepInfo.StepModules)
  1910. {
  1911. if (ModuleHelper.IsPm(module))
  1912. {
  1913. if (stepInfo.CleanInterval > 0
  1914. && stepInfo.StepParameter.ContainsKey("CleanRecipeWafer")
  1915. && !string.IsNullOrEmpty((string)stepInfo.StepParameter["CleanRecipeWafer"]))
  1916. {
  1917. needDummyWafer = true;
  1918. break;
  1919. }
  1920. }
  1921. }
  1922. if (needDummyWafer)
  1923. break;
  1924. }
  1925. return needDummyWafer;
  1926. }
  1927. private bool ActiveProcessJob(ProcessJobInfo pj)
  1928. {
  1929. //pm is ok
  1930. if (!CheckSequencePmReady(pj.Sequence, null, out _, out string reason))
  1931. {
  1932. EV.PostWarningLog(LogSource, $"can not active {pj.Name}, {reason}");
  1933. return false;
  1934. }
  1935. _lstPmsCurrentSequence.Clear();
  1936. for (int i = 0; i < pj.Sequence.Steps.Count; i++)
  1937. {
  1938. SequenceStepInfo stepInfo = pj.Sequence.Steps[i];
  1939. foreach (var module in stepInfo.StepModules)
  1940. {
  1941. if (ModuleHelper.IsPm(module))
  1942. {
  1943. var pm = _lstPms.Find(x => x.Module == module);
  1944. if (pm != null)
  1945. _lstPmsCurrentSequence.Add(pm);
  1946. }
  1947. }
  1948. }
  1949. foreach (var pjSlotWafer in pj.SlotWafers)
  1950. {
  1951. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1952. wafer.ProcessJob = pj;
  1953. wafer.NextSequenceStep = 0;
  1954. WaferDataRecorder.SetPjInfo(wafer.InnerId.ToString(), pj.InnerId.ToString());
  1955. }
  1956. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
  1957. CarrierInfo carrier = CarrierManager.Instance.GetCarrier(cj.Module);
  1958. JobDataRecorder.StartPJ(pj.InnerId.ToString(), carrier.InnerId.ToString(), cj.InnerId.ToString(), pj.Name, cj.Module, cj.Module, pj.SlotWafers.Count);
  1959. pj.SetState(EnumProcessJobState.Processing);
  1960. PreJobClean(cj);
  1961. return true;
  1962. }
  1963. #endregion
  1964. #region Module task
  1965. public Result MonitorModuleTasks()
  1966. {
  1967. MonitorPMTask();
  1968. MonitorEfemRobotTask();
  1969. for (int i = 0; i < tmRobotActions.Count; i++)
  1970. {
  1971. MonitorTmRobotTask();
  1972. }
  1973. //MonitorLoadLockTask();
  1974. MonitorInterlockTask();
  1975. MonitorAlignerTask();
  1976. return Result.RUN;
  1977. }
  1978. private void MonitorInterlockTask()
  1979. {
  1980. foreach (var cj in _lstControlJobs)
  1981. {
  1982. if (cj.State == EnumControlJobState.Executing || cj.State == EnumControlJobState.Paused ||
  1983. cj.State == EnumControlJobState.WaitingForStart)
  1984. {
  1985. var lp = GetModule(cj.Module);
  1986. if (CarrierManager.Instance.CheckNoCarrier(lp.Module, 0))
  1987. {
  1988. EV.PostAlarmLog("System", "Cassette removed while job not finished.");
  1989. //Singleton<RouteManager>.Instance.PostMsg(RouteManager.MSG.ERROR);
  1990. }
  1991. }
  1992. }
  1993. }
  1994. private void MonitorAlignerTask()
  1995. {
  1996. if (!_aligner.IsAvailable)
  1997. return;
  1998. if (CheckWaferNextStepIsAlign(_aligner.Module, 0))
  1999. {
  2000. WaferInfo wafer = WaferManager.Instance.GetWafer(_aligner.Module, 0);
  2001. GetWaferSequenceAlignAngle(_aligner.Module, 0, out double angle);
  2002. if (_aligner.Align(angle))
  2003. {
  2004. wafer.NextSequenceStep++;
  2005. }
  2006. WaferDataRecorder.SetWaferNotchAngle(wafer.InnerId.ToString(), (float)angle);
  2007. }
  2008. }
  2009. //private void MonitorBufferTask()
  2010. //{
  2011. // foreach (var buffer in _lstBuffers)
  2012. // {
  2013. // if (!buffer.IsAvailable)
  2014. // continue;
  2015. // }
  2016. //}
  2017. private void MonitorLoadLockTask()
  2018. {
  2019. // bool isPrepareTransferForEfemobotPlace = GetWaferCountInJobQueue() > 0;
  2020. // foreach (var ll in _lstLls)
  2021. // {
  2022. // if (ll.Entity.IsPrepareTransfer)
  2023. // {
  2024. // return;
  2025. // }
  2026. // var deviceLL = DEVICE.GetDevice<LoadLock>(ll.Module.ToString());
  2027. // //if (ll.CheckAtAtm() && (ll.Entity.IsCooling || deviceLL.CheckDoorOpen()))
  2028. // if (deviceLL.CheckDoorOpen())
  2029. // {
  2030. // var wafers = WaferManager.Instance.GetWafers(ll.Module).ToList();
  2031. // int emptySlot = 0;
  2032. // foreach (var wafer in wafers)
  2033. // {
  2034. // if (wafer.IsEmpty || wafer.ProcessState != EnumWaferProcessStatus.Idle)
  2035. // emptySlot++;
  2036. // }
  2037. // if (emptySlot >= GetWaferCountInJobQueue())
  2038. // {
  2039. // isPrepareTransferForEfemobotPlace = false;
  2040. // break;
  2041. // }
  2042. // }
  2043. // }
  2044. // foreach (var ll in _lstLls)
  2045. // {
  2046. // if (!ll.IsAvailable)
  2047. // continue;
  2048. // var deviceLL = DEVICE.GetDevice<LoadLock>(ll.Module.ToString());
  2049. // var wafers = WaferManager.Instance.GetWafers(ll.Module).ToList();
  2050. // var isEmptyLL = true;
  2051. // bool isPrepareTransferForEfemobotPick = true;
  2052. // for (int i = 0; i <= 5;)
  2053. // {
  2054. // var wafer0 = WaferManager.Instance.GetWafer(ll.Module, i);
  2055. // var wafer1 = WaferManager.Instance.GetWafer(ll.Module, i + 1);
  2056. // if (!wafer0.IsEmpty || !wafer1.IsEmpty)
  2057. // isEmptyLL = false;
  2058. // if (wafer0.IsEmpty && wafer1.IsEmpty && GetVacuumWafer() > 0)
  2059. // isPrepareTransferForEfemobotPick = false;
  2060. // if ((!wafer0.IsEmpty && wafer0.ProcessState == EnumWaferProcessStatus.Idle) ||
  2061. // (!wafer1.IsEmpty && wafer1.ProcessState == EnumWaferProcessStatus.Idle))
  2062. // isPrepareTransferForEfemobotPick = false;
  2063. // i += 2;
  2064. // }
  2065. // if (isEmptyLL)
  2066. // isPrepareTransferForEfemobotPick = false;
  2067. // if (isPrepareTransferForEfemobotPlace && isEmptyLL && (_tmDevice.CheckSlitValveClose(ll.Module) || GetVacuumWafer() == 0) &&
  2068. // !ll.Entity.IsPrepareTransferReady(ModuleName.EfemRobot, EnumTransferType.Place))
  2069. // {
  2070. // ll.PrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0);
  2071. // return;
  2072. // }
  2073. // if (isPrepareTransferForEfemobotPick)
  2074. // {
  2075. // if (!ll.Entity.IsPrepareTransferReady(ModuleName.EfemRobot, EnumTransferType.Pick))
  2076. // {
  2077. // if (!_loadlockCooling.ContainsKey(ll.Module))
  2078. // _loadlockCooling.Add(ll.Module, false);
  2079. // _loadlockCooling[ll.Module] = false;
  2080. // ll.PrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, 0);
  2081. // return;
  2082. // }
  2083. // //TODO, cooling 要在 Open ATM door 之前做,PrepareTransfer 需要分开 [2021/7/3 TerryLu]
  2084. // if (ll.Entity.IsPreCoolingDone())
  2085. // {
  2086. // foreach (var wafer in wafers)
  2087. // {
  2088. // if (wafer != null && !wafer.IsEmpty && GetWaferSequenceLoadLockCoolingTime(ll.Module, wafer.Slot, out int coolingTime))
  2089. // {
  2090. // _loadlockCooling[ll.Module] = true;
  2091. // ll.Cooling(coolingTime);
  2092. // break;
  2093. // }
  2094. // }
  2095. // if (_loadlockCooling[ll.Module])
  2096. // {
  2097. // foreach (var wafer in wafers)
  2098. // {
  2099. // if (wafer != null && !wafer.IsEmpty)
  2100. // {
  2101. // wafer.NextSequenceStep++;
  2102. // }
  2103. // }
  2104. // }
  2105. // }
  2106. // }
  2107. // bool isPrepareTransferForTMRobot = true;
  2108. // bool isAllEmpty = true;
  2109. // foreach (var wafer in wafers)
  2110. // {
  2111. // if (!wafer.IsEmpty)
  2112. // isAllEmpty = false;
  2113. // if (wafer.IsEmpty && GetATMWafer() > 0)
  2114. // {
  2115. // isPrepareTransferForTMRobot = false;
  2116. // break;
  2117. // }
  2118. // if (wafer.ProcessState != EnumWaferProcessStatus.Idle)
  2119. // {
  2120. // isPrepareTransferForTMRobot = false;
  2121. // break;
  2122. // }
  2123. // }
  2124. // if (isAllEmpty)
  2125. // {
  2126. // if (GetVacuumWafer() == 0)
  2127. // {
  2128. // isPrepareTransferForTMRobot = false;
  2129. // }
  2130. // else
  2131. // {
  2132. // foreach (var anotherLL in _lstLls)
  2133. // {
  2134. // if (!anotherLL.IsOnline || anotherLL == ll)
  2135. // continue;
  2136. // var anotherLLWafers = WaferManager.Instance.GetWafers(anotherLL.Module).ToList();
  2137. // int count = 0;
  2138. // for (int i = 0; i <= 5;)
  2139. // {
  2140. // if (WaferManager.Instance.CheckNoWafer(anotherLL.Module, i) && WaferManager.Instance.CheckNoWafer(anotherLL.Module, i + 1))
  2141. // {
  2142. // count++;
  2143. // }
  2144. // i += 2;
  2145. // }
  2146. // if (count >= GetVacuumWafer())
  2147. // {
  2148. // isPrepareTransferForTMRobot = false;
  2149. // break;
  2150. // }
  2151. // }
  2152. // }
  2153. // }
  2154. // if (isPrepareTransferForTMRobot && !ll.Entity.IsPrepareTransferReady(ModuleName.TMRobot, EnumTransferType.Pick))
  2155. // {
  2156. // ll.PrepareTransfer(ModuleName.TMRobot, EnumTransferType.Pick, 0);
  2157. // continue;
  2158. // }
  2159. // }
  2160. }
  2161. private void MonitorPMTask()
  2162. {
  2163. foreach (var pm in _lstPms)
  2164. {
  2165. if (!pm.IsAvailable)
  2166. continue;
  2167. if (WaferManager.Instance.CheckHasWafer(pm.Module, 0) || WaferManager.Instance.CheckHasWafer(pm.Module, 1))
  2168. {
  2169. if (CheckNeedRunClean(pm.Module, out bool withWafer, out string recipe) && withWafer
  2170. && WaferManager.Instance.GetWafer(pm.Module, 0).Status == WaferStatus.Dummy
  2171. && WaferManager.Instance.GetWafer(pm.Module, 0).ProcessState == EnumWaferProcessStatus.Wait
  2172. && WaferManager.Instance.GetWafer(pm.Module, 1).Status == WaferStatus.Dummy
  2173. && WaferManager.Instance.GetWafer(pm.Module, 1).ProcessState == EnumWaferProcessStatus.Wait)
  2174. {
  2175. pm.Process(recipe, true, withWafer);
  2176. continue;
  2177. }
  2178. var wafer0 = WaferManager.Instance.GetWafer(pm.Module, 0);
  2179. var wafer1 = WaferManager.Instance.GetWafer(pm.Module, 1);
  2180. if (CheckCanProcess(pm.Module))
  2181. {
  2182. WaferInfo wafer = wafer0.Status != WaferStatus.Empty ? wafer0 : wafer1;
  2183. if (pm.Process(wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepParameter[$"{pm.Module}Recipe"].ToString(), false, true))
  2184. {
  2185. if (wafer0.Status != WaferStatus.Empty)
  2186. wafer0.NextSequenceStep++;
  2187. if (wafer1.Status != WaferStatus.Empty)
  2188. wafer1.NextSequenceStep++;
  2189. continue;
  2190. }
  2191. }
  2192. }
  2193. else
  2194. {
  2195. if (CheckNeedRunClean(pm.Module, out bool withWafer, out string recipe) && !withWafer)
  2196. {
  2197. pm.Process(recipe, true, withWafer);
  2198. continue;
  2199. }
  2200. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0)
  2201. && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1)
  2202. )
  2203. {
  2204. var _moduleName = ModuleName.LP1;
  2205. if (LPHadCreateJob != "LP1")
  2206. {
  2207. _moduleName = ModuleName.LP2;
  2208. }
  2209. SlotItem item = GetNextWaferInJobQueue(_moduleName);
  2210. if (item != null && CheckWaferNeedProcessPre(item.Module, item.Slot, pm.Module))
  2211. {
  2212. if (GetWaferTemperatureSetInRecipe(item.Module, item.Slot, pm.Module, out double temp1, out double temp2) && !pm.CheckTempReady(temp1, temp2))
  2213. {
  2214. if (temp1 != 0 && temp2 != 0)
  2215. {
  2216. pm.Preheating(temp1, temp2);
  2217. continue;
  2218. }
  2219. }
  2220. }
  2221. }
  2222. }
  2223. //if (!pm.IsAvailable)
  2224. // continue;
  2225. //var wafers = FindAllLoadLockSlotForTMRobotPick();
  2226. //if (wafers.Count > 0)
  2227. //{
  2228. // if (wafers.Any(x => CheckWaferNeedProcess(x.Item1.Module, x.Item2, pm.Module)))
  2229. // {
  2230. // for (int i = 0; i < WaferManager.Instance.GetWafers(pm.Module).Length; i++)
  2231. // {
  2232. // if (WaferManager.Instance.CheckNoWafer(pm.Module, i) && !pm.IsReadyForPlace(ModuleName.TMRobot, Hand.Blade1, i))
  2233. // {
  2234. // pm.PrepareTransfer(ModuleName.TMRobot, EnumTransferType.Place, i);
  2235. // return;
  2236. // }
  2237. // }
  2238. // }
  2239. //}
  2240. //else
  2241. //{
  2242. // if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0)
  2243. // && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1)
  2244. // && WaferManager.Instance.CheckNoWafer(pm.Module, 0)
  2245. // && WaferManager.Instance.CheckNoWafer(pm.Module, 1)
  2246. // && _tmRobot.IsAvailable
  2247. // && !pm.CheckSlitValveClose())
  2248. // {
  2249. // pm.CloseSlitValve();
  2250. // return;
  2251. // }
  2252. //}
  2253. }
  2254. }
  2255. private void MonitorTmRobotTask()
  2256. {
  2257. if (!_tmRobot.IsAvailable)
  2258. return;
  2259. //TM robot is idle, release all the target
  2260. foreach (var ll in _lstLls)
  2261. {
  2262. if (ll.IsWaitTransfer(ModuleName.TMRobot))
  2263. ll.StopWaitTransfer(ModuleName.TMRobot);
  2264. }
  2265. foreach (var pm in _lstPms)
  2266. {
  2267. if (pm.IsWaitTransfer(ModuleName.TMRobot))
  2268. pm.StopWaitTransfer(ModuleName.TMRobot);
  2269. }
  2270. //MonitorTmRobotDummyWaferBufferTask();
  2271. //if (!_tmRobot.IsAvailable)
  2272. // return;
  2273. if (!_tmRobot.IsAvailable)
  2274. return;
  2275. var act = tmRobotActions.Peek();
  2276. act.Invoke();
  2277. if (!_tmRobot.IsAvailable)
  2278. return;
  2279. if (act == MonitorTmRobotLoadLockPickTask)
  2280. {
  2281. List<Tuple<SchedulerLoadLock, int>> availableLoadLockSlots = FindAllLoadLockSlotForTMRobotPick();
  2282. if (availableLoadLockSlots.Count > 0)
  2283. {
  2284. Tuple<SchedulerLoadLock, int> firstSlot = GetWaferOrderInJobQueue(availableLoadLockSlots);
  2285. if (firstSlot != null)
  2286. {
  2287. SchedulerLoadLock ll = firstSlot.Item1;
  2288. int pickSlot = firstSlot.Item2;
  2289. if (!ll.IsAvailable)
  2290. return;
  2291. }
  2292. }
  2293. }
  2294. if (act == MonitorTmRobotLoadLockPlaceTask && _lstLls.All(x => !x.IsAvailable))
  2295. return;
  2296. tmRobotActions.Enqueue(tmRobotActions.Dequeue());
  2297. //MonitorTmRobotLoadLockPickTask();
  2298. //if (!_tmRobot.IsAvailable)
  2299. // return;
  2300. //MonitorTmRobotPMPickTask();
  2301. //if (!_tmRobot.IsAvailable)
  2302. // return;
  2303. //MonitorTmRobotLoadLockPlaceTask();
  2304. //if (!_tmRobot.IsAvailable)
  2305. // return;
  2306. //MonitorTmRobotPMPlaceTask();
  2307. //if (!_tmRobot.IsAvailable)
  2308. // return;
  2309. //MonitorTmRobotGoToTask();
  2310. }
  2311. private void MonitorTmRobotLoadLockPlaceTask()
  2312. {
  2313. if (!_tmRobot.IsAvailable)
  2314. return;
  2315. //place to ll
  2316. bool blade0HasWaferAndProcessed = _tmRobot.Blade1Enable && WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0) && CheckWaferNextStepIsLoadLock(ModuleName.TMRobot, 0);
  2317. bool blade1HasWaferAndProcessed = _tmRobot.Blade2Enable && WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1) && CheckWaferNextStepIsLoadLock(ModuleName.TMRobot, 1);
  2318. if (blade0HasWaferAndProcessed || blade1HasWaferAndProcessed)
  2319. {
  2320. Hand placeBlade = blade0HasWaferAndProcessed ? Hand.Blade1 : Hand.Blade2;
  2321. foreach (var ll in _lstLls)
  2322. {
  2323. if (!ll.IsAvailable)
  2324. continue;
  2325. if (!CheckWaferNextStepIsLoadLock(ModuleName.TMRobot, (int)placeBlade, ll.Module))
  2326. continue;
  2327. int? placeSlot = GetAvilableLoadLockSlotForTMRobotPlace(ll);
  2328. if (placeSlot != null)
  2329. {
  2330. if (_tmRobot.Place(ll.Module, (int)placeSlot, placeBlade, 0, 0, false))
  2331. {
  2332. WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)placeBlade).NextSequenceStep++;
  2333. ll.WaitTransfer(ModuleName.TMRobot);
  2334. return;
  2335. }
  2336. }
  2337. }
  2338. }
  2339. if (GetEmptySlotInPM() < 1)
  2340. return;
  2341. }
  2342. private void MonitorTmRobotLoadLockPickTask()
  2343. {
  2344. if (!_tmRobot.IsAvailable)
  2345. return;
  2346. if (!CanTmRobotLoadLockPick())
  2347. return;
  2348. //pick from ll
  2349. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0) || WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1))
  2350. {
  2351. Hand pickBlade;
  2352. if (_tmRobot.Blade1Enable && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0))
  2353. {
  2354. pickBlade = Hand.Blade1;
  2355. }
  2356. else if (_tmRobot.Blade2Enable && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1))
  2357. {
  2358. pickBlade = Hand.Blade2;
  2359. }
  2360. else
  2361. {
  2362. return;
  2363. }
  2364. //if (_lstLls.All(x => !x.IsAvailable))
  2365. // return;
  2366. List<Tuple<SchedulerLoadLock, int>> availableLoadLockSlots = FindAllLoadLockSlotForTMRobotPick();
  2367. if (availableLoadLockSlots.Count > 0)
  2368. {
  2369. Tuple<SchedulerLoadLock, int> firstSlot = GetWaferOrderInJobQueue(availableLoadLockSlots);
  2370. if (firstSlot != null)
  2371. {
  2372. SchedulerLoadLock ll = firstSlot.Item1;
  2373. int pickSlot = firstSlot.Item2;
  2374. if (!ll.IsAvailable)
  2375. return;
  2376. if (_tmRobot.Pick(ll.Module, (int)pickSlot, pickBlade, 0, 0, false))
  2377. {
  2378. ll.WaitTransfer(ModuleName.TMRobot);
  2379. return;
  2380. }
  2381. }
  2382. }
  2383. }
  2384. }
  2385. private R_TRIG tmRobotGotoLoadLockTrig = new R_TRIG();
  2386. private R_TRIG tmRobotGotoPMTrig = new R_TRIG();
  2387. SchedulerPM gotoPm = null;
  2388. private void MonitorTmRobotGoToTask()
  2389. {
  2390. if (!_tmRobot.IsAvailable)
  2391. return;
  2392. //int gotoSlot = Int32.MaxValue;
  2393. //int gotoModule = -1;
  2394. //int waferOriginSlot = int.MaxValue;
  2395. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0) && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1))
  2396. {
  2397. //PMA、PMB都为空,ll中有需要跑的wafer时,准备tmRobot到ll
  2398. var llWafers = FindAllLoadLockSlotForTMRobotPick();
  2399. tmRobotGotoLoadLockTrig.CLK = llWafers.Count > 0 && !CanTmRobotLoadLockPick() && GetEmptySlotInPMA() == 2 && GetEmptySlotInPMB() == 2;
  2400. if (tmRobotGotoLoadLockTrig.Q)
  2401. {
  2402. if (_tmRobot.Goto(llWafers[0].Item1.Module, llWafers[0].Item2, Hand.Blade1))
  2403. {
  2404. llWafers[0].Item1.WaitTransfer(ModuleName.TMRobot);
  2405. return;
  2406. }
  2407. }
  2408. //PMA、PMB都在工艺过程中,tmRobot移动到先开始工艺的腔体位置
  2409. bool PMAInProcess = _pm1.CheckInProcess();
  2410. bool PMBInProcess = _pm2.CheckInProcess();
  2411. if (PMAInProcess ^ PMBInProcess)
  2412. {
  2413. gotoPm = PMAInProcess ? _pm1 : _pm2;
  2414. }
  2415. if (!PMAInProcess && !PMBInProcess)
  2416. {
  2417. gotoPm = null;
  2418. }
  2419. tmRobotGotoPMTrig.CLK = PMAInProcess && PMBInProcess && gotoPm != null;
  2420. if (tmRobotGotoPMTrig.Q)
  2421. {
  2422. if (_tmRobot.Goto(gotoPm.Module, 0, Hand.Blade1))
  2423. {
  2424. gotoPm.WaitTransfer(ModuleName.TMRobot);
  2425. return;
  2426. }
  2427. }
  2428. }
  2429. }
  2430. private bool CanTmRobotLoadLockPick()
  2431. {
  2432. if (FindAllLoadLockSlotForTMRobotPick().Count <= 1
  2433. && GetUnprocessedWaferCount() >= 1
  2434. && WaferManager.Instance.GetWafers(ModuleName.TMRobot).All(x => x.IsEmpty))
  2435. //&& (CheckWaferNeedProcess(ModuleName.EfemRobot, 0) || CheckWaferNeedProcess(ModuleName.EfemRobot, 1) || CheckWaferNeedProcess(ModuleName.Aligner, 0)))
  2436. return false;
  2437. var tmWafers = WaferManager.Instance.GetWafers(ModuleName.TMRobot);
  2438. for (int i = 0; i < tmWafers.Length; i++)
  2439. {
  2440. if (!tmWafers[i].IsEmpty && !CheckWaferNeedProcess(tmWafers[i]))
  2441. return false;
  2442. }
  2443. foreach (var pm in _lstPms)
  2444. {
  2445. var pmWafer0 = WaferManager.Instance.GetWafer(pm.Module, 0);
  2446. var pmWafer1 = WaferManager.Instance.GetWafer(pm.Module, 1);
  2447. //如果腔体中两片都满了,则跳过
  2448. if (!pmWafer0.IsEmpty && !pmWafer1.IsEmpty)
  2449. continue;
  2450. //如果腔体中一片为空,则取一片相同recipeName的放入
  2451. if (!pmWafer0.IsEmpty || !pmWafer1.IsEmpty)
  2452. {
  2453. var wafer = !pmWafer0.IsEmpty ? pmWafer0 : pmWafer1;
  2454. if (!CheckWaferNeedProcess(wafer))
  2455. continue;
  2456. //判断TMRobot是否已经存在相同recipeName的wafer
  2457. for (int i = 0; i < tmWafers.Length; i++)
  2458. {
  2459. if (CheckWaferNeedProcess(tmWafers[i])
  2460. && tmWafers[i].ProcessJob.Sequence.Name == wafer.ProcessJob.Sequence.Name)
  2461. return false;
  2462. }
  2463. }
  2464. }
  2465. return true;
  2466. }
  2467. //private void MonitorTmRobotDummyWaferBufferTask()
  2468. //{
  2469. // if (!_tmRobot.IsAvailable)
  2470. // return;
  2471. // //place to buffer
  2472. // bool blade0HasWaferAndProcessedDummy = WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0) &&
  2473. // WaferManager.Instance.GetWafer(ModuleName.TMRobot, 0).Status == WaferStatus.Dummy &&
  2474. // WaferManager.Instance.GetWafer(ModuleName.TMRobot, 0).ProcessState == EnumWaferProcessStatus.Completed;
  2475. // bool blade1HasWaferAndProcessedDummy = WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1) &&
  2476. // WaferManager.Instance.GetWafer(ModuleName.TMRobot, 1).Status == WaferStatus.Dummy &&
  2477. // WaferManager.Instance.GetWafer(ModuleName.TMRobot, 1).ProcessState == EnumWaferProcessStatus.Completed;
  2478. // if (blade0HasWaferAndProcessedDummy || blade1HasWaferAndProcessedDummy)
  2479. // {
  2480. // Hand placeBlade = blade0HasWaferAndProcessedDummy ? Hand.Blade1 : Hand.Blade2;
  2481. // if (blade0HasWaferAndProcessedDummy && blade1HasWaferAndProcessedDummy)
  2482. // {
  2483. // if (WaferManager.Instance.GetWafer(ModuleName.TMRobot, 1).OriginSlot <
  2484. // WaferManager.Instance.GetWafer(ModuleName.TMRobot, 0).OriginSlot)
  2485. // {
  2486. // placeBlade = Hand.Blade2;
  2487. // }
  2488. // }
  2489. // int placeSlot = WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)placeBlade).OriginSlot;
  2490. // if (WaferManager.Instance.CheckNoWafer(_pm1.Module, placeSlot) && _pm1.IsReadyForPlace(ModuleName.TMRobot, placeBlade, placeSlot))
  2491. // {
  2492. // if (_tmRobot.Place(_pm1.Module, placeSlot, placeBlade))
  2493. // {
  2494. // _pm1.WaitTransfer(ModuleName.TMRobot);
  2495. // return;
  2496. // }
  2497. // }
  2498. // }
  2499. // if (!_tmRobot.IsAvailable)
  2500. // return;
  2501. // //pick from buffer
  2502. // foreach (var schedulerPm in _lstPms)
  2503. // {
  2504. // if (!CheckNeedRunClean(schedulerPm.Module, out bool withWafer, out string _) || !withWafer)
  2505. // continue;
  2506. // if (WaferManager.Instance.CheckHasWafer(schedulerPm.Module, 0))
  2507. // continue;
  2508. // if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0) ||
  2509. // WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1))
  2510. // {
  2511. // Hand pickBlade = WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0)
  2512. // ? Hand.Blade1
  2513. // : Hand.Blade2;
  2514. // for (int i = 0; i < 2; i++)
  2515. // {
  2516. // if ((WaferManager.Instance.GetWafer(_pm1.Module, i).ProcessState == EnumWaferProcessStatus.Wait)
  2517. // && _pm1.IsReadyForPick(ModuleName.TMRobot, pickBlade, i))
  2518. // {
  2519. // if (_tmRobot.Pick(_pm1.Module, i, pickBlade))
  2520. // {
  2521. // _pm1.WaitTransfer(ModuleName.TMRobot);
  2522. // return;
  2523. // }
  2524. // }
  2525. // }
  2526. // }
  2527. // }
  2528. //}
  2529. private void MonitorTmRobotPMAPlaceTask()
  2530. {
  2531. //if (!_pm1.IsAvailable)
  2532. // return;
  2533. //if (_tmRobot.HasWafer(0) && CheckWaferNeedProcess(ModuleName.TMRobot, 0, _pm1.Module))
  2534. //{
  2535. // if (WaferManager.Instance.CheckNoWafer(_pm1.Module, 0) && !_pm1.IsReadyForPlace(ModuleName.TMRobot, Hand.Blade1, 0))
  2536. // {
  2537. // _pm1.PrepareTransfer(ModuleName.TMRobot, EnumTransferType.Place, 0);
  2538. // return;
  2539. // }
  2540. // if (WaferManager.Instance.CheckNoWafer(_pm1.Module, 1) && !_pm1.IsReadyForPlace(ModuleName.TMRobot, Hand.Blade1, 1))
  2541. // {
  2542. // _pm1.PrepareTransfer(ModuleName.TMRobot, EnumTransferType.Place, 1);
  2543. // return;
  2544. // }
  2545. //}
  2546. //if (_tmRobot.HasWafer(1) && CheckWaferNeedProcess(ModuleName.TMRobot, 1, _pm1.Module))
  2547. //{
  2548. // if (WaferManager.Instance.CheckNoWafer(_pm1.Module, 0) && !_pm1.IsReadyForPlace(ModuleName.TMRobot, Hand.Blade1, 0))
  2549. // {
  2550. // _pm1.PrepareTransfer(ModuleName.TMRobot, EnumTransferType.Place, 0);
  2551. // return;
  2552. // }
  2553. // if (WaferManager.Instance.CheckNoWafer(_pm1.Module, 1) && !_pm1.IsReadyForPlace(ModuleName.TMRobot, Hand.Blade1, 1))
  2554. // {
  2555. // _pm1.PrepareTransfer(ModuleName.TMRobot, EnumTransferType.Place, 1);
  2556. // return;
  2557. // }
  2558. //}
  2559. if (!_tmRobot.IsAvailable)
  2560. return;
  2561. //place
  2562. bool blade0HasWaferAndNeedProcesse = _tmRobot.Blade1Enable && WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0) && CheckWaferNeedProcess(ModuleName.TMRobot, 0);
  2563. bool blade1HasWaferAndNeedProcesse = _tmRobot.Blade2Enable && WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1) && CheckWaferNeedProcess(ModuleName.TMRobot, 1);
  2564. if (blade0HasWaferAndNeedProcesse || blade1HasWaferAndNeedProcesse)
  2565. {
  2566. Hand placeBlade = blade0HasWaferAndNeedProcesse ? Hand.Blade1 : Hand.Blade2;
  2567. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)placeBlade);
  2568. //foreach (var schedulerPm in _lstPms)
  2569. {
  2570. var schedulerPm = _pm1;
  2571. if (!schedulerPm.IsAvailable)
  2572. return;
  2573. var pmWafer0 = WaferManager.Instance.GetWafer(schedulerPm.Module, 0);
  2574. var pmWafer1 = WaferManager.Instance.GetWafer(schedulerPm.Module, 1);
  2575. //如果腔体中两片都满了,则不允许放入
  2576. if (!pmWafer0.IsEmpty && !pmWafer1.IsEmpty)
  2577. return;
  2578. //如果腔体中两片都为空,则取一片放入
  2579. if (pmWafer0.IsEmpty && pmWafer1.IsEmpty)
  2580. {
  2581. if (WaferManager.Instance.CheckNoWafer(schedulerPm.Module, 0)
  2582. && CheckCanPlaceWaferToPM(schedulerPm.Module, wafer))
  2583. {
  2584. if (GetWaferTemperatureSetInRecipe(ModuleName.TMRobot, (int)placeBlade, ModuleName.PMA, out double temp1, out double temp2))
  2585. {
  2586. if (_tmRobot.Place(schedulerPm.Module, 0, placeBlade, temp1, temp2, true))
  2587. {
  2588. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  2589. return;
  2590. }
  2591. }
  2592. }
  2593. }
  2594. //如果腔体中一片为空,则取一片相同recipeName的放入
  2595. if (!pmWafer0.IsEmpty || !pmWafer1.IsEmpty)
  2596. {
  2597. var pmWafer = !pmWafer0.IsEmpty ? pmWafer0 : pmWafer1;
  2598. if (!CheckWaferNeedProcess(pmWafer))
  2599. return;
  2600. int placeSlot = pmWafer0.IsEmpty ? 0 : 1;
  2601. if (WaferManager.Instance.CheckNoWafer(schedulerPm.Module, placeSlot)
  2602. && CheckCanPlaceWaferToPM(schedulerPm.Module, wafer))
  2603. {
  2604. if (GetWaferTemperatureSetInRecipe(ModuleName.TMRobot, (int)placeBlade, ModuleName.PMA, out double temp1, out double temp2))
  2605. {
  2606. if (_tmRobot.Place(schedulerPm.Module, placeSlot, placeBlade, temp1, temp2, true))
  2607. {
  2608. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  2609. return;
  2610. }
  2611. }
  2612. }
  2613. }
  2614. }
  2615. }
  2616. }
  2617. private void MonitorTmRobotPMBPlaceTask()
  2618. {
  2619. //if (!_pm2.IsAvailable)
  2620. // return;
  2621. //if (_tmRobot.HasWafer(0) && CheckWaferNeedProcess(ModuleName.TMRobot, 0, _pm2.Module))
  2622. //{
  2623. // if (WaferManager.Instance.CheckNoWafer(_pm2.Module, 0) && !_pm2.IsReadyForPlace(ModuleName.TMRobot, Hand.Blade1, 0))
  2624. // {
  2625. // _pm2.PrepareTransfer(ModuleName.TMRobot, EnumTransferType.Place, 0);
  2626. // return;
  2627. // }
  2628. // if (WaferManager.Instance.CheckNoWafer(_pm2.Module, 1) && !_pm2.IsReadyForPlace(ModuleName.TMRobot, Hand.Blade1, 1))
  2629. // {
  2630. // _pm2.PrepareTransfer(ModuleName.TMRobot, EnumTransferType.Place, 1);
  2631. // return;
  2632. // }
  2633. //}
  2634. //if (_tmRobot.HasWafer(1) && CheckWaferNeedProcess(ModuleName.TMRobot, 1, _pm2.Module))
  2635. //{
  2636. // if (WaferManager.Instance.CheckNoWafer(_pm2.Module, 0) && !_pm2.IsReadyForPlace(ModuleName.TMRobot, Hand.Blade1, 0))
  2637. // {
  2638. // _pm2.PrepareTransfer(ModuleName.TMRobot, EnumTransferType.Place, 0);
  2639. // return;
  2640. // }
  2641. // if (WaferManager.Instance.CheckNoWafer(_pm2.Module, 1) && !_pm2.IsReadyForPlace(ModuleName.TMRobot, Hand.Blade1, 1))
  2642. // {
  2643. // _pm2.PrepareTransfer(ModuleName.TMRobot, EnumTransferType.Place, 1);
  2644. // return;
  2645. // }
  2646. //}
  2647. if (!_tmRobot.IsAvailable)
  2648. return;
  2649. //place
  2650. bool blade0HasWaferAndNeedProcesse = _tmRobot.Blade1Enable && WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0) && CheckWaferNeedProcess(ModuleName.TMRobot, 0);
  2651. bool blade1HasWaferAndNeedProcesse = _tmRobot.Blade2Enable && WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1) && CheckWaferNeedProcess(ModuleName.TMRobot, 1);
  2652. if (blade0HasWaferAndNeedProcesse || blade1HasWaferAndNeedProcesse)
  2653. {
  2654. Hand placeBlade = blade0HasWaferAndNeedProcesse ? Hand.Blade1 : Hand.Blade2;
  2655. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)placeBlade);
  2656. //foreach (var schedulerPm in _lstPms)
  2657. {
  2658. var schedulerPm = _pm2;
  2659. if (!schedulerPm.IsAvailable)
  2660. return;
  2661. var pmWafer0 = WaferManager.Instance.GetWafer(schedulerPm.Module, 0);
  2662. var pmWafer1 = WaferManager.Instance.GetWafer(schedulerPm.Module, 1);
  2663. //如果腔体中两片都满了,则不允许放入
  2664. if (!pmWafer0.IsEmpty && !pmWafer1.IsEmpty)
  2665. return;
  2666. //如果腔体中两片都为空,则取一片放入
  2667. if (pmWafer0.IsEmpty && pmWafer1.IsEmpty)
  2668. {
  2669. if (WaferManager.Instance.CheckNoWafer(schedulerPm.Module, 0)
  2670. && CheckCanPlaceWaferToPM(schedulerPm.Module, wafer))
  2671. {
  2672. if (GetWaferTemperatureSetInRecipe(ModuleName.TMRobot, (int)placeBlade, ModuleName.PMB, out double temp1, out double temp2))
  2673. {
  2674. if (_tmRobot.Place(schedulerPm.Module, 0, placeBlade, temp1, temp2, true))
  2675. {
  2676. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  2677. return;
  2678. }
  2679. }
  2680. }
  2681. }
  2682. //如果腔体中一片为空,则取一片相同recipeName的放入
  2683. if (!pmWafer0.IsEmpty || !pmWafer1.IsEmpty)
  2684. {
  2685. var pmWafer = !pmWafer0.IsEmpty ? pmWafer0 : pmWafer1;
  2686. if (!CheckWaferNeedProcess(pmWafer))
  2687. return;
  2688. int placeSlot = pmWafer0.IsEmpty ? 0 : 1;
  2689. if (WaferManager.Instance.CheckNoWafer(schedulerPm.Module, placeSlot)
  2690. && CheckCanPlaceWaferToPM(schedulerPm.Module, wafer))
  2691. {
  2692. if (GetWaferTemperatureSetInRecipe(ModuleName.TMRobot, (int)placeBlade, ModuleName.PMB, out double temp1, out double temp2))
  2693. {
  2694. if (_tmRobot.Place(schedulerPm.Module, placeSlot, placeBlade, temp1, temp2, true))
  2695. {
  2696. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  2697. return;
  2698. }
  2699. }
  2700. }
  2701. }
  2702. }
  2703. }
  2704. }
  2705. private void MonitorTmRobotPMAPickTask()
  2706. {
  2707. if (!_tmRobot.IsAvailable)
  2708. return;
  2709. // pick
  2710. if ((WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0) || WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1)))
  2711. {
  2712. Hand pickBlade;
  2713. if (_tmRobot.Blade1Enable && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0))
  2714. {
  2715. pickBlade = Hand.Blade1;
  2716. }
  2717. else if (_tmRobot.Blade2Enable && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1))
  2718. {
  2719. pickBlade = Hand.Blade2;
  2720. }
  2721. else
  2722. {
  2723. return;
  2724. }
  2725. //foreach (var schedulerPm in _lstPms)
  2726. {
  2727. var schedulerPm = _pm1;
  2728. if (!schedulerPm.IsAvailable)
  2729. return;
  2730. if (CheckCanPickWaferFromPM(schedulerPm.Module, 0))
  2731. {
  2732. if (GetWaferTemperatureSetInRecipe(schedulerPm.Module, 0, ModuleName.PMA, out double temp1, out double temp2))
  2733. {
  2734. if (_tmRobot.Pick(schedulerPm.Module, 0, pickBlade, temp1, temp2, true))
  2735. {
  2736. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  2737. return;
  2738. }
  2739. }
  2740. }
  2741. if (CheckCanPickWaferFromPM(schedulerPm.Module, 1))
  2742. {
  2743. if (GetWaferTemperatureSetInRecipe(schedulerPm.Module, 1, ModuleName.PMA, out double temp1, out double temp2))
  2744. {
  2745. if (_tmRobot.Pick(schedulerPm.Module, 1, pickBlade, temp1, temp2, true))
  2746. {
  2747. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  2748. return;
  2749. }
  2750. }
  2751. }
  2752. }
  2753. }
  2754. }
  2755. private void MonitorTmRobotPMBPickTask()
  2756. {
  2757. if (!_tmRobot.IsAvailable)
  2758. return;
  2759. // pick
  2760. if ((WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0) || WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1)))
  2761. {
  2762. Hand pickBlade;
  2763. if (_tmRobot.Blade1Enable && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0))
  2764. {
  2765. pickBlade = Hand.Blade1;
  2766. }
  2767. else if (_tmRobot.Blade2Enable && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1))
  2768. {
  2769. pickBlade = Hand.Blade2;
  2770. }
  2771. else
  2772. {
  2773. return;
  2774. }
  2775. //foreach (var schedulerPm in _lstPms)
  2776. {
  2777. var schedulerPm = _pm2;
  2778. if (!schedulerPm.IsAvailable)
  2779. return;
  2780. if (CheckCanPickWaferFromPM(schedulerPm.Module, 0))
  2781. {
  2782. if (GetWaferTemperatureSetInRecipe(schedulerPm.Module, 0, ModuleName.PMB, out double temp1, out double temp2))
  2783. {
  2784. if (_tmRobot.Pick(schedulerPm.Module, 0, pickBlade, temp1, temp2, true))
  2785. {
  2786. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  2787. return;
  2788. }
  2789. }
  2790. }
  2791. if (CheckCanPickWaferFromPM(schedulerPm.Module, 1))
  2792. {
  2793. if (GetWaferTemperatureSetInRecipe(schedulerPm.Module, 1, ModuleName.PMB, out double temp1, out double temp2))
  2794. {
  2795. if (_tmRobot.Pick(schedulerPm.Module, 1, pickBlade, temp1, temp2, true))
  2796. {
  2797. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  2798. return;
  2799. }
  2800. }
  2801. }
  2802. }
  2803. }
  2804. }
  2805. static readonly List<string> llNameList = new List<string>()
  2806. { "IsAvailable", "Task", "IsOnline", "IsError" , "IsIdle", "IsBusy", "IsPrepareTransfer", "IsCooling", "IsAtm", "IsVacuum", "Cooling", "WaitTransfer"
  2807. , "Wafer0", "Wafer1", "Wafer2", "Wafer3", "Wafer4", "Wafer5"
  2808. , "NextStep0", "NextStep1", "NextStep2", "NextStep3", "NextStep4", "NextStep5"
  2809. , "need0", "need1", "need2", "need3", "need4", "need5"};
  2810. static readonly List<string> efemNameList = new List<string>()
  2811. { "IsAvailable","IsOnline","IsReady","Task","IsError"," WaitTransfer"
  2812. , "Wafer0", "Wafer1", "Wafer2"
  2813. , "NextStep0", "NextStep1", "NextStep2"
  2814. , "need0", "need1", "need2"};
  2815. static readonly List<string> tmRobotNameList = new List<string>()
  2816. { "IsAvailable","IsOnline","IsError","Task","IsError"," WaitTransfer"
  2817. , "Wafer0", "Wafer1", "Wafer2", "Wafer3"
  2818. , "NextStep0", "NextStep1", "NextStep2", "NextStep3"
  2819. , "need0", "need1", "need2", "need3"};
  2820. static readonly List<string> pmNameList = new List<string>()
  2821. { "IsAvailable","IsOnline","IsError","TaskDone","IsError"," WaitTransfer"
  2822. , "Wafer0", "Wafer1", "Wafer2", "Wafer3"
  2823. , "NextStep0", "NextStep1", "NextStep2", "NextStep3"
  2824. , "need0", "need1", "need2", "need3"};
  2825. static readonly List<string> lpNameList = new List<string>()
  2826. { "IsAvailable","Task","IsOnline","IsError","IsReady"};
  2827. private int _GetWaferNextStepId(ModuleName module, int slotId)
  2828. {
  2829. if (!WaferManager.Instance.IsWaferSlotLocationValid(module, slotId)) return -1;
  2830. var wafer = WaferManager.Instance.GetWafer(module, slotId);
  2831. return wafer.NextSequenceStep;
  2832. }
  2833. private string _GetWaferOrigin(ModuleName module, int slotId)
  2834. {
  2835. if (!WaferManager.Instance.IsWaferSlotLocationValid(module, slotId)) return "";
  2836. var wafer = WaferManager.Instance.GetWafer(module, slotId);
  2837. return wafer.WaferOrigin;
  2838. }
  2839. private void MonitorEfemRobotTask()
  2840. {
  2841. if (!_efem.IsAvailable)
  2842. return;
  2843. ////efem robot is idle, release all the target
  2844. foreach (var ll in _lstLls)
  2845. {
  2846. if (ll.IsWaitTransfer(ModuleName.EfemRobot))
  2847. ll.StopWaitTransfer(ModuleName.EfemRobot);
  2848. }
  2849. if (_aligner.IsWaitTransfer(ModuleName.EfemRobot))
  2850. _aligner.StopWaitTransfer(ModuleName.EfemRobot);
  2851. foreach (var lp in _lstLps)
  2852. {
  2853. if (lp.IsWaitTransfer(ModuleName.EfemRobot))
  2854. lp.StopWaitTransfer(ModuleName.EfemRobot);
  2855. }
  2856. if (!_efem.IsAvailable)
  2857. return;
  2858. var act = efemRobotActions.Peek();
  2859. act.Invoke();
  2860. if (!_efem.IsAvailable)
  2861. return;
  2862. efemRobotActions.Enqueue(efemRobotActions.Dequeue());
  2863. //if (!_efem.IsAvailable)
  2864. // return;
  2865. //MonitorEfemRobotAlignerTask();
  2866. //if (!_efem.IsAvailable)
  2867. // return;
  2868. //MonitorEfemRobotLoadLockTask();
  2869. //if (_aligner.HasWafer(0) && (!_efem.Blade1Enable || !_efem.Blade2Enable))
  2870. // return;
  2871. //if (_aligner.HasWafer(0) && (_efem.HasWafer(0) || _efem.HasWafer(1)))
  2872. // return;
  2873. //if (!_efem.IsAvailable)
  2874. // return;
  2875. //MonitorEfemRobotLoadPortTask();
  2876. //MonitorEfemRobotGoToTask();
  2877. }
  2878. private void MonitorEfemRobotLoadPortPlaceTask()
  2879. {
  2880. if (!_efem.IsAvailable)
  2881. return;
  2882. //place
  2883. bool blade0HasWaferAndProcessed = _efem.Blade1Enable && WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0) &&
  2884. !CheckWaferNeedProcess(ModuleName.EfemRobot, 0);
  2885. bool blade1HasWaferAndProcessed = _efem.Blade2Enable && WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1) &&
  2886. !CheckWaferNeedProcess(ModuleName.EfemRobot, 1);
  2887. if (blade0HasWaferAndProcessed || blade1HasWaferAndProcessed)
  2888. {
  2889. Hand placeBlade = blade0HasWaferAndProcessed ? Hand.Blade1 : Hand.Blade2;
  2890. if (blade0HasWaferAndProcessed && blade1HasWaferAndProcessed)
  2891. {
  2892. if (WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 1).OriginSlot <
  2893. WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 0).OriginSlot)
  2894. {
  2895. placeBlade = Hand.Blade2;
  2896. }
  2897. }
  2898. SlotItem destination = GetWaferReturnLoadPort(ModuleName.EfemRobot, (int)placeBlade);
  2899. if (destination != null && ModuleHelper.IsLoadPort(destination.Module))
  2900. {
  2901. SchedulerLoadPort lp = (SchedulerLoadPort)GetModule(destination.Module.ToString());
  2902. if (lp.IsReadyForPlace(ModuleName.EfemRobot, placeBlade, destination.Slot))
  2903. {
  2904. if (_efem.Place(destination.Module, destination.Slot, placeBlade))
  2905. {
  2906. lp.WaitTransfer(ModuleName.EfemRobot);
  2907. if (_CycleData.IsCycleMode)
  2908. _CycleData.IncreaseWaferCount(1);
  2909. //_cycledTotalWafer++;
  2910. //if (SC.ContainsItem("System.TotalCycledWafer"))
  2911. // SC.SetItemValue("System.TotalCycledWafer", _cycledTotalWafer);
  2912. return;
  2913. }
  2914. }
  2915. }
  2916. }
  2917. }
  2918. private void MonitorEfemRobotLoadPortPickTask()
  2919. {
  2920. if (!_efem.IsAvailable)
  2921. return;
  2922. if (_aligner.HasWafer(0) && (!_efem.Blade1Enable || !_efem.Blade2Enable))
  2923. return;
  2924. if (_aligner.HasWafer(0) && (_efem.HasWafer(0) || _efem.HasWafer(1)))
  2925. return;
  2926. if (_lstLls.Any(x => GetEmptySlotInLoadLock(x) < 4))
  2927. return;
  2928. //pick
  2929. bool isBlade0Empty = _efem.Blade1Enable && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0);
  2930. bool isBlade1Empty = _efem.Blade2Enable && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1);
  2931. if (GetWaferCountInJobQueue() > 0 && (isBlade0Empty || isBlade1Empty) && EfemRobotPickAllowable)
  2932. {
  2933. Hand pickBlade = isBlade1Empty ? Hand.Blade2 : Hand.Blade1;
  2934. SlotItem position = GetWaferInJobQueue();
  2935. if (position != null)
  2936. {
  2937. SchedulerLoadPort lp = GetModule(position.Module.ToString()) as SchedulerLoadPort;
  2938. if (lp != null && lp.IsReadyForPick(ModuleName.EfemRobot, pickBlade, position.Slot))
  2939. {
  2940. //WaferManager.Instance.GetWafer(position.Module, position.Slot).NextSequenceStep++;
  2941. if (_efem.Pick(position.Module, position.Slot, pickBlade))
  2942. {
  2943. lp.WaitTransfer(ModuleName.EfemRobot);
  2944. return;
  2945. }
  2946. }
  2947. }
  2948. }
  2949. }
  2950. private bool GetWaferProcessAccess(WaferInfo wafer)
  2951. {
  2952. if (wafer.ProcessJob == null || string.IsNullOrEmpty(wafer.ProcessJob.Name))
  2953. return false;
  2954. return GetPMOccupiedCount(wafer.ProcessJob.Name) > GetWaitingProcessWaferCount(wafer.ProcessJob.Name);
  2955. }
  2956. private int GetPMOccupiedCount(string pjName)
  2957. {
  2958. List<ModuleName> location = new List<ModuleName>();
  2959. foreach (var pj in _lstProcessJobs)
  2960. {
  2961. if (pj.Name != pjName)
  2962. continue;
  2963. if (pj.State != EnumProcessJobState.Processing)
  2964. continue;
  2965. foreach (var step in pj.Sequence.Steps)
  2966. {
  2967. foreach (var module in step.StepModules)
  2968. {
  2969. if (ModuleHelper.IsPm(module) && !location.Exists(x => x == module))
  2970. location.Add(module);
  2971. }
  2972. }
  2973. }
  2974. return location.Count;
  2975. }
  2976. private int GetWaitingProcessWaferCount(string pjName)
  2977. {
  2978. List<Tuple<ModuleName, int>> location = new List<Tuple<ModuleName, int>>()
  2979. {
  2980. Tuple.Create(ModuleName.TMRobot, 0),
  2981. Tuple.Create(ModuleName.TMRobot, 1),
  2982. Tuple.Create(ModuleName.LLA, 0),
  2983. Tuple.Create(ModuleName.LLB, 0),
  2984. Tuple.Create(ModuleName.AlignerB, 0),
  2985. Tuple.Create(ModuleName.PMA, 0),
  2986. Tuple.Create(ModuleName.PMB, 0),
  2987. Tuple.Create(ModuleName.PMC, 0),
  2988. };
  2989. int count = 0;
  2990. foreach (var tuple in location)
  2991. {
  2992. WaferInfo wafer = WaferManager.Instance.GetWafer(tuple.Item1, tuple.Item2);
  2993. if (wafer.IsEmpty)
  2994. continue;
  2995. if (wafer.ProcessJob != null && wafer.ProcessJob.Name == pjName)
  2996. count++;
  2997. }
  2998. return count;
  2999. }
  3000. Dictionary<string, Dictionary<string, List<object>>> _ValueDict = new Dictionary<string, Dictionary<string, List<object>>>();
  3001. //private void PrintVariables(string key, List<string> names, params object[] values)
  3002. //{
  3003. // StackTrace trace = new StackTrace(true);
  3004. // var frames = trace.GetFrames();//1代表上级,2代表上上级,以此类推
  3005. // if (frames.Length < 2) return;
  3006. // var frame1 = frames[1];
  3007. // var method1 = frame1.GetMethod();
  3008. // if (method1 == null) return;
  3009. // string methodName = method1.Name;
  3010. // var newList = values.ToList();
  3011. // if (!_ValueDict.ContainsKey(methodName))
  3012. // {
  3013. // _ValueDict[methodName] = new Dictionary<string, List<object>>() { { key, newList } };
  3014. // LOG.Debug($"{methodName} Key={key} Values({_ToString(names, newList)})");
  3015. // }
  3016. // else
  3017. // {
  3018. // var dict = _ValueDict[methodName];
  3019. // if (dict.ContainsKey(key))
  3020. // {
  3021. // var list = dict[key];
  3022. // StringBuilder builder = new StringBuilder();
  3023. // for (int ii = 0; ii < names.Count; ii++)
  3024. // {
  3025. // if (list[ii].Equals(newList[ii])) continue;
  3026. // builder.Append($",{names[ii]}({list[ii]} --> {newList[ii]})");
  3027. // list[ii] = newList[ii];
  3028. // }
  3029. // if (builder.Length > 0)
  3030. // {
  3031. // LOG.Debug($"{methodName} Key={key} {builder.ToString()}");
  3032. // }
  3033. // }
  3034. // else
  3035. // {
  3036. // _ValueDict[methodName].Add(key, newList);
  3037. // LOG.Debug($"{methodName} Key={key} Values({_ToString(names, newList)})");
  3038. // }
  3039. // }
  3040. //}
  3041. private string _ToString(List<string> names, List<object> objList)
  3042. {
  3043. StringBuilder builder = new StringBuilder();
  3044. for (int ii = 0; ii < names.Count; ii++)
  3045. {
  3046. builder.Append($",{names[ii]}={objList[ii]}");
  3047. }
  3048. return builder.ToString().Trim(',');
  3049. }
  3050. private void MonitorEfemRobotLoadLockPickTask()
  3051. {
  3052. if (!_efem.IsAvailable)
  3053. return;
  3054. foreach (var ll in _lstLls)
  3055. {
  3056. if (!ll.IsAvailable)
  3057. continue;
  3058. //pick
  3059. bool blade1EmptyAndEnable = _efem.Blade1Enable && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0);
  3060. bool blade2EmptyAndEnable = _efem.Blade2Enable && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1);
  3061. if (blade1EmptyAndEnable || blade2EmptyAndEnable)
  3062. {
  3063. if (CheckWaferNeedProcess(ModuleName.EfemRobot, 0) || CheckWaferNeedProcess(ModuleName.EfemRobot, 1))
  3064. continue;
  3065. Hand pickBlade = blade2EmptyAndEnable ? Hand.Blade2 : Hand.Blade1;
  3066. int pickSlot = Int32.MaxValue;
  3067. for (int i = 0; i < 8; i++)
  3068. {
  3069. if (!CheckWaferNeedProcess(ll.Module, i) &&
  3070. ll.IsReadyForPick(ModuleName.EfemRobot, pickBlade, i))
  3071. {
  3072. pickSlot = i;
  3073. break;
  3074. }
  3075. }
  3076. if (pickSlot != Int32.MaxValue)
  3077. {
  3078. //WaferManager.Instance.GetWafer(ll.Module, pickSlot).NextSequenceStep++;
  3079. if (_efem.Pick(ll.Module, pickSlot, pickBlade))
  3080. {
  3081. ll.WaitTransfer(ModuleName.EfemRobot);
  3082. return;
  3083. }
  3084. }
  3085. }
  3086. }
  3087. if (!_efem.IsAvailable)
  3088. return;
  3089. }
  3090. private void MonitorEfemRobotLoadLockPlaceTask()
  3091. {
  3092. if (!_efem.IsAvailable)
  3093. return;
  3094. //place
  3095. foreach (var ll in _lstLls)
  3096. {
  3097. if (!ll.IsAvailable)
  3098. continue;
  3099. bool blade1NeedPlace = _efem.Blade1Enable && WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0) && CheckWaferNeedProcess(ModuleName.EfemRobot, 0) && !CheckWaferNextStepIsAlign(ModuleName.EfemRobot, 0);
  3100. bool blade2NeedPlace = _efem.Blade2Enable && WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1) && CheckWaferNeedProcess(ModuleName.EfemRobot, 1) && !CheckWaferNextStepIsAlign(ModuleName.EfemRobot, 1);
  3101. if (!blade1NeedPlace && !blade2NeedPlace)
  3102. {
  3103. EfemRobotPickAllowable = true;
  3104. }
  3105. else
  3106. {
  3107. EfemRobotPickAllowable = false;
  3108. }
  3109. if (blade1NeedPlace || blade2NeedPlace)
  3110. {
  3111. Hand placeBlade = blade1NeedPlace ? Hand.Blade1 : Hand.Blade2;
  3112. if (!CheckWaferNextStepIsLoadLock(ModuleName.EfemRobot, (int)placeBlade, ll.Module))
  3113. continue;
  3114. int placeSlot = Int32.MaxValue;
  3115. if (blade1NeedPlace || blade2NeedPlace)
  3116. {
  3117. for (int i = 0; i < 6; i++)
  3118. {
  3119. if (ll.IsReadyForPlace(ModuleName.EfemRobot, placeBlade, i))
  3120. {
  3121. placeSlot = i;
  3122. break;
  3123. }
  3124. }
  3125. }
  3126. if (placeSlot != Int32.MaxValue)
  3127. {
  3128. if (_efem.Place(ll.Module, (int)placeSlot, placeBlade))
  3129. {
  3130. WaferManager.Instance.GetWafer(ModuleName.EfemRobot, (int)placeBlade).NextSequenceStep++;
  3131. ll.WaitTransfer(ModuleName.EfemRobot);
  3132. return;
  3133. }
  3134. }
  3135. }
  3136. }
  3137. }
  3138. private void MonitorEfemRobotAlignerPickTask()
  3139. {
  3140. if (!_efem.IsAvailable)
  3141. return;
  3142. if (!_aligner.IsAvailable)
  3143. return;
  3144. //pick from aligner
  3145. if (WaferManager.Instance.CheckHasWafer(ModuleName.Aligner, 0) && !CheckWaferNextStepIsAlign(ModuleName.Aligner, 0))
  3146. {
  3147. bool blade1EmptyAndEnable = _efem.Blade1Enable && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0);
  3148. bool blade2EmptyAndEnable = _efem.Blade2Enable && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1);
  3149. if (blade1EmptyAndEnable || blade2EmptyAndEnable)
  3150. {
  3151. Hand pickBlade = blade1EmptyAndEnable ? Hand.Blade1 : Hand.Blade2;
  3152. //if ((blade1Empty && blade2Empty))
  3153. {
  3154. if (_aligner.IsReadyForPick(ModuleName.EfemRobot, pickBlade, 0))
  3155. {
  3156. if (_efem.Pick(_aligner.Module, 0, pickBlade))
  3157. {
  3158. _aligner.WaitTransfer(ModuleName.EfemRobot);
  3159. return;
  3160. }
  3161. }
  3162. }
  3163. }
  3164. }
  3165. if (!_efem.IsAvailable)
  3166. return;
  3167. }
  3168. private void MonitorEfemRobotAlignerPlaceTask()
  3169. {
  3170. if (!_efem.IsAvailable)
  3171. return;
  3172. //place to aligner
  3173. if (WaferManager.Instance.CheckNoWafer(ModuleName.Aligner, 0))
  3174. {
  3175. bool blade1NeedAlign = _efem.Blade1Enable && WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0) &&
  3176. CheckWaferNextStepIsAlign(ModuleName.EfemRobot, 0);
  3177. bool blade2NeedAlign = _efem.Blade2Enable && WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1) &&
  3178. CheckWaferNextStepIsAlign(ModuleName.EfemRobot, 1);
  3179. if (blade1NeedAlign || blade2NeedAlign)
  3180. {
  3181. Hand placeBlade = blade1NeedAlign ? Hand.Blade1 : Hand.Blade2;
  3182. if (blade1NeedAlign && blade2NeedAlign &&
  3183. WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 1).OriginSlot <
  3184. WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 0).OriginSlot)
  3185. placeBlade = Hand.Blade2;
  3186. if (_aligner.IsReadyForPlace(ModuleName.EfemRobot, placeBlade, 0))
  3187. {
  3188. if (_efem.Place(_aligner.Module, 0, placeBlade))
  3189. {
  3190. _aligner.WaitTransfer(ModuleName.EfemRobot);
  3191. return;
  3192. }
  3193. }
  3194. }
  3195. }
  3196. }
  3197. //private void MonitorEfemRobotGoToTask()
  3198. //{
  3199. // if (!_efem.IsAvailable)
  3200. // return;
  3201. // SchedulerLoadLock gotoLL = null;
  3202. // Hand gotoBlade = Hand.Both;
  3203. // int gotoSlot = int.MaxValue;
  3204. // bool arm1Empty = WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0) && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1);
  3205. // bool arm2Empty = WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 2);
  3206. // foreach (var ll in _lstLls)
  3207. // {
  3208. // if (!ll.IsOnline)
  3209. // continue;
  3210. // if (!ll.Entity.IsPrepareTransfer)
  3211. // continue;
  3212. // if (arm1Empty && arm2Empty)
  3213. // {
  3214. // for (int i = 0; i <= 5; i++)
  3215. // {
  3216. // var wafer = WaferManager.Instance.GetWafer(ll.Module, i);
  3217. // if (wafer != null && !wafer.IsEmpty && wafer.ProcessState == EnumWaferProcessStatus.Completed)
  3218. // {
  3219. // gotoLL = ll;
  3220. // gotoBlade = Hand.Both;
  3221. // gotoSlot = 0;
  3222. // break;
  3223. // }
  3224. // }
  3225. // }
  3226. // else
  3227. // {
  3228. // if (!arm1Empty && !arm2Empty)
  3229. // {
  3230. // for (int i = 0; i <= 1; i++)
  3231. // {
  3232. // if (WaferManager.Instance.CheckNoWafer(ll.Module, i) &&
  3233. // WaferManager.Instance.CheckNoWafer(ll.Module, i + 2) &&
  3234. // WaferManager.Instance.CheckNoWafer(ll.Module, i + 4))
  3235. // {
  3236. // gotoBlade = Hand.Both;
  3237. // gotoSlot = i;
  3238. // gotoLL = ll;
  3239. // break;
  3240. // }
  3241. // else if (WaferManager.Instance.CheckNoWafer(ll.Module, i) &&
  3242. // WaferManager.Instance.CheckNoWafer(ll.Module, i + 2))
  3243. // {
  3244. // gotoBlade = Hand.Blade1;
  3245. // gotoSlot = i;
  3246. // gotoLL = ll;
  3247. // break;
  3248. // }
  3249. // if (ll.IsReadyForPlace(ModuleName.EfemRobot, Hand.Blade2, i + 4))
  3250. // {
  3251. // gotoBlade = Hand.Blade2;
  3252. // gotoSlot = i + 4;
  3253. // gotoLL = ll;
  3254. // break;
  3255. // }
  3256. // }
  3257. // }
  3258. // else if (!arm1Empty)
  3259. // {
  3260. // for (int i = 0; i <= 1; i++)
  3261. // {
  3262. // if (WaferManager.Instance.CheckNoWafer(ll.Module, i) &&
  3263. // WaferManager.Instance.CheckNoWafer(ll.Module, i + 2) &&
  3264. // WaferManager.Instance.CheckNoWafer(ll.Module, i + 4))
  3265. // {
  3266. // gotoBlade = Hand.Both;
  3267. // gotoSlot = i;
  3268. // gotoLL = ll;
  3269. // break;
  3270. // }
  3271. // }
  3272. // }
  3273. // else
  3274. // {
  3275. // for (int i = 0; i <= 1; i++)
  3276. // {
  3277. // if (ll.IsReadyForPlace(ModuleName.EfemRobot, Hand.Blade2, i + 4))
  3278. // {
  3279. // gotoBlade = Hand.Blade2;
  3280. // gotoSlot = i + 4;
  3281. // gotoLL = ll;
  3282. // break;
  3283. // }
  3284. // }
  3285. // if (gotoSlot == Int32.MaxValue)
  3286. // {
  3287. // for (int i = 0; i <= 5; i++)
  3288. // {
  3289. // if (ll.IsReadyForPlace(ModuleName.EfemRobot, Hand.Blade2, i))
  3290. // {
  3291. // gotoBlade = Hand.Blade2;
  3292. // gotoSlot = i + 4;
  3293. // gotoLL = ll;
  3294. // break;
  3295. // }
  3296. // }
  3297. // }
  3298. // }
  3299. // }
  3300. // if (gotoLL != null && gotoSlot != int.MaxValue)
  3301. // break;
  3302. // }
  3303. // if (gotoLL != null && gotoSlot != int.MaxValue)
  3304. // {
  3305. // if (_efem.PreviousTarget == gotoLL.Module)
  3306. // return;
  3307. // if (_efem.Goto(gotoLL.Module, gotoSlot, gotoBlade))
  3308. // {
  3309. // gotoLL.WaitTransfer(ModuleName.EfemRobot);
  3310. // return;
  3311. // }
  3312. // }
  3313. //}
  3314. private SlotItem GetNextWaferInJobQueue(ModuleName lpModule)
  3315. {
  3316. if (!_isRunningInParallelMode)
  3317. {
  3318. foreach (var cj in _lstControlJobs)
  3319. {
  3320. if (lpModule != ModuleName.System && (cj.Module != lpModule.ToString()))
  3321. continue;
  3322. if (cj.State == EnumControlJobState.Executing)
  3323. {
  3324. foreach (var pj in _lstProcessJobs)
  3325. {
  3326. if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing)
  3327. {
  3328. foreach (var pjSlotWafer in pj.SlotWafers)
  3329. {
  3330. if (CheckWaferNeedProcessAndPMAvailable(pjSlotWafer.Item1, pjSlotWafer.Item2))
  3331. return new SlotItem(pjSlotWafer.Item1, pjSlotWafer.Item2);
  3332. }
  3333. }
  3334. }
  3335. }
  3336. }
  3337. return null;
  3338. }
  3339. //parallel mode
  3340. Dictionary<string, SlotItem> pjWafer = new Dictionary<string, SlotItem>();
  3341. Dictionary<string, List<ModuleName>> pmUsed = new Dictionary<string, List<ModuleName>>();
  3342. foreach (var cj in _lstControlJobs)
  3343. {
  3344. if (cj.State != EnumControlJobState.Executing)
  3345. continue;
  3346. foreach (var pj in _lstProcessJobs)
  3347. {
  3348. if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing)
  3349. {
  3350. foreach (var pjSlotWafer in pj.SlotWafers)
  3351. {
  3352. if (CheckWaferNeedProcessAndPMAvailable(pjSlotWafer.Item1, pjSlotWafer.Item2))
  3353. {
  3354. pjWafer[pj.Name] = new SlotItem(pjSlotWafer.Item1, pjSlotWafer.Item2);
  3355. break;
  3356. }
  3357. }
  3358. }
  3359. }
  3360. }
  3361. if (pjWafer.Count == 0)
  3362. return null;
  3363. if (pjWafer.Count == 1)
  3364. return pjWafer.Values.First();
  3365. string preferPj = pjWafer.Keys.First();
  3366. int runningWaferCount = GetWaitingProcessWaferCount(preferPj);
  3367. foreach (var slotItem in pjWafer)
  3368. {
  3369. if (slotItem.Key == preferPj)
  3370. continue;
  3371. int count = GetWaitingProcessWaferCount(slotItem.Key);
  3372. if (count < runningWaferCount)
  3373. {
  3374. preferPj = slotItem.Key;
  3375. runningWaferCount = count;
  3376. }
  3377. }
  3378. return pjWafer[preferPj];
  3379. }
  3380. public bool CheckWaferNeedProcessAndPMAvailable(ModuleName waferModule, int waferSlot, ModuleName processIn = ModuleName.System)
  3381. {
  3382. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  3383. if (wafer.IsEmpty)
  3384. return false;
  3385. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  3386. return false;
  3387. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  3388. return false;
  3389. for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  3390. {
  3391. if (wafer.ProcessJob.Sequence.Steps[i].StepModules
  3392. .Contains(ModuleName.PMA) || wafer.ProcessJob.Sequence.Steps[i].StepModules
  3393. .Contains(ModuleName.PMB))
  3394. {
  3395. var hasPmAvailable = false;
  3396. foreach (var stepModule in wafer.ProcessJob.Sequence.Steps[i].StepModules)
  3397. {
  3398. var pm = GetModule(stepModule.ToString()) as SchedulerPM;
  3399. if (pm != null)
  3400. {
  3401. if (pm.IsAvailable || (pm.IsOnline && pm.Task != SchedulerModule.TaskType.PreJobProcess))
  3402. {
  3403. hasPmAvailable = true;
  3404. break;
  3405. }
  3406. }
  3407. }
  3408. if (!hasPmAvailable)
  3409. return false;
  3410. if (processIn == ModuleName.System)
  3411. return true;
  3412. if (wafer.ProcessJob.Sequence.Steps[i].StepModules
  3413. .Contains(processIn))
  3414. return true;
  3415. }
  3416. }
  3417. return false;
  3418. }
  3419. public bool LoadRecipe(string module, string CurrentRecipeBaseName, out double temp1, out double temp2)
  3420. {
  3421. var CurrentRecipeContent = RecipeFileManager.Instance.LoadRecipe("", CurrentRecipeBaseName, true);
  3422. temp1 = 0;
  3423. temp2 = 0;
  3424. if (string.IsNullOrEmpty(CurrentRecipeContent))
  3425. {
  3426. EV.PostInfoLog(ModuleName.System.ToString(), $"error during read recipe file {CurrentRecipeBaseName}");
  3427. return false;
  3428. }
  3429. if (!Recipe.Parse(module, CurrentRecipeContent, out RecipeHead recipeHead, out var recipeSteps))
  3430. {
  3431. return false;
  3432. }
  3433. temp1 = GetChamber1Temp(recipeHead);
  3434. temp2 = GetChamber2Temp(recipeHead);
  3435. return true;
  3436. }
  3437. public double GetChamber1Temp(RecipeHead CurrentRecipeHead)
  3438. {
  3439. if (CurrentRecipeHead != null)
  3440. {
  3441. if (!string.IsNullOrEmpty(CurrentRecipeHead.Chamber1Temperature))
  3442. {
  3443. double setpoint = Convert.ToDouble(CurrentRecipeHead.Chamber1Temperature);
  3444. if (setpoint > 0 && setpoint < 600)
  3445. return setpoint;
  3446. }
  3447. }
  3448. return 0;
  3449. }
  3450. public double GetChamber2Temp(RecipeHead CurrentRecipeHead)
  3451. {
  3452. if (CurrentRecipeHead != null)
  3453. {
  3454. if (!string.IsNullOrEmpty(CurrentRecipeHead.Chamber2Temperature))
  3455. {
  3456. double setpoint = Convert.ToDouble(CurrentRecipeHead.Chamber2Temperature);
  3457. if (setpoint > 0 && setpoint < 600)
  3458. return setpoint;
  3459. }
  3460. }
  3461. return 0;
  3462. }
  3463. private bool GetWaferTemperatureSetInRecipe(ModuleName waferModule, int waferSlot, ModuleName pmModule, out double temp1, out double temp2)
  3464. {
  3465. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  3466. var seq = wafer.ProcessJob.Sequence;
  3467. for (int i = 0; i < seq.Steps.Count; i++)
  3468. {
  3469. SequenceStepInfo stepInfo = seq.Steps[i];
  3470. foreach (var module in stepInfo.StepModules)
  3471. {
  3472. if (module == pmModule)
  3473. {
  3474. LoadRecipe(pmModule.ToString(), seq.Steps[i].StepParameter[module == ModuleName.PMA ? "PMARecipe" : "PMBRecipe"].ToString(), out double chambertemp1, out double chambertemp2);
  3475. temp1 = (double)chambertemp1;
  3476. temp2 = (double)chambertemp2;
  3477. return true;
  3478. }
  3479. }
  3480. }
  3481. temp1 = 0;
  3482. temp2 = 0;
  3483. LOG.Error($"Can not find wafer {waferModule} {waferSlot + 1} temperature set in recipe");
  3484. return false;
  3485. }
  3486. #endregion
  3487. #region Logic Check
  3488. private bool CheckLoadLockAvaiableForTMRobot()
  3489. {
  3490. bool isPrepareTransferForTMobot = GetVacuumWafer() == 0;
  3491. foreach (var ll in _lstLls)
  3492. {
  3493. if (!ll.IsAvailable)
  3494. continue;
  3495. var deviceLL = DEVICE.GetDevice<LoadLock>(ll.Module.ToString());
  3496. var wafers = WaferManager.Instance.GetWafers(ll.Module).ToList();
  3497. for (int i = 0; i <= 5;)
  3498. {
  3499. var wafer0 = WaferManager.Instance.GetWafer(ll.Module, i);
  3500. var wafer1 = WaferManager.Instance.GetWafer(ll.Module, i + 1);
  3501. if ((!wafer0.IsEmpty && wafer0.ProcessState == EnumWaferProcessStatus.Idle) ||
  3502. (!wafer1.IsEmpty && wafer1.ProcessState == EnumWaferProcessStatus.Idle))
  3503. {
  3504. isPrepareTransferForTMobot = true;
  3505. break;
  3506. }
  3507. i += 2;
  3508. }
  3509. }
  3510. return isPrepareTransferForTMobot;
  3511. }
  3512. //private bool CheckPMTemperature(string module)
  3513. //{
  3514. // var pmDevice = DEVICE.GetDevice<SpinelPM>(module);
  3515. // if (pmDevice != null && _temperatureSetpointDic.ContainsKey(module) && _temperatureSetpointDic[module] > 0)
  3516. // {
  3517. // if (!pmDevice.CheckHeater1Temperature(_temperatureSetpointDic[module]) ||
  3518. // !pmDevice.CheckHeater2Temperature(_temperatureSetpointDic[module]))
  3519. // {
  3520. // if (!_temperatureTrigDic.ContainsKey(module))
  3521. // _temperatureTrigDic.Add(module, new R_TRIG());
  3522. // _temperatureTrigDic[module].CLK = true;
  3523. // if (_temperatureTrigDic[module].Q)
  3524. // {
  3525. // EV.PostWarningLog("Scheduler", $"{module} heater temperature is not in the scope");
  3526. // }
  3527. // pmDevice.SetHeater1(_temperatureSetpointDic[module]);
  3528. // pmDevice.SetHeater2(_temperatureSetpointDic[module]);
  3529. // }
  3530. // if (pmDevice.CheckHeater1Temperature(_temperatureSetpointDic[module]) &&
  3531. // pmDevice.CheckHeater2Temperature(_temperatureSetpointDic[module]))
  3532. // {
  3533. // return true;
  3534. // }
  3535. // }
  3536. // else
  3537. // return true;
  3538. // return false;
  3539. //}
  3540. private bool CheckWaferNextProcessIsPM(ModuleName waferModule, int waferSlot)
  3541. {
  3542. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  3543. if (wafer.IsEmpty)
  3544. return false;
  3545. if (wafer.ProcessJob == null ||
  3546. wafer.ProcessJob.Sequence == null ||
  3547. wafer.ProcessJob.Sequence.Steps == null ||
  3548. wafer.ProcessJob.Sequence.Steps.Count <= wafer.NextSequenceStep ||
  3549. wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep] == null ||
  3550. wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules == null)
  3551. {
  3552. return false;
  3553. }
  3554. return wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Any(x => ModuleHelper.IsPm(x));
  3555. }
  3556. private bool CheckWaferNextProcessIsPMAvaiable(ModuleName waferModule, int waferSlot)
  3557. {
  3558. if (!CheckWaferNextProcessIsPM(waferModule, waferSlot))
  3559. return false;
  3560. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  3561. foreach (var stepModule in wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules)
  3562. {
  3563. if (_lstPms.Any(pm => pm.Module == stepModule && pm.IsAvailable && WaferManager.Instance.CheckNoWafer(pm.Module, waferSlot)))
  3564. {
  3565. return true;
  3566. }
  3567. }
  3568. return false;
  3569. }
  3570. private bool CheckNeedRunClean(ModuleName module, out bool withWafer, out string recipeName)
  3571. {
  3572. recipeName = string.Empty;
  3573. withWafer = false;
  3574. return false;
  3575. SequenceInfo seq = GetCurrentSequenceInfo();
  3576. int waferProcessed = StatsDataManager.Instance.GetValue($"{module}.WaferProcessedSincePreviousClean");
  3577. if (seq == null)
  3578. return false;
  3579. foreach (var stepInfo in seq.Steps)
  3580. {
  3581. if (!stepInfo.StepModules.Contains(module))
  3582. continue;
  3583. if (stepInfo.StepParameter.ContainsKey("CleanRecipeNoWafer")
  3584. && !string.IsNullOrEmpty((string)stepInfo.StepParameter["CleanRecipeNoWafer"]))
  3585. {
  3586. if (stepInfo.CleanInterval > 0 && waferProcessed >= stepInfo.CleanInterval)
  3587. {
  3588. recipeName = (string)stepInfo.StepParameter["CleanRecipeNoWafer"];
  3589. withWafer = false;
  3590. return true;
  3591. }
  3592. }
  3593. if (stepInfo.StepParameter.ContainsKey("CleanRecipeWafer")
  3594. && !string.IsNullOrEmpty((string)stepInfo.StepParameter["CleanRecipeWafer"]))
  3595. {
  3596. if (stepInfo.CleanInterval > 0 && waferProcessed >= stepInfo.CleanInterval)
  3597. {
  3598. recipeName = (string)stepInfo.StepParameter["CleanRecipeWafer"];
  3599. withWafer = true;
  3600. return true;
  3601. }
  3602. }
  3603. }
  3604. return false;
  3605. }
  3606. private bool CheckVacuumWaferHasAvailableTarget(ModuleName waferModule, int waferSlot, ModuleName chamberSwappable)
  3607. {
  3608. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  3609. //System.Diagnostics.Trace.Assert(!wafer.IsEmpty);
  3610. if (CheckWaferNeedProcess(waferModule, waferSlot))
  3611. {
  3612. // Check for an empty PM
  3613. foreach (var pm in _lstPms)
  3614. {
  3615. if (WaferManager.Instance.CheckNoWafer(pm.Module, 0) || pm.Module == chamberSwappable)
  3616. {
  3617. if (pm.IsAvailable == false)
  3618. continue;
  3619. if (!CheckWaferNextProcessIn(waferModule, waferSlot, pm.Module))
  3620. continue;
  3621. return true;
  3622. }
  3623. }
  3624. }
  3625. else
  3626. {
  3627. // No more processing needed, check for a outbound loadlock slot
  3628. return true;
  3629. }
  3630. return false;
  3631. }
  3632. private bool CheckWaferNextProcessIn(ModuleName waferModule, int waferSlot, ModuleName chamber)
  3633. {
  3634. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  3635. if (wafer.ProcessJob == null ||
  3636. wafer.ProcessJob.Sequence == null ||
  3637. wafer.ProcessJob.Sequence.Steps == null ||
  3638. wafer.ProcessJob.Sequence.Steps.Count <= wafer.NextSequenceStep ||
  3639. wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep] == null ||
  3640. wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules == null)
  3641. {
  3642. return false;
  3643. }
  3644. return wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(chamber);
  3645. }
  3646. private SequenceInfo GetCurrentSequenceInfo()
  3647. {
  3648. foreach (var pj in _lstProcessJobs)
  3649. {
  3650. if (pj.State == EnumProcessJobState.Processing)
  3651. {
  3652. return pj.Sequence;
  3653. }
  3654. }
  3655. return null;
  3656. }
  3657. private bool GetWaferSequenceAlignAngle(ModuleName module, int slot, out double angle)
  3658. {
  3659. angle = 0;
  3660. if (!WaferManager.Instance.CheckHasWafer(module, slot))
  3661. return false;
  3662. WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
  3663. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  3664. return false;
  3665. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  3666. return false;
  3667. if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Aligner))
  3668. return false;
  3669. angle = wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].AlignAngle;
  3670. return true;
  3671. }
  3672. private bool GetWaferSequenceLoadLockCoolingTime(ModuleName module, int slot, out int coolingTime)
  3673. {
  3674. coolingTime = 0;
  3675. if (!WaferManager.Instance.CheckHasWafer(module, slot))
  3676. return false;
  3677. WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
  3678. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  3679. return false;
  3680. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  3681. return false;
  3682. if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(module))
  3683. return false;
  3684. if (!int.TryParse(wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepParameter["CoolingTime"].ToString(),
  3685. out coolingTime))
  3686. {
  3687. coolingTime = SC.GetValue<int>("System.DefaultCoolingTime");
  3688. EV.PostWarningLog("Scheduler", $"Sequence step LL cooling time is not valid, instead with the SC default value {coolingTime} seconds");
  3689. return false;
  3690. }
  3691. return true;
  3692. }
  3693. private bool CheckWaferNextStepIsLoadLock(ModuleName module, int slot, ModuleName LL = ModuleName.System)
  3694. {
  3695. if (!WaferManager.Instance.CheckHasWafer(module, slot))
  3696. return false;
  3697. WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
  3698. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  3699. return false;
  3700. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  3701. return false;
  3702. if (LL != ModuleName.System && !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(LL))
  3703. return false;
  3704. if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.LLA) &&
  3705. !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.LLB))
  3706. return false;
  3707. return true;
  3708. }
  3709. private bool CheckWaferNextStepIsAlign(ModuleName module, int slot)
  3710. {
  3711. if (!WaferManager.Instance.CheckHasWafer(module, slot))
  3712. return false;
  3713. WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
  3714. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  3715. return false;
  3716. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  3717. return false;
  3718. if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Aligner) &&
  3719. !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.AlignerA) &&
  3720. !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.AlignerB))
  3721. return false;
  3722. return true;
  3723. }
  3724. public bool CheckWaferNeedProcess(ModuleName waferModule, int waferSlot, ModuleName processIn = ModuleName.System)
  3725. {
  3726. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  3727. if (wafer.IsEmpty)
  3728. return false;
  3729. if (wafer.Status == WaferStatus.Dummy && wafer.ProcessState == EnumWaferProcessStatus.Wait)
  3730. {
  3731. if (ModuleHelper.IsPm(processIn))
  3732. {
  3733. return (CheckNeedRunClean(processIn, out bool withWafer, out _) && withWafer);
  3734. }
  3735. return true;
  3736. }
  3737. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.ProcessJob.Sequence.Steps == null)
  3738. return false;
  3739. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count || wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules == null)
  3740. return false;
  3741. if (processIn != ModuleName.System && !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(processIn))
  3742. return false;
  3743. bool hasPm = false;
  3744. for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  3745. {
  3746. foreach (var stepModule in wafer.ProcessJob.Sequence.Steps[i].StepModules)
  3747. {
  3748. if (ModuleHelper.IsPm(stepModule))
  3749. {
  3750. hasPm = true;
  3751. break;
  3752. }
  3753. }
  3754. if (hasPm)
  3755. break;
  3756. }
  3757. if (processIn == ModuleName.System && !hasPm)
  3758. return false;
  3759. return true;
  3760. }
  3761. public bool CheckWaferNeedProcess(WaferInfo wafer, ModuleName processIn = ModuleName.System)
  3762. {
  3763. if (wafer.IsEmpty)
  3764. return false;
  3765. if (wafer.Status == WaferStatus.Dummy && wafer.ProcessState == EnumWaferProcessStatus.Wait)
  3766. {
  3767. if (ModuleHelper.IsPm(processIn))
  3768. {
  3769. return (CheckNeedRunClean(processIn, out bool withWafer, out _) && withWafer);
  3770. }
  3771. return true;
  3772. }
  3773. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.ProcessJob.Sequence.Steps == null)
  3774. return false;
  3775. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count || wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules == null)
  3776. return false;
  3777. if (processIn != ModuleName.System && !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(processIn))
  3778. return false;
  3779. bool hasPm = false;
  3780. for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  3781. {
  3782. foreach (var stepModule in wafer.ProcessJob.Sequence.Steps[i].StepModules)
  3783. {
  3784. if (ModuleHelper.IsPm(stepModule))
  3785. {
  3786. hasPm = true;
  3787. break;
  3788. }
  3789. }
  3790. if (hasPm)
  3791. break;
  3792. }
  3793. if (processIn == ModuleName.System && !hasPm)
  3794. return false;
  3795. return true;
  3796. }
  3797. public bool CheckWaferNeedProcessPre(ModuleName waferModule, int waferSlot, ModuleName processIn = ModuleName.System)
  3798. {
  3799. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  3800. if (wafer.IsEmpty)
  3801. return false;
  3802. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  3803. return false;
  3804. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  3805. return false;
  3806. for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  3807. {
  3808. if (wafer.ProcessJob.Sequence.Steps[i].StepModules
  3809. .Contains(ModuleName.PMA) || wafer.ProcessJob.Sequence.Steps[i].StepModules
  3810. .Contains(ModuleName.PMB))
  3811. {
  3812. if (processIn == ModuleName.System)
  3813. return true;
  3814. if (wafer.ProcessJob.Sequence.Steps[i].StepModules
  3815. .Contains(processIn))
  3816. return true;
  3817. }
  3818. }
  3819. return false;
  3820. }
  3821. public bool CheckWaferNeedGotoPM(ModuleName waferModule, int waferSlot, ModuleName processIn = ModuleName.System)
  3822. {
  3823. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  3824. if (wafer.IsEmpty)
  3825. return false;
  3826. if (wafer.Status == WaferStatus.Dummy && wafer.ProcessState == EnumWaferProcessStatus.Wait)
  3827. {
  3828. if (ModuleHelper.IsPm(processIn))
  3829. {
  3830. return (CheckNeedRunClean(processIn, out bool withWafer, out _) && withWafer);
  3831. }
  3832. return true;
  3833. }
  3834. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.ProcessJob.Sequence.Steps == null)
  3835. return false;
  3836. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count || wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules == null)
  3837. return false;
  3838. if (processIn != ModuleName.System && !wafer.ProcessJob.Sequence.Steps.Any(x => x.StepModules.Contains(processIn)))
  3839. return false;
  3840. bool hasPm = false;
  3841. for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  3842. {
  3843. foreach (var stepModule in wafer.ProcessJob.Sequence.Steps[i].StepModules)
  3844. {
  3845. if (ModuleHelper.IsPm(stepModule))
  3846. {
  3847. hasPm = true;
  3848. break;
  3849. }
  3850. }
  3851. if (hasPm)
  3852. break;
  3853. }
  3854. if (processIn == ModuleName.System && !hasPm)
  3855. return false;
  3856. return true;
  3857. }
  3858. public bool CheckWaferNeedGotoPM(WaferInfo wafer, ModuleName processIn = ModuleName.System)
  3859. {
  3860. if (wafer.IsEmpty)
  3861. return false;
  3862. if (wafer.Status == WaferStatus.Dummy && wafer.ProcessState == EnumWaferProcessStatus.Wait)
  3863. {
  3864. if (ModuleHelper.IsPm(processIn))
  3865. {
  3866. return (CheckNeedRunClean(processIn, out bool withWafer, out _) && withWafer);
  3867. }
  3868. return true;
  3869. }
  3870. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.ProcessJob.Sequence.Steps == null)
  3871. return false;
  3872. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count || wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules == null)
  3873. return false;
  3874. if (processIn != ModuleName.System && !wafer.ProcessJob.Sequence.Steps.Any(x => x.StepModules.Contains(processIn)))
  3875. return false;
  3876. bool hasPm = false;
  3877. for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  3878. {
  3879. foreach (var stepModule in wafer.ProcessJob.Sequence.Steps[i].StepModules)
  3880. {
  3881. if (ModuleHelper.IsPm(stepModule))
  3882. {
  3883. hasPm = true;
  3884. break;
  3885. }
  3886. }
  3887. if (hasPm)
  3888. break;
  3889. }
  3890. if (processIn == ModuleName.System && !hasPm)
  3891. return false;
  3892. return true;
  3893. }
  3894. public bool CheckWaferSequenceStepDone(ModuleName waferModule, int waferSlot)
  3895. {
  3896. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  3897. if (wafer.IsEmpty)
  3898. return false;
  3899. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  3900. return false;
  3901. if (wafer.NextSequenceStep < wafer.ProcessJob.Sequence.Steps.Count)
  3902. return false;
  3903. return true;
  3904. }
  3905. public bool CheckWaferProcessModuleIsAvailable(ModuleName waferModule, int waferSlot)
  3906. {
  3907. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  3908. if (wafer.IsEmpty)
  3909. return false;
  3910. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  3911. return false;
  3912. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  3913. return false;
  3914. foreach (var step in wafer.ProcessJob.Sequence.Steps)
  3915. {
  3916. foreach (var module in step.StepModules)
  3917. {
  3918. if (WaferManager.Instance.CheckNoWafer(module, 0)
  3919. && _lstPms.Find(x => x.Module == module).IsAvailable
  3920. && !CheckNeedRunClean(module, out bool _, out string _))
  3921. return true;
  3922. }
  3923. }
  3924. return false;
  3925. }
  3926. private int GetATMWafer()
  3927. {
  3928. int count = GetWaferCountInJobQueue();
  3929. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0))
  3930. count++;
  3931. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1))
  3932. count++;
  3933. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 2))
  3934. count++;
  3935. return count;
  3936. }
  3937. private int GetVacuumWafer()
  3938. {
  3939. int count = 0;
  3940. foreach (var schedulerPm in _lstPms)
  3941. {
  3942. if (schedulerPm == null ||
  3943. (!schedulerPm.IsOnline))
  3944. continue;
  3945. if (WaferManager.Instance.CheckHasWafer(schedulerPm.Module, 0) || WaferManager.Instance.CheckHasWafer(schedulerPm.Module, 1))
  3946. count++;
  3947. }
  3948. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0) || WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1))
  3949. count++;
  3950. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 2) || WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 3))
  3951. count++;
  3952. return count;
  3953. }
  3954. private int GetVacuumProcessedWafer()
  3955. {
  3956. int count = 0;
  3957. foreach (var schedulerPm in _lstPmsCurrentSequence)
  3958. {
  3959. if (schedulerPm == null)
  3960. continue;
  3961. if (WaferManager.Instance.CheckHasWafer(schedulerPm.Module, 0)
  3962. && schedulerPm.IsAvailable
  3963. && !CheckWaferNeedProcess(schedulerPm.Module, 0)
  3964. && !WaferManager.Instance.CheckWaferIsDummy(schedulerPm.Module, 0))
  3965. count++;
  3966. }
  3967. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0) && !CheckWaferNeedProcess(ModuleName.TMRobot, 0) && !WaferManager.Instance.CheckWaferIsDummy(ModuleName.TMRobot, 0))
  3968. count++;
  3969. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1) && !CheckWaferNeedProcess(ModuleName.TMRobot, 1) && !WaferManager.Instance.CheckWaferIsDummy(ModuleName.TMRobot, 1))
  3970. count++;
  3971. return count;
  3972. }
  3973. private int GetUnprocessedWafer()
  3974. {
  3975. int count = 0;
  3976. foreach (var cj in _lstControlJobs)
  3977. {
  3978. if (cj.State == EnumControlJobState.Executing)
  3979. {
  3980. foreach (var pj in _lstProcessJobs)
  3981. {
  3982. if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing)
  3983. {
  3984. foreach (var pjSlotWafer in pj.SlotWafers)
  3985. {
  3986. if (CheckWaferNeedProcess(pjSlotWafer.Item1, pjSlotWafer.Item2))
  3987. count++;
  3988. }
  3989. }
  3990. }
  3991. }
  3992. }
  3993. foreach (var ll in _lstLls)
  3994. {
  3995. if (CheckWaferNeedProcess(ll.Module, 0))
  3996. count++;
  3997. if (CheckWaferNeedProcess(ll.Module, 1))
  3998. count++;
  3999. if (CheckWaferNeedProcess(ll.Module, 2))
  4000. count++;
  4001. if (CheckWaferNeedProcess(ll.Module, 3))
  4002. count++;
  4003. if (CheckWaferNeedProcess(ll.Module, 4))
  4004. count++;
  4005. if (CheckWaferNeedProcess(ll.Module, 5))
  4006. count++;
  4007. }
  4008. if (CheckWaferNeedProcess(ModuleName.TMRobot, 0))
  4009. count++;
  4010. if (CheckWaferNeedProcess(ModuleName.TMRobot, 1))
  4011. count++;
  4012. if (CheckWaferNeedProcess(ModuleName.TMRobot, 2))
  4013. count++;
  4014. if (CheckWaferNeedProcess(ModuleName.TMRobot, 3))
  4015. count++;
  4016. return count;
  4017. }
  4018. private int GetAvailablePmCount()
  4019. {
  4020. int count = 0;
  4021. foreach (var pm in _lstPms)
  4022. {
  4023. if (!pm.IsAvailable)
  4024. continue;
  4025. if (WaferManager.Instance.CheckNoWafer(pm.Module, 0))
  4026. count++;
  4027. }
  4028. return count;
  4029. }
  4030. private SlotItem GetWaferInJobQueue()
  4031. {
  4032. SlotItem slotItem = null;
  4033. bool enableParallel = SC.GetValue<bool>("System.Scheduler.IsRunInParallelMode");
  4034. var OrderedLstCJs = _lstControlJobs.OrderBy(x => x.BeginTime);
  4035. if (enableParallel)
  4036. {
  4037. var priorityFindWaferGotoPMA = GetWaferCountLoadLockToPM(ModuleName.PMA) < 1;
  4038. var priorityFindWaferGotoPMB = GetWaferCountLoadLockToPM(ModuleName.PMB) < 1;
  4039. foreach (var cj in OrderedLstCJs)
  4040. {
  4041. if (cj.State == EnumControlJobState.Executing)
  4042. {
  4043. foreach (var pj in _lstProcessJobs)
  4044. {
  4045. if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing)
  4046. {
  4047. foreach (var pjSlotWafer in pj.SlotWafers)
  4048. {
  4049. if (priorityFindWaferGotoPMA)
  4050. {
  4051. if (CheckWaferNeedGotoPM(pjSlotWafer.Item1, pjSlotWafer.Item2, ModuleName.PMA))
  4052. {
  4053. return new SlotItem(pjSlotWafer.Item1, pjSlotWafer.Item2);
  4054. }
  4055. }
  4056. if (priorityFindWaferGotoPMB)
  4057. {
  4058. if (CheckWaferNeedGotoPM(pjSlotWafer.Item1, pjSlotWafer.Item2, ModuleName.PMB))
  4059. {
  4060. return new SlotItem(pjSlotWafer.Item1, pjSlotWafer.Item2);
  4061. }
  4062. }
  4063. }
  4064. }
  4065. }
  4066. }
  4067. }
  4068. }
  4069. if (slotItem == null)
  4070. {
  4071. foreach (var cj in OrderedLstCJs)
  4072. {
  4073. if (cj.State == EnumControlJobState.Executing)
  4074. {
  4075. foreach (var pj in _lstProcessJobs)
  4076. {
  4077. if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing)
  4078. {
  4079. foreach (var pjSlotWafer in pj.SlotWafers)
  4080. {
  4081. if (CheckWaferNeedProcess(pjSlotWafer.Item1, pjSlotWafer.Item2))
  4082. {
  4083. return new SlotItem(pjSlotWafer.Item1, pjSlotWafer.Item2);
  4084. }
  4085. }
  4086. }
  4087. }
  4088. }
  4089. }
  4090. }
  4091. return slotItem;
  4092. }
  4093. private Tuple<SchedulerLoadLock, int> GetWaferOrderInJobQueue(List<Tuple<SchedulerLoadLock, int>> llSlots)
  4094. {
  4095. foreach (var cj in _lstControlJobs)
  4096. {
  4097. if (cj.State == EnumControlJobState.Executing)
  4098. {
  4099. foreach (var pj in _lstProcessJobs)
  4100. {
  4101. if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing)
  4102. {
  4103. foreach (var pjSlotWafer in pj.SlotWafers)
  4104. {
  4105. foreach (var slot in llSlots)
  4106. {
  4107. var wafer = WaferManager.Instance.GetWafer(slot.Item1.Module, slot.Item2);
  4108. if (wafer.OriginStation == (int)pjSlotWafer.Item1 && wafer.OriginSlot == pjSlotWafer.Item2)
  4109. return slot;
  4110. }
  4111. }
  4112. }
  4113. }
  4114. }
  4115. }
  4116. return null;
  4117. }
  4118. private bool CheckWaferInJobQueue(ModuleName module, int slot)
  4119. {
  4120. foreach (var cj in _lstControlJobs)
  4121. {
  4122. if (cj.State == EnumControlJobState.Executing)
  4123. {
  4124. foreach (var pj in _lstProcessJobs)
  4125. {
  4126. if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing)
  4127. {
  4128. foreach (var pjSlotWafer in pj.SlotWafers)
  4129. {
  4130. if (pjSlotWafer.Item1 == module && pjSlotWafer.Item2 == slot && CheckWaferNeedProcess(pjSlotWafer.Item1, pjSlotWafer.Item2))
  4131. {
  4132. return true;
  4133. }
  4134. }
  4135. }
  4136. }
  4137. }
  4138. }
  4139. return false;
  4140. }
  4141. private int GetWaferCountInJobQueue()
  4142. {
  4143. int count = 0;
  4144. foreach (var lp in _lstLps)
  4145. {
  4146. for (int i = 0; i < 25; i++)
  4147. {
  4148. if (CheckWaferNeedProcess(lp.Module, i))
  4149. count++;
  4150. }
  4151. }
  4152. return count;
  4153. }
  4154. //private SchedulerLoadLock GetCurrentLoadLockForTMPlace()
  4155. //{
  4156. // foreach (var ll in _lstLls)
  4157. // {
  4158. // if (!ll.IsAvailable)
  4159. // continue;
  4160. // //if (!ll.CheckAtVacuum())
  4161. // // continue;
  4162. // var wafers = WaferManager.Instance.GetWafers(ll.Module).ToList();
  4163. // if (wafers.Any(x => x.ProcessState == EnumWaferProcessStatus.Completed))
  4164. // {
  4165. // for (int i = 0; i < 5;)
  4166. // {
  4167. // if ((WaferManager.Instance.CheckNoWafer(ll.Module, i))
  4168. // && (WaferManager.Instance.CheckNoWafer(ll.Module, i + 1)))
  4169. // {
  4170. // return ll;
  4171. // }
  4172. // i += 2;
  4173. // }
  4174. // }
  4175. // }
  4176. // SchedulerLoadLock currentLoadLock = null;
  4177. // DateTime dtMin = DateTime.MaxValue;
  4178. // foreach (var ll in _lstLls)
  4179. // {
  4180. // if (!ll.IsAvailable || !ll.CheckAtVacuum())
  4181. // continue;
  4182. // var wafers = WaferManager.Instance.GetWafers(ll.Module).ToList();
  4183. // DateTime dtCurrentLL = DateTime.MaxValue;
  4184. // foreach (var wafer in wafers)
  4185. // {
  4186. // if (wafer != null && !wafer.IsEmpty && wafer.SubstHists.Length > 0)
  4187. // {
  4188. // var dt = wafer.SubstHists[wafer.SubstHists.Length - 1].AccessTime;
  4189. // if (dt.CompareTo(dtMin) < 0)
  4190. // dtCurrentLL = dt;
  4191. // }
  4192. // }
  4193. // if (dtCurrentLL.CompareTo(dtMin) < 0)
  4194. // {
  4195. // dtMin = dtCurrentLL;
  4196. // currentLoadLock = ll;
  4197. // }
  4198. // }
  4199. // foreach (var ll in _lstLls)
  4200. // {
  4201. // if (currentLoadLock != null && currentLoadLock != ll)
  4202. // continue;
  4203. // for (int i = 0; i < 5;)
  4204. // {
  4205. // if ((WaferManager.Instance.CheckNoWafer(ll.Module, i))
  4206. // && (WaferManager.Instance.CheckNoWafer(ll.Module, i + 1)))
  4207. // {
  4208. // return currentLoadLock;
  4209. // }
  4210. // i += 2;
  4211. // }
  4212. // currentLoadLock = null;//no empty slot
  4213. // }
  4214. // return currentLoadLock;
  4215. //}
  4216. //private SchedulerLoadLock GetCurrentLoadLockForTMPick()
  4217. //{
  4218. // SchedulerLoadLock currentLoadLock = null;
  4219. // DateTime dtMin = DateTime.MaxValue;
  4220. // foreach (var ll in _lstLls)
  4221. // {
  4222. // if (!ll.IsAvailable || !ll.CheckAtVacuum())
  4223. // continue;
  4224. // var wafers = WaferManager.Instance.GetWafers(ll.Module).ToList();
  4225. // DateTime dtCurrentLL = DateTime.MaxValue;
  4226. // foreach (var wafer in wafers)
  4227. // {
  4228. // if (wafer != null && !wafer.IsEmpty && wafer.ProcessState == EnumWaferProcessStatus.Idle && wafer.SubstHists.Length > 0)
  4229. // {
  4230. // var dt = wafer.SubstHists[wafer.SubstHists.Length - 1].AccessTime;
  4231. // if (dt.CompareTo(dtMin) < 0)
  4232. // dtCurrentLL = dt;
  4233. // }
  4234. // }
  4235. // if (dtCurrentLL.CompareTo(dtMin) < 0)
  4236. // {
  4237. // dtMin = dtCurrentLL;
  4238. // currentLoadLock = ll;
  4239. // }
  4240. // }
  4241. // return currentLoadLock;
  4242. //}
  4243. //private SchedulerLoadLock GetCurrentLoadLockForEfem()
  4244. //{
  4245. // SchedulerLoadLock currentLoadLock = null;
  4246. // foreach (var ll in _lstLls)
  4247. // {
  4248. // if (!ll.IsOnline)
  4249. // continue;
  4250. // var wafers = WaferManager.Instance.GetWafers(ll.Module).ToList();
  4251. // if (loadlockDevice.CheckDoorOpen())
  4252. // {
  4253. // foreach (var wafer in wafers)
  4254. // {
  4255. // if (wafer != null && !wafer.IsEmpty && wafer.ProcessState == EnumWaferProcessStatus.Idle)
  4256. // {
  4257. // currentLoadLock = ll;
  4258. // break;
  4259. // }
  4260. // }
  4261. // if (!wafers.Any(x => x.IsEmpty))
  4262. // {
  4263. // currentLoadLock = null;
  4264. // }
  4265. // }
  4266. // }
  4267. // return currentLoadLock;
  4268. //}
  4269. private int GetEmptySlotInCurrentLoadLock()
  4270. {
  4271. int count = 0;
  4272. //SchedulerLoadLock currentLoadLock = GetCurrentLoadLockForEfem();
  4273. foreach (var ll in _lstLls)
  4274. {
  4275. if (!ll.IsOnline)
  4276. continue;
  4277. //if (currentLoadLock != null && currentLoadLock != ll)
  4278. // continue;
  4279. //var loadlockDevice = DEVICE.GetDevice<SpinelLoadLock>(ll.Module.ToString());
  4280. var wafers = WaferManager.Instance.GetWafers(ll.Module).ToList();
  4281. //if (loadlockDevice.CheckDoorOpen())
  4282. {
  4283. for (int i = 0; i <= 1; i++)
  4284. {
  4285. var wafer0 = WaferManager.Instance.GetWafer(ll.Module, i);
  4286. var wafer1 = WaferManager.Instance.GetWafer(ll.Module, i + 2);
  4287. var wafer2 = WaferManager.Instance.GetWafer(ll.Module, i + 4);
  4288. if (wafer0 != null && wafer0.IsEmpty)
  4289. count++;
  4290. if (wafer1 != null && wafer1.IsEmpty)
  4291. count++;
  4292. if (wafer2 != null && wafer2.IsEmpty)
  4293. count++;
  4294. if (count > 0)
  4295. break;
  4296. }
  4297. }
  4298. }
  4299. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0) && CheckWaferNeedProcess(ModuleName.EfemRobot, 0))
  4300. count--;
  4301. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1) && CheckWaferNeedProcess(ModuleName.EfemRobot, 1))
  4302. count--;
  4303. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 2) && CheckWaferNeedProcess(ModuleName.EfemRobot, 2))
  4304. count--;
  4305. return count < 0 ? 0 : count;
  4306. }
  4307. private int GetEmptySlotInLoadLock(SchedulerLoadLock ll)
  4308. {
  4309. int count = 0;
  4310. {
  4311. if (!ll.IsOnline)
  4312. return count;
  4313. var wafers = WaferManager.Instance.GetWafers(ll.Module);
  4314. for (int i = 0; i < wafers.Length; i++)
  4315. {
  4316. if (wafers[i].IsEmpty)
  4317. count++;
  4318. }
  4319. }
  4320. return count;
  4321. }
  4322. private int GetEmptySlotInLoadLock()
  4323. {
  4324. int count = 0;
  4325. foreach (var ll in _lstLls)
  4326. {
  4327. if (!ll.IsOnline)
  4328. continue;
  4329. var wafers = WaferManager.Instance.GetWafers(ll.Module);
  4330. for (int i = 0; i < wafers.Length; i++)
  4331. {
  4332. if (wafers[i].IsEmpty)
  4333. count++;
  4334. }
  4335. }
  4336. return count;
  4337. }
  4338. private int GetEmptySlotInPM()
  4339. {
  4340. int count = 0;
  4341. foreach (var pm in _lstPms)
  4342. {
  4343. if (!pm.IsOnline)
  4344. continue;
  4345. var wafers = WaferManager.Instance.GetWafers(pm.Module);
  4346. for (int i = 0; i < wafers.Length; i++)
  4347. {
  4348. if (wafers[i].IsEmpty)
  4349. count++;
  4350. }
  4351. }
  4352. return count;
  4353. }
  4354. private int GetEmptySlotInPMA()
  4355. {
  4356. int count = 0;
  4357. if (!_pm1.IsOnline)
  4358. return count;
  4359. var wafers = WaferManager.Instance.GetWafers(_pm1.Module);
  4360. for (int i = 0; i < wafers.Length; i++)
  4361. {
  4362. if (wafers[i].IsEmpty)
  4363. count++;
  4364. }
  4365. return count;
  4366. }
  4367. private int GetEmptySlotInPMB()
  4368. {
  4369. int count = 0;
  4370. if (!_pm2.IsOnline)
  4371. return count;
  4372. var wafers = WaferManager.Instance.GetWafers(_pm2.Module);
  4373. for (int i = 0; i < wafers.Length; i++)
  4374. {
  4375. if (wafers[i].IsEmpty)
  4376. count++;
  4377. }
  4378. return count;
  4379. }
  4380. private bool CheckAlignerWaferCanPick(WaferInfo wafer, ModuleName aligner)
  4381. {
  4382. if (wafer == null || wafer.IsEmpty || wafer.ProcessJob == null ||
  4383. wafer.ProcessJob.Sequence == null || wafer.ProcessJob.Sequence.Steps == null || wafer.ProcessJob.Sequence.Steps.Count == 0)
  4384. return false;
  4385. var stepModules = wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules;
  4386. int count = 0;
  4387. int waferCount = 0;
  4388. if (stepModules == null || stepModules.Count == 0)
  4389. {
  4390. return false;
  4391. }
  4392. foreach (var pm in _lstPms)
  4393. {
  4394. if (pm.IsOnline && stepModules.Contains(pm.Module))
  4395. {
  4396. count++;
  4397. if (WaferManager.Instance.CheckHasWafer(pm.Module, 0))
  4398. waferCount++;
  4399. }
  4400. }
  4401. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0) && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1))
  4402. {
  4403. count++;
  4404. }
  4405. else if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0) || WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1))
  4406. {
  4407. var robotWafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0) ? 0 : 1);
  4408. if (robotWafer != null && !robotWafer.IsEmpty && robotWafer.ProcessJob != null &&
  4409. robotWafer.ProcessJob.Sequence != null || robotWafer.ProcessJob.Sequence.Steps != null && robotWafer.ProcessJob.Sequence.Steps.Count > 0)
  4410. {
  4411. stepModules = robotWafer.ProcessJob.Sequence.Steps[robotWafer.NextSequenceStep].StepModules;
  4412. if (stepModules != null && stepModules.Count > 0)
  4413. {
  4414. if (stepModules.Contains(aligner))
  4415. {
  4416. count++;
  4417. }
  4418. }
  4419. }
  4420. }
  4421. return count - waferCount > 0;
  4422. }
  4423. private bool CheckWaferCanPick(WaferInfo wafer)
  4424. {
  4425. if (wafer == null || wafer.IsEmpty || wafer.ProcessJob == null ||
  4426. wafer.ProcessJob.Sequence == null || wafer.ProcessJob.Sequence.Steps == null || wafer.ProcessJob.Sequence.Steps.Count == 0)
  4427. return false;
  4428. var stepModules = wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep + 1].StepModules;
  4429. int count = 0;
  4430. int waferCount = 0;
  4431. if (stepModules == null || stepModules.Count == 0)
  4432. {
  4433. return false;
  4434. }
  4435. if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0) && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1))
  4436. {
  4437. count++;
  4438. }
  4439. return count - waferCount > 0;
  4440. }
  4441. private SlotItem GetWaferReturnLoadPort(ModuleName module, int slot)
  4442. {
  4443. WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
  4444. if (!wafer.IsEmpty)
  4445. {
  4446. return new SlotItem((ModuleName)wafer.OriginStation, wafer.OriginSlot);
  4447. }
  4448. return null;
  4449. }
  4450. private bool ValidateSequence(string[] seqs, out string reason)
  4451. {
  4452. reason = string.Empty;
  4453. bool isAllSequenceNull = true;
  4454. for (int i = 0; i < seqs.Length; i++)
  4455. {
  4456. if (string.IsNullOrEmpty(seqs[i]))
  4457. continue;
  4458. var sequence = SequenceInfoHelper.GetInfo(seqs[i]);
  4459. if ((sequence == null || sequence.Steps == null || sequence.Steps.Count == 0) && !string.IsNullOrEmpty(sequence.Name))
  4460. {
  4461. reason = $"Invalid sequence {seqs[i]}";
  4462. return false;
  4463. }
  4464. isAllSequenceNull = false;
  4465. foreach (var step in sequence.Steps)
  4466. {
  4467. foreach (var module in step.StepModules)
  4468. {
  4469. if (!SC.GetValueOrDefault<bool>($"System.SetUp.{module}.IsInstalled"))
  4470. {
  4471. reason = $"Invalid sequence {seqs[i]}, {module} is uninstalled";
  4472. return false;
  4473. }
  4474. }
  4475. if (step.StepModules.Any(x => x == ModuleName.Aligner))
  4476. {
  4477. if (!SC.GetValueOrDefault<bool>("System.SetUp.Aligner.IsInstalled"))
  4478. {
  4479. reason = $"Invalid sequence {seqs[i]}, Aligner is uninstalled";
  4480. return false;
  4481. }
  4482. if (step.AlignAngle < 0 || step.AlignAngle > 360)
  4483. {
  4484. reason = $"Invalid sequence {seqs[i]}, Aligner angle parameter is not valid";
  4485. return false;
  4486. }
  4487. }
  4488. }
  4489. }
  4490. if (isAllSequenceNull)
  4491. {
  4492. reason = $"Invalid sequence, sequence are all null ";
  4493. return false;
  4494. }
  4495. return true;
  4496. }
  4497. private void CalcedThroughput(List<ProcessJobInfo> pjRemoveList)
  4498. {
  4499. int count = 0;
  4500. foreach (var pj in pjRemoveList)
  4501. {
  4502. foreach (var pjSlotWafer in pj.SlotWafers)
  4503. {
  4504. WaferInfo waferInfo = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  4505. if (waferInfo.ProcessState == EnumWaferProcessStatus.Completed
  4506. && waferInfo.SubstTransStatus == SubstrateTransportStatus.AtDestination)
  4507. {
  4508. count++;
  4509. }
  4510. }
  4511. }
  4512. _throughputData.UpdateCalced(count);
  4513. }
  4514. private void CalcingThroughput()
  4515. {
  4516. if (!_lstControlJobs.Any())
  4517. {
  4518. _throughputData.Pause();
  4519. return;
  4520. }
  4521. if (!_lstControlJobs.Any(x => x.State == EnumControlJobState.Executing))
  4522. {
  4523. _throughputData.Pause();
  4524. return;
  4525. }
  4526. _throughputData.BeginCalc();
  4527. int count = 0;
  4528. foreach (var pj in _lstProcessJobs)
  4529. {
  4530. foreach (var pjSlotWafer in pj.SlotWafers)
  4531. {
  4532. WaferInfo waferInfo = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  4533. if (waferInfo.ProcessState == EnumWaferProcessStatus.Completed
  4534. && waferInfo.SubstTransStatus == SubstrateTransportStatus.AtDestination)
  4535. {
  4536. count++;
  4537. }
  4538. }
  4539. }
  4540. if (count > _throughputData.CalcingProcessedCount)
  4541. {
  4542. _throughputData.UpdateCalcing(count);
  4543. }
  4544. }
  4545. #endregion
  4546. #region Checked
  4547. public bool CheckCanProcess(ModuleName pmModule)
  4548. {
  4549. var wafer0 = WaferManager.Instance.GetWafer(pmModule, 0);
  4550. var wafer1 = WaferManager.Instance.GetWafer(pmModule, 1);
  4551. //如果PM腔体中有wafer,但不需要process,则不允许PM进行Process
  4552. if (!wafer0.IsEmpty && !CheckWaferNeedProcess(pmModule, 0, pmModule))
  4553. {
  4554. return false;
  4555. }
  4556. if (!wafer1.IsEmpty && !CheckWaferNeedProcess(pmModule, 1, pmModule))
  4557. {
  4558. return false;
  4559. }
  4560. //如果PM腔体中两片wafer都需要Process,并且recipe名字相同,则允许process
  4561. if (CheckWaferNeedProcess(pmModule, 0, pmModule)
  4562. && CheckWaferNeedProcess(pmModule, 1, pmModule)
  4563. && wafer0.ProcessJob.Sequence.Name == wafer1.ProcessJob.Sequence.Name)
  4564. {
  4565. return true;
  4566. }
  4567. //如果PM腔体中只有一片wafer需要Process,并且LLA/LLB/TMRobot中找不到相同SequenceName的wafer时,允许process
  4568. if (CheckWaferNeedProcess(pmModule, 0, pmModule))
  4569. {
  4570. var pmWafer = WaferManager.Instance.GetWafer(pmModule, 0);
  4571. if (pmWafer.ProcessJob != null)
  4572. {
  4573. if (GetSameSequenceUnprocessedWaferCount(new List<ModuleName>() { ModuleName.LLA, ModuleName.LLB, ModuleName.TMRobot }, pmWafer.ProcessJob.Sequence.Name) == 0)
  4574. return true;
  4575. }
  4576. }
  4577. if (CheckWaferNeedProcess(pmModule, 1, pmModule))
  4578. {
  4579. var pmWafer = WaferManager.Instance.GetWafer(pmModule, 1);
  4580. if (pmWafer.ProcessJob != null)
  4581. {
  4582. if (GetSameSequenceUnprocessedWaferCount(new List<ModuleName>() { ModuleName.LLA, ModuleName.LLB, ModuleName.TMRobot }, pmWafer.ProcessJob.Sequence.Name) == 0)
  4583. return true;
  4584. }
  4585. }
  4586. return false;
  4587. }
  4588. public bool CheckCanPlaceWaferToPM(ModuleName pmModule, WaferInfo wafer)
  4589. {
  4590. if (!_tmRobot.IsAvailable)
  4591. return false;
  4592. if (!CheckWaferNeedProcess(wafer, pmModule))
  4593. return false;
  4594. var wafer0 = WaferManager.Instance.GetWafer(pmModule, 0);
  4595. if (!wafer0.IsEmpty && !CheckWaferNeedProcess(pmModule, 0, pmModule))
  4596. {
  4597. return false;
  4598. }
  4599. var wafer1 = WaferManager.Instance.GetWafer(pmModule, 1);
  4600. if (!wafer1.IsEmpty && !CheckWaferNeedProcess(pmModule, 1, pmModule))
  4601. {
  4602. return false;
  4603. }
  4604. if (CheckWaferNeedProcess(wafer0, pmModule)
  4605. && CheckWaferNeedProcess(wafer, pmModule)
  4606. && wafer0.ProcessJob.Sequence.Name == wafer.ProcessJob.Sequence.Name)
  4607. return true;
  4608. if (CheckWaferNeedProcess(wafer1, pmModule)
  4609. && CheckWaferNeedProcess(wafer, pmModule)
  4610. && wafer1.ProcessJob.Sequence.Name == wafer.ProcessJob.Sequence.Name)
  4611. return true;
  4612. if (wafer0.IsEmpty
  4613. && wafer1.IsEmpty
  4614. && CheckWaferNeedProcess(wafer, pmModule))
  4615. return true;
  4616. return false;
  4617. }
  4618. public bool CheckCanPickWaferFromPM(ModuleName pmModule, int slot)
  4619. {
  4620. if (!_tmRobot.IsAvailable)
  4621. return false;
  4622. var wafer = WaferManager.Instance.GetWafer(pmModule, slot);
  4623. if (!wafer.IsEmpty
  4624. && wafer.ProcessJob != null
  4625. && wafer.ProcessJob.Sequence != null
  4626. && wafer.ProcessJob.Sequence.Steps != null
  4627. && wafer.ProcessState == EnumWaferProcessStatus.Completed)
  4628. return true;
  4629. return false;
  4630. }
  4631. public int GetSameSequenceUnprocessedWaferCount(List<ModuleName> modules, string sequenceName)
  4632. {
  4633. int count = 0;
  4634. for (int i = 0; i < modules.Count; i++)
  4635. {
  4636. var wafers = WaferManager.Instance.GetWafers(modules[i]);
  4637. for (int j = 0; j < wafers.Length; j++)
  4638. {
  4639. if (CheckWaferNeedProcess(wafers[j])
  4640. && wafers[j].ProcessJob != null
  4641. && wafers[j].ProcessJob.Sequence.Name == sequenceName)
  4642. count++;
  4643. }
  4644. }
  4645. return count;
  4646. }
  4647. public int? GetAvilableLoadLockSlotForEfemRobotPlace(SchedulerLoadLock ll)
  4648. {
  4649. if (!ll.IsAvailable)
  4650. return null;
  4651. var wafers = WaferManager.Instance.GetWafers(ll.Module);
  4652. for (int i = 0; i < wafers.Length; i++)
  4653. {
  4654. if (wafers[i].IsEmpty && ll.IsReadyForPlace(ModuleName.TMRobot, Hand.Blade1, i))
  4655. return i;
  4656. }
  4657. return null;
  4658. }
  4659. public int? GetAvilableLoadLockSlotForTMRobotPlace(SchedulerLoadLock ll)
  4660. {
  4661. if (!ll.IsAvailable)
  4662. return null;
  4663. var wafers = WaferManager.Instance.GetWafers(ll.Module);
  4664. for (int i = 0; i < wafers.Length; i++)
  4665. {
  4666. if (wafers[i].IsEmpty && ll.IsReadyForPlace(ModuleName.TMRobot, Hand.Blade1, i))
  4667. return i;
  4668. }
  4669. return null;
  4670. }
  4671. public int? GetAvilableLoadLockSlotForTMRobotPick(SchedulerLoadLock ll)
  4672. {
  4673. if (!ll.IsAvailable)
  4674. return null;
  4675. var wafers = WaferManager.Instance.GetWafers(ll.Module);
  4676. foreach (var pm in _lstPms)
  4677. {
  4678. var pmWafer0 = WaferManager.Instance.GetWafer(pm.Module, 0);
  4679. var pmWafer1 = WaferManager.Instance.GetWafer(pm.Module, 1);
  4680. //如果腔体中两片都满了,则跳过
  4681. if (!pmWafer0.IsEmpty && !pmWafer1.IsEmpty)
  4682. continue;
  4683. //如果腔体中两片都为空,则取一片放入
  4684. if (pmWafer0.IsEmpty && pmWafer1.IsEmpty)
  4685. {
  4686. for (int i = 0; i < wafers.Length; i++)
  4687. {
  4688. if (!wafers[i].IsEmpty
  4689. && ll.IsReadyForPick(ModuleName.TMRobot, Hand.Blade1, i)
  4690. && CheckWaferNeedProcess(ll.Module, i))
  4691. return i;
  4692. }
  4693. }
  4694. //如果腔体中一片为空,则取一片相同recipeName的放入
  4695. if (!pmWafer0.IsEmpty || !pmWafer1.IsEmpty)
  4696. {
  4697. var wafer = !pmWafer0.IsEmpty ? pmWafer0 : pmWafer1;
  4698. if (!CheckWaferNeedProcess(wafer))
  4699. return null;
  4700. var tmWafers = WaferManager.Instance.GetWafers(ModuleName.TMRobot);
  4701. //判断TMRobot是否已经存在相同recipeName的wafer
  4702. for (int i = 0; i < tmWafers.Length; i++)
  4703. {
  4704. if (CheckWaferNeedProcess(tmWafers[i])
  4705. && tmWafers[i].ProcessJob.Sequence.Name == wafer.ProcessJob.Sequence.Name)
  4706. return null;
  4707. }
  4708. for (int i = 0; i < wafers.Length; i++)
  4709. {
  4710. if (!wafers[i].IsEmpty
  4711. && ll.IsReadyForPick(ModuleName.TMRobot, Hand.Blade1, i)
  4712. && CheckWaferNeedProcess(ll.Module, i)
  4713. && wafers[i].ProcessJob.Sequence.Name == wafer.ProcessJob.Sequence.Name)
  4714. return i;
  4715. }
  4716. }
  4717. }
  4718. return null;
  4719. }
  4720. public List<Tuple<SchedulerLoadLock, int>> GetAvilableLoadLockSlotForTMRobotPick()
  4721. {
  4722. List<Tuple<SchedulerLoadLock, int>> result = new List<Tuple<SchedulerLoadLock, int>>();
  4723. foreach (var ll in _lstLls)
  4724. {
  4725. if (!ll.IsAvailable)
  4726. continue;
  4727. var wafers = WaferManager.Instance.GetWafers(ll.Module);
  4728. foreach (var pm in _lstPms)
  4729. {
  4730. var pmWafer0 = WaferManager.Instance.GetWafer(pm.Module, 0);
  4731. var pmWafer1 = WaferManager.Instance.GetWafer(pm.Module, 1);
  4732. //如果腔体中两片都满了,则跳过
  4733. if (!pmWafer0.IsEmpty && !pmWafer1.IsEmpty)
  4734. continue;
  4735. //如果腔体中两片都为空,则取一片放入
  4736. if (pmWafer0.IsEmpty && pmWafer1.IsEmpty)
  4737. {
  4738. for (int i = 0; i < wafers.Length; i++)
  4739. {
  4740. if (!wafers[i].IsEmpty
  4741. && ll.IsReadyForPick(ModuleName.TMRobot, Hand.Blade1, i)
  4742. && CheckWaferNeedProcess(ll.Module, i, pm.Module)
  4743. && !result.Exists(x => x.Item1 == ll && x.Item2 == i))
  4744. result.Add(new Tuple<SchedulerLoadLock, int>(ll, i));
  4745. }
  4746. }
  4747. //如果腔体中一片为空,则取一片相同recipeName的放入
  4748. if (!pmWafer0.IsEmpty || !pmWafer1.IsEmpty)
  4749. {
  4750. var wafer = !pmWafer0.IsEmpty ? pmWafer0 : pmWafer1;
  4751. if (!CheckWaferNeedProcess(wafer))
  4752. continue;
  4753. var tmWafers = WaferManager.Instance.GetWafers(ModuleName.TMRobot);
  4754. //判断TMRobot是否已经存在相同recipeName的wafer
  4755. for (int i = 0; i < tmWafers.Length; i++)
  4756. {
  4757. if (CheckWaferNeedProcess(tmWafers[i])
  4758. && tmWafers[i].ProcessJob.Sequence.Name == wafer.ProcessJob.Sequence.Name)
  4759. continue;
  4760. }
  4761. for (int i = 0; i < wafers.Length; i++)
  4762. {
  4763. if (!wafers[i].IsEmpty
  4764. && ll.IsReadyForPick(ModuleName.TMRobot, Hand.Blade1, i)
  4765. && CheckWaferNeedProcess(ll.Module, i, pm.Module)
  4766. && wafers[i].ProcessJob.Sequence.Name == wafer.ProcessJob.Sequence.Name
  4767. && !result.Exists(x => x.Item1 == ll && x.Item2 == i))
  4768. result.Add(new Tuple<SchedulerLoadLock, int>(ll, i));
  4769. }
  4770. }
  4771. }
  4772. }
  4773. return result;
  4774. }
  4775. public List<Tuple<SchedulerLoadLock, int>> FindAllLoadLockSlotForTMRobotPick()
  4776. {
  4777. List<Tuple<SchedulerLoadLock, int>> result = new List<Tuple<SchedulerLoadLock, int>>();
  4778. foreach (var ll in _lstLls)
  4779. {
  4780. var wafers = WaferManager.Instance.GetWafers(ll.Module);
  4781. foreach (var pm in _lstPms)
  4782. {
  4783. var pmWafer0 = WaferManager.Instance.GetWafer(pm.Module, 0);
  4784. var pmWafer1 = WaferManager.Instance.GetWafer(pm.Module, 1);
  4785. //如果腔体中两片都满了,则跳过
  4786. if (!pmWafer0.IsEmpty && !pmWafer1.IsEmpty)
  4787. continue;
  4788. //如果腔体中两片都为空,则取一片放入
  4789. if (pmWafer0.IsEmpty && pmWafer1.IsEmpty)
  4790. {
  4791. for (int i = 0; i < wafers.Length; i++)
  4792. {
  4793. if (!wafers[i].IsEmpty
  4794. && ll.IsReadyForPick(ModuleName.TMRobot, Hand.Blade1, i)
  4795. && CheckWaferNeedProcess(ll.Module, i, pm.Module)
  4796. && !result.Exists(x => x.Item1 == ll && x.Item2 == i))
  4797. result.Add(new Tuple<SchedulerLoadLock, int>(ll, i));
  4798. }
  4799. }
  4800. //如果腔体中一片为空,则取一片相同recipeName的放入
  4801. if (!pmWafer0.IsEmpty || !pmWafer1.IsEmpty)
  4802. {
  4803. var wafer = !pmWafer0.IsEmpty ? pmWafer0 : pmWafer1;
  4804. if (!CheckWaferNeedProcess(wafer))
  4805. continue;
  4806. var tmWafers = WaferManager.Instance.GetWafers(ModuleName.TMRobot);
  4807. //判断TMRobot是否已经存在相同recipeName的wafer
  4808. for (int i = 0; i < tmWafers.Length; i++)
  4809. {
  4810. if (CheckWaferNeedProcess(tmWafers[i])
  4811. && tmWafers[i].ProcessJob.Sequence.Name == wafer.ProcessJob.Sequence.Name)
  4812. continue;
  4813. }
  4814. for (int i = 0; i < wafers.Length; i++)
  4815. {
  4816. if (!wafers[i].IsEmpty
  4817. && ll.IsReadyForPick(ModuleName.TMRobot, Hand.Blade1, i)
  4818. && CheckWaferNeedProcess(ll.Module, i, pm.Module)
  4819. && wafers[i].ProcessJob.Sequence.Name == wafer.ProcessJob.Sequence.Name
  4820. && !result.Exists(x => x.Item1 == ll && x.Item2 == i))
  4821. result.Add(new Tuple<SchedulerLoadLock, int>(ll, i));
  4822. }
  4823. }
  4824. }
  4825. }
  4826. return result;
  4827. }
  4828. public int GetWaferCountLoadLockToPM(ModuleName pmModule)
  4829. {
  4830. int result = 0;
  4831. foreach (var ll in _lstLls)
  4832. {
  4833. var wafers = WaferManager.Instance.GetWafers(ll.Module);
  4834. foreach (var pm in _lstPms)
  4835. {
  4836. if (pm.Module != pmModule)
  4837. continue;
  4838. for (int i = 0; i < wafers.Length; i++)
  4839. {
  4840. if (!wafers[i].IsEmpty && CheckWaferNeedProcess(ll.Module, i, pm.Module))
  4841. result++;
  4842. }
  4843. }
  4844. }
  4845. return result;
  4846. }
  4847. #endregion
  4848. }
  4849. }