123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884 |
- using System;
- using System.Collections.Generic;
- using System.IO.Ports;
- using System.Linq;
- using System.Text;
- using Aitex.Core.Common.DeviceData;
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Device.Unit;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.OperationCenter;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Util;
- using MECF.Framework.Common.Communications;
- using MECF.Framework.Common.Device.Bases;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Common;
- using Newtonsoft.Json;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.SubstrateTrackings;
- using System.Threading;
- using Aitex.Core.Common;
- using Aitex.Core.RT.DataCenter;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
- using System.Xml;
- using Aitex.Core.RT.IOCore;
- using Aitex.Core.RT.Routine;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots;
- using MECF.Framework.Common.CommonData;
- using EventType = Aitex.Core.RT.Event.EventType;
- namespace Aitex.Core.RT.Device.Unit
- {
- public class GAPlcRobot:RobotBaseDevice
- {
- public GAPlcRobot(string module,XmlElement node,string ioModule =""): base(node.GetAttribute("module"), node.GetAttribute("id"))
- {
- base.Module = node.GetAttribute("module");//string.IsNullOrEmpty(node.GetAttribute("module")) ? module : node.GetAttribute("module");
- base.Name = node.GetAttribute("id");
- ioModule = node.GetAttribute("ioModule");
- _aiCurrentXPos_L = ParseAiNode("AI_CurrentXPos_L", node, ioModule);
- _aiCurrentXPos_H = ParseAiNode("AI_CurrentXPos_H", node, ioModule);
- _aiCurrentYPos_L = ParseAiNode("AI_CurrentYPos_L", node, ioModule);
- _aiCurrentYPos_H = ParseAiNode("AI_CurrentYPos_H", node, ioModule);
- _aiCurrentZPos_L = ParseAiNode("AI_CurrentZPos_L", node, ioModule);
- _aiCurrentZPos_H = ParseAiNode("AI_CurrentZPos_H", node, ioModule);
- _aiZAxisPitch_L = ParseAiNode("AI_ZAxisPitch_L", node, ioModule);
- _aiZAxisPitch_H = ParseAiNode("AI_ZAxisPitch_H", node, ioModule);
- _aiZAxisFirstPos_L = ParseAiNode("AI_ZAxisFirstPos_L", node, ioModule);
- _aiZAxisFirstPos_H = ParseAiNode("AI_ZAxisFirstPos_H", node, ioModule);
- _aiZAxisPlacePos_L = ParseAiNode("AI_ZAxisPlacePos_L", node, ioModule);
- _aiZAxisPlacePos_H = ParseAiNode("AI_ZAxisPlacePos_H", node, ioModule);
- _aiXAxisMoveDistance_L = ParseAiNode("AI_XAxisMoveDistance_L", node, ioModule);
- _aiXAxisMoveDistance_H = ParseAiNode("AI_XAxisMoveDistance_H", node, ioModule);
- _aiYAxisMoveDistance_L = ParseAiNode("AI_YAxisMoveDistance_L", node, ioModule);
- _aiYAxisMoveDistance_H = ParseAiNode("AI_YAxisMoveDistance_H", node, ioModule);
- _aiZAxisMoveSpeed_L = ParseAiNode("AI_ZAxisMoveSpeed_L", node, ioModule);
- _aiZAxisMoveSpeed_H = ParseAiNode("AI_ZAxisMoveSpeed_H", node, ioModule);
- _aiXAxisMoveSpeed_L = ParseAiNode("AI_XAxisMoveSpeed_L", node, ioModule);
- _aiXAxisMoveSpeed_H = ParseAiNode("AI_XAxisMoveSpeed_H", node, ioModule);
- _aiYAxisMoveSpeed_L = ParseAiNode("AI_YAxisMoveSpeed_L", node, ioModule);
- _aiYAxisMoveSpeed_H = ParseAiNode("AI_YAxisMoveSpeed_H", node, ioModule);
- _aiTargetPos = ParseAiNode("AI_TargetPos", node, ioModule);
- _aoZAxisPitch_L = ParseAoNode("AO_ZAxisPitch_L", node, ioModule);
- _aoZAxisPitch_H = ParseAoNode("AO_ZAxisPitch_H", node, ioModule);
- _aoZAxisFirstPos_L = ParseAoNode("AO_ZAxisFirstPos_L", node, ioModule);
- _aoZAxisFirstPos_H = ParseAoNode("AO_ZAxisFirstPos_H", node, ioModule);
- _aoZAxisPlacePos_L = ParseAoNode("AO_ZAxisPlacePos_L", node, ioModule);
- _aoZAxisPlacePos_H = ParseAoNode("AO_ZAxisPlacePos_H", node, ioModule);
- _aoXAxisMoveDistance_L = ParseAoNode("AO_XAxisMoveDistance_L", node, ioModule);
- _aoXAxisMoveDistance_H = ParseAoNode("AO_XAxisMoveDistance_H", node, ioModule);
- _aoYAxisMoveDistance_L = ParseAoNode("AO_YAxisMoveDistance_L", node, ioModule);
- _aoYAxisMoveDistance_H = ParseAoNode("AO_YAxisMoveDistance_H", node, ioModule);
- _aoZAxisMoveSpeed_L = ParseAoNode("AO_ZAxisMoveSpeed_L", node, ioModule);
- _aoZAxisMoveSpeed_H = ParseAoNode("AO_ZAxisMoveSpeed_H", node, ioModule);
- _aoXAxisMoveSpeed_L = ParseAoNode("AO_XAxisMoveSpeed_L", node, ioModule);
- _aoXAxisMoveSpeed_H = ParseAoNode("AO_XAxisMoveSpeed_H", node, ioModule);
- _aoYAxisMoveSpeed_L = ParseAoNode("AO_YAxisMoveSpeed_L", node, ioModule);
- _aoYAxisMoveSpeed_H = ParseAoNode("AO_YAxisMoveSpeed_H", node, ioModule);
- _aoTargetPos = ParseAoNode("AO_TargetPos", node, ioModule);
- _aoXMoveFwdDistance_L = ParseAoNode("AO_XMoveFwdDistance_L", node, ioModule);
- _aoXMoveFwdDistance_H = ParseAoNode("AO_XMoveFwdDistance_H", node, ioModule);
- _aoYMoveFwdDistance_L = ParseAoNode("AO_YMoveFwdDistance_L", node, ioModule);
- _aoYMoveFwdDistance_H = ParseAoNode("AO_YMoveFwdDistance_H", node, ioModule);
- _aoZMoveFwdDistance_L = ParseAoNode("AO_ZMoveFwdDistance_L", node, ioModule);
- _aoZMoveFwdDistance_H = ParseAoNode("AO_ZMoveFwdDistance_H", node, ioModule);
- _aoXMoveRevDistance_L = ParseAoNode("AO_XMoveRevDistance_L", node, ioModule);
- _aoXMoveRevDistance_H = ParseAoNode("AO_XMoveRevDistance_H", node, ioModule);
- _aoYMoveRevDistance_L = ParseAoNode("AO_YMoveRevDistance_L", node, ioModule);
- _aoYMoveRevDistance_H = ParseAoNode("AO_YMoveRevDistance_H", node, ioModule);
- _aoZMoveRevDistance_L = ParseAoNode("AO_ZMoveRevDistance_L", node, ioModule);
- _aoZMoveRevDistance_H = ParseAoNode("AO_ZMoveRevDistance_H", node, ioModule);
- _diReset_Ack = ParseDiNode("DI_Reset_Ack", node, ioModule);
- _diHome_Ack = ParseDiNode("DI_Home_Ack", node, ioModule);
- _diSave_Ack = ParseDiNode("DI_Save_Ack", node, ioModule);
- _diPick_Ack = ParseDiNode("DI_Pick_Ack", node, ioModule);
- _diPlace_Ack = ParseDiNode("DI_Place_Ack", node, ioModule);
- _diX_Fwd_Ack = ParseDiNode("DI_X_Fwd_Ack", node, ioModule);
- _diX_Rev_Ack = ParseDiNode("DI_X_Rev_Ack", node, ioModule);
- _diY_Fwd_Ack = ParseDiNode("DI_Y_Fwd_Ack", node, ioModule);
- _diY_Rev_Ack = ParseDiNode("DI_Y_Rev_Ack", node, ioModule);
- _diZ_Fwd_Ack = ParseDiNode("DI_Z_Fwd_Ack", node, ioModule);
- _diZ_Rev_Ack = ParseDiNode("DI_Z_Rev_Ack", node, ioModule);
- _diPlugError = ParseDiNode("DI_PlugError", node, ioModule);
- _diZMotionError = ParseDiNode("DI_ZMotionError", node, ioModule);
- _diXMotionError = ParseDiNode("DI_XMotionError", node, ioModule);
- _diYMotionError = ParseDiNode("DI_YMotionError", node, ioModule);
- _diZMotionOutLimit = ParseDiNode("DI_ZMotionOutLimit", node, ioModule);
- _diXMotionOutLimit = ParseDiNode("DI_XMotionOutLimit", node, ioModule);
- _diYMotionOutLimit = ParseDiNode("DI_YMotionOutLimit", node, ioModule);
- _diPLCReady = ParseDiNode("DI_PLCReady", node, ioModule);
- _diMotionIdle = ParseDiNode("DI_MotionIdle", node, ioModule);
- _doResetCmd = ParseDoNode("DO_ResetCmd", node, ioModule);
- _doHomeCmd = ParseDoNode("DO_HomeCmd", node, ioModule);
- _doSaveCmd = ParseDoNode("DO_SaveCmd", node, ioModule);
- _doPickCmd = ParseDoNode("DO_PickCmd", node, ioModule);
- _doPlaceCmd = ParseDoNode("DO_PlaceCmd", node, ioModule);
- _doX_FwdCmd = ParseDoNode("DO_X_FwdCmd", node, ioModule);
- _doX_RevCmd = ParseDoNode("DO_X_RevCmd", node, ioModule);
- _doY_FwdCmd = ParseDoNode("DO_Y_FwdCmd", node, ioModule);
- _doY_RevCmd = ParseDoNode("DO_Y_RevCmd", node, ioModule);
- _doZ_FwdCmd = ParseDoNode("DO_Z_FwdCmd", node, ioModule);
- _doZ_RevCmd = ParseDoNode("DO_Z_RevCmd", node, ioModule);
- EV.Subscribe(new EventItem("Alarm", AlarmRobotError, $"Robot occurred error.", EventLevel.Alarm, EventType.EventUI_Notify));
- DATA.Subscribe($"{Name}.PLCReady", () => _diPLCReady.Value);
- DATA.Subscribe($"{Name}.MotionIdle", () => _diMotionIdle.Value);
- DATA.Subscribe($"{Name}.SlotPitch", () => _slotPitch);
- DATA.Subscribe($"{Name}.FirstZPosition", () => _zFirstPosition);
- DATA.Subscribe($"{Name}.PlaceWaferZPosition", () => _zPutWaferPosition);
- DATA.Subscribe($"{Name}.XMoveDistance", () => _xMoveDistance);
- DATA.Subscribe($"{Name}.YMoveDistance", () => _yMoveDistance);
- DATA.Subscribe($"{Name}.ZMoveSpeed", () => _zMoveSpeed);
- DATA.Subscribe($"{Name}.YMoveSpeed", () => _yMoveSpeed);
- DATA.Subscribe($"{Name}.XMoveSpeed", () => _xMoveSpeed);
- DATA.Subscribe($"{Name}.CurrentXPosition", () => _currentXPosition);
- DATA.Subscribe($"{Name}.CurrentYPosition", () => _currentYPosition);
- DATA.Subscribe($"{Name}.CurrentZPosition", () => _currentZPosition);
- _trigErrorOccurred = new R_TRIG();
- _thread = new PeriodicJob(10, OnTimer, $"{Module}.{Name} MonitorHandler", true);
- }
- private string AlarmRobotError = "RobotOccurredError";
-
- private AIAccessor _aiZAxisPitch_L;
- private AIAccessor _aiZAxisPitch_H;
- private AIAccessor _aiZAxisFirstPos_L;
- private AIAccessor _aiZAxisFirstPos_H;
- private AIAccessor _aiZAxisPlacePos_L;
- private AIAccessor _aiZAxisPlacePos_H;
- private AIAccessor _aiXAxisMoveDistance_L;
- private AIAccessor _aiXAxisMoveDistance_H;
- private AIAccessor _aiYAxisMoveDistance_L;
- private AIAccessor _aiYAxisMoveDistance_H;
- private AIAccessor _aiZAxisMoveSpeed_L;
- private AIAccessor _aiZAxisMoveSpeed_H;
- private AIAccessor _aiXAxisMoveSpeed_L;
- private AIAccessor _aiXAxisMoveSpeed_H;
- private AIAccessor _aiYAxisMoveSpeed_L;
- private AIAccessor _aiYAxisMoveSpeed_H;
- private AIAccessor _aiTargetPos;
- private AIAccessor _aiCurrentXPos_L;
- private AIAccessor _aiCurrentXPos_H;
- private AIAccessor _aiCurrentYPos_L;
- private AIAccessor _aiCurrentYPos_H;
- private AIAccessor _aiCurrentZPos_L;
- private AIAccessor _aiCurrentZPos_H;
- private AOAccessor _aoZAxisPitch_L;
- private AOAccessor _aoZAxisPitch_H;
- private AOAccessor _aoZAxisFirstPos_L;
- private AOAccessor _aoZAxisFirstPos_H;
- private AOAccessor _aoZAxisPlacePos_L;
- private AOAccessor _aoZAxisPlacePos_H;
- private AOAccessor _aoXAxisMoveDistance_L;
- private AOAccessor _aoXAxisMoveDistance_H;
- private AOAccessor _aoYAxisMoveDistance_L;
- private AOAccessor _aoYAxisMoveDistance_H;
- private AOAccessor _aoZAxisMoveSpeed_L;
- private AOAccessor _aoZAxisMoveSpeed_H;
- private AOAccessor _aoXAxisMoveSpeed_L;
- private AOAccessor _aoXAxisMoveSpeed_H;
- private AOAccessor _aoYAxisMoveSpeed_L;
- private AOAccessor _aoYAxisMoveSpeed_H;
- private AOAccessor _aoTargetPos;
- private AOAccessor _aoXMoveFwdDistance_L;
- private AOAccessor _aoXMoveFwdDistance_H;
- private AOAccessor _aoYMoveFwdDistance_L;
- private AOAccessor _aoYMoveFwdDistance_H;
- private AOAccessor _aoZMoveFwdDistance_L;
- private AOAccessor _aoZMoveFwdDistance_H;
- private AOAccessor _aoXMoveRevDistance_L;
- private AOAccessor _aoXMoveRevDistance_H;
- private AOAccessor _aoYMoveRevDistance_L;
- private AOAccessor _aoYMoveRevDistance_H;
- private AOAccessor _aoZMoveRevDistance_L;
- private AOAccessor _aoZMoveRevDistance_H;
- private DIAccessor _diReset_Ack;
- private DIAccessor _diHome_Ack;
- private DIAccessor _diSave_Ack;
- private DIAccessor _diPick_Ack;
- private DIAccessor _diPlace_Ack;
- private DIAccessor _diX_Fwd_Ack;
- private DIAccessor _diX_Rev_Ack;
- private DIAccessor _diY_Fwd_Ack;
- private DIAccessor _diY_Rev_Ack;
- private DIAccessor _diZ_Fwd_Ack;
- private DIAccessor _diZ_Rev_Ack;
- private DIAccessor _diPlugError;
- private DIAccessor _diZMotionError;
- private DIAccessor _diXMotionError;
- private DIAccessor _diYMotionError;
- private DIAccessor _diZMotionOutLimit;
- private DIAccessor _diXMotionOutLimit;
- private DIAccessor _diYMotionOutLimit;
- private DIAccessor _diPLCReady;
- private DIAccessor _diMotionIdle;
- private DOAccessor _doResetCmd;
- private DOAccessor _doHomeCmd;
- private DOAccessor _doSaveCmd;
- private DOAccessor _doPickCmd;
- private DOAccessor _doPlaceCmd;
- private DOAccessor _doX_FwdCmd;
- private DOAccessor _doX_RevCmd;
- private DOAccessor _doY_FwdCmd;
- private DOAccessor _doY_RevCmd;
- private DOAccessor _doZ_FwdCmd;
- private DOAccessor _doZ_RevCmd;
- private PeriodicJob _thread;
- private R_TRIG _trigErrorOccurred;
- private int _currentXPosition
- {
- get
- {
- return TwoShortConvInt(_aiCurrentXPos_L.Value, _aiCurrentXPos_H.Value);
- }
- }
- private int _currentYPosition
- {
- get
- {
- return TwoShortConvInt(_aiCurrentYPos_L.Value, _aiCurrentYPos_H.Value);
- }
- }
- private int _currentZPosition
- {
- get
- {
- return TwoShortConvInt(_aiCurrentZPos_L.Value, _aiCurrentZPos_H.Value);
- }
- }
- private int _slotPitch
- {
- get
- {
- return TwoShortConvInt(_aiZAxisPitch_L.Value, _aiZAxisPitch_H.Value);
- }
- }
- private int _zFirstPosition
- {
- get
- {
- return TwoShortConvInt(_aiZAxisFirstPos_L .Value, _aiZAxisFirstPos_H.Value);
- }
- }
- private int _zPutWaferPosition
- {
- get
- {
- return TwoShortConvInt(_aiZAxisPlacePos_L.Value, _aiZAxisPlacePos_H.Value);
- }
- }
- private int _xMoveDistance
- {
- get
- {
- return TwoShortConvInt(_aiXAxisMoveDistance_L.Value, _aiXAxisMoveDistance_H.Value);
- }
- }
- private int _yMoveDistance
- {
- get
- {
- return TwoShortConvInt(_aiYAxisMoveDistance_L.Value, _aiYAxisMoveDistance_H.Value);
- }
- }
- private int _zMoveSpeed
- {
- get
- {
- return TwoShortConvInt(_aiZAxisMoveSpeed_L.Value, _aiZAxisMoveSpeed_H.Value);
- }
- }
- private int _yMoveSpeed
- {
- get
- {
- return TwoShortConvInt(_aiYAxisMoveSpeed_L.Value, _aiYAxisMoveSpeed_H.Value);
- }
- }
- private int _xMoveSpeed
- {
- get
- {
- return TwoShortConvInt(_aiXAxisMoveSpeed_L.Value, _aiXAxisMoveSpeed_H.Value);
- }
- }
- private bool OnTimer()
- {
- _trigErrorOccurred.CLK =
- _diPlugError.Value || _diZMotionError.Value
- || _diXMotionError.Value || _diYMotionError.Value || _diZMotionOutLimit.Value
- || _diXMotionOutLimit.Value || _diYMotionOutLimit.Value;
- if(_trigErrorOccurred.Q)
- {
- EV.Notify(AlarmRobotError);
- if (_diPlugError.Value)
- {
- EV.PostAlarmLog("Robot", $"Robot occurred error: _diPlugError.");
- }
- if (_diZMotionError.Value)
- {
- EV.PostAlarmLog("Robot", $"Robot occurred error: _diZMotionError.");
- }
- if (_diXMotionError.Value)
- {
- EV.PostAlarmLog("Robot", $"Robot occurred error: _diXMotionError.");
- }
- if (_diYMotionError.Value)
- {
- EV.PostAlarmLog("Robot", $"Robot occurred error: _diYMotionError.");
- }
- if (_diZMotionOutLimit.Value)
- {
- EV.PostAlarmLog("Robot", $"Robot occurred error: _diZMotionOutLimit.");
- }
- if (_diYMotionOutLimit.Value)
- {
- EV.PostAlarmLog("Robot", $"Robot occurred error: _diYMotionOutLimit.");
- }
- if (_diXMotionOutLimit.Value)
- {
- EV.PostAlarmLog("Robot", $"Robot occurred error: _diXMotionOutLimit.");
- }
- OnError("Robot Error");
- }
- return true;
- }
- #region Override Robot base function
- private enum RobotStepEnum
- {
- ActionStep1,
- ActionStep2,
- ActionStep3,
- ActionStep4,
- ActionStep5,
- ActionStep6,
- ActionStep7,
- ActionStep8,
- ActionStep9,
- ActionStep10,
- ActionStep11,
- ActionStep12,
- ActionStep13,
- ActionStep14,
- ActionStep15,
- ActionStep16,
- }
- private DateTime _dtActionStart;
-
- protected override bool fClear(object[] param)
- {
- return true;
- }
- protected override bool fStartReadData(object[] param)
- {
- return true;
- }
- protected override bool fStartSetParameters(object[] param)
- {
-
- try
- {
- _aoZAxisPitch_L.Value = _aiZAxisPitch_L.Value;
- _aoZAxisPitch_H.Value = _aiZAxisPitch_H.Value;
- _aoZAxisFirstPos_L.Value = _aiZAxisFirstPos_L.Value;
- _aoZAxisFirstPos_H.Value = _aiZAxisFirstPos_H.Value;
- _aoZAxisPlacePos_L.Value = _aiZAxisPlacePos_L.Value;
- _aoZAxisPlacePos_H.Value = _aiZAxisPlacePos_H.Value;
- _aoXAxisMoveDistance_L.Value = _aiXAxisMoveDistance_L.Value;
- _aoXAxisMoveDistance_H.Value = _aiXAxisMoveDistance_H.Value;
- _aoYAxisMoveDistance_L.Value = _aiYAxisMoveDistance_L.Value;
- _aoYAxisMoveDistance_H.Value = _aiYAxisMoveDistance_H.Value;
- _aoZAxisMoveSpeed_L.Value = _aiZAxisMoveSpeed_L.Value;
- _aoZAxisMoveSpeed_H.Value = _aiZAxisMoveSpeed_H.Value;
- _aoXAxisMoveSpeed_L.Value = _aiXAxisMoveSpeed_L.Value;
- _aoXAxisMoveSpeed_H.Value = _aiXAxisMoveSpeed_H.Value;
- _aoYAxisMoveSpeed_L.Value = _aiYAxisMoveSpeed_L.Value;
- _aoYAxisMoveSpeed_H.Value = _aiYAxisMoveSpeed_H.Value;
- string setcommand = param[0].ToString();
- int setvalue = Convert.ToInt32(param[1].ToString());
- short lowbit=0, highbit=0;
- IntConvTwoShort(setvalue, ref lowbit, ref highbit);
- _dtActionStart = DateTime.Now;
- ResetRoutine();
- switch (setcommand)
- {
- case "SlotPitch":
- _aoZAxisPitch_L.Value = lowbit;
- _aoZAxisPitch_H.Value = highbit;
- break;
- case "FirstZPosition":
- _aoZAxisFirstPos_L.Value = lowbit;
- _aoZAxisFirstPos_H.Value = highbit;
- break;
- case "PlaceWaferZPosition":
- _aoZAxisPlacePos_L.Value = lowbit;
- _aoZAxisPlacePos_H.Value = highbit;
- break;
- case "XMoveDistance":
- _aoXAxisMoveDistance_L.Value = lowbit;
- _aoXAxisMoveDistance_H.Value = highbit;
- break;
- case "YMoveDistance":
- _aoYAxisMoveDistance_L.Value = lowbit;
- _aoYAxisMoveDistance_H.Value = highbit;
- break;
- case "ZMoveSpeed":
- _aoZAxisMoveSpeed_L.Value = lowbit;
- _aoZAxisMoveSpeed_H.Value = highbit;
- break;
- case "XMoveSpeed":
- _aoXAxisMoveSpeed_L.Value = lowbit;
- _aoXAxisMoveSpeed_H.Value = highbit;
- break;
- case "YMoveSpeed":
- _aoYAxisMoveSpeed_L.Value = lowbit;
- _aoYAxisMoveSpeed_H.Value = highbit;
- break;
- default:
- return false;
- }
- }
- catch(Exception ex)
- {
- LOG.Write(ex);
- }
- return true;
- }
- protected override bool fMonitorSetParamter(object[] param)
- {
- IsBusy = false;
- if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(RobotCommandTimeout))
- {
- OnError("Command execution timeout");
- return true;
- }
- try
- {
- SetDoState((int)RobotStepEnum.ActionStep2, _doSaveCmd, true, Notify);
- WaitDiState((int)RobotStepEnum.ActionStep3, RobotCommandTimeout, _diSave_Ack, true, Notify, Stop);
- SetDoState((int)RobotStepEnum.ActionStep4, _doSaveCmd, false, Notify);
- WaitDiState((int)RobotStepEnum.ActionStep5, RobotCommandTimeout, _diSave_Ack, false, Notify, Stop);
- }
- catch (RoutineBreakException)
- {
- return false;
- }
- catch (RoutineFaildException)
- {
- EV.PostAlarmLog("Alarm", "Pick wafer failed.");
- OnError("PickFailed");
- }
- return true;
- }
- protected override bool fStartTransferWafer(object[] param)
- {
- return true;
- }
- protected override bool fStartUnGrip(object[] param)
- {
- return false;
- }
- protected override bool fStartGrip(object[] param)
- {
- return false;
- }
- protected override bool fStartGoTo(object[] param)
- {
- return false;
- }
- protected override bool fStartMapWafer(object[] param)
- {
- return false;
- }
- protected override bool fStartSwapWafer(object[] param)
- {
- return false;
- }
- protected override bool fStartPlaceWafer(object[] param)
- {
- if(!_diPLCReady.Value)
- {
- EV.PostAlarmLog("Robot", "PLC ready signal is OFF.");
- return false;
- }
- if(!_diMotionIdle.Value)
- {
- EV.PostAlarmLog("Robot", "Motion idle signal is OFF.");
- return false;
- }
- _dtActionStart = DateTime.Now;
- ResetRoutine();
- try
- {
- //RobotArmEnum arm = (RobotArmEnum)param[0];
- ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), param[1].ToString());
- int slotindex = int.Parse(param[2].ToString());
- if (ModuleHelper.IsLoadPort(tempmodule))
- {
- _aoTargetPos.Value = (short)(slotindex + 1);
- }
- else
- _aoTargetPos.Value = 26;
- Blade1Target = tempmodule;
- Blade2Target = tempmodule;
- CmdTarget = tempmodule;
- MoveInfo = new RobotMoveInfo()
- {
- Action = RobotAction.Picking,
- ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
- BladeTarget = BuildBladeTarget(),
- };
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- return false;
- }
- return true;
- }
- protected override bool fMonitorPlace(object[] param)
- {
- IsBusy = false;
- if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(RobotCommandTimeout))
- {
- OnError("Command execution timeout");
- return true;
- }
- try
- {
- WaitAiValue((int)RobotStepEnum.ActionStep1, RobotCommandTimeout, _aiTargetPos, _aoTargetPos.Value, Notify, Stop);
- SetDoState((int)RobotStepEnum.ActionStep2, _doPlaceCmd, true, Notify);
- WaitDiState((int)RobotStepEnum.ActionStep3, RobotCommandTimeout, _diPlace_Ack, true, Notify, Stop);
- SetDoState((int)RobotStepEnum.ActionStep4, _doPlaceCmd, false, Notify);
- WaitDiState((int)RobotStepEnum.ActionStep5, RobotCommandTimeout, _diPlace_Ack, false, Notify, Stop);
- }
- catch (RoutineBreakException)
- {
- return false;
- }
- catch (RoutineFaildException)
- {
- EV.PostAlarmLog("Alarm", "Pick wafer failed.");
- OnError("PickFailed");
- return true;
- }
- Blade1Target = ModuleName.System;
- Blade2Target = ModuleName.System;
- CmdTarget = ModuleName.System;
- MoveInfo = new RobotMoveInfo()
- {
- Action = RobotAction.Picking,
- ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
- BladeTarget = BuildBladeTarget(),
- };
- ModuleName sourcemodule;
- if (!Enum.TryParse(CurrentParamter[1].ToString(), out sourcemodule)) return false;
- int SourceslotIndex;
- if (!int.TryParse(CurrentParamter[2].ToString(), out SourceslotIndex)) return false;
- WaferManager.Instance.WaferMoved(RobotModuleName, 0,sourcemodule, SourceslotIndex);
- return true;
- }
- protected override bool fMonitorPick(object[] param)
- {
- IsBusy = false;
- if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(RobotCommandTimeout))
- {
- OnError("Command execution timeout");
- return true;
- }
- try
- {
- WaitAiValue((int)RobotStepEnum.ActionStep1, RobotCommandTimeout, _aiTargetPos, _aoTargetPos.Value, Notify, Stop);
- SetDoState((int)RobotStepEnum.ActionStep2, _doPickCmd, true, Notify);
- WaitDiState((int)RobotStepEnum.ActionStep3, RobotCommandTimeout, _diPick_Ack, true, Notify, Stop);
- SetDoState((int)RobotStepEnum.ActionStep4, _doPickCmd, false, Notify);
- WaitDiState((int)RobotStepEnum.ActionStep5, RobotCommandTimeout, _diPick_Ack, false, Notify, Stop);
- }
- catch (RoutineBreakException)
- {
- return false;
- }
- catch (RoutineFaildException)
- {
- EV.PostAlarmLog("Alarm","Pick wafer failed.");
- OnError("PickFailed");
- return true;
- }
- Blade1Target = ModuleName.System;
- Blade2Target = ModuleName.System;
- CmdTarget = ModuleName.System;
- MoveInfo = new RobotMoveInfo()
- {
- Action = RobotAction.Picking,
- ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
- BladeTarget = BuildBladeTarget(),
- };
- ModuleName sourcemodule;
- if (!Enum.TryParse(CurrentParamter[1].ToString(), out sourcemodule)) return false;
- int SourceslotIndex;
- if (!int.TryParse(CurrentParamter[2].ToString(), out SourceslotIndex)) return false;
- WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 0);
- return true;
- }
- protected override bool fStartPickWafer(object[] param)
- {
- if (!_diPLCReady.Value)
- {
- EV.PostAlarmLog("Robot", "PLC ready signal is OFF.");
- return false;
- }
- if (!_diMotionIdle.Value)
- {
- EV.PostAlarmLog("Robot", "Motion idle signal is OFF.");
- return false;
- }
- _dtActionStart = DateTime.Now;
- ResetRoutine();
- try
- {
- ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), param[1].ToString());
- int slotindex = int.Parse(param[2].ToString());
- if (ModuleHelper.IsLoadPort(tempmodule))
- {
- _aoTargetPos.Value = (short)(slotindex + 1);
- }
- else
- _aoTargetPos.Value = 26;
- Blade1Target = tempmodule;
- Blade2Target = tempmodule;
- CmdTarget = tempmodule;
- MoveInfo = new RobotMoveInfo()
- {
- Action = RobotAction.Picking,
- ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
- BladeTarget = BuildBladeTarget(),
- };
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- return false;
- }
- return true;
- }
- protected override bool fResetToReady(object[] param)
- {
- return true;
- }
- protected override bool fReset(object[] param)
- {
- _dtActionStart = DateTime.Now;
- ResetRoutine();
- return true;
- }
- protected override bool fMonitorReset(object[] param)
- {
- IsBusy = false;
- if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(RobotCommandTimeout))
- {
- OnError("Command execution timeout");
- return true;
- }
- try
- {
- SetDoState((int)RobotStepEnum.ActionStep1, _doPickCmd, false, Notify);
- SetDoState((int)RobotStepEnum.ActionStep2, _doPlaceCmd, false, Notify);
- SetDoState((int)RobotStepEnum.ActionStep3, _doHomeCmd, false, Notify);
- SetDoState((int)RobotStepEnum.ActionStep4, _doSaveCmd, false, Notify);
- SetDoState((int)RobotStepEnum.ActionStep5, _doX_FwdCmd, false, Notify);
- SetDoState((int)RobotStepEnum.ActionStep6, _doX_RevCmd, false, Notify);
- SetDoState((int)RobotStepEnum.ActionStep7, _doY_FwdCmd, false, Notify);
- SetDoState((int)RobotStepEnum.ActionStep8, _doY_RevCmd, false, Notify);
- SetDoState((int)RobotStepEnum.ActionStep9, _doZ_FwdCmd, false, Notify);
- SetDoState((int)RobotStepEnum.ActionStep10, _doZ_RevCmd, false, Notify);
- SetDoState((int)RobotStepEnum.ActionStep11, _doResetCmd, true, Notify);
- WaitDiState((int)RobotStepEnum.ActionStep12, RobotCommandTimeout, _diReset_Ack, true, Notify, Stop);
- SetDoState((int)RobotStepEnum.ActionStep13, _doResetCmd, false, Notify);
- WaitDiState((int)RobotStepEnum.ActionStep14, RobotCommandTimeout, _diReset_Ack, false, Notify, Stop);
- }
- catch (RoutineBreakException)
- {
- return false;
- }
- catch (RoutineFaildException)
- {
- EV.PostAlarmLog("Alarm", "Pick wafer failed.");
- OnError("PickFailed");
- return true;
- }
- return true;
- }
- protected override bool fStartInit(object[] param)
- {
- _dtActionStart = DateTime.Now;
- ResetRoutine();
- return true;
- }
- protected override bool fMonitorInit(object[] param)
- {
- IsBusy = false;
- if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(RobotCommandTimeout))
- {
- OnError("Command execution timeout");
- return true;
- }
- try
- {
- SetDoState((int)RobotStepEnum.ActionStep1, _doPickCmd, false, Notify);
- SetDoState((int)RobotStepEnum.ActionStep2, _doPlaceCmd, false, Notify);
- SetDoState((int)RobotStepEnum.ActionStep3, _doResetCmd, false, Notify);
- SetDoState((int)RobotStepEnum.ActionStep4, _doSaveCmd, false, Notify);
- SetDoState((int)RobotStepEnum.ActionStep5, _doX_FwdCmd, false, Notify);
- SetDoState((int)RobotStepEnum.ActionStep6, _doX_RevCmd, false, Notify);
- SetDoState((int)RobotStepEnum.ActionStep7, _doY_FwdCmd, false, Notify);
- SetDoState((int)RobotStepEnum.ActionStep8, _doY_RevCmd, false, Notify);
- SetDoState((int)RobotStepEnum.ActionStep9, _doZ_FwdCmd, false, Notify);
- SetDoState((int)RobotStepEnum.ActionStep10, _doZ_RevCmd, false, Notify);
- SetDoState((int)RobotStepEnum.ActionStep11, _doHomeCmd, true, Notify);
- WaitDiState((int)RobotStepEnum.ActionStep12, RobotCommandTimeout, _diHome_Ack, true, Notify, Stop);
- SetDoState((int)RobotStepEnum.ActionStep13, _doHomeCmd, false, Notify);
- WaitDiState((int)RobotStepEnum.ActionStep14, RobotCommandTimeout, _diHome_Ack, false, Notify, Stop);
- }
- catch (RoutineBreakException)
- {
- return false;
- }
- catch (RoutineFaildException)
- {
- EV.PostAlarmLog("Alarm", "Pick wafer failed.");
- OnError("PickFailed");
- return true;
- }
- Blade1Target = ModuleName.System;
- Blade2Target = ModuleName.System;
- CmdTarget = ModuleName.System;
- MoveInfo = new RobotMoveInfo()
- {
- Action = RobotAction.Picking,
- ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
- BladeTarget = BuildBladeTarget(),
- };
- return true;
- }
- protected override bool fStartExecuteCommand(object[] param)
- {
- CurrentExecuteCmd = param[0].ToString();
- if (string.IsNullOrEmpty(CurrentExecuteCmd))
- return false;
- _dtActionStart = DateTime.Now;
- ResetRoutine();
- return true;
-
- }
- public string CurrentExecuteCmd { get; private set; }
- protected override bool fMonitorExecuting(object[] param)
- {
- string command = CurrentParamter[0].ToString();
- Int32 pnum = Convert.ToInt32(CurrentParamter[1]);
- short high16bit = (short)(pnum >> 16);
- short low16bit = (short)(pnum & ushort.MaxValue);
- try
- {
- switch (command)
- {
- case "XMoveFwd":
- SetAoValue((int)RobotStepEnum.ActionStep1, _aoXMoveFwdDistance_H, high16bit, Notify);
- SetAoValue((int)RobotStepEnum.ActionStep2, _aoXMoveFwdDistance_L, low16bit, Notify);
- SetDoState((int)RobotStepEnum.ActionStep3, _doX_FwdCmd, true, Notify);
- WaitDiState((int)RobotStepEnum.ActionStep4, RobotCommandTimeout, _diX_Fwd_Ack, true, Notify,Stop);
- SetDoState((int)RobotStepEnum.ActionStep5, _doX_FwdCmd, false, Notify);
- WaitDiState((int)RobotStepEnum.ActionStep6, RobotCommandTimeout, _diX_Fwd_Ack, false, Notify, Stop);
- SetAoValue((int)RobotStepEnum.ActionStep7, _aoXMoveFwdDistance_H, 0, Notify);
- SetAoValue((int)RobotStepEnum.ActionStep8, _aoXMoveFwdDistance_L, 0, Notify);
- break;
- case "XMoveRev":
- high16bit = (short)((-1*pnum) >> 16);
- low16bit = (short)((-1 * pnum) & ushort.MaxValue);
- SetAoValue((int)RobotStepEnum.ActionStep1, _aoXMoveRevDistance_H, high16bit, Notify);
- SetAoValue((int)RobotStepEnum.ActionStep2, _aoXMoveRevDistance_L, low16bit, Notify);
- SetDoState((int)RobotStepEnum.ActionStep3, _doX_RevCmd, true, Notify);
- WaitDiState((int)RobotStepEnum.ActionStep4, RobotCommandTimeout, _diX_Rev_Ack, true, Notify, Stop);
- SetDoState((int)RobotStepEnum.ActionStep5, _doX_RevCmd, false, Notify);
- WaitDiState((int)RobotStepEnum.ActionStep6, RobotCommandTimeout, _diX_Rev_Ack, false, Notify, Stop);
- SetAoValue((int)RobotStepEnum.ActionStep7, _aoXMoveRevDistance_H, 0, Notify);
- SetAoValue((int)RobotStepEnum.ActionStep8, _aoXMoveRevDistance_L, 0, Notify);
- break;
- case "YMoveFwd":
- SetAoValue((int)RobotStepEnum.ActionStep1, _aoYMoveFwdDistance_H, high16bit, Notify);
- SetAoValue((int)RobotStepEnum.ActionStep2, _aoYMoveFwdDistance_L, low16bit, Notify);
- SetDoState((int)RobotStepEnum.ActionStep3, _doY_FwdCmd, true, Notify);
- WaitDiState((int)RobotStepEnum.ActionStep4, RobotCommandTimeout, _diY_Fwd_Ack, true, Notify, Stop);
- SetDoState((int)RobotStepEnum.ActionStep5, _doY_FwdCmd, false, Notify);
- WaitDiState((int)RobotStepEnum.ActionStep6, RobotCommandTimeout, _diY_Fwd_Ack, false, Notify, Stop);
- SetAoValue((int)RobotStepEnum.ActionStep7, _aoYMoveFwdDistance_H, 0, Notify);
- SetAoValue((int)RobotStepEnum.ActionStep8, _aoYMoveFwdDistance_L, 0, Notify);
- break;
- case "YMoveRev":
- high16bit = (short)((-1 * pnum) >> 16);
- low16bit = (short)((-1 * pnum) & ushort.MaxValue);
- SetAoValue((int)RobotStepEnum.ActionStep1, _aoYMoveRevDistance_H, high16bit, Notify);
- SetAoValue((int)RobotStepEnum.ActionStep2, _aoYMoveRevDistance_L, low16bit, Notify);
- SetDoState((int)RobotStepEnum.ActionStep3, _doY_RevCmd, true, Notify);
- WaitDiState((int)RobotStepEnum.ActionStep4, RobotCommandTimeout, _diY_Rev_Ack, true, Notify, Stop);
- SetDoState((int)RobotStepEnum.ActionStep5, _doY_RevCmd, false, Notify);
- WaitDiState((int)RobotStepEnum.ActionStep6, RobotCommandTimeout, _diY_Rev_Ack, false, Notify, Stop);
- SetAoValue((int)RobotStepEnum.ActionStep7, _aoYMoveRevDistance_H, 0, Notify);
- SetAoValue((int)RobotStepEnum.ActionStep8, _aoYMoveRevDistance_L, 0, Notify);
- break;
- case "ZMoveFwd":
- SetAoValue((int)RobotStepEnum.ActionStep1, _aoZMoveFwdDistance_H, high16bit, Notify);
- SetAoValue((int)RobotStepEnum.ActionStep2, _aoZMoveFwdDistance_L, low16bit, Notify);
- SetDoState((int)RobotStepEnum.ActionStep3, _doZ_FwdCmd, true, Notify);
- WaitDiState((int)RobotStepEnum.ActionStep4, RobotCommandTimeout, _diZ_Fwd_Ack, true, Notify, Stop);
- SetDoState((int)RobotStepEnum.ActionStep5, _doZ_FwdCmd, false, Notify);
- WaitDiState((int)RobotStepEnum.ActionStep6, RobotCommandTimeout, _diZ_Fwd_Ack, false, Notify, Stop);
- SetAoValue((int)RobotStepEnum.ActionStep7, _aoZMoveFwdDistance_H, 0, Notify);
- SetAoValue((int)RobotStepEnum.ActionStep8, _aoZMoveFwdDistance_L, 0, Notify);
- break;
- case "ZMoveRev":
- high16bit = (short)((-1 * pnum) >> 16);
- low16bit = (short)((-1 * pnum) & ushort.MaxValue);
- SetAoValue((int)RobotStepEnum.ActionStep1, _aoZMoveRevDistance_H, high16bit, Notify);
- SetAoValue((int)RobotStepEnum.ActionStep2, _aoZMoveRevDistance_L, low16bit, Notify);
- SetDoState((int)RobotStepEnum.ActionStep3, _doZ_RevCmd, true, Notify);
- WaitDiState((int)RobotStepEnum.ActionStep4, RobotCommandTimeout, _diZ_Rev_Ack, true, Notify, Stop);
- SetDoState((int)RobotStepEnum.ActionStep5, _doZ_RevCmd, false, Notify);
- WaitDiState((int)RobotStepEnum.ActionStep6, RobotCommandTimeout, _diZ_Rev_Ack, false, Notify, Stop);
- SetAoValue((int)RobotStepEnum.ActionStep7, _aoZMoveRevDistance_H, 0, Notify);
- SetAoValue((int)RobotStepEnum.ActionStep8, _aoZMoveRevDistance_L, 0, Notify);
- break;
- default:
- break;
- }
- }
- catch (RoutineBreakException)
- {
- return false;
- }
- catch (RoutineFaildException)
- {
- EV.PostAlarmLog("Alarm", $"Execute command:{command} failed.");
- OnError($"Execute {command} failed");
- return true;
- }
- return true;
- }
- protected override bool fError(object[] param)
- {
- return true;
- }
- protected override bool fStartExtendForPick(object[] param)
- {
- return true;
- }
- protected override bool fStartExtendForPlace(object[] param)
- {
- return true;
- }
- protected override bool fStartRetractFromPick(object[] param)
- {
- return true;
- }
- protected override bool fStartRetractFromPlace(object[] param)
- {
- return true;
- }
- public override RobotArmWaferStateEnum GetWaferState(RobotArmEnum arm)
- {
- if (WaferManager.Instance.CheckHasWafer(RobotModuleName, 0))
- return RobotArmWaferStateEnum.Present;
- return RobotArmWaferStateEnum.Absent;
- }
- private string BuildBladeTarget()
- {
- return (CmdRobotArm == RobotArmEnum.Upper ? "ArmB" : "ArmA") + "." + CmdTarget;
- }
- private static int TwoShortConvInt(short low16bit, short high16bit)
- {
- return (high16bit << 16) + low16bit + (low16bit<0 ? UInt16.MaxValue+1 :0);
- }
- private static void IntConvTwoShort(int num,ref short low16bit,ref short high16bit)
- {
- high16bit = (short)(num >> 16);
- low16bit = (short)(num & ushort.MaxValue);
- }
- #endregion
- public DOAccessor ParseDoNode(string name, XmlElement node, string ioModule = "")
- {
- if (!string.IsNullOrEmpty(node.GetAttribute(name).Trim()))
- return IO.DO[string.IsNullOrEmpty(ioModule) ? node.GetAttribute(name).Trim() : $"{ioModule}.{node.GetAttribute(name).Trim()}"];
- return null;
- }
- public DIAccessor ParseDiNode(string name, XmlElement node, string ioModule = "")
- {
- if (!string.IsNullOrEmpty(node.GetAttribute(name).Trim()))
- return IO.DI[string.IsNullOrEmpty(ioModule) ? node.GetAttribute(name).Trim() : $"{ioModule}.{node.GetAttribute(name).Trim()}"];
- return null;
- }
- public AOAccessor ParseAoNode(string name, XmlElement node, string ioModule = "")
- {
- if (!string.IsNullOrEmpty(node.GetAttribute(name).Trim()))
- return IO.AO[string.IsNullOrEmpty(ioModule) ? node.GetAttribute(name).Trim() : $"{ioModule}.{node.GetAttribute(name).Trim()}"];
- return null;
- }
- public AIAccessor ParseAiNode(string name, XmlElement node, string ioModule = "")
- {
- if (!string.IsNullOrEmpty(node.GetAttribute(name).Trim()))
- return IO.AI[string.IsNullOrEmpty(ioModule) ? node.GetAttribute(name).Trim() : $"{ioModule}.{node.GetAttribute(name).Trim()}"];
- return null;
- }
- public SCConfigItem ParseScNode(string name, XmlElement node, string ioModule = "", string defaultScPath = "")
- {
- SCConfigItem result = null;
- if (!string.IsNullOrEmpty(node.GetAttribute(name).Trim()))
- result = SC.GetConfigItem(node.GetAttribute(name));
- if (result == null && !string.IsNullOrEmpty(defaultScPath) && SC.ContainsItem(defaultScPath))
- result = SC.GetConfigItem(defaultScPath);
- return result;
- }
- public static T ParseDeviceNode<T>(string name, XmlElement node) where T : class, IDevice
- {
- if (!string.IsNullOrEmpty(node.GetAttribute(name).Trim()))
- return DEVICE.GetDevice<T>(node.GetAttribute(name));
- LOG.Write(string.Format("{0},未定义{1}", node.InnerXml, name));
- return null;
- }
- public static T ParseDeviceNode<T>(string module, string name, XmlElement node) where T : class, IDevice
- {
- string device_id = node.GetAttribute(name);
- if (!string.IsNullOrEmpty(device_id) && !string.IsNullOrEmpty(device_id.Trim()))
- {
- return DEVICE.GetDevice<T>($"{module}.{device_id}");
- }
- LOG.Write(string.Format("{0},undefined {1}", node.InnerXml, name));
- return null;
- }
- public enum CarrierMode
- {
- Foup,
- Fosb,
- OpenCassette,
- }
- private void SetAoValue(int id, AOAccessor ao, short value, Action<string> notify)
- {
- var ret = Execute(id, () =>
- {
- notify($"{RobotModuleName} set {ao.Name} to {value}.");
- ao.Value = value;
- return true;
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw new RoutineFaildException();
- }
- }
- }
- private void WaitAiValue(int id, int time, AIAccessor ai, short value, Action<string> notify, Action<string> error)
- {
- var ret = ExecuteAndWait(id, () =>
- {
- notify($"Wait {RobotModuleName} {ai.Name} to be {value}");
- return true;
- }, () =>
- {
- if (ai.Value == value)
- return true;
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw new RoutineFaildException();
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- //EV.Notify(RobotModuleName);
- error($"Wait {RobotModuleName} {ai.Name} to be {value} timeout after {time} seconds");
- throw new RoutineFaildException();
- }
- else
- {
- throw new RoutineBreakException();
- }
- }
- }
- private void WaitDiState(int id, int time, DIAccessor di, bool state, Action<string> notify, Action<string> error)
- {
- var ret = ExecuteAndWait(id, () =>
- {
- notify($"Wait {RobotModuleName} {di.Name} to be {state}");
- return true;
- }, () =>
- {
- if (di.Value == state)
- return true;
- return false;
- }, time * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw new RoutineFaildException();
- }
- else if (ret.Item2 == Result.TIMEOUT) //timeout
- {
- //EV.Notify();
- error($"Wait {RobotModuleName} {di.Name} to be {state} timeout after {time} seconds");
- throw new RoutineFaildException();
- }
- else
- {
- throw new RoutineBreakException();
- }
- }
- }
- private void SetDoState(int id, DOAccessor _do, bool state, Action<string> notify)
- {
- var ret = Execute(id, () =>
- {
- notify($"{RobotModuleName} start set {_do.Name} to {state}.");
- //if (_do.Value == state)
- //{
- // _do.Value = !state;
- // Thread.Sleep(500);
- //}
- return _do.SetValue(state, out _);
- });
- if (ret.Item1)
- {
- if (ret.Item2 == Result.FAIL)
- {
- throw new RoutineFaildException();
- }
- }
- }
- protected void Notify(string message)
- {
- EV.PostMessage(Name, EventEnum.GeneralInfo, string.Format("{0}:{1}", Name, message));
- }
- protected void Stop(string failReason)
- {
- OnError(string.Format("Failed {0}, {1} ", Name, failReason));
- }
- #region Routine Executor
- //timer, 计算routine时间
- protected DeviceTimer counter = new DeviceTimer();
- protected DeviceTimer delayTimer = new DeviceTimer();
- private enum STATE
- {
- IDLE,
- WAIT,
- }
- public int TokenId
- {
- get { return _id; }
- }
- private int _id; //step index
- /// <summary>
- /// already done steps
- /// </summary>
- private Stack<int> _steps = new Stack<int>();
- private STATE state; //step state //idel,wait,
- //loop control
- private int loop = 0;
- private int loopCount = 0;
- private int loopID = 0;
- private DeviceTimer timer = new DeviceTimer();
- public int LoopCounter { get { return loop; } }
- public int LoopTotalTime { get { return loopCount; } }
- // public int Timeout { get { return (int)(timer.GetTotalTime() / 1000); } }
- //状态持续时间,单位为秒
- public int Elapsed { get { return (int)(timer.GetElapseTime() / 1000); } }
- protected RoutineResult RoutineToken = new RoutineResult() { Result = RoutineState.Running };
- public void ResetRoutine()
- {
- _id = 0;
- _steps.Clear();
- loop = 0;
- loopCount = 0;
- state = STATE.IDLE;
- counter.Start(60 * 60 * 100); //默认1小时
- RoutineToken.Result = RoutineState.Running;
- }
- protected void PerformRoutineStep(int id, Func<RoutineState> execution, RoutineResult result)
- {
- if (!Acitve(id))
- return;
- result.Result = execution();
- }
- #region interface
- public void StopLoop()
- {
- loop = loopCount;
- }
- public Tuple<bool, Result> Loop<T>(T id, Func<bool> func, int count)
- {
- int idx = Convert.ToInt32(id);
- bool bActive = Acitve(idx);
- if (bActive)
- {
- if (!func())
- {
- return Tuple.Create(bActive, Result.FAIL); //执行错误
- }
- loopID = idx;
- loopCount = count;
- next();
- return Tuple.Create(true, Result.RUN);
- }
- return Tuple.Create(false, Result.RUN);
- }
- public Tuple<bool, Result> EndLoop<T>(T id, Func<bool> func)
- {
- int idx = Convert.ToInt32(id);
- bool bActive = Acitve(idx);
- if (bActive)
- {
- if (++loop >= loopCount) //Loop 结束
- {
- if (!func())
- {
- return Tuple.Create(bActive, Result.FAIL); //执行错误
- }
- loop = 0;
- loopCount = 0; // Loop 结束时,当前loop和loop总数都清零
- next();
- return Tuple.Create(true, Result.RUN);
- }
- //继续下一LOOP
- next(loopID);
- return Tuple.Create(true, Result.RUN);
- }
- return Tuple.Create(false, Result.RUN);
- }
- public Tuple<bool, Result> ExecuteAndWait<T>(T id, IRoutine routine)
- {
- int idx = Convert.ToInt32(id);
- bool bActive = Acitve(idx);
- if (bActive)
- {
- if (state == STATE.IDLE)
- {
- Result startRet = routine.Start();
- if (startRet == Result.FAIL)
- {
- return Tuple.Create(true, Result.FAIL); //执行错误
- }
- else if (startRet == Result.DONE)
- {
- next();
- return Tuple.Create(true, Result.DONE);
- }
- state = STATE.WAIT;
- }
- Result ret = routine.Monitor();
- if (ret == Result.DONE)
- {
- next();
- return Tuple.Create(true, Result.DONE);
- }
- else if (ret == Result.FAIL || ret == Result.TIMEOUT)
- {
- return Tuple.Create(true, Result.FAIL);
- }
- else
- {
- return Tuple.Create(true, Result.RUN);
- }
- }
- return Tuple.Create(false, Result.RUN);
- }
- public Tuple<bool, Result> ExecuteAndWait<T>(T id, List<IRoutine> routines)
- {
- int idx = Convert.ToInt32(id);
- bool bActive = Acitve(idx);
- if (bActive)
- {
- if (state == STATE.IDLE)
- {
- foreach (var item in routines)
- {
- if (item.Start() == Result.FAIL)
- return Tuple.Create(true, Result.FAIL);
- }
- state = STATE.WAIT;
- }
- //wait all sub failed or completedboo
- bool bFail = false;
- bool bDone = true;
- foreach (var item in routines)
- {
- Result ret = item.Monitor();
- bDone &= (ret == Result.FAIL || ret == Result.DONE);
- bFail |= ret == Result.FAIL;
- }
- if (bDone)
- {
- next();
- if (bFail)
- return Tuple.Create(true, Result.FAIL);
- return Tuple.Create(true, Result.DONE);
- }
- return Tuple.Create(true, Result.RUN);
- }
- return Tuple.Create(false, Result.RUN);
- }
- public Tuple<bool, Result> Check<T>(T id, Func<bool> func) //顺序执行
- {
- return Check(Check(Convert.ToInt32(id), func));
- }
- public Tuple<bool, Result> Execute<T>(T id, Func<bool> func) //顺序执行
- {
- return Check(execute(Convert.ToInt32(id), func));
- }
- public Tuple<bool, Result> Wait<T>(T id, Func<bool> func, double timeout = int.MaxValue) //Wait condition
- {
- return Check(wait(Convert.ToInt32(id), func, timeout));
- }
- public Tuple<bool, Result> Wait<T>(T id, Func<bool?> func, double timeout = int.MaxValue) //Wait condition
- {
- return Check(wait(Convert.ToInt32(id), func, timeout));
- }
- public Tuple<bool, Result> ExecuteAndWait<T>(T id, Func<bool> execute, Func<bool?> check, double timeout = int.MaxValue)
- {
- int idx = Convert.ToInt32(id);
- bool bActive = Acitve(idx);
- bool? bExecute = false;
- if (bActive)
- {
- if (state == STATE.IDLE)
- {
- if (!execute())
- {
- return Tuple.Create(bActive, Result.FAIL); //执行错误
- }
- timer.Start(timeout);
- state = STATE.WAIT;
- }
- bExecute = check();
- if (bExecute == null)
- {
- return Tuple.Create(bActive, Result.FAIL); //Termianate
- }
- else
- {
- if (bExecute.Value) //检查Success, next
- {
- next();
- return Tuple.Create(true, Result.RUN);
- }
- }
- if (timer.IsTimeout())
- return Tuple.Create(true, Result.TIMEOUT);
- return Tuple.Create(true, Result.RUN);
- }
- return Tuple.Create(false, Result.RUN);
- }
- public Tuple<bool, Result> ExecuteAndWait<T>(T id, Func<bool> execute, Func<bool?> check, Func<double> time)
- {
- int idx = Convert.ToInt32(id);
- bool bActive = Acitve(idx);
- bool? bExecute = false;
- double timeout = 0;
- if (bActive)
- {
- if (state == STATE.IDLE)
- {
- timeout = time();
- if (!execute())
- {
- return Tuple.Create(true, Result.FAIL); //执行错误
- }
- timer.Start(timeout);
- state = STATE.WAIT;
- }
- bExecute = check();
- if (bExecute == null)
- {
- return Tuple.Create(true, Result.FAIL); //Termianate
- }
- if (bExecute.Value) //检查Success, next
- {
- next();
- return Tuple.Create(true, Result.RUN);
- }
- if (timer.IsTimeout())
- return Tuple.Create(true, Result.TIMEOUT);
- return Tuple.Create(true, Result.RUN);
- }
- return Tuple.Create(false, Result.RUN);
- }
- public Tuple<bool, Result> Wait<T>(T id, IRoutine rt)
- {
- int idx = Convert.ToInt32(id);
- bool bActive = Acitve(idx);
- if (bActive)
- {
- if (state == STATE.IDLE)
- {
- rt.Start();
- state = STATE.WAIT;
- }
- Result ret = rt.Monitor();
- return Tuple.Create(true, ret);
- }
- return Tuple.Create(false, Result.RUN);
- }
- //Monitor
- public Tuple<bool, Result> Monitor<T>(T id, Func<bool> func, Func<bool> check, double time)
- {
- int idx = Convert.ToInt32(id);
- bool bActive = Acitve(idx);
- bool bCheck = false;
- if (bActive)
- {
- if (state == STATE.IDLE)
- {
- if ((func != null) && !func())
- {
- return Tuple.Create(true, Result.FAIL);
- }
- timer.Start(time);
- state = STATE.WAIT;
- }
- bCheck = check();
- if (!bCheck)
- {
- return Tuple.Create(true, Result.FAIL); //Termianate
- }
- if (timer.IsTimeout())
- {
- next();
- }
- return Tuple.Create(true, Result.RUN);
- }
- return Tuple.Create(false, Result.RUN);
- }
- //Delay
- public Tuple<bool, Result> Delay<T>(T id, Func<bool> func, double time)
- {
- int idx = Convert.ToInt32(id);
- bool bActive = Acitve(idx);
- if (bActive)
- {
- if (state == STATE.IDLE)
- {
- if ((func != null) && !func())
- {
- return Tuple.Create(true, Result.FAIL);
- }
- timer.Start(time);
- state = STATE.WAIT;
- }
- if (timer.IsTimeout())
- {
- next();
- }
- return Tuple.Create(true, Result.RUN);
- }
- return Tuple.Create(false, Result.RUN);
- }
- //先delay 再运行
- public Tuple<bool, Result> DelayCheck<T>(T id, Func<bool> func, double time)
- {
- int idx = Convert.ToInt32(id);
- bool bActive = Acitve(idx);
- if (bActive)
- {
- if (state == STATE.IDLE)
- {
- timer.Start(time);
- state = STATE.WAIT;
- }
- if (timer.IsTimeout())
- {
- if (func != null && !func())
- {
- return Tuple.Create(true, Result.FAIL);
- }
- next();
- }
- return Tuple.Create(true, Result.RUN);
- }
- return Tuple.Create(false, Result.RUN);
- }
- #endregion
- private Tuple<bool, bool> execute(int id, Func<bool> func) //顺序执行
- {
- bool bActive = Acitve(id);
- bool bExecute = false;
- if (bActive)
- {
- bExecute = func();
- if (bExecute)
- {
- next();
- }
- }
- return Tuple.Create(bActive, bExecute);
- }
- private Tuple<bool, bool> Check(int id, Func<bool> func) //check
- {
- bool bActive = Acitve(id);
- bool bExecute = false;
- if (bActive)
- {
- bExecute = func();
- next();
- }
- return Tuple.Create(bActive, bExecute);
- }
- /// <summary>
- /// </summary>
- /// <param name="id"></param>
- /// <param name="func"></param>
- /// <param name="timeout"></param>
- /// <returns>
- /// item1 Active
- /// item2 execute
- /// item3 Timeout
- ///</returns>
- private Tuple<bool, bool, bool> wait(int id, Func<bool> func, double timeout = int.MaxValue) //Wait condition
- {
- bool bActive = Acitve(id);
- bool bExecute = false;
- bool bTimeout = false;
- if (bActive)
- {
- if (state == STATE.IDLE)
- {
- timer.Start(timeout);
- state = STATE.WAIT;
- }
- bExecute = func();
- if (bExecute)
- {
- next();
- }
- bTimeout = timer.IsTimeout();
- }
- return Tuple.Create(bActive, bExecute, bTimeout);
- }
- private Tuple<bool, bool?, bool> wait(int id, Func<bool?> func, double timeout = int.MaxValue) //Wait condition && Check error
- {
- bool bActive = Acitve(id);
- bool? bExecute = false;
- bool bTimeout = false;
- if (bActive)
- {
- if (state == STATE.IDLE)
- {
- timer.Start(timeout);
- state = STATE.WAIT;
- }
- bExecute = func();
- if (bExecute.HasValue && bExecute.Value)
- {
- next();
- }
- bTimeout = timer.IsTimeout();
- }
- return Tuple.Create(bActive, bExecute, bTimeout);
- }
- /// <summary>
- /// </summary>
- /// <param name="value"></param>
- /// <returns>
- /// item1 true, return item2
- /// </returns>
- private Tuple<bool, Result> Check(Tuple<bool, bool> value)
- {
- if (value.Item1)
- {
- if (!value.Item2)
- {
- return Tuple.Create(true, Result.FAIL);
- }
- return Tuple.Create(true, Result.RUN);
- }
- return Tuple.Create(false, Result.RUN);
- }
- private Tuple<bool, Result> Check(Tuple<bool, bool, bool> value)
- {
- if (value.Item1) // 当前执行
- {
- if (CheckTimeout(value)) //timeout
- {
- return Tuple.Create(true, Result.TIMEOUT);
- }
- return Tuple.Create(true, Result.RUN);
- }
- return Tuple.Create(false, Result.RUN);
- }
- private Tuple<bool, Result> Check(Tuple<bool, bool?, bool> value)
- {
- if (value.Item1) // 当前执行
- {
- if (value.Item2 == null)
- {
- return Tuple.Create(true, Result.FAIL);
- }
- else
- {
- if (value.Item2 == false && value.Item3 == true) //timeout
- {
- return Tuple.Create(true, Result.TIMEOUT);
- }
- return Tuple.Create(true, Result.RUN);
- }
- }
- return Tuple.Create(false, Result.RUN);
- }
- private bool CheckTimeout(Tuple<bool, bool, bool> value)
- {
- return value.Item1 == true && value.Item2 == false && value.Item3 == true;
- }
- private bool Acitve(int id) //
- {
- if (_steps.Contains(id))
- return false;
- this._id = id;
- return true;
- }
- private void next()
- {
- _steps.Push(this._id);
- state = STATE.IDLE;
- }
- private void next(int step) //loop
- {
- while (_steps.Pop() != step) ;
- state = STATE.IDLE;
- }
- public void Delay(int id, double delaySeconds)
- {
- Tuple<bool, Result> ret = Delay(id, () =>
- {
- return true;
- }, delaySeconds * 1000);
- if (ret.Item1)
- {
- if (ret.Item2 == Result.RUN)
- {
- throw (new RoutineBreakException());
- }
- }
- }
- public bool IsActived(int id)
- {
- return _steps.Contains(id);
- }
-
- #endregion
- }
- }
|