NcdIoLoadPort.cs 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Device.Unit;
  5. using Aitex.Core.RT.Event;
  6. using Aitex.Core.RT.IOCore;
  7. using Aitex.Core.RT.Log;
  8. using Aitex.Core.RT.Routine;
  9. using Aitex.Core.RT.SCCore;
  10. using Aitex.Core.Util;
  11. using Aitex.Sorter.Common;
  12. using MECF.Framework.Common.Communications;
  13. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
  14. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.TDK;
  15. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.TDKB;
  16. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.IO.Ports;
  20. using System.Linq;
  21. using System.Text;
  22. using System.Threading;
  23. using System.Threading.Tasks;
  24. using System.Xml;
  25. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.VCE.BrooksVCE;
  26. using MECF.Framework.Common.SubstrateTrackings;
  27. //namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.NCD
  28. namespace Aitex.Core.RT.Device.Unit
  29. {
  30. public class NcdIoLoadPort:LoadPortBaseDevice
  31. {
  32. public NcdIoLoadPort(string module, XmlElement node, string ioModule = ""):
  33. base(node.GetAttribute("module"), node.GetAttribute("id"))
  34. {
  35. base.Module = node.GetAttribute("module");//string.IsNullOrEmpty(node.GetAttribute("module")) ? module : node.GetAttribute("module");
  36. base.Name = node.GetAttribute("id");
  37. ioModule = node.GetAttribute("ioModule");
  38. _doRecipeSaveCommand = ParseDoNode("DO_RecipeSaveCommand", node, ioModule);
  39. _doRecipeLoadCommand = ParseDoNode("DO_RecipeLoadCommand", node, ioModule);
  40. _doIntialCommand = ParseDoNode("DO_IntialCommand", node, ioModule);
  41. _doResetCommand = ParseDoNode("DO_ResetCommand", node, ioModule);
  42. _doSingleMappingCommand = ParseDoNode("DO_SingleMappingCommand", node, ioModule);
  43. _doLoadLight = ParseDoNode("DO_LoadLight", node, ioModule);
  44. _doUnloadLight = ParseDoNode("DO_UnloadLight", node, ioModule);
  45. _doStatu1Light = ParseDoNode("DO_Statu1Light", node, ioModule);
  46. _doStatu2Light = ParseDoNode("DO_Statu2Light", node, ioModule);
  47. _doLoadCommand = ParseDoNode("DO_LoadCommand", node, ioModule);
  48. _doUnloadCommand = ParseDoNode("DO_UnloadCommand", node, ioModule);
  49. _doMapDisableCommand = ParseDoNode("DO_MapDisableCommand", node, ioModule);
  50. _doMapEnableCommand = ParseDoNode("DO_MapEnableCommand", node, ioModule);
  51. _doClampOnCommand = ParseDoNode("DO_ClampOnCommand", node, ioModule);
  52. _doClampOffCommand = ParseDoNode("DO_ClampOffCommand", node, ioModule);
  53. _doDOCKForwardCommand = ParseDoNode("DO_DOCKForwardCommand", node, ioModule);
  54. _doDOCKHomeCommand = ParseDoNode("DO_DOCKHomeCommand", node, ioModule);
  55. _doLatchOnCommand = ParseDoNode("DO_LatchOnCommand", node, ioModule);
  56. _doLatchOffCommand = ParseDoNode("DO_LatchOffCommand", node, ioModule);
  57. _doDoorCloseCommand = ParseDoNode("DO_DoorCloseCommand", node, ioModule);
  58. _doDoorOpenCommand = ParseDoNode("DO_DoorOpenCommand", node, ioModule);
  59. _doVACOnCommand = ParseDoNode("DO_VACOnCommand", node, ioModule);
  60. _doVACOffCommand = ParseDoNode("DO_VACOffCommand", node, ioModule);
  61. _doVertiaclDownCommand = ParseDoNode("DO_VertiaclDownCommand", node, ioModule);
  62. _doVertiaclUpCommand = ParseDoNode("DO_VertiaclUpCommand", node, ioModule);
  63. _doZtoMAPPINGSTARTPOSI = ParseDoNode("DO_ZtoMAPPINGSTARTPOSI", node, ioModule);
  64. _doZtoMAPPINGENDPOSI = ParseDoNode("DO_ZtoMAPPINGENDPOSI", node, ioModule);
  65. _doMAPIN = ParseDoNode("DO_MAPIN", node, ioModule);
  66. _doMAPOUT = ParseDoNode("DO_MAPOUT", node, ioModule);
  67. _aoSAVECurrentRecipeNumber = ParseAoNode("AO_SAVECurrentRecipeNumber", node, ioModule);
  68. _aoMAPSTAR = ParseAoNode("AO_MAPSTAR", node, ioModule);
  69. _aoMAPEND = ParseAoNode("AO_MAPEND", node, ioModule);
  70. _aoSENSOR = ParseAoNode("AO_SENSOR", node, ioModule);
  71. _aoSLOT = ParseAoNode("AO_SLOT", node, ioModule);
  72. _aoPITCH = ParseAoNode("AO_PITCH", node, ioModule);
  73. _aoPOSITIONRANGE = ParseAoNode("AO_POSITIONRANGE", node, ioModule);
  74. _aoPOSITIONRANGEUPPER = ParseAoNode("AO_POSITIONRANGEUPPER", node, ioModule);
  75. _aoPOSITIONRANGELOWER = ParseAoNode("AO_POSITIONRANGELOWER", node, ioModule);
  76. _aoTHICK = ParseAoNode("AO_THICK", node, ioModule);
  77. _aoTHICKRANGE = ParseAoNode("AO_THICKRANGE", node, ioModule);
  78. _aoOFFSET = ParseAoNode("AO_OFFSET", node, ioModule);
  79. _aoCarrierType = ParseAoNode("AO_CarrierType", node, ioModule);
  80. _aiSlot1MapResult = ParseAiNode("AI_Slot1MapResult", node, ioModule);
  81. _aiSlot2MapResult = ParseAiNode("AI_Slot2MapResult", node, ioModule);
  82. _aiSlot3MapResult = ParseAiNode("AI_Slot3MapResult", node, ioModule);
  83. _aiSlot4MapResult = ParseAiNode("AI_Slot4MapResult", node, ioModule);
  84. _aiSlot5MapResult = ParseAiNode("AI_Slot5MapResult", node, ioModule);
  85. _aiSlot6MapResult = ParseAiNode("AI_Slot6MapResult", node, ioModule);
  86. _aiSlot7MapResult = ParseAiNode("AI_Slot7MapResult", node, ioModule);
  87. _aiSlot8MapResult = ParseAiNode("AI_Slot8MapResult", node, ioModule);
  88. _aiSlot9MapResult = ParseAiNode("AI_Slot9MapResult", node, ioModule);
  89. _aiSlot10MapResult = ParseAiNode("AI_Slot10MapResult", node, ioModule);
  90. _aiSlot11MapResult = ParseAiNode("AI_Slot11MapResult", node, ioModule);
  91. _aiSlot12MapResult = ParseAiNode("AI_Slot12MapResult", node, ioModule);
  92. _aiSlot13MapResult = ParseAiNode("AI_Slot13MapResult", node, ioModule);
  93. _aiSlot14MapResult = ParseAiNode("AI_Slot14MapResult", node, ioModule);
  94. _aiSlot15MapResult = ParseAiNode("AI_Slot15MapResult", node, ioModule);
  95. _aiSlot16MapResult = ParseAiNode("AI_Slot16MapResult", node, ioModule);
  96. _aiSlot17MapResult = ParseAiNode("AI_Slot17MapResult", node, ioModule);
  97. _aiSlot18MapResult = ParseAiNode("AI_Slot18MapResult", node, ioModule);
  98. _aiSlot19MapResult = ParseAiNode("AI_Slot19MapResult", node, ioModule);
  99. _aiSlot20MapResult = ParseAiNode("AI_Slot20MapResult", node, ioModule);
  100. _aiSlot21MapResult = ParseAiNode("AI_Slot21MapResult", node, ioModule);
  101. _aiSlot22MapResult = ParseAiNode("AI_Slot22MapResult", node, ioModule);
  102. _aiSlot23MapResult = ParseAiNode("AI_Slot23MapResult", node, ioModule);
  103. _aiSlot24MapResult = ParseAiNode("AI_Slot24MapResult", node, ioModule);
  104. _aiSlot25MapResult = ParseAiNode("AI_Slot25MapResult", node, ioModule);
  105. _aiWAFERPOSITIONUPPEREDGE_Slot1 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot1", node, ioModule);
  106. _aiWAFERPOSITIONLOWEREDGE_Slot1 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot1", node, ioModule);
  107. _aiWAFERPOSITIONUPPEREDGE_Slot2 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot2", node, ioModule);
  108. _aiWAFERPOSITIONLOWEREDGE_Slot2 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot2", node, ioModule);
  109. _aiWAFERPOSITIONUPPEREDGE_Slot3 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot3", node, ioModule);
  110. _aiWAFERPOSITIONLOWEREDGE_Slot3 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot3", node, ioModule);
  111. _aiWAFERPOSITIONUPPEREDGE_Slot4 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot4", node, ioModule);
  112. _aiWAFERPOSITIONLOWEREDGE_Slot4 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot4", node, ioModule);
  113. _aiWAFERPOSITIONUPPEREDGE_Slot5 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot5", node, ioModule);
  114. _aiWAFERPOSITIONLOWEREDGE_Slot5 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot5", node, ioModule);
  115. _aiWAFERPOSITIONUPPEREDGE_Slot6 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot6", node, ioModule);
  116. _aiWAFERPOSITIONLOWEREDGE_Slot6 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot6", node, ioModule);
  117. _aiWAFERPOSITIONUPPEREDGE_Slot7 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot7", node, ioModule);
  118. _aiWAFERPOSITIONLOWEREDGE_Slot7 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot7", node, ioModule);
  119. _aiWAFERPOSITIONUPPEREDGE_Slot8 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot8", node, ioModule);
  120. _aiWAFERPOSITIONLOWEREDGE_Slot8 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot8", node, ioModule);
  121. _aiWAFERPOSITIONUPPEREDGE_Slot9 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot9", node, ioModule);
  122. _aiWAFERPOSITIONLOWEREDGE_Slot9 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot9", node, ioModule);
  123. _aiWAFERPOSITIONUPPEREDGE_Slot10 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot10", node, ioModule);
  124. _aiWAFERPOSITIONLOWEREDGE_Slot10 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot10", node, ioModule);
  125. _aiWAFERPOSITIONUPPEREDGE_Slot11 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot11", node, ioModule);
  126. _aiWAFERPOSITIONLOWEREDGE_Slot11 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot11", node, ioModule);
  127. _aiWAFERPOSITIONUPPEREDGE_Slot12 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot12", node, ioModule);
  128. _aiWAFERPOSITIONLOWEREDGE_Slot12 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot12", node, ioModule);
  129. _aiWAFERPOSITIONUPPEREDGE_Slot13 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot13", node, ioModule);
  130. _aiWAFERPOSITIONLOWEREDGE_Slot13 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot13", node, ioModule);
  131. _aiWAFERPOSITIONUPPEREDGE_Slot14 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot14", node, ioModule);
  132. _aiWAFERPOSITIONLOWEREDGE_Slot14 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot14", node, ioModule);
  133. _aiWAFERPOSITIONUPPEREDGE_Slot15 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot15", node, ioModule);
  134. _aiWAFERPOSITIONLOWEREDGE_Slot15 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot15", node, ioModule);
  135. _aiWAFERPOSITIONUPPEREDGE_Slot16 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot16", node, ioModule);
  136. _aiWAFERPOSITIONLOWEREDGE_Slot16 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot16", node, ioModule);
  137. _aiWAFERPOSITIONUPPEREDGE_Slot17 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot17", node, ioModule);
  138. _aiWAFERPOSITIONLOWEREDGE_Slot17 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot17", node, ioModule);
  139. _aiWAFERPOSITIONUPPEREDGE_Slot18 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot18", node, ioModule);
  140. _aiWAFERPOSITIONLOWEREDGE_Slot18 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot18", node, ioModule);
  141. _aiWAFERPOSITIONUPPEREDGE_Slot19 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot19", node, ioModule);
  142. _aiWAFERPOSITIONLOWEREDGE_Slot19 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot19", node, ioModule);
  143. _aiWAFERPOSITIONUPPEREDGE_Slot20 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot20", node, ioModule);
  144. _aiWAFERPOSITIONLOWEREDGE_Slot20 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot20", node, ioModule);
  145. _aiWAFERPOSITIONUPPEREDGE_Slot21 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot21", node, ioModule);
  146. _aiWAFERPOSITIONLOWEREDGE_Slot21 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot21", node, ioModule);
  147. _aiWAFERPOSITIONUPPEREDGE_Slot22 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot22", node, ioModule);
  148. _aiWAFERPOSITIONLOWEREDGE_Slot22 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot22", node, ioModule);
  149. _aiWAFERPOSITIONUPPEREDGE_Slot23 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot23", node, ioModule);
  150. _aiWAFERPOSITIONLOWEREDGE_Slot23 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot23", node, ioModule);
  151. _aiWAFERPOSITIONUPPEREDGE_Slot24 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot24", node, ioModule);
  152. _aiWAFERPOSITIONLOWEREDGE_Slot24 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot24", node, ioModule);
  153. _aiWAFERPOSITIONUPPEREDGE_Slot25 = ParseAiNode("AI_WAFERPOSITIONUPPEREDGE_Slot25", node, ioModule);
  154. _aiWAFERPOSITIONLOWEREDGE_Slot25 = ParseAiNode("AI_WAFERPOSITIONLOWEREDGE_Slot25", node, ioModule);
  155. _aiErrorCode = ParseAiNode("AI_ErrorCode", node, ioModule);
  156. _aiLastErrorCode = ParseAiNode("AI_LastErrorCode", node, ioModule);
  157. _aiRECIPE_TYPE_FEEDBACK = ParseAiNode("AI_RECIPE_TYPE_FEEDBACK", node, ioModule);
  158. _diAck_RecieSave = ParseDiNode("DI_Ack_RecieSave", node, ioModule);
  159. _diAck_RecipeLoad = ParseDiNode("DI_Ack_RecipeLoad", node, ioModule);
  160. _diAck_Init = ParseDiNode("DI_Ack_Init", node, ioModule);
  161. _diAck_Reset = ParseDiNode("DI_Ack_Reset", node, ioModule);
  162. _diAck_SingleMap = ParseDiNode("DI_Ack_SingleMap", node, ioModule);
  163. _diAck_HomePos = ParseDiNode("DI_Ack_HomePos", node, ioModule);
  164. _diSensor_Presence = ParseDiNode("DI_Sensor_Presence", node, ioModule);
  165. _diSensor_Placement = ParseDiNode("DI_Sensor_Placement", node, ioModule);
  166. _diSensor_Protrude = ParseDiNode("DI_Sensor_Protrude", node, ioModule);
  167. _diSensor_VerticalDown = ParseDiNode("DI_Sensor_VerticalDown", node, ioModule);
  168. _diAck_Load = ParseDiNode("DI_Ack_Load", node, ioModule);
  169. _diAck_Unload = ParseDiNode("DI_Ack_Unload", node, ioModule);
  170. _diAck_MapDisable = ParseDiNode("DI_Ack_MapDisable", node, ioModule);
  171. _diAck_MapEnable = ParseDiNode("DI_Ack_MapEnable", node, ioModule);
  172. _diAck_ClampOn = ParseDiNode("DI_Ack_ClampOn", node, ioModule);
  173. _diAck_ClampOff = ParseDiNode("DI_Ack_ClampOff", node, ioModule);
  174. _diAck_DockFwd = ParseDiNode("DI_Ack_DockFwd", node, ioModule);
  175. _diAck_DockHome = ParseDiNode("DI_Ack_DockHome", node, ioModule);
  176. _diAck_LatchOn = ParseDiNode("DI_Ack_LatchOn", node, ioModule);
  177. _diAck_LatchOff = ParseDiNode("DI_Ack_LatchOff", node, ioModule);
  178. _diAck_DoorClose = ParseDiNode("DI_Ack_DoorClose", node, ioModule);
  179. _diAck_DoorOpen = ParseDiNode("DI_Ack_DoorOpen", node, ioModule);
  180. _diAck_VacOn = ParseDiNode("DI_Ack_VacOn", node, ioModule);
  181. _diAck_VacOff = ParseDiNode("DI_Ack_VacOff", node, ioModule);
  182. _diAck_VerticalDown = ParseDiNode("DI_Ack_VerticalDown", node, ioModule);
  183. _diAck_VerticalUp = ParseDiNode("DI_Ack_VerticalUp", node, ioModule);
  184. _diAck_ZtoMapStart = ParseDiNode("DI_Ack_ZtoMapStart", node, ioModule);
  185. _diAck_ZtoMapEnd = ParseDiNode("DI_Ack_ZtoMapEnd", node, ioModule);
  186. _diAck_Mapin = ParseDiNode("DI_Ack_Mapin", node, ioModule);
  187. _diAck_MapOut = ParseDiNode("DI_Ack_MapOut", node, ioModule);
  188. _diAck_CmdClear = ParseDiNode("DI_Ack_CmdClear", node, ioModule);
  189. _diAck_E84Disable = ParseDiNode("DI_Ack_E84Disable", node, ioModule);
  190. _diAck_E84Enable = ParseDiNode("DI_Ack_E84Enable", node, ioModule);
  191. _di12MapSensor = ParseDiNode("DI_12MapSensor", node, ioModule);
  192. _di8MapSensor = ParseDiNode("DI_8MapSensor", node, ioModule);
  193. _diSERVOHOME = ParseDiNode("DI_SERVOHOME", node, ioModule);
  194. _diFoupPlacementSensor = ParseDiNode("DI_FoupPlacementSensor", node, ioModule);
  195. _diDoorCheckSensor = ParseDiNode("DI_DoorCheckSensor", node, ioModule);
  196. _diCDASensor = ParseDiNode("DI_CDASensor", node, ioModule);
  197. _diDockHomeSensor = ParseDiNode("DI_DockHomeSensor", node, ioModule);
  198. _diClampOffSensor = ParseDiNode("DI_ClampOffSensor", node, ioModule);
  199. _diPodForwardSensor = ParseDiNode("DI_PodForwardSensor", node, ioModule);
  200. _diClampOnSensor = ParseDiNode("DI_ClampOnSensor", node, ioModule);
  201. _diVACSensor = ParseDiNode("DI_VACSensor", node, ioModule);
  202. _diLatchLockSensor = ParseDiNode("DI_LatchLockSensor", node, ioModule);
  203. _diLatchUnlockSensor = ParseDiNode("DI_LatchUnlockSensor", node, ioModule);
  204. _diDoorOpenSensor = ParseDiNode("DI_DoorOpenSensor", node, ioModule);
  205. _diDoorCloseSensor = ParseDiNode("DI_DoorCloseSensor", node, ioModule);
  206. _diVerticalMiddleSensor = ParseDiNode("DI_VerticalMiddleSensor", node, ioModule);
  207. _diVerticalDownSensor = ParseDiNode("DI_VerticalDownSensor", node, ioModule);
  208. _diOPSwitchButton = ParseDiNode("DI_OPSwitchButton", node, ioModule);
  209. _diMapin = ParseDiNode("DI_Mapin", node, ioModule);
  210. _diMapout = ParseDiNode("DI_Mapout", node, ioModule);
  211. _diProtrudesensor = ParseDiNode("DI_Protrudesensor", node, ioModule);
  212. _diInfoPadA = ParseDiNode("DI_InfoPadA", node, ioModule);
  213. _diInfoPadB = ParseDiNode("DI_InfoPadB", node, ioModule);
  214. _diInfoPadC = ParseDiNode("DI_InfoPadC", node, ioModule);
  215. _diInfoPadD = ParseDiNode("DI_InfoPadD", node, ioModule);
  216. _diServoOn = ParseDiNode("DI_ServoOn", node, ioModule);
  217. _diPresence = ParseDiNode("DI_Presence", node, ioModule);
  218. _diStepError = ParseDiNode("DI_StepError", node, ioModule);
  219. _diServoerror = ParseDiNode("DI_Servoerror", node, ioModule);
  220. _diDoorSafe = ParseDiNode("DI_DoorSafe", node, ioModule);
  221. _diSERVO = ParseDiNode("DI_SERVO", node, ioModule);
  222. _diSTEP = ParseDiNode("DI_STEP", node, ioModule);
  223. _diClampOnCylinder = ParseDiNode("DI_ClampOnCylinder", node, ioModule);
  224. _diClampOffCylinder = ParseDiNode("DI_ClampOffCylinder", node, ioModule);
  225. _diLatchOnCylinder = ParseDiNode("DI_LatchOnCylinder", node, ioModule);
  226. _diLatchOffCylinder = ParseDiNode("DI_LatchOffCylinder", node, ioModule);
  227. _diDoorOpenCylinder = ParseDiNode("DI_DoorOpenCylinder", node, ioModule);
  228. _diDoorCloseCylinder = ParseDiNode("DI_DoorCloseCylinder", node, ioModule);
  229. _diSERVOCLEAR1 = ParseDiNode("DI_SERVOCLEAR1", node, ioModule);
  230. _diSERVOON1 = ParseDiNode("DI_SERVOON1", node, ioModule);
  231. _diD3UBIN = ParseDiNode("DI_D3UBIN", node, ioModule);
  232. _diMapForwardCylinder = ParseDiNode("DI_MapForwardCylinder", node, ioModule);
  233. _diSERVOCLEAR2 = ParseDiNode("DI_SERVOCLEAR2", node, ioModule);
  234. _diSERVOON2 = ParseDiNode("DI_SERVOON2", node, ioModule);
  235. _diSERVOCLCOUNT = ParseDiNode("DI_SERVOCLCOUNT", node, ioModule);
  236. _diVAC = ParseDiNode("DI_VAC", node, ioModule);
  237. _diSERVOBRAKE = ParseDiNode("DI_SERVOBRAKE", node, ioModule);
  238. _diLoadLight = ParseDiNode("DI_LoadLight", node, ioModule);
  239. _diUnloadLight = ParseDiNode("DI_UnloadLight", node, ioModule);
  240. _diPOWERLIGHT = ParseDiNode("DI_POWERLIGHT", node, ioModule);
  241. _diFoupPlacementLight = ParseDiNode("DI_FoupPlacementLight", node, ioModule);
  242. _diFoupPresenceLight = ParseDiNode("DI_FoupPresenceLight", node, ioModule);
  243. _diAlarmOccurLight = ParseDiNode("DI_AlarmOccurLight", node, ioModule);
  244. _diStatu1Light = ParseDiNode("DI_Statu1Light", node, ioModule);
  245. _diStatu2Light = ParseDiNode("DI_Statu2Light", node, ioModule);
  246. WaferManager.Instance.SubscribeLocation(LPModuleName, ValidSlotsNumber);
  247. SubscribeData();
  248. SubscribeEventAndAlarm();
  249. IsMapWaferByLoadPort = true;
  250. _carrierArrived = new R_TRIG();
  251. _errorOccurredTrig = new R_TRIG();
  252. _lastErrorOccurredTrig = new R_TRIG();
  253. _alarmWaferProtrudeTrig = new R_TRIG();
  254. _thread = new PeriodicJob(10, OnTimer, $"{Module}.{Name} MonitorHandler", true);
  255. }
  256. protected override void SubscribeWaferPosition()
  257. {
  258. }
  259. public string[] AlarmNcdLoadPortErrors;
  260. public string[] AlarmNcdLoadPortLastErrors;
  261. private void SubscribeEventAndAlarm()
  262. {
  263. AlarmNcdLoadPortErrors = new string[73];
  264. for(int i=0;i<73;i++)
  265. {
  266. AlarmNcdLoadPortErrors[i] = "Ncd " + LPModuleName.ToString() + "Error" + (i + 1).ToString();
  267. EV.Subscribe(new EventItem(64000 + (((int)LPModuleName-1) *100) + i+1, "Alarm", AlarmNcdLoadPortErrors[i], $"Load Port {Name} occurred error, D2801 error code is {i+1}.", EventLevel.Alarm, EventType.EventUI_Notify));
  268. }
  269. AlarmNcdLoadPortLastErrors = new string[29];
  270. for (int i = 0; i < 29; i++)
  271. {
  272. AlarmNcdLoadPortLastErrors[i] = "Ncd " + LPModuleName.ToString() + "LastError" + (i + 1).ToString();
  273. EV.Subscribe(new EventItem("Alarm", AlarmNcdLoadPortLastErrors[i], $"Load Port {Name} occurred error, D2802 error code is {i + 1}.", EventLevel.Alarm, EventType.EventUI_Notify));
  274. }
  275. EV.Subscribe(new EventItem("Alarm", AlarmLoadPortLoadRecipeFailed, $"Load Port {Name} load recipe Timeout.", EventLevel.Alarm, EventType.EventUI_Notify));
  276. }
  277. private string AlarmLoadPortLoadRecipeFailed
  278. {
  279. get => LPModuleName.ToString() + "LoadRecipeFailed";
  280. }
  281. private void SubscribeData()
  282. {
  283. DATA.Subscribe($"{Module}.{Name}.SystemStatus", () => CurrentState.ToString());
  284. DATA.Subscribe($"{Module}.{Name}.Mode", () => Mode.ToString());
  285. DATA.Subscribe($"{Module}.{Name}.InitPosMovement", () => InitPosMovement.ToString());
  286. DATA.Subscribe($"{Module}.{Name}.OperationStatus", () => OperationStatus.ToString());
  287. DATA.Subscribe($"{Module}.{Name}.ErrorCode", () => ErrorCode.ToString());
  288. DATA.Subscribe($"{Module}.{Name}.ContainerStatus", () => ContainerStatus.ToString());
  289. DATA.Subscribe($"{Module}.{Name}.ClampPosition", () => ClampPosition.ToString());
  290. DATA.Subscribe($"{Module}.{Name}.LPDoorLatchPosition", () => LPDoorLatchPosition.ToString());
  291. DATA.Subscribe($"{Module}.{Name}.VacuumStatus", () => VacuumStatus.ToString());
  292. DATA.Subscribe($"{Module}.{Name}.LPDoorState", () => LPDoorState.ToString());
  293. DATA.Subscribe($"{Module}.{Name}.WaferProtrusion", () => WaferProtrusion.ToString());
  294. DATA.Subscribe($"{Module}.{Name}.ElevatorAxisPosition", () => ElevatorAxisPosition.ToString());
  295. DATA.Subscribe($"{Module}.{Name}.MapperPostion", () => MapperPostion.ToString());
  296. DATA.Subscribe($"{Module}.{Name}.MappingStatus", () => MappingStatus.ToString());
  297. DATA.Subscribe($"{Module}.{Name}.Model", () => Model.ToString());
  298. DATA.Subscribe($"{Module}.{Name}.IsFosbModeActual", () => IsFosbModeActual.ToString());
  299. DATA.Subscribe($"{Module}.{Name}.DockPosition", () => DockPosition.ToString());
  300. DATA.Subscribe($"{Name}.SystemStatus", () => CurrentState.ToString());
  301. DATA.Subscribe($"{Name}.Mode", () => Mode.ToString());
  302. DATA.Subscribe($"{Name}.InitPosMovement", () => InitPosMovement.ToString());
  303. DATA.Subscribe($"{Name}.OperationStatus", () => OperationStatus.ToString());
  304. DATA.Subscribe($"{Name}.ErrorCode", () => ErrorCode.ToString());
  305. DATA.Subscribe($"{Name}.ContainerStatus", () => ContainerStatus.ToString());
  306. DATA.Subscribe($"{Name}.ClampPosition", () => ClampPosition.ToString());
  307. DATA.Subscribe($"{Name}.LPDoorLatchPosition", () => LPDoorLatchPosition.ToString());
  308. DATA.Subscribe($"{Name}.VacuumStatus", () => VacuumStatus.ToString());
  309. DATA.Subscribe($"{Name}.LPDoorState", () => LPDoorState.ToString());
  310. DATA.Subscribe($"{Name}.WaferProtrusion", () => WaferProtrusion.ToString());
  311. DATA.Subscribe($"{Name}.ElevatorAxisPosition", () => ElevatorAxisPosition.ToString());
  312. DATA.Subscribe($"{Name}.MapperPostion", () => MapperPostion.ToString());
  313. DATA.Subscribe($"{Name}.MappingStatus", () => MappingStatus.ToString());
  314. DATA.Subscribe($"{Name}.Model", () => Model.ToString());
  315. DATA.Subscribe($"{Name}.IsFosbModeActual", () => IsFosbModeActual.ToString());
  316. DATA.Subscribe($"{Name}.DockPosition", () => DockPosition.ToString());
  317. }
  318. private PeriodicJob _thread;
  319. private DOAccessor _doRecipeSaveCommand;
  320. private DOAccessor _doRecipeLoadCommand;
  321. private DOAccessor _doIntialCommand;
  322. private DOAccessor _doResetCommand;
  323. private DOAccessor _doSingleMappingCommand;
  324. private DOAccessor _doLoadLight;
  325. private DOAccessor _doUnloadLight;
  326. private DOAccessor _doStatu1Light;
  327. private DOAccessor _doStatu2Light;
  328. private DOAccessor _doLoadCommand;
  329. private DOAccessor _doUnloadCommand;
  330. private DOAccessor _doMapDisableCommand;
  331. private DOAccessor _doMapEnableCommand;
  332. private DOAccessor _doClampOnCommand;
  333. private DOAccessor _doClampOffCommand;
  334. private DOAccessor _doDOCKForwardCommand;
  335. private DOAccessor _doDOCKHomeCommand;
  336. private DOAccessor _doLatchOnCommand;
  337. private DOAccessor _doLatchOffCommand;
  338. private DOAccessor _doDoorCloseCommand;
  339. private DOAccessor _doDoorOpenCommand;
  340. private DOAccessor _doVACOnCommand;
  341. private DOAccessor _doVACOffCommand;
  342. private DOAccessor _doVertiaclDownCommand;
  343. private DOAccessor _doVertiaclUpCommand;
  344. private DOAccessor _doZtoMAPPINGSTARTPOSI;
  345. private DOAccessor _doZtoMAPPINGENDPOSI;
  346. private DOAccessor _doMAPIN;
  347. private DOAccessor _doMAPOUT;
  348. private AOAccessor _aoSAVECurrentRecipeNumber;
  349. private AOAccessor _aoMAPSTAR; //MAP STAR(10um) [ 2000<VALUE<30000]
  350. private AOAccessor _aoMAPEND;//MAP END(10um) [2000<VALUE<30000]
  351. private AOAccessor _aoSENSOR; //SENSOR (1:12寸 ; 2:8寸)
  352. private AOAccessor _aoSLOT;
  353. private AOAccessor _aoPITCH;
  354. private AOAccessor _aoPOSITIONRANGE; //POSITION RANGE(10um)
  355. private AOAccessor _aoPOSITIONRANGEUPPER; //POSITION RANGE UPPER(%)
  356. private AOAccessor _aoPOSITIONRANGELOWER; //POSITION RANGE LOWER(%)
  357. private AOAccessor _aoTHICK;//THICK(10um)
  358. private AOAccessor _aoTHICKRANGE;//THICK RANGE(10um)
  359. private AOAccessor _aoOFFSET;//OFFSET(10um)
  360. private AOAccessor _aoCarrierType;//料盒种类(1-FOUP,2-FOSB,3-Open Cassette)
  361. private AIAccessor _aiSlot1MapResult; // ( 0:No Wafer, 1:Wafer, 2:Crossed )
  362. private AIAccessor _aiSlot2MapResult;
  363. private AIAccessor _aiSlot3MapResult;
  364. private AIAccessor _aiSlot4MapResult;
  365. private AIAccessor _aiSlot5MapResult;
  366. private AIAccessor _aiSlot6MapResult;
  367. private AIAccessor _aiSlot7MapResult;
  368. private AIAccessor _aiSlot8MapResult;
  369. private AIAccessor _aiSlot9MapResult;
  370. private AIAccessor _aiSlot10MapResult;
  371. private AIAccessor _aiSlot11MapResult;
  372. private AIAccessor _aiSlot12MapResult;
  373. private AIAccessor _aiSlot13MapResult;
  374. private AIAccessor _aiSlot14MapResult;
  375. private AIAccessor _aiSlot15MapResult;
  376. private AIAccessor _aiSlot16MapResult;
  377. private AIAccessor _aiSlot17MapResult;
  378. private AIAccessor _aiSlot18MapResult;
  379. private AIAccessor _aiSlot19MapResult;
  380. private AIAccessor _aiSlot20MapResult;
  381. private AIAccessor _aiSlot21MapResult;
  382. private AIAccessor _aiSlot22MapResult;
  383. private AIAccessor _aiSlot23MapResult;
  384. private AIAccessor _aiSlot24MapResult;
  385. private AIAccessor _aiSlot25MapResult;
  386. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot1;
  387. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot1;
  388. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot2;
  389. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot2;
  390. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot3;
  391. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot3;
  392. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot4;
  393. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot4;
  394. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot5;
  395. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot5;
  396. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot6;
  397. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot6;
  398. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot7;
  399. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot7;
  400. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot8;
  401. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot8;
  402. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot9;
  403. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot9;
  404. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot10;
  405. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot10;
  406. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot11;
  407. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot11;
  408. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot12;
  409. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot12;
  410. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot13;
  411. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot13;
  412. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot14;
  413. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot14;
  414. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot15;
  415. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot15;
  416. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot16;
  417. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot16;
  418. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot17;
  419. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot17;
  420. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot18;
  421. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot18;
  422. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot19;
  423. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot19;
  424. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot20;
  425. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot20;
  426. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot21;
  427. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot21;
  428. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot22;
  429. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot22;
  430. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot23;
  431. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot23;
  432. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot24;
  433. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot24;
  434. private AIAccessor _aiWAFERPOSITIONUPPEREDGE_Slot25;
  435. private AIAccessor _aiWAFERPOSITIONLOWEREDGE_Slot25;
  436. private AIAccessor _aiErrorCode;
  437. private AIAccessor _aiLastErrorCode;
  438. private AIAccessor _aiTYPE1_CurrentRecipeNumber;
  439. private AIAccessor _aiTYPE1_MAPSTAR;
  440. private AIAccessor _aiTYPE1_MAPEND;
  441. private AIAccessor _aiTYPE1_SENSOR_WaferSize;
  442. private AIAccessor _aiTYPE1_SLOT;
  443. private AIAccessor _aiTYPE1_PITCH;
  444. private AIAccessor _aiTYPE1_POSITIONRANGE;
  445. private AIAccessor _aiTYPE1_POSITIONRANGEUPPER;
  446. private AIAccessor _aiTYPE1_POSITIONRANGELOWER;
  447. private AIAccessor _aiTYPE1_THICK;
  448. private AIAccessor _aiTYPE1_THICKRANGE;
  449. private AIAccessor _aiTYPE1_OFFSET;
  450. private AIAccessor _aiTYPE2_CurrentRecipeNumber;
  451. private AIAccessor _aiTYPE2_MAPSTAR;
  452. private AIAccessor _aiTYPE2_MAPEND;
  453. private AIAccessor _aiTYPE2_SENSOR_WaferSize;
  454. private AIAccessor _aiTYPE2_SLOT;
  455. private AIAccessor _aiTYPE2_PITCH;
  456. private AIAccessor _aiTYPE2_POSITIONRANGE;
  457. private AIAccessor _aiTYPE2_POSITIONRANGEUPPER;
  458. private AIAccessor _aiTYPE2_POSITIONRANGELOWER;
  459. private AIAccessor _aiTYPE2_THICK;
  460. private AIAccessor _aiTYPE2_THICKRANGE;
  461. private AIAccessor _aiTYPE2_OFFSET;
  462. private AIAccessor _aiTYPE3_CurrentRecipeNumber;
  463. private AIAccessor _aiTYPE3_MAPSTAR;
  464. private AIAccessor _aiTYPE3_MAPEND;
  465. private AIAccessor _aiTYPE3_SENSOR_WaferSize;
  466. private AIAccessor _aiTYPE3_SLOT;
  467. private AIAccessor _aiTYPE3_PITCH;
  468. private AIAccessor _aiTYPE3_POSITIONRANGE;
  469. private AIAccessor _aiTYPE3_POSITIONRANGEUPPER;
  470. private AIAccessor _aiTYPE3_POSITIONRANGELOWER;
  471. private AIAccessor _aiTYPE3_THICK;
  472. private AIAccessor _aiTYPE3_THICKRANGE;
  473. private AIAccessor _aiTYPE3_OFFSET;
  474. private AIAccessor _aiTYPE4_CurrentRecipeNumber;
  475. private AIAccessor _aiTYPE4_MAPSTAR;
  476. private AIAccessor _aiTYPE4_MAPEND;
  477. private AIAccessor _aiTYPE4_SENSOR_WaferSize;
  478. private AIAccessor _aiTYPE4_SLOT;
  479. private AIAccessor _aiTYPE4_PITCH;
  480. private AIAccessor _aiTYPE4_POSITIONRANGE;
  481. private AIAccessor _aiTYPE4_POSITIONRANGEUPPER;
  482. private AIAccessor _aiTYPE4_POSITIONRANGELOWER;
  483. private AIAccessor _aiTYPE4_THICK;
  484. private AIAccessor _aiTYPE4_THICKRANGE;
  485. private AIAccessor _aiTYPE4_OFFSET;
  486. private AIAccessor _aiTYPE5_CurrentRecipeNumber;
  487. private AIAccessor _aiTYPE5_MAPSTAR;
  488. private AIAccessor _aiTYPE5_MAPEND;
  489. private AIAccessor _aiTYPE5_SENSOR_WaferSize;
  490. private AIAccessor _aiTYPE5_SLOT;
  491. private AIAccessor _aiTYPE5_PITCH;
  492. private AIAccessor _aiTYPE5_POSITIONRANGE;
  493. private AIAccessor _aiTYPE5_POSITIONRANGEUPPER;
  494. private AIAccessor _aiTYPE5_POSITIONRANGELOWER;
  495. private AIAccessor _aiTYPE5_THICK;
  496. private AIAccessor _aiTYPE5_THICKRANGE;
  497. private AIAccessor _aiTYPE5_OFFSET;
  498. private AIAccessor _aiTYPE6_CurrentRecipeNumber;
  499. private AIAccessor _aiTYPE6_MAPSTAR;
  500. private AIAccessor _aiTYPE6_MAPEND;
  501. private AIAccessor _aiTYPE6_SENSOR_WaferSize;
  502. private AIAccessor _aiTYPE6_SLOT;
  503. private AIAccessor _aiTYPE6_PITCH;
  504. private AIAccessor _aiTYPE6_POSITIONRANGE;
  505. private AIAccessor _aiTYPE6_POSITIONRANGEUPPER;
  506. private AIAccessor _aiTYPE6_POSITIONRANGELOWER;
  507. private AIAccessor _aiTYPE6_THICK;
  508. private AIAccessor _aiTYPE6_THICKRANGE;
  509. private AIAccessor _aiTYPE6_OFFSET;
  510. private AIAccessor _aiRECIPE_TYPE_FEEDBACK;
  511. private DIAccessor _diAck_RecieSave;
  512. private DIAccessor _diAck_RecipeLoad;
  513. private DIAccessor _diAck_Init;
  514. private DIAccessor _diAck_Reset;
  515. private DIAccessor _diAck_SingleMap;
  516. private DIAccessor _diAck_HomePos;
  517. private DIAccessor _diSensor_Presence;
  518. private DIAccessor _diSensor_Placement;
  519. private DIAccessor _diSensor_Protrude;
  520. private DIAccessor _diSensor_VerticalDown;
  521. private DIAccessor _diAck_Load;
  522. private DIAccessor _diAck_Unload;
  523. private DIAccessor _diAck_MapDisable;
  524. private DIAccessor _diAck_MapEnable;
  525. private DIAccessor _diAck_ClampOn;
  526. private DIAccessor _diAck_ClampOff;
  527. private DIAccessor _diAck_DockFwd;
  528. private DIAccessor _diAck_DockHome;
  529. private DIAccessor _diAck_LatchOn;
  530. private DIAccessor _diAck_LatchOff;
  531. private DIAccessor _diAck_DoorClose;
  532. private DIAccessor _diAck_DoorOpen;
  533. private DIAccessor _diAck_VacOn;
  534. private DIAccessor _diAck_VacOff;
  535. private DIAccessor _diAck_VerticalDown;
  536. private DIAccessor _diAck_VerticalUp;
  537. private DIAccessor _diAck_ZtoMapStart;
  538. private DIAccessor _diAck_ZtoMapEnd;
  539. private DIAccessor _diAck_Mapin;
  540. private DIAccessor _diAck_MapOut;
  541. private DIAccessor _diAck_CmdClear;
  542. private DIAccessor _diAck_E84Disable;
  543. private DIAccessor _diAck_E84Enable;
  544. //原X,Y
  545. private DIAccessor _di12MapSensor;
  546. private DIAccessor _di8MapSensor;
  547. private DIAccessor _diSERVOHOME;
  548. private DIAccessor _diFoupPlacementSensor;
  549. private DIAccessor _diDoorCheckSensor;
  550. private DIAccessor _diCDASensor;
  551. private DIAccessor _diDockHomeSensor;
  552. private DIAccessor _diClampOffSensor;
  553. private DIAccessor _diPodForwardSensor;
  554. private DIAccessor _diClampOnSensor;
  555. private DIAccessor _diVACSensor;
  556. private DIAccessor _diLatchLockSensor;
  557. private DIAccessor _diLatchUnlockSensor;
  558. private DIAccessor _diDoorOpenSensor;
  559. private DIAccessor _diDoorCloseSensor;
  560. private DIAccessor _diVerticalMiddleSensor;
  561. private DIAccessor _diVerticalDownSensor;
  562. private DIAccessor _diOPSwitchButton;
  563. private DIAccessor _diMapin;
  564. private DIAccessor _diMapout;
  565. private DIAccessor _diProtrudesensor;
  566. private DIAccessor _diInfoPadA;
  567. private DIAccessor _diInfoPadB;
  568. private DIAccessor _diInfoPadC;
  569. private DIAccessor _diInfoPadD;
  570. private DIAccessor _diServoOn;
  571. private DIAccessor _diPresence;
  572. private DIAccessor _diStepError;
  573. private DIAccessor _diServoerror;
  574. private DIAccessor _diDoorSafe;
  575. private DIAccessor _diSERVO;
  576. private DIAccessor _diSTEP;
  577. private DIAccessor _diClampOnCylinder;
  578. private DIAccessor _diClampOffCylinder;
  579. private DIAccessor _diLatchOnCylinder;
  580. private DIAccessor _diLatchOffCylinder;
  581. private DIAccessor _diDoorOpenCylinder;
  582. private DIAccessor _diDoorCloseCylinder;
  583. private DIAccessor _diSERVOCLEAR1;
  584. private DIAccessor _diSERVOON1;
  585. private DIAccessor _diD3UBIN;
  586. private DIAccessor _diMapForwardCylinder;
  587. private DIAccessor _diSERVOCLEAR2;
  588. private DIAccessor _diSERVOON2;
  589. private DIAccessor _diSERVOCLCOUNT;
  590. private DIAccessor _diVAC;
  591. private DIAccessor _diSERVOBRAKE;
  592. private DIAccessor _diLoadLight;
  593. private DIAccessor _diUnloadLight;
  594. private DIAccessor _diPOWERLIGHT;
  595. private DIAccessor _diFoupPlacementLight;
  596. private DIAccessor _diFoupPresenceLight;
  597. private DIAccessor _diAlarmOccurLight;
  598. private DIAccessor _diStatu1Light;
  599. private DIAccessor _diStatu2Light;
  600. private IoSensor _diIronCassetteDoorClose;
  601. public IoSensor DiIronCassetteDoorClose
  602. {
  603. get => _diIronCassetteDoorClose;
  604. set
  605. {
  606. _diIronCassetteDoorClose = value;
  607. _diIronCassetteDoorClose.OnSignalChanged += _diIronCassetteDoorClose_OnSignalChanged;
  608. }
  609. }
  610. private void _diIronCassetteDoorClose_OnSignalChanged(IoSensor arg1, bool arg2)
  611. {
  612. if (!IsPlacement || !IsMapped) return;
  613. if (arg2) return;
  614. if (_diIronCassetteDoorClose.Value) return;
  615. if (!_diDockHomeSensor.Value) return;
  616. if (!IsReady()) return;
  617. if (!_isNeedCheckIronDoor) return;
  618. Unclamp(out _);
  619. }
  620. private DateTime _actionStartTime;
  621. private int _actionTimeLimit;
  622. protected R_TRIG _carrierArrived;
  623. protected R_TRIG _errorOccurredTrig;
  624. protected R_TRIG _lastErrorOccurredTrig;
  625. protected R_TRIG _alarmWaferProtrudeTrig;
  626. private int _errorCode = 0;
  627. private int _lastErrorCode = 0;
  628. public override string ErrorCode
  629. {
  630. get => _aiErrorCode.Value.ToString();
  631. }
  632. public TDKMode Mode { get; set; } = TDKMode.Online;
  633. public TDKInitPosMovement InitPosMovement { get; set; }
  634. public TDKOperationStatus OperationStatus { get; set; }
  635. public TDKContainerStatus ContainerStatus
  636. {
  637. get
  638. {
  639. if (_isPlaced && _isPresent)
  640. return TDKContainerStatus.NormalMount;
  641. if (!_isPlaced && !_isPresent)
  642. return TDKContainerStatus.Absence;
  643. return TDKContainerStatus.MountError;
  644. }
  645. }
  646. public TDKPosition ClampPosition
  647. {
  648. get
  649. {
  650. if (_diClampOffSensor.Value && !_diClampOnCylinder.Value)
  651. return TDKPosition.Open;
  652. if (!_diClampOffSensor.Value && _diClampOnCylinder.Value)
  653. return TDKPosition.Close;
  654. return TDKPosition.TBD;
  655. }
  656. }
  657. public TDKPosition LPDoorLatchPosition
  658. {
  659. get
  660. {
  661. if (_diLatchLockSensor.Value && !_diLatchUnlockSensor.Value)
  662. return TDKPosition.Close;
  663. if (!_diLatchLockSensor.Value && _diLatchUnlockSensor.Value)
  664. return TDKPosition.Open;
  665. return TDKPosition.TBD;
  666. }
  667. }
  668. public TDKVacummStatus VacuumStatus
  669. {
  670. get
  671. {
  672. if (_diVACSensor.Value)
  673. return TDKVacummStatus.ON;
  674. return TDKVacummStatus.OFF;
  675. }
  676. }
  677. public TDKPosition LPDoorState
  678. {
  679. get
  680. {
  681. if (_diDoorOpenSensor.Value && !_diDoorCloseSensor.Value)
  682. return TDKPosition.Open;
  683. if(!_diDoorOpenSensor.Value && _diDoorCloseSensor.Value)
  684. return TDKPosition.Close;
  685. return TDKPosition.TBD;
  686. }
  687. }
  688. public TDKWaferProtrusion WaferProtrusion
  689. {
  690. get
  691. {
  692. if (!_diProtrudesensor.Value)
  693. return TDKWaferProtrusion.ShadingStatus;
  694. return TDKWaferProtrusion.LightIncidentStatus;
  695. }
  696. }
  697. public TDKElevatorAxisPosition ElevatorAxisPosition
  698. {
  699. get
  700. {
  701. if (_diVerticalDownSensor.Value)
  702. return TDKElevatorAxisPosition.Down;
  703. if (_diAck_ZtoMapEnd.Value)
  704. return TDKElevatorAxisPosition.MappingStartPos;
  705. if (_diAck_ZtoMapStart.Value)
  706. return TDKElevatorAxisPosition.MappingEndPos;
  707. return TDKElevatorAxisPosition.TBD;
  708. }
  709. }
  710. public TDKDockPosition DockPosition
  711. {
  712. get
  713. {
  714. if (_diDockHomeSensor.Value && !_diPodForwardSensor.Value)
  715. return TDKDockPosition.Undock;
  716. if (!_diDockHomeSensor.Value && _diPodForwardSensor.Value)
  717. return TDKDockPosition.Dock;
  718. return TDKDockPosition.TBD;
  719. }
  720. }
  721. public TDKMapPosition MapperPostion
  722. {
  723. get => TDKMapPosition.TBD;
  724. }
  725. public TDKMappingStatus MappingStatus { get; set; } = TDKMappingStatus.NormalEnd;
  726. public TDKModel Model { get; set; }
  727. public CarrierMode LPCarrierMode
  728. {
  729. get
  730. {
  731. int intvalue = 0;
  732. if (SC.ContainsItem($"CarrierInfo.CarrierFosbMode{InfoPadCarrierIndex}"))
  733. intvalue = SC.GetValue<int>($"CarrierInfo.CarrierFosbMode{InfoPadCarrierIndex}");
  734. if(SC.ContainsItem($"CarrierInfo.Carrier{InfoPadCarrierIndex}.CarrierFosbMode"))
  735. {
  736. bool bvalue = SC.GetValue<bool>($"CarrierInfo.Carrier{InfoPadCarrierIndex}.CarrierFosbMode");
  737. return bvalue ? CarrierMode.Fosb : CarrierMode.Foup;
  738. }
  739. if (intvalue == 0)
  740. return CarrierMode.Foup;
  741. if (intvalue == 1)
  742. return CarrierMode.Fosb;
  743. if (intvalue == 2)
  744. return CarrierMode.OpenCassette;
  745. return CarrierMode.Foup;
  746. }
  747. }
  748. public override bool IsWaferProtrude
  749. {
  750. get
  751. {
  752. //_alarmWaferProtrudeTrig.CLK = !_diProtrudesensor.Value;
  753. //if(_alarmWaferProtrudeTrig.Q)
  754. //{
  755. // EV.Notify(AlarmLoadPortWaferProtrusion);
  756. //}
  757. return (!_diProtrudesensor.Value);
  758. }
  759. }
  760. public override bool IsEnableLoad(out string reason)
  761. {
  762. //if(IsWaferProtrude)
  763. //{
  764. // reason = "Wafer Protrusion";
  765. // return false;
  766. //}
  767. if(_isNeedCheckIronDoor)
  768. {
  769. if(DiIronCassetteDoorClose!=null && !DiIronCassetteDoorClose.Value)
  770. {
  771. reason = "Iron Door Closed";
  772. return false;
  773. }
  774. }
  775. return base.IsEnableLoad(out reason);
  776. }
  777. public override bool IsEnableMapWafer(out string reason)
  778. {
  779. if (IsWaferProtrude)
  780. {
  781. reason = "Wafer Protrusion";
  782. return false;
  783. }
  784. if (_isNeedCheckIronDoor)
  785. {
  786. if (DiIronCassetteDoorClose != null && !DiIronCassetteDoorClose.Value)
  787. {
  788. reason = "Iron Door Closed";
  789. return false;
  790. }
  791. }
  792. return base.IsEnableMapWafer(out reason);
  793. }
  794. private bool _isNeedCheckIronDoor
  795. {
  796. get
  797. {
  798. if (SC.ContainsItem($"CarrierInfo.NeedCheckIronDoorCarrier{InfoPadCarrierIndex}"))
  799. return SC.GetValue<bool>($"CarrierInfo.NeedCheckIronDoorCarrier{InfoPadCarrierIndex}");
  800. if (SC.ContainsItem($"CarrierInfo.Carrier{InfoPadCarrierIndex}.NeedCheckIronDoorCarrier"))
  801. return SC.GetValue<bool>($"CarrierInfo.Carrier{InfoPadCarrierIndex}.NeedCheckIronDoorCarrier");
  802. return false;
  803. }
  804. }
  805. public override bool IsEnableTransferWafer(out string reason)
  806. {
  807. if(!IsLoaded)
  808. {
  809. reason = "Carrier Is not loaded";
  810. return false;
  811. }
  812. if(!IsMapped)
  813. {
  814. reason = "Not Mapped";
  815. return false;
  816. }
  817. if(!IsReady())
  818. {
  819. reason = "Not Ready";
  820. return false;
  821. }
  822. if (IsWaferProtrude)
  823. {
  824. EV.Notify(AlarmLoadPortWaferProtrusion);
  825. OnError("Wafer Protrusion");
  826. reason = "Wafer Protrusion";
  827. return false;
  828. }
  829. if (_isNeedCheckIronDoor)
  830. {
  831. if (DiIronCassetteDoorClose != null && !DiIronCassetteDoorClose.Value)
  832. {
  833. reason = "Iron Door Closed";
  834. return false;
  835. }
  836. }
  837. if(ErrorCode !="0")
  838. {
  839. reason = "ErrorCode is " + ErrorCode;
  840. return false;
  841. }
  842. if (_isDisableEvenSlot)
  843. {
  844. for(int i =0;i<SlotMap.ToArray().Length;i++)
  845. {
  846. if (i % 2 == 0) continue;
  847. if (SlotMap[i] != '0')
  848. {
  849. OnError("Detect wafer on even slot.");
  850. reason = "Detect wafer on even slot";
  851. return false;
  852. }
  853. }
  854. }
  855. if (_isDisableOddSlot)
  856. {
  857. for (int i = 0; i < SlotMap.ToArray().Length; i++)
  858. {
  859. if (i % 2 == 1) continue;
  860. if (SlotMap[i] != '0')
  861. {
  862. OnError("Detect wafer on odd slot.");
  863. reason = "Detect wafer on odd slot";
  864. return false;
  865. }
  866. }
  867. }
  868. if (IsVerifyPreDefineWaferCount && WaferCount != PreDefineWaferCount)
  869. {
  870. reason = "Mapping Error:WaferCount not matched";
  871. return false;
  872. }
  873. return base.IsEnableTransferWafer(out reason);
  874. }
  875. public override FoupClampState ClampState
  876. {
  877. get
  878. {
  879. if (_diClampOffSensor.Value && !_diClampOnCylinder.Value)
  880. return FoupClampState.Open;
  881. if (!_diClampOffSensor.Value && _diClampOnCylinder.Value)
  882. return FoupClampState.Close;
  883. return FoupClampState.Unknown;
  884. }
  885. }
  886. public override FoupDockState DockState
  887. {
  888. get
  889. {
  890. if(_diDockHomeSensor.Value && !_diPodForwardSensor.Value)
  891. return FoupDockState.Undocked;
  892. if(!_diDockHomeSensor.Value && _diPodForwardSensor.Value)
  893. return FoupDockState.Docked;
  894. return FoupDockState.Unknown;
  895. }
  896. }
  897. public override LoadportCassetteState CassetteState
  898. {
  899. get
  900. {
  901. if (_isPlaced && _isPresent)
  902. return LoadportCassetteState.Normal;
  903. if (!_isPlaced)
  904. return LoadportCassetteState.Absent;
  905. return LoadportCassetteState.Unknown;
  906. }
  907. }
  908. public override FoupDoorState DoorState
  909. {
  910. get
  911. {
  912. if (LPDoorState == TDKPosition.Close)
  913. return FoupDoorState.Close;
  914. if (LPDoorState == TDKPosition.Open)
  915. return FoupDoorState.Open;
  916. return FoupDoorState.Unknown;
  917. }
  918. }
  919. public override FoupDoorPostionEnum DoorPosition
  920. {
  921. get
  922. {
  923. if (_diVerticalDownSensor.Value && !_diVerticalMiddleSensor.Value)
  924. return FoupDoorPostionEnum.Down;
  925. if (!_diAck_ZtoMapEnd.Value && !_diVerticalMiddleSensor.Value)
  926. return FoupDoorPostionEnum.Unknown;
  927. return FoupDoorPostionEnum.Unknown;
  928. }
  929. }
  930. public override bool IsVacuumON
  931. {
  932. get
  933. {
  934. return _diVACSensor.Value;
  935. }
  936. }
  937. public override WaferSize GetCurrentWaferSize()
  938. {
  939. int intvalue = 0;
  940. if(SC.ContainsItem($"CarrierInfo.CarrierWaferSize{InfoPadCarrierIndex}"))
  941. intvalue = SC.GetValue<int>($"CarrierInfo.CarrierWaferSize{InfoPadCarrierIndex}");
  942. if (SC.ContainsItem($"CarrierInfo.Carrier{InfoPadCarrierIndex}.CarrierWaferSize"))
  943. intvalue = SC.GetValue<int>($"CarrierInfo.Carrier{InfoPadCarrierIndex}.CarrierWaferSize");
  944. if (intvalue == 0)
  945. return WaferSize.WS0;
  946. if (intvalue == 6)
  947. return WaferSize.WS6;
  948. if (intvalue == 8)
  949. return WaferSize.WS8;
  950. if (intvalue == 12)
  951. return WaferSize.WS12;
  952. return WaferSize.WS0;
  953. }
  954. public override int InfoPadCarrierIndex
  955. {
  956. get
  957. {
  958. if (IsAutoDetectCarrierType)
  959. {
  960. return (_diInfoPadA.Value ? 8 : 0) + (_diInfoPadB.Value ? 4 : 0) +
  961. (_diInfoPadC.Value ? 2 : 0) + (_diInfoPadD.Value ? 1 : 0);
  962. }
  963. return base.InfoPadCarrierIndex;
  964. }
  965. set
  966. {
  967. base.InfoPadCarrierIndex = value;
  968. }
  969. }
  970. public override bool IsVerifyPreDefineWaferCount
  971. {
  972. get
  973. {
  974. if (SC.ContainsItem($"LoadPort.{LPModuleName}.IsVerifyPreDefineWaferCount"))
  975. return SC.GetValue<bool>($"LoadPort.{LPModuleName}.IsVerifyPreDefineWaferCount");
  976. return false;
  977. }
  978. }
  979. public override string SpecCarrierType
  980. {
  981. get
  982. {
  983. if (!_isPlaced) return "";
  984. if (SC.ContainsItem($"CarrierInfo.CarrierName{InfoPadCarrierIndex}"))
  985. return SC.GetStringValue($"CarrierInfo.CarrierName{InfoPadCarrierIndex}");
  986. if (SC.ContainsItem($"CarrierInfo.Carrier{InfoPadCarrierIndex}.CarrierName"))
  987. return SC.GetStringValue($"CarrierInfo.Carrier{InfoPadCarrierIndex}.CarrierName");
  988. return "";
  989. }
  990. }
  991. private bool OnTimer()
  992. {
  993. try
  994. {
  995. _errorOccurredTrig.CLK = (int)_aiErrorCode.Value != _errorCode;
  996. _errorCode = (int)_aiErrorCode.Value;
  997. _lastErrorOccurredTrig.CLK = (int)_aiLastErrorCode.Value != _lastErrorCode;
  998. _lastErrorCode = (int)_aiLastErrorCode.Value;
  999. if(_errorOccurredTrig.Q && _errorCode >0)
  1000. {
  1001. if (AlarmNcdLoadPortErrors.Length >= _errorCode - 1000)
  1002. {
  1003. EV.Notify(AlarmNcdLoadPortErrors[_errorCode - 1001]);
  1004. OnError(AlarmNcdLoadPortErrors[_errorCode - 1001]);
  1005. }
  1006. }
  1007. if(_lastErrorOccurredTrig.Q && _lastErrorCode>0)
  1008. {
  1009. if (AlarmNcdLoadPortLastErrors.Length > _lastErrorCode - 1000)
  1010. {
  1011. EV.Notify(AlarmNcdLoadPortLastErrors[_lastErrorCode - 1001]);
  1012. OnError(AlarmNcdLoadPortLastErrors[_errorCode - 1001]);
  1013. }
  1014. }
  1015. _isPresent = _diSensor_Presence.Value;
  1016. _isPlaced = _diSensor_Placement.Value;
  1017. SetPresent(_isPresent);
  1018. SetPlaced(_diSensor_Placement.Value);
  1019. _carrierArrived.CLK = _diSensor_Placement.Value;
  1020. if (_carrierArrived.Q)
  1021. {
  1022. //CheckAndLoadRecipe();
  1023. }
  1024. MonitorInterlock();
  1025. }
  1026. catch(Exception ex)
  1027. {
  1028. LOG.Write(ex);
  1029. }
  1030. return true;
  1031. }
  1032. private void MonitorInterlock()
  1033. {
  1034. if ( CurrentState == LoadPortStateEnum.Error) return;
  1035. if(DockState == FoupDockState.Docked)
  1036. {
  1037. if (!_isPlaced)
  1038. OnError("Carrier removed unexpectly.");
  1039. }
  1040. }
  1041. private int _intRecipeNum
  1042. {
  1043. get
  1044. {
  1045. if (SC.ContainsItem($"CarrierInfo.CarrierRecipeNumber{InfoPadCarrierIndex}"))
  1046. return SC.GetValue<int>($"CarrierInfo.CarrierRecipeNumber{InfoPadCarrierIndex}");
  1047. if (SC.ContainsItem($"CarrierInfo.Carrier{InfoPadCarrierIndex}.LPRecipeNumber"))
  1048. return SC.GetValue<int>($"CarrierInfo.Carrier{InfoPadCarrierIndex}.LPRecipeNumber");
  1049. return 1;
  1050. }
  1051. }
  1052. private bool CheckAndLoadRecipe()
  1053. {
  1054. int timelimit = SC.ContainsItem($"LoadPort.{Name}.TimeLimitAction") ?
  1055. SC.GetValue<int>($"LoadPort.{Name}.TimeLimitAction") : 45;
  1056. if (_aiRECIPE_TYPE_FEEDBACK.Value == _intRecipeNum)
  1057. {
  1058. LOG.Write($"{LPModuleName} current recipe is {_intRecipeNum},no need to change");
  1059. return true;
  1060. }
  1061. if (_doRecipeLoadCommand.Value)
  1062. {
  1063. _doRecipeLoadCommand.SetValue(false, out _);
  1064. Thread.Sleep(1000);
  1065. }
  1066. _aoSAVECurrentRecipeNumber.Value = (short)_intRecipeNum;
  1067. LOG.Write($"{LPModuleName} set _aoSAVECurrentRecipeNumber value to {_intRecipeNum}");
  1068. Thread.Sleep(200);
  1069. _doRecipeLoadCommand.SetValue(true, out _);
  1070. DateTime _stTime = DateTime.Now;
  1071. while(!_diAck_RecipeLoad.Value || _aiRECIPE_TYPE_FEEDBACK.Value != _intRecipeNum)
  1072. {
  1073. if (DateTime.Now - _stTime > TimeSpan.FromSeconds(timelimit))
  1074. {
  1075. _doRecipeLoadCommand.SetValue(false, out _);
  1076. EV.Notify($"{LPModuleName}LoadRecipeFailed");
  1077. OnError($"{LPModuleName}LoadRecipeFailed");
  1078. return false;
  1079. }
  1080. }
  1081. _doRecipeLoadCommand.SetValue(false, out _);
  1082. _stTime = DateTime.Now;
  1083. while (_diAck_RecipeLoad.Value)
  1084. {
  1085. if (DateTime.Now - _stTime > TimeSpan.FromSeconds(timelimit))
  1086. {
  1087. _doRecipeLoadCommand.SetValue(false, out _);
  1088. EV.Notify($"{LPModuleName}LoadRecipeFailed");
  1089. OnError($"{LPModuleName}LoadRecipeFailed");
  1090. return false;
  1091. }
  1092. }
  1093. return true;
  1094. }
  1095. protected override bool fStartInit(object[] param)
  1096. {
  1097. ResetRoutine();
  1098. _actionTimeLimit = SC.ContainsItem($"LoadPort.{Name}.TimeLimitLoadportHome") ?
  1099. SC.GetValue<int>($"LoadPort.{Name}.TimeLimitLoadportHome") : 45;
  1100. //if(!_diProtrudesensor.Value)
  1101. //{
  1102. // EV.Notify(AlarmLoadPortWaferProtrusion);
  1103. // return false;
  1104. //}
  1105. return true;
  1106. //_actionStartTime = DateTime.Now;
  1107. //if (!CheckAndLoadRecipe())
  1108. // return false;
  1109. //return _doIntialCommand.SetValue(true, out _);
  1110. }
  1111. protected override bool fMonitorInit(object[] param)
  1112. {
  1113. IsBusy = false;
  1114. try
  1115. {
  1116. SetAoValue((int)LoadPortStepEnum.LoadRecipe1, _aoSAVECurrentRecipeNumber, (short)_intRecipeNum, Notify);
  1117. SetDoState((int)LoadPortStepEnum.LoadRecipe2, _doRecipeLoadCommand, true, Notify);
  1118. WaitDiState((int)LoadPortStepEnum.LoadRecipe3, _actionTimeLimit, _diAck_RecipeLoad, true, Notify, Stop);
  1119. WaitAiValue((int)LoadPortStepEnum.LoadRecipe4, _actionTimeLimit, _aiRECIPE_TYPE_FEEDBACK, (short)_intRecipeNum, Notify, Stop);
  1120. SetDoState((int)LoadPortStepEnum.LoadRecipe5, _doRecipeLoadCommand, false, Notify);
  1121. WaitDiState((int)LoadPortStepEnum.LoadRecipe6, _actionTimeLimit, _diAck_RecipeLoad, false, Notify, Stop);
  1122. SetDoState((int)LoadPortStepEnum.ActionStep1, _doIntialCommand, true, Notify);
  1123. WaitDiState((int)LoadPortStepEnum.ActionStep2, _actionTimeLimit, _diAck_Init, true, Notify, Stop);
  1124. SetDoState((int)LoadPortStepEnum.ActionStep3, _doIntialCommand, false, Notify);
  1125. WaitDiState((int)LoadPortStepEnum.ActionStep4, _actionTimeLimit, _diAck_Init, false, Notify, Stop);
  1126. }
  1127. catch (RoutineBreakException)
  1128. {
  1129. return false;
  1130. }
  1131. catch (RoutineFaildException)
  1132. {
  1133. EV.Notify(AlarmLoadPortHomeTimeout);
  1134. OnError("Home failed");
  1135. return true;
  1136. }
  1137. OnHomed();
  1138. return true;
  1139. }
  1140. protected override bool fStartLoad(object[] param)
  1141. {
  1142. _actionTimeLimit = SC.ContainsItem($"LoadPort.{Name}.TimeLimitLoadportLoad") ?
  1143. SC.GetValue<int>($"LoadPort.{Name}.TimeLimitLoadportLoad") : 45;
  1144. ResetRoutine();
  1145. if (param == null || param.Length == 0)
  1146. {
  1147. _doMapEnableCommand.SetValue(true, out _);
  1148. _doMapDisableCommand.SetValue(false, out _);
  1149. _currentloadCommand = "LoadWithMap";
  1150. }
  1151. if (param.Length >= 1 && param[0].ToString() == "LoadWithMap")
  1152. {
  1153. _doMapEnableCommand.SetValue(true, out _);
  1154. _doMapDisableCommand.SetValue(false, out _);
  1155. _currentloadCommand = "LoadWithMap";
  1156. }
  1157. if (param.Length >= 1 && param[0].ToString() == "LoadWithoutMap")
  1158. {
  1159. _doMapEnableCommand.SetValue(false, out _);
  1160. _doMapDisableCommand.SetValue(true, out _);
  1161. _currentloadCommand = "LoadWithoutMap";
  1162. }
  1163. if (param.Length >= 1 && param[0].ToString() == "LoadWithCloseDoor")
  1164. {
  1165. _doMapEnableCommand.SetValue(true, out _);
  1166. _doMapDisableCommand.SetValue(false, out _);
  1167. _currentloadCommand = "LoadWithCloseDoor";
  1168. }
  1169. if (param.Length >= 1 && param[0].ToString() == "LoadWithoutMapWithCloseDoor")
  1170. {
  1171. _doMapEnableCommand.SetValue(false, out _);
  1172. _doMapDisableCommand.SetValue(true, out _);
  1173. _currentloadCommand = "LoadWithoutMapWithCloseDoor";
  1174. }
  1175. _isNeedLoadRecipe = _aiRECIPE_TYPE_FEEDBACK.Value != (short)_intRecipeNum;
  1176. return true;
  1177. }
  1178. private string _currentloadCommand = "";
  1179. private bool _isNeedLoadRecipe;
  1180. protected override bool fMonitorLoad(object[] param)
  1181. {
  1182. IsBusy = false;
  1183. try
  1184. {
  1185. if (_isNeedLoadRecipe)
  1186. {
  1187. SetAoValue((int)LoadPortStepEnum.LoadRecipe1, _aoSAVECurrentRecipeNumber, (short)_intRecipeNum, Notify);
  1188. SetDoState((int)LoadPortStepEnum.LoadRecipe2, _doRecipeLoadCommand, true, Notify);
  1189. WaitDiState((int)LoadPortStepEnum.LoadRecipe3, _actionTimeLimit, _diAck_RecipeLoad, true, Notify, Stop);
  1190. WaitAiValue((int)LoadPortStepEnum.LoadRecipe4, _actionTimeLimit, _aiRECIPE_TYPE_FEEDBACK, (short)_intRecipeNum, Notify, Stop);
  1191. SetDoState((int)LoadPortStepEnum.LoadRecipe5, _doRecipeLoadCommand, false, Notify);
  1192. WaitDiState((int)LoadPortStepEnum.LoadRecipe6, _actionTimeLimit, _diAck_RecipeLoad, false, Notify, Stop);
  1193. }
  1194. SetDoState((int)LoadPortStepEnum.ActionStep1, _doLoadCommand, true, Notify);
  1195. WaitDiState((int)LoadPortStepEnum.ActionStep2, _actionTimeLimit, _diAck_Load, true, Notify, Stop);
  1196. SetDoState((int)LoadPortStepEnum.ActionStep3, _doLoadCommand, false, Notify);
  1197. WaitDiState((int)LoadPortStepEnum.ActionStep4, _actionTimeLimit, _diAck_Load, false, Notify, Stop);
  1198. if(_currentloadCommand == "LoadWithCloseDoor")
  1199. {
  1200. SetDoState((int)LoadPortStepEnum.ActionStep5, _doVertiaclUpCommand, true, Notify);
  1201. WaitDiState((int)LoadPortStepEnum.ActionStep6, _actionTimeLimit, _diAck_VerticalUp, true, Notify, Stop);
  1202. SetDoState((int)LoadPortStepEnum.ActionStep7, _doVertiaclUpCommand, false, Notify);
  1203. WaitDiState((int)LoadPortStepEnum.ActionStep8, _actionTimeLimit, _diAck_VerticalUp, false, Notify, Stop);
  1204. SetDoState((int)LoadPortStepEnum.ActionStep9, _doVertiaclUpCommand, true, Notify);
  1205. WaitDiState((int)LoadPortStepEnum.ActionStep10, _actionTimeLimit, _diAck_VerticalUp, true, Notify, Stop);
  1206. SetDoState((int)LoadPortStepEnum.ActionStep11, _doVertiaclUpCommand, false, Notify);
  1207. WaitDiState((int)LoadPortStepEnum.ActionStep12, _actionTimeLimit, _diAck_VerticalUp, false, Notify, Stop);
  1208. SetDoState((int)LoadPortStepEnum.ActionStep13, _doDoorCloseCommand, true, Notify);
  1209. WaitDiState((int)LoadPortStepEnum.ActionStep14, _actionTimeLimit, _diAck_DoorClose, true, Notify, Stop);
  1210. SetDoState((int)LoadPortStepEnum.ActionStep15, _doDoorCloseCommand, false, Notify);
  1211. WaitDiState((int)LoadPortStepEnum.ActionStep16, _actionTimeLimit, _diAck_DoorClose, false, Notify, Stop);
  1212. }
  1213. }
  1214. catch (RoutineBreakException)
  1215. {
  1216. return false;
  1217. }
  1218. catch (RoutineFaildException)
  1219. {
  1220. EV.Notify(AlarmLoadPortLoadTimeOut);
  1221. OnError("LoadFailed");
  1222. return true;
  1223. }
  1224. OnLoaded();
  1225. if(_currentloadCommand == "LoadWithMap" || _currentloadCommand == "LoadWithCloseDoor")
  1226. {
  1227. ReadSlotMap();
  1228. }
  1229. return true;
  1230. //if (DateTime.Now - _actionStartTime > TimeSpan.FromSeconds(timelimit))
  1231. //{
  1232. // _doLoadCommand.SetValue(false, out _);
  1233. // OnError("Load timeout");
  1234. // return false;
  1235. //}
  1236. //if (_diAck_Load.Value && _diPodForwardSensor.Value && _diDoorOpenSensor.Value && _diVerticalDownSensor.Value)
  1237. //{
  1238. // _doLoadCommand.SetValue(false, out _);
  1239. // switch (_currentloadCommand)
  1240. // {
  1241. // case "LoadWithMap":
  1242. // //if (!IsMapped)
  1243. // ReadSlotMap();
  1244. // return true;
  1245. // case "LoadWithCloseDoor":
  1246. // if (!_diAck_VerticalUp.Value || _diVerticalDownSensor.Value)
  1247. // {
  1248. // _doVertiaclUpCommand.SetValue(true, out _);
  1249. // _doVertiaclDownCommand.SetValue(false, out _);
  1250. // }
  1251. // if(_diAck_VerticalUp.Value && !_diVerticalDownSensor.Value)
  1252. // {
  1253. // _doVertiaclUpCommand.SetValue(false, out _);
  1254. // _doVertiaclDownCommand.SetValue(false, out _);
  1255. // _doDoorOpenCommand.SetValue(false, out _);
  1256. // _doDoorCloseCommand.SetValue(true, out _);
  1257. // }
  1258. // if(!_diVerticalDownSensor.Value && _diAck_DoorClose.Value && _diDoorCloseSensor.Value)
  1259. // {
  1260. // _doDoorOpenCommand.SetValue(false, out _);
  1261. // _doDoorCloseCommand.SetValue(false, out _);
  1262. // ReadSlotMap();
  1263. // return true;
  1264. // }
  1265. // break;
  1266. // default:
  1267. // break;
  1268. // }
  1269. // _doLoadCommand.SetValue(false, out _);
  1270. // return true;
  1271. //}
  1272. //return base.fMonitorLoad(param);
  1273. }
  1274. protected override bool fMonitorTransferBlock(object[] param)
  1275. {
  1276. //if (!_isPlaced)
  1277. //{
  1278. // OnError("Placement Error");
  1279. // return false;
  1280. //}
  1281. return base.fMonitorTransferBlock(param);
  1282. }
  1283. public override int ValidStartSlotIndex => base.ValidStartSlotIndex;
  1284. public override int ValidEndSlotIndex
  1285. {
  1286. get
  1287. {
  1288. return ValidStartSlotIndex + ValidSlotsNumber - 1;
  1289. }
  1290. }
  1291. private void ReadSlotMap()
  1292. {
  1293. string strslotmap = "";
  1294. AIAccessor[] ais = new AIAccessor[]
  1295. {
  1296. _aiSlot25MapResult,_aiSlot24MapResult,_aiSlot23MapResult,_aiSlot22MapResult ,_aiSlot21MapResult,
  1297. _aiSlot20MapResult,_aiSlot19MapResult, _aiSlot18MapResult, _aiSlot17MapResult ,_aiSlot16MapResult,
  1298. _aiSlot15MapResult,_aiSlot14MapResult,_aiSlot13MapResult,_aiSlot12MapResult ,_aiSlot11MapResult,
  1299. _aiSlot10MapResult,_aiSlot9MapResult,_aiSlot8MapResult,_aiSlot7MapResult ,_aiSlot6MapResult,
  1300. _aiSlot5MapResult,_aiSlot4MapResult,_aiSlot3MapResult,_aiSlot2MapResult,_aiSlot1MapResult,
  1301. };
  1302. WaferCount = 0;
  1303. for(int i= 24 - ValidEndSlotIndex; i<=24;i++)
  1304. {
  1305. if (ais[i].Value != 0)
  1306. {
  1307. WaferCount++;
  1308. if (_isDisableEvenSlot && i % 2 == 1)
  1309. {
  1310. strslotmap = strslotmap + "?";
  1311. OnError("Detect wafer on even slot;");
  1312. continue;
  1313. }
  1314. if (_isDisableOddSlot && i % 2 == 0)
  1315. {
  1316. strslotmap = strslotmap + "?";
  1317. OnError("Detect wafer on odd slot;");
  1318. continue;
  1319. }
  1320. }
  1321. strslotmap = strslotmap + ais[i].Value.ToString("D1");
  1322. }
  1323. if(IsVerifyPreDefineWaferCount)
  1324. {
  1325. if(WaferCount != PreDefineWaferCount)
  1326. {
  1327. EV.PostAlarmLog("LoadPort", $"{LPModuleName} mapping error,predefine count is {PreDefineWaferCount}, " +
  1328. $"Mapping result is {WaferCount}.");
  1329. OnError("Mapping Error");
  1330. }
  1331. }
  1332. OnSlotMapRead(strslotmap);
  1333. }
  1334. private bool _isDisableEvenSlot
  1335. {
  1336. get
  1337. {
  1338. if (SC.ContainsItem($"CarrierInfo.DisableEvenSlot{InfoPadCarrierIndex}"))
  1339. return SC.GetValue<bool>($"CarrierInfo.DisableEvenSlot{InfoPadCarrierIndex}");
  1340. if (SC.ContainsItem($"CarrierInfo.Carrier{InfoPadCarrierIndex}.DisableEvenSlot"))
  1341. return SC.GetValue<bool>($"CarrierInfo.Carrier{InfoPadCarrierIndex}.DisableEvenSlot");
  1342. return false;
  1343. }
  1344. }
  1345. private bool _isDisableOddSlot
  1346. {
  1347. get
  1348. {
  1349. if (SC.ContainsItem($"CarrierInfo.DisableOddSlot{InfoPadCarrierIndex}"))
  1350. return SC.GetValue<bool>($"CarrierInfo.DisableOddSlot{InfoPadCarrierIndex}");
  1351. if (SC.ContainsItem($"CarrierInfo.Carrier{InfoPadCarrierIndex}.DisableOddSlot"))
  1352. return SC.GetValue<bool>($"CarrierInfo.Carrier{InfoPadCarrierIndex}.DisableOddSlot");
  1353. return false;
  1354. }
  1355. }
  1356. protected override bool fStartRead(object[] param)
  1357. {
  1358. return true;
  1359. }
  1360. protected override bool fStartReset(object[] param)
  1361. {
  1362. if(!_doResetCommand.Value)
  1363. {
  1364. _doResetCommand.SetValue(true, out _);
  1365. }
  1366. else
  1367. {
  1368. _doResetCommand.SetValue(false, out _);
  1369. Thread.Sleep(1000);
  1370. _doResetCommand.SetValue(true, out _);
  1371. }
  1372. _doLoadCommand.SetValue(false, out _);
  1373. _doUnloadCommand.SetValue(false, out _);
  1374. _actionStartTime = DateTime.Now;
  1375. return true;
  1376. }
  1377. protected override bool fMonitorReset(object[] param)
  1378. {
  1379. IsBusy = false;
  1380. if(DateTime.Now - _actionStartTime>TimeSpan.FromSeconds(10))
  1381. {
  1382. OnError("Reset Timeout");
  1383. _doResetCommand.SetValue(false, out _);
  1384. return false;
  1385. }
  1386. if(_diAck_Reset.Value)
  1387. {
  1388. _doResetCommand.SetValue(false, out _);
  1389. _errorCode = 0;
  1390. _lastErrorCode = 0;
  1391. return true;
  1392. }
  1393. return false;
  1394. }
  1395. protected override bool fStartUnload(object[] param)
  1396. {
  1397. _actionTimeLimit = SC.ContainsItem($"LoadPort.{Name}.TimeLimitLoadportUnload") ?
  1398. SC.GetValue<int>($"LoadPort.{Name}.TimeLimitLoadportUnload") : 45;
  1399. ResetRoutine();
  1400. _isNeedLoadRecipe = _aiRECIPE_TYPE_FEEDBACK.Value !=(short)_intRecipeNum;
  1401. return true;
  1402. }
  1403. public override int ValidSlotsNumber
  1404. {
  1405. get
  1406. {
  1407. if (SC.ContainsItem($"CarrierInfo.CarrierSlotsNumber{InfoPadCarrierIndex}"))
  1408. return SC.GetValue<int>($"CarrierInfo.CarrierSlotsNumber{InfoPadCarrierIndex}");
  1409. if (SC.ContainsItem($"CarrierInfo.Carrier{InfoPadCarrierIndex}.CarrierSlotsNumber"))
  1410. return SC.GetValue<int>($"CarrierInfo.Carrier{InfoPadCarrierIndex}.CarrierSlotsNumber");
  1411. return 25;
  1412. }
  1413. }
  1414. private bool _isKeepClampAfterUnload
  1415. {
  1416. get
  1417. {
  1418. if (SC.ContainsItem($"CarrierInfo.KeepClampedAfterUnloadCarrier{InfoPadCarrierIndex}"))
  1419. return SC.GetValue<bool>($"CarrierInfo.KeepClampedAfterUnloadCarrier{InfoPadCarrierIndex}");
  1420. if (SC.ContainsItem($"CarrierInfo.Carrier{InfoPadCarrierIndex}.KeepClampedAfterUnloadCarrier"))
  1421. return SC.GetValue<bool>($"CarrierInfo.Carrier{InfoPadCarrierIndex}.KeepClampedAfterUnloadCarrier");
  1422. return false;
  1423. }
  1424. }
  1425. protected override bool fMonitorUnload(object[] param)
  1426. {
  1427. IsBusy = false;
  1428. try
  1429. {
  1430. if (_isNeedLoadRecipe)
  1431. {
  1432. SetAoValue((int)LoadPortStepEnum.LoadRecipe1, _aoSAVECurrentRecipeNumber, (short)_intRecipeNum, Notify);
  1433. SetDoState((int)LoadPortStepEnum.LoadRecipe2, _doRecipeLoadCommand, true, Notify);
  1434. WaitDiState((int)LoadPortStepEnum.LoadRecipe3, _actionTimeLimit, _diAck_RecipeLoad, true, Notify, Stop);
  1435. WaitAiValue((int)LoadPortStepEnum.LoadRecipe4, _actionTimeLimit, _aiRECIPE_TYPE_FEEDBACK, (short)_intRecipeNum, Notify, Stop);
  1436. SetDoState((int)LoadPortStepEnum.LoadRecipe5, _doRecipeLoadCommand, false, Notify);
  1437. WaitDiState((int)LoadPortStepEnum.LoadRecipe6, _actionTimeLimit, _diAck_RecipeLoad, false, Notify, Stop);
  1438. }
  1439. SetDoState((int)LoadPortStepEnum.ActionStep1, _doUnloadCommand, true, Notify);
  1440. WaitDiState((int)LoadPortStepEnum.ActionStep2, _actionTimeLimit, _diAck_Unload, true, Notify, Stop);
  1441. SetDoState((int)LoadPortStepEnum.ActionStep3, _doUnloadCommand, false, Notify);
  1442. WaitDiState((int)LoadPortStepEnum.ActionStep4, _actionTimeLimit, _diAck_Unload, false, Notify, Stop);
  1443. if(_isKeepClampAfterUnload)
  1444. {
  1445. SetDoState((int)LoadPortStepEnum.ActionStep5, _doClampOnCommand, true, Notify);
  1446. WaitDiState((int)LoadPortStepEnum.ActionStep6, _actionTimeLimit, _diAck_ClampOn, true, Notify, Stop);
  1447. SetDoState((int)LoadPortStepEnum.ActionStep7, _doClampOnCommand, false, Notify);
  1448. WaitDiState((int)LoadPortStepEnum.ActionStep8, _actionTimeLimit, _diAck_ClampOn, false, Notify, Stop);
  1449. }
  1450. else
  1451. {
  1452. base.OnUnloaded();
  1453. }
  1454. }
  1455. catch (RoutineBreakException)
  1456. {
  1457. return false;
  1458. }
  1459. catch (RoutineFaildException)
  1460. {
  1461. EV.Notify(AlarmLoadPortUnloadTimeOut);
  1462. OnError("UnloadFailed");
  1463. return true;
  1464. }
  1465. return true;
  1466. }
  1467. protected override bool fStartWrite(object[] param)
  1468. {
  1469. return true;
  1470. }
  1471. protected override bool fStartExecute(object[] param)
  1472. {
  1473. _actionStartTime = DateTime.Now;
  1474. try
  1475. {
  1476. switch (param[0].ToString())
  1477. {
  1478. case "SetIndicator":
  1479. _currentExecuteCommand = "SetIndicator";
  1480. Indicator light = (Indicator)param[1];
  1481. IndicatorState state = (IndicatorState)param[2];
  1482. switch(light)
  1483. {
  1484. case Indicator.LOAD:
  1485. if (state == IndicatorState.BLINK || state == IndicatorState.ON)
  1486. _doLoadLight.SetValue(true, out _);
  1487. if (state == IndicatorState.OFF)
  1488. _doLoadLight.SetValue(false, out _);
  1489. break;
  1490. case Indicator.UNLOAD:
  1491. if (state == IndicatorState.BLINK || state == IndicatorState.ON)
  1492. _doUnloadLight.SetValue(true, out _);
  1493. if (state == IndicatorState.OFF)
  1494. _doUnloadLight.SetValue(false, out _);
  1495. break;
  1496. case Indicator.ACCESSAUTO:
  1497. if (state == IndicatorState.BLINK || state == IndicatorState.ON)
  1498. _doStatu1Light.SetValue(true, out _);
  1499. if (state == IndicatorState.OFF)
  1500. _doStatu1Light.SetValue(false, out _);
  1501. break;
  1502. case Indicator.ACCESSMANUL:
  1503. if (state == IndicatorState.BLINK || state == IndicatorState.ON)
  1504. _doStatu2Light.SetValue(true, out _);
  1505. if (state == IndicatorState.OFF)
  1506. _doStatu2Light.SetValue(false, out _);
  1507. break;
  1508. }
  1509. break;
  1510. case "QueryIndicator":
  1511. break;
  1512. case "QueryState":
  1513. _currentExecuteCommand = "QueryState";
  1514. break;
  1515. case "Undock":
  1516. _currentExecuteCommand = "Undock";
  1517. _doDOCKHomeCommand.SetValue(true, out _);
  1518. _doDOCKForwardCommand.SetValue(false, out _);
  1519. break;
  1520. case "Dock":
  1521. if (!CheckAndLoadRecipe())
  1522. return false;
  1523. _currentExecuteCommand = "Dock";
  1524. _doDOCKHomeCommand.SetValue(false, out _);
  1525. _doDOCKForwardCommand.SetValue(true, out _);
  1526. break;
  1527. case "CloseDoor":
  1528. _currentExecuteCommand = "CloseDoor";
  1529. _doDoorOpenCommand.SetValue(false, out _);
  1530. _doDoorCloseCommand.SetValue(true, out _);
  1531. break;
  1532. case "OpenDoor":
  1533. _currentExecuteCommand = "CloseDoor";
  1534. _doDoorOpenCommand.SetValue(true, out _);
  1535. _doDoorCloseCommand.SetValue(false, out _);
  1536. break;
  1537. case "Unclamp":
  1538. _currentExecuteCommand = "Unclamp";
  1539. _doClampOffCommand.SetValue(true, out _);
  1540. _doClampOnCommand.SetValue(false, out _);
  1541. break;
  1542. case "Clamp":
  1543. if (!CheckAndLoadRecipe())
  1544. return false;
  1545. _currentExecuteCommand = "Clamp";
  1546. _doClampOffCommand.SetValue(false, out _);
  1547. _doClampOnCommand.SetValue(true, out _);
  1548. break;
  1549. case "DoorUp":
  1550. _currentExecuteCommand = "DoorUp";
  1551. _doVertiaclDownCommand.SetValue(false, out _);
  1552. _doVertiaclUpCommand.SetValue(true, out _);
  1553. break;
  1554. case "DoorDown":
  1555. _currentExecuteCommand = "DoorDown";
  1556. _doVertiaclDownCommand.SetValue(true, out _);
  1557. _doVertiaclUpCommand.SetValue(false, out _);
  1558. break;
  1559. case "MapWafer":
  1560. //_currentExecuteCommand = "MapWafer";
  1561. //_doZtoMAPPINGSTARTPOSI.SetValue(true, out _);
  1562. break;
  1563. case "DoorUpAndClose":
  1564. _currentExecuteCommand = "DoorUpAndClose";
  1565. _doVertiaclUpCommand.SetValue(true, out _);
  1566. break;
  1567. case "OpenDoorAndDown":
  1568. _currentExecuteCommand = "DoorUpAndClose";
  1569. _doDoorOpenCommand.SetValue(true, out _);
  1570. break;
  1571. case "Move":
  1572. HandlerMoveCommand(param[1].ToString());
  1573. break;
  1574. case "Set":
  1575. break;
  1576. case "Get":
  1577. break;
  1578. }
  1579. return true;
  1580. }
  1581. catch (Exception ex)
  1582. {
  1583. LOG.Write(ex);
  1584. EV.PostAlarmLog(Name, $"Parameter invalid");
  1585. return false;
  1586. }
  1587. }
  1588. private void HandlerMoveCommand(string movecommand)
  1589. {
  1590. switch(movecommand)
  1591. {
  1592. case "PODCL":
  1593. _currentExecuteCommand = "Clamp";
  1594. _doClampOffCommand.SetValue(false, out _);
  1595. _doClampOnCommand.SetValue(true, out _);
  1596. break;
  1597. case "YDOOR":
  1598. _currentExecuteCommand = "Dock";
  1599. _doDOCKHomeCommand.SetValue(false, out _);
  1600. _doDOCKForwardCommand.SetValue(true, out _);
  1601. break;
  1602. case "VACON":
  1603. _currentExecuteCommand = "VacuumOn";
  1604. _doVACOnCommand.SetValue(true, out _);
  1605. _doVACOffCommand.SetValue(false, out _);
  1606. break;
  1607. case "DOROP":
  1608. _currentExecuteCommand = "UnlatchDoor";
  1609. _doLatchOffCommand.SetValue(true, out _);
  1610. _doLatchOnCommand.SetValue(false, out _);
  1611. break;
  1612. case "ZMPST":
  1613. _currentExecuteCommand = "MoveToMapStart";
  1614. _doZtoMAPPINGSTARTPOSI.SetValue(true, out _);
  1615. _doZtoMAPPINGENDPOSI.SetValue(false, out _);
  1616. break;
  1617. case "MAPOP":
  1618. _currentExecuteCommand = "MoveToMapMeasurement";
  1619. break;
  1620. case "ZDRMP":
  1621. _currentExecuteCommand = "MoveToMapEnd";
  1622. _doZtoMAPPINGSTARTPOSI.SetValue(false, out _);
  1623. _doZtoMAPPINGENDPOSI.SetValue(true, out _);
  1624. break;
  1625. case "MAPCL":
  1626. _currentExecuteCommand = "MoveToMapWait";
  1627. break;
  1628. case "ZDRDW":
  1629. _currentExecuteCommand = "MoveToLoadPosition";
  1630. break;
  1631. case "ZDRUP":
  1632. _currentExecuteCommand = "MoveToDoorOpenClosePostion";
  1633. _doVertiaclUpCommand.SetValue(true, out _);
  1634. _doVertiaclDownCommand.SetValue(false, out _);
  1635. break;
  1636. case "DORFW":
  1637. _currentExecuteCommand = "CloseDoor";
  1638. _doDoorCloseCommand.SetValue(true, out _);
  1639. _doDoorOpenCommand.SetValue(false, out _);
  1640. break;
  1641. case "DORCL":
  1642. _currentExecuteCommand = "LatchDoor";
  1643. _doLatchOnCommand.SetValue(true, out _);
  1644. _doLatchOffCommand.SetValue(false, out _);
  1645. break;
  1646. case "VACOF":
  1647. _currentExecuteCommand = "VacuumOff";
  1648. _doVACOffCommand.SetValue(true, out _);
  1649. _doVACOnCommand.SetValue(false, out _);
  1650. break;
  1651. case "YWAIT":
  1652. _currentExecuteCommand = "Undock";
  1653. _doDOCKHomeCommand.SetValue(true, out _);
  1654. _doDOCKForwardCommand.SetValue(false, out _);
  1655. break;
  1656. case "PODOP":
  1657. _currentExecuteCommand = "Unclamp";
  1658. _doClampOffCommand.SetValue(true, out _);
  1659. _doClampOnCommand.SetValue(false, out _);
  1660. break;
  1661. case "ORGSH":
  1662. _currentExecuteCommand = "ORGSH";
  1663. _doIntialCommand.SetValue(true, out _);
  1664. break;
  1665. default:
  1666. break;
  1667. }
  1668. }
  1669. private string _currentExecuteCommand;
  1670. protected override bool fMonitorExecuting(object[] param)
  1671. {
  1672. IsBusy = false;
  1673. int timelimit = SC.ContainsItem($"LoadPort.{Name}.TimeLimitAction") ?
  1674. SC.GetValue<int>($"LoadPort.{Name}.TimeLimitAction") : 45;
  1675. if (DateTime.Now - _actionStartTime > TimeSpan.FromSeconds(timelimit))
  1676. {
  1677. OnError("Execute command timeout");
  1678. return true;
  1679. }
  1680. switch(_currentExecuteCommand)
  1681. {
  1682. case "SetIndicator":
  1683. return true;
  1684. case "Clamp":
  1685. if (_diAck_ClampOn.Value)
  1686. {
  1687. _doClampOnCommand.SetValue(false, out _);
  1688. return true;
  1689. }
  1690. break;
  1691. case "Unclamp":
  1692. if (_diAck_ClampOff.Value)
  1693. {
  1694. _doClampOffCommand.SetValue(false, out _);
  1695. if (_diDockHomeSensor.Value)
  1696. base.OnUnloaded();
  1697. return true;
  1698. }
  1699. break;
  1700. case "Dock":
  1701. if (_diAck_DockFwd.Value)
  1702. {
  1703. _doDOCKForwardCommand.SetValue(false, out _);
  1704. return true;
  1705. }
  1706. break;
  1707. case "Undock":
  1708. if (_diAck_DockFwd.Value)
  1709. {
  1710. _doDOCKHomeCommand.SetValue(false, out _);
  1711. return true;
  1712. }
  1713. break;
  1714. case "VacuumOn":
  1715. if(_diAck_VacOn.Value)
  1716. {
  1717. _doVACOnCommand.SetValue(false, out _);
  1718. return true;
  1719. }
  1720. break;
  1721. case "VacuumOff":
  1722. if(_diAck_VacOff.Value)
  1723. {
  1724. _doVACOffCommand.SetValue(false, out _);
  1725. return true;
  1726. }
  1727. break;
  1728. case "LatchDoor":
  1729. if(_diAck_LatchOn.Value)
  1730. {
  1731. _doLatchOnCommand.SetValue(false, out _);
  1732. return true;
  1733. }
  1734. break;
  1735. case "UnlatchDoor":
  1736. if(_diAck_LatchOff.Value)
  1737. {
  1738. _doLatchOffCommand.SetValue(false, out _);
  1739. return true;
  1740. }
  1741. break;
  1742. case "OpenDoor":
  1743. if(_diAck_DoorOpen.Value)
  1744. {
  1745. _doDoorOpenCommand.SetValue(false, out _);
  1746. return true;
  1747. }
  1748. break;
  1749. case "CloseDoor":
  1750. if(_diAck_DoorClose.Value)
  1751. {
  1752. _doDoorCloseCommand.SetValue(false, out _);
  1753. return true;
  1754. }
  1755. break;
  1756. case "MoveToDoorOpenClosePostion":
  1757. case "DoorUp":
  1758. if (_diAck_VerticalUp.Value)
  1759. {
  1760. _doVertiaclUpCommand.SetValue(false, out _);
  1761. return true;
  1762. }
  1763. break;
  1764. case "MoveToMapStart":
  1765. if(_diAck_ZtoMapStart.Value)
  1766. {
  1767. _doZtoMAPPINGSTARTPOSI.SetValue(false, out _);
  1768. return true;
  1769. }
  1770. break;
  1771. case "MoveToMapEnd":
  1772. if(_diAck_ZtoMapEnd.Value)
  1773. {
  1774. _doZtoMAPPINGENDPOSI.SetValue(false, out _);
  1775. return true;
  1776. }
  1777. break;
  1778. case "DoorDown":
  1779. if(_diAck_VerticalDown.Value)
  1780. {
  1781. _doVertiaclDownCommand.SetValue(false, out _);
  1782. return true;
  1783. }
  1784. break;
  1785. case "ORGSH":
  1786. if(_diAck_Init.Value)
  1787. {
  1788. _doIntialCommand.SetValue(false, out _);
  1789. return true;
  1790. }
  1791. break;
  1792. case "MapWafer":
  1793. //if(_diAck_Mapin)
  1794. default:
  1795. return true;
  1796. }
  1797. return base.fMonitorExecuting(param);
  1798. }
  1799. public override bool SetIndicator(Indicator light, IndicatorState state, out string reason)
  1800. {
  1801. reason = "";
  1802. return fStartExecute(new object[] { "SetIndicator", light, state });
  1803. }
  1804. public DOAccessor ParseDoNode(string name, XmlElement node, string ioModule = "")
  1805. {
  1806. if (!string.IsNullOrEmpty(node.GetAttribute(name).Trim()))
  1807. return IO.DO[string.IsNullOrEmpty(ioModule) ? node.GetAttribute(name).Trim() : $"{ioModule}.{node.GetAttribute(name).Trim()}"];
  1808. return null;
  1809. }
  1810. public DIAccessor ParseDiNode(string name, XmlElement node, string ioModule = "")
  1811. {
  1812. if (!string.IsNullOrEmpty(node.GetAttribute(name).Trim()))
  1813. return IO.DI[string.IsNullOrEmpty(ioModule) ? node.GetAttribute(name).Trim() : $"{ioModule}.{node.GetAttribute(name).Trim()}"];
  1814. return null;
  1815. }
  1816. public AOAccessor ParseAoNode(string name, XmlElement node, string ioModule = "")
  1817. {
  1818. if (!string.IsNullOrEmpty(node.GetAttribute(name).Trim()))
  1819. return IO.AO[string.IsNullOrEmpty(ioModule) ? node.GetAttribute(name).Trim() : $"{ioModule}.{node.GetAttribute(name).Trim()}"];
  1820. return null;
  1821. }
  1822. public AIAccessor ParseAiNode(string name, XmlElement node, string ioModule = "")
  1823. {
  1824. if (!string.IsNullOrEmpty(node.GetAttribute(name).Trim()))
  1825. return IO.AI[string.IsNullOrEmpty(ioModule) ? node.GetAttribute(name).Trim() : $"{ioModule}.{node.GetAttribute(name).Trim()}"];
  1826. return null;
  1827. }
  1828. public SCConfigItem ParseScNode(string name, XmlElement node, string ioModule = "", string defaultScPath = "")
  1829. {
  1830. SCConfigItem result = null;
  1831. if (!string.IsNullOrEmpty(node.GetAttribute(name).Trim()))
  1832. result = SC.GetConfigItem(node.GetAttribute(name));
  1833. if (result == null && !string.IsNullOrEmpty(defaultScPath) && SC.ContainsItem(defaultScPath))
  1834. result = SC.GetConfigItem(defaultScPath);
  1835. return result;
  1836. }
  1837. public static T ParseDeviceNode<T>(string name, XmlElement node) where T : class, IDevice
  1838. {
  1839. if (!string.IsNullOrEmpty(node.GetAttribute(name).Trim()))
  1840. return DEVICE.GetDevice<T>(node.GetAttribute(name));
  1841. LOG.Write(string.Format("{0},未定义{1}", node.InnerXml, name));
  1842. return null;
  1843. }
  1844. public static T ParseDeviceNode<T>(string module, string name, XmlElement node) where T : class, IDevice
  1845. {
  1846. string device_id = node.GetAttribute(name);
  1847. if (!string.IsNullOrEmpty(device_id) && !string.IsNullOrEmpty(device_id.Trim()))
  1848. {
  1849. return DEVICE.GetDevice<T>($"{module}.{device_id}");
  1850. }
  1851. LOG.Write(string.Format("{0},undefined {1}", node.InnerXml, name));
  1852. return null;
  1853. }
  1854. public enum CarrierMode
  1855. {
  1856. Foup,
  1857. Fosb,
  1858. OpenCassette,
  1859. }
  1860. private void SetAoValue(int id, AOAccessor ao, short value,Action<string> notify)
  1861. {
  1862. var ret = Execute(id, () =>
  1863. {
  1864. notify($"{LPModuleName} set {ao.Name} to {value}.");
  1865. ao.Value = value;
  1866. return true;
  1867. });
  1868. if (ret.Item1)
  1869. {
  1870. if (ret.Item2 == Result.FAIL)
  1871. {
  1872. throw new RoutineFaildException();
  1873. }
  1874. }
  1875. }
  1876. private void WaitAiValue(int id, int time, AIAccessor ai, short value, Action<string> notify, Action<string> error)
  1877. {
  1878. var ret = ExecuteAndWait(id, () =>
  1879. {
  1880. notify($"Wait {LPModuleName} {ai.Name} to be {value}");
  1881. return true;
  1882. }, () =>
  1883. {
  1884. if (ai.Value == value)
  1885. return true;
  1886. return false;
  1887. }, time * 1000);
  1888. if (ret.Item1)
  1889. {
  1890. if (ret.Item2 == Result.FAIL)
  1891. {
  1892. throw new RoutineFaildException();
  1893. }
  1894. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1895. {
  1896. EV.Notify(AlarmLoadPortError);
  1897. error($"Wait {LPModuleName} {ai.Name} to be {value} timeout after {time} seconds");
  1898. throw new RoutineFaildException();
  1899. }
  1900. else
  1901. {
  1902. throw new RoutineBreakException();
  1903. }
  1904. }
  1905. }
  1906. private void WaitDiState(int id, int time, DIAccessor di,bool state, Action<string> notify, Action<string> error)
  1907. {
  1908. var ret = ExecuteAndWait(id, () =>
  1909. {
  1910. notify($"Wait {LPModuleName} {di.Name} to be {state}");
  1911. return true;
  1912. }, () =>
  1913. {
  1914. if (di.Value == state)
  1915. return true;
  1916. return false;
  1917. }, time * 1000);
  1918. if (ret.Item1)
  1919. {
  1920. if (ret.Item2 == Result.FAIL)
  1921. {
  1922. throw new RoutineFaildException();
  1923. }
  1924. else if (ret.Item2 == Result.TIMEOUT) //timeout
  1925. {
  1926. EV.Notify(AlarmLoadPortError);
  1927. error($"Wait {LPModuleName} {di.Name} to be {state} timeout after {time} seconds");
  1928. throw new RoutineFaildException();
  1929. }
  1930. else
  1931. {
  1932. throw new RoutineBreakException();
  1933. }
  1934. }
  1935. }
  1936. private void SetDoState(int id, DOAccessor _do, bool state, Action<string> notify)
  1937. {
  1938. var ret = Execute(id, () =>
  1939. {
  1940. notify($"{LPModuleName} start set {_do.Name} to {state}.");
  1941. if (_do.Value == state)
  1942. {
  1943. _do.Value = !state;
  1944. Thread.Sleep(500);
  1945. }
  1946. return _do.SetValue(state, out _);
  1947. });
  1948. if (ret.Item1)
  1949. {
  1950. if (ret.Item2 == Result.FAIL)
  1951. {
  1952. throw new RoutineFaildException();
  1953. }
  1954. }
  1955. }
  1956. protected void Notify(string message)
  1957. {
  1958. EV.PostMessage(Name, EventEnum.GeneralInfo, string.Format("{0}:{1}", Name, message));
  1959. }
  1960. protected void Stop(string failReason)
  1961. {
  1962. OnError(string.Format("Failed {0}, {1} ", Name, failReason));
  1963. }
  1964. private enum LoadPortStepEnum
  1965. {
  1966. LoadRecipe1,
  1967. LoadRecipe2,
  1968. LoadRecipe3,
  1969. LoadRecipe4,
  1970. LoadRecipe5,
  1971. LoadRecipe6,
  1972. ActionStep1,
  1973. ActionStep2,
  1974. ActionStep3,
  1975. ActionStep4,
  1976. ActionStep5,
  1977. ActionStep6,
  1978. ActionStep7,
  1979. ActionStep8,
  1980. ActionStep9,
  1981. ActionStep10,
  1982. ActionStep11,
  1983. ActionStep12,
  1984. ActionStep13,
  1985. ActionStep14,
  1986. ActionStep15,
  1987. ActionStep16,
  1988. }
  1989. //timer, 计算routine时间
  1990. protected DeviceTimer counter = new DeviceTimer();
  1991. protected DeviceTimer delayTimer = new DeviceTimer();
  1992. private enum STATE
  1993. {
  1994. IDLE,
  1995. WAIT,
  1996. }
  1997. public int TokenId
  1998. {
  1999. get { return _id; }
  2000. }
  2001. private int _id; //step index
  2002. /// <summary>
  2003. /// already done steps
  2004. /// </summary>
  2005. private Stack<int> _steps = new Stack<int>();
  2006. private STATE state; //step state //idel,wait,
  2007. //loop control
  2008. private int loop = 0;
  2009. private int loopCount = 0;
  2010. private int loopID = 0;
  2011. private DeviceTimer timer = new DeviceTimer();
  2012. public int LoopCounter { get { return loop; } }
  2013. public int LoopTotalTime { get { return loopCount; } }
  2014. // public int Timeout { get { return (int)(timer.GetTotalTime() / 1000); } }
  2015. //状态持续时间,单位为秒
  2016. public int Elapsed { get { return (int)(timer.GetElapseTime() / 1000); } }
  2017. protected RoutineResult RoutineToken = new RoutineResult() { Result = RoutineState.Running };
  2018. public void ResetRoutine()
  2019. {
  2020. _id = 0;
  2021. _steps.Clear();
  2022. loop = 0;
  2023. loopCount = 0;
  2024. state = STATE.IDLE;
  2025. counter.Start(60 * 60 * 100); //默认1小时
  2026. RoutineToken.Result = RoutineState.Running;
  2027. }
  2028. protected void PerformRoutineStep(int id, Func<RoutineState> execution, RoutineResult result)
  2029. {
  2030. if (!Acitve(id))
  2031. return;
  2032. result.Result = execution();
  2033. }
  2034. #region interface
  2035. public void StopLoop()
  2036. {
  2037. loop = loopCount;
  2038. }
  2039. public Tuple<bool, Result> Loop<T>(T id, Func<bool> func, int count)
  2040. {
  2041. int idx = Convert.ToInt32(id);
  2042. bool bActive = Acitve(idx);
  2043. if (bActive)
  2044. {
  2045. if (!func())
  2046. {
  2047. return Tuple.Create(bActive, Result.FAIL); //执行错误
  2048. }
  2049. loopID = idx;
  2050. loopCount = count;
  2051. next();
  2052. return Tuple.Create(true, Result.RUN);
  2053. }
  2054. return Tuple.Create(false, Result.RUN);
  2055. }
  2056. public Tuple<bool, Result> EndLoop<T>(T id, Func<bool> func)
  2057. {
  2058. int idx = Convert.ToInt32(id);
  2059. bool bActive = Acitve(idx);
  2060. if (bActive)
  2061. {
  2062. if (++loop >= loopCount) //Loop 结束
  2063. {
  2064. if (!func())
  2065. {
  2066. return Tuple.Create(bActive, Result.FAIL); //执行错误
  2067. }
  2068. loop = 0;
  2069. loopCount = 0; // Loop 结束时,当前loop和loop总数都清零
  2070. next();
  2071. return Tuple.Create(true, Result.RUN);
  2072. }
  2073. //继续下一LOOP
  2074. next(loopID);
  2075. return Tuple.Create(true, Result.RUN);
  2076. }
  2077. return Tuple.Create(false, Result.RUN);
  2078. }
  2079. public Tuple<bool, Result> ExecuteAndWait<T>(T id, IRoutine routine)
  2080. {
  2081. int idx = Convert.ToInt32(id);
  2082. bool bActive = Acitve(idx);
  2083. if (bActive)
  2084. {
  2085. if (state == STATE.IDLE)
  2086. {
  2087. Result startRet = routine.Start();
  2088. if (startRet == Result.FAIL)
  2089. {
  2090. return Tuple.Create(true, Result.FAIL); //执行错误
  2091. }
  2092. else if (startRet == Result.DONE)
  2093. {
  2094. next();
  2095. return Tuple.Create(true, Result.DONE);
  2096. }
  2097. state = STATE.WAIT;
  2098. }
  2099. Result ret = routine.Monitor();
  2100. if (ret == Result.DONE)
  2101. {
  2102. next();
  2103. return Tuple.Create(true, Result.DONE);
  2104. }
  2105. else if (ret == Result.FAIL || ret == Result.TIMEOUT)
  2106. {
  2107. return Tuple.Create(true, Result.FAIL);
  2108. }
  2109. else
  2110. {
  2111. return Tuple.Create(true, Result.RUN);
  2112. }
  2113. }
  2114. return Tuple.Create(false, Result.RUN);
  2115. }
  2116. public Tuple<bool, Result> ExecuteAndWait<T>(T id, List<IRoutine> routines)
  2117. {
  2118. int idx = Convert.ToInt32(id);
  2119. bool bActive = Acitve(idx);
  2120. if (bActive)
  2121. {
  2122. if (state == STATE.IDLE)
  2123. {
  2124. foreach (var item in routines)
  2125. {
  2126. if (item.Start() == Result.FAIL)
  2127. return Tuple.Create(true, Result.FAIL);
  2128. }
  2129. state = STATE.WAIT;
  2130. }
  2131. //wait all sub failed or completedboo
  2132. bool bFail = false;
  2133. bool bDone = true;
  2134. foreach (var item in routines)
  2135. {
  2136. Result ret = item.Monitor();
  2137. bDone &= (ret == Result.FAIL || ret == Result.DONE);
  2138. bFail |= ret == Result.FAIL;
  2139. }
  2140. if (bDone)
  2141. {
  2142. next();
  2143. if (bFail)
  2144. return Tuple.Create(true, Result.FAIL);
  2145. return Tuple.Create(true, Result.DONE);
  2146. }
  2147. return Tuple.Create(true, Result.RUN);
  2148. }
  2149. return Tuple.Create(false, Result.RUN);
  2150. }
  2151. public Tuple<bool, Result> Check<T>(T id, Func<bool> func) //顺序执行
  2152. {
  2153. return Check(Check(Convert.ToInt32(id), func));
  2154. }
  2155. public Tuple<bool, Result> Execute<T>(T id, Func<bool> func) //顺序执行
  2156. {
  2157. return Check(execute(Convert.ToInt32(id), func));
  2158. }
  2159. public Tuple<bool, Result> Wait<T>(T id, Func<bool> func, double timeout = int.MaxValue) //Wait condition
  2160. {
  2161. return Check(wait(Convert.ToInt32(id), func, timeout));
  2162. }
  2163. public Tuple<bool, Result> Wait<T>(T id, Func<bool?> func, double timeout = int.MaxValue) //Wait condition
  2164. {
  2165. return Check(wait(Convert.ToInt32(id), func, timeout));
  2166. }
  2167. public Tuple<bool, Result> ExecuteAndWait<T>(T id, Func<bool> execute, Func<bool?> check, double timeout = int.MaxValue)
  2168. {
  2169. int idx = Convert.ToInt32(id);
  2170. bool bActive = Acitve(idx);
  2171. bool? bExecute = false;
  2172. if (bActive)
  2173. {
  2174. if (state == STATE.IDLE)
  2175. {
  2176. if (!execute())
  2177. {
  2178. return Tuple.Create(bActive, Result.FAIL); //执行错误
  2179. }
  2180. timer.Start(timeout);
  2181. state = STATE.WAIT;
  2182. }
  2183. bExecute = check();
  2184. if (bExecute == null)
  2185. {
  2186. return Tuple.Create(bActive, Result.FAIL); //Termianate
  2187. }
  2188. else
  2189. {
  2190. if (bExecute.Value) //检查Success, next
  2191. {
  2192. next();
  2193. return Tuple.Create(true, Result.RUN);
  2194. }
  2195. }
  2196. if (timer.IsTimeout())
  2197. return Tuple.Create(true, Result.TIMEOUT);
  2198. return Tuple.Create(true, Result.RUN);
  2199. }
  2200. return Tuple.Create(false, Result.RUN);
  2201. }
  2202. public Tuple<bool, Result> ExecuteAndWait<T>(T id, Func<bool> execute, Func<bool?> check, Func<double> time)
  2203. {
  2204. int idx = Convert.ToInt32(id);
  2205. bool bActive = Acitve(idx);
  2206. bool? bExecute = false;
  2207. double timeout = 0;
  2208. if (bActive)
  2209. {
  2210. if (state == STATE.IDLE)
  2211. {
  2212. timeout = time();
  2213. if (!execute())
  2214. {
  2215. return Tuple.Create(true, Result.FAIL); //执行错误
  2216. }
  2217. timer.Start(timeout);
  2218. state = STATE.WAIT;
  2219. }
  2220. bExecute = check();
  2221. if (bExecute == null)
  2222. {
  2223. return Tuple.Create(true, Result.FAIL); //Termianate
  2224. }
  2225. if (bExecute.Value) //检查Success, next
  2226. {
  2227. next();
  2228. return Tuple.Create(true, Result.RUN);
  2229. }
  2230. if (timer.IsTimeout())
  2231. return Tuple.Create(true, Result.TIMEOUT);
  2232. return Tuple.Create(true, Result.RUN);
  2233. }
  2234. return Tuple.Create(false, Result.RUN);
  2235. }
  2236. public Tuple<bool, Result> Wait<T>(T id, IRoutine rt)
  2237. {
  2238. int idx = Convert.ToInt32(id);
  2239. bool bActive = Acitve(idx);
  2240. if (bActive)
  2241. {
  2242. if (state == STATE.IDLE)
  2243. {
  2244. rt.Start();
  2245. state = STATE.WAIT;
  2246. }
  2247. Result ret = rt.Monitor();
  2248. return Tuple.Create(true, ret);
  2249. }
  2250. return Tuple.Create(false, Result.RUN);
  2251. }
  2252. //Monitor
  2253. public Tuple<bool, Result> Monitor<T>(T id, Func<bool> func, Func<bool> check, double time)
  2254. {
  2255. int idx = Convert.ToInt32(id);
  2256. bool bActive = Acitve(idx);
  2257. bool bCheck = false;
  2258. if (bActive)
  2259. {
  2260. if (state == STATE.IDLE)
  2261. {
  2262. if ((func != null) && !func())
  2263. {
  2264. return Tuple.Create(true, Result.FAIL);
  2265. }
  2266. timer.Start(time);
  2267. state = STATE.WAIT;
  2268. }
  2269. bCheck = check();
  2270. if (!bCheck)
  2271. {
  2272. return Tuple.Create(true, Result.FAIL); //Termianate
  2273. }
  2274. if (timer.IsTimeout())
  2275. {
  2276. next();
  2277. }
  2278. return Tuple.Create(true, Result.RUN);
  2279. }
  2280. return Tuple.Create(false, Result.RUN);
  2281. }
  2282. //Delay
  2283. public Tuple<bool, Result> Delay<T>(T id, Func<bool> func, double time)
  2284. {
  2285. int idx = Convert.ToInt32(id);
  2286. bool bActive = Acitve(idx);
  2287. if (bActive)
  2288. {
  2289. if (state == STATE.IDLE)
  2290. {
  2291. if ((func != null) && !func())
  2292. {
  2293. return Tuple.Create(true, Result.FAIL);
  2294. }
  2295. timer.Start(time);
  2296. state = STATE.WAIT;
  2297. }
  2298. if (timer.IsTimeout())
  2299. {
  2300. next();
  2301. }
  2302. return Tuple.Create(true, Result.RUN);
  2303. }
  2304. return Tuple.Create(false, Result.RUN);
  2305. }
  2306. //先delay 再运行
  2307. public Tuple<bool, Result> DelayCheck<T>(T id, Func<bool> func, double time)
  2308. {
  2309. int idx = Convert.ToInt32(id);
  2310. bool bActive = Acitve(idx);
  2311. if (bActive)
  2312. {
  2313. if (state == STATE.IDLE)
  2314. {
  2315. timer.Start(time);
  2316. state = STATE.WAIT;
  2317. }
  2318. if (timer.IsTimeout())
  2319. {
  2320. if (func != null && !func())
  2321. {
  2322. return Tuple.Create(true, Result.FAIL);
  2323. }
  2324. next();
  2325. }
  2326. return Tuple.Create(true, Result.RUN);
  2327. }
  2328. return Tuple.Create(false, Result.RUN);
  2329. }
  2330. #endregion
  2331. private Tuple<bool, bool> execute(int id, Func<bool> func) //顺序执行
  2332. {
  2333. bool bActive = Acitve(id);
  2334. bool bExecute = false;
  2335. if (bActive)
  2336. {
  2337. bExecute = func();
  2338. if (bExecute)
  2339. {
  2340. next();
  2341. }
  2342. }
  2343. return Tuple.Create(bActive, bExecute);
  2344. }
  2345. private Tuple<bool, bool> Check(int id, Func<bool> func) //check
  2346. {
  2347. bool bActive = Acitve(id);
  2348. bool bExecute = false;
  2349. if (bActive)
  2350. {
  2351. bExecute = func();
  2352. next();
  2353. }
  2354. return Tuple.Create(bActive, bExecute);
  2355. }
  2356. /// <summary>
  2357. /// </summary>
  2358. /// <param name="id"></param>
  2359. /// <param name="func"></param>
  2360. /// <param name="timeout"></param>
  2361. /// <returns>
  2362. /// item1 Active
  2363. /// item2 execute
  2364. /// item3 Timeout
  2365. ///</returns>
  2366. private Tuple<bool, bool, bool> wait(int id, Func<bool> func, double timeout = int.MaxValue) //Wait condition
  2367. {
  2368. bool bActive = Acitve(id);
  2369. bool bExecute = false;
  2370. bool bTimeout = false;
  2371. if (bActive)
  2372. {
  2373. if (state == STATE.IDLE)
  2374. {
  2375. timer.Start(timeout);
  2376. state = STATE.WAIT;
  2377. }
  2378. bExecute = func();
  2379. if (bExecute)
  2380. {
  2381. next();
  2382. }
  2383. bTimeout = timer.IsTimeout();
  2384. }
  2385. return Tuple.Create(bActive, bExecute, bTimeout);
  2386. }
  2387. private Tuple<bool, bool?, bool> wait(int id, Func<bool?> func, double timeout = int.MaxValue) //Wait condition && Check error
  2388. {
  2389. bool bActive = Acitve(id);
  2390. bool? bExecute = false;
  2391. bool bTimeout = false;
  2392. if (bActive)
  2393. {
  2394. if (state == STATE.IDLE)
  2395. {
  2396. timer.Start(timeout);
  2397. state = STATE.WAIT;
  2398. }
  2399. bExecute = func();
  2400. if (bExecute.HasValue && bExecute.Value)
  2401. {
  2402. next();
  2403. }
  2404. bTimeout = timer.IsTimeout();
  2405. }
  2406. return Tuple.Create(bActive, bExecute, bTimeout);
  2407. }
  2408. /// <summary>
  2409. /// </summary>
  2410. /// <param name="value"></param>
  2411. /// <returns>
  2412. /// item1 true, return item2
  2413. /// </returns>
  2414. private Tuple<bool, Result> Check(Tuple<bool, bool> value)
  2415. {
  2416. if (value.Item1)
  2417. {
  2418. if (!value.Item2)
  2419. {
  2420. return Tuple.Create(true, Result.FAIL);
  2421. }
  2422. return Tuple.Create(true, Result.RUN);
  2423. }
  2424. return Tuple.Create(false, Result.RUN);
  2425. }
  2426. private Tuple<bool, Result> Check(Tuple<bool, bool, bool> value)
  2427. {
  2428. if (value.Item1) // 当前执行
  2429. {
  2430. if (CheckTimeout(value)) //timeout
  2431. {
  2432. return Tuple.Create(true, Result.TIMEOUT);
  2433. }
  2434. return Tuple.Create(true, Result.RUN);
  2435. }
  2436. return Tuple.Create(false, Result.RUN);
  2437. }
  2438. private Tuple<bool, Result> Check(Tuple<bool, bool?, bool> value)
  2439. {
  2440. if (value.Item1) // 当前执行
  2441. {
  2442. if (value.Item2 == null)
  2443. {
  2444. return Tuple.Create(true, Result.FAIL);
  2445. }
  2446. else
  2447. {
  2448. if (value.Item2 == false && value.Item3 == true) //timeout
  2449. {
  2450. return Tuple.Create(true, Result.TIMEOUT);
  2451. }
  2452. return Tuple.Create(true, Result.RUN);
  2453. }
  2454. }
  2455. return Tuple.Create(false, Result.RUN);
  2456. }
  2457. private bool CheckTimeout(Tuple<bool, bool, bool> value)
  2458. {
  2459. return value.Item1 == true && value.Item2 == false && value.Item3 == true;
  2460. }
  2461. private bool Acitve(int id) //
  2462. {
  2463. if (_steps.Contains(id))
  2464. return false;
  2465. this._id = id;
  2466. return true;
  2467. }
  2468. private void next()
  2469. {
  2470. _steps.Push(this._id);
  2471. state = STATE.IDLE;
  2472. }
  2473. private void next(int step) //loop
  2474. {
  2475. while (_steps.Pop() != step) ;
  2476. state = STATE.IDLE;
  2477. }
  2478. public void Delay(int id, double delaySeconds)
  2479. {
  2480. Tuple<bool, Result> ret = Delay(id, () =>
  2481. {
  2482. return true;
  2483. }, delaySeconds * 1000);
  2484. if (ret.Item1)
  2485. {
  2486. if (ret.Item2 == Result.RUN)
  2487. {
  2488. throw (new RoutineBreakException());
  2489. }
  2490. }
  2491. }
  2492. public bool IsActived(int id)
  2493. {
  2494. return _steps.Contains(id);
  2495. }
  2496. }
  2497. }