AutoTransfer.cs 298 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305
  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. #region 常量
  42. /// <summary>
  43. /// ProcessJob状态变化
  44. /// </summary>
  45. private const string E40ProcessStateChanged = "E40ProcessStateChanged";
  46. #endregion
  47. //const Hand Hand_Dual = Hand.Blade1;
  48. //const Hand Hand_Single = Hand.Blade2;
  49. //用于避免两爪都有wafer,放了一片就又去LoadPort Pick
  50. private bool EfemRobotPickAllowable = true;
  51. private bool _isRunningInParallelMode;
  52. private List<ModuleName> _mapTarget = new List<ModuleName>();
  53. private List<ControlJobInfo> _lstControlJobs = new List<ControlJobInfo>();
  54. private List<ProcessJobInfo> _lstProcessJobs = new List<ProcessJobInfo>();
  55. //private Object _locker = new Object();
  56. private List<SchedulerPM> _lstPms = new List<SchedulerPM>();
  57. private List<SchedulerLoadPort> _lstLps = new List<SchedulerLoadPort>();
  58. private List<SchedulerLoadLock> _lstLls = new List<SchedulerLoadLock>();
  59. private List<SchedulerAligner> _lstAligners = new List<SchedulerAligner>();
  60. private List<SchedulerAligner> _lstCoolings = new List<SchedulerAligner>();
  61. private List<SchedulerPM> _lstPmsCurrentSequence = new List<SchedulerPM>();
  62. private R_TRIG _trigLp1JobComplete = new R_TRIG();
  63. private R_TRIG _trigLp2JobComplete = new R_TRIG();
  64. private R_TRIG _trigLp3JobComplete = new R_TRIG();
  65. private Dictionary<ModuleName, R_TRIG> _checkNoCarrierByModule = new Dictionary<ModuleName, R_TRIG>();
  66. private Dictionary<string, float> _temperatureSetpointDic = new Dictionary<string, float>();
  67. private Dictionary<string, R_TRIG> _temperatureTrigDic = new Dictionary<string, R_TRIG>();
  68. private Dictionary<string, List<string>> currentSlotSequenceList = new Dictionary<string, List<string>>()
  69. {
  70. {"LP1",Enumerable.Repeat("",25).ToList()},
  71. {"LP2",Enumerable.Repeat("",25).ToList()},
  72. {"LP3",Enumerable.Repeat("",25).ToList()}
  73. };
  74. private const string LogSource = "Scheduler";
  75. private int[] _pmSlots = new int[] { 0, 1 };
  76. private int[] _llSlots = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 };
  77. private Dictionary<ModuleName, Tuple<R_TRIG, DeviceTimer>> _pmSwapWaitTimeOut = new Dictionary<ModuleName, Tuple<R_TRIG, DeviceTimer>>();
  78. public bool PreheatDone { get; set; }
  79. //private bool _isCycleMode;
  80. //private int _cycleSetPoint = 0;
  81. //private int _cycledCount = 0;
  82. //private int _cycledWafer = 0;
  83. private SchedulerFACallback _faCallback;
  84. private SchedulerDBCallback _dbCallback;
  85. //private float _throughput;
  86. //private DeviceTimer _throughputTimer = new DeviceTimer();
  87. //private int _processedWaferCountInFinishedCJ;
  88. class CycleData
  89. {
  90. public DateTime StartTime { get; private set; }
  91. public TimeSpan EscapeTime => _lpCycleTime.Count == 0 ? TimeSpan.Zero : DateTime.Now.Subtract(_lpCycleTime.Values.Min());
  92. public bool IsCycleMode => SC.GetValue<bool>("System.IsCycleMode");
  93. public string CycleBy => SC.GetStringValue("System.CycleBy");
  94. public int CycleCountSetPoint => SC.GetValue<int>("System.CycleCount");// 设置的循环次数
  95. public int CycledCount => _lpCycleCount.Count == 0 ? 0:_lpCycleCount.Values.Min();// 已处理的循环次数
  96. public int CycleWaferCountSetPoint => SC.GetValue<int>("System.CycleWaferCount");// 设置的晶圆片数
  97. public int CycledWaferCount => _lpCycleWafer.Values.Sum(); // 已处理的晶圆片数
  98. private Dictionary<ModuleName, int> _lpCycleCount = new Dictionary<ModuleName, int>();
  99. private Dictionary<ModuleName, DateTime> _lpCycleTime = new Dictionary<ModuleName, DateTime>();
  100. private Dictionary<ModuleName, int> _lpCycleWafer = new Dictionary<ModuleName, int>();
  101. public void Start(ModuleName lpModule, bool isReset)
  102. {
  103. LOG.Info("Cycle: Start cycle data");
  104. if (isReset) Reset();
  105. _lpCycleCount[lpModule] = 0;
  106. _lpCycleTime[lpModule] = DateTime.Now;
  107. _lpCycleWafer[lpModule] = 0;
  108. }
  109. public void Reset()
  110. {
  111. LOG.Info("Cycle: Reset cycle data");
  112. _lpCycleCount.Clear();
  113. _lpCycleTime.Clear();
  114. _lpCycleWafer.Clear();
  115. }
  116. //public void BeginOrAddCycle(int setpoint)
  117. //{
  118. // if (IsCycleMode) // add
  119. // {
  120. // CycleWaferCountSetPoint += setpoint;
  121. // LOG.Info($"Cycle: Add {setpoint} wafers, total cycle count = {CycleWaferCountSetPoint}");
  122. // }
  123. // else // begin
  124. // {
  125. // IsCycleMode = true;
  126. // StartTime = DateTime.Now;
  127. // CycleWaferCountSetPoint = setpoint;
  128. // CycledWaferCount = 0;
  129. // LOG.Info($"Cycle: Begin {setpoint} wafers");
  130. // }
  131. //}
  132. public bool IsCycleEnd(ModuleName lpModule)
  133. {
  134. if (!IsCycleMode)
  135. return true;
  136. return (CycleBy == "WaferCount" && CycledWaferCount >= CycleWaferCountSetPoint) ||
  137. (CycleBy == "LotCount" && _lpCycleCount[lpModule] >= CycleCountSetPoint);
  138. }
  139. public bool IsCycleEnd()
  140. {
  141. if (!IsCycleMode)
  142. return true;
  143. return (CycleBy == "WaferCount" && CycledWaferCount >= CycleWaferCountSetPoint) ||
  144. (CycleBy == "LotCount" && _lpCycleCount.Values.Count > 0 && _lpCycleCount.Values.Min() >= CycleCountSetPoint);
  145. }
  146. public void Increase(ModuleName lpModule, int waferCount, int count = 1)
  147. {
  148. IncreaseWaferCount(lpModule, waferCount);
  149. IncreaseCount(lpModule, count);
  150. }
  151. public void IncreaseWaferCount(ModuleName lpModule, int waferCount)
  152. {
  153. _lpCycleWafer[lpModule]++;
  154. LOG.Info($"Cycle: finished {CycledWaferCount} wafer(s)");
  155. }
  156. public void IncreaseCount(ModuleName lpModule, int count = 1)
  157. {
  158. _lpCycleCount[lpModule]++;
  159. LOG.Info($"Cycle: finished {CycledCount} Count(s)");
  160. }
  161. }
  162. class ThroughputData
  163. {
  164. public bool IsCalcing { get; private set; } = false;
  165. public DateTime CacledLastTime { get; private set; } = DateTime.MinValue; // 创建时间或者计算时间
  166. public double CalcedTotalTimeSeconds { get; private set; } = 0; // 总的计算时间
  167. public int CalcedProcessedCount { get; private set; } = 0; // 已计算完的总数(control job)
  168. public double TotalTimeSeconds { get; private set; }
  169. public DateTime CaclingLastTime { get; private set; } = DateTime.MinValue; // 创建时间或者计算时间
  170. public int CalcingProcessedCount { get; private set; } = 0;// 正在计算的总数(control job)
  171. public int ProcessedCount => CalcedProcessedCount + CalcingProcessedCount;
  172. public double Throughput { get; private set; }
  173. public double LiveThroughput { get; private set; }
  174. public void BeginCalc()
  175. {
  176. if (IsCalcing) return;
  177. IsCalcing = true;
  178. CalcedTotalTimeSeconds = 0;
  179. CacledLastTime = DateTime.Now;
  180. CaclingLastTime = DateTime.Now;
  181. LOG.Info("Throughput: Begin");
  182. }
  183. public void Pause()
  184. {
  185. if (!IsCalcing)
  186. {
  187. IsCalcing = false;
  188. //LOG.Info("Throughput: Pause");
  189. }
  190. }
  191. public void Reset()
  192. {
  193. CacledLastTime = DateTime.Now;
  194. CalcedTotalTimeSeconds = 0;
  195. CalcedProcessedCount = 0;
  196. CaclingLastTime = DateTime.Now;
  197. CalcedProcessedCount = 0;
  198. CalcingProcessedCount = 0;
  199. Throughput = 0;
  200. LiveThroughput = 0;
  201. LOG.Info("Throughput: Reset");
  202. }
  203. public void UpdateCalced(int calcedCount)
  204. {
  205. CalcedProcessedCount += calcedCount;
  206. CalcingProcessedCount -= calcedCount;
  207. if (CalcingProcessedCount < 0) CalcingProcessedCount = 0;
  208. CalcedTotalTimeSeconds += DateTime.Now.Subtract(CacledLastTime).TotalSeconds;
  209. CacledLastTime = DateTime.Now;
  210. }
  211. public void UpdateCalcing(int calcingCount)
  212. {
  213. DateTime now = DateTime.Now;
  214. double seconds_this = now.Subtract(CaclingLastTime).TotalSeconds;
  215. int calcingCount_this = calcingCount - CalcingProcessedCount;
  216. double count_this = ProcessedCount + calcingCount;
  217. LiveThroughput = 3600 / (seconds_this / calcingCount_this);
  218. TotalTimeSeconds = CalcedTotalTimeSeconds + seconds_this;
  219. Throughput = 3600 * count_this / TotalTimeSeconds;
  220. LOG.Info($"Throughput: {Throughput}, Finished {count_this} wafer(s) in {(int)TotalTimeSeconds} seconds;" +
  221. $" {LiveThroughput} last wafer in {(int)seconds_this} seconds");
  222. CaclingLastTime = now;
  223. CalcingProcessedCount = calcingCount;
  224. }
  225. }
  226. private CycleData _CycleData = new CycleData();
  227. private ThroughputData _throughputData = new ThroughputData();
  228. private bool _isAutoUnloadFoup
  229. {
  230. get
  231. {
  232. return SC.GetValue<bool>("EFEM.LoadPort.EnableAutoUnloadFoup");
  233. }
  234. }
  235. private bool _PMA1Disabled;
  236. private bool _PMA2Disabled;
  237. private bool _PMB1Disabled;
  238. private bool _PMB2Disabled;
  239. private ModuleName _TMRobotBlade1Station = ModuleName.System;
  240. private Dictionary<ModuleName, bool> _loadlockCooling = new Dictionary<ModuleName, bool>();
  241. Queue<Action> tmRobotActions = new Queue<Action>() { };
  242. Queue<Action> efemRobotActions = new Queue<Action>() { };
  243. public AutoTransfer(EquipmentManager equipment)
  244. {
  245. _PMA1Disabled = SC.GetValueOrDefault<bool>($"System.SetUp.PMAChamber1Disabled.IsInstalled");
  246. _PMA2Disabled = SC.GetValueOrDefault<bool>($"System.SetUp.PMAChamber2Disabled.IsInstalled");
  247. _PMB1Disabled = SC.GetValueOrDefault<bool>($"System.SetUp.PMBChamber1Disabled.IsInstalled");
  248. _PMB2Disabled = SC.GetValueOrDefault<bool>($"System.SetUp.PMBChamber2Disabled.IsInstalled");
  249. _faCallback = new SchedulerFACallback();
  250. _dbCallback = new SchedulerDBCallback();
  251. if (SC.GetValueOrDefault<bool>("System.SetUp.PMA.IsInstalled"))
  252. _lstPms.Add(_pm1);
  253. if (SC.GetValueOrDefault<bool>("System.SetUp.PMB.IsInstalled"))
  254. _lstPms.Add(_pm2);
  255. //if (SC.GetValueOrDefault<bool>("System.SetUp.PMC.IsInstalled"))
  256. // _lstPms.Add(_pm3);
  257. if (SC.GetValueOrDefault<bool>("System.SetUp.LLA.IsInstalled"))
  258. _lstLls.Add(_loadlockA);
  259. if (SC.GetValueOrDefault<bool>("System.SetUp.LLB.IsInstalled"))
  260. _lstLls.Add(_loadlockB);
  261. if (SC.GetValueOrDefault<bool>("System.SetUp.Aligner1.IsInstalled"))
  262. _lstAligners.Add(_aligner1);
  263. if (SC.GetValueOrDefault<bool>("System.SetUp.Aligner2.IsInstalled"))
  264. _lstAligners.Add(_aligner2);
  265. if (SC.GetValueOrDefault<bool>("System.SetUp.Cooling1.IsInstalled"))
  266. _lstCoolings.Add(_cooling1);
  267. if (SC.GetValueOrDefault<bool>("System.SetUp.Cooling2.IsInstalled"))
  268. _lstCoolings.Add(_cooling2);
  269. if (SC.GetValueOrDefault<bool>("System.SetUp.LP1.IsInstalled"))
  270. {
  271. _lstLps.Add(_lp1);
  272. _checkNoCarrierByModule[_lp1.Module] = new R_TRIG();
  273. }
  274. if (SC.GetValueOrDefault<bool>("System.SetUp.LP2.IsInstalled"))
  275. {
  276. _lstLps.Add(_lp2);
  277. _checkNoCarrierByModule[_lp2.Module] = new R_TRIG();
  278. }
  279. if (SC.GetValueOrDefault<bool>("System.SetUp.LP3.IsInstalled"))
  280. {
  281. _lstLps.Add(_lp3);
  282. _checkNoCarrierByModule[_lp3.Module] = new R_TRIG();
  283. }
  284. _pmSwapWaitTimeOut.Clear();
  285. _lstPms.ForEach(p=>_pmSwapWaitTimeOut[p.Module] = new Tuple<R_TRIG, DeviceTimer>(new R_TRIG(),new DeviceTimer()));
  286. //临时办法,设备异常后进行reset,重新home后reset机械手task
  287. OP.Subscribe($"{ModuleName.TM}.ResetTask", (string cmd, object[] args) =>
  288. {
  289. _tmRobot.ResetTask();
  290. return true;
  291. });
  292. OP.Subscribe($"{ModuleName.EFEM}.ResetTask", (string cmd, object[] args) =>
  293. {
  294. _efem.ResetTask();
  295. return true;
  296. });
  297. DATA.Subscribe("Scheduler.IsCycleMode", () => _CycleData.IsCycleMode);
  298. DATA.Subscribe("Scheduler.CycleBy", () => _CycleData.CycleBy);
  299. DATA.Subscribe("Scheduler.CycleCountSetPoint", () => _CycleData.CycleCountSetPoint);
  300. DATA.Subscribe("Scheduler.CycledCount", () => _CycleData.CycledCount);
  301. DATA.Subscribe("Scheduler.CycleWaferCountSetPoint", () => _CycleData.CycleWaferCountSetPoint);
  302. DATA.Subscribe("Scheduler.CycledWaferCount", () => _CycleData.CycledWaferCount);
  303. DATA.Subscribe("Scheduler.CycleEscapeTime", () => _CycleData.EscapeTime);
  304. DATA.Subscribe("Scheduler.Throughput", () => _throughputData.Throughput);
  305. DATA.Subscribe("Scheduler.LiveThroughput", () => _throughputData.LiveThroughput);
  306. DATA.Subscribe("System.Scheduler.RunningRecipeList", () => _GetRunningRecipeList());
  307. DATA.Subscribe("Scheduler.CjIdList", () => _GetRunningCjIdList());
  308. DATA.Subscribe("Scheduler.CurrentRecipeList", () =>
  309. {
  310. return _lstProcessJobs;
  311. });
  312. for (int j=1; j<= _lstLps.Count;j++)
  313. {
  314. int lpIndex = j;
  315. ModuleName lp = _lstLps[lpIndex-1].Module;
  316. DATA.Subscribe($"{lp}.LocalJobName", () =>
  317. {
  318. var jb = _lstControlJobs.Find(x => x.Module == $"{lp}");
  319. if (jb != null)
  320. return jb.Name;
  321. return "";
  322. });
  323. DATA.Subscribe($"{lp}.JobLotName", () =>
  324. {
  325. var cj = _lstControlJobs.FirstOrDefault(x => x.Module == $"{lp}");
  326. if (cj != null)
  327. return cj.LotName;
  328. return "";
  329. });
  330. DATA.Subscribe($"{lp}.LocalJobStatus", () =>
  331. {
  332. var jb = _lstControlJobs.Find(x => x.Module == $"{lp}");
  333. if (jb != null)
  334. return jb.State.ToString();
  335. return "";
  336. });
  337. DATA.Subscribe($"{lp}.CurrentRecipeList", () =>
  338. {
  339. List<string> result = Enumerable.Repeat("", 25).ToList();
  340. for (int i = 0; i < _lstProcessJobs.Count; i++)
  341. {
  342. if (_lstProcessJobs[i].SlotWafers != null)
  343. {
  344. foreach (var wafers in _lstProcessJobs[i].SlotWafers)
  345. {
  346. if (wafers.Item1 == lp)
  347. {
  348. result[wafers.Item2] = _lstProcessJobs[i].Sequence.Name;
  349. }
  350. }
  351. }
  352. }
  353. return result;
  354. });
  355. }
  356. tmRobotActions.Enqueue(MonitorTmRobotPMPickAndPlaceTask);
  357. tmRobotActions.Enqueue(MonitorTmRobotPMAPlaceTask);
  358. tmRobotActions.Enqueue(MonitorTmRobotPMBPlaceTask);
  359. tmRobotActions.Enqueue(MonitorTmRobotPMAPlaceTask);
  360. tmRobotActions.Enqueue(MonitorTmRobotPMBPlaceTask);
  361. tmRobotActions.Enqueue(MonitorTmRobotPMAPlaceTask);
  362. tmRobotActions.Enqueue(MonitorTmRobotPMBPlaceTask);
  363. tmRobotActions.Enqueue(MonitorTmRobotLoadLockPickTask);
  364. tmRobotActions.Enqueue(MonitorTmRobotPMAPlaceTask);
  365. tmRobotActions.Enqueue(MonitorTmRobotPMBPlaceTask);
  366. tmRobotActions.Enqueue(MonitorTmRobotPMAPickTask);
  367. tmRobotActions.Enqueue(MonitorTmRobotPMBPickTask);
  368. tmRobotActions.Enqueue(MonitorTmRobotLoadLockPlaceTask);
  369. //tmRobotActions.Enqueue(MonitorTmRobotGoToTask);
  370. efemRobotActions.Enqueue(MonitorEfemRobotAlignerPickTask);
  371. efemRobotActions.Enqueue(MonitorEfemRobotAlignerPlaceTask);
  372. efemRobotActions.Enqueue(MonitorEfemRobotLoadLockPlaceTask);
  373. efemRobotActions.Enqueue(MonitorEfemRobotLoadLockPickTask);
  374. efemRobotActions.Enqueue(MonitorEfemRobotCoolingPickTask);
  375. efemRobotActions.Enqueue(MonitorEfemRobotCoolingPlaceTask);
  376. efemRobotActions.Enqueue(MonitorEfemRobotLoadPortPickTask);
  377. efemRobotActions.Enqueue(MonitorEfemRobotLoadPortPlaceTask);
  378. }
  379. private List<string> _GetRunningCjIdList()
  380. {
  381. return _lstControlJobs/*.Where(o => o.State == EnumControlJobState.Executing
  382. || o.State == EnumControlJobState.Paused)*/.Select(o => o.InnerId.ToString()).ToList();
  383. }
  384. const string StrProcessRecipe = "ProcessRecipe";
  385. const string StrRecipe = "Recipe";
  386. private List<string> _GetRunningRecipeList()
  387. {
  388. var runningCjList = _lstControlJobs.Where(o => o.State == EnumControlJobState.Executing
  389. || o.State == EnumControlJobState.Paused).Select(o => o.Name).ToList();
  390. return _lstProcessJobs.Where(o => runningCjList.Contains(o.ControlJobName))
  391. .SelectMany(a => a.Sequence.Steps.SelectMany(b => b.StepParameter.Where(c => c.Key == StrProcessRecipe || c.Key == StrRecipe))).Select(d => d.Value as string)
  392. .Where(o => !string.IsNullOrWhiteSpace(o)).ToList();
  393. }
  394. public bool HasJobRunning
  395. {
  396. get { return _lstControlJobs.Count > 0; }
  397. }
  398. public void Clear()
  399. {
  400. _tmRobot.ResetTask();
  401. _efem.ResetTask();
  402. foreach (var pm in _lstPms)
  403. {
  404. pm.ResetTask();
  405. }
  406. //foreach (var lp in _lstLps)
  407. //{
  408. // lp.ResetTask();
  409. //}
  410. _lstControlJobs.Clear();
  411. _lstProcessJobs.Clear();
  412. _temperatureSetpointDic.Clear();
  413. _temperatureTrigDic.Clear();
  414. _CycleData.Reset();
  415. }
  416. #region Job Management
  417. public bool CreateJob(Dictionary<string, object> param)
  418. {
  419. string reason;
  420. string[] slotSequence = (string[])param["SlotSequence"];
  421. string jobId = (string)param["JobId"];
  422. string module = (string)param["Module"];
  423. PreheatDone = false;
  424. bool autoStart = (bool)param["AutoStart"];
  425. string lotId = jobId;
  426. if (param.ContainsKey("LotId"))
  427. lotId = (string)param["LotId"];
  428. if(!_efem.Blade1Enable && !_efem.Blade2Enable)
  429. {
  430. EV.PostWarningLog(LogSource, $"EFEM lower blade and EFEM upper blade are not enabled ");
  431. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  432. return false;
  433. }
  434. if (!_tmRobot.Blade1Enable && !_tmRobot.Blade2Enable)
  435. {
  436. EV.PostWarningLog(LogSource, $"TM lower blade and TM upper blade are not enabled ");
  437. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  438. return false;
  439. }
  440. if (!ValidateSequence(slotSequence, out reason))
  441. {
  442. EV.PostWarningLog(LogSource, $"{reason}");
  443. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  444. return false;
  445. }
  446. if (slotSequence.Length != 25)
  447. {
  448. reason = $"slot sequence parameter not valid, length is {slotSequence.Length}, should be 25";
  449. EV.PostWarningLog(LogSource, reason);
  450. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  451. return false;
  452. }
  453. if (!ModuleHelper.IsLoadPort(ModuleHelper.Converter(module)))
  454. {
  455. reason = $"{module} should be LP";
  456. EV.PostWarningLog(LogSource, reason);
  457. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  458. return false;
  459. }
  460. if (string.IsNullOrEmpty(jobId))
  461. {
  462. jobId = "CJ_Local_" + module;
  463. }
  464. if (_lstControlJobs.Exists(x => x.Name == jobId))
  465. {
  466. reason = $"LotID : {jobId} already created";
  467. EV.PostAlarmLog(LogSource, reason);
  468. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  469. return false;
  470. }
  471. var sameLotId = _lstLps.Select(p => CarrierManager.Instance.GetCarrier(p.Module).LotId).Where(p => !string.IsNullOrWhiteSpace(p)).GroupBy(p => p).Where(p => p.Count() > 1);
  472. if(sameLotId != null && sameLotId.Count() >0)
  473. {
  474. reason = $"The Carrier's LotIds on the {_lstLps.Count} LoadPorts are the same , {sameLotId.ToList()[0].Key} .";
  475. EV.PostAlarmLog(LogSource, reason);
  476. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  477. return false;
  478. }
  479. SchedulerLoadPort lp = GetModule(module) as SchedulerLoadPort;
  480. if (!lp.CheckReadyRunJob())
  481. {
  482. reason = $"{module} not ready";
  483. EV.PostWarningLog(LogSource, reason);
  484. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  485. return false;
  486. }
  487. ControlJobInfo cj = new ControlJobInfo();
  488. cj.Name = jobId;
  489. cj.Module = module;
  490. cj.LotName = jobId;
  491. cj.LotInnerId = Guid.NewGuid();
  492. cj.LotWafers = new List<WaferInfo>();
  493. cj.SetState(EnumControlJobState.WaitingForStart);
  494. Dictionary<string, bool[]> seqSlot = new Dictionary<string, bool[]>();
  495. Dictionary<string, List<Tuple<ModuleName, int>>> seqSlotWafers = new Dictionary<string, List<Tuple<ModuleName, int>>>();
  496. Dictionary<string, string> indexSequence = new Dictionary<string, string>();
  497. bool enableGroupBySequence = SC.GetValue<bool>("System.Scheduler.GroupWaferBySequence");
  498. string WaferAssociationInfo = $"WaferAssociationInfo({module}):";
  499. for (int i = 0; i < 25; i++)
  500. {
  501. WaferAssociationInfo = WaferAssociationInfo + string.Format(" slot{0} -- {1};", i + 1, slotSequence[i]);
  502. if (string.IsNullOrEmpty(slotSequence[i]) || string.IsNullOrEmpty(slotSequence[i].Trim()))
  503. continue;
  504. string groupName = enableGroupBySequence ? slotSequence[i].Trim() : i.ToString();
  505. indexSequence[groupName] = slotSequence[i];
  506. if (!seqSlot.ContainsKey(groupName))
  507. {
  508. seqSlot[groupName] = new bool[25];
  509. }
  510. if (!seqSlotWafers.ContainsKey(groupName))
  511. {
  512. seqSlotWafers[groupName] = new List<Tuple<ModuleName, int>>();
  513. }
  514. seqSlot[groupName][i] = true;
  515. if (!WaferManager.Instance.CheckHasWafer(module, i))
  516. {
  517. reason = $"job wafer: {module} slot {i + 1} not in the carrier";
  518. EV.PostWarningLog(LogSource, reason);
  519. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  520. return false;
  521. }
  522. if (!WaferManager.Instance.CheckWafer(ModuleHelper.Converter(module), i, WaferStatus.Normal))
  523. {
  524. reason = $"job wafer: {module} slot {i + 1} status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).Status}";
  525. EV.PostWarningLog(LogSource, reason);
  526. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  527. return false;
  528. }
  529. var wafer = WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i);
  530. if (wafer == null || wafer.IsEmpty)
  531. {
  532. reason = $"specifies wafer: {module} slot {i + 1} not in the carrier";
  533. EV.PostWarningLog(LogSource, reason);
  534. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  535. return false;
  536. }
  537. if (!ModuleHelper.IsLoadPort(ModuleHelper.Converter(wafer.WaferOrigin.Split('.')[0])))
  538. {
  539. reason = $"specifies wafer: {module} slot {i + 1} not origin LP";
  540. EV.PostWarningLog(LogSource, reason);
  541. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  542. return false;
  543. }
  544. if (wafer.ProcessState != EnumWaferProcessStatus.Idle)
  545. {
  546. reason = $"specifies wafer: {module} slot {i + 1} process state is not idle";
  547. EV.PostWarningLog(LogSource, reason);
  548. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  549. return false;
  550. }
  551. seqSlotWafers[groupName].Add(Tuple.Create(ModuleHelper.Converter(module), i));
  552. cj.LotWafers.Add(WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i));
  553. WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), i).PPID = slotSequence[i];
  554. }
  555. currentSlotSequenceList[module] = slotSequence.Reverse().ToList();
  556. EV.PostInfoLog(LogSource, WaferAssociationInfo);
  557. if (seqSlotWafers.Count == 0)
  558. {
  559. reason = $"Can not create job, no wafer assigned";
  560. EV.PostWarningLog(LogSource, reason);
  561. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  562. return false;
  563. }
  564. List<ProcessJobInfo> pjs = new List<ProcessJobInfo>();
  565. string[] seqs = seqSlot.Keys.ToArray();
  566. for (int i = 0; i < seqs.Length; i++)
  567. {
  568. ProcessJobInfo pj = new ProcessJobInfo();
  569. pj.Name = jobId + "_" + (i + 1);
  570. pj.Sequence = SequenceInfoHelper.GetInfo(indexSequence[seqs[i]]);
  571. pj.ControlJobName = cj.Name;
  572. pj.LotName = lotId;
  573. pj.SlotWafers = seqSlotWafers[seqs[i]];
  574. pj.SetState(EnumProcessJobState.Queued);
  575. if (!CheckSequencePmReady(pj.Sequence, null, out _, out string innerReason))
  576. {
  577. reason = $"no valid chamber for the {innerReason}";
  578. EV.PostWarningLog(LogSource, reason);
  579. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  580. return false;
  581. }
  582. if (!CheckSequenceRecipeFileValid(pj.Sequence, out reason))
  583. {
  584. reason = $"recipe file not valid in the sequence, {reason}";
  585. EV.PostWarningLog(LogSource, reason);
  586. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  587. return false;
  588. }
  589. if (!CheckSequenceOrderOk(pj.Sequence, out reason))
  590. {
  591. reason = $"sequence path not valid, {reason}";
  592. EV.PostWarningLog(LogSource, reason);
  593. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  594. return false;
  595. }
  596. if (CheckSequenceNeedDummyWafer(pj.Sequence))
  597. {
  598. reason = $"create job failed, no valid dummy wafer exist";
  599. EV.PostWarningLog(LogSource, reason);
  600. _faCallback.JobCreateFailed(module, lotId, jobId, "");
  601. return false;
  602. }
  603. pjs.Add(pj);
  604. }
  605. foreach (var pj in pjs)
  606. {
  607. cj.ProcessJobNameList.Add(pj.Name);
  608. _lstProcessJobs.Add(pj);
  609. }
  610. _lstControlJobs.Add(cj);
  611. int totalWafer = 0;
  612. foreach (var pj in pjs)
  613. {
  614. foreach (var pjSlotWafer in pj.SlotWafers)
  615. {
  616. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  617. wafer.ProcessJob = pj;
  618. WaferDataRecorder.SetCjInfo(wafer.InnerId.ToString(), cj.InnerId.ToString());
  619. WaferDataRecorder.SetWaferSequence(wafer.InnerId.ToString(), pj.Sequence.Name);
  620. WaferDataRecorder.SetWaferLotId(wafer.InnerId.ToString(), lotId);
  621. WaferManager.Instance.UpdateWaferLotId(pjSlotWafer.Item1, pjSlotWafer.Item2, lotId);
  622. totalWafer++;
  623. }
  624. }
  625. _faCallback.JobCreated(cj, GetFirstProcessJob(cj));
  626. CarrierInfo carrier = CarrierManager.Instance.GetCarrier(cj.Module);
  627. JobDataRecorder.StartCJ(cj.InnerId.ToString(), carrier.InnerId.ToString(), cj.Name, cj.Module, cj.Module, totalWafer);
  628. return true;
  629. }
  630. public bool CreateControlJob(string jobId, string module, List<string> pjIDs, bool isAutoStart)
  631. {
  632. if (_lstControlJobs.Exists(x => x.Name == jobId))
  633. {
  634. EV.PostWarningLog(LogSource, $"{jobId} is already created");
  635. return false;
  636. }
  637. if (!ModuleHelper.IsLoadPort(ModuleHelper.Converter(module)))
  638. {
  639. EV.PostWarningLog(LogSource, $"{module} should be LoadPort");
  640. return false;
  641. }
  642. LoadPort lp = DEVICE.GetDevice<LoadPort>($"{module}");
  643. if (!lp.IsIdle)
  644. {
  645. EV.PostWarningLog(LogSource, $"{module} is not idle");
  646. return false;
  647. }
  648. if (!lp.IsMapped)
  649. {
  650. EV.PostWarningLog(LogSource, $"{module} is not mapped");
  651. return false;
  652. }
  653. if (!lp.IsPresent)
  654. {
  655. EV.PostWarningLog(LogSource, $"{module} is not present");
  656. return false;
  657. }
  658. foreach (var _lp in _lstLps)
  659. {
  660. if (_lp.Module.ToString() == module)
  661. {
  662. if (!_lp.IsOnline)
  663. {
  664. EV.PostWarningLog(LogSource, $"{module} is not online");
  665. return false;
  666. }
  667. if (_lp.IsError)
  668. {
  669. EV.PostWarningLog(LogSource, $"{module} is error");
  670. return false;
  671. }
  672. }
  673. }
  674. if (_lstProcessJobs.Count <= 0) //判断上一步ProcessJob是否创建成功
  675. {
  676. EV.PostWarningLog(LogSource, $"process job is not exist");
  677. return false;
  678. }
  679. ControlJobInfo cj = new ControlJobInfo();
  680. cj.Name = jobId;
  681. cj.Module = module;
  682. cj.SetState(EnumControlJobState.WaitingForStart);
  683. cj.LotName = jobId;
  684. cj.LotWafers = new List<WaferInfo>();
  685. int totalWafer = 0;
  686. foreach (var pjName in pjIDs)
  687. {
  688. var pj = _lstProcessJobs.FirstOrDefault(x => x.Name == pjName);
  689. if (pj == null)
  690. {
  691. LOG.Info($"not find {pjName} while create control job");
  692. continue;
  693. }
  694. var slotWafers = new List<Tuple<ModuleName, int>>();
  695. foreach (var slotWafer in pj.SlotWafers)
  696. {
  697. if (!WaferManager.Instance.CheckHasWafer(module, slotWafer.Item2))
  698. {
  699. EV.PostWarningLog(LogSource, $"job wafer: {module} slot {slotWafer.Item2 + 1} not in the carrier");
  700. return false;
  701. }
  702. if (!WaferManager.Instance.CheckWafer(ModuleHelper.Converter(module), slotWafer.Item2, WaferStatus.Normal))
  703. {
  704. EV.PostWarningLog(LogSource, $"job wafer: {module} slot {slotWafer.Item2 + 1} status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), slotWafer.Item2).Status}");
  705. return false;
  706. }
  707. if (WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), slotWafer.Item2).ProcessState != EnumWaferProcessStatus.Idle)
  708. {
  709. EV.PostWarningLog(LogSource, $"job wafer: {module} slot {slotWafer.Item2 + 1} process status is {WaferManager.Instance.GetWafer(ModuleHelper.Converter(module), slotWafer.Item2).ProcessState}");
  710. return false;
  711. }
  712. slotWafers.Add(Tuple.Create(ModuleHelper.Converter(module), slotWafer.Item2));
  713. totalWafer++;
  714. }
  715. pj.ControlJobName = jobId;
  716. cj.ProcessJobNameList.Add(pj.Name);
  717. pj.SlotWafers = slotWafers;
  718. foreach (var pjSlotWafer in pj.SlotWafers)
  719. {
  720. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  721. cj.LotWafers.Add(wafer);
  722. WaferDataRecorder.SetCjInfo(wafer.InnerId.ToString(), cj.InnerId.ToString());
  723. WaferDataRecorder.SetWaferSequence(wafer.InnerId.ToString(), pj.Sequence.Name);
  724. //WaferDataRecorder.SetWaferLotId(wafer.InnerId.ToString(), jobId);
  725. }
  726. }
  727. _lstControlJobs.Add(cj);
  728. CarrierInfo carrier = CarrierManager.Instance.GetCarrier(cj.Module);
  729. JobDataRecorder.StartCJ(cj.InnerId.ToString(), carrier.InnerId.ToString(), cj.Name, cj.Module, cj.Module, totalWafer);
  730. return true;
  731. }
  732. public bool CreateProcessJob(string jobId, string sequenceName, List<int> slotNumbers, bool isAutoStart)
  733. {
  734. var sequenceInfo = SequenceInfoHelper.GetInfo(sequenceName);
  735. #region 模块检查
  736. if (!CheckSequenceAlignerReady(sequenceInfo, out string reason))
  737. {
  738. EV.PostWarningLog(LogSource, $"Aligner is not ready for the {reason}");
  739. return false;
  740. }
  741. if (!CheckSequencePMReady(sequenceInfo, out reason))
  742. {
  743. EV.PostWarningLog(LogSource, $"PM is not ready for the {reason}");
  744. return false;
  745. }
  746. #endregion
  747. #region Sequence检查
  748. if (!CheckSequenceAlignerOrder(sequenceInfo, out reason))
  749. {
  750. EV.PostWarningLog(LogSource, $"Aligner order is not valid for the {reason}");
  751. return false;
  752. }
  753. if (!CheckSequencePMOrder(sequenceInfo, out reason))
  754. {
  755. EV.PostWarningLog(LogSource, $"PM order is not valid, {reason}");
  756. return false;
  757. }
  758. #endregion
  759. var slotWafers = new List<Tuple<ModuleName, int>>();
  760. foreach (var slot in slotNumbers)
  761. {
  762. slotWafers.Add(Tuple.Create(ModuleName.System, slot));
  763. }
  764. ProcessJobInfo pj = new ProcessJobInfo();
  765. pj.Name = jobId;
  766. pj.Sequence = sequenceInfo;
  767. pj.SlotWafers = slotWafers;
  768. pj.SetState(EnumProcessJobState.Queued);
  769. pj.CreateTime = DateTime.Now;
  770. _lstProcessJobs.Add(pj);
  771. return true;
  772. }
  773. /// <summary>
  774. /// 创建ControlJob
  775. /// </summary>
  776. /// <param name="controlJobId"></param>
  777. /// <param name="moduleName"></param>
  778. /// <param name="carrierId"></param>
  779. /// <param name="processJobs"></param>
  780. /// <param name="reason"></param>
  781. /// <returns></returns>
  782. public void CreateControlJob(string controlJobId, string carrierId, List<string> processJobs)
  783. {
  784. ControlJobInfo cj = new ControlJobInfo();
  785. cj.Name = controlJobId;
  786. cj.LotName = carrierId;
  787. cj.LotInnerId = Guid.NewGuid();
  788. cj.LotWafers = new List<WaferInfo>();
  789. cj.ProcessJobNameList = processJobs;
  790. cj.SetState(EnumControlJobState.WaitingForStart);
  791. cj.CreateTime = DateTime.Now;
  792. List<string> processJobsId = new List<string>();
  793. for (int i=0;i<processJobs.Count;i++)
  794. {
  795. ProcessJobInfo pj = _lstProcessJobs.Find(O => O.Name == processJobs[i]);
  796. if (pj != null)
  797. {
  798. if (pj.SlotWafers != null&&!processJobsId.Contains(pj.Name))
  799. {
  800. foreach (var pjSlotWafer in pj.SlotWafers)
  801. {
  802. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  803. WaferDataRecorder.SetCjInfo(wafer.InnerId.ToString(), cj.InnerId.ToString());
  804. cj.LotWafers.Add(wafer);
  805. }
  806. processJobsId.Add(pj.Name);
  807. }
  808. pj.ControlJobName = cj.Name;
  809. }
  810. }
  811. _lstControlJobs.Add(cj);
  812. _faCallback.JobCreated(cj, GetFirstProcessJob(cj));
  813. //CarrierInfo carrier = CarrierManager.Instance.GetCarrier(cj.Module);
  814. //JobDataRecorder.StartCJ(cj.InnerId.ToString(), carrier.InnerId.ToString(), cj.Name, cj.Module, cj.Module, totalWafer);
  815. }
  816. /// <summary>
  817. /// 检验创建ControlJob的条件
  818. /// </summary>
  819. /// <returns></returns>
  820. public bool CheckCreateControlJobCondition(List<string> modules, out string reason)
  821. {
  822. reason = "";
  823. if (!_efem.Blade1Enable && !_efem.Blade2Enable)
  824. {
  825. reason = $"EFEM lower blade and EFEM upper blade are not enabled ";
  826. EV.PostWarningLog(LogSource, reason);
  827. return false;
  828. }
  829. if (!_tmRobot.Blade1Enable && !_tmRobot.Blade2Enable)
  830. {
  831. reason = "TM lower blade and TM upper blade are not enabled ";
  832. EV.PostWarningLog(LogSource, reason);
  833. return false;
  834. }
  835. foreach (string module in modules)
  836. {
  837. SchedulerLoadPort lp = GetModule(module) as SchedulerLoadPort;
  838. if (!lp.CheckReadyRunJob())
  839. {
  840. reason = $"{module} not ready";
  841. EV.PostWarningLog(LogSource, reason);
  842. return false;
  843. }
  844. }
  845. return true;
  846. }
  847. /// <summary>
  848. /// 创建ProcessJob
  849. /// </summary>
  850. /// <param name="jobId"></param>
  851. /// <param name="sequenceName"></param>
  852. /// <returns></returns>
  853. public bool CreateProcessJob(string jobId, string sequenceName,string carrierId,out string reason)
  854. {
  855. reason = "";
  856. List<string> sequences = RecipeFileManager.Instance.GetSequenceNameList();
  857. if(!sequences.Contains(sequenceName))
  858. {
  859. reason = $"sequence[{sequenceName}] is not exist!";
  860. EV.PostWarningLog(LogSource,reason);
  861. return false;
  862. }
  863. var sequenceInfo = SequenceInfoHelper.GetInfo(sequenceName);
  864. #region 模块检查
  865. if (!CheckSequencePMReady(sequenceInfo, out reason))
  866. {
  867. EV.PostWarningLog(LogSource, $"PM is not ready for the {reason}");
  868. return false;
  869. }
  870. if (!CheckSequenceAlignerReady(sequenceInfo, out reason))
  871. {
  872. EV.PostWarningLog(LogSource, $"Aligner is not ready for the {reason}");
  873. return false;
  874. }
  875. #endregion
  876. #region Sequence检查
  877. if (!CheckSequenceAlignerOrder(sequenceInfo, out reason))
  878. {
  879. EV.PostWarningLog(LogSource, $"Aligner order is not valid for the {reason}");
  880. return false;
  881. }
  882. if (!CheckSequencePMOrder(sequenceInfo, out reason))
  883. {
  884. EV.PostWarningLog(LogSource, $"PM order is not valid, {reason}");
  885. return false;
  886. }
  887. #endregion
  888. ProcessJobInfo pj = new ProcessJobInfo();
  889. pj.Name = jobId;
  890. pj.Sequence = sequenceInfo;
  891. pj.LotName = carrierId;
  892. pj.CreateTime = DateTime.Now;
  893. pj.SetState(EnumProcessJobState.Queued);
  894. _lstProcessJobs.Add(pj);
  895. return true;
  896. }
  897. /// <summary>
  898. /// 更新processId对应的Wafer
  899. /// </summary>
  900. /// <param name="processJobId"></param>
  901. public void UpdateProcessJobSlotWafer(string processJobId,string moduleName,List<int> slots)
  902. {
  903. ProcessJobInfo pj = _lstProcessJobs.FirstOrDefault(O => O.Name == processJobId);
  904. if (pj != null)
  905. {
  906. pj.SlotWafers = new List<Tuple<ModuleName, int>>();
  907. for(int i=0;i<slots.Count; i++)
  908. {
  909. pj.SlotWafers.Add(Tuple.Create(ModuleHelper.Converter(moduleName), slots[i] > 1 ? slots[i]-1:0));
  910. }
  911. foreach (var pjSlotWafer in pj.SlotWafers)
  912. {
  913. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  914. wafer.ProcessJob = pj;
  915. WaferDataRecorder.SetWaferSequence(wafer.InnerId.ToString(), pj.Sequence.Name);
  916. WaferDataRecorder.SetWaferLotId(wafer.InnerId.ToString(), pj.LotName);
  917. WaferManager.Instance.UpdateWaferLotId(pjSlotWafer.Item1, pjSlotWafer.Item2, pj.LotName);
  918. }
  919. //由于原来逻辑是根据PJ的Queued状态才会启动任务,因此暂时先注释
  920. //pj.SetState(EnumProcessJobState.SetUp);
  921. OP.DoOperation(E40ProcessStateChanged, pj.Name, EnumProcessJobState.SetUp);
  922. }
  923. }
  924. /// <summary>
  925. /// 更新ControlJob Module信息
  926. /// </summary>
  927. /// <param name="controlJobId"></param>
  928. /// <param name="moduleName"></param>
  929. public void UpdateControlJobModule(string controlJobId,string moduleName)
  930. {
  931. ControlJobInfo cj = _lstControlJobs.FirstOrDefault(O => O.Name == controlJobId);
  932. if (cj != null)
  933. {
  934. cj.Module = moduleName;
  935. CarrierInfo carrier = CarrierManager.Instance.GetCarrier(cj.Module);
  936. int totalWafer = 0;
  937. for (int i = 0; i < cj.ProcessJobNameList.Count; i++)
  938. {
  939. ProcessJobInfo pj = _lstProcessJobs.Find(O => O.Name == cj.ProcessJobNameList[i]);
  940. if (pj != null && pj.SlotWafers != null)
  941. {
  942. foreach (var pjSlotWafer in pj.SlotWafers)
  943. {
  944. ///创建时没有Wafer信息
  945. if (cj.LotWafers.Count == 0)
  946. {
  947. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  948. WaferDataRecorder.SetCjInfo(wafer.InnerId.ToString(), cj.InnerId.ToString());
  949. cj.LotWafers.Add(wafer);
  950. }
  951. totalWafer++;
  952. }
  953. }
  954. }
  955. _faCallback.JobWaitingForStart(cj, GetFirstProcessJob(cj));
  956. JobDataRecorder.StartCJ(cj.InnerId.ToString(), carrier.InnerId.ToString(), cj.Name, cj.Module, cj.Module, totalWafer);
  957. }
  958. }
  959. private bool CheckSequenceAlignerReady(SequenceInfo seq, out string reason)
  960. {
  961. for (int i = 0; i < seq.Steps.Count; i++)
  962. {
  963. SequenceStepInfo stepInfo = seq.Steps[i];
  964. foreach (var module in stepInfo.StepModules)
  965. {
  966. if (ModuleHelper.IsAligner(module))
  967. {
  968. if (!GetModule(module.ToString()).IsOnline)
  969. {
  970. reason = $"Step {i + 1}, {module} is not online";
  971. return false;
  972. }
  973. //if (!_aligner.IsIdle)
  974. //{
  975. // reason = $"Step {i + 1}, {module} is not idle";
  976. // return false;
  977. //}
  978. if (GetModule(module.ToString()).IsError)
  979. {
  980. reason = $"Step {i + 1}, {module} is error";
  981. return false;
  982. }
  983. }
  984. }
  985. }
  986. reason = string.Empty;
  987. return true;
  988. }
  989. private bool CheckSequenceAlignerOrder(SequenceInfo seq, out string reason)
  990. {
  991. int alignerCount = 0;
  992. int alignerIndex = -1;
  993. int llIndex = -1;
  994. int pmIndex = -1;
  995. for (int i = 0; i < seq.Steps.Count; i++)
  996. {
  997. SequenceStepInfo stepInfo = seq.Steps[i];
  998. foreach (var module in stepInfo.StepModules)
  999. {
  1000. if (ModuleHelper.IsAligner(module))
  1001. {
  1002. alignerCount++;
  1003. alignerIndex = i;
  1004. if (i == seq.Steps.Count - 1)
  1005. {
  1006. reason = $"Step {i + 1}, {module} can not be the last step";
  1007. return false;
  1008. }
  1009. }
  1010. if (ModuleHelper.IsLoadLock(module))
  1011. {
  1012. if (llIndex == -1 || llIndex > i)
  1013. llIndex = i;
  1014. }
  1015. if (ModuleHelper.IsPm(module))
  1016. {
  1017. pmIndex = i;
  1018. }
  1019. }
  1020. }
  1021. if (alignerCount >= 2)
  1022. {
  1023. reason = $"Step {alignerIndex + 1}, Aligner step can appear once at most in sequence";
  1024. return false;
  1025. }
  1026. else if (alignerCount == 1)
  1027. {
  1028. if (llIndex != -1 && alignerIndex > llIndex)
  1029. {
  1030. reason = $"Step {alignerIndex + 1}, Aligner step should be in front of LoadLock step";
  1031. return false;
  1032. }
  1033. if (pmIndex != -1 && alignerIndex > pmIndex)
  1034. {
  1035. reason = $"Step {alignerIndex + 1}, Aligner step should be in front of PM step";
  1036. return false;
  1037. }
  1038. }
  1039. reason = string.Empty;
  1040. return true;
  1041. }
  1042. private bool CheckSequencePMReady(SequenceInfo seq, out string reason)
  1043. {
  1044. for (int i = 0; i < seq.Steps.Count; i++)
  1045. {
  1046. SequenceStepInfo stepInfo = seq.Steps[i];
  1047. if (stepInfo.StepModules.Count == 0)
  1048. {
  1049. reason = $"Step {i + 1}, no PM is selected";
  1050. return false;
  1051. }
  1052. foreach (var module in stepInfo.StepModules)
  1053. {
  1054. if (ModuleHelper.IsPm(module))
  1055. {
  1056. foreach (var pm in _lstPms)
  1057. {
  1058. if (pm.Module == module)
  1059. {
  1060. if (!pm.IsOnline)
  1061. {
  1062. reason = $"Step {i + 1}, selected {module} is not online";
  1063. return false;
  1064. }
  1065. //if (!pm.IsIdle)
  1066. //{
  1067. // reason = $"Step {i + 1}, selected {module} is not idle";
  1068. // return false;
  1069. //}
  1070. if (pm.IsError)
  1071. {
  1072. reason = $"Step {i + 1}, selected {module} is error";
  1073. return false;
  1074. }
  1075. #region Check Recipe File Valid
  1076. var recipeContent = RecipeFileManager.Instance.LoadRecipe("", stepInfo.StepParameter[$"{module}Recipe"].ToString(), false);
  1077. if (string.IsNullOrEmpty(recipeContent))
  1078. {
  1079. reason = $"Step {i + 1}, can not find recipe file {stepInfo.RecipeName}";
  1080. return false;
  1081. }
  1082. #endregion
  1083. }
  1084. }
  1085. }
  1086. }
  1087. }
  1088. reason = "";
  1089. return true;
  1090. }
  1091. private bool CheckSequencePMOrder(SequenceInfo seq, out string reason)
  1092. {
  1093. int pmCount = 0;
  1094. for (int i = 0; i < seq.Steps.Count; i++)
  1095. {
  1096. SequenceStepInfo stepInfo = seq.Steps[i];
  1097. foreach (var module in stepInfo.StepModules)
  1098. {
  1099. if (ModuleHelper.IsPm(module))
  1100. {
  1101. pmCount++;
  1102. break;
  1103. }
  1104. }
  1105. }
  1106. if (pmCount == 0)
  1107. {
  1108. reason = $"Sequence must contains PM step";
  1109. return false;
  1110. }
  1111. if (pmCount >= 2)
  1112. {
  1113. reason = $"PM step only can appear once in sequence";
  1114. return false;
  1115. }
  1116. reason = string.Empty;
  1117. return true;
  1118. }
  1119. internal ProcessJobInfo GetFirstProcessJob(ControlJobInfo cj)
  1120. {
  1121. foreach (var pj in _lstProcessJobs)
  1122. {
  1123. if (pj.ControlJobName == cj.Name)
  1124. return pj;
  1125. }
  1126. return null;
  1127. }
  1128. public bool StopJob(string jobName)
  1129. {
  1130. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  1131. if (cj == null)
  1132. {
  1133. EV.PostWarningLog(LogSource, $"stop job rejected, not found job with id {jobName}");
  1134. return false;
  1135. }
  1136. foreach (var pj in _lstProcessJobs)
  1137. {
  1138. if (pj.ControlJobName == cj.Name)
  1139. {
  1140. pj.SetState(EnumProcessJobState.Stopping);
  1141. OP.DoOperation(E40ProcessStateChanged, pj.Name, EnumProcessJobState.Stopping);
  1142. }
  1143. }
  1144. cj.SetState(EnumControlJobState.Completed);
  1145. _faCallback.JobStopped(cj, GetFirstProcessJob(cj));
  1146. _dbCallback.LotFinished(cj);
  1147. return true;
  1148. }
  1149. public bool AbortJob(string jobName)
  1150. {
  1151. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  1152. if (cj == null)
  1153. {
  1154. EV.PostWarningLog(LogSource, $"abort job rejected, not found job with id {jobName}");
  1155. return false;
  1156. }
  1157. int unprocessed_cj = 0;
  1158. int aborted_cj = 0;
  1159. List<ProcessJobInfo> pjAbortList = new List<ProcessJobInfo>();
  1160. foreach (var pj in _lstProcessJobs)
  1161. {
  1162. if (pj.ControlJobName == cj.Name)
  1163. {
  1164. pj.SetState(EnumProcessJobState.Aborting);
  1165. OP.DoOperation(E40ProcessStateChanged, pj.Name, EnumProcessJobState.Aborting);
  1166. pjAbortList.Add(pj);
  1167. int unprocessed = 0;
  1168. int aborted = 0;
  1169. WaferInfo[] wafers = WaferManager.Instance.GetWaferByProcessJob(pj.Name);
  1170. foreach (var waferInfo in wafers)
  1171. {
  1172. waferInfo.ProcessJob = null;
  1173. waferInfo.NextSequenceStep = 0;
  1174. if (waferInfo.ProcessState != EnumWaferProcessStatus.Completed)
  1175. {
  1176. unprocessed++;
  1177. unprocessed_cj++;
  1178. }
  1179. }
  1180. JobDataRecorder.EndPJ(pj.InnerId.ToString(), aborted, unprocessed);
  1181. }
  1182. }
  1183. foreach (var pj in pjAbortList)
  1184. {
  1185. _lstProcessJobs.Remove(pj);
  1186. }
  1187. cj.SetState(EnumControlJobState.Completed);
  1188. _lstControlJobs.Remove(cj);
  1189. JobDataRecorder.EndCJ(cj.InnerId.ToString(), aborted_cj, unprocessed_cj);
  1190. _faCallback.JobAborted(cj, GetFirstProcessJob(cj));
  1191. _dbCallback.LotFinished(cj);
  1192. _temperatureSetpointDic.Clear();
  1193. _temperatureTrigDic.Clear();
  1194. return true;
  1195. }
  1196. public bool ResumeJob(string jobName)
  1197. {
  1198. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  1199. if (cj == null)
  1200. {
  1201. EV.PostWarningLog(LogSource, $"resume job rejected, not found job with id {jobName}");
  1202. return false;
  1203. }
  1204. if (cj.State == EnumControlJobState.Paused)
  1205. {
  1206. cj.SetState(EnumControlJobState.Executing);
  1207. }
  1208. _faCallback.JobResumed(cj, GetFirstProcessJob(cj));
  1209. return true;
  1210. }
  1211. private void CheckRecipeTemperatureAlarmMessage(ControlJobInfo cj)
  1212. {
  1213. try
  1214. {
  1215. if(cj == null || _lstProcessJobs == null)
  1216. {
  1217. return;
  1218. }
  1219. if (!SC.IsATMMode)
  1220. {
  1221. foreach (var pj in _lstProcessJobs)
  1222. {
  1223. if (pj.ControlJobName == cj.Name)
  1224. {
  1225. SlotItem slotItem = null;
  1226. if (pj.SlotWafers != null)
  1227. {
  1228. foreach (var pjSlotWafer in pj.SlotWafers)
  1229. {
  1230. if (CheckWaferNeedProcessAndPMAvailable(pjSlotWafer.Item1, pjSlotWafer.Item2))
  1231. {
  1232. slotItem = new SlotItem(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1233. break;
  1234. }
  1235. }
  1236. }
  1237. if (slotItem != null)
  1238. {
  1239. const string _gt = "greater than";
  1240. foreach (var pm in _lstPms)
  1241. {
  1242. if (CheckWaferNeedProcessPre(slotItem.Module, slotItem.Slot, pm.Module) && GetWaferTemperatureSetInRecipe(slotItem.Module, slotItem.Slot, pm.Module, out double temp1, out double temp2))
  1243. {
  1244. if (pm.CheckTemp1Alarm(temp1))
  1245. {
  1246. EV.PostWarningLog(LogSource, $"Chamber 1 Temperature {_gt} LEHeater1 with {pm.Module}1");
  1247. }
  1248. if (pm.CheckTemp2Alarm(temp2))
  1249. {
  1250. EV.PostWarningLog(LogSource, $"Chamber 2 Temperature {_gt} LEHeater2 with {pm.Module}2");
  1251. }
  1252. }
  1253. }
  1254. }
  1255. }
  1256. }
  1257. }
  1258. }
  1259. catch(Exception ex)
  1260. {
  1261. LOG.Write(ex);
  1262. }
  1263. }
  1264. public bool StartJob(string jobName)
  1265. {
  1266. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  1267. if (cj == null)
  1268. {
  1269. EV.PostWarningLog(LogSource, $"start job rejected, not found job with id {jobName}");
  1270. return false;
  1271. }
  1272. if (_CycleData.IsCycleMode)
  1273. {
  1274. _CycleData.Start(ModuleHelper.Converter(cj.Module), _lstControlJobs.All(p => p.State == EnumControlJobState.WaitingForStart));
  1275. }
  1276. CheckRecipeTemperatureAlarmMessage(cj);
  1277. if (cj.State == EnumControlJobState.WaitingForStart)
  1278. {
  1279. cj.SetState(EnumControlJobState.Executing);
  1280. (GetModule(cj.Module) as SchedulerLoadPort).NoteJobStart();
  1281. //if (cj.IsCycleMode)
  1282. //{
  1283. // _CycleData.BeginOrAddCycle(cj.CycleWaferCountSP);
  1284. //}
  1285. cj.BeginTime = DateTime.Now;
  1286. cj.LotInnerId = Guid.NewGuid();
  1287. _dbCallback.LotCreated(cj);
  1288. _faCallback.JobStarted(cj, GetFirstProcessJob(cj));
  1289. //foreach (var pj in _lstProcessJobs)
  1290. //{
  1291. // if (pj.ControlJobName == cj.Name)
  1292. // {
  1293. // pj.SetState(EnumProcessJobState.Processing);
  1294. // }
  1295. //}
  1296. }
  1297. return true;
  1298. }
  1299. public bool PauseJob(string jobName)
  1300. {
  1301. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == jobName);
  1302. if (cj == null)
  1303. {
  1304. EV.PostWarningLog(LogSource, $"pause job rejected, not found job with id {jobName}");
  1305. return false;
  1306. }
  1307. if (cj.State == EnumControlJobState.Executing)
  1308. {
  1309. cj.SetState(EnumControlJobState.Paused);
  1310. }
  1311. _faCallback.JobPaused(cj, GetFirstProcessJob(cj));
  1312. return true;
  1313. }
  1314. public void Abort()
  1315. {
  1316. }
  1317. public bool IsCJExisted(string CJID)
  1318. {
  1319. return _lstControlJobs.Exists(x => x.Name == CJID);
  1320. }
  1321. public void ModuleError(string moduleName)
  1322. {
  1323. GetModule(moduleName).ResetTask();
  1324. PauseJob(string.Empty);
  1325. }
  1326. public void Map(string moduleName)
  1327. {
  1328. ModuleName target = ModuleHelper.Converter(moduleName);
  1329. if (!ModuleHelper.IsLoadPort(target))
  1330. {
  1331. EV.PostWarningLog(LogSource, $"Invalid map target {target}");
  1332. return;
  1333. }
  1334. if (!_mapTarget.Contains(target))
  1335. {
  1336. _mapTarget.Add(target);
  1337. }
  1338. }
  1339. #endregion
  1340. private string CheckAlignerHasWafer()
  1341. {
  1342. var waferInfo = string.Empty;
  1343. foreach (var schedulerAligner in _lstAligners)
  1344. {
  1345. if (schedulerAligner.IsAvailable)
  1346. {
  1347. if (WaferManager.Instance.CheckHasWafer(schedulerAligner.Module, 0))
  1348. waferInfo += $"{(waferInfo == "" ? "" : ", ")}{schedulerAligner.Module}";
  1349. }
  1350. }
  1351. return waferInfo;
  1352. }
  1353. private string CheckLlHasWafer()
  1354. {
  1355. var waferInfo = string.Empty;
  1356. foreach (var schedulerLl in _lstLls)
  1357. {
  1358. if (schedulerLl.IsAvailable && WaferManager.Instance.AllLocationWafers.ContainsKey(schedulerLl.Module))
  1359. {
  1360. var list = WaferManager.Instance.AllLocationWafers[schedulerLl.Module];
  1361. if (list != null && list.Count > 0)
  1362. {
  1363. foreach (var childItem in list.Keys)
  1364. {
  1365. if (WaferManager.Instance.CheckHasWafer(schedulerLl.Module, childItem))
  1366. {
  1367. waferInfo += $"{(waferInfo == "" ? "" : ", ")}{schedulerLl.Module}";
  1368. break;
  1369. }
  1370. }
  1371. }
  1372. }
  1373. }
  1374. return waferInfo;
  1375. }
  1376. private string CheckCoolingHasWafer()
  1377. {
  1378. var waferInfo = string.Empty;
  1379. foreach (var schedulerCool in _lstCoolings)
  1380. {
  1381. if (schedulerCool.IsAvailable)
  1382. {
  1383. if (WaferManager.Instance.CheckHasWafer(schedulerCool.Module, 0))
  1384. waferInfo += $"{(waferInfo == "" ? "" : ", ")}{schedulerCool.Module}";
  1385. }
  1386. }
  1387. return waferInfo;
  1388. }
  1389. private string CheckEfemRobotHasWafer()
  1390. {
  1391. var waferInfo = string.Empty;
  1392. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0))
  1393. waferInfo += $"{(waferInfo == "" ? "" : ", ")}{ModuleName.EfemRobot} primary arm";
  1394. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1))
  1395. waferInfo += $"{(waferInfo == "" ? "" : ", ")}{ModuleName.EfemRobot} secondly arm";
  1396. return waferInfo;
  1397. }
  1398. public Result Start(params object[] objs)
  1399. {
  1400. _ValueDict.Clear();
  1401. var waferInfo = "";
  1402. bool hasPmOnline = false;
  1403. foreach (var schedulerPm in _lstPms)
  1404. {
  1405. if (schedulerPm.IsAvailable)
  1406. {
  1407. hasPmOnline = true;
  1408. if(WaferManager.Instance.AllLocationWafers.ContainsKey(schedulerPm.Module))
  1409. {
  1410. var list = WaferManager.Instance.AllLocationWafers[schedulerPm.Module];
  1411. if(list != null && list.Count > 0)
  1412. {
  1413. foreach(var item in list.Keys)
  1414. {
  1415. if (WaferManager.Instance.CheckHasWafer(schedulerPm.Module, item))
  1416. {
  1417. waferInfo += $"{(waferInfo == "" ? "" : ", ")}{schedulerPm.Module}";
  1418. break;
  1419. }
  1420. }
  1421. }
  1422. }
  1423. //if (WaferManager.Instance.CheckHasWafer(schedulerPm.Module, 0))
  1424. // waferInfo += $"{(waferInfo == "" ? "" : ", ")}{schedulerPm.Module}";
  1425. }
  1426. }
  1427. waferInfo += CheckAlignerHasWafer();
  1428. waferInfo += CheckLlHasWafer();
  1429. waferInfo += CheckCoolingHasWafer();
  1430. waferInfo += CheckEfemRobotHasWafer();
  1431. bool hasTMOnline = false;
  1432. if (_tmRobot.IsAvailable)
  1433. hasTMOnline = true;
  1434. if (Converter.MapBladeToSlots(Hand.Blade1).Any(p=>WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, p)))
  1435. waferInfo += $"{(waferInfo == "" ? "" : ", ")}{ModuleName.TMRobot} primary arm";
  1436. if (Converter.MapBladeToSlots(Hand.Blade2).Any(p=>WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, p)))
  1437. waferInfo += $"{(waferInfo == "" ? "" : ", ")}{ModuleName.TMRobot} secondly arm";
  1438. if (!hasPmOnline || !hasTMOnline)
  1439. {
  1440. var content = hasPmOnline ? "" : "both process chamber";
  1441. content += hasTMOnline ? "" : $"{(content == "" ? "" : ", ")}TM";
  1442. EV.PostWarningLog("Scheduler", $"can not change to auto mode, {content} is busy or offline");
  1443. return Result.FAIL;
  1444. }
  1445. if (waferInfo != "")
  1446. {
  1447. EV.PostWarningLog("Scheduler", $"can not change to auto mode, {waferInfo} wafer presence.");
  1448. return Result.FAIL;
  1449. }
  1450. if (!_efem.IsOnline)
  1451. {
  1452. EV.PostWarningLog("Scheduler", $"can not change to auto mode, EFEM is offline");
  1453. return Result.FAIL;
  1454. }
  1455. return Result.RUN;
  1456. }
  1457. public Result Monitor()
  1458. {
  1459. UploadWaferEndToEap();
  1460. MonitorJobTasks();
  1461. MonitorCleanTasks();
  1462. MonitorEfemRobotMapTask();
  1463. ControlJobInfo cjActive = _lstControlJobs.Find(x => x.State == EnumControlJobState.Executing);
  1464. if (cjActive != null)
  1465. {
  1466. MonitorModuleTasks();
  1467. }
  1468. return Result.RUN;
  1469. }
  1470. private void UploadWaferEndToEap()
  1471. {
  1472. foreach(var lp in _lstLps)
  1473. {
  1474. for (int i = 0; i < 25; i++)
  1475. {
  1476. if (lp.FirstDetectWaferArrive(i))
  1477. {
  1478. ProcessJobInfo pj = WaferManager.Instance.GetWafer(lp.Module, i).ProcessJob;
  1479. if (pj == null)
  1480. continue;
  1481. var processState = lp.GetWaferInfo(i).ProcessState;
  1482. if (processState == EnumWaferProcessStatus.Failed || processState == EnumWaferProcessStatus.Completed)
  1483. {
  1484. _faCallback.JobWaferEnd(pj, lp.Module.ToString(), i);
  1485. }
  1486. }
  1487. }
  1488. }
  1489. }
  1490. #region Job task
  1491. public Result MonitorJobTasks()
  1492. {
  1493. UpdateParallelMode();
  1494. CalcingThroughput();
  1495. UpdateProcessJobStatus();
  1496. UpdateControlJobStatus();
  1497. //if (GetUnprocessedWaferCount() < SC.GetValue<int>("System.Scheduler.WaferCountBelowWhichStartNewProcessJob"))
  1498. {
  1499. StartNewJob();
  1500. }
  1501. return Result.RUN;
  1502. }
  1503. //only for pj in process
  1504. protected int GetUnprocessedWaferCount()
  1505. {
  1506. int count = 0;
  1507. foreach (ProcessJobInfo pj in _lstProcessJobs)
  1508. {
  1509. if (pj.State == EnumProcessJobState.Processing || pj.State == EnumProcessJobState.Paused)
  1510. count += GetUnprocessedWaferCount(pj);
  1511. }
  1512. if (CheckWaferNeedProcess(WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 0)))
  1513. count++;
  1514. if (CheckWaferNeedProcess(WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 1)))
  1515. count++;
  1516. foreach(var item in _lstAligners)
  1517. {
  1518. if(CheckWaferNeedProcess(WaferManager.Instance.GetWafer(item.Module, 0))) count++;
  1519. }
  1520. return count;
  1521. }
  1522. protected int GetUnprocessedWaferCount(ProcessJobInfo pj)
  1523. {
  1524. int count = 0;
  1525. if(pj.SlotWafers==null)
  1526. {
  1527. return 0;
  1528. }
  1529. for (int i = 0; i < pj.SlotWafers.Count; ++i)
  1530. {
  1531. WaferInfo wafer = WaferManager.Instance.GetWafer(pj.SlotWafers[i].Item1, pj.SlotWafers[i].Item2);
  1532. if (wafer.IsEmpty)
  1533. continue;
  1534. if (CheckWaferNeedProcess(pj.SlotWafers[i].Item1, pj.SlotWafers[i].Item2))
  1535. count++;
  1536. }
  1537. return count;
  1538. }
  1539. protected bool CheckAllWaferReturned(ProcessJobInfo pj, bool checkAllProcessed)
  1540. {
  1541. if(pj.SlotWafers==null)
  1542. {
  1543. return false;
  1544. }
  1545. for (int i = 0; i < pj.SlotWafers.Count; ++i)
  1546. {
  1547. WaferInfo wafer = WaferManager.Instance.GetWafer(pj.SlotWafers[i].Item1, pj.SlotWafers[i].Item2);
  1548. if (wafer.IsEmpty)
  1549. return false;
  1550. if (checkAllProcessed && CheckWaferNeedProcess(pj.SlotWafers[i].Item1, pj.SlotWafers[i].Item2))
  1551. return false;
  1552. }
  1553. return true;
  1554. }
  1555. protected bool CheckAllDummyWaferReturned()
  1556. {
  1557. foreach (var schedulerPm in _lstPms)
  1558. {
  1559. if (WaferManager.Instance.CheckWaferIsDummy(schedulerPm.Module, 0))
  1560. return false;
  1561. }
  1562. if (WaferManager.Instance.CheckWaferIsDummy(_tmRobot.Module, 0))
  1563. return false;
  1564. if (WaferManager.Instance.CheckWaferIsDummy(_tmRobot.Module, 1))
  1565. return false;
  1566. return true;
  1567. }
  1568. protected bool CheckAllPmCleaned(ProcessJobInfo pj)
  1569. {
  1570. foreach (var schedulerPm in _lstPms)
  1571. {
  1572. if (CheckNeedRunClean(schedulerPm.Module, out _, out _))
  1573. {
  1574. foreach (var sequenceStepInfo in pj.Sequence.Steps)
  1575. {
  1576. if (sequenceStepInfo.StepModules.Contains(schedulerPm.Module))
  1577. return false;
  1578. }
  1579. }
  1580. }
  1581. return true;
  1582. }
  1583. private void UpdateProcessJobStatus()
  1584. {
  1585. foreach (var pj in _lstProcessJobs)
  1586. {
  1587. if (pj.State == EnumProcessJobState.Processing)
  1588. {
  1589. if (CheckAllWaferReturned(pj, true) && CheckAllPmCleaned(pj) && CheckAllDummyWaferReturned())
  1590. {
  1591. pj.SetState(EnumProcessJobState.ProcessingComplete);
  1592. pj.EndTime = DateTime.Now;
  1593. OP.DoOperation(E40ProcessStateChanged, pj.Name,EnumProcessJobState.ProcessingComplete);
  1594. JobDataRecorder.EndPJ(pj.InnerId.ToString(), 0, 0);
  1595. }
  1596. }
  1597. else if (pj.State == EnumProcessJobState.Stopping)
  1598. {
  1599. if (CheckAllWaferReturned(pj, false) && CheckAllPmCleaned(pj) && CheckAllDummyWaferReturned())
  1600. {
  1601. pj.SetState(EnumProcessJobState.ProcessingComplete);
  1602. pj.EndTime = DateTime.Now;
  1603. OP.DoOperation(E40ProcessStateChanged, pj.Name,EnumProcessJobState.Complete);
  1604. JobDataRecorder.EndPJ(pj.InnerId.ToString(), 0, 0);
  1605. }
  1606. }
  1607. }
  1608. }
  1609. private void UpdateParallelMode()
  1610. {
  1611. bool enableParallel = SC.GetValue<bool>("System.Scheduler.IsRunInParallelMode");
  1612. int hasJobLpCount = 0;
  1613. _isRunningInParallelMode = enableParallel;
  1614. List<ModuleName> pmUsed = new List<ModuleName>();
  1615. foreach (var lp in _lstLps)
  1616. {
  1617. var cj = _lstControlJobs.Find(x => x.Module == lp.Module.ToString());
  1618. if (cj != null)
  1619. {
  1620. hasJobLpCount++;
  1621. var pj = _lstProcessJobs.FirstOrDefault(x => x.ControlJobName == cj.Name);
  1622. if (pj != null)
  1623. {
  1624. var seq = pj.Sequence;
  1625. for (int i = 0; i < seq.Steps.Count; i++)
  1626. {
  1627. SequenceStepInfo stepInfo = seq.Steps[i];
  1628. foreach (var module in stepInfo.StepModules)
  1629. {
  1630. if (ModuleHelper.IsPm(module) && !pmUsed.Contains(module))
  1631. pmUsed.Add(module);
  1632. }
  1633. }
  1634. }
  1635. }
  1636. }
  1637. _isRunningInParallelMode = enableParallel && hasJobLpCount > 1 && pmUsed.Count > 1;
  1638. }
  1639. private void UpdateControlJobStatus()
  1640. {
  1641. if (_lstControlJobs.Count == 0)
  1642. return;
  1643. List<ControlJobInfo> cjRemoveList = new List<ControlJobInfo>();
  1644. foreach (var cj in _lstControlJobs)
  1645. {
  1646. if (cj.State == EnumControlJobState.Executing)
  1647. {
  1648. bool allPjCompleted = true;
  1649. foreach (var pjName in cj.ProcessJobNameList)
  1650. {
  1651. var pj = _lstProcessJobs.FirstOrDefault(x => x.Name == pjName);
  1652. if (pj == null) { LOG.Error($"Not find pj named {pjName} in {cj.Name}"); continue; }
  1653. if (pj.State != EnumProcessJobState.Complete &&
  1654. pj.State != EnumProcessJobState.ProcessingComplete)
  1655. {
  1656. allPjCompleted = false; break;
  1657. }
  1658. if (allPjCompleted)
  1659. {
  1660. if (pj.SlotWafers != null)
  1661. {
  1662. pj.SlotWafers.ForEach(p =>
  1663. {
  1664. if (ModuleHelper.IsLoadPort(p.Item1))
  1665. {
  1666. allPjCompleted = allPjCompleted && WaferManager.Instance.CheckHasWafer(ModuleHelper.Converter(p.Item1.ToString()), p.Item2);
  1667. }
  1668. });
  1669. }
  1670. }
  1671. }
  1672. if (allPjCompleted)
  1673. {
  1674. if (!_CycleData.IsCycleMode || (_CycleData.IsCycleMode && _CycleData.IsCycleEnd(ModuleHelper.Converter(cj.Module))))
  1675. CompleteJobClean(cj);
  1676. UploadWaferEndToEap();
  1677. _FinishCJ(cj);
  1678. cj.EndTime = DateTime.Now;
  1679. 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";
  1680. EV.PostInfoLog("Scheduler", strInfo);
  1681. if (SC.GetValue<bool>("System.Job.EnablePopDialogWhenJobDone"))
  1682. {
  1683. EV.PostPopDialogMessage(EventLevel.Information, "System Information", strInfo);
  1684. }
  1685. }
  1686. }
  1687. }
  1688. if (_lstControlJobs.Any(cj => cj.State == EnumControlJobState.Completed) && _CycleData.IsCycleMode)
  1689. {
  1690. var completeCJs = from cj in _lstControlJobs
  1691. where cj.State == EnumControlJobState.Completed
  1692. select cj;
  1693. var otherCJs = from cj in _lstControlJobs
  1694. where cj.State != EnumControlJobState.Completed
  1695. select cj;
  1696. _lstControlJobs = otherCJs.Concat(completeCJs).ToList();
  1697. _lstControlJobs.ForEach(cj =>
  1698. {
  1699. if (cj.State == EnumControlJobState.Completed)
  1700. {
  1701. _CycleData.IncreaseCount(ModuleHelper.Converter(cj.Module));
  1702. if (_CycleData.IsCycleEnd(ModuleHelper.Converter(cj.Module)))
  1703. return;
  1704. cj.SetState(EnumControlJobState.Executing);
  1705. cj.BeginTime = DateTime.Now;
  1706. cj.LotWafers.ForEach(x =>
  1707. {
  1708. x.NextSequenceStep = 0;
  1709. x.ProcessState = EnumWaferProcessStatus.Idle;
  1710. });
  1711. foreach (var pjName in cj.ProcessJobNameList)
  1712. {
  1713. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  1714. if (pj == null)
  1715. {
  1716. LOG.Error($"Not find pj named {pjName} in {cj.Name}");
  1717. continue;
  1718. }
  1719. pj.SetState(EnumProcessJobState.Queued);
  1720. }
  1721. }
  1722. });
  1723. }
  1724. foreach (var cj in _lstControlJobs)
  1725. {
  1726. if (cj.State == EnumControlJobState.Completed
  1727. && (!_CycleData.IsCycleMode || _CycleData.IsCycleMode && _CycleData.IsCycleEnd(ModuleHelper.Converter(cj.Module)))
  1728. && (!_isAutoUnloadFoup || (_isAutoUnloadFoup && (GetModule(cj.Module.ToString()) as SchedulerLoadPort).IsUnloaded)))
  1729. {
  1730. (GetModule(cj.Module) as SchedulerLoadPort).NoteJobComplete();
  1731. cjRemoveList.Add(cj);
  1732. }
  1733. }
  1734. foreach (var cj in cjRemoveList)
  1735. {
  1736. List<ProcessJobInfo> pjRemoveList = _lstProcessJobs.Where(o => o.ControlJobName == cj.Name).ToList();
  1737. pjRemoveList.ForEach(o => _lstProcessJobs.Remove(o));
  1738. _lstControlJobs.Remove(cj);
  1739. CalcedThroughput(pjRemoveList);
  1740. }
  1741. ControlJobInfo cjActived = null;
  1742. foreach (var cj in _lstControlJobs)
  1743. {
  1744. if (cj.State == EnumControlJobState.Executing)
  1745. {
  1746. cjActived = cj;
  1747. break;
  1748. }
  1749. }
  1750. if (cjActived != null)
  1751. {
  1752. bool allPjResouceOk = true;
  1753. string reason = string.Empty;
  1754. foreach (var pjName in cjActived.ProcessJobNameList)
  1755. {
  1756. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  1757. if (pj == null)
  1758. {
  1759. LOG.Error($"Not find pj named {pjName} in {cjActived.Name}");
  1760. continue;
  1761. }
  1762. if (pj.State != EnumProcessJobState.Complete && pj.State != EnumProcessJobState.ProcessingComplete)
  1763. {
  1764. if (!CheckSequencePmReady(pj.Sequence, null, out _, out reason))
  1765. {
  1766. allPjResouceOk = false;
  1767. break;
  1768. }
  1769. }
  1770. }
  1771. if (!allPjResouceOk)
  1772. {
  1773. cjActived.SetState(EnumControlJobState.Paused);
  1774. EV.PostWarningLog(LogSource, $"{cjActived.Module} paused, {reason}");
  1775. }
  1776. }
  1777. }
  1778. private void _FinishCJ(ControlJobInfo cj)
  1779. {
  1780. cj.SetState(EnumControlJobState.Completed);
  1781. int unprocessed_cj = 0;
  1782. int aborted_cj = 0;
  1783. foreach (var pj in _lstProcessJobs)
  1784. {
  1785. if (pj.ControlJobName == cj.Name)
  1786. {
  1787. int unprocessed = 0;
  1788. int aborted = 0;
  1789. WaferInfo[] wafers = WaferManager.Instance.GetWaferByProcessJob(pj.Name);
  1790. foreach (var waferInfo in wafers)
  1791. {
  1792. waferInfo.ProcessJob = null;
  1793. waferInfo.NextSequenceStep = 0;
  1794. if (waferInfo.ProcessState != EnumWaferProcessStatus.Completed)
  1795. {
  1796. unprocessed++;
  1797. unprocessed_cj++;
  1798. }
  1799. }
  1800. JobDataRecorder.EndPJ(pj.InnerId.ToString(), aborted, unprocessed);
  1801. }
  1802. }
  1803. JobDataRecorder.EndCJ(cj.InnerId.ToString(), aborted_cj, unprocessed_cj);
  1804. _faCallback.JobFinished(cj, GetFirstProcessJob(cj));
  1805. _dbCallback.LotFinished(cj);
  1806. }
  1807. //private bool _HandleFinishedCycleCJ(ControlJobInfo cj)
  1808. //{
  1809. // //if (!cj.IsCycleMode) return false;
  1810. // int countProcessed = 0;
  1811. // foreach (var pjName in cj.ProcessJobNameList)
  1812. // {
  1813. // var pj = _lstProcessJobs.FirstOrDefault(x => x.Name == pjName);
  1814. // if (pj == null) { LOG.Error($"Not find pj named {pjName} in {cj.Name}"); continue; }
  1815. // if (pj.State == EnumProcessJobState.Complete || pj.State == EnumProcessJobState.ProcessingComplete)
  1816. // {
  1817. // foreach (var pjSlotWafer in pj.SlotWafers)
  1818. // {
  1819. // WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  1820. // if (!wafer.IsEmpty && !CheckWaferNeedProcess(pjSlotWafer.Item1, pjSlotWafer.Item2))
  1821. // countProcessed++;
  1822. // }
  1823. // }
  1824. // }
  1825. // _CycleData.Increase(countProcessed);
  1826. // int leftCount = _CycleData.CycleWaferCountSetPoint - _CycleData.CycledWaferCount;
  1827. // // finished cycle
  1828. // if (leftCount <= 0) return false;
  1829. // // 移除老的cj
  1830. // var pjList = _lstProcessJobs.Where(o => o.ControlJobName == cj.Name).ToList();
  1831. // CalcedThroughput(pjList);
  1832. // pjList.ForEach(o => _lstProcessJobs.Remove(o));
  1833. // _lstControlJobs.Remove(cj);
  1834. // // 模拟 LP unload / load
  1835. // {
  1836. // ModuleName mName = ModuleHelper.Converter(cj.Module);
  1837. // var wafers_old = WaferManager.Instance.GetWafers(mName).ToList();
  1838. // WaferManager.Instance.DeleteWafer(mName, 0, SC.GetValue<int>($"EFEM.LoadPort.CassetteSlotNumber"));
  1839. // CarrierManager.Instance.DeleteCarrier(cj.Module);
  1840. // CarrierManager.Instance.CreateCarrier(cj.Module);
  1841. // foreach (var wafer in wafers_old)
  1842. // {
  1843. // if (wafer.Status != WaferStatus.Normal) continue;
  1844. // var newWafer = WaferManager.Instance.CreateWafer(mName, wafer.Slot, wafer.Status);
  1845. // newWafer.PPID = wafer.PPID;
  1846. // CarrierManager.Instance.RegisterCarrierWafer(cj.Module, wafer.Slot, newWafer);
  1847. // }
  1848. // }
  1849. // // 产生新的cj
  1850. // ControlJobInfo newCj = new ControlJobInfo();
  1851. // newCj.Name = cj.Name;
  1852. // newCj.Module = cj.Module;
  1853. // newCj.LotName = cj.LotName;
  1854. // //newCj.IsCycleMode = cj.IsCycleMode;
  1855. // //newCj.CycleWaferCountSP = cj.CycleWaferCountSP;
  1856. // //newCj.CycledWaferCount = _CycleData.CycledWaferCount;
  1857. // newCj.LotInnerId = Guid.NewGuid();
  1858. // newCj.LotWafers = cj.LotWafers.Take(leftCount).ToList();
  1859. // int addedCount = 0;
  1860. // List<ProcessJobInfo> newPjList = new List<ProcessJobInfo>();
  1861. // //int toAddCount = Math.Min(leftCount, cj.LotWafers.Count);
  1862. // for (int ii = 0; ii < cj.ProcessJobNameList.Count; ii++)
  1863. // {
  1864. // string pjName = cj.ProcessJobNameList[ii];
  1865. // var pj = pjList.FirstOrDefault(o => o.ControlJobName == cj.Name && o.Name == pjName);
  1866. // if (pj == null) continue;
  1867. // int toAddCount = Math.Min(leftCount - addedCount, cj.LotWafers.Count);
  1868. // if (toAddCount <= 0) break;
  1869. // addedCount += toAddCount;
  1870. // ProcessJobInfo newPj = new ProcessJobInfo();
  1871. // newPj.Name = pj.Name;
  1872. // newPj.Sequence = pj.Sequence;
  1873. // newPj.ControlJobName = pj.ControlJobName;
  1874. // newPj.SlotWafers = pj.SlotWafers.Take(toAddCount).ToList();
  1875. // newPj.SetState(EnumProcessJobState.Queued);
  1876. // _lstProcessJobs.Add(newPj);
  1877. // newCj.ProcessJobNameList.Add(pj.Name);
  1878. // newPjList.Add(newPj);
  1879. // }
  1880. // _lstControlJobs.Add(newCj);
  1881. // // 开始新的cj
  1882. // newCj.SetState(EnumControlJobState.Executing);
  1883. // newCj.LotInnerId = Guid.NewGuid();
  1884. // newCj.BeginTime = DateTime.Now;
  1885. // _dbCallback.LotCreated(newCj);
  1886. // newPjList.ForEach(o => ActiveProcessJob(o));
  1887. // return true;
  1888. //}
  1889. public bool CheckAllJobDone()
  1890. {
  1891. for(int i = 0; i < _lstLps.Count; i++)
  1892. {
  1893. var lp = _lstLps[i];
  1894. if (lp != null && lp.IsAvailable)
  1895. {
  1896. _trigLp1JobComplete.CLK = CheckJobComplete(lp.Module.ToString());
  1897. if (_trigLp1JobComplete.Q)
  1898. {
  1899. if (_isAutoUnloadFoup)
  1900. {
  1901. lp.Unload();
  1902. }
  1903. EV.Notify("CARRIER_PROCESS_COMPLETE", new SerializableDictionary<string, object>()
  1904. {
  1905. { "PortID", i+1},
  1906. { "PORT_ID", i+1},
  1907. { "CarrierID", CarrierManager.Instance.GetCarrier(lp.Module.ToString()).CarrierId},
  1908. { "CAR_ID", CarrierManager.Instance.GetCarrier(lp.Module.ToString()).CarrierId}
  1909. });
  1910. }
  1911. }
  1912. }
  1913. foreach (var cj in _lstControlJobs)
  1914. {
  1915. if (cj.State == EnumControlJobState.Executing || cj.State == EnumControlJobState.Paused)
  1916. return false;
  1917. }
  1918. return _lstLps.All(p => p.IsAvailable);
  1919. }
  1920. private bool CheckJobComplete(string lp = null)
  1921. {
  1922. if (_lstProcessJobs.Count == 0)
  1923. return false;
  1924. if (_lstControlJobs.Count == 0)
  1925. return false;
  1926. if (_CycleData.IsCycleMode && !_CycleData.IsCycleEnd())
  1927. return false;
  1928. if (lp != null)
  1929. {
  1930. var cj = _lstControlJobs.Find(x => x.Module == lp);
  1931. if (cj == null)
  1932. return false;
  1933. }
  1934. foreach (var pj in _lstProcessJobs)
  1935. {
  1936. if (lp == null)
  1937. {
  1938. if (pj.State != EnumProcessJobState.ProcessingComplete)
  1939. {
  1940. return false;
  1941. }
  1942. }
  1943. }
  1944. foreach (var cj in _lstControlJobs)
  1945. {
  1946. if (lp == null)
  1947. {
  1948. if (cj.State != EnumControlJobState.Completed)
  1949. {
  1950. return false;
  1951. }
  1952. }
  1953. else
  1954. {
  1955. if (cj.Module == lp && cj.State != EnumControlJobState.Completed)
  1956. {
  1957. return false;
  1958. }
  1959. }
  1960. }
  1961. return true;
  1962. }
  1963. private void StartNewJob()
  1964. {
  1965. ControlJobInfo cjActived = null;
  1966. bool enableParallel = SC.GetValue<bool>("System.Scheduler.IsRunInParallelMode");
  1967. List<ModuleName> pmOccupied = GetPmUsedInRunningPj();
  1968. var orderedLstCJs = _lstControlJobs.OrderBy(x => x.BeginTime);
  1969. foreach (var cj in orderedLstCJs)
  1970. {
  1971. if (cj.State != EnumControlJobState.Executing)
  1972. continue;
  1973. cjActived = cj;
  1974. foreach (var pjName in cjActived.ProcessJobNameList)
  1975. {
  1976. var pj = _lstProcessJobs.Find(x => x.Name == pjName);
  1977. if (pj == null)
  1978. {
  1979. LOG.Error($"Not find pj named {pjName} in {cjActived.Name}");
  1980. continue;
  1981. }
  1982. if (pj.State == EnumProcessJobState.Queued)
  1983. {
  1984. var pmIsReady = CheckSequencePmReady(pj.Sequence, pmOccupied, out var pmUsed, out string reason);
  1985. if (pmUsed.Count > 0)
  1986. {
  1987. var needPreClean = pmUsed.Any(x =>
  1988. {
  1989. return SC.GetValue<bool>($"{x.ToString()}.JobClean.IsEnabled") && SC.GetValue<bool>($"{x.ToString()}.JobClean.EnablePreJobClean");
  1990. });
  1991. if (needPreClean && !pmIsReady)
  1992. break;
  1993. ActiveProcessJob(pj);
  1994. foreach (var moduleName in pmUsed)
  1995. {
  1996. if (!pmOccupied.Contains(moduleName))
  1997. pmOccupied.Add(moduleName);
  1998. }
  1999. break;
  2000. }
  2001. }
  2002. }
  2003. if (!_isRunningInParallelMode)
  2004. continue;
  2005. }
  2006. }
  2007. private List<ModuleName> GetPmUsedInRunningPj()
  2008. {
  2009. var pmUsed = new List<ModuleName>();
  2010. foreach (var cj in _lstControlJobs)
  2011. {
  2012. if (cj.State != EnumControlJobState.Executing && cj.State != EnumControlJobState.Paused)
  2013. continue;
  2014. foreach (var pj in _lstProcessJobs)
  2015. {
  2016. if (pj.ControlJobName == cj.Name && (pj.State == EnumProcessJobState.Processing || pj.State == EnumProcessJobState.Paused))
  2017. {
  2018. for (int i = 0; i < pj.Sequence.Steps.Count; i++)
  2019. {
  2020. SequenceStepInfo stepInfo = pj.Sequence.Steps[i];
  2021. foreach (var module in stepInfo.StepModules)
  2022. {
  2023. if (ModuleHelper.IsPm(module) && !pmUsed.Contains(module))
  2024. {
  2025. pmUsed.Add(module);
  2026. }
  2027. }
  2028. }
  2029. }
  2030. }
  2031. }
  2032. return pmUsed;
  2033. }
  2034. //private bool CheckSequencePmReady(SequenceInfo seq, out string reason)
  2035. //{
  2036. // for (int i = 0; i < seq.Steps.Count; i++)
  2037. // {
  2038. // SequenceStepInfo stepInfo = seq.Steps[i];
  2039. // bool hasPm = false;
  2040. // foreach (var module in stepInfo.StepModules)
  2041. // {
  2042. // if (ModuleHelper.IsPm(module))
  2043. // {
  2044. // PM pm = DEVICE.GetDevice<PM>(module.ToString());
  2045. // if (pm.IsInstalled && !pm.IsError)
  2046. // {
  2047. // hasPm = true;
  2048. // break;
  2049. // }
  2050. // }
  2051. // else
  2052. // {
  2053. // hasPm = true; // other modules default ok
  2054. // }
  2055. // }
  2056. // if (!hasPm)
  2057. // {
  2058. // reason = $"Step {i + 1} no valid PM, " + string.Join("|", stepInfo.StepModules);
  2059. // return false;
  2060. // }
  2061. // }
  2062. // reason = "";
  2063. // return true;
  2064. //}
  2065. private bool CheckSequencePmReady(SequenceInfo seq, List<ModuleName> pmOccupied, out List<ModuleName> pmUsed, out string reason)
  2066. {
  2067. pmUsed = new List<ModuleName>();
  2068. reason = "";
  2069. bool pmIsReady = true;
  2070. for (int i = 0; i < seq.Steps.Count; i++)
  2071. {
  2072. SequenceStepInfo stepInfo = seq.Steps[i];
  2073. bool hasPm = false;
  2074. foreach (var module in stepInfo.StepModules)
  2075. {
  2076. if (!ModuleHelper.IsPm(module))
  2077. {
  2078. hasPm = true;
  2079. break;
  2080. }
  2081. PMModuleBase pm = null;
  2082. pm = EquipmentManager.Modules[module] as PMModuleBase;
  2083. if(pm != null && !pm.IsOnline)
  2084. {
  2085. reason = $"The selected sequence({string.Join("|", stepInfo.StepModules)}) of {module} chamber must be online";
  2086. return false;
  2087. }
  2088. if (pm.IsInstalled && (pmOccupied == null || !pmOccupied.Contains(ModuleHelper.Converter(pm.Module))))
  2089. {
  2090. hasPm = true;
  2091. }
  2092. if (!pmUsed.Contains(ModuleHelper.Converter(pm.Module)))
  2093. pmUsed.Add(ModuleHelper.Converter(pm.Module));
  2094. }
  2095. if (pmIsReady && !hasPm)
  2096. {
  2097. reason = $"Step {i + 1} no valid PM, " + string.Join("|", stepInfo.StepModules);
  2098. pmIsReady = false;
  2099. }
  2100. }
  2101. return pmIsReady;
  2102. }
  2103. private bool CheckSequenceRecipeFileValidTobedone(SequenceInfo seq, out string reason)
  2104. {
  2105. for (int i = 0; i < seq.Steps.Count; i++)
  2106. {
  2107. SequenceStepInfo stepInfo = seq.Steps[i];
  2108. foreach (var module in stepInfo.StepModules)
  2109. {
  2110. if (ModuleHelper.IsPm(module))
  2111. {
  2112. var recipeContent =
  2113. RecipeFileManager.Instance.LoadRecipe($"{module}\\", stepInfo.RecipeName, false);
  2114. if (string.IsNullOrEmpty(recipeContent))
  2115. {
  2116. reason = $"Can not find recipe file {module}\\{stepInfo.RecipeName}";
  2117. return false;
  2118. }
  2119. string cleanRecipeName = "";
  2120. if (stepInfo.CleanInterval > 0
  2121. && stepInfo.StepParameter.ContainsKey("CleanRecipeNoWafer")
  2122. && !string.IsNullOrEmpty((string)stepInfo.StepParameter["CleanRecipeNoWafer"]))
  2123. {
  2124. cleanRecipeName = (string)stepInfo.StepParameter["CleanRecipeNoWafer"];
  2125. if (!string.IsNullOrEmpty(cleanRecipeName))
  2126. {
  2127. recipeContent =
  2128. RecipeFileManager.Instance.LoadRecipe($"{module}\\", cleanRecipeName, false);
  2129. if (string.IsNullOrEmpty(recipeContent))
  2130. {
  2131. reason = $"Can not find recipe file {module}\\{cleanRecipeName}";
  2132. return false;
  2133. }
  2134. }
  2135. }
  2136. if (stepInfo.CleanInterval > 0
  2137. && stepInfo.StepParameter.ContainsKey("CleanRecipeWafer")
  2138. && !string.IsNullOrEmpty((string)stepInfo.StepParameter["CleanRecipeWafer"]))
  2139. {
  2140. cleanRecipeName = (string)stepInfo.StepParameter["CleanRecipeWafer"];
  2141. if (!string.IsNullOrEmpty(cleanRecipeName))
  2142. {
  2143. recipeContent =
  2144. RecipeFileManager.Instance.LoadRecipe($"{module}\\", cleanRecipeName, false);
  2145. if (string.IsNullOrEmpty(recipeContent))
  2146. {
  2147. reason = $"Can not find recipe file {module}\\{cleanRecipeName}";
  2148. return false;
  2149. }
  2150. }
  2151. }
  2152. }
  2153. }
  2154. }
  2155. reason = "";
  2156. return true;
  2157. }
  2158. private bool CheckSequenceRecipeFileValid(SequenceInfo seq, out string reason)
  2159. {
  2160. for (int i = 0; i < seq.Steps.Count; i++)
  2161. {
  2162. SequenceStepInfo stepInfo = seq.Steps[i];
  2163. foreach (var module in stepInfo.StepModules)
  2164. {
  2165. if (ModuleHelper.IsPm(module))
  2166. {
  2167. string pmRecipeName = module+ "Recipe";
  2168. string recipeContent = RecipeFileManager.Instance.LoadRecipe("", stepInfo.StepParameter[pmRecipeName].ToString(), false);
  2169. if (string.IsNullOrEmpty(recipeContent))
  2170. {
  2171. reason = $"Can not find recipe file {stepInfo.StepParameter[$"{module}Recipe"].ToString()}";
  2172. return false;
  2173. }
  2174. if (Recipe.Parse(module.ToString(), recipeContent, out RecipeHead recipeHead, out var recipeSteps))
  2175. {
  2176. if(recipeHead != null && !string.IsNullOrWhiteSpace(recipeHead.NotToPurgeOrVent))
  2177. {
  2178. if(bool.TryParse(recipeHead.NotToPurgeOrVent, out bool isNotToPurgeOrVent))
  2179. {
  2180. if(isNotToPurgeOrVent)
  2181. {
  2182. reason = $"Check recipe checked(Not To Purge OR Vent)";
  2183. return false;
  2184. }
  2185. }
  2186. }
  2187. }
  2188. }
  2189. }
  2190. }
  2191. reason = "";
  2192. return true;
  2193. }
  2194. private bool CheckSequenceOrderOk(SequenceInfo seq, out string reason)
  2195. {
  2196. reason = "";
  2197. bool foundPm = false;
  2198. bool isLLBeforePm = false;
  2199. bool isLLAfterPm = false;
  2200. bool isAlignerAfterLL = false;
  2201. for (int i = 0; i < seq.Steps.Count; i++)
  2202. {
  2203. SequenceStepInfo stepInfo = seq.Steps[i];
  2204. foreach (var module in stepInfo.StepModules)
  2205. {
  2206. if (ModuleHelper.IsPm(module))
  2207. {
  2208. foundPm = true;
  2209. }
  2210. if (!foundPm && ModuleHelper.IsLoadLock(module))
  2211. {
  2212. isLLBeforePm = true;
  2213. }
  2214. if (foundPm && ModuleHelper.IsLoadLock(module))
  2215. {
  2216. isLLAfterPm = true;
  2217. }
  2218. if (ModuleHelper.IsAligner(module) && (isLLBeforePm || foundPm))
  2219. {
  2220. isAlignerAfterLL = true;
  2221. }
  2222. }
  2223. }
  2224. if (!isLLBeforePm)
  2225. {
  2226. reason = $"not found LL before PM;";
  2227. return false;
  2228. }
  2229. if (!isLLAfterPm)
  2230. {
  2231. reason = $"not found LL after PM;";
  2232. return false;
  2233. }
  2234. if (!foundPm)
  2235. {
  2236. reason = $"not found PM in the sequence file;";
  2237. return false;
  2238. }
  2239. if (isAlignerAfterLL)
  2240. {
  2241. reason = "Aligner after LL not support";
  2242. return false;
  2243. }
  2244. List<ModuleName> preStepModules = new List<ModuleName>();
  2245. for (int i = 0; i < seq.Steps.Count; i++)
  2246. {
  2247. SequenceStepInfo stepInfo = seq.Steps[i];
  2248. foreach (var module in stepInfo.StepModules)
  2249. {
  2250. if (preStepModules.Count > 0)
  2251. {
  2252. //aligner前后不能是TMRobot
  2253. if (ModuleHelper.IsAligner(module) && preStepModules.Exists(x => ModuleHelper.IsTM(x) || ModuleHelper.IsTMRobot(x)))
  2254. {
  2255. reason = $"Step {i + 1} is valid , TMRobot can't after Aligner";
  2256. return false;
  2257. }
  2258. if ((ModuleHelper.IsTM(module) || ModuleHelper.IsTMRobot(module)) && preStepModules.Exists(x => ModuleHelper.IsAligner(x)))
  2259. {
  2260. reason = $"Step {i + 1} is valid , TMRobot can't before Aligner";
  2261. return false;
  2262. }
  2263. //Cooling前后不能是TMRobot
  2264. if (ModuleHelper.IsCooling(module) && preStepModules.Exists(x => ModuleHelper.IsTM(x) || ModuleHelper.IsTMRobot(x)))
  2265. {
  2266. reason = $"Step {i + 1} is valid , TMRobot can't after Cooling";
  2267. return false;
  2268. }
  2269. if ((ModuleHelper.IsTM(module) || ModuleHelper.IsTMRobot(module)) && preStepModules.Exists(x => ModuleHelper.IsCooling(x)))
  2270. {
  2271. reason = $"Step {i + 1} is valid , TMRobot can't before Cooling";
  2272. return false;
  2273. }
  2274. //PM前后不能是EfemRobot
  2275. if (ModuleHelper.IsPm(module) && preStepModules.Exists(x => ModuleHelper.IsEfem(x) || ModuleHelper.IsEfemRobot(x)))
  2276. {
  2277. reason = $"Step {i + 1} is valid , EfemRobot can't after Pm";
  2278. return false;
  2279. }
  2280. if ((ModuleHelper.IsEfem(module) || ModuleHelper.IsEfemRobot(module)) && preStepModules.Exists(x => ModuleHelper.IsPm(x)))
  2281. {
  2282. reason = $"Step {i + 1} is valid , EfemRobot can't before Pm";
  2283. return false;
  2284. }
  2285. }
  2286. preStepModules = stepInfo.StepModules;
  2287. }
  2288. }
  2289. return true;
  2290. }
  2291. private bool CheckSequenceNeedDummyWafer(SequenceInfo seq)
  2292. {
  2293. bool needDummyWafer = false;
  2294. for (int i = 0; i < seq.Steps.Count; i++)
  2295. {
  2296. SequenceStepInfo stepInfo = seq.Steps[i];
  2297. foreach (var module in stepInfo.StepModules)
  2298. {
  2299. if (ModuleHelper.IsPm(module))
  2300. {
  2301. if (stepInfo.CleanInterval > 0
  2302. && stepInfo.StepParameter.ContainsKey("CleanRecipeWafer")
  2303. && !string.IsNullOrEmpty((string)stepInfo.StepParameter["CleanRecipeWafer"]))
  2304. {
  2305. needDummyWafer = true;
  2306. break;
  2307. }
  2308. }
  2309. }
  2310. if (needDummyWafer)
  2311. break;
  2312. }
  2313. return needDummyWafer;
  2314. }
  2315. private bool ActiveProcessJob(ProcessJobInfo pj)
  2316. {
  2317. //pm is ok
  2318. if (!CheckSequencePmReady(pj.Sequence, null, out _, out string reason))
  2319. {
  2320. EV.PostWarningLog(LogSource, $"can not active {pj.Name}, {reason}");
  2321. return false;
  2322. }
  2323. _lstPmsCurrentSequence.Clear();
  2324. for (int i = 0; i < pj.Sequence.Steps.Count; i++)
  2325. {
  2326. SequenceStepInfo stepInfo = pj.Sequence.Steps[i];
  2327. foreach (var module in stepInfo.StepModules)
  2328. {
  2329. if (ModuleHelper.IsPm(module))
  2330. {
  2331. var pm = _lstPms.Find(x => x.Module == module);
  2332. if (pm != null)
  2333. _lstPmsCurrentSequence.Add(pm);
  2334. }
  2335. }
  2336. }
  2337. if (pj.SlotWafers != null)
  2338. {
  2339. foreach (var pjSlotWafer in pj.SlotWafers)
  2340. {
  2341. WaferInfo wafer = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  2342. wafer.ProcessJob = pj;
  2343. wafer.NextSequenceStep = 0;
  2344. WaferDataRecorder.SetPjInfo(wafer.InnerId.ToString(), pj.InnerId.ToString());
  2345. }
  2346. }
  2347. ControlJobInfo cj = _lstControlJobs.Find(x => x.Name == pj.ControlJobName);
  2348. CarrierInfo carrier = CarrierManager.Instance.GetCarrier(cj.Module);
  2349. if (pj.SlotWafers != null)
  2350. {
  2351. JobDataRecorder.StartPJ(pj.InnerId.ToString(), carrier.InnerId.ToString(), cj.InnerId.ToString(), pj.Name, cj.Module, cj.Module, pj.SlotWafers.Count);
  2352. }
  2353. pj.SetState(EnumProcessJobState.Processing);
  2354. pj.BeginTime = DateTime.Now;
  2355. OP.DoOperation(E40ProcessStateChanged, pj.Name, EnumProcessJobState.Processing);
  2356. PreJobClean(cj);
  2357. return true;
  2358. }
  2359. #endregion
  2360. #region Module task
  2361. public Result MonitorModuleTasks()
  2362. {
  2363. MonitorPMTask();
  2364. MonitorEfemRobotTask();
  2365. for (int i = 0; i < tmRobotActions.Count; i++)
  2366. {
  2367. MonitorTmRobotTask();
  2368. }
  2369. MonitorTmRobotGoToTask();
  2370. MonitorLoadLockTask();
  2371. MonitorInterlockTask();
  2372. MonitorAlignerTask();
  2373. MonitorCoolingTask();
  2374. return Result.RUN;
  2375. }
  2376. private void MonitorInterlockTask()
  2377. {
  2378. foreach (var cj in _lstControlJobs)
  2379. {
  2380. if (cj.State == EnumControlJobState.Executing || cj.State == EnumControlJobState.Paused ||
  2381. cj.State == EnumControlJobState.WaitingForStart)
  2382. {
  2383. if (!string.IsNullOrEmpty(cj.Module))
  2384. {
  2385. var lp = GetModule(cj.Module);
  2386. _checkNoCarrierByModule[lp.Module].CLK = CarrierManager.Instance.CheckNoCarrier(lp.Module, 0);
  2387. if (_checkNoCarrierByModule[lp.Module].Q)
  2388. {
  2389. EV.PostAlarmLog(lp.Module.ToString(), "Cassette removed while job not finished.");
  2390. //Singleton<RouteManager>.Instance.PostMsg(RouteManager.MSG.ERROR);
  2391. }
  2392. }
  2393. }
  2394. }
  2395. }
  2396. private void MonitorAlignerTask()
  2397. {
  2398. foreach (var aligner in _lstAligners)
  2399. {
  2400. if (!aligner.IsAvailable)
  2401. continue;
  2402. if (aligner.CheckWaferNextStepIsThisModule(aligner.Module, 0))
  2403. {
  2404. WaferInfo wafer = WaferManager.Instance.GetWafer(aligner.Module, 0);
  2405. if (aligner.Align(wafer.InnerId.ToString()))
  2406. {
  2407. wafer.NextSequenceStep++;
  2408. }
  2409. }
  2410. }
  2411. }
  2412. private void MonitorCoolingTask()
  2413. {
  2414. foreach (var cooling in _lstCoolings)
  2415. {
  2416. if (!cooling.IsAvailable)
  2417. continue;
  2418. if (cooling.CheckWaferNextStepIsThisModule(cooling.Module, 0))
  2419. {
  2420. WaferInfo wafer = WaferManager.Instance.GetWafer(cooling.Module, 0);
  2421. GetWaferSequenceCoolingTime(cooling.Module, 0, out int coolingTime);
  2422. if (cooling.Cooling(coolingTime))
  2423. {
  2424. wafer.NextSequenceStep++;
  2425. }
  2426. }
  2427. }
  2428. }
  2429. //private void MonitorBufferTask()
  2430. //{
  2431. // foreach (var buffer in _lstBuffers)
  2432. // {
  2433. // if (!buffer.IsAvailable)
  2434. // continue;
  2435. // }
  2436. //}
  2437. private void MonitorLoadLockTask()
  2438. {
  2439. foreach (var ll in _lstLls)
  2440. {
  2441. if (!ll.IsAvailable)
  2442. continue;
  2443. var wafers = WaferManager.Instance.GetWafers(ll.Module);
  2444. for (int i = 0; i < wafers.Length; i++)
  2445. {
  2446. if (ll.FirstDetectWaferArrive(i))
  2447. {
  2448. ll.PostTransfer(ll.Module, EnumTransferType.Place, i);
  2449. }
  2450. }
  2451. }
  2452. // bool isPrepareTransferForEfemobotPlace = GetWaferCountInJobQueue() > 0;
  2453. // foreach (var ll in _lstLls)
  2454. // {
  2455. // if (ll.Entity.IsPrepareTransfer)
  2456. // {
  2457. // return;
  2458. // }
  2459. // var deviceLL = DEVICE.GetDevice<LoadLock>(ll.Module.ToString());
  2460. // //if (ll.CheckAtAtm() && (ll.Entity.IsCooling || deviceLL.CheckDoorOpen()))
  2461. // if (deviceLL.CheckDoorOpen())
  2462. // {
  2463. // var wafers = WaferManager.Instance.GetWafers(ll.Module).ToList();
  2464. // int emptySlot = 0;
  2465. // foreach (var wafer in wafers)
  2466. // {
  2467. // if (wafer.IsEmpty || wafer.ProcessState != EnumWaferProcessStatus.Idle)
  2468. // emptySlot++;
  2469. // }
  2470. // if (emptySlot >= GetWaferCountInJobQueue())
  2471. // {
  2472. // isPrepareTransferForEfemobotPlace = false;
  2473. // break;
  2474. // }
  2475. // }
  2476. // }
  2477. // foreach (var ll in _lstLls)
  2478. // {
  2479. // if (!ll.IsAvailable)
  2480. // continue;
  2481. // var deviceLL = DEVICE.GetDevice<LoadLock>(ll.Module.ToString());
  2482. // var wafers = WaferManager.Instance.GetWafers(ll.Module).ToList();
  2483. // var isEmptyLL = true;
  2484. // bool isPrepareTransferForEfemobotPick = true;
  2485. // for (int i = 0; i <= 5;)
  2486. // {
  2487. // var wafer0 = WaferManager.Instance.GetWafer(ll.Module, i);
  2488. // var wafer1 = WaferManager.Instance.GetWafer(ll.Module, i + 1);
  2489. // if (!wafer0.IsEmpty || !wafer1.IsEmpty)
  2490. // isEmptyLL = false;
  2491. // if (wafer0.IsEmpty && wafer1.IsEmpty && GetVacuumWafer() > 0)
  2492. // isPrepareTransferForEfemobotPick = false;
  2493. // if ((!wafer0.IsEmpty && wafer0.ProcessState == EnumWaferProcessStatus.Idle) ||
  2494. // (!wafer1.IsEmpty && wafer1.ProcessState == EnumWaferProcessStatus.Idle))
  2495. // isPrepareTransferForEfemobotPick = false;
  2496. // i += 2;
  2497. // }
  2498. // if (isEmptyLL)
  2499. // isPrepareTransferForEfemobotPick = false;
  2500. // if (isPrepareTransferForEfemobotPlace && isEmptyLL && (_tmDevice.CheckSlitValveClose(ll.Module) || GetVacuumWafer() == 0) &&
  2501. // !ll.Entity.IsPrepareTransferReady(ModuleName.EfemRobot, EnumTransferType.Place))
  2502. // {
  2503. // ll.PrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Place, 0);
  2504. // return;
  2505. // }
  2506. // if (isPrepareTransferForEfemobotPick)
  2507. // {
  2508. // if (!ll.Entity.IsPrepareTransferReady(ModuleName.EfemRobot, EnumTransferType.Pick))
  2509. // {
  2510. // if (!_loadlockCooling.ContainsKey(ll.Module))
  2511. // _loadlockCooling.Add(ll.Module, false);
  2512. // _loadlockCooling[ll.Module] = false;
  2513. // ll.PrepareTransfer(ModuleName.EfemRobot, EnumTransferType.Pick, 0);
  2514. // return;
  2515. // }
  2516. // //TODO, cooling 要在 Open ATM door 之前做,PrepareTransfer 需要分开 [2021/7/3 TerryLu]
  2517. // if (ll.Entity.IsPreCoolingDone())
  2518. // {
  2519. // foreach (var wafer in wafers)
  2520. // {
  2521. // if (wafer != null && !wafer.IsEmpty && GetWaferSequenceLoadLockCoolingTime(ll.Module, wafer.Slot, out int coolingTime))
  2522. // {
  2523. // _loadlockCooling[ll.Module] = true;
  2524. // ll.Cooling(coolingTime);
  2525. // break;
  2526. // }
  2527. // }
  2528. // if (_loadlockCooling[ll.Module])
  2529. // {
  2530. // foreach (var wafer in wafers)
  2531. // {
  2532. // if (wafer != null && !wafer.IsEmpty)
  2533. // {
  2534. // wafer.NextSequenceStep++;
  2535. // }
  2536. // }
  2537. // }
  2538. // }
  2539. // }
  2540. // bool isPrepareTransferForTMRobot = true;
  2541. // bool isAllEmpty = true;
  2542. // foreach (var wafer in wafers)
  2543. // {
  2544. // if (!wafer.IsEmpty)
  2545. // isAllEmpty = false;
  2546. // if (wafer.IsEmpty && GetATMWafer() > 0)
  2547. // {
  2548. // isPrepareTransferForTMRobot = false;
  2549. // break;
  2550. // }
  2551. // if (wafer.ProcessState != EnumWaferProcessStatus.Idle)
  2552. // {
  2553. // isPrepareTransferForTMRobot = false;
  2554. // break;
  2555. // }
  2556. // }
  2557. // if (isAllEmpty)
  2558. // {
  2559. // if (GetVacuumWafer() == 0)
  2560. // {
  2561. // isPrepareTransferForTMRobot = false;
  2562. // }
  2563. // else
  2564. // {
  2565. // foreach (var anotherLL in _lstLls)
  2566. // {
  2567. // if (!anotherLL.IsOnline || anotherLL == ll)
  2568. // continue;
  2569. // var anotherLLWafers = WaferManager.Instance.GetWafers(anotherLL.Module).ToList();
  2570. // int count = 0;
  2571. // for (int i = 0; i <= 5;)
  2572. // {
  2573. // if (WaferManager.Instance.CheckNoWafer(anotherLL.Module, i) && WaferManager.Instance.CheckNoWafer(anotherLL.Module, i + 1))
  2574. // {
  2575. // count++;
  2576. // }
  2577. // i += 2;
  2578. // }
  2579. // if (count >= GetVacuumWafer())
  2580. // {
  2581. // isPrepareTransferForTMRobot = false;
  2582. // break;
  2583. // }
  2584. // }
  2585. // }
  2586. // }
  2587. // if (isPrepareTransferForTMRobot && !ll.Entity.IsPrepareTransferReady(ModuleName.TMRobot, EnumTransferType.Pick))
  2588. // {
  2589. // ll.PrepareTransfer(ModuleName.TMRobot, EnumTransferType.Pick, 0);
  2590. // continue;
  2591. // }
  2592. // }
  2593. }
  2594. private void MonitorPMTask()
  2595. {
  2596. foreach (var pm in _lstPms)
  2597. {
  2598. if (!pm.IsAvailable)
  2599. continue;
  2600. if (WaferManager.Instance.CheckHasWafer(pm.Module, 0) || WaferManager.Instance.CheckHasWafer(pm.Module, 1))
  2601. {
  2602. if (CheckNeedRunClean(pm.Module, out bool withWafer, out string recipe) && withWafer
  2603. && WaferManager.Instance.GetWafer(pm.Module, 0).Status == WaferStatus.Dummy
  2604. && WaferManager.Instance.GetWafer(pm.Module, 0).ProcessState == EnumWaferProcessStatus.Wait
  2605. && WaferManager.Instance.GetWafer(pm.Module, 1).Status == WaferStatus.Dummy
  2606. && WaferManager.Instance.GetWafer(pm.Module, 1).ProcessState == EnumWaferProcessStatus.Wait)
  2607. {
  2608. pm.Process(recipe, true, withWafer);
  2609. continue;
  2610. }
  2611. var wafer0 = WaferManager.Instance.GetWafer(pm.Module, 0);
  2612. var wafer1 = WaferManager.Instance.GetWafer(pm.Module, 1);
  2613. if (CheckCanProcess(pm.Module))
  2614. {
  2615. WaferInfo wafer = wafer0.Status != WaferStatus.Empty ? wafer0 : wafer1;
  2616. if (pm.Process(wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepParameter[$"{pm.Module}Recipe"].ToString(), false, true))
  2617. {
  2618. if (wafer0.Status != WaferStatus.Empty)
  2619. wafer0.NextSequenceStep++;
  2620. if (wafer1.Status != WaferStatus.Empty)
  2621. wafer1.NextSequenceStep++;
  2622. continue;
  2623. }
  2624. }
  2625. }
  2626. else
  2627. {
  2628. if (CheckNeedRunClean(pm.Module, out bool withWafer, out string recipe) && !withWafer)
  2629. {
  2630. pm.Process(recipe, true, withWafer);
  2631. continue;
  2632. }
  2633. if (!SC.IsATMMode)
  2634. {
  2635. if (WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0)
  2636. && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1)
  2637. && _lstAligners.All(p => WaferManager.Instance.CheckNoWafer(p.Module, 0))
  2638. && Converter.MapBladeToSlots(Hand.Blade1).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p))
  2639. && Converter.MapBladeToSlots(Hand.Blade2).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p))
  2640. && _lstCoolings.All(p => WaferManager.Instance.CheckNoWafer(p.Module, 0))
  2641. && _lstPms.All(p => _pmSlots.All(s => WaferManager.Instance.CheckNoWafer(p.Module, s)))
  2642. && _lstLls.All(p => _llSlots.All(s => WaferManager.Instance.CheckNoWafer(p.Module, s)))
  2643. )
  2644. {
  2645. SlotItem item = GetNextWaferInJobQueue(ModuleName.System, pm.Module);
  2646. if (item != null && CheckWaferNeedProcessPre(item.Module, item.Slot, pm.Module))
  2647. {
  2648. if (GetWaferTemperatureSetInRecipe(item.Module, item.Slot, pm.Module, out double temp1, out double temp2) && !pm.CheckTempReady(temp1, temp2))
  2649. {
  2650. //if (temp1 != 0 && temp2 != 0)
  2651. {
  2652. pm.Preheating(temp1, temp2);
  2653. continue;
  2654. }
  2655. }
  2656. }
  2657. }
  2658. }
  2659. }
  2660. //if (!pm.IsAvailable)
  2661. // continue;
  2662. //var wafers = FindAllLoadLockSlotForTMRobotPick();
  2663. //if (wafers.Count > 0)
  2664. //{
  2665. // if (wafers.Any(x => CheckWaferNeedProcess(x.Item1.Module, x.Item2, pm.Module)))
  2666. // {
  2667. // for (int i = 0; i < WaferManager.Instance.GetWafers(pm.Module).Length; i++)
  2668. // {
  2669. // if (WaferManager.Instance.CheckNoWafer(pm.Module, i) && !pm.IsReadyForPlace(ModuleName.TMRobot, Hand.Blade1, i))
  2670. // {
  2671. // pm.PrepareTransfer(ModuleName.TMRobot, EnumTransferType.Place, i);
  2672. // return;
  2673. // }
  2674. // }
  2675. // }
  2676. //}
  2677. //else
  2678. //{
  2679. // if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0)
  2680. // && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1)
  2681. // && WaferManager.Instance.CheckNoWafer(pm.Module, 0)
  2682. // && WaferManager.Instance.CheckNoWafer(pm.Module, 1)
  2683. // && _tmRobot.IsAvailable
  2684. // && !pm.CheckSlitValveClose())
  2685. // {
  2686. // pm.CloseSlitValve();
  2687. // return;
  2688. // }
  2689. //}
  2690. }
  2691. }
  2692. public bool CheckLLANoWafer()
  2693. {
  2694. var _LLANoWafer = true;
  2695. for (int _llacount = 0; _llacount <= 7; _llacount++)
  2696. {
  2697. _LLANoWafer = WaferManager.Instance.CheckNoWafer(ModuleName.LLA, _llacount);
  2698. }
  2699. return _LLANoWafer;
  2700. }
  2701. public bool CheckLLBNoWafer()
  2702. {
  2703. var _LLBNoWafer = true;
  2704. for (int _llbcount = 0; _llbcount <= 7; _llbcount++)
  2705. {
  2706. _LLBNoWafer = WaferManager.Instance.CheckNoWafer(ModuleName.LLB, _llbcount);
  2707. }
  2708. return _LLBNoWafer;
  2709. }
  2710. private void MonitorTmRobotTask()
  2711. {
  2712. if (_tmRobot.FirstDetectWaferArrive(0) && _tmRobot.CheckWaferNextStepIsThisModule(ModuleName.TMRobot, (int)ArmBlade.ArmAFork0))
  2713. GetModule(_tmRobot.Module).GetWaferInfo((int)ArmBlade.ArmAFork0).NextSequenceStep++;
  2714. if (_tmRobot.FirstDetectWaferArrive(1) && _tmRobot.CheckWaferNextStepIsThisModule(ModuleName.TMRobot, (int)ArmBlade.ArmBFork1))
  2715. GetModule(_tmRobot.Module).GetWaferInfo((int)ArmBlade.ArmBFork1).NextSequenceStep++;
  2716. if(SC.IsDoubleFork)
  2717. {
  2718. if (_tmRobot.FirstDetectWaferArrive(2) && _tmRobot.CheckWaferNextStepIsThisModule(ModuleName.TMRobot, (int)ArmBlade.ArmAFork2))
  2719. GetModule(_tmRobot.Module).GetWaferInfo((int)ArmBlade.ArmAFork2).NextSequenceStep++;
  2720. if (_tmRobot.FirstDetectWaferArrive(3) && _tmRobot.CheckWaferNextStepIsThisModule(ModuleName.TMRobot, (int)ArmBlade.ArmBFork3))
  2721. GetModule(_tmRobot.Module).GetWaferInfo((int)ArmBlade.ArmBFork3).NextSequenceStep++;
  2722. }
  2723. if (!_tmRobot.IsAvailable)
  2724. return;
  2725. //TM robot is idle, release all the target
  2726. foreach (var ll in _lstLls)
  2727. {
  2728. if (ll.IsWaitTransfer(ModuleName.TMRobot))
  2729. ll.StopWaitTransfer(ModuleName.TMRobot);
  2730. }
  2731. foreach (var pm in _lstPms)
  2732. {
  2733. if (pm.IsWaitTransfer(ModuleName.TMRobot))
  2734. pm.StopWaitTransfer(ModuleName.TMRobot);
  2735. }
  2736. //MonitorTmRobotDummyWaferBufferTask();
  2737. //if (!_tmRobot.IsAvailable)
  2738. // return;
  2739. if (!_tmRobot.IsAvailable)
  2740. return;
  2741. tmRobotActions.FirstOrDefault(p=>p== MonitorTmRobotPMPickAndPlaceTask)?.Invoke();
  2742. if (!_tmRobot.IsAvailable)
  2743. return;
  2744. var act = tmRobotActions.Peek();
  2745. act.Invoke();
  2746. if (!_tmRobot.IsAvailable)
  2747. return;
  2748. if (act == MonitorTmRobotLoadLockPickTask)
  2749. {
  2750. List<Tuple<SchedulerLoadLock, int>> availableLoadLockSlots = FindAllLoadLockSlotForTMRobotPick();
  2751. if (availableLoadLockSlots.Count > 0)
  2752. {
  2753. Tuple<SchedulerLoadLock, int> firstSlot = GetWaferOrderInJobQueue(availableLoadLockSlots);
  2754. if (firstSlot != null)
  2755. {
  2756. SchedulerLoadLock ll = firstSlot.Item1;
  2757. int pickSlot = firstSlot.Item2;
  2758. if (!ll.IsAvailable)
  2759. return;
  2760. }
  2761. }
  2762. }
  2763. if (act == MonitorTmRobotLoadLockPlaceTask && _lstLls.All(x => !x.IsAvailable))
  2764. return;
  2765. tmRobotActions.Enqueue(tmRobotActions.Dequeue());
  2766. //MonitorTmRobotLoadLockPickTask();
  2767. //if (!_tmRobot.IsAvailable)
  2768. // return;
  2769. //MonitorTmRobotPMPickTask();
  2770. //if (!_tmRobot.IsAvailable)
  2771. // return;
  2772. //MonitorTmRobotLoadLockPlaceTask();
  2773. //if (!_tmRobot.IsAvailable)
  2774. // return;
  2775. //MonitorTmRobotPMPlaceTask();
  2776. //if (!_tmRobot.IsAvailable)
  2777. // return;
  2778. //MonitorTmRobotGoToTask();
  2779. }
  2780. private void MonitorTmRobotLoadLockPlaceTask()
  2781. {
  2782. if (!_tmRobot.IsAvailable)
  2783. return;
  2784. if (SC.IsDoubleFork && _lstLls.Any(x => !x.IsAvailable))
  2785. return;
  2786. //place to ll
  2787. bool blade0HasWaferAndProcessed = _tmRobot.Blade1Enable && CheckHasWaferAndNextStepIsLoadLock(Hand.Blade1);
  2788. bool blade1HasWaferAndProcessed = _tmRobot.Blade2Enable && CheckHasWaferAndNextStepIsLoadLock(Hand.Blade2);
  2789. if (blade0HasWaferAndProcessed || blade1HasWaferAndProcessed)
  2790. {
  2791. Hand placeBlade = blade0HasWaferAndProcessed ? Hand.Blade1 : Hand.Blade2;
  2792. var panAndSlots = Converter.GetPanAndSlotFromPlace(placeBlade);
  2793. foreach (var ll in _lstLls)
  2794. {
  2795. if (!ll.IsAvailable)
  2796. continue;
  2797. if (panAndSlots.Item2.Count() >0 && !panAndSlots.Item2.All(p=> CheckWaferNextStepIsLoadLock(ModuleName.TMRobot, p, ll.Module))) continue;
  2798. var placeSlot = GetAvilableLoadLockSlotForTMRobotPlace(placeBlade,ll);
  2799. if (placeSlot != null && placeSlot.Count() > 0)
  2800. {
  2801. if (_tmRobot.Place(ll.Module, Converter.MapPanToLLSlot(panAndSlots.Item1, placeSlot.ToArray()), placeBlade, panAndSlots.Item1, 0, 0, false))
  2802. {
  2803. Array.ForEach(panAndSlots.Item2, p=> WaferManager.Instance.GetWafer(ModuleName.TMRobot, p).NextSequenceStep++);
  2804. if (SC.IsDoubleFork)
  2805. _lstLls.All(p => p.WaitTransfer(ModuleName.TMRobot));
  2806. else
  2807. ll.WaitTransfer(ModuleName.TMRobot);
  2808. return;
  2809. }
  2810. }
  2811. }
  2812. }
  2813. if (GetEmptySlotInPM() < 1)
  2814. return;
  2815. }
  2816. private void MonitorTmRobotLoadLockPickTask()
  2817. {
  2818. if (!_tmRobot.IsAvailable)
  2819. return;
  2820. if (SC.IsDoubleFork && _lstLls.Any(x => !x.IsAvailable))
  2821. return;
  2822. if (!CanTmRobotLoadLockPick())
  2823. return;
  2824. //pick from ll
  2825. bool blade1EmptyAndEnable = _tmRobot.Blade1Enable && Converter.MapBladeToSlots(Hand.Blade1).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p));
  2826. bool blade2EmptyAndEnable = _tmRobot.Blade2Enable && Converter.MapBladeToSlots(Hand.Blade2).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p));
  2827. if (blade1EmptyAndEnable || blade2EmptyAndEnable)
  2828. {
  2829. //if (_lstLls.All(x => !x.IsAvailable))
  2830. // return;
  2831. List<Tuple<SchedulerLoadLock, int>> availableLoadLockSlots = FindAllLoadLockSlotForTMRobotPick();
  2832. if (availableLoadLockSlots.Count > 0)
  2833. {
  2834. var targetLoadLock = TryFindLLAndPairSlot(availableLoadLockSlots);
  2835. if (targetLoadLock == null) return;
  2836. var slots = targetLoadLock.Item2;
  2837. var ll = targetLoadLock.Item1;
  2838. Hand pickBlade = Hand.Blade1;
  2839. foreach (var slot in slots)
  2840. {
  2841. if ((blade1EmptyAndEnable && _tmRobot.CheckWaferNextStepIsThisModuleSlot(ll.Module, slot, 0)) ||
  2842. (blade1EmptyAndEnable && !_tmRobot.CheckWaferNextStepIsThisModuleSlot(ll.Module, slot, 1)))
  2843. {
  2844. pickBlade = Hand.Blade1;
  2845. }
  2846. else if (blade2EmptyAndEnable && _tmRobot.CheckWaferNextStepIsThisModuleSlot(ll.Module, slot, 1) ||
  2847. (blade2EmptyAndEnable && !_tmRobot.CheckWaferNextStepIsThisModuleSlot(ll.Module, slot, 0)))
  2848. {
  2849. pickBlade = Hand.Blade2;
  2850. }
  2851. else
  2852. {
  2853. return;
  2854. }
  2855. }
  2856. if (slots.All(p => ll.IsReadyForPick(ModuleName.TMRobot, pickBlade, p)) &&
  2857. _tmRobot.Pick(ll.Module, slots.ToArray(), pickBlade, Converter.GetPanAndSlotFromPick(pickBlade, slots.ToArray()).Item1, 0, 0, false))
  2858. {
  2859. if (SC.IsDoubleFork)
  2860. _lstLls.All(p => p.WaitTransfer(ModuleName.TMRobot));
  2861. else
  2862. ll.WaitTransfer(ModuleName.TMRobot);
  2863. return;
  2864. }
  2865. }
  2866. }
  2867. }
  2868. private R_TRIG tmRobotGotoLoadLockTrig = new R_TRIG();
  2869. private R_TRIG tmRobotGotoPMTrig = new R_TRIG();
  2870. SchedulerPM gotoPm = null;
  2871. private void MonitorTmRobotGoToTask()
  2872. {
  2873. if (!_tmRobot.IsAvailable)
  2874. return;
  2875. if (!SC.IsDoubleFork)
  2876. return;
  2877. if (_lstLps.SelectMany(p => WaferManager.Instance.GetWafers(p.Module).Where(m => !m.IsEmpty && m.ProcessJob != null && m.ProcessJob.Sequence != null))
  2878. .Select(w => w.ProcessJob.Sequence.Name).GroupBy(p => p).Count() > 1)
  2879. return;
  2880. if ((_tmRobot.Blade1Enable ^ _tmRobot.Blade2Enable) &&
  2881. (Converter.MapBladeToSlots(Hand.Blade1).Any(p => WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, p)) ||
  2882. Converter.MapBladeToSlots(Hand.Blade2).Any(p => WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, p))))
  2883. return;
  2884. if ((_tmRobot.Blade1Enable ^ _tmRobot.Blade2Enable) ||
  2885. (_lstLls.SelectMany(ll => WaferManager.Instance.GetWafers(ll.Module).Where(w => CheckWaferNeedProcess(w))).Count() < 1 && GetUnprocessedWaferCount() < 1) ||
  2886. (_tmRobot.Blade1Enable && _tmRobot.Blade2Enable &&
  2887. (Converter.MapBladeToSlots(Hand.Blade1).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p)) ^
  2888. Converter.MapBladeToSlots(Hand.Blade2).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p)))))
  2889. {
  2890. Hand pickBlade = (Converter.MapBladeToSlots(Hand.Blade1).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p)) && _tmRobot.Blade1Enable) ? Hand.Blade1 : Hand.Blade2;
  2891. Hand placeBlade = pickBlade == Hand.Blade1 ? Hand.Blade2 : Hand.Blade1;
  2892. SchedulerPM gotoPm = null;
  2893. foreach (var pm in _lstPms)
  2894. {
  2895. if (_pmSlots.All(p => WaferManager.Instance.CheckNoWafer(pm.Module, p))
  2896. || (Converter.MapBladeToSlots(placeBlade).Any(p=>WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot,p))
  2897. && !CheckCanPlaceWaferToPM(pm.Module, placeBlade)))
  2898. continue;
  2899. if (gotoPm == null || (pm.WaferArriveTicks[0] < gotoPm.WaferArriveTicks[0]))
  2900. {
  2901. gotoPm = pm;
  2902. }
  2903. }
  2904. if(gotoPm != null && _tmRobot.PreviousTarget != gotoPm.Module)
  2905. {
  2906. var slots = _pmSlots.Where(p=>WaferManager.Instance.CheckHasWafer(gotoPm.Module,p)).ToArray();
  2907. _tmRobot.Goto(gotoPm.Module, slots, pickBlade, Converter.GetPanAndSlotFromPick(pickBlade, slots).Item1);
  2908. }
  2909. }
  2910. }
  2911. private bool CanTmRobotLoadLockPick()
  2912. {
  2913. //单手臂时1片就允许TMRobot取片
  2914. var StartPickCount = (_PMA1Disabled || _PMA2Disabled || _PMB1Disabled || _PMB2Disabled) ? 0 : 1;
  2915. var targetWafers = FindAllLoadLockSlotForTMRobotPick();
  2916. if ((targetWafers.Count <= StartPickCount
  2917. && GetUnprocessedWaferCount() >= 1
  2918. && WaferManager.Instance.GetWafers(ModuleName.TMRobot).All(x => x.IsEmpty)
  2919. && CheckSequenceNameAndNeedProcess(targetWafers)) ||
  2920. (SC.IsDoubleFork && !ExistPairWafer(targetWafers) && CheckSequenceNameAndNeedProcess(targetWafers))
  2921. )
  2922. return false;
  2923. var tmWafers = WaferManager.Instance.GetWafers(ModuleName.TMRobot);
  2924. for (int i = 0; i < tmWafers.Length; i++)
  2925. {
  2926. //disable功能启用后只允许单手臂动作
  2927. if (!tmWafers[i].IsEmpty && (_PMA1Disabled || _PMA2Disabled || _PMB1Disabled || _PMB2Disabled))
  2928. return false;
  2929. if (!tmWafers[i].IsEmpty && !CheckWaferNeedProcess(tmWafers[i]))
  2930. return false;
  2931. }
  2932. foreach (var pm in _lstPms)
  2933. {
  2934. var pmWafer0 = WaferManager.Instance.GetWafer(pm.Module, 0);
  2935. var pmWafer1 = WaferManager.Instance.GetWafer(pm.Module, 1);
  2936. //如果腔体中两片都满了,则跳过
  2937. if (!pmWafer0.IsEmpty && !pmWafer1.IsEmpty)
  2938. continue;
  2939. //如果腔体中一片为空,则取一片相同recipeName的放入
  2940. if (!pmWafer0.IsEmpty)
  2941. {
  2942. var wafer = pmWafer0;
  2943. if (!CheckWaferNeedProcess(wafer))
  2944. continue;
  2945. //判断TMRobot是否已经存在相同recipeName的wafer
  2946. for (int i = 0; i < tmWafers.Length; i++)
  2947. {
  2948. if (CheckWaferNeedProcessBySlot(tmWafers[i], pm.Module, 1)
  2949. && tmWafers[i].ProcessJob.Sequence.Name == wafer.ProcessJob.Sequence.Name)
  2950. return false;
  2951. }
  2952. }
  2953. if (!pmWafer1.IsEmpty)
  2954. {
  2955. var wafer = pmWafer1;
  2956. if (!CheckWaferNeedProcess(wafer))
  2957. continue;
  2958. //判断TMRobot是否已经存在相同recipeName的wafer
  2959. for (int i = 0; i < tmWafers.Length; i++)
  2960. {
  2961. if (CheckWaferNeedProcessBySlot(tmWafers[i], pm.Module, 0)
  2962. && tmWafers[i].ProcessJob.Sequence.Name == wafer.ProcessJob.Sequence.Name)
  2963. return false;
  2964. }
  2965. }
  2966. }
  2967. return true;
  2968. }
  2969. private bool CheckCanPlaceWaferToPM(ModuleName pm, Hand placeBlade)
  2970. {
  2971. var pmSlotAndHandSlot = new Dictionary<int, int>() { { _pmSlots[0], (int)placeBlade }, { _pmSlots[1], ((int)placeBlade) + 2 } };
  2972. foreach (var item in pmSlotAndHandSlot)
  2973. {
  2974. if(WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, item.Value) &&
  2975. !CheckWaferNeedProcessBySlot(WaferManager.Instance.GetWafer(ModuleName.TMRobot, item.Value), pm,item.Key))
  2976. {
  2977. return false;
  2978. }
  2979. }
  2980. return true;
  2981. }
  2982. private void MonitorTmRobotPMPickAndPlaceTask()
  2983. {
  2984. if (!_tmRobot.IsAvailable)
  2985. return;
  2986. if (!SC.IsDoubleFork)
  2987. return;
  2988. if (_tmRobot.Blade1Enable && _tmRobot.Blade2Enable &&
  2989. (Converter.MapBladeToSlots(Hand.Blade1).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p)) ^
  2990. Converter.MapBladeToSlots(Hand.Blade2).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p))))
  2991. {
  2992. Hand pickBlade = Converter.MapBladeToSlots(Hand.Blade1).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p)) ? Hand.Blade1 : Hand.Blade2;
  2993. Hand placeBlade = pickBlade == Hand.Blade1 ? Hand.Blade2 : Hand.Blade1;
  2994. SchedulerPM swapPm = null;
  2995. foreach (var pm in _lstPms)
  2996. {
  2997. if (!pm.IsAvailable || _pmSlots.All(p=> WaferManager.Instance.CheckNoWafer(pm.Module, p))
  2998. || _pmSlots.Any(p=> CheckWaferNeedProcess(pm.Module, p, pm.Module))
  2999. || _pmSlots.Any(p=> !pm.IsReadyForPick(ModuleName.TMRobot, pickBlade, p))
  3000. || !CheckCanPlaceWaferToPM(pm.Module, placeBlade))
  3001. continue;
  3002. if (swapPm == null || (pm.WaferArriveTicks[0] < swapPm.WaferArriveTicks[0]))
  3003. {
  3004. swapPm = pm;
  3005. }
  3006. }
  3007. if (swapPm != null && GetWaferTemperatureSetInRecipe(ModuleName.TMRobot, (int)placeBlade, swapPm.Module, out double temp1, out double temp2))
  3008. {
  3009. var panAndSlotFromPlace = Converter.GetPanAndSlotFromPlace(placeBlade);
  3010. var pickSlot = _pmSlots.Where(p => WaferManager.Instance.CheckHasWafer(swapPm.Module, p)).ToArray();
  3011. var panAndSlotFromPick = Converter.GetPanAndSlotFromPick(pickBlade, pickSlot);
  3012. if (_tmRobot.PickAndPlace(swapPm.Module, pickBlade, panAndSlotFromPick.Item1, pickSlot, placeBlade, panAndSlotFromPlace.Item1, Converter.MapPanToPmSlot(panAndSlotFromPlace.Item1), temp1, temp2))
  3013. {
  3014. ResetPmSwapWaitTimeOut(swapPm.Module);
  3015. swapPm.WaitTransfer(ModuleName.TMRobot);
  3016. return;
  3017. }
  3018. }
  3019. }
  3020. }
  3021. private void MonitorTmRobotPMAPlaceTask()
  3022. {
  3023. if (!_tmRobot.IsAvailable)
  3024. return;
  3025. if (!_pm1.IsAvailable)
  3026. return;
  3027. //place
  3028. bool blade0HasWaferAndNeedProcesse = _tmRobot.Blade1Enable && CheckHasWaferAndNeedProcess(Hand.Blade1);
  3029. bool blade1HasWaferAndNeedProcesse = _tmRobot.Blade2Enable && CheckHasWaferAndNeedProcess(Hand.Blade2);
  3030. if (blade0HasWaferAndNeedProcesse || blade1HasWaferAndNeedProcesse)
  3031. {
  3032. Hand placeBlade = blade0HasWaferAndNeedProcesse ? Hand.Blade1 : Hand.Blade2;
  3033. //var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)placeBlade);
  3034. //foreach (var schedulerPm in _lstPms)
  3035. {
  3036. var schedulerPm = _pm1;
  3037. if (!schedulerPm.IsAvailable)
  3038. return;
  3039. var pmWafer0 = WaferManager.Instance.GetWafer(schedulerPm.Module, 0);
  3040. var pmWafer1 = WaferManager.Instance.GetWafer(schedulerPm.Module, 1);
  3041. //如果腔体中两片都满了,则不允许放入
  3042. if (!pmWafer0.IsEmpty && !pmWafer1.IsEmpty)
  3043. return;
  3044. if (blade0HasWaferAndNeedProcesse && blade1HasWaferAndNeedProcesse)
  3045. {
  3046. var targetHands = CheckCanPlaceWaferToPM(new Hand[] { Hand.Blade1, Hand.Blade2 }, schedulerPm.Module);
  3047. if (targetHands.Count > 1)
  3048. {
  3049. placeBlade = Hand.Blade1;
  3050. if (GetHandWafers(Hand.Blade2).Select(p => p.OriginSlot).Min() < GetHandWafers(Hand.Blade1).Select(p => p.OriginSlot).Min())
  3051. {
  3052. placeBlade = Hand.Blade2;
  3053. }
  3054. }
  3055. else if (targetHands.Count == 1)
  3056. placeBlade = targetHands[0];
  3057. }
  3058. var panAndSlot = Converter.GetPanAndSlotFromPlace(placeBlade);
  3059. //如果腔体中两片都为空
  3060. if (pmWafer0.IsEmpty && pmWafer1.IsEmpty)
  3061. {
  3062. if (SC.IsDoubleFork)
  3063. {
  3064. if (_PMA1Disabled || _PMA2Disabled) return;
  3065. if (!_pmSlots.All(p => WaferManager.Instance.CheckNoWafer(schedulerPm.Module, p))) return;
  3066. var wafers = GetHandWafers(placeBlade);
  3067. for(int i = 0;i< wafers.Length; i++)
  3068. {
  3069. if (!CheckCanPlaceWaferToPM(schedulerPm.Module, i, wafers[i])) return;
  3070. }
  3071. if (GetWaferTemperatureSetInRecipe(ModuleName.TMRobot, panAndSlot.Item2[0], ModuleName.PMA, out double temp1, out double temp2))
  3072. {
  3073. var pmSlots = Converter.MapPanToPmSlot(panAndSlot.Item1);
  3074. if (pmSlots != null && _tmRobot.Place(schedulerPm.Module, pmSlots, placeBlade, panAndSlot.Item1, temp1, temp2, true))
  3075. {
  3076. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  3077. return;
  3078. }
  3079. }
  3080. }
  3081. else
  3082. {
  3083. Dictionary<int, bool> targetSlots = new Dictionary<int, bool>() { { 0, _PMA1Disabled }, { 1, _PMA2Disabled } };
  3084. foreach(var targetSlot in targetSlots.Keys)
  3085. {
  3086. if (WaferManager.Instance.CheckNoWafer(schedulerPm.Module, targetSlot) &&
  3087. CheckCanPlaceWaferToPM(schedulerPm.Module, targetSlot, WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)placeBlade)) &&
  3088. !targetSlots[targetSlot])
  3089. {
  3090. if (GetWaferTemperatureSetInRecipe(ModuleName.TMRobot, (int)placeBlade, ModuleName.PMA, out double temp1, out double temp2))
  3091. {
  3092. if (_tmRobot.Place(schedulerPm.Module, new int[] { targetSlot}, placeBlade, panAndSlot.Item1, temp1, temp2, true))
  3093. {
  3094. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  3095. return;
  3096. }
  3097. }
  3098. }
  3099. }
  3100. }
  3101. }
  3102. if (SC.IsDoubleFork) return;
  3103. //如果腔体中一片为空,则取一片相同recipeName的放入
  3104. if (!pmWafer0.IsEmpty)
  3105. {
  3106. var pmWafer = pmWafer0;
  3107. if (!CheckWaferNeedProcess(pmWafer))
  3108. return;
  3109. int placeSlot = 1;
  3110. if (WaferManager.Instance.CheckNoWafer(schedulerPm.Module, placeSlot))
  3111. {
  3112. if (!GetSameRecipeNameByHand(schedulerPm, placeSlot, out Hand newPlaceBlade))
  3113. return;
  3114. placeBlade = newPlaceBlade;
  3115. if (_PMA2Disabled)
  3116. return;
  3117. if (GetWaferTemperatureSetInRecipe(ModuleName.TMRobot, (int)placeBlade, ModuleName.PMA, out double temp1, out double temp2))
  3118. {
  3119. if (_tmRobot.Place(schedulerPm.Module, new int[] { placeSlot }, placeBlade, panAndSlot.Item1, temp1, temp2, true))
  3120. {
  3121. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  3122. return;
  3123. }
  3124. }
  3125. }
  3126. }
  3127. if (!pmWafer1.IsEmpty)
  3128. {
  3129. var pmWafer = pmWafer1;
  3130. if (!CheckWaferNeedProcess(pmWafer))
  3131. return;
  3132. int placeSlot = 0;
  3133. if (WaferManager.Instance.CheckNoWafer(schedulerPm.Module, placeSlot))
  3134. {
  3135. if (!GetSameRecipeNameByHand(schedulerPm, placeSlot, out Hand newPlaceBlade))
  3136. return;
  3137. placeBlade = newPlaceBlade;
  3138. if (_PMA1Disabled)
  3139. return;
  3140. if (GetWaferTemperatureSetInRecipe(ModuleName.TMRobot, (int)placeBlade, ModuleName.PMA, out double temp1, out double temp2))
  3141. {
  3142. if (_tmRobot.Place(schedulerPm.Module, new int[] { placeSlot }, placeBlade, panAndSlot.Item1, temp1, temp2, true))
  3143. {
  3144. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  3145. return;
  3146. }
  3147. }
  3148. }
  3149. }
  3150. }
  3151. }
  3152. }
  3153. private void MonitorTmRobotPMBPlaceTask()
  3154. {
  3155. if (!_tmRobot.IsAvailable)
  3156. return;
  3157. if (!_pm2.IsAvailable)
  3158. return;
  3159. //place
  3160. bool blade0HasWaferAndNeedProcesse = _tmRobot.Blade1Enable && CheckHasWaferAndNeedProcess(Hand.Blade1);
  3161. bool blade1HasWaferAndNeedProcesse = _tmRobot.Blade2Enable && CheckHasWaferAndNeedProcess(Hand.Blade2);
  3162. if (blade0HasWaferAndNeedProcesse || blade1HasWaferAndNeedProcesse)
  3163. {
  3164. Hand placeBlade = blade0HasWaferAndNeedProcesse ? Hand.Blade1 : Hand.Blade2;
  3165. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)placeBlade);
  3166. //foreach (var schedulerPm in _lstPms)
  3167. {
  3168. var schedulerPm = _pm2;
  3169. if (!schedulerPm.IsAvailable)
  3170. return;
  3171. var pmWafer0 = WaferManager.Instance.GetWafer(schedulerPm.Module, 0);
  3172. var pmWafer1 = WaferManager.Instance.GetWafer(schedulerPm.Module, 1);
  3173. //如果腔体中两片都满了,则不允许放入
  3174. if (!pmWafer0.IsEmpty && !pmWafer1.IsEmpty)
  3175. return;
  3176. if (blade0HasWaferAndNeedProcesse && blade1HasWaferAndNeedProcesse)
  3177. {
  3178. var targetHands = CheckCanPlaceWaferToPM(new Hand[] { Hand.Blade1, Hand.Blade2 }, schedulerPm.Module);
  3179. if (targetHands.Count > 1)
  3180. {
  3181. placeBlade = Hand.Blade1;
  3182. if (GetHandWafers(Hand.Blade2).Select(p => p.OriginSlot).Min() < GetHandWafers(Hand.Blade1).Select(p => p.OriginSlot).Min())
  3183. {
  3184. placeBlade = Hand.Blade2;
  3185. }
  3186. }
  3187. else if (targetHands.Count == 1)
  3188. placeBlade = targetHands[0];
  3189. }
  3190. var panAndSlot = Converter.GetPanAndSlotFromPlace(placeBlade);
  3191. //如果腔体中两片都为空
  3192. if (pmWafer0.IsEmpty && pmWafer1.IsEmpty)
  3193. {
  3194. if (SC.IsDoubleFork)
  3195. {
  3196. if (_PMB1Disabled || _PMB2Disabled) return;
  3197. var wafers = GetHandWafers(placeBlade);
  3198. for (int i = 0; i < wafers.Length; i++)
  3199. {
  3200. if (!CheckCanPlaceWaferToPM(schedulerPm.Module, i, wafers[i])) return;
  3201. }
  3202. if (GetWaferTemperatureSetInRecipe(ModuleName.TMRobot, panAndSlot.Item2[0], ModuleName.PMB, out double temp1, out double temp2))
  3203. {
  3204. var pmSlots = Converter.MapPanToPmSlot(panAndSlot.Item1);
  3205. if (pmSlots != null && _tmRobot.Place(schedulerPm.Module, pmSlots, placeBlade, panAndSlot.Item1,temp1, temp2, true))
  3206. {
  3207. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  3208. return;
  3209. }
  3210. }
  3211. }
  3212. else
  3213. {
  3214. Dictionary<int, bool> targetSlots = new Dictionary<int, bool>() { { 0, _PMB1Disabled }, { 1, _PMB2Disabled } };
  3215. foreach (var targetSlot in targetSlots.Keys)
  3216. {
  3217. if (WaferManager.Instance.CheckNoWafer(schedulerPm.Module, targetSlot)
  3218. && CheckCanPlaceWaferToPM(schedulerPm.Module, targetSlot, WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)placeBlade))
  3219. && !targetSlots[targetSlot])
  3220. {
  3221. if (GetWaferTemperatureSetInRecipe(ModuleName.TMRobot, (int)placeBlade, ModuleName.PMB, out double temp1, out double temp2))
  3222. {
  3223. if (_tmRobot.Place(schedulerPm.Module, new int[] { targetSlot }, placeBlade, panAndSlot.Item1, temp1, temp2, true))
  3224. {
  3225. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  3226. return;
  3227. }
  3228. }
  3229. }
  3230. }
  3231. }
  3232. }
  3233. if (SC.IsDoubleFork) return;
  3234. //如果腔体中一片为空,则取一片相同recipeName的放入
  3235. if (!pmWafer0.IsEmpty)
  3236. {
  3237. var pmWafer = pmWafer0;
  3238. if (!CheckWaferNeedProcess(pmWafer))
  3239. return;
  3240. int placeSlot = 1;
  3241. if (WaferManager.Instance.CheckNoWafer(schedulerPm.Module, placeSlot))
  3242. {
  3243. if (!GetSameRecipeNameByHand(schedulerPm, placeSlot, out Hand newPlaceBlade))
  3244. return;
  3245. placeBlade = newPlaceBlade;
  3246. if (_PMB2Disabled)
  3247. return;
  3248. if (GetWaferTemperatureSetInRecipe(ModuleName.TMRobot, (int)placeBlade, ModuleName.PMB, out double temp1, out double temp2))
  3249. {
  3250. if (_tmRobot.Place(schedulerPm.Module, new int[] { placeSlot }, placeBlade, panAndSlot.Item1, temp1, temp2, true))
  3251. {
  3252. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  3253. return;
  3254. }
  3255. }
  3256. }
  3257. }
  3258. if (!pmWafer1.IsEmpty)
  3259. {
  3260. var pmWafer = pmWafer1;
  3261. if (!CheckWaferNeedProcess(pmWafer))
  3262. return;
  3263. int placeSlot = 0;
  3264. if (WaferManager.Instance.CheckNoWafer(schedulerPm.Module, placeSlot))
  3265. {
  3266. if (!GetSameRecipeNameByHand(schedulerPm, placeSlot, out Hand newPlaceBlade))
  3267. return;
  3268. placeBlade = newPlaceBlade;
  3269. if (_PMB1Disabled)
  3270. return;
  3271. if (GetWaferTemperatureSetInRecipe(ModuleName.TMRobot, (int)placeBlade, ModuleName.PMB, out double temp1, out double temp2))
  3272. {
  3273. if (_tmRobot.Place(schedulerPm.Module, new int[] { placeSlot }, placeBlade, panAndSlot.Item1, temp1, temp2, true))
  3274. {
  3275. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  3276. return;
  3277. }
  3278. }
  3279. }
  3280. }
  3281. }
  3282. }
  3283. }
  3284. private bool GetSameRecipeNameByHand(SchedulerPM schedulerPm, int placeSlot, out Hand placeHand)
  3285. {
  3286. placeHand = Hand.Blade1;
  3287. if (_tmRobot.Blade1Enable && CheckHasWaferAndNeedProcess(Hand.Blade1) &&
  3288. CheckCanPlaceWaferToPM(schedulerPm.Module, placeSlot, WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)Hand.Blade1)))
  3289. {
  3290. placeHand = Hand.Blade1;
  3291. return true;
  3292. }
  3293. else if (_tmRobot.Blade2Enable && CheckHasWaferAndNeedProcess(Hand.Blade2) &&
  3294. CheckCanPlaceWaferToPM(schedulerPm.Module, placeSlot, WaferManager.Instance.GetWafer(ModuleName.TMRobot, (int)Hand.Blade2)))
  3295. {
  3296. placeHand = Hand.Blade2;
  3297. return true;
  3298. }
  3299. return false;
  3300. }
  3301. private void MonitorTmRobotPMAPickTask()
  3302. {
  3303. if (!_tmRobot.IsAvailable)
  3304. return;
  3305. bool blade1EmptyAndEnable = _tmRobot.Blade1Enable && Converter.MapBladeToSlots(Hand.Blade1).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p));
  3306. bool blade2EmptyAndEnable = _tmRobot.Blade2Enable && Converter.MapBladeToSlots(Hand.Blade2).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p));
  3307. // pick
  3308. if (blade1EmptyAndEnable || blade2EmptyAndEnable)
  3309. {
  3310. //foreach (var schedulerPm in _lstPms)
  3311. {
  3312. var schedulerPm = _pm1;
  3313. if (!schedulerPm.IsAvailable)
  3314. return;
  3315. var canPickSlotAndHand = new Dictionary<int, Tuple<Hand,double,double>>();
  3316. var targetSlotAndHandSlots = new Dictionary<int, Tuple<int, int>>() { { 0, new Tuple<int, int>(0, 1) }, { 1, new Tuple<int, int>(0, 1) } };
  3317. foreach(var targetSlot in targetSlotAndHandSlots.Keys)
  3318. {
  3319. if (IsExistSwap(schedulerPm.Module, targetSlot)) return;
  3320. if (CheckCanPickWaferFromPM(schedulerPm.Module, targetSlot) &&
  3321. GetWaferTemperatureSetInRecipe(schedulerPm.Module, targetSlot, ModuleName.PMA, out double temp1, out double temp2))
  3322. {
  3323. Hand pickBlade;
  3324. if ((blade1EmptyAndEnable && _tmRobot.CheckWaferNextStepIsThisModuleSlot(schedulerPm.Module, targetSlot, targetSlotAndHandSlots[targetSlot].Item1)) ||
  3325. (blade1EmptyAndEnable && !_tmRobot.CheckWaferNextStepIsThisModuleSlot(schedulerPm.Module, targetSlot, targetSlotAndHandSlots[targetSlot].Item2)))
  3326. {
  3327. pickBlade = Hand.Blade1;
  3328. }
  3329. else if ((blade2EmptyAndEnable && _tmRobot.CheckWaferNextStepIsThisModuleSlot(schedulerPm.Module, targetSlot, targetSlotAndHandSlots[targetSlot].Item2)) ||
  3330. (blade2EmptyAndEnable && !_tmRobot.CheckWaferNextStepIsThisModuleSlot(schedulerPm.Module, targetSlot, targetSlotAndHandSlots[targetSlot].Item1)))
  3331. {
  3332. pickBlade = Hand.Blade2;
  3333. }
  3334. else
  3335. {
  3336. return;
  3337. }
  3338. if (schedulerPm.IsReadyForPick(ModuleName.TMRobot, pickBlade, targetSlot))
  3339. {
  3340. if (!SC.IsDoubleFork && _tmRobot.Pick(schedulerPm.Module, new int[] { targetSlot }, pickBlade, Converter.GetPanAndSlotFromPick(pickBlade, new int[] { targetSlot }).Item1, temp1, temp2, true))
  3341. {
  3342. ResetPmSwapWaitTimeOut(schedulerPm.Module);
  3343. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  3344. return;
  3345. }
  3346. canPickSlotAndHand[targetSlot] = new Tuple<Hand, double, double>(pickBlade, temp1, temp2);
  3347. }
  3348. }
  3349. }
  3350. if (canPickSlotAndHand.Count>0)
  3351. {
  3352. if (!SC.IsDoubleFork && canPickSlotAndHand.Count > 1) canPickSlotAndHand.Remove(1);
  3353. var firstSlot= canPickSlotAndHand.Keys.First();
  3354. var pickBlade = canPickSlotAndHand[firstSlot].Item1;
  3355. var temp1 = canPickSlotAndHand[firstSlot].Item2;
  3356. var temp2 = canPickSlotAndHand[firstSlot].Item3;
  3357. if (_tmRobot.Pick(schedulerPm.Module, canPickSlotAndHand.Keys.ToArray(), pickBlade, Converter.GetPanAndSlotFromPick(pickBlade, canPickSlotAndHand.Keys.ToArray()).Item1, temp1, temp2, true))
  3358. {
  3359. ResetPmSwapWaitTimeOut(schedulerPm.Module);
  3360. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  3361. return;
  3362. }
  3363. }
  3364. }
  3365. }
  3366. }
  3367. private void MonitorTmRobotPMBPickTask()
  3368. {
  3369. if (!_tmRobot.IsAvailable)
  3370. return;
  3371. bool blade1EmptyAndEnable = _tmRobot.Blade1Enable && Converter.MapBladeToSlots(Hand.Blade1).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p));
  3372. bool blade2EmptyAndEnable = _tmRobot.Blade2Enable && Converter.MapBladeToSlots(Hand.Blade2).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p));
  3373. // pick
  3374. if (blade1EmptyAndEnable || blade2EmptyAndEnable)
  3375. {
  3376. //foreach (var schedulerPm in _lstPms)
  3377. {
  3378. var schedulerPm = _pm2;
  3379. if (!schedulerPm.IsAvailable)
  3380. return;
  3381. var canPickSlotAndHand = new Dictionary<int, Tuple<Hand, double, double>>();
  3382. var targetSlotAndHandSlots = new Dictionary<int, Tuple<int, int>>() { { 0, new Tuple<int, int>(0, 1) }, { 1, new Tuple<int, int>(0, 1) } };
  3383. foreach(var targetSlot in targetSlotAndHandSlots.Keys)
  3384. {
  3385. if (IsExistSwap(schedulerPm.Module, targetSlot)) return;
  3386. if (CheckCanPickWaferFromPM(schedulerPm.Module, targetSlot) &&
  3387. GetWaferTemperatureSetInRecipe(schedulerPm.Module, targetSlot, ModuleName.PMB, out double temp1, out double temp2))
  3388. {
  3389. Hand pickBlade;
  3390. if ((blade1EmptyAndEnable && _tmRobot.CheckWaferNextStepIsThisModuleSlot(schedulerPm.Module, targetSlot, targetSlotAndHandSlots[targetSlot].Item1)) ||
  3391. (blade1EmptyAndEnable && !_tmRobot.CheckWaferNextStepIsThisModuleSlot(schedulerPm.Module, targetSlot, targetSlotAndHandSlots[targetSlot].Item2)))
  3392. {
  3393. pickBlade = Hand.Blade1;
  3394. }
  3395. else if ((blade2EmptyAndEnable && _tmRobot.CheckWaferNextStepIsThisModuleSlot(schedulerPm.Module, targetSlot, targetSlotAndHandSlots[targetSlot].Item2)) ||
  3396. (blade2EmptyAndEnable && !_tmRobot.CheckWaferNextStepIsThisModuleSlot(schedulerPm.Module, targetSlot, targetSlotAndHandSlots[targetSlot].Item1)))
  3397. {
  3398. pickBlade = Hand.Blade2;
  3399. }
  3400. else
  3401. {
  3402. return;
  3403. }
  3404. if (schedulerPm.IsReadyForPick(ModuleName.TMRobot, pickBlade, targetSlot))
  3405. {
  3406. if (!SC.IsDoubleFork && _tmRobot.Pick(schedulerPm.Module, new int[] { targetSlot }, pickBlade, Converter.GetPanAndSlotFromPick(pickBlade, new int[] { targetSlot }).Item1, temp1, temp2, true))
  3407. {
  3408. ResetPmSwapWaitTimeOut(schedulerPm.Module);
  3409. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  3410. return;
  3411. }
  3412. canPickSlotAndHand[targetSlot] = new Tuple<Hand, double, double>(pickBlade, temp1, temp2);
  3413. }
  3414. }
  3415. }
  3416. if (canPickSlotAndHand.Count > 0)
  3417. {
  3418. if (!SC.IsDoubleFork && canPickSlotAndHand.Count > 1) canPickSlotAndHand.Remove(1);
  3419. var firstSlot = canPickSlotAndHand.Keys.First();
  3420. var pickBlade = canPickSlotAndHand[firstSlot].Item1;
  3421. var temp1 = canPickSlotAndHand[firstSlot].Item2;
  3422. var temp2 = canPickSlotAndHand[firstSlot].Item3;
  3423. if (_tmRobot.Pick(schedulerPm.Module, canPickSlotAndHand.Keys.ToArray(), pickBlade, Converter.GetPanAndSlotFromPick(pickBlade, canPickSlotAndHand.Keys.ToArray()).Item1, temp1, temp2, true))
  3424. {
  3425. ResetPmSwapWaitTimeOut(schedulerPm.Module);
  3426. schedulerPm.WaitTransfer(ModuleName.TMRobot);
  3427. return;
  3428. }
  3429. }
  3430. }
  3431. }
  3432. }
  3433. static readonly List<string> llNameList = new List<string>()
  3434. { "IsAvailable", "Task", "IsOnline", "IsError" , "IsIdle", "IsBusy", "IsPrepareTransfer", "IsCooling", "IsAtm", "IsVacuum", "Cooling", "WaitTransfer"
  3435. , "Wafer0", "Wafer1", "Wafer2", "Wafer3", "Wafer4", "Wafer5"
  3436. , "NextStep0", "NextStep1", "NextStep2", "NextStep3", "NextStep4", "NextStep5"
  3437. , "need0", "need1", "need2", "need3", "need4", "need5"};
  3438. static readonly List<string> efemNameList = new List<string>()
  3439. { "IsAvailable","IsOnline","IsReady","Task","IsError"," WaitTransfer"
  3440. , "Wafer0", "Wafer1", "Wafer2"
  3441. , "NextStep0", "NextStep1", "NextStep2"
  3442. , "need0", "need1", "need2"};
  3443. static readonly List<string> tmRobotNameList = new List<string>()
  3444. { "IsAvailable","IsOnline","IsError","Task","IsError"," WaitTransfer"
  3445. , "Wafer0", "Wafer1", "Wafer2", "Wafer3"
  3446. , "NextStep0", "NextStep1", "NextStep2", "NextStep3"
  3447. , "need0", "need1", "need2", "need3"};
  3448. static readonly List<string> pmNameList = new List<string>()
  3449. { "IsAvailable","IsOnline","IsError","TaskDone","IsError"," WaitTransfer"
  3450. , "Wafer0", "Wafer1", "Wafer2", "Wafer3"
  3451. , "NextStep0", "NextStep1", "NextStep2", "NextStep3"
  3452. , "need0", "need1", "need2", "need3"};
  3453. static readonly List<string> lpNameList = new List<string>()
  3454. { "IsAvailable","Task","IsOnline","IsError","IsReady"};
  3455. private int _GetWaferNextStepId(ModuleName module, int slotId)
  3456. {
  3457. if (!WaferManager.Instance.IsWaferSlotLocationValid(module, slotId)) return -1;
  3458. var wafer = WaferManager.Instance.GetWafer(module, slotId);
  3459. return wafer.NextSequenceStep;
  3460. }
  3461. private string _GetWaferOrigin(ModuleName module, int slotId)
  3462. {
  3463. if (!WaferManager.Instance.IsWaferSlotLocationValid(module, slotId)) return "";
  3464. var wafer = WaferManager.Instance.GetWafer(module, slotId);
  3465. return wafer.WaferOrigin;
  3466. }
  3467. private bool GetWaferProcessAccess(WaferInfo wafer)
  3468. {
  3469. if (wafer.ProcessJob == null || string.IsNullOrEmpty(wafer.ProcessJob.Name))
  3470. return false;
  3471. return GetPMOccupiedCount(wafer.ProcessJob.Name) > GetWaitingProcessWaferCount(wafer.ProcessJob.Name);
  3472. }
  3473. private int GetPMOccupiedCount(string pjName)
  3474. {
  3475. List<ModuleName> location = new List<ModuleName>();
  3476. foreach (var pj in _lstProcessJobs)
  3477. {
  3478. if (pj.Name != pjName)
  3479. continue;
  3480. if (pj.State != EnumProcessJobState.Processing)
  3481. continue;
  3482. foreach (var step in pj.Sequence.Steps)
  3483. {
  3484. foreach (var module in step.StepModules)
  3485. {
  3486. if (ModuleHelper.IsPm(module) && !location.Exists(x => x == module))
  3487. location.Add(module);
  3488. }
  3489. }
  3490. }
  3491. return location.Count;
  3492. }
  3493. private int GetWaitingProcessWaferCount(string pjName)
  3494. {
  3495. List<Tuple<ModuleName, int>> location = new List<Tuple<ModuleName, int>>()
  3496. {
  3497. Tuple.Create(ModuleName.TMRobot, 0),
  3498. Tuple.Create(ModuleName.TMRobot, 1),
  3499. Tuple.Create(ModuleName.LLA, 0),
  3500. Tuple.Create(ModuleName.LLB, 0),
  3501. Tuple.Create(ModuleName.Aligner1, 0),
  3502. Tuple.Create(ModuleName.Aligner2, 0),
  3503. Tuple.Create(ModuleName.Cooling1, 0),
  3504. Tuple.Create(ModuleName.Cooling2, 0),
  3505. Tuple.Create(ModuleName.PMA, 0),
  3506. Tuple.Create(ModuleName.PMB, 0),
  3507. //Tuple.Create(ModuleName.PMC, 0),
  3508. };
  3509. location.Where(p => p.Item1 != ModuleName.EfemRobot && p.Item1 != ModuleName.TMRobot && !SC.GetValueOrDefault<bool>($"System.SetUp.{p.Item1.ToString()}.IsInstalled"))
  3510. .ToList().ForEach(p => location.Remove(p));
  3511. int count = 0;
  3512. foreach (var tuple in location)
  3513. {
  3514. WaferInfo wafer = WaferManager.Instance.GetWafer(tuple.Item1, tuple.Item2);
  3515. if (wafer.IsEmpty)
  3516. continue;
  3517. if (wafer.ProcessJob != null && wafer.ProcessJob.Name == pjName)
  3518. count++;
  3519. }
  3520. return count;
  3521. }
  3522. Dictionary<string, Dictionary<string, List<object>>> _ValueDict = new Dictionary<string, Dictionary<string, List<object>>>();
  3523. //private void PrintVariables(string key, List<string> names, params object[] values)
  3524. //{
  3525. // StackTrace trace = new StackTrace(true);
  3526. // var frames = trace.GetFrames();//1代表上级,2代表上上级,以此类推
  3527. // if (frames.Length < 2) return;
  3528. // var frame1 = frames[1];
  3529. // var method1 = frame1.GetMethod();
  3530. // if (method1 == null) return;
  3531. // string methodName = method1.Name;
  3532. // var newList = values.ToList();
  3533. // if (!_ValueDict.ContainsKey(methodName))
  3534. // {
  3535. // _ValueDict[methodName] = new Dictionary<string, List<object>>() { { key, newList } };
  3536. // LOG.Debug($"{methodName} Key={key} Values({_ToString(names, newList)})");
  3537. // }
  3538. // else
  3539. // {
  3540. // var dict = _ValueDict[methodName];
  3541. // if (dict.ContainsKey(key))
  3542. // {
  3543. // var list = dict[key];
  3544. // StringBuilder builder = new StringBuilder();
  3545. // for (int ii = 0; ii < names.Count; ii++)
  3546. // {
  3547. // if (list[ii].Equals(newList[ii])) continue;
  3548. // builder.Append($",{names[ii]}({list[ii]} --> {newList[ii]})");
  3549. // list[ii] = newList[ii];
  3550. // }
  3551. // if (builder.Length > 0)
  3552. // {
  3553. // LOG.Debug($"{methodName} Key={key} {builder.ToString()}");
  3554. // }
  3555. // }
  3556. // else
  3557. // {
  3558. // _ValueDict[methodName].Add(key, newList);
  3559. // LOG.Debug($"{methodName} Key={key} Values({_ToString(names, newList)})");
  3560. // }
  3561. // }
  3562. //}
  3563. private string _ToString(List<string> names, List<object> objList)
  3564. {
  3565. StringBuilder builder = new StringBuilder();
  3566. for (int ii = 0; ii < names.Count; ii++)
  3567. {
  3568. builder.Append($",{names[ii]}={objList[ii]}");
  3569. }
  3570. return builder.ToString().Trim(',');
  3571. }
  3572. #region EfemRobotTask
  3573. private void MonitorEfemRobotMapTask()
  3574. {
  3575. if (!_efem.IsAvailable)
  3576. return;
  3577. if (_mapTarget.Count > 0)
  3578. {
  3579. ModuleName first = _mapTarget[0];
  3580. foreach (var cj in _lstControlJobs)
  3581. {
  3582. if (cj.Module != first.ToString())
  3583. continue;
  3584. if (cj.State == EnumControlJobState.Executing || cj.State == EnumControlJobState.Paused)
  3585. {
  3586. EV.PostWarningLog("System", $"{first} is running, can not map again");
  3587. _mapTarget.Remove(first);
  3588. return;
  3589. }
  3590. }
  3591. SchedulerLoadPort lp = GetModule(first.ToString()) as SchedulerLoadPort;
  3592. if (lp != null && lp.IsAvailable)
  3593. {
  3594. _efem.Map(first);
  3595. _mapTarget.Remove(first);
  3596. }
  3597. }
  3598. }
  3599. private void MonitorEfemRobotTask()
  3600. {
  3601. if (_efem.FirstDetectWaferArrive(0) && _efem.CheckWaferNextStepIsThisModule(ModuleName.EfemRobot, 0))
  3602. GetModule(_efem.Module).GetWaferInfo(0).NextSequenceStep++;
  3603. if (_efem.FirstDetectWaferArrive(1) && _efem.CheckWaferNextStepIsThisModule(ModuleName.EfemRobot, 1))
  3604. GetModule(_efem.Module).GetWaferInfo(1).NextSequenceStep++;
  3605. if (!_efem.IsAvailable)
  3606. return;
  3607. ////efem robot is idle, release all the target
  3608. foreach (var ll in _lstLls)
  3609. {
  3610. if (ll.IsWaitTransfer(ModuleName.EfemRobot))
  3611. ll.StopWaitTransfer(ModuleName.EfemRobot);
  3612. }
  3613. foreach (var al in _lstAligners)
  3614. {
  3615. if (al.IsWaitTransfer(ModuleName.EfemRobot))
  3616. al.StopWaitTransfer(ModuleName.EfemRobot);
  3617. }
  3618. foreach (var bf in _lstCoolings)
  3619. {
  3620. if (bf.IsWaitTransfer(ModuleName.EfemRobot))
  3621. bf.StopWaitTransfer(ModuleName.EfemRobot);
  3622. }
  3623. foreach (var lp in _lstLps)
  3624. {
  3625. if (lp.IsWaitTransfer(ModuleName.EfemRobot))
  3626. lp.StopWaitTransfer(ModuleName.EfemRobot);
  3627. }
  3628. if (!_efem.IsAvailable)
  3629. return;
  3630. var act = efemRobotActions.Peek();
  3631. act.Invoke();
  3632. if (!_efem.IsAvailable)
  3633. return;
  3634. efemRobotActions.Enqueue(efemRobotActions.Dequeue());
  3635. //if (!_efem.IsAvailable)
  3636. // return;
  3637. //MonitorEfemRobotAlignerTask();
  3638. //if (!_efem.IsAvailable)
  3639. // return;
  3640. //MonitorEfemRobotLoadLockTask();
  3641. //if (_aligner.HasWafer(0) && (!_efem.Blade1Enable || !_efem.Blade2Enable))
  3642. // return;
  3643. //if (_aligner.HasWafer(0) && (_efem.HasWafer(0) || _efem.HasWafer(1)))
  3644. // return;
  3645. //if (!_efem.IsAvailable)
  3646. // return;
  3647. //MonitorEfemRobotLoadPortTask();
  3648. //MonitorEfemRobotGoToTask();
  3649. }
  3650. private void MonitorEfemRobotLoadPortPickTask()
  3651. {
  3652. if (!_efem.IsAvailable)
  3653. return;
  3654. if ((_aligner1.HasWafer(0) || _aligner2.HasWafer(0)) && (!_efem.Blade1Enable || !_efem.Blade2Enable))
  3655. return;
  3656. int waferCount = 0;
  3657. if (_aligner1.HasWafer(0)) waferCount++;
  3658. if (_aligner2.HasWafer(0)) waferCount++;
  3659. if (_efem.HasWafer(0)) waferCount++;
  3660. if (_efem.HasWafer(1)) waferCount++;
  3661. if (waferCount >= 2)
  3662. return;
  3663. if (_lstLls.Any(x => GetEmptySlotInLoadLock(x) < 4) ||
  3664. _lstLls.Any(x => GetNoNeedProcessInLoadLock(x) >= 4))
  3665. return;
  3666. //pick
  3667. bool blade1EmptyAndEnable = _efem.Blade1Enable && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0);
  3668. bool blade2EmptyAndEnable = _efem.Blade2Enable && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1);
  3669. if (GetWaferCountInJobQueue() > 0 && (blade1EmptyAndEnable || blade2EmptyAndEnable) && EfemRobotPickAllowable)
  3670. {
  3671. SlotItem position = GetWaferInJobQueue();
  3672. if (position != null && (SC.IsATMMode || CheckWaferPmTemperatureIsOk(position.Module, position.Slot)))
  3673. {
  3674. SchedulerLoadPort lp = GetModule(position.Module.ToString()) as SchedulerLoadPort;
  3675. Hand pickBlade;
  3676. if (blade1EmptyAndEnable && _efem.CheckWaferNextStepIsThisModuleSlot(position.Module, position.Slot, 0))
  3677. {
  3678. pickBlade = Hand.Blade1;
  3679. }
  3680. else if (blade2EmptyAndEnable && _efem.CheckWaferNextStepIsThisModuleSlot(position.Module, position.Slot, 1))
  3681. {
  3682. pickBlade = Hand.Blade2;
  3683. }
  3684. else if (blade1EmptyAndEnable && !_efem.CheckWaferNextStepIsThisModuleSlot(position.Module, position.Slot, 1))
  3685. {
  3686. pickBlade = Hand.Blade1;
  3687. }
  3688. else if (blade2EmptyAndEnable && !_efem.CheckWaferNextStepIsThisModuleSlot(position.Module, position.Slot, 0))
  3689. {
  3690. pickBlade = Hand.Blade2;
  3691. }
  3692. else
  3693. {
  3694. return;
  3695. }
  3696. if (lp != null && lp.IsReadyForPick(ModuleName.EfemRobot, pickBlade, position.Slot))
  3697. {
  3698. //WaferManager.Instance.GetWafer(position.Module, position.Slot).NextSequenceStep++;
  3699. if (GetModule(position.Module.ToString()).CheckWaferNextStepModuleNoWafer(position.Slot))
  3700. {
  3701. ProcessJobInfo pj = lp.GetWaferInfo(position.Slot).ProcessJob;
  3702. _faCallback.JobWaferStart(pj, position.Module.ToString(), position.Slot);
  3703. if (_efem.Pick(position.Module, position.Slot, pickBlade))
  3704. {
  3705. lp.WaitTransfer(ModuleName.EfemRobot);
  3706. return;
  3707. }
  3708. }
  3709. }
  3710. }
  3711. }
  3712. }
  3713. private bool CheckWaferPmTemperatureIsOk(ModuleName waferModule, int waferSlot)
  3714. {
  3715. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  3716. if (wafer.IsEmpty || wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  3717. return false;
  3718. var seq = wafer.ProcessJob.Sequence;
  3719. for (int i = 0; i < seq.Steps.Count; i++)
  3720. {
  3721. SequenceStepInfo stepInfo = seq.Steps[i];
  3722. bool stepOk = false;
  3723. foreach (var module in stepInfo.StepModules)
  3724. {
  3725. if (ModuleHelper.IsPm(module))
  3726. {
  3727. var realmodule = module.ToString();
  3728. string recipeName = realmodule + "Recipe";
  3729. LoadRecipe(realmodule, seq.Steps[i].StepParameter[recipeName].ToString(), out double chambertemp1, out double chambertemp2);
  3730. if ((GetModule(realmodule.ToString()) as SchedulerPM).CheckTransferTempReady(chambertemp1, chambertemp2))
  3731. {
  3732. stepOk = true;
  3733. break;
  3734. }
  3735. }
  3736. else
  3737. {
  3738. stepOk = true;
  3739. }
  3740. }
  3741. if (!stepOk)
  3742. return false;
  3743. }
  3744. return true;
  3745. }
  3746. private void MonitorEfemRobotLoadPortPlaceTask()
  3747. {
  3748. if (!_efem.IsAvailable)
  3749. return;
  3750. //place
  3751. bool blade0HasWaferAndProcessed = _efem.Blade1Enable && WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0) &&
  3752. !CheckWaferNeedProcess(ModuleName.EfemRobot, 0) && !CheckWaferNextStepIsCooling(ModuleName.EfemRobot, 0);
  3753. bool blade1HasWaferAndProcessed = _efem.Blade2Enable && WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1) &&
  3754. !CheckWaferNeedProcess(ModuleName.EfemRobot, 1) && !CheckWaferNextStepIsCooling(ModuleName.EfemRobot, 1);
  3755. if (blade0HasWaferAndProcessed || blade1HasWaferAndProcessed)
  3756. {
  3757. Hand placeBlade = blade0HasWaferAndProcessed ? Hand.Blade1 : Hand.Blade2;
  3758. if (blade0HasWaferAndProcessed && blade1HasWaferAndProcessed)
  3759. {
  3760. if (WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 1).OriginSlot <
  3761. WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 0).OriginSlot)
  3762. {
  3763. placeBlade = Hand.Blade2;
  3764. }
  3765. }
  3766. SlotItem destination = GetWaferReturnLoadPort(ModuleName.EfemRobot, (int)placeBlade);
  3767. if (destination != null && ModuleHelper.IsLoadPort(destination.Module))
  3768. {
  3769. SchedulerLoadPort lp = (SchedulerLoadPort)GetModule(destination.Module.ToString());
  3770. if (lp.IsReadyForPlace(ModuleName.EfemRobot, placeBlade, destination.Slot))
  3771. {
  3772. if (_efem.Place(destination.Module, destination.Slot, placeBlade))
  3773. {
  3774. lp.WaitTransfer(ModuleName.EfemRobot);
  3775. if (_CycleData.IsCycleMode)
  3776. _CycleData.IncreaseWaferCount(lp.Module, 1);
  3777. //_cycledTotalWafer++;
  3778. //if (SC.ContainsItem("System.TotalCycledWafer"))
  3779. // SC.SetItemValue("System.TotalCycledWafer", _cycledTotalWafer);
  3780. return;
  3781. }
  3782. }
  3783. }
  3784. }
  3785. }
  3786. private void MonitorEfemRobotLoadLockPickTask()
  3787. {
  3788. if (!_efem.IsAvailable)
  3789. return;
  3790. if ((_cooling1.HasWafer(0) || _cooling2.HasWafer(0)) && (!_efem.Blade1Enable || !_efem.Blade2Enable))
  3791. return;
  3792. int waferCount = 0;
  3793. if (_cooling1.HasWafer(0)) waferCount++;
  3794. if (_cooling2.HasWafer(0)) waferCount++;
  3795. if (_efem.HasWafer(0)) waferCount++;
  3796. if (_efem.HasWafer(1)) waferCount++;
  3797. if (waferCount >= 2)
  3798. return;
  3799. bool blade1EmptyAndEnable = _efem.Blade1Enable && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0);
  3800. bool blade2EmptyAndEnable = _efem.Blade2Enable && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1);
  3801. if (!blade1EmptyAndEnable && !blade2EmptyAndEnable) return;
  3802. if ((CheckWaferNeedProcess(ModuleName.EfemRobot, 0) || CheckWaferNeedProcess(ModuleName.EfemRobot, 1)))
  3803. {
  3804. var wafers = WaferManager.Instance.GetWafers(ModuleName.EfemRobot).Where(p=>!p.IsEmpty).ToList();
  3805. if(wafers.Any(p=> p.ProcessJob.Sequence.Steps[p.NextSequenceStep].StepModules.Any(m=>ModuleHelper.IsLoadLock(m) && GetEmptySlotInLoadLock(_lstLls.FirstOrDefault(t=>t.Module==m)) > 4)))
  3806. return;
  3807. }
  3808. //List<WaferInfo> canPickWafers = new List<WaferInfo>();
  3809. WaferInfo canPickWafers = null;
  3810. SchedulerLoadLock selectLL = null;
  3811. foreach (var ll in _lstLls)
  3812. {
  3813. var llWafers = WaferManager.Instance.GetWafers(ll.Module);
  3814. for (int i = 0; i < llWafers.Length; i++)
  3815. {
  3816. if (!CheckWaferNeedProcess(ll.Module, i) &&
  3817. ll.IsReadyForPick(ModuleName.EfemRobot, Hand.Blade1, i))
  3818. {
  3819. if (canPickWafers == null || (canPickWafers != null && canPickWafers.OriginSlot > llWafers[i].OriginSlot))
  3820. {
  3821. canPickWafers = llWafers[i];
  3822. selectLL = ll;
  3823. }
  3824. }
  3825. }
  3826. }
  3827. if (canPickWafers == null || selectLL == null || !selectLL.IsAvailable)
  3828. return;
  3829. if (canPickWafers != null && selectLL != null)
  3830. {
  3831. Hand pickBlade;
  3832. if ((blade1EmptyAndEnable && _efem.CheckWaferNextStepIsThisModuleSlot(selectLL.Module, canPickWafers.Slot, 0)) ||
  3833. (blade1EmptyAndEnable && !_efem.CheckWaferNextStepIsThisModuleSlot(selectLL.Module, canPickWafers.Slot, 1)))
  3834. {
  3835. pickBlade = Hand.Blade1;
  3836. }
  3837. else if (blade2EmptyAndEnable && _efem.CheckWaferNextStepIsThisModuleSlot(selectLL.Module, canPickWafers.Slot, 1) ||
  3838. (blade2EmptyAndEnable && !_efem.CheckWaferNextStepIsThisModuleSlot(selectLL.Module, canPickWafers.Slot, 0)))
  3839. {
  3840. pickBlade = Hand.Blade2;
  3841. }
  3842. else
  3843. {
  3844. return;
  3845. }
  3846. if (selectLL.IsReadyForPick(ModuleName.EfemRobot, pickBlade, canPickWafers.Slot))
  3847. {
  3848. if (_efem.Pick(selectLL.Module, canPickWafers.Slot, pickBlade))
  3849. {
  3850. selectLL.WaitTransfer(ModuleName.EfemRobot);
  3851. return;
  3852. }
  3853. }
  3854. }
  3855. if (!_efem.IsAvailable)
  3856. return;
  3857. }
  3858. private void MonitorEfemRobotLoadLockPlaceTask()
  3859. {
  3860. if (!_efem.IsAvailable)
  3861. return;
  3862. //place
  3863. foreach (var ll in _lstLls)
  3864. {
  3865. if (!ll.IsAvailable)
  3866. continue;
  3867. bool blade1NeedPlace = _efem.Blade1Enable && WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0) && CheckWaferNeedProcess(ModuleName.EfemRobot, 0) && !CheckWaferNextStepIsAlign(ModuleName.EfemRobot, 0);
  3868. bool blade2NeedPlace = _efem.Blade2Enable && WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1) && CheckWaferNeedProcess(ModuleName.EfemRobot, 1) && !CheckWaferNextStepIsAlign(ModuleName.EfemRobot, 1);
  3869. if (!blade1NeedPlace && !blade2NeedPlace)
  3870. {
  3871. EfemRobotPickAllowable = true;
  3872. }
  3873. else
  3874. {
  3875. EfemRobotPickAllowable = false;
  3876. }
  3877. if (blade1NeedPlace || blade2NeedPlace)
  3878. {
  3879. Hand placeBlade = blade1NeedPlace ? Hand.Blade1 : Hand.Blade2;
  3880. if (!CheckWaferNextStepIsLoadLock(ModuleName.EfemRobot, (int)placeBlade, ll.Module))
  3881. continue;
  3882. int placeSlot = Int32.MaxValue;
  3883. if (blade1NeedPlace || blade2NeedPlace)
  3884. {
  3885. if (SC.IsDoubleFork && !TryFindNeedPairLoadLock(ModuleName.EfemRobot, placeBlade, ll)) continue;
  3886. for (int i = 0; i < 6; i++)
  3887. {
  3888. if (ll.IsReadyForPlace(ModuleName.EfemRobot, placeBlade, i, true))
  3889. {
  3890. placeSlot = i;
  3891. break;
  3892. }
  3893. }
  3894. }
  3895. if (placeSlot != Int32.MaxValue)
  3896. {
  3897. if (_efem.Place(ll.Module, (int)placeSlot, placeBlade))
  3898. {
  3899. WaferManager.Instance.GetWafer(ModuleName.EfemRobot, (int)placeBlade).NextSequenceStep++;
  3900. ll.WaitTransfer(ModuleName.EfemRobot, (int)placeSlot);
  3901. return;
  3902. }
  3903. }
  3904. }
  3905. }
  3906. }
  3907. private void MonitorEfemRobotAlignerPickTask()
  3908. {
  3909. if (!_efem.IsAvailable)
  3910. return;
  3911. //pick from aligner
  3912. bool blade1EmptyAndEnable = _efem.Blade1Enable && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0);
  3913. bool blade2EmptyAndEnable = _efem.Blade2Enable && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1);
  3914. if (blade1EmptyAndEnable || blade2EmptyAndEnable)
  3915. {
  3916. foreach (var aligner in GetWaferOrderInJobQueue(_lstAligners))
  3917. {
  3918. if (!_efem.IsAvailable)
  3919. return;
  3920. if (!aligner.IsAvailable)
  3921. continue;
  3922. if (aligner.HasWafer(0) && !aligner.CheckWaferNextStepIsThisModule(aligner.Module, 0))
  3923. {
  3924. var wafer = WaferManager.Instance.GetWafer(aligner.Module, 0);
  3925. var nextModules = wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules;
  3926. if (nextModules.Any(p => ModuleHelper.IsLoadLock(p)) && _lstLls.Where(p => nextModules.Contains(p.Module)).All(x => GetNoNeedProcessInLoadLock(x) >=4))
  3927. continue;
  3928. if ((_efem.Blade1Enable ^ _efem.Blade2Enable) && nextModules.Any(p => ModuleHelper.IsLoadLock(p)) && _lstLls.Where(p => nextModules.Contains(p.Module)).All(x => GetNoNeedProcessInLoadLock(x)>0))
  3929. continue;
  3930. Hand pickBlade;
  3931. if (blade1EmptyAndEnable && _efem.CheckWaferNextStepIsThisModuleSlot(aligner.Module, 0, 0))
  3932. {
  3933. pickBlade = Hand.Blade1;
  3934. }
  3935. else if (blade2EmptyAndEnable && _efem.CheckWaferNextStepIsThisModuleSlot(aligner.Module, 0, 1))
  3936. {
  3937. pickBlade = Hand.Blade2;
  3938. }
  3939. else if (blade1EmptyAndEnable && !_efem.CheckWaferNextStepIsThisModuleSlot(aligner.Module, 0, 1))
  3940. {
  3941. pickBlade = Hand.Blade1;
  3942. }
  3943. else if (blade2EmptyAndEnable && !_efem.CheckWaferNextStepIsThisModuleSlot(aligner.Module, 0, 0))
  3944. {
  3945. pickBlade = Hand.Blade2;
  3946. }
  3947. else
  3948. {
  3949. return;
  3950. }
  3951. if (aligner.IsReadyForPick(ModuleName.EfemRobot, pickBlade, 0))
  3952. {
  3953. if (_efem.Pick(aligner.Module, 0, pickBlade))
  3954. {
  3955. aligner.WaitTransfer(ModuleName.EfemRobot);
  3956. return;
  3957. }
  3958. }
  3959. }
  3960. }
  3961. }
  3962. }
  3963. private void MonitorEfemRobotAlignerPlaceTask()
  3964. {
  3965. if (!_efem.IsAvailable)
  3966. return;
  3967. //place to aligner
  3968. bool blade1NeedAlign = _efem.Blade1Enable && WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0) &&
  3969. CheckWaferNextStepIsAlign(ModuleName.EfemRobot, 0);
  3970. bool blade2NeedAlign = _efem.Blade2Enable && WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1) &&
  3971. CheckWaferNextStepIsAlign(ModuleName.EfemRobot, 1);
  3972. if (blade1NeedAlign || blade2NeedAlign)
  3973. {
  3974. Hand placeBlade = blade1NeedAlign ? Hand.Blade1 : Hand.Blade2;
  3975. if (blade1NeedAlign && blade2NeedAlign &&
  3976. WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 1).OriginSlot <
  3977. WaferManager.Instance.GetWafer(ModuleName.EfemRobot, 0).OriginSlot)
  3978. placeBlade = Hand.Blade2;
  3979. foreach (var aligner in _lstAligners)
  3980. {
  3981. if (!_efem.IsAvailable)
  3982. return;
  3983. if (!aligner.IsAvailable)
  3984. continue;
  3985. if (!aligner.CheckWaferNextStepIsThisModule(ModuleName.EfemRobot, (int)placeBlade))
  3986. continue;
  3987. if (aligner.IsReadyForPlace(ModuleName.EfemRobot, placeBlade, 0))
  3988. {
  3989. if (_efem.Place(aligner.Module, 0, placeBlade))
  3990. {
  3991. aligner.WaitTransfer(ModuleName.EfemRobot);
  3992. return;
  3993. }
  3994. }
  3995. }
  3996. }
  3997. }
  3998. private void MonitorEfemRobotCoolingPickTask()
  3999. {
  4000. if (!_efem.IsAvailable)
  4001. return;
  4002. //pick from Cooling
  4003. bool blade1EmptyAndEnable = _efem.Blade1Enable && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0);
  4004. bool blade2EmptyAndEnable = _efem.Blade2Enable && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1);
  4005. if (blade1EmptyAndEnable || blade2EmptyAndEnable)
  4006. {
  4007. foreach (var cooling in GetWaferOrderInJobQueue(_lstCoolings))
  4008. {
  4009. if (!_efem.IsAvailable)
  4010. return;
  4011. if (!cooling.IsAvailable)
  4012. continue;
  4013. Hand pickBlade;
  4014. if (blade1EmptyAndEnable && _efem.CheckWaferNextStepIsThisModuleSlot(cooling.Module, 0, 0))
  4015. {
  4016. pickBlade = Hand.Blade1;
  4017. }
  4018. else if (blade2EmptyAndEnable && _efem.CheckWaferNextStepIsThisModuleSlot(cooling.Module, 0, 1))
  4019. {
  4020. pickBlade = Hand.Blade2;
  4021. }
  4022. else if (blade1EmptyAndEnable && !_efem.CheckWaferNextStepIsThisModuleSlot(cooling.Module, 0, 1))
  4023. {
  4024. pickBlade = Hand.Blade1;
  4025. }
  4026. else if (blade2EmptyAndEnable && !_efem.CheckWaferNextStepIsThisModuleSlot(cooling.Module, 0, 0))
  4027. {
  4028. pickBlade = Hand.Blade2;
  4029. }
  4030. else
  4031. {
  4032. return;
  4033. }
  4034. if (cooling.HasWafer(0) && !cooling.CheckWaferNextStepIsThisModule(cooling.Module, 0))
  4035. {
  4036. if (cooling.IsReadyForPick(ModuleName.EfemRobot, pickBlade, 0))
  4037. {
  4038. if (_efem.Pick(cooling.Module, 0, pickBlade))
  4039. {
  4040. cooling.WaitTransfer(ModuleName.EfemRobot);
  4041. return;
  4042. }
  4043. }
  4044. }
  4045. }
  4046. }
  4047. }
  4048. private void MonitorEfemRobotCoolingPlaceTask()
  4049. {
  4050. if (!_efem.IsAvailable)
  4051. return;
  4052. //place to aligner
  4053. bool blade1NeedCooling = _efem.Blade1Enable && WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0) &&
  4054. CheckWaferNextStepIsCooling(ModuleName.EfemRobot, 0);
  4055. bool blade2NeedCooling = _efem.Blade2Enable && WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1) &&
  4056. CheckWaferNextStepIsCooling(ModuleName.EfemRobot, 1);
  4057. if (blade1NeedCooling || blade2NeedCooling)
  4058. {
  4059. Hand placeBlade = blade1NeedCooling ? Hand.Blade1 : Hand.Blade2;
  4060. foreach (var cooling in _lstCoolings)
  4061. {
  4062. if (!_efem.IsAvailable)
  4063. return;
  4064. if (!cooling.IsAvailable)
  4065. continue;
  4066. if (!cooling.CheckWaferNextStepIsThisModule(ModuleName.EfemRobot, (int)placeBlade))
  4067. continue;
  4068. if (cooling.IsReadyForPlace(ModuleName.EfemRobot, placeBlade, 0))
  4069. {
  4070. if (_efem.Place(cooling.Module, 0, placeBlade))
  4071. {
  4072. cooling.WaitTransfer(ModuleName.EfemRobot);
  4073. return;
  4074. }
  4075. }
  4076. }
  4077. }
  4078. }
  4079. #endregion
  4080. //private void MonitorEfemRobotGoToTask()
  4081. //{
  4082. // if (!_efem.IsAvailable)
  4083. // return;
  4084. // SchedulerLoadLock gotoLL = null;
  4085. // Hand gotoBlade = Hand.Both;
  4086. // int gotoSlot = int.MaxValue;
  4087. // bool arm1Empty = WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 0) && WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 1);
  4088. // bool arm2Empty = WaferManager.Instance.CheckNoWafer(ModuleName.EfemRobot, 2);
  4089. // foreach (var ll in _lstLls)
  4090. // {
  4091. // if (!ll.IsOnline)
  4092. // continue;
  4093. // if (!ll.Entity.IsPrepareTransfer)
  4094. // continue;
  4095. // if (arm1Empty && arm2Empty)
  4096. // {
  4097. // for (int i = 0; i <= 5; i++)
  4098. // {
  4099. // var wafer = WaferManager.Instance.GetWafer(ll.Module, i);
  4100. // if (wafer != null && !wafer.IsEmpty && wafer.ProcessState == EnumWaferProcessStatus.Completed)
  4101. // {
  4102. // gotoLL = ll;
  4103. // gotoBlade = Hand.Both;
  4104. // gotoSlot = 0;
  4105. // break;
  4106. // }
  4107. // }
  4108. // }
  4109. // else
  4110. // {
  4111. // if (!arm1Empty && !arm2Empty)
  4112. // {
  4113. // for (int i = 0; i <= 1; i++)
  4114. // {
  4115. // if (WaferManager.Instance.CheckNoWafer(ll.Module, i) &&
  4116. // WaferManager.Instance.CheckNoWafer(ll.Module, i + 2) &&
  4117. // WaferManager.Instance.CheckNoWafer(ll.Module, i + 4))
  4118. // {
  4119. // gotoBlade = Hand.Both;
  4120. // gotoSlot = i;
  4121. // gotoLL = ll;
  4122. // break;
  4123. // }
  4124. // else if (WaferManager.Instance.CheckNoWafer(ll.Module, i) &&
  4125. // WaferManager.Instance.CheckNoWafer(ll.Module, i + 2))
  4126. // {
  4127. // gotoBlade = Hand.Blade1;
  4128. // gotoSlot = i;
  4129. // gotoLL = ll;
  4130. // break;
  4131. // }
  4132. // if (ll.IsReadyForPlace(ModuleName.EfemRobot, Hand.Blade2, i + 4))
  4133. // {
  4134. // gotoBlade = Hand.Blade2;
  4135. // gotoSlot = i + 4;
  4136. // gotoLL = ll;
  4137. // break;
  4138. // }
  4139. // }
  4140. // }
  4141. // else if (!arm1Empty)
  4142. // {
  4143. // for (int i = 0; i <= 1; i++)
  4144. // {
  4145. // if (WaferManager.Instance.CheckNoWafer(ll.Module, i) &&
  4146. // WaferManager.Instance.CheckNoWafer(ll.Module, i + 2) &&
  4147. // WaferManager.Instance.CheckNoWafer(ll.Module, i + 4))
  4148. // {
  4149. // gotoBlade = Hand.Both;
  4150. // gotoSlot = i;
  4151. // gotoLL = ll;
  4152. // break;
  4153. // }
  4154. // }
  4155. // }
  4156. // else
  4157. // {
  4158. // for (int i = 0; i <= 1; i++)
  4159. // {
  4160. // if (ll.IsReadyForPlace(ModuleName.EfemRobot, Hand.Blade2, i + 4))
  4161. // {
  4162. // gotoBlade = Hand.Blade2;
  4163. // gotoSlot = i + 4;
  4164. // gotoLL = ll;
  4165. // break;
  4166. // }
  4167. // }
  4168. // if (gotoSlot == Int32.MaxValue)
  4169. // {
  4170. // for (int i = 0; i <= 5; i++)
  4171. // {
  4172. // if (ll.IsReadyForPlace(ModuleName.EfemRobot, Hand.Blade2, i))
  4173. // {
  4174. // gotoBlade = Hand.Blade2;
  4175. // gotoSlot = i + 4;
  4176. // gotoLL = ll;
  4177. // break;
  4178. // }
  4179. // }
  4180. // }
  4181. // }
  4182. // }
  4183. // if (gotoLL != null && gotoSlot != int.MaxValue)
  4184. // break;
  4185. // }
  4186. // if (gotoLL != null && gotoSlot != int.MaxValue)
  4187. // {
  4188. // if (_efem.PreviousTarget == gotoLL.Module)
  4189. // return;
  4190. // if (_efem.Goto(gotoLL.Module, gotoSlot, gotoBlade))
  4191. // {
  4192. // gotoLL.WaitTransfer(ModuleName.EfemRobot);
  4193. // return;
  4194. // }
  4195. // }
  4196. //}
  4197. private SlotItem GetNextWaferInJobQueue(ModuleName lpModule, ModuleName pmModule)
  4198. {
  4199. if (!_isRunningInParallelMode)
  4200. {
  4201. foreach (var cj in _lstControlJobs)
  4202. {
  4203. if (lpModule != ModuleName.System && (cj.Module != lpModule.ToString()))
  4204. continue;
  4205. if (cj.State == EnumControlJobState.Executing)
  4206. {
  4207. foreach (var pj in _lstProcessJobs)
  4208. {
  4209. if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing&&pj.SlotWafers!=null)
  4210. {
  4211. foreach (var pjSlotWafer in pj.SlotWafers)
  4212. {
  4213. if (CheckWaferNeedProcessAndPMAvailable(pjSlotWafer.Item1, pjSlotWafer.Item2, pmModule))
  4214. return new SlotItem(pjSlotWafer.Item1, pjSlotWafer.Item2);
  4215. }
  4216. }
  4217. }
  4218. }
  4219. }
  4220. return null;
  4221. }
  4222. //parallel mode
  4223. Dictionary<string, SlotItem> pjWafer = new Dictionary<string, SlotItem>();
  4224. Dictionary<string, List<ModuleName>> pmUsed = new Dictionary<string, List<ModuleName>>();
  4225. foreach (var cj in _lstControlJobs)
  4226. {
  4227. if (cj.State != EnumControlJobState.Executing)
  4228. continue;
  4229. foreach (var pj in _lstProcessJobs)
  4230. {
  4231. if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing&&pj.SlotWafers!=null)
  4232. {
  4233. foreach (var pjSlotWafer in pj.SlotWafers)
  4234. {
  4235. if (CheckWaferNeedProcessAndPMAvailable(pjSlotWafer.Item1, pjSlotWafer.Item2))
  4236. {
  4237. pjWafer[pj.Name] = new SlotItem(pjSlotWafer.Item1, pjSlotWafer.Item2);
  4238. break;
  4239. }
  4240. }
  4241. }
  4242. }
  4243. }
  4244. if (pjWafer.Count == 0)
  4245. return null;
  4246. if (pjWafer.Count == 1)
  4247. return pjWafer.Values.First();
  4248. string preferPj = pjWafer.Keys.First();
  4249. int runningWaferCount = GetWaitingProcessWaferCount(preferPj);
  4250. foreach (var slotItem in pjWafer)
  4251. {
  4252. if (slotItem.Key == preferPj)
  4253. continue;
  4254. int count = GetWaitingProcessWaferCount(slotItem.Key);
  4255. if (count <= runningWaferCount)
  4256. {
  4257. preferPj = slotItem.Key;
  4258. runningWaferCount = count;
  4259. }
  4260. }
  4261. return pjWafer[preferPj];
  4262. }
  4263. public bool CheckWaferNeedProcessAndPMAvailable(ModuleName waferModule, int waferSlot, ModuleName processIn = ModuleName.System)
  4264. {
  4265. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  4266. if (wafer.IsEmpty)
  4267. return false;
  4268. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  4269. return false;
  4270. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  4271. return false;
  4272. for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  4273. {
  4274. if (wafer.ProcessJob.Sequence.Steps[i].StepModules.Any(p => ModuleHelper.IsPm(p)))
  4275. {
  4276. var hasPmAvailable = false;
  4277. foreach (var stepModule in wafer.ProcessJob.Sequence.Steps[i].StepModules)
  4278. {
  4279. SchedulerPM pm = _lstPms.FirstOrDefault(p=>p.Module == stepModule);
  4280. if (pm != null)
  4281. {
  4282. if (pm.IsAvailable || (pm.IsOnline && pm.Task != SchedulerModule.TaskType.PreJobProcess))
  4283. {
  4284. hasPmAvailable = true;
  4285. break;
  4286. }
  4287. }
  4288. }
  4289. if (!hasPmAvailable)
  4290. return false;
  4291. if (processIn == ModuleName.System)
  4292. return true;
  4293. if (wafer.ProcessJob.Sequence.Steps[i].StepModules
  4294. .Contains(processIn))
  4295. return true;
  4296. }
  4297. }
  4298. return false;
  4299. }
  4300. public bool LoadRecipe(string module, string CurrentRecipeBaseName, out double temp1, out double temp2)
  4301. {
  4302. var CurrentRecipeContent = RecipeFileManager.Instance.LoadRecipe("", CurrentRecipeBaseName, true);
  4303. temp1 = 0;
  4304. temp2 = 0;
  4305. if (string.IsNullOrEmpty(CurrentRecipeContent))
  4306. {
  4307. EV.PostInfoLog(ModuleName.System.ToString(), $"error during read recipe file {CurrentRecipeBaseName}");
  4308. return false;
  4309. }
  4310. if (!Recipe.Parse(module, CurrentRecipeContent, out RecipeHead recipeHead, out var recipeSteps))
  4311. {
  4312. return false;
  4313. }
  4314. temp1 = GetChamber1Temp(recipeHead);
  4315. temp2 = GetChamber2Temp(recipeHead);
  4316. return true;
  4317. }
  4318. public double GetChamber1Temp(RecipeHead CurrentRecipeHead)
  4319. {
  4320. if (CurrentRecipeHead != null)
  4321. {
  4322. if (!string.IsNullOrEmpty(CurrentRecipeHead.Chamber1Temperature))
  4323. {
  4324. double setpoint = Convert.ToDouble(CurrentRecipeHead.Chamber1Temperature);
  4325. if (setpoint > 0 && setpoint < 600)
  4326. return setpoint;
  4327. }
  4328. }
  4329. return 0;
  4330. }
  4331. public double GetChamber2Temp(RecipeHead CurrentRecipeHead)
  4332. {
  4333. if (CurrentRecipeHead != null)
  4334. {
  4335. if (!string.IsNullOrEmpty(CurrentRecipeHead.Chamber2Temperature))
  4336. {
  4337. double setpoint = Convert.ToDouble(CurrentRecipeHead.Chamber2Temperature);
  4338. if (setpoint > 0 && setpoint < 600)
  4339. return setpoint;
  4340. }
  4341. }
  4342. return 0;
  4343. }
  4344. private bool GetWaferTemperatureSetInRecipe(ModuleName waferModule, int waferSlot, ModuleName pmModule, out double temp1, out double temp2)
  4345. {
  4346. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  4347. if(!wafer.IsEmpty && wafer.ProcessJob != null && wafer.ProcessJob.Sequence != null && ModuleHelper.IsPm(pmModule))
  4348. {
  4349. var seq = wafer.ProcessJob.Sequence;
  4350. string recipeName = pmModule.ToString() + "Recipe";
  4351. SequenceStepInfo stepInfo = seq.Steps.FirstOrDefault(p=>p.StepModules.Contains(pmModule));
  4352. if (stepInfo != null && stepInfo.StepParameter != null && stepInfo.StepParameter.ContainsKey(recipeName))
  4353. {
  4354. LoadRecipe(pmModule.ToString(), stepInfo.StepParameter[recipeName].ToString(), out double chambertemp1, out double chambertemp2);
  4355. temp1 = chambertemp1;
  4356. temp2 = chambertemp2;
  4357. return true;
  4358. }
  4359. }
  4360. temp1 = 0;
  4361. temp2 = 0;
  4362. LOG.Error($"Can not find wafer {waferModule} {waferSlot + 1} temperature set in recipe");
  4363. return false;
  4364. }
  4365. #endregion
  4366. #region Logic Check
  4367. private bool CheckLoadLockAvaiableForTMRobot()
  4368. {
  4369. bool isPrepareTransferForTMobot = GetVacuumWafer() == 0;
  4370. foreach (var ll in _lstLls)
  4371. {
  4372. if (!ll.IsAvailable)
  4373. continue;
  4374. var deviceLL = DEVICE.GetDevice<LoadLock>(ll.Module.ToString());
  4375. var wafers = WaferManager.Instance.GetWafers(ll.Module).ToList();
  4376. for (int i = 0; i <= 5;)
  4377. {
  4378. var wafer0 = WaferManager.Instance.GetWafer(ll.Module, i);
  4379. var wafer1 = WaferManager.Instance.GetWafer(ll.Module, i + 1);
  4380. if ((!wafer0.IsEmpty && wafer0.ProcessState == EnumWaferProcessStatus.Idle) ||
  4381. (!wafer1.IsEmpty && wafer1.ProcessState == EnumWaferProcessStatus.Idle))
  4382. {
  4383. isPrepareTransferForTMobot = true;
  4384. break;
  4385. }
  4386. i += 2;
  4387. }
  4388. }
  4389. return isPrepareTransferForTMobot;
  4390. }
  4391. //private bool CheckPMTemperature(string module)
  4392. //{
  4393. // var pmDevice = DEVICE.GetDevice<SpinelPM>(module);
  4394. // if (pmDevice != null && _temperatureSetpointDic.ContainsKey(module) && _temperatureSetpointDic[module] > 0)
  4395. // {
  4396. // if (!pmDevice.CheckHeater1Temperature(_temperatureSetpointDic[module]) ||
  4397. // !pmDevice.CheckHeater2Temperature(_temperatureSetpointDic[module]))
  4398. // {
  4399. // if (!_temperatureTrigDic.ContainsKey(module))
  4400. // _temperatureTrigDic.Add(module, new R_TRIG());
  4401. // _temperatureTrigDic[module].CLK = true;
  4402. // if (_temperatureTrigDic[module].Q)
  4403. // {
  4404. // EV.PostWarningLog("Scheduler", $"{module} heater temperature is not in the scope");
  4405. // }
  4406. // pmDevice.SetHeater1(_temperatureSetpointDic[module]);
  4407. // pmDevice.SetHeater2(_temperatureSetpointDic[module]);
  4408. // }
  4409. // if (pmDevice.CheckHeater1Temperature(_temperatureSetpointDic[module]) &&
  4410. // pmDevice.CheckHeater2Temperature(_temperatureSetpointDic[module]))
  4411. // {
  4412. // return true;
  4413. // }
  4414. // }
  4415. // else
  4416. // return true;
  4417. // return false;
  4418. //}
  4419. private bool CheckWaferNextProcessIsPM(ModuleName waferModule, int waferSlot)
  4420. {
  4421. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  4422. if (wafer.IsEmpty)
  4423. return false;
  4424. if (wafer.ProcessJob == null ||
  4425. wafer.ProcessJob.Sequence == null ||
  4426. wafer.ProcessJob.Sequence.Steps == null ||
  4427. wafer.ProcessJob.Sequence.Steps.Count <= wafer.NextSequenceStep ||
  4428. wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep] == null ||
  4429. wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules == null)
  4430. {
  4431. return false;
  4432. }
  4433. return wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Any(x => ModuleHelper.IsPm(x));
  4434. }
  4435. private bool CheckWaferNextProcessIsPMAvaiable(ModuleName waferModule, int waferSlot)
  4436. {
  4437. if (!CheckWaferNextProcessIsPM(waferModule, waferSlot))
  4438. return false;
  4439. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  4440. foreach (var stepModule in wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules)
  4441. {
  4442. if (_lstPms.Any(pm => pm.Module == stepModule && pm.IsAvailable && WaferManager.Instance.CheckNoWafer(pm.Module, waferSlot)))
  4443. {
  4444. return true;
  4445. }
  4446. }
  4447. return false;
  4448. }
  4449. private bool CheckNeedRunClean(ModuleName module, out bool withWafer, out string recipeName)
  4450. {
  4451. recipeName = string.Empty;
  4452. withWafer = false;
  4453. return false;
  4454. SequenceInfo seq = GetCurrentSequenceInfo();
  4455. int waferProcessed = StatsDataManager.Instance.GetValue($"{module}.WaferProcessedSincePreviousClean");
  4456. if (seq == null)
  4457. return false;
  4458. foreach (var stepInfo in seq.Steps)
  4459. {
  4460. if (!stepInfo.StepModules.Contains(module))
  4461. continue;
  4462. if (stepInfo.StepParameter.ContainsKey("CleanRecipeNoWafer")
  4463. && !string.IsNullOrEmpty((string)stepInfo.StepParameter["CleanRecipeNoWafer"]))
  4464. {
  4465. if (stepInfo.CleanInterval > 0 && waferProcessed >= stepInfo.CleanInterval)
  4466. {
  4467. recipeName = (string)stepInfo.StepParameter["CleanRecipeNoWafer"];
  4468. withWafer = false;
  4469. return true;
  4470. }
  4471. }
  4472. if (stepInfo.StepParameter.ContainsKey("CleanRecipeWafer")
  4473. && !string.IsNullOrEmpty((string)stepInfo.StepParameter["CleanRecipeWafer"]))
  4474. {
  4475. if (stepInfo.CleanInterval > 0 && waferProcessed >= stepInfo.CleanInterval)
  4476. {
  4477. recipeName = (string)stepInfo.StepParameter["CleanRecipeWafer"];
  4478. withWafer = true;
  4479. return true;
  4480. }
  4481. }
  4482. }
  4483. return false;
  4484. }
  4485. //private bool CheckVacuumWaferHasAvailableTarget(ModuleName waferModule, int waferSlot, ModuleName chamberSwappable)
  4486. //{
  4487. // WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  4488. // //System.Diagnostics.Trace.Assert(!wafer.IsEmpty);
  4489. // if (CheckWaferNeedProcess(waferModule, waferSlot))
  4490. // {
  4491. // // Check for an empty PM
  4492. // foreach (var pm in _lstPms)
  4493. // {
  4494. // if (WaferManager.Instance.CheckNoWafer(pm.Module, 0) || pm.Module == chamberSwappable)
  4495. // {
  4496. // if (pm.IsAvailable == false)
  4497. // continue;
  4498. // if (!CheckWaferNextProcessIn(waferModule, waferSlot, pm.Module))
  4499. // continue;
  4500. // return true;
  4501. // }
  4502. // }
  4503. // }
  4504. // else
  4505. // {
  4506. // // No more processing needed, check for a outbound loadlock slot
  4507. // return true;
  4508. // }
  4509. // return false;
  4510. //}
  4511. //private bool CheckWaferNextProcessIn(ModuleName waferModule, int waferSlot, ModuleName chamber)
  4512. //{
  4513. // WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  4514. // if (wafer.ProcessJob == null ||
  4515. // wafer.ProcessJob.Sequence == null ||
  4516. // wafer.ProcessJob.Sequence.Steps == null ||
  4517. // wafer.ProcessJob.Sequence.Steps.Count <= wafer.NextSequenceStep ||
  4518. // wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep] == null ||
  4519. // wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules == null)
  4520. // {
  4521. // return false;
  4522. // }
  4523. // return wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(chamber);
  4524. //}
  4525. private SequenceInfo GetCurrentSequenceInfo()
  4526. {
  4527. foreach (var pj in _lstProcessJobs)
  4528. {
  4529. if (pj.State == EnumProcessJobState.Processing)
  4530. {
  4531. return pj.Sequence;
  4532. }
  4533. }
  4534. return null;
  4535. }
  4536. private bool GetWaferSequenceAlignAngle(ModuleName module, int slot, out double angle)
  4537. {
  4538. angle = 0;
  4539. if (!WaferManager.Instance.CheckHasWafer(module, slot))
  4540. return false;
  4541. WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
  4542. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  4543. return false;
  4544. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  4545. return false;
  4546. if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Aligner))
  4547. return false;
  4548. angle = wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].AlignAngle;
  4549. return true;
  4550. }
  4551. private bool GetWaferSequenceCoolingTime(ModuleName module, int slot, out int coolingTime)
  4552. {
  4553. coolingTime = 0;
  4554. if (!WaferManager.Instance.CheckHasWafer(module, slot))
  4555. return false;
  4556. WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
  4557. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  4558. return false;
  4559. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  4560. return false;
  4561. if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(module))
  4562. return false;
  4563. if (!int.TryParse(wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepParameter["CoolingTime"].ToString(),
  4564. out coolingTime))
  4565. {
  4566. coolingTime = SC.GetValueOrDefault<int>("System.DefaultCoolingTime");
  4567. EV.PostWarningLog("Scheduler", $"Sequence step LL cooling time is not valid, instead with the SC default value {coolingTime} seconds");
  4568. return false;
  4569. }
  4570. return true;
  4571. }
  4572. private bool CheckWaferNextStepIsLoadLock(ModuleName module, int slot, ModuleName LL = ModuleName.System)
  4573. {
  4574. if (!WaferManager.Instance.CheckHasWafer(module, slot))
  4575. return false;
  4576. WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
  4577. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  4578. return false;
  4579. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  4580. return false;
  4581. if (LL != ModuleName.System && !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(LL))
  4582. return false;
  4583. if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.LLA) &&
  4584. !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.LLB))
  4585. return false;
  4586. return true;
  4587. }
  4588. private bool CheckWaferNextStepIsAlign(ModuleName module, int slot)
  4589. {
  4590. if (!WaferManager.Instance.CheckHasWafer(module, slot))
  4591. return false;
  4592. WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
  4593. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  4594. return false;
  4595. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  4596. return false;
  4597. if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Aligner) &&
  4598. !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.AlignerA) &&
  4599. !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.AlignerB) &&
  4600. !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Aligner1) &&
  4601. !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Aligner2))
  4602. return false;
  4603. return true;
  4604. }
  4605. private bool CheckWaferNextStepIsCooling(ModuleName module, int slot)
  4606. {
  4607. if (!WaferManager.Instance.CheckHasWafer(module, slot))
  4608. return false;
  4609. WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
  4610. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  4611. return false;
  4612. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  4613. return false;
  4614. if (!wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Cooling) &&
  4615. !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Cooling1) &&
  4616. !wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules.Contains(ModuleName.Cooling2))
  4617. return false;
  4618. return true;
  4619. }
  4620. public bool CheckWaferNeedProcess(ModuleName waferModule, int waferSlot, ModuleName processIn = ModuleName.System)
  4621. {
  4622. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  4623. if (wafer.IsEmpty)
  4624. return false;
  4625. if (wafer.Status == WaferStatus.Dummy && wafer.ProcessState == EnumWaferProcessStatus.Wait)
  4626. {
  4627. if (ModuleHelper.IsPm(processIn))
  4628. {
  4629. return (CheckNeedRunClean(processIn, out bool withWafer, out _) && withWafer);
  4630. }
  4631. return true;
  4632. }
  4633. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.ProcessJob.Sequence.Steps == null)
  4634. return false;
  4635. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count || wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules == null)
  4636. return false;
  4637. for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  4638. {
  4639. if (processIn != ModuleName.System && wafer.ProcessJob.Sequence.Steps[i].StepModules.Contains(processIn))
  4640. {
  4641. return true;
  4642. }
  4643. }
  4644. bool hasPm = false;
  4645. for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  4646. {
  4647. foreach (var stepModule in wafer.ProcessJob.Sequence.Steps[i].StepModules)
  4648. {
  4649. if (ModuleHelper.IsPm(stepModule))
  4650. {
  4651. hasPm = true;
  4652. break;
  4653. }
  4654. }
  4655. if (hasPm)
  4656. break;
  4657. }
  4658. if (processIn == ModuleName.System && hasPm)
  4659. return true;
  4660. return false;
  4661. }
  4662. public bool CheckWaferNeedProcessPre(ModuleName waferModule, int waferSlot, ModuleName processIn = ModuleName.System)
  4663. {
  4664. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  4665. if (wafer.IsEmpty)
  4666. return false;
  4667. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  4668. return false;
  4669. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  4670. return false;
  4671. for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  4672. {
  4673. if (wafer.ProcessJob.Sequence.Steps[i].StepModules.Any(p => ModuleHelper.IsPm(p)))
  4674. {
  4675. if (processIn == ModuleName.System)
  4676. return true;
  4677. if (wafer.ProcessJob.Sequence.Steps[i].StepModules.Contains(processIn))
  4678. {
  4679. return true;
  4680. }
  4681. }
  4682. }
  4683. return false;
  4684. }
  4685. public bool CheckWaferNeedProcessBySlot(ModuleName waferModule, int waferSlot, ModuleName processIn, int pmSlot)
  4686. {
  4687. var result = CheckWaferNeedProcess(waferModule, waferSlot, processIn);
  4688. if (result && pmSlot >= 0)
  4689. {
  4690. if (ModuleHelper.IsPm(processIn))
  4691. {
  4692. result = false;
  4693. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  4694. for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  4695. {
  4696. if (wafer.ProcessJob.Sequence.Steps[i].StepModules.Contains(processIn)
  4697. && wafer.ProcessJob.Sequence.Steps[i].StepParameter.ContainsKey(processIn.ToString())
  4698. )
  4699. {
  4700. var slotList = wafer.ProcessJob.Sequence.Steps[i].StepParameter[processIn.ToString()];
  4701. result = (slotList != null && slotList.ToString().IndexOf(pmSlot.ToString()) > -1);
  4702. }
  4703. }
  4704. }
  4705. }
  4706. return result;
  4707. }
  4708. public bool CheckWaferNeedProcessBySlot(WaferInfo wafer, ModuleName processIn, int slot)
  4709. {
  4710. var result = CheckWaferNeedProcess(wafer, processIn);
  4711. if (result && slot >= 0)
  4712. {
  4713. if(ModuleHelper.IsPm(processIn))
  4714. {
  4715. result = false;
  4716. for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  4717. {
  4718. if (wafer.ProcessJob.Sequence.Steps[i].StepModules.Contains(processIn)
  4719. && wafer.ProcessJob.Sequence.Steps[i].StepParameter.ContainsKey(processIn.ToString())
  4720. )
  4721. {
  4722. var slotList = wafer.ProcessJob.Sequence.Steps[i].StepParameter[processIn.ToString()];
  4723. result = (slotList != null && slotList.ToString().IndexOf(slot.ToString())>-1);
  4724. }
  4725. }
  4726. }
  4727. }
  4728. return result;
  4729. }
  4730. public bool CheckWaferNeedProcess(WaferInfo wafer, ModuleName processIn = ModuleName.System)
  4731. {
  4732. if (wafer.IsEmpty)
  4733. return false;
  4734. if (wafer.Status == WaferStatus.Dummy && wafer.ProcessState == EnumWaferProcessStatus.Wait)
  4735. {
  4736. if (ModuleHelper.IsPm(processIn))
  4737. {
  4738. return (CheckNeedRunClean(processIn, out bool withWafer, out _) && withWafer);
  4739. }
  4740. return true;
  4741. }
  4742. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.ProcessJob.Sequence.Steps == null)
  4743. return false;
  4744. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count || wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules == null)
  4745. return false;
  4746. for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  4747. {
  4748. if (processIn != ModuleName.System && wafer.ProcessJob.Sequence.Steps[i].StepModules.Contains(processIn))
  4749. {
  4750. return true;
  4751. }
  4752. }
  4753. bool hasPm = false;
  4754. for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  4755. {
  4756. foreach (var stepModule in wafer.ProcessJob.Sequence.Steps[i].StepModules)
  4757. {
  4758. if (ModuleHelper.IsPm(stepModule))
  4759. {
  4760. hasPm = true;
  4761. break;
  4762. }
  4763. }
  4764. if (hasPm)
  4765. break;
  4766. }
  4767. if (processIn == ModuleName.System && hasPm)
  4768. return true;
  4769. return false;
  4770. }
  4771. public bool CheckWaferNeedGotoPM(ModuleName waferModule, int waferSlot, ModuleName processIn = ModuleName.System)
  4772. {
  4773. WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  4774. if (wafer.IsEmpty)
  4775. return false;
  4776. if (wafer.Status == WaferStatus.Dummy && wafer.ProcessState == EnumWaferProcessStatus.Wait)
  4777. {
  4778. if (ModuleHelper.IsPm(processIn))
  4779. {
  4780. return (CheckNeedRunClean(processIn, out bool withWafer, out _) && withWafer);
  4781. }
  4782. return true;
  4783. }
  4784. if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.ProcessJob.Sequence.Steps == null)
  4785. return false;
  4786. if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count || wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules == null)
  4787. return false;
  4788. if (processIn != ModuleName.System && !wafer.ProcessJob.Sequence.Steps.Any(x => x.StepModules.Contains(processIn)))
  4789. {
  4790. return false;
  4791. }
  4792. bool hasPm = false;
  4793. for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  4794. {
  4795. foreach (var stepModule in wafer.ProcessJob.Sequence.Steps[i].StepModules)
  4796. {
  4797. if (ModuleHelper.IsPm(stepModule))
  4798. {
  4799. hasPm = true;
  4800. break;
  4801. }
  4802. }
  4803. if (hasPm)
  4804. break;
  4805. }
  4806. if (processIn == ModuleName.System && !hasPm)
  4807. return false;
  4808. return true;
  4809. }
  4810. //public bool CheckWaferNeedGotoPM(WaferInfo wafer, ModuleName processIn = ModuleName.System)
  4811. //{
  4812. // if (wafer.IsEmpty)
  4813. // return false;
  4814. // if (wafer.Status == WaferStatus.Dummy && wafer.ProcessState == EnumWaferProcessStatus.Wait)
  4815. // {
  4816. // if (ModuleHelper.IsPm(processIn))
  4817. // {
  4818. // return (CheckNeedRunClean(processIn, out bool withWafer, out _) && withWafer);
  4819. // }
  4820. // return true;
  4821. // }
  4822. // if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null || wafer.ProcessJob.Sequence.Steps == null)
  4823. // return false;
  4824. // if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count || wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules == null)
  4825. // return false;
  4826. // if (processIn != ModuleName.System && !wafer.ProcessJob.Sequence.Steps.Any(x => x.StepModules.Contains(processIn)))
  4827. // {
  4828. // return false;
  4829. // }
  4830. // bool hasPm = false;
  4831. // for (int i = wafer.NextSequenceStep; i < wafer.ProcessJob.Sequence.Steps.Count; i++)
  4832. // {
  4833. // foreach (var stepModule in wafer.ProcessJob.Sequence.Steps[i].StepModules)
  4834. // {
  4835. // if (ModuleHelper.IsPm(stepModule))
  4836. // {
  4837. // hasPm = true;
  4838. // break;
  4839. // }
  4840. // }
  4841. // if (hasPm)
  4842. // break;
  4843. // }
  4844. // if (processIn == ModuleName.System && !hasPm)
  4845. // return false;
  4846. // return true;
  4847. //}
  4848. //public bool CheckWaferSequenceStepDone(ModuleName waferModule, int waferSlot)
  4849. //{
  4850. // WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  4851. // if (wafer.IsEmpty)
  4852. // return false;
  4853. // if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  4854. // return false;
  4855. // if (wafer.NextSequenceStep < wafer.ProcessJob.Sequence.Steps.Count)
  4856. // return false;
  4857. // return true;
  4858. //}
  4859. //public bool CheckWaferProcessModuleIsAvailable(ModuleName waferModule, int waferSlot)
  4860. //{
  4861. // WaferInfo wafer = WaferManager.Instance.GetWafer(waferModule, waferSlot);
  4862. // if (wafer.IsEmpty)
  4863. // return false;
  4864. // if (wafer.ProcessJob == null || wafer.ProcessJob.Sequence == null)
  4865. // return false;
  4866. // if (wafer.NextSequenceStep >= wafer.ProcessJob.Sequence.Steps.Count)
  4867. // return false;
  4868. // foreach (var step in wafer.ProcessJob.Sequence.Steps)
  4869. // {
  4870. // foreach (var module in step.StepModules)
  4871. // {
  4872. // if (WaferManager.Instance.CheckNoWafer(module, 0)
  4873. // && _lstPms.Find(x => x.Module == module).IsAvailable
  4874. // && !CheckNeedRunClean(module, out bool _, out string _))
  4875. // return true;
  4876. // }
  4877. // }
  4878. // return false;
  4879. //}
  4880. //private int GetATMWafer()
  4881. //{
  4882. // int count = GetWaferCountInJobQueue();
  4883. // if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0))
  4884. // count++;
  4885. // if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1))
  4886. // count++;
  4887. // if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 2))
  4888. // count++;
  4889. // return count;
  4890. //}
  4891. private int GetVacuumWafer()
  4892. {
  4893. int count = 0;
  4894. foreach (var schedulerPm in _lstPms)
  4895. {
  4896. if (schedulerPm == null ||
  4897. (!schedulerPm.IsOnline))
  4898. continue;
  4899. if (WaferManager.Instance.CheckHasWafer(schedulerPm.Module, 0) || WaferManager.Instance.CheckHasWafer(schedulerPm.Module, 1))
  4900. count++;
  4901. }
  4902. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0) || WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1))
  4903. count++;
  4904. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 2) || WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 3))
  4905. count++;
  4906. return count;
  4907. }
  4908. //private int GetVacuumProcessedWafer()
  4909. //{
  4910. // int count = 0;
  4911. // foreach (var schedulerPm in _lstPmsCurrentSequence)
  4912. // {
  4913. // if (schedulerPm == null)
  4914. // continue;
  4915. // if (WaferManager.Instance.CheckHasWafer(schedulerPm.Module, 0)
  4916. // && schedulerPm.IsAvailable
  4917. // && !CheckWaferNeedProcess(schedulerPm.Module, 0)
  4918. // && !WaferManager.Instance.CheckWaferIsDummy(schedulerPm.Module, 0))
  4919. // count++;
  4920. // }
  4921. // if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0) && !CheckWaferNeedProcess(ModuleName.TMRobot, 0) && !WaferManager.Instance.CheckWaferIsDummy(ModuleName.TMRobot, 0))
  4922. // count++;
  4923. // if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 1) && !CheckWaferNeedProcess(ModuleName.TMRobot, 1) && !WaferManager.Instance.CheckWaferIsDummy(ModuleName.TMRobot, 1))
  4924. // count++;
  4925. // return count;
  4926. //}
  4927. //private int GetUnprocessedWafer()
  4928. //{
  4929. // int count = 0;
  4930. // foreach (var cj in _lstControlJobs)
  4931. // {
  4932. // if (cj.State == EnumControlJobState.Executing)
  4933. // {
  4934. // foreach (var pj in _lstProcessJobs)
  4935. // {
  4936. // if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing)
  4937. // {
  4938. // foreach (var pjSlotWafer in pj.SlotWafers)
  4939. // {
  4940. // if (CheckWaferNeedProcess(pjSlotWafer.Item1, pjSlotWafer.Item2))
  4941. // count++;
  4942. // }
  4943. // }
  4944. // }
  4945. // }
  4946. // }
  4947. // foreach (var ll in _lstLls)
  4948. // {
  4949. // if (CheckWaferNeedProcess(ll.Module, 0))
  4950. // count++;
  4951. // if (CheckWaferNeedProcess(ll.Module, 1))
  4952. // count++;
  4953. // if (CheckWaferNeedProcess(ll.Module, 2))
  4954. // count++;
  4955. // if (CheckWaferNeedProcess(ll.Module, 3))
  4956. // count++;
  4957. // if (CheckWaferNeedProcess(ll.Module, 4))
  4958. // count++;
  4959. // if (CheckWaferNeedProcess(ll.Module, 5))
  4960. // count++;
  4961. // }
  4962. // if (CheckWaferNeedProcess(ModuleName.TMRobot, 0))
  4963. // count++;
  4964. // if (CheckWaferNeedProcess(ModuleName.TMRobot, 1))
  4965. // count++;
  4966. // if (CheckWaferNeedProcess(ModuleName.TMRobot, 2))
  4967. // count++;
  4968. // if (CheckWaferNeedProcess(ModuleName.TMRobot, 3))
  4969. // count++;
  4970. // return count;
  4971. //}
  4972. //private int GetAvailablePmCount()
  4973. //{
  4974. // int count = 0;
  4975. // foreach (var pm in _lstPms)
  4976. // {
  4977. // if (!pm.IsAvailable)
  4978. // continue;
  4979. // if (WaferManager.Instance.CheckNoWafer(pm.Module, 0))
  4980. // count++;
  4981. // }
  4982. // return count;
  4983. //}
  4984. private SlotItem GetWaferInJobQueue()
  4985. {
  4986. SlotItem slotItem = null;
  4987. bool enableParallel = SC.GetValue<bool>("System.Scheduler.IsRunInParallelMode");
  4988. var OrderedLstCJs = _lstControlJobs.OrderBy(x => x.BeginTime);
  4989. if (enableParallel)
  4990. {
  4991. var priorityFindWaferGotoPMA = GetWaferCountLoadLockToPM(ModuleName.PMA) <= GetWaferCountLoadLockToPM(ModuleName.PMB);
  4992. var priorityFindWaferGotoPMB = GetWaferCountLoadLockToPM(ModuleName.PMA) > GetWaferCountLoadLockToPM(ModuleName.PMB);
  4993. foreach (var cj in OrderedLstCJs)
  4994. {
  4995. if (cj.State == EnumControlJobState.Executing)
  4996. {
  4997. foreach (var pj in _lstProcessJobs)
  4998. {
  4999. if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing&&pj.SlotWafers!=null)
  5000. {
  5001. foreach (var pjSlotWafer in pj.SlotWafers)
  5002. {
  5003. if (priorityFindWaferGotoPMA)
  5004. {
  5005. if (CheckWaferNeedGotoPM(pjSlotWafer.Item1, pjSlotWafer.Item2, ModuleName.PMA))
  5006. {
  5007. return new SlotItem(pjSlotWafer.Item1, pjSlotWafer.Item2);
  5008. }
  5009. }
  5010. if (priorityFindWaferGotoPMB)
  5011. {
  5012. if (CheckWaferNeedGotoPM(pjSlotWafer.Item1, pjSlotWafer.Item2, ModuleName.PMB))
  5013. {
  5014. return new SlotItem(pjSlotWafer.Item1, pjSlotWafer.Item2);
  5015. }
  5016. }
  5017. }
  5018. }
  5019. }
  5020. }
  5021. }
  5022. }
  5023. if (slotItem == null)
  5024. {
  5025. foreach (var cj in OrderedLstCJs)
  5026. {
  5027. if (cj.State == EnumControlJobState.Executing)
  5028. {
  5029. foreach (var pj in _lstProcessJobs)
  5030. {
  5031. if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing&&pj.SlotWafers!=null)
  5032. {
  5033. foreach (var pjSlotWafer in pj.SlotWafers)
  5034. {
  5035. if (CheckWaferNeedProcess(pjSlotWafer.Item1, pjSlotWafer.Item2))
  5036. {
  5037. return new SlotItem(pjSlotWafer.Item1, pjSlotWafer.Item2);
  5038. }
  5039. }
  5040. }
  5041. }
  5042. }
  5043. }
  5044. }
  5045. return slotItem;
  5046. }
  5047. private Tuple<SchedulerLoadLock, int> GetWaferOrderInJobQueue(List<Tuple<SchedulerLoadLock, int>> llSlots)
  5048. {
  5049. foreach (var cj in _lstControlJobs.OrderBy(p=>p.BeginTime))
  5050. {
  5051. if (cj.State == EnumControlJobState.Executing)
  5052. {
  5053. foreach (var pj in _lstProcessJobs)
  5054. {
  5055. if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing&&pj.SlotWafers!=null)
  5056. {
  5057. foreach (var pjSlotWafer in pj.SlotWafers)
  5058. {
  5059. foreach (var slot in llSlots)
  5060. {
  5061. var wafer = WaferManager.Instance.GetWafer(slot.Item1.Module, slot.Item2);
  5062. if (wafer.OriginStation == (int)pjSlotWafer.Item1 && wafer.OriginSlot == pjSlotWafer.Item2)
  5063. return slot;
  5064. }
  5065. }
  5066. }
  5067. }
  5068. }
  5069. }
  5070. return null;
  5071. }
  5072. //用于Aligners、Coolings排序
  5073. private List<SchedulerAligner> GetWaferOrderInJobQueue(List<SchedulerAligner> moduleSlots)
  5074. {
  5075. List<SchedulerAligner> result = new List<SchedulerAligner>();
  5076. foreach (var cj in _lstControlJobs)
  5077. {
  5078. if (cj.State == EnumControlJobState.Executing)
  5079. {
  5080. foreach (var pj in _lstProcessJobs)
  5081. {
  5082. if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing&&pj.SlotWafers!=null)
  5083. {
  5084. foreach (var pjSlotWafer in pj.SlotWafers)
  5085. {
  5086. foreach (var moduleSlot in moduleSlots)
  5087. {
  5088. var wafer = WaferManager.Instance.GetWafer(moduleSlot.Module, 0);
  5089. if (wafer.OriginStation == (int)pjSlotWafer.Item1 && wafer.OriginSlot == pjSlotWafer.Item2)
  5090. result.Add(moduleSlot);
  5091. }
  5092. }
  5093. }
  5094. }
  5095. }
  5096. }
  5097. return result;
  5098. }
  5099. private List<WaferInfo> SortWaferByJobQueue(List<WaferInfo> originWafers)
  5100. {
  5101. List<WaferInfo> result = new List<WaferInfo>();
  5102. foreach (var cj in _lstControlJobs)
  5103. {
  5104. if (cj.State == EnumControlJobState.Executing)
  5105. {
  5106. foreach (var pj in _lstProcessJobs)
  5107. {
  5108. if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing&&pj.SlotWafers!=null)
  5109. {
  5110. foreach (var pjSlotWafer in pj.SlotWafers)
  5111. {
  5112. foreach (var wafer in originWafers)
  5113. {
  5114. if (wafer.OriginStation == (int)pjSlotWafer.Item1 && wafer.OriginSlot == pjSlotWafer.Item2)
  5115. result.Add(wafer);
  5116. }
  5117. }
  5118. }
  5119. }
  5120. }
  5121. }
  5122. return result;
  5123. }
  5124. private bool CheckWaferInJobQueue(ModuleName module, int slot)
  5125. {
  5126. foreach (var cj in _lstControlJobs)
  5127. {
  5128. if (cj.State == EnumControlJobState.Executing)
  5129. {
  5130. foreach (var pj in _lstProcessJobs)
  5131. {
  5132. if (pj.ControlJobName == cj.Name && pj.State == EnumProcessJobState.Processing&&pj.SlotWafers!=null)
  5133. {
  5134. foreach (var pjSlotWafer in pj.SlotWafers)
  5135. {
  5136. if (pjSlotWafer.Item1 == module && pjSlotWafer.Item2 == slot && CheckWaferNeedProcess(pjSlotWafer.Item1, pjSlotWafer.Item2))
  5137. {
  5138. return true;
  5139. }
  5140. }
  5141. }
  5142. }
  5143. }
  5144. }
  5145. return false;
  5146. }
  5147. private int GetWaferCountInJobQueue()
  5148. {
  5149. int count = 0;
  5150. foreach (var lp in _lstLps)
  5151. {
  5152. for (int i = 0; i < 25; i++)
  5153. {
  5154. if (CheckWaferNeedProcess(lp.Module, i))
  5155. count++;
  5156. }
  5157. }
  5158. return count;
  5159. }
  5160. //private SchedulerLoadLock GetCurrentLoadLockForTMPlace()
  5161. //{
  5162. // foreach (var ll in _lstLls)
  5163. // {
  5164. // if (!ll.IsAvailable)
  5165. // continue;
  5166. // //if (!ll.CheckAtVacuum())
  5167. // // continue;
  5168. // var wafers = WaferManager.Instance.GetWafers(ll.Module).ToList();
  5169. // if (wafers.Any(x => x.ProcessState == EnumWaferProcessStatus.Completed))
  5170. // {
  5171. // for (int i = 0; i < 5;)
  5172. // {
  5173. // if ((WaferManager.Instance.CheckNoWafer(ll.Module, i))
  5174. // && (WaferManager.Instance.CheckNoWafer(ll.Module, i + 1)))
  5175. // {
  5176. // return ll;
  5177. // }
  5178. // i += 2;
  5179. // }
  5180. // }
  5181. // }
  5182. // SchedulerLoadLock currentLoadLock = null;
  5183. // DateTime dtMin = DateTime.MaxValue;
  5184. // foreach (var ll in _lstLls)
  5185. // {
  5186. // if (!ll.IsAvailable || !ll.CheckAtVacuum())
  5187. // continue;
  5188. // var wafers = WaferManager.Instance.GetWafers(ll.Module).ToList();
  5189. // DateTime dtCurrentLL = DateTime.MaxValue;
  5190. // foreach (var wafer in wafers)
  5191. // {
  5192. // if (wafer != null && !wafer.IsEmpty && wafer.SubstHists.Length > 0)
  5193. // {
  5194. // var dt = wafer.SubstHists[wafer.SubstHists.Length - 1].AccessTime;
  5195. // if (dt.CompareTo(dtMin) < 0)
  5196. // dtCurrentLL = dt;
  5197. // }
  5198. // }
  5199. // if (dtCurrentLL.CompareTo(dtMin) < 0)
  5200. // {
  5201. // dtMin = dtCurrentLL;
  5202. // currentLoadLock = ll;
  5203. // }
  5204. // }
  5205. // foreach (var ll in _lstLls)
  5206. // {
  5207. // if (currentLoadLock != null && currentLoadLock != ll)
  5208. // continue;
  5209. // for (int i = 0; i < 5;)
  5210. // {
  5211. // if ((WaferManager.Instance.CheckNoWafer(ll.Module, i))
  5212. // && (WaferManager.Instance.CheckNoWafer(ll.Module, i + 1)))
  5213. // {
  5214. // return currentLoadLock;
  5215. // }
  5216. // i += 2;
  5217. // }
  5218. // currentLoadLock = null;//no empty slot
  5219. // }
  5220. // return currentLoadLock;
  5221. //}
  5222. //private SchedulerLoadLock GetCurrentLoadLockForTMPick()
  5223. //{
  5224. // SchedulerLoadLock currentLoadLock = null;
  5225. // DateTime dtMin = DateTime.MaxValue;
  5226. // foreach (var ll in _lstLls)
  5227. // {
  5228. // if (!ll.IsAvailable || !ll.CheckAtVacuum())
  5229. // continue;
  5230. // var wafers = WaferManager.Instance.GetWafers(ll.Module).ToList();
  5231. // DateTime dtCurrentLL = DateTime.MaxValue;
  5232. // foreach (var wafer in wafers)
  5233. // {
  5234. // if (wafer != null && !wafer.IsEmpty && wafer.ProcessState == EnumWaferProcessStatus.Idle && wafer.SubstHists.Length > 0)
  5235. // {
  5236. // var dt = wafer.SubstHists[wafer.SubstHists.Length - 1].AccessTime;
  5237. // if (dt.CompareTo(dtMin) < 0)
  5238. // dtCurrentLL = dt;
  5239. // }
  5240. // }
  5241. // if (dtCurrentLL.CompareTo(dtMin) < 0)
  5242. // {
  5243. // dtMin = dtCurrentLL;
  5244. // currentLoadLock = ll;
  5245. // }
  5246. // }
  5247. // return currentLoadLock;
  5248. //}
  5249. //private SchedulerLoadLock GetCurrentLoadLockForEfem()
  5250. //{
  5251. // SchedulerLoadLock currentLoadLock = null;
  5252. // foreach (var ll in _lstLls)
  5253. // {
  5254. // if (!ll.IsOnline)
  5255. // continue;
  5256. // var wafers = WaferManager.Instance.GetWafers(ll.Module).ToList();
  5257. // if (loadlockDevice.CheckDoorOpen())
  5258. // {
  5259. // foreach (var wafer in wafers)
  5260. // {
  5261. // if (wafer != null && !wafer.IsEmpty && wafer.ProcessState == EnumWaferProcessStatus.Idle)
  5262. // {
  5263. // currentLoadLock = ll;
  5264. // break;
  5265. // }
  5266. // }
  5267. // if (!wafers.Any(x => x.IsEmpty))
  5268. // {
  5269. // currentLoadLock = null;
  5270. // }
  5271. // }
  5272. // }
  5273. // return currentLoadLock;
  5274. //}
  5275. private int GetEmptySlotInCurrentLoadLock()
  5276. {
  5277. int count = 0;
  5278. //SchedulerLoadLock currentLoadLock = GetCurrentLoadLockForEfem();
  5279. foreach (var ll in _lstLls)
  5280. {
  5281. if (!ll.IsOnline)
  5282. continue;
  5283. //if (currentLoadLock != null && currentLoadLock != ll)
  5284. // continue;
  5285. //var loadlockDevice = DEVICE.GetDevice<SpinelLoadLock>(ll.Module.ToString());
  5286. var wafers = WaferManager.Instance.GetWafers(ll.Module).ToList();
  5287. //if (loadlockDevice.CheckDoorOpen())
  5288. {
  5289. for (int i = 0; i <= 1; i++)
  5290. {
  5291. var wafer0 = WaferManager.Instance.GetWafer(ll.Module, i);
  5292. var wafer1 = WaferManager.Instance.GetWafer(ll.Module, i + 2);
  5293. var wafer2 = WaferManager.Instance.GetWafer(ll.Module, i + 4);
  5294. if (wafer0 != null && wafer0.IsEmpty)
  5295. count++;
  5296. if (wafer1 != null && wafer1.IsEmpty)
  5297. count++;
  5298. if (wafer2 != null && wafer2.IsEmpty)
  5299. count++;
  5300. if (count > 0)
  5301. break;
  5302. }
  5303. }
  5304. }
  5305. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 0) && CheckWaferNeedProcess(ModuleName.EfemRobot, 0))
  5306. count--;
  5307. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 1) && CheckWaferNeedProcess(ModuleName.EfemRobot, 1))
  5308. count--;
  5309. if (WaferManager.Instance.CheckHasWafer(ModuleName.EfemRobot, 2) && CheckWaferNeedProcess(ModuleName.EfemRobot, 2))
  5310. count--;
  5311. return count < 0 ? 0 : count;
  5312. }
  5313. private int GetEmptySlotInLoadLock(SchedulerLoadLock ll)
  5314. {
  5315. int count = 0;
  5316. {
  5317. if (!ll.IsOnline)
  5318. return count;
  5319. var wafers = WaferManager.Instance.GetWafers(ll.Module);
  5320. for (int i = 0; i < wafers.Length; i++)
  5321. {
  5322. if (wafers[i].IsEmpty)
  5323. count++;
  5324. }
  5325. }
  5326. return count;
  5327. }
  5328. private int GetEmptySlotInLoadLock()
  5329. {
  5330. int count = 0;
  5331. foreach (var ll in _lstLls)
  5332. {
  5333. if (!ll.IsOnline)
  5334. continue;
  5335. var wafers = WaferManager.Instance.GetWafers(ll.Module);
  5336. for (int i = 0; i < wafers.Length; i++)
  5337. {
  5338. if (wafers[i].IsEmpty)
  5339. count++;
  5340. }
  5341. }
  5342. return count;
  5343. }
  5344. private int GetEmptySlotInPM()
  5345. {
  5346. int count = 0;
  5347. foreach (var pm in _lstPms)
  5348. {
  5349. if (!pm.IsOnline)
  5350. continue;
  5351. var wafers = WaferManager.Instance.GetWafers(pm.Module);
  5352. for (int i = 0; i < wafers.Length; i++)
  5353. {
  5354. if (wafers[i].IsEmpty)
  5355. count++;
  5356. }
  5357. }
  5358. return count;
  5359. }
  5360. private int GetEmptySlotInPMA()
  5361. {
  5362. int count = 0;
  5363. if (!_pm1.IsOnline)
  5364. return count;
  5365. var wafers = WaferManager.Instance.GetWafers(_pm1.Module);
  5366. for (int i = 0; i < wafers.Length; i++)
  5367. {
  5368. if (wafers[i].IsEmpty)
  5369. count++;
  5370. }
  5371. return count;
  5372. }
  5373. private int GetEmptySlotInPMB()
  5374. {
  5375. int count = 0;
  5376. if (!_pm2.IsOnline)
  5377. return count;
  5378. var wafers = WaferManager.Instance.GetWafers(_pm2.Module);
  5379. for (int i = 0; i < wafers.Length; i++)
  5380. {
  5381. if (wafers[i].IsEmpty)
  5382. count++;
  5383. }
  5384. return count;
  5385. }
  5386. //private bool CheckAlignerWaferCanPick(WaferInfo wafer, ModuleName aligner)
  5387. //{
  5388. // if (wafer == null || wafer.IsEmpty || wafer.ProcessJob == null ||
  5389. // wafer.ProcessJob.Sequence == null || wafer.ProcessJob.Sequence.Steps == null || wafer.ProcessJob.Sequence.Steps.Count == 0)
  5390. // return false;
  5391. // var stepModules = wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep].StepModules;
  5392. // int count = 0;
  5393. // int waferCount = 0;
  5394. // if (stepModules == null || stepModules.Count == 0)
  5395. // {
  5396. // return false;
  5397. // }
  5398. // foreach (var pm in _lstPms)
  5399. // {
  5400. // if (pm.IsOnline && stepModules.Contains(pm.Module))
  5401. // {
  5402. // count++;
  5403. // if (WaferManager.Instance.CheckHasWafer(pm.Module, 0))
  5404. // waferCount++;
  5405. // }
  5406. // }
  5407. // if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0) && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1))
  5408. // {
  5409. // count++;
  5410. // }
  5411. // else if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0) || WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1))
  5412. // {
  5413. // var robotWafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, 0) ? 0 : 1);
  5414. // if (robotWafer != null && !robotWafer.IsEmpty && robotWafer.ProcessJob != null &&
  5415. // robotWafer.ProcessJob.Sequence != null || robotWafer.ProcessJob.Sequence.Steps != null && robotWafer.ProcessJob.Sequence.Steps.Count > 0)
  5416. // {
  5417. // stepModules = robotWafer.ProcessJob.Sequence.Steps[robotWafer.NextSequenceStep].StepModules;
  5418. // if (stepModules != null && stepModules.Count > 0)
  5419. // {
  5420. // if (stepModules.Contains(aligner))
  5421. // {
  5422. // count++;
  5423. // }
  5424. // }
  5425. // }
  5426. // }
  5427. // return count - waferCount > 0;
  5428. //}
  5429. //private bool CheckWaferCanPick(WaferInfo wafer)
  5430. //{
  5431. // if (wafer == null || wafer.IsEmpty || wafer.ProcessJob == null ||
  5432. // wafer.ProcessJob.Sequence == null || wafer.ProcessJob.Sequence.Steps == null || wafer.ProcessJob.Sequence.Steps.Count == 0)
  5433. // return false;
  5434. // var stepModules = wafer.ProcessJob.Sequence.Steps[wafer.NextSequenceStep + 1].StepModules;
  5435. // int count = 0;
  5436. // int waferCount = 0;
  5437. // if (stepModules == null || stepModules.Count == 0)
  5438. // {
  5439. // return false;
  5440. // }
  5441. // if (WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 0) && WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, 1))
  5442. // {
  5443. // count++;
  5444. // }
  5445. // return count - waferCount > 0;
  5446. //}
  5447. private SlotItem GetWaferReturnLoadPort(ModuleName module, int slot)
  5448. {
  5449. WaferInfo wafer = WaferManager.Instance.GetWafer(module, slot);
  5450. if (!wafer.IsEmpty)
  5451. {
  5452. return new SlotItem((ModuleName)wafer.OriginStation, wafer.OriginSlot);
  5453. }
  5454. return null;
  5455. }
  5456. private bool CheckSequenceRobotSlotEnable(bool blade1Enable, bool blade2Enable, string slotSelection, string title, out string errorMsg)
  5457. {
  5458. errorMsg = string.Empty;
  5459. if(!string.IsNullOrWhiteSpace(slotSelection))
  5460. {
  5461. var dic = new Dictionary<int, bool>() { { 0, blade1Enable }, { 1, blade2Enable } };
  5462. var pos = new string[] { "lower", "upper" };
  5463. foreach (var index in dic.Keys)
  5464. {
  5465. if (slotSelection.Contains(index.ToString()) && !dic[index])
  5466. {
  5467. errorMsg = $"{title} {pos[index]} blade is not enabled ";
  5468. return false;
  5469. }
  5470. }
  5471. }
  5472. return true;
  5473. }
  5474. private bool ValidateSequence(string[] seqs, out string reason)
  5475. {
  5476. reason = string.Empty;
  5477. bool isAllSequenceNull = true;
  5478. for (int i = 0; i < seqs.Length; i++)
  5479. {
  5480. if (string.IsNullOrEmpty(seqs[i]))
  5481. continue;
  5482. var sequence = SequenceInfoHelper.GetInfo(seqs[i]);
  5483. if ((sequence == null || sequence.Steps == null || sequence.Steps.Count == 0) && !string.IsNullOrEmpty(sequence.Name))
  5484. {
  5485. reason = $"Invalid sequence {seqs[i]}";
  5486. return false;
  5487. }
  5488. isAllSequenceNull = false;
  5489. foreach (var step in sequence.Steps)
  5490. {
  5491. foreach (var module in step.StepModules)
  5492. {
  5493. if (ModuleHelper.IsEfem(module) || ModuleHelper.IsEfemRobot(module))
  5494. {
  5495. }
  5496. else if (ModuleHelper.IsTM(module) || ModuleHelper.IsTMRobot(module))
  5497. {
  5498. }
  5499. else if (ModuleHelper.IsPm(module))
  5500. {
  5501. string pmInstall = $"System.SetUp.{module}.IsInstalled";
  5502. if (!SC.GetValueOrDefault<bool>(pmInstall))
  5503. {
  5504. reason = $"Invalid sequence {seqs[i]}, {module} is uninstalled";
  5505. return false;
  5506. }
  5507. }
  5508. else if (!SC.GetValueOrDefault<bool>($"System.SetUp.{module}.IsInstalled"))
  5509. {
  5510. reason = $"Invalid sequence {seqs[i]}, {module} is uninstalled";
  5511. return false;
  5512. }
  5513. }
  5514. if (step.StepModules.Any(p => ModuleHelper.IsEfemRobot(p)))
  5515. {
  5516. string slotSelection = step.StepParameter.ContainsKey("SlotSelection") ? step.StepParameter["SlotSelection"].ToString() : string.Empty;
  5517. if(!CheckSequenceRobotSlotEnable(_efem.Blade1Enable, _efem.Blade2Enable, slotSelection, "efem robot", out reason))
  5518. {
  5519. reason = $"Invalid sequence {seqs[i]}, {reason}";
  5520. return false;
  5521. }
  5522. }
  5523. if (step.StepModules.Any(p => ModuleHelper.IsTMRobot(p)))
  5524. {
  5525. string slotSelection = step.StepParameter.ContainsKey("SlotSelection") ? step.StepParameter["SlotSelection"].ToString() : string.Empty;
  5526. if (!CheckSequenceRobotSlotEnable(_tmRobot.Blade1Enable, _tmRobot.Blade2Enable, slotSelection, "tm robot", out reason))
  5527. {
  5528. reason = $"Invalid sequence {seqs[i]}, {reason}";
  5529. return false;
  5530. }
  5531. }
  5532. if (step.StepModules.Any(x => x == ModuleName.Aligner1))
  5533. {
  5534. if (!SC.GetValueOrDefault<bool>("System.SetUp.Aligner1.IsInstalled"))
  5535. {
  5536. reason = $"Invalid sequence {seqs[i]}, Aligner1 is uninstalled";
  5537. return false;
  5538. }
  5539. if (step.AlignAngle < 0 || step.AlignAngle > 360)
  5540. {
  5541. reason = $"Invalid sequence {seqs[i]}, Aligner1 angle parameter is not valid";
  5542. return false;
  5543. }
  5544. }
  5545. if (step.StepModules.Any(x => x == ModuleName.Aligner2))
  5546. {
  5547. if (!SC.GetValueOrDefault<bool>("System.SetUp.Aligner2.IsInstalled"))
  5548. {
  5549. reason = $"Invalid sequence {seqs[i]}, Aligner2 is uninstalled";
  5550. return false;
  5551. }
  5552. if (step.AlignAngle < 0 || step.AlignAngle > 360)
  5553. {
  5554. reason = $"Invalid sequence {seqs[i]}, Aligner2 angle parameter is not valid";
  5555. return false;
  5556. }
  5557. }
  5558. }
  5559. }
  5560. if (isAllSequenceNull)
  5561. {
  5562. reason = $"Invalid sequence, sequence are all null ";
  5563. return false;
  5564. }
  5565. return true;
  5566. }
  5567. private void CalcedThroughput(List<ProcessJobInfo> pjRemoveList)
  5568. {
  5569. int count = 0;
  5570. foreach (var pj in pjRemoveList)
  5571. {
  5572. if (pj.SlotWafers != null)
  5573. {
  5574. foreach (var pjSlotWafer in pj.SlotWafers)
  5575. {
  5576. WaferInfo waferInfo = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  5577. if (waferInfo.ProcessState == EnumWaferProcessStatus.Completed
  5578. && waferInfo.SubstTransStatus == SubstrateTransportStatus.AtDestination)
  5579. {
  5580. count++;
  5581. }
  5582. }
  5583. }
  5584. }
  5585. _throughputData.UpdateCalced(count);
  5586. }
  5587. private void CalcingThroughput()
  5588. {
  5589. if (!_lstControlJobs.Any())
  5590. {
  5591. _throughputData.Pause();
  5592. return;
  5593. }
  5594. if (!_lstControlJobs.Any(x => x.State == EnumControlJobState.Executing))
  5595. {
  5596. _throughputData.Pause();
  5597. return;
  5598. }
  5599. _throughputData.BeginCalc();
  5600. int count = 0;
  5601. foreach (var pj in _lstProcessJobs)
  5602. {
  5603. if(pj.SlotWafers==null)
  5604. {
  5605. continue;
  5606. }
  5607. foreach (var pjSlotWafer in pj.SlotWafers)
  5608. {
  5609. WaferInfo waferInfo = WaferManager.Instance.GetWafer(pjSlotWafer.Item1, pjSlotWafer.Item2);
  5610. if (waferInfo.ProcessState == EnumWaferProcessStatus.Completed
  5611. && waferInfo.SubstTransStatus == SubstrateTransportStatus.AtDestination)
  5612. {
  5613. count++;
  5614. }
  5615. }
  5616. }
  5617. if (count > _throughputData.CalcingProcessedCount)
  5618. {
  5619. _throughputData.UpdateCalcing(count);
  5620. }
  5621. }
  5622. #endregion
  5623. #region Checked
  5624. public bool CheckCanProcess(ModuleName pmModule)
  5625. {
  5626. var wafer0 = WaferManager.Instance.GetWafer(pmModule, 0);
  5627. var wafer1 = WaferManager.Instance.GetWafer(pmModule, 1);
  5628. bool _PM1Disabled = SC.GetValueOrDefault<bool>($"System.SetUp.{pmModule}Chamber1Disabled.IsInstalled");
  5629. bool _PM2Disabled = SC.GetValueOrDefault<bool>($"System.SetUp.{pmModule}Chamber2Disabled.IsInstalled");
  5630. //如果PM腔体中有wafer,但不需要process,则不允许PM进行Process
  5631. if (!wafer0.IsEmpty && !CheckWaferNeedProcessBySlot(pmModule, 0, pmModule,0))
  5632. {
  5633. return false;
  5634. }
  5635. if (!wafer1.IsEmpty && !CheckWaferNeedProcessBySlot(pmModule, 1, pmModule,1))
  5636. {
  5637. return false;
  5638. }
  5639. //如果PM腔体中两片wafer都需要Process,并且recipe名字相同,则允许process
  5640. if (CheckWaferNeedProcessBySlot(pmModule, 0, pmModule,0)
  5641. && CheckWaferNeedProcessBySlot(pmModule, 1, pmModule,1)
  5642. && wafer0.ProcessJob.Sequence.Name == wafer1.ProcessJob.Sequence.Name)
  5643. {
  5644. return true;
  5645. }
  5646. //如果PM腔体中只有一片wafer需要Process,并且LLA/LLB/TMRobot中找不到相同SequenceName的wafer时,允许process
  5647. if (CheckWaferNeedProcessBySlot(pmModule, 0, pmModule,0))
  5648. {
  5649. var pmWafer = WaferManager.Instance.GetWafer(pmModule, 0);
  5650. if (pmWafer.ProcessJob != null)
  5651. {
  5652. if (_PM2Disabled)
  5653. return true;
  5654. if (GetSameSequenceUnprocessedWaferCount(new List<ModuleName>(_lstLls.Select(p=>p.Module)) { ModuleName.TMRobot }, pmWafer.ProcessJob.Sequence.Name, pmModule, 1) == 0)
  5655. return true;
  5656. if (CheckUnprocessedWaferByStation(pmModule, 1,pmWafer))
  5657. return true;
  5658. }
  5659. }
  5660. if (CheckWaferNeedProcessBySlot(pmModule, 1, pmModule,1))
  5661. {
  5662. var pmWafer = WaferManager.Instance.GetWafer(pmModule, 1);
  5663. if (pmWafer.ProcessJob != null)
  5664. {
  5665. if (_PM1Disabled)
  5666. return true;
  5667. if (GetSameSequenceUnprocessedWaferCount(new List<ModuleName>(_lstLls.Select(p => p.Module)) { ModuleName.TMRobot }, pmWafer.ProcessJob.Sequence.Name, pmModule, 0) == 0)
  5668. return true;
  5669. if (CheckUnprocessedWaferByStation(pmModule, 0, pmWafer))
  5670. return true;
  5671. }
  5672. }
  5673. return false;
  5674. }
  5675. public bool CheckCanPlaceWaferToPM(ModuleName pmModule, int slot, WaferInfo wafer)
  5676. {
  5677. if (!_tmRobot.IsAvailable)
  5678. return false;
  5679. if (!CheckWaferNeedProcessBySlot(wafer, pmModule, slot))
  5680. return false;
  5681. var wafer0 = WaferManager.Instance.GetWafer(pmModule, 0);
  5682. if (!wafer0.IsEmpty && !CheckWaferNeedProcessBySlot(wafer0, pmModule, 0))
  5683. {
  5684. return false;
  5685. }
  5686. var wafer1 = WaferManager.Instance.GetWafer(pmModule, 1);
  5687. if (!wafer1.IsEmpty && !CheckWaferNeedProcessBySlot(wafer1, pmModule, 1))
  5688. {
  5689. return false;
  5690. }
  5691. if (CheckWaferNeedProcessBySlot(wafer0, pmModule, 0)
  5692. && CheckWaferNeedProcessBySlot(wafer, pmModule, slot)
  5693. && wafer0.ProcessJob.Sequence.Name == wafer.ProcessJob.Sequence.Name)
  5694. return true;
  5695. if (CheckWaferNeedProcessBySlot(wafer1, pmModule, 1)
  5696. && CheckWaferNeedProcessBySlot(wafer, pmModule, slot)
  5697. && wafer1.ProcessJob.Sequence.Name == wafer.ProcessJob.Sequence.Name)
  5698. return true;
  5699. if (wafer0.IsEmpty
  5700. && wafer1.IsEmpty
  5701. && CheckWaferNeedProcessBySlot(wafer, pmModule, slot))
  5702. return true;
  5703. return false;
  5704. }
  5705. public bool CheckCanPickWaferFromPM(ModuleName pmModule, int slot)
  5706. {
  5707. if (!_tmRobot.IsAvailable)
  5708. return false;
  5709. var wafer = WaferManager.Instance.GetWafer(pmModule, slot);
  5710. if (!wafer.IsEmpty
  5711. && wafer.ProcessJob != null
  5712. && wafer.ProcessJob.Sequence != null
  5713. && wafer.ProcessJob.Sequence.Steps != null
  5714. && wafer.ProcessState == EnumWaferProcessStatus.Completed)
  5715. return true;
  5716. return false;
  5717. }
  5718. public int GetSameSequenceUnprocessedWaferCount(List<ModuleName> modules, string sequenceName, ModuleName processIn, int slot)
  5719. {
  5720. int count = 0;
  5721. for (int i = 0; i < modules.Count; i++)
  5722. {
  5723. var wafers = WaferManager.Instance.GetWafers(modules[i]);
  5724. for (int j = 0; j < wafers.Length; j++)
  5725. {
  5726. if (CheckWaferNeedProcessBySlot(wafers[j], processIn, slot)
  5727. && wafers[j].ProcessJob != null
  5728. && wafers[j].ProcessJob.Sequence.Name == sequenceName)
  5729. count++;
  5730. }
  5731. }
  5732. return count;
  5733. }
  5734. public bool CheckUnprocessedWaferByStation(ModuleName processIn, int slot, WaferInfo sourceWafer)
  5735. {
  5736. var modules = new List<ModuleName>() { ModuleName.LP1, ModuleName.LP2, ModuleName.LP3, ModuleName.Aligner1,
  5737. ModuleName.Aligner2, ModuleName.LLA, ModuleName.LLB, ModuleName.TMRobot, ModuleName.EfemRobot };
  5738. modules.Where(p => p != ModuleName.EfemRobot && p != ModuleName.TMRobot && !SC.GetValueOrDefault<bool>($"System.SetUp.{p}.IsInstalled")).ToList()
  5739. .ForEach(p => modules.Remove(p));
  5740. return !modules.Any(p => WaferManager.Instance.GetWafers(p).Any(wafer => CheckWaferNeedProcessBySlot(wafer, processIn, slot)
  5741. && wafer.OriginStation == sourceWafer.OriginStation
  5742. && wafer.ProcessJob != null
  5743. && wafer.ProcessJob.Sequence.Name == sourceWafer.ProcessJob.Sequence.Name));
  5744. }
  5745. public int? GetAvilableLoadLockSlotForEfemRobotPlace(SchedulerLoadLock ll)
  5746. {
  5747. if (!ll.IsAvailable)
  5748. return null;
  5749. var wafers = WaferManager.Instance.GetWafers(ll.Module);
  5750. for (int i = 0; i < wafers.Length; i++)
  5751. {
  5752. if (wafers[i].IsEmpty && ll.IsReadyForPlace(ModuleName.TMRobot, Hand.Blade1, i))
  5753. return i;
  5754. }
  5755. return null;
  5756. }
  5757. public List<int> GetAvilableLoadLockSlotForTMRobotPlace(Hand blade, SchedulerLoadLock ll)
  5758. {
  5759. if (!ll.IsAvailable)
  5760. return null;
  5761. var wafers = WaferManager.Instance.GetWafers(ll.Module);
  5762. var waferLen = wafers.Length;
  5763. for (int i = 0; i < waferLen; i++)
  5764. {
  5765. var slots = TryGetPairSlot(i);
  5766. if (slots.Count > 0 && slots.All(p => wafers[i].IsEmpty && ll.IsReadyForPlace(ModuleName.TMRobot, blade, p)))
  5767. return slots;
  5768. }
  5769. return null;
  5770. }
  5771. //public int? GetAvilableLoadLockSlotForTMRobotPick(SchedulerLoadLock ll)
  5772. //{
  5773. // if (!ll.IsAvailable)
  5774. // return null;
  5775. // var wafers = WaferManager.Instance.GetWafers(ll.Module);
  5776. // foreach (var pm in _lstPms)
  5777. // {
  5778. // var pmWafer0 = WaferManager.Instance.GetWafer(pm.Module, 0);
  5779. // var pmWafer1 = WaferManager.Instance.GetWafer(pm.Module, 1);
  5780. // //如果腔体中两片都满了,则跳过
  5781. // if (!pmWafer0.IsEmpty && !pmWafer1.IsEmpty)
  5782. // continue;
  5783. // //如果腔体中两片都为空,则取一片放入
  5784. // if (pmWafer0.IsEmpty && pmWafer1.IsEmpty)
  5785. // {
  5786. // for (int i = 0; i < wafers.Length; i++)
  5787. // {
  5788. // if (!wafers[i].IsEmpty
  5789. // && ll.IsReadyForPick(ModuleName.TMRobot, Hand.Blade1, i)
  5790. // && CheckWaferNeedProcess(ll.Module, i))
  5791. // return i;
  5792. // }
  5793. // }
  5794. // //如果腔体中一片为空,则取一片相同recipeName的放入
  5795. // if (!pmWafer0.IsEmpty || !pmWafer1.IsEmpty)
  5796. // {
  5797. // var wafer = !pmWafer0.IsEmpty ? pmWafer0 : pmWafer1;
  5798. // if (!CheckWaferNeedProcess(wafer))
  5799. // return null;
  5800. // var tmWafers = WaferManager.Instance.GetWafers(ModuleName.TMRobot);
  5801. // //判断TMRobot是否已经存在相同recipeName的wafer
  5802. // for (int i = 0; i < tmWafers.Length; i++)
  5803. // {
  5804. // if (CheckWaferNeedProcess(tmWafers[i])
  5805. // && tmWafers[i].ProcessJob.Sequence.Name == wafer.ProcessJob.Sequence.Name)
  5806. // return null;
  5807. // }
  5808. // for (int i = 0; i < wafers.Length; i++)
  5809. // {
  5810. // if (!wafers[i].IsEmpty
  5811. // && ll.IsReadyForPick(ModuleName.TMRobot, Hand.Blade1, i)
  5812. // && CheckWaferNeedProcess(ll.Module, i)
  5813. // && wafers[i].ProcessJob.Sequence.Name == wafer.ProcessJob.Sequence.Name)
  5814. // return i;
  5815. // }
  5816. // }
  5817. // }
  5818. // return null;
  5819. //}
  5820. //public List<Tuple<SchedulerLoadLock, int>> GetAvilableLoadLockSlotForTMRobotPick()
  5821. //{
  5822. // List<Tuple<SchedulerLoadLock, int>> result = new List<Tuple<SchedulerLoadLock, int>>();
  5823. // foreach (var ll in _lstLls)
  5824. // {
  5825. // if (!ll.IsAvailable)
  5826. // continue;
  5827. // var wafers = WaferManager.Instance.GetWafers(ll.Module);
  5828. // foreach (var pm in _lstPms)
  5829. // {
  5830. // var pmWafer0 = WaferManager.Instance.GetWafer(pm.Module, 0);
  5831. // var pmWafer1 = WaferManager.Instance.GetWafer(pm.Module, 1);
  5832. // //如果腔体中两片都满了,则跳过
  5833. // if (!pmWafer0.IsEmpty && !pmWafer1.IsEmpty)
  5834. // continue;
  5835. // //如果腔体中两片都为空,则取一片放入
  5836. // if (pmWafer0.IsEmpty && pmWafer1.IsEmpty)
  5837. // {
  5838. // for (int i = 0; i < wafers.Length; i++)
  5839. // {
  5840. // if (!wafers[i].IsEmpty
  5841. // && ll.IsReadyForPick(ModuleName.TMRobot, Hand.Blade1, i)
  5842. // && CheckWaferNeedProcess(ll.Module, i, pm.Module)
  5843. // && !result.Exists(x => x.Item1 == ll && x.Item2 == i))
  5844. // result.Add(new Tuple<SchedulerLoadLock, int>(ll, i));
  5845. // }
  5846. // }
  5847. // //如果腔体中一片为空,则取一片相同recipeName的放入
  5848. // if (!pmWafer0.IsEmpty || !pmWafer1.IsEmpty)
  5849. // {
  5850. // var wafer = !pmWafer0.IsEmpty ? pmWafer0 : pmWafer1;
  5851. // if (!CheckWaferNeedProcess(wafer))
  5852. // continue;
  5853. // var tmWafers = WaferManager.Instance.GetWafers(ModuleName.TMRobot);
  5854. // //判断TMRobot是否已经存在相同recipeName的wafer
  5855. // for (int i = 0; i < tmWafers.Length; i++)
  5856. // {
  5857. // if (CheckWaferNeedProcess(tmWafers[i])
  5858. // && tmWafers[i].ProcessJob.Sequence.Name == wafer.ProcessJob.Sequence.Name)
  5859. // continue;
  5860. // }
  5861. // for (int i = 0; i < wafers.Length; i++)
  5862. // {
  5863. // if (!wafers[i].IsEmpty
  5864. // && ll.IsReadyForPick(ModuleName.TMRobot, Hand.Blade1, i)
  5865. // && CheckWaferNeedProcess(ll.Module, i, pm.Module)
  5866. // && wafers[i].ProcessJob.Sequence.Name == wafer.ProcessJob.Sequence.Name
  5867. // && !result.Exists(x => x.Item1 == ll && x.Item2 == i))
  5868. // result.Add(new Tuple<SchedulerLoadLock, int>(ll, i));
  5869. // }
  5870. // }
  5871. // }
  5872. // }
  5873. // return result;
  5874. //}
  5875. public List<Tuple<SchedulerLoadLock, int>> FindAllLoadLockSlotForTMRobotPick()
  5876. {
  5877. List<Tuple<SchedulerLoadLock, int>> result = new List<Tuple<SchedulerLoadLock, int>>();
  5878. foreach (var ll in _lstLls)
  5879. {
  5880. var wafers = WaferManager.Instance.GetWafers(ll.Module);
  5881. foreach (var pm in _lstPms)
  5882. {
  5883. var pmWafer0 = WaferManager.Instance.GetWafer(pm.Module, 0);
  5884. var pmWafer1 = WaferManager.Instance.GetWafer(pm.Module, 1);
  5885. if(pm.IsError) continue;
  5886. //如果腔体中两片都满了,则跳过
  5887. if (!pmWafer0.IsEmpty && !pmWafer1.IsEmpty && !SC.IsDoubleFork)
  5888. continue;
  5889. bool blade1EmptyAndEnable = _tmRobot.Blade1Enable && Converter.MapBladeToSlots(Hand.Blade1).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p));
  5890. bool blade2EmptyAndEnable = _tmRobot.Blade2Enable && Converter.MapBladeToSlots(Hand.Blade2).All(p => WaferManager.Instance.CheckNoWafer(ModuleName.TMRobot, p));
  5891. //如果腔体中两片都为空
  5892. if ((pmWafer0.IsEmpty && pmWafer1.IsEmpty) ||
  5893. (SC.IsDoubleFork && blade1EmptyAndEnable && blade2EmptyAndEnable))
  5894. {
  5895. if (SC.IsDoubleFork && pm.Module == ModuleName.PMA && (_PMA1Disabled || _PMA2Disabled)) continue;
  5896. if (SC.IsDoubleFork && pm.Module == ModuleName.PMB && (_PMB1Disabled || _PMB2Disabled)) continue;
  5897. for (int i = 0; i < wafers.Length; i++)
  5898. {
  5899. if (!wafers[i].IsEmpty
  5900. && ll.IsReadyForPick(ModuleName.TMRobot, Hand.Blade1, i)
  5901. && (CheckWaferNeedProcessBySlot(ll.Module, i, pm.Module, 0) || CheckWaferNeedProcessBySlot(ll.Module, i, pm.Module, 1))
  5902. && !result.Exists(x => x.Item1 == ll && x.Item2 == i))
  5903. result.Add(new Tuple<SchedulerLoadLock, int>(ll, i));
  5904. }
  5905. }
  5906. if (SC.IsDoubleFork) continue;
  5907. if (pm.Module == ModuleName.PMA && !pmWafer0.IsEmpty && _PMA2Disabled)
  5908. {
  5909. continue;
  5910. }
  5911. if (pm.Module == ModuleName.PMA && !pmWafer1.IsEmpty && _PMA1Disabled)
  5912. {
  5913. continue;
  5914. }
  5915. if (pm.Module == ModuleName.PMB && !pmWafer0.IsEmpty && _PMB2Disabled)
  5916. {
  5917. continue;
  5918. }
  5919. if (pm.Module == ModuleName.PMB && !pmWafer1.IsEmpty && _PMB1Disabled)
  5920. {
  5921. continue;
  5922. }
  5923. //如果腔体中一片为空,则取一片相同recipeName的放入
  5924. if (!pmWafer0.IsEmpty)
  5925. {
  5926. var wafer = !pmWafer0.IsEmpty ? pmWafer0 : pmWafer1;
  5927. if (!CheckWaferNeedProcessBySlot(wafer, pm.Module, 1))
  5928. continue;
  5929. var tmWafers = WaferManager.Instance.GetWafers(ModuleName.TMRobot);
  5930. //判断TMRobot是否已经存在相同recipeName的wafer
  5931. for (int i = 0; i < tmWafers.Length; i++)
  5932. {
  5933. if (CheckWaferNeedProcessBySlot(tmWafers[i], pm.Module, 1)
  5934. && tmWafers[i].ProcessJob.Sequence.Name == wafer.ProcessJob.Sequence.Name)
  5935. continue;
  5936. }
  5937. for (int i = 0; i < wafers.Length; i++)
  5938. {
  5939. if (!wafers[i].IsEmpty
  5940. && ll.IsReadyForPick(ModuleName.TMRobot, Hand.Blade1, i)
  5941. && CheckWaferNeedProcessBySlot(ll.Module, i, pm.Module, 1)
  5942. && wafers[i].ProcessJob.Sequence.Name == wafer.ProcessJob.Sequence.Name
  5943. && !result.Exists(x => x.Item1 == ll && x.Item2 == i))
  5944. result.Add(new Tuple<SchedulerLoadLock, int>(ll, i));
  5945. }
  5946. }
  5947. if (!pmWafer1.IsEmpty)
  5948. {
  5949. var wafer = !pmWafer0.IsEmpty ? pmWafer0 : pmWafer1;
  5950. if (!CheckWaferNeedProcessBySlot(wafer, pm.Module, 0))
  5951. continue;
  5952. var tmWafers = WaferManager.Instance.GetWafers(ModuleName.TMRobot);
  5953. //判断TMRobot是否已经存在相同recipeName的wafer
  5954. for (int i = 0; i < tmWafers.Length; i++)
  5955. {
  5956. if (CheckWaferNeedProcessBySlot(tmWafers[i], pm.Module, 0)
  5957. && tmWafers[i].ProcessJob.Sequence.Name == wafer.ProcessJob.Sequence.Name)
  5958. continue;
  5959. }
  5960. for (int i = 0; i < wafers.Length; i++)
  5961. {
  5962. if (!wafers[i].IsEmpty
  5963. && ll.IsReadyForPick(ModuleName.TMRobot, Hand.Blade1, i)
  5964. && CheckWaferNeedProcessBySlot(ll.Module, i, pm.Module, 0)
  5965. && wafers[i].ProcessJob.Sequence.Name == wafer.ProcessJob.Sequence.Name
  5966. && !result.Exists(x => x.Item1 == ll && x.Item2 == i))
  5967. result.Add(new Tuple<SchedulerLoadLock, int>(ll, i));
  5968. }
  5969. }
  5970. }
  5971. }
  5972. return result;
  5973. }
  5974. public int GetWaferCountLoadLockToPM(ModuleName pmModule)
  5975. {
  5976. int result = 0;
  5977. foreach (var ll in _lstLls)
  5978. {
  5979. var wafers = WaferManager.Instance.GetWafers(ll.Module);
  5980. foreach (var pm in _lstPms)
  5981. {
  5982. if (pm.Module != pmModule)
  5983. continue;
  5984. for (int i = 0; i < wafers.Length; i++)
  5985. {
  5986. if (!wafers[i].IsEmpty
  5987. && (CheckWaferNeedProcessBySlot(ll.Module, i, pm.Module, 0)
  5988. || CheckWaferNeedProcessBySlot(ll.Module, i, pm.Module, 1)))
  5989. result++;
  5990. }
  5991. }
  5992. }
  5993. return result;
  5994. }
  5995. public bool CheckRecipeUsedInJob(string pathName)
  5996. {
  5997. foreach (var pj in _lstProcessJobs)
  5998. {
  5999. var seq = pj.Sequence;
  6000. for (int i = 0; i < seq.Steps.Count; i++)
  6001. {
  6002. SequenceStepInfo stepInfo = seq.Steps[i];
  6003. foreach (var module in stepInfo.StepModules)
  6004. {
  6005. if (ModuleHelper.IsPm(module))
  6006. {
  6007. string attr = module == ModuleName.PMA ? "PMARecipe" : "PMBRecipe";
  6008. if (stepInfo.StepParameter.ContainsKey(attr)
  6009. && !string.IsNullOrEmpty((string)stepInfo.StepParameter[attr]))
  6010. {
  6011. var recipeName = (string)stepInfo.StepParameter[attr];
  6012. if (!string.IsNullOrEmpty(recipeName))
  6013. {
  6014. if (pathName.EndsWith(recipeName + ".rcp"))
  6015. return true;
  6016. }
  6017. }
  6018. }
  6019. }
  6020. }
  6021. }
  6022. return false;
  6023. }
  6024. public bool CheckSequenceUsedInJob(string pathName)
  6025. {
  6026. foreach (var pj in _lstProcessJobs)
  6027. {
  6028. if (pathName.EndsWith(pj.Sequence.Name + ".seq"))
  6029. return true;
  6030. }
  6031. return false;
  6032. }
  6033. private bool CheckHasWaferAndNextStepIsLoadLock(Hand hand)
  6034. {
  6035. var forkSlots = new int[] { (int)hand, ((int)hand) + 2 };
  6036. var sourceSlots = new List<int>();
  6037. foreach (var forkSlot in forkSlots)
  6038. {
  6039. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, forkSlot);
  6040. if (wafer != null && !wafer.IsEmpty) sourceSlots.Add(forkSlot);
  6041. }
  6042. return sourceSlots.Count() > 0 && sourceSlots.All(p => CheckWaferNextStepIsLoadLock(ModuleName.TMRobot, p));
  6043. }
  6044. private List<int> TryGetPairSlot(int sourceSlot)
  6045. {
  6046. if (SC.IsDoubleFork)
  6047. {
  6048. var targetSlots = new List<int>() { sourceSlot, (sourceSlot % 2 > 0) ? sourceSlot - 1 : sourceSlot + 1 };
  6049. targetSlots.Sort();
  6050. return targetSlots;
  6051. }
  6052. return new List<int>() { sourceSlot };
  6053. }
  6054. private int GetNoNeedProcessInLoadLock(SchedulerLoadLock ll)
  6055. {
  6056. int count = 0;
  6057. if (!ll.IsOnline)
  6058. return count;
  6059. var wafers = WaferManager.Instance.GetWafers(ll.Module);
  6060. for (int i = 0; i < wafers.Length; i++)
  6061. {
  6062. if (wafers[i] != null && !wafers[i].IsEmpty && !CheckWaferNeedProcess(ll.Module, i)) count++;
  6063. }
  6064. return count;
  6065. }
  6066. private SchedulerPM GetExistSwapPM()
  6067. {
  6068. SchedulerPM swapPm = null;
  6069. if (!SC.IsDoubleFork) return swapPm;
  6070. foreach(var pm in _lstPms)
  6071. {
  6072. if(IsExistSwap(pm.Module,0) &&
  6073. (swapPm == null || (swapPm != null && (pm.WaferArriveTicks[0] < swapPm.WaferArriveTicks[0]))))
  6074. {
  6075. swapPm = pm;
  6076. }
  6077. }
  6078. return swapPm;
  6079. }
  6080. private bool CheckLLSlotForSwap(ModuleName llModule, params int[] llSlots)
  6081. {
  6082. var swapPm = GetExistSwapPM();
  6083. if (swapPm == null) return true;
  6084. return llSlots.Any(p => _pmSlots.Any(s => CheckWaferNeedProcessBySlot(llModule, p, swapPm.Module, s)));
  6085. }
  6086. private bool IsExistSwap(ModuleName pm, int pmSlot)
  6087. {
  6088. if (!_pmSwapWaitTimeOut[pm].Item2.IsTimeout() && SC.IsDoubleFork &&
  6089. _tmRobot.Blade1Enable && _tmRobot.Blade2Enable &&
  6090. _lstPms.Sum(p => WaferManager.Instance.GetWafers(p.Module).Where(m => !m.IsEmpty).Count()) > 3 &&
  6091. CheckCanPickWaferFromPM(pm, pmSlot))
  6092. {
  6093. _pmSwapWaitTimeOut[pm].Item1.CLK = _lstLls.Any(ll => _llSlots.Any(s => WaferManager.Instance.CheckHasWafer(ll.Module, s) &&
  6094. CheckWaferNeedProcessBySlot(ll.Module, s, pm, pmSlot)));
  6095. if (_pmSwapWaitTimeOut[pm].Item1.Q) _pmSwapWaitTimeOut[pm].Item2.Start(2000);
  6096. return _pmSwapWaitTimeOut[pm].Item1.CLK;
  6097. }
  6098. return false;
  6099. }
  6100. private void ResetPmSwapWaitTimeOut(ModuleName pm)
  6101. {
  6102. _pmSwapWaitTimeOut[pm].Item1.RST = true;
  6103. _pmSwapWaitTimeOut[pm].Item2.Stop();
  6104. }
  6105. private Tuple<SchedulerLoadLock, List<int>> FindPairSlotInLL(List<Tuple<SchedulerLoadLock, int>> llSlots)
  6106. {
  6107. var newLLSlot = new List<Tuple<SchedulerLoadLock, int>>();
  6108. newLLSlot.AddRange(llSlots);
  6109. newLLSlot.Sort(LoadLockComparison);
  6110. for (var i = 0; i < llSlots.Count; i++)
  6111. {
  6112. var selectSlot = GetWaferOrderInJobQueue(newLLSlot);
  6113. if (selectSlot != null && selectSlot.Item1.IsAvailable)
  6114. {
  6115. int pickSlot = selectSlot.Item2;
  6116. var pairSlot = TryGetPairSlot(pickSlot);
  6117. if (pairSlot.Count > 1 &&
  6118. pairSlot.All(slot => llSlots.FirstOrDefault(p => p.Item1.Module == selectSlot.Item1.Module && p.Item2 == slot) != null) &&
  6119. CheckLLSlotForSwap(selectSlot.Item1.Module, pairSlot.ToArray()))
  6120. {
  6121. return new Tuple<SchedulerLoadLock, List<int>>(selectSlot.Item1, pairSlot);
  6122. }
  6123. else
  6124. {
  6125. if (CheckLLSlotForSwap(selectSlot.Item1.Module, selectSlot.Item2) &&
  6126. (!SC.IsDoubleFork || !CheckSequenceNameAndNeedProcess(WaferManager.Instance.GetWafer(selectSlot.Item1.Module, selectSlot.Item2).ProcessJob.Sequence.Name)))
  6127. {
  6128. return new Tuple<SchedulerLoadLock, List<int>>(selectSlot.Item1, new List<int>() { selectSlot.Item2 });
  6129. }
  6130. }
  6131. newLLSlot.Remove(selectSlot);
  6132. }
  6133. }
  6134. return null;
  6135. }
  6136. private int LoadLockComparison(Tuple<SchedulerLoadLock, int> x, Tuple<SchedulerLoadLock, int> y)
  6137. {
  6138. return (int)(x.Item1.WaferArriveTicks[x.Item2] - y.Item1.WaferArriveTicks[y.Item2]);
  6139. }
  6140. private Tuple<SchedulerLoadLock, List<int>> FindSingleSlotInLL(List<Tuple<SchedulerLoadLock, int>> llSlots)
  6141. {
  6142. var newLLSlot = new List<Tuple<SchedulerLoadLock, int>>();
  6143. newLLSlot.AddRange(llSlots);
  6144. for (var i = 0; i < llSlots.Count; i++)
  6145. {
  6146. Tuple<SchedulerLoadLock, int> selectSlot = GetWaferOrderInJobQueue(newLLSlot);
  6147. if (selectSlot != null)
  6148. {
  6149. SchedulerLoadLock ll = selectSlot.Item1;
  6150. if (!ll.IsAvailable)
  6151. return null;
  6152. if(CheckLLSlotForSwap(selectSlot.Item1.Module, selectSlot.Item2) &&
  6153. !CheckSequenceNameAndNeedProcess(WaferManager.Instance.GetWafer(ll.Module,selectSlot.Item2).ProcessJob.Sequence.Name))
  6154. {
  6155. return new Tuple<SchedulerLoadLock, List<int>>(ll, new List<int>() { selectSlot.Item2 });
  6156. }
  6157. newLLSlot.Remove(selectSlot);
  6158. }
  6159. }
  6160. return null;
  6161. }
  6162. private Tuple<SchedulerLoadLock, List<int>> TryFindLLAndPairSlot(List<Tuple<SchedulerLoadLock, int>> llSlots)//(List<Tuple<SchedulerLoadLock, int>> lists, Tuple<SchedulerLoadLock, int> firstSlot, out int secondSlot)
  6163. {
  6164. if (SC.IsDoubleFork && GetExistSwapPM() == null &&
  6165. _lstPms.Sum(p => WaferManager.Instance.GetWafers(p.Module).Where(m => !m.IsEmpty).Count()) > 3)
  6166. {
  6167. var allSequenceName = _lstPms.SelectMany(p => WaferManager.Instance.GetWafers(p.Module).Where(m => !m.IsEmpty)).Select(w => w.ProcessJob.Sequence.Name);
  6168. if (allSequenceName.GroupBy(p => p).Count() > 1) return null;
  6169. }
  6170. return FindPairSlotInLL(llSlots);
  6171. }
  6172. private bool ExistPairWafer(List<Tuple<SchedulerLoadLock, int>> targetWafers)
  6173. {
  6174. if (targetWafers.Count > 0)
  6175. {
  6176. var targetLLSlots = targetWafers.GroupBy(p => p.Item1);
  6177. var pairSlots = new string[] { "01", "23", "45", "67" };
  6178. foreach (var item in targetLLSlots)
  6179. {
  6180. var slots = string.Join("", item.Select(p => p.Item2).ToArray().OrderBy(p => p));
  6181. if (pairSlots.Any(p => slots.Contains(p)))
  6182. {
  6183. return true;
  6184. }
  6185. }
  6186. }
  6187. return false;
  6188. }
  6189. private bool CheckHasWaferAndNeedProcess(Hand hand)
  6190. {
  6191. var forkSlots = new int[] { (int)hand, ((int)hand) + 2 };
  6192. var sourceSlots = new List<int>();
  6193. foreach (var forkSlot in forkSlots)
  6194. {
  6195. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, forkSlot);
  6196. if (wafer != null && !wafer.IsEmpty) sourceSlots.Add(forkSlot);
  6197. }
  6198. return sourceSlots.Count > 0 && sourceSlots.All(p => CheckWaferNeedProcess(ModuleName.TMRobot, p));
  6199. }
  6200. private int[] GetHasWaferSlotByHand(Hand hand)
  6201. {
  6202. var forkSlots = new int[] { (int)hand, ((int)hand) + 2 };
  6203. var sourceSlots = new List<int>();
  6204. foreach (var forkSlot in forkSlots)
  6205. {
  6206. var wafer = WaferManager.Instance.GetWafer(ModuleName.TMRobot, forkSlot);
  6207. if (wafer != null && !wafer.IsEmpty) sourceSlots.Add(forkSlot);
  6208. }
  6209. return sourceSlots.ToArray();
  6210. }
  6211. private WaferInfo[] GetHandWafers(Hand hand)
  6212. {
  6213. return GetHasWaferSlotByHand(hand).Select(p => WaferManager.Instance.GetWafer(ModuleName.TMRobot, p)).ToArray();
  6214. }
  6215. private List<Hand> CheckCanPlaceWaferToPM(Hand[] sourceHand, ModuleName pm)
  6216. {
  6217. List<Hand> hands = new List<Hand>();
  6218. for (int i = 0; i < sourceHand.Length; i++)
  6219. {
  6220. var wafers = GetHandWafers(sourceHand[i]);
  6221. var pmSlot = wafers.Length > 1 ? new int[] { 0, 1 } : new int[] { 0 };
  6222. if (pmSlot.All(p => CheckCanPlaceWaferToPM(pm, p, wafers[p]))) hands.Add(sourceHand[i]);
  6223. }
  6224. return hands;
  6225. }
  6226. private bool TryFindNeedPairLoadLock(ModuleName root, Hand hand, SchedulerLoadLock curLL)
  6227. {
  6228. var sourceWafer = WaferManager.Instance.GetWafer(root, (int)hand);
  6229. if (sourceWafer == null || sourceWafer.IsEmpty ||
  6230. sourceWafer.ProcessJob == null || sourceWafer.ProcessJob.Sequence == null) return false;
  6231. var targetLL = curLL;
  6232. foreach (var ll in _lstLls)
  6233. {
  6234. if (!_efem.IsAvailable)
  6235. return false;
  6236. if (ll == curLL) continue;
  6237. if (!CheckWaferNextStepIsLoadLock(ModuleName.EfemRobot, (int)hand, ll.Module))
  6238. continue;
  6239. for (int i = 0; i < 6; i++)
  6240. {
  6241. var wafer = WaferManager.Instance.GetWafer(ll.Module, i);
  6242. if (wafer != null && !wafer.IsEmpty &&
  6243. wafer.ProcessJob != null && wafer.ProcessJob.Sequence != null &&
  6244. wafer.ProcessState == EnumWaferProcessStatus.Idle &&
  6245. sourceWafer.ProcessJob.Sequence.Name == wafer.ProcessJob.Sequence.Name
  6246. )
  6247. {
  6248. var nextSlot = (i % 2 > 0) ? i - 1 : i + 1;
  6249. var nextWafer = WaferManager.Instance.GetWafer(ll.Module, nextSlot);
  6250. if (nextWafer != null && !nextWafer.IsEmpty) continue;
  6251. targetLL = ll;
  6252. break;
  6253. }
  6254. }
  6255. }
  6256. return targetLL.Module == curLL.Module;
  6257. }
  6258. private bool CheckSequenceNameAndNeedProcess(string sequenceName)
  6259. {
  6260. foreach (ProcessJobInfo pj in _lstProcessJobs)
  6261. {
  6262. if (pj.State == EnumProcessJobState.Processing || pj.State == EnumProcessJobState.Paused)
  6263. {
  6264. for (int i = 0; i < pj.SlotWafers.Count; ++i)
  6265. {
  6266. WaferInfo wafer = WaferManager.Instance.GetWafer(pj.SlotWafers[i].Item1, pj.SlotWafers[i].Item2);
  6267. if (wafer.IsEmpty)
  6268. continue;
  6269. if (CheckWaferNeedProcess(pj.SlotWafers[i].Item1, pj.SlotWafers[i].Item2) && wafer.ProcessJob.Sequence.Name == sequenceName)
  6270. return true;
  6271. }
  6272. }
  6273. }
  6274. var moduleList = new List<ModuleName>();
  6275. moduleList.Add(ModuleName.EfemRobot);
  6276. moduleList.AddRange(_lstAligners.Select(p => p.Module));
  6277. return moduleList.Any(p => WaferManager.Instance.GetWafers(p).Where(w => !w.IsEmpty).Any(w => CheckWaferNeedProcess(w) && w.ProcessJob.Sequence.Name == sequenceName));
  6278. }
  6279. private bool CheckSequenceNameAndNeedProcess(List<Tuple<SchedulerLoadLock, int>> targetWafers)
  6280. {
  6281. return targetWafers.Count <= 0 || targetWafers.All(p => CheckSequenceNameAndNeedProcess(WaferManager.Instance.GetWafer(p.Item1.Module, p.Item2).ProcessJob.Sequence.Name));
  6282. }
  6283. #endregion
  6284. }
  6285. }