GM201LVPRobot.cs 112 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479
  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.Log;
  7. using Aitex.Core.RT.OperationCenter;
  8. using Aitex.Core.RT.SCCore;
  9. using Aitex.Core.Util;
  10. using MECF.Framework.Common.CommonData;
  11. using MECF.Framework.Common.Communications;
  12. using MECF.Framework.Common.Equipment;
  13. using MECF.Framework.Common.SubstrateTrackings;
  14. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
  15. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  16. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Diagnostics;
  20. using System.Linq;
  21. using System.Text;
  22. using System.Threading;
  23. using EventType = Aitex.Core.RT.Event.EventType;
  24. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.HRC100Robots.GM201LVPRobot
  25. {
  26. public class YaskawaRobotMessage : AsciiMessage
  27. {
  28. public int UNo { get; set; }
  29. public int SeqNo { get; set; }
  30. public string Status { get; set; }
  31. public string Ackcd { get; set; }
  32. public string Command { get; set; }
  33. public string[] Data { get; set; }
  34. public string ErrorCode { get; set; }
  35. public string EvNo { get; set; }
  36. public string EvDate { get; set; }
  37. public string EvData { get; set; }
  38. }
  39. public class GM201LVPRobot : RobotBaseDevice, IConnection
  40. {
  41. //public int UnitNumber
  42. //{
  43. // get; private set;
  44. //}
  45. private bool isSimulatorMode;
  46. private string _scRoot;
  47. private bool _isError;
  48. public GM201LVPTokenGenerator SeqnoGenerator { get; private set; }
  49. public bool IsEnableSeqNo { get; private set; }
  50. public bool IsEnableCheckSum { get; private set; }
  51. public int CurrentSeqNo { get; set; }
  52. public string PortName;
  53. private string _address;
  54. private bool _enableLog;
  55. private GM201LVPRobotConnection _connection;
  56. private R_TRIG _trigError = new R_TRIG();
  57. private R_TRIG _trigCommunicationError = new R_TRIG();
  58. private R_TRIG _trigRetryConnect = new R_TRIG();
  59. public string Address => _address;
  60. private PeriodicJob _thread;
  61. private object _locker = new object();
  62. private LinkedList<HandlerBase> _lstHandlers = new LinkedList<HandlerBase>();
  63. private LinkedList<HandlerBase> _lstMonitorHandler = new LinkedList<HandlerBase>();
  64. private IoSensor _diRobotReady = null; //Normal ON
  65. private IoSensor _diRobotBlade1WaferOn = null; //Off when wafer present
  66. private IoSensor _diRobotBlade2WaferOn = null;
  67. private IoSensor _diRobotError = null; //Normal ON
  68. private IoSensor _diTPinUse = null;
  69. private IoTrigger _doRobotHold = null; // Normal ON
  70. public ModuleName CurrentInteractiveModule { get; private set; }
  71. public bool IsConnected => throw new NotImplementedException();
  72. public float CurrentThetaPosition { get; private set; }
  73. public float CurrentExtensionPosition { get; private set; }
  74. public float CurrentArm1Position { get; private set; }
  75. public float CurrentArm2Position { get; private set; }
  76. public float CurrentZPosition { get; private set; }
  77. public float CommandThetaPosition { get; private set; }
  78. public float CommandExtensionPosition { get; private set; }
  79. public float CommandArm1Position { get; private set; }
  80. public float CommandArm2Position { get; private set; }
  81. public float CommandZPosition { get; private set; }
  82. public int SpeedLevel { get; private set; }
  83. public int SpeedLevelSetting => SC.GetValue<int>($"{Name}.RobotSpeed");
  84. public string ReadMemorySpec { get; private set; }
  85. public string ReadTransferStation { get; private set; }
  86. public int ReadSlotNumber { get; private set; }
  87. public string ReadArmPosture { get; private set; }
  88. public RobotArmEnum ReadBladeNo { get; private set; }
  89. public GM201LVPPositonEnum ReadPositionType { get; private set; }
  90. public float ReadThetaPosition { get; private set; }
  91. public float ReadExtensionPosition { get; private set; }
  92. public float ReadArm1Position { get; private set; }
  93. public float ReadArm2Position { get; private set; }
  94. public float ReadZPosition { get; private set; }
  95. public Dictionary<string, string> ReadStationItemValues { get; private set; } = new Dictionary<string, string>();
  96. public Dictionary<string, string> ReadStationItemContents { get; private set; } = new Dictionary<string, string>();
  97. public string ReadParameterType { get; private set; }
  98. public string ReadParameterNo { get; private set; }
  99. public string ReadParameterValue { get; private set; }
  100. public bool IsManipulatorBatteryLow { get; private set; }
  101. public bool IsCommandExecutionReady { get; private set; }
  102. public bool IsServoON { get; private set; }
  103. public bool IsErrorOccurred { get; private set; }
  104. public bool IsControllerBatteryLow { get; private set; }
  105. public bool IsCheckInterlockWaferPresenceOnBlade1 { get; private set; }
  106. public bool IsCheckInterlockWaferPresenceOnBlade2 { get; private set; }
  107. public bool IsCheckInterlockWaferPresenceOnBlade3 { get; private set; }
  108. public bool IsCheckInterlockWaferPresenceOnBlade4 { get; private set; }
  109. public bool IsCheckInterlockWaferPresenceOnBlade5 { get; private set; }
  110. public string RobotSoftwareVersion { get; private set; }
  111. public string ReadMappingTransferStation { get; private set; }
  112. public int ReadMappingSlotNumbers { get; private set; }
  113. public string ReadSlotMap { get; private set; }
  114. public MaterialType _MaterialType { get; set; }
  115. private int _timeLimitPick => SC.GetValue<int>($"{Name}.PickTimeout");
  116. private int _timeLimitPlace => SC.GetValue<int>($"{Name}.PlaceTimeout");
  117. private int _timeLimitHome => SC.GetValue<int>($"{Name}.HomeTimeout");
  118. private int _timeLimitMotion => SC.GetValue<int>($"{Name}.MotionTimeout");
  119. public Dictionary<string, float> ReadMappingCalibrationResult { get; private set; }
  120. public Dictionary<string, string> ReadRobotParameterResult { get; private set; } = new Dictionary<string, string>();
  121. public enum MaterialType
  122. {
  123. Carrier,
  124. Wafer
  125. }
  126. private Dictionary<string, string> _moduleAssociateStationDic;
  127. public override Dictionary<string, string> ModuleAssociateStationDic
  128. {
  129. get
  130. {
  131. return _moduleAssociateStationDic;
  132. }
  133. set
  134. {
  135. _moduleAssociateStationDic = value;
  136. }
  137. }
  138. private Dictionary<string, string> _moduleAssociateHandDic;
  139. public Dictionary<string, string> ModuleAssociateHandDic
  140. {
  141. get
  142. {
  143. return _moduleAssociateHandDic;
  144. }
  145. set
  146. {
  147. _moduleAssociateHandDic = value;
  148. }
  149. }
  150. private IoAlarmSignal _tpStatus = null;
  151. public GM201LVPRobot(string module, string name, string scRoot, MaterialType material, IoSensor[] dis, IoTrigger[] dos) : base(module, name)
  152. {
  153. Module = module;
  154. Name = name;
  155. _MaterialType = material;
  156. isSimulatorMode = SC.ContainsItem("System.IsSimulatorMode") ? SC.GetValue<bool>("System.IsSimulatorMode") : false;
  157. _scRoot = scRoot;
  158. _address = SC.GetStringValue($"{Name}.Address");
  159. _enableLog = SC.GetValue<bool>($"{Name}.EnableLogMessage");
  160. //UnitNumber = SC.GetValue<int>($"{_scRoot}.{Name}.UnitNumber");
  161. //IsEnableCheckSum = SC.GetValue<bool>($"{_scRoot}.{Name}.EnableCheckSum");
  162. //IsEnableSeqNo = SC.GetValue<bool>($"{_scRoot}.{Name}.EnableSeqNo");
  163. //SpeedLevelSetting = SC.GetValue<int>($"{Name}.SpeedLevel");
  164. _connection = new GM201LVPRobotConnection(this, _address);
  165. _connection.EnableLog(_enableLog);
  166. //SeqnoGenerator = new GM201LVPTokenGenerator($"{_scRoot}.{Name}.CommunicationToken");
  167. if (dis != null && dis.Length >= 5)
  168. {
  169. _diRobotReady = dis[0];
  170. _diRobotBlade1WaferOn = dis[1];
  171. _diRobotBlade2WaferOn = dis[2];
  172. _diRobotError = dis[3];
  173. _diTPinUse = dis[4];
  174. _diRobotError.OnSignalChanged += _diRobotError_OnSignalChanged;
  175. _diTPinUse.OnSignalChanged += _diTPinUse_OnSignalChanged;
  176. }
  177. if (dos != null && dos.Length >= 1)
  178. {
  179. _doRobotHold = dos[0];
  180. }
  181. ConnectionManager.Instance.Subscribe($"{Name}", _connection);
  182. _thread = new PeriodicJob(10, OnTimer, $"{Module}.{Name} MonitorHandler", true);
  183. ReadStationItemContents.Add("00", "Upward offset");
  184. ReadStationItemContents.Add("01", "Downward offset");
  185. ReadStationItemContents.Add("02", "Grip position offset");
  186. ReadStationItemContents.Add("06", "G2/P3 offset in the extending direction");
  187. ReadStationItemContents.Add("08", "Put downward offset");
  188. ReadStationItemContents.Add("70", "Get operation Movet_grip function yes/no");
  189. ReadStationItemContents.Add("71", "Get operation rising pattern");
  190. ReadStationItemContents.Add("80", "Put operation Move_grip function yes/no");
  191. ReadStationItemContents.Add("81", "Put operation dropping pattern");
  192. ReadStationItemContents.Add("50", "Slot Numbers");
  193. ReadStationItemContents.Add("30", "Slot pitch(Left elbow,Blade1)");
  194. ReadStationItemContents.Add("31", "Slot pitch(Left elbow,Blade2)");
  195. ReadStationItemContents.Add("32", "Slot pitch(Right elbow,Blade1)");
  196. ReadStationItemContents.Add("33", "Slot pitch(Right elbow,Blade2)");
  197. if (Name == "CarrierRobot")
  198. {
  199. _tpStatus = DEVICE.GetDevice<IoAlarmSignal>($"PM1.AlarmSignaFOUPRobotTPStatusWarning");
  200. }
  201. else
  202. {
  203. _tpStatus = DEVICE.GetDevice<IoAlarmSignal>($"PM1.AlarmSignaWaferRobotTPStatusWarning");
  204. }
  205. ResetPropertiesAndResponses();
  206. RegisterSpecialData();
  207. RegisterAlarm();
  208. }
  209. protected override void SubscribeWaferLocation()
  210. {
  211. }
  212. private void RegisterAlarm()
  213. {
  214. EV.Subscribe(new EventItem("Alarm", $"{Name}Error040", $"{Name} Robot Occurred Error:机械手在 TP 模式中,命令被拒绝。", "机械手在 TP 模式中,命令被拒绝。"));
  215. EV.Subscribe(new EventItem("Alarm", $"{Name}Error041", $"{Name} Robot Occurred Error:机械手在空模式中,命令被拒绝。", "机械手在空模式中,命令被拒绝。"));
  216. EV.Subscribe(new EventItem("Alarm", $"{Name}Error055", $"{Name} Robot Occurred Error:设定无法访问的工位。", "指定了不可访问的工位类型。"));
  217. EV.Subscribe(new EventItem("Alarm", $"{Name}Error057", $"{Name} Robot Occurred Error:运动失败。", "伺服电机执行运动程序失败。"));
  218. EV.Subscribe(new EventItem("Alarm", $"{Name}Error070", $"{Name} Robot Occurred Error:位置未记录完整。", "命令被拒绝,因为此工位没有示教,未记录位置信息。"));
  219. EV.Subscribe(new EventItem("Alarm", $"{Name}Error072", $"{Name} Robot Occurred Error:层数超限。", "机械手运行位置已超出工位层数上限。"));
  220. EV.Subscribe(new EventItem("Alarm", $"{Name}Error073", $"{Name} Robot Occurred Error:禁止轴动作。", "当前轴动作可能会导致碰撞。"));
  221. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*00", $"{Name} Robot Occurred Error:伺服报警。", "控制器判断驱动器有报警。"));
  222. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*01", $"{Name} Robot Occurred Error:伺服警告。", "控制器判断驱动器警告。"));
  223. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*02", $"{Name} Robot Occurred Error:伺服驱动器参数错误1", "伺服单元的参数有误差。"));
  224. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*03", $"{Name} Robot Occurred Error:主回路错误。", "主电路的检测数据有错误。"));
  225. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*04", $"{Name} Robot Occurred Error:伺服驱动器参数错误2。", "伺服参数异常。"));
  226. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*05", $"{Name} Robot Occurred Error:结合误差1。", "连接不支持的设备。"));
  227. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*07", $"{Name} Robot Occurred Error:结合误差2。", "编码器类型不匹配。"));
  228. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*08", $"{Name} Robot Occurred Error:伺服驱动器参数错误3。", "伺服参数异常。"));
  229. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*10", $"{Name} Robot Occurred Error:溢出电流。", "过电流。"));
  230. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*30", $"{Name} Robot Occurred Error:检测到再生错误。", "检测再生电路错误。"));
  231. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*32", $"{Name} Robot Occurred Error:再生过载。", "发生再生过载。"));
  232. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*33", $"{Name} Robot Occurred Error:主电路电源接线错误。", "电源接线不正确。"));
  233. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*40", $"{Name} Robot Occurred Error:过电压。", "驱动器电压过高。"));
  234. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*41", $"{Name} Robot Occurred Error:欠电压。", "驱动器电压过底。"));
  235. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*50", $"{Name} Robot Occurred Error:碰撞检出警报。", "检测到了碰撞发生。"));
  236. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*51", $"{Name} Robot Occurred Error:电机超速。", "电机转速过高。"));
  237. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*52", $"{Name} Robot Occurred Error:振动报警。", "电机转速出现异常振荡。"));
  238. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*55", $"{Name} Robot Occurred Error:伺服驱动器参数错误4。", "伺服参数异常。"));
  239. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*71", $"{Name} Robot Occurred Error:瞬时过载(电机)。", "电机被施加了很大程度上超过额定值的转矩。"));
  240. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*72", $"{Name} Robot Occurred Error:连续过载(电机)。", "一个大大超过额定值的转矩被连续施加。"));
  241. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*73", $"{Name} Robot Occurred Error:动态制动过载。", "超过动态制动电阻容量。"));
  242. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*74", $"{Name} Robot Occurred Error:浪涌限流电阻过载。", "主电路电源经常被打开和关闭。"));
  243. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*7A", $"{Name} Robot Occurred Error:控制器风机停止。", "控制器风扇停止运行。"));
  244. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*7B", $"{Name} Robot Occurred Error:温度传感器电路错误。", "温度传感器电路错误。"));
  245. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*81", $"{Name} Robot Occurred Error:绝对编码器备份错误。", "绝对编码器电池被移除过,位置数据被清除。"));
  246. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*82", $"{Name} Robot Occurred Error:绝对编码器校验错误", "编码器内存的校验和结果有错误。"));
  247. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*83", $"{Name} Robot Occurred Error:绝对编码器的电池电压低。", "绝对值编码器备用电池电压低。"));
  248. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*84", $"{Name} Robot Occurred Error:编码器数据误差。", "编码器内部数据错误。"));
  249. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*85", $"{Name} Robot Occurred Error:编码器速度过快。", "通电时编码器高速旋转。"));
  250. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*86", $"{Name} Robot Occurred Error:编码器过热。", "编码器过热。"));
  251. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*B3", $"{Name} Robot Occurred Error:电流检测错误。", "电流检测电路错误。"));
  252. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*B6", $"{Name} Robot Occurred Error:伺服 M-III 通信错误。", "MECHATROLINK 通信出现错误。"));
  253. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*BF", $"{Name} Robot Occurred Error:系统报警。", "伺服单元内部程序错误。"));
  254. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*C1", $"{Name} Robot Occurred Error:电机失控。", "伺服电机失控。"));
  255. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*C2", $"{Name} Robot Occurred Error:相位信息不匹配。", "相位信息不匹配。"));
  256. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*C5", $"{Name} Robot Occurred Error:极性检测失败。", "极性检测错误。"));
  257. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*C8", $"{Name} Robot Occurred Error:编码器复位错误。", "多回合数据未正确清除或设置。"));
  258. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*C9", $"{Name} Robot Occurred Error:编码器通信错误。", "编码器与伺服单元通信错误。"));
  259. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*CA", $"{Name} Robot Occurred Error:编码器参数错误1。", "编码器中的参数已损坏。"));
  260. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*CB", $"{Name} Robot Occurred Error:编码器参数错误2。", "与编码器通信的内容不正确。"));
  261. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*CC", $"{Name} Robot Occurred Error:编码器参数错误3。", "编码器与驱动器数据不一致。"));
  262. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*D0", $"{Name} Robot Occurred Error:位置偏差错误。", "位置偏差脉冲超过设定值。"));
  263. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*D3", $"{Name} Robot Occurred Error:位置数据溢出。", "反馈数据超过+1,879,048,192。"));
  264. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*D8", $"{Name} Robot Occurred Error:转矩检测异常。", "检测到异常转矩。"));
  265. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*E0", $"{Name} Robot Occurred Error:伺服 M-III 通信错误 2。", "MECHATROLINK 与伺服单元通信时发生同步错误。"));
  266. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*E4", $"{Name} Robot Occurred Error:伺服 M-III 通信错误 3。", "MECHATROLINK 通信设置不正确。"));
  267. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*E5", $"{Name} Robot Occurred Error:伺服 M-III 通信错误 4。", "MECHATROLINK 与伺服单元通信时发生同步错误。"));
  268. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*E6", $"{Name} Robot Occurred Error:伺服 M-III 通信错误 5。", "MECHATROLINK 通信出现错误。"));
  269. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*ED", $"{Name} Robot Occurred Error:伺服 M-III 通信错误 6。", "MECHATROLINK 通信出现错误。"));
  270. EV.Subscribe(new EventItem("Alarm", $"{Name}Error*F1", $"{Name} Robot Occurred Error:相位损失。", "电源缺相。"));
  271. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorE*E", $"{Name} Robot Occurred Error:通信错误(内部控制器)。", "控制器内部通信故障。"));
  272. EV.Subscribe(new EventItem("Alarm", $"{Name}Error930", $"{Name} Robot Occurred Error:未定义的命令收到。", "从主机接收到未定义的命令。"));
  273. EV.Subscribe(new EventItem("Alarm", $"{Name}Error940", $"{Name} Robot Occurred Error:消息参数错误。", "从主机接收的命令附加的参数无效。"));
  274. EV.Subscribe(new EventItem("Alarm", $"{Name}Error950", $"{Name} Robot Occurred Error:机械手在运动中,命令被拒绝。", "命令被拒绝,控制器正在执行一个运动命令。"));
  275. EV.Subscribe(new EventItem("Alarm", $"{Name}Error970", $"{Name} Robot Occurred Error:分隔符错误。", "没有分隔符。"));
  276. EV.Subscribe(new EventItem("Alarm", $"{Name}Error971", $"{Name} Robot Occurred Error:结束符错误。", "结束符不正确。"));
  277. EV.Subscribe(new EventItem("Alarm", $"{Name}Error972", $"{Name} Robot Occurred Error:指令长度错误。", "指令长度不正确。"));
  278. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorA10", $"{Name} Robot Occurred Error:外部急停。", "I/O 启用外部紧急停止(EXESP)功能。"));
  279. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorA20", $"{Name} Robot Occurred Error:T.P 紧急停。", "教学挂件上的急停按钮被按下。"));
  280. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorA30", $"{Name} Robot Occurred Error:急停。", "主机发出紧急停止命令。"));
  281. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorA31", $"{Name} Robot Occurred Error:碰撞检出。", "机械手发生碰撞。"));
  282. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorA45", $"{Name} Robot Occurred Error:单元风扇1错误。", "主机风扇1故障。"));
  283. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorA47", $"{Name} Robot Occurred Error:机械手风扇1错误。", "机械手风扇故障。"));
  284. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorA4F", $"{Name} Robot Occurred Error:控制器电池报警。", "控制器内存备用电池电量不足。"));
  285. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorA60", $"{Name} Robot Occurred Error:F47 连续错误。", "重新检测到供电电压下降。"));
  286. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorAE0", $"{Name} Robot Occurred Error:主机模式切换错误。", "模式切换到“HOST”,同时从示教器控制。"));
  287. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorAE1", $"{Name} Robot Occurred Error:教模式切换错误。", "在主机控制下切换为“TEACH”模式。"));
  288. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorAE8", $"{Name} Robot Occurred Error:伺服使能开关错误。", "示教器操作时松开使能开关。"));
  289. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorAF0", $"{Name} Robot Occurred Error:互锁故障1。", "检测到安全模块错误。"));
  290. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorAF1", $"{Name} Robot Occurred Error:互锁故障2。", "检测到安全模块错误。"));
  291. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorAF2", $"{Name} Robot Occurred Error:互锁故障3。", "检测到安全模块错误。"));
  292. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorAF3", $"{Name} Robot Occurred Error:互锁故障4。", "检测到安全模块错误。"));
  293. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorAF4", $"{Name} Robot Occurred Error:互锁故障5。", "检测到安全模块错误。"));
  294. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorAF5", $"{Name} Robot Occurred Error:互锁故障6。", "检测到安全模块错误。"));
  295. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorAF6", $"{Name} Robot Occurred Error:互锁故障7。", "检测到安全模块错误。"));
  296. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorAF8", $"{Name} Robot Occurred Error:互锁故障8。", "检测到安全模块错误。"));
  297. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorAF9", $"{Name} Robot Occurred Error:互锁故障9。", "检测到安全模块错误。"));
  298. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorAFA", $"{Name} Robot Occurred Error:互锁故障10。", "检测到安全模块错误。"));
  299. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorAFB", $"{Name} Robot Occurred Error:互锁故障11。", "检测到安全模块错误。"));
  300. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorAFC", $"{Name} Robot Occurred Error:互锁故障12。", "检测到安全模块错误。"));
  301. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB20", $"{Name} Robot Occurred Error:轴1正(+)方向软件限位检测1。", "正方向超过Axis-1运动范围。"));
  302. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB21", $"{Name} Robot Occurred Error:轴2正(+)方向软件限位检测1。", "正方向超过Axis-3运动范围。."));
  303. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB22", $"{Name} Robot Occurred Error:轴3正(+)方向软件限位检测1。", "正方向超过Axis-3运动范围。"));
  304. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB23", $"{Name} Robot Occurred Error:轴4正(+)方向软件限位检测1。", "正方向超过Axis-4运动范围。"));
  305. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB24", $"{Name} Robot Occurred Error:轴5正(+)方向软件限位检测1。", "正方向超过Axis-5运动范围。"));
  306. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB25", $"{Name} Robot Occurred Error:轴6正(+)方向软件限位检测1。", "正方向超过Axis-6运动范围。"));
  307. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB28", $"{Name} Robot Occurred Error:轴1正(+)方向限位检测。", "正方向超过Axis-1运动范围。"));
  308. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB29", $"{Name} Robot Occurred Error:轴2正(+)方向限位检测。", "正方向超过Axis-2运动范围。"));
  309. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB2A", $"{Name} Robot Occurred Error:轴3正(+)方向限位检测。", "正方向超过Axis-3运动范围。"));
  310. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB2B", $"{Name} Robot Occurred Error:轴4正(+)方向限位检测。", "正方向超过Axis-4运动范围。"));
  311. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB2C", $"{Name} Robot Occurred Error:轴5正(+)方向限位检测。", "正方向超过Axis-5运动范围。"));
  312. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB2D", $"{Name} Robot Occurred Error:轴6正(+)方向限位检测。", "正方向超过Axis-6运动范围。"));
  313. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB30", $"{Name} Robot Occurred Error:轴1负(-)方向软件限位检测1。", "负方向超过Axis-1运动范围。"));
  314. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB31", $"{Name} Robot Occurred Error:轴2负(-)方向软件限位检测1。", "负方向超过Axis-2运动范围。"));
  315. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB32", $"{Name} Robot Occurred Error:轴3负(-)方向软件限位检测1。", "负方向超过Axis-3运动范围。"));
  316. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB33", $"{Name} Robot Occurred Error:轴4负(-)方向软件限位检测1。", "负方向超过Axis-4运动范围。"));
  317. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB34", $"{Name} Robot Occurred Error:轴5负(-)方向软件限位检测1。", "负方向超过Axis-5运动范围。"));
  318. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB35", $"{Name} Robot Occurred Error:轴6负(-)方向软件限位检测1。", "负方向超过Axis-6运动范围。"));
  319. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB38", $"{Name} Robot Occurred Error:轴1负(-)方向限位检测。", "负方向超过Axis-1运动范围。"));
  320. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB39", $"{Name} Robot Occurred Error:轴2负(-)方向限位检测。", "负方向超过Axis-2运动范围。"));
  321. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB3A", $"{Name} Robot Occurred Error:轴3负(-)方向限位检测。", "负方向超过Axis-3运动范围。"));
  322. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB3B", $"{Name} Robot Occurred Error:轴4负(-)方向限位检测。", "负方向超过Axis-4运动范围。"));
  323. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB3C", $"{Name} Robot Occurred Error:轴5负(-)方向限位检测。", "负方向超过Axis-5运动范围。"));
  324. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB3D", $"{Name} Robot Occurred Error:轴6负(-)方向限位检测。", "负方向超过Axis-6运动范围。"));
  325. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB88", $"{Name} Robot Occurred Error:手爪传感器ON超时错误1。", "取片时手爪传感器1没有在规定时间内ON。"));
  326. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB89", $"{Name} Robot Occurred Error:手爪传感器ON超时错误2。", "取片时手爪传感器2没有在规定时间内ON。"));
  327. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB8A", $"{Name} Robot Occurred Error:手爪传感器OFF超时错误1。", "放片时手爪传感器1没有在规定时间内OFF。"));
  328. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorB8B", $"{Name} Robot Occurred Error:手爪传感器OFF超时错误2。", "放片时手爪传感器2没有在规定时间内OFF。"));
  329. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorBA8", $"{Name} Robot Occurred Error:手爪传感器OFF状态错误1。", "取片时手爪传感器1状态应该为OFF但当前状态未符合。"));
  330. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorBA9", $"{Name} Robot Occurred Error:手爪传感器OFF状态错误2。", "取片时手爪传感器2状态应该为OFF但当前状态未符合。"));
  331. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorBAA", $"{Name} Robot Occurred Error:手爪传感器ON状态错误1。", "放片时手爪传感器1状态应该为ON但当前状态未符合。"));
  332. EV.Subscribe(new EventItem("Alarm", $"{Name}ErrorBAB", $"{Name} Robot Occurred Error:手爪传感器ON状态错误2。", "放片时手爪传感器 2 状态应该为 ON 但当前状态未符合。"));
  333. }
  334. public void NotifyAlarmByErrorCode(string errorcode)
  335. {
  336. EV.Notify($"{Name}Error{errorcode}");
  337. }
  338. private void _diTPinUse_OnSignalChanged(IoSensor arg1, bool arg2)
  339. {
  340. SetMaintenanceMode(!arg1.Value);
  341. }
  342. private void _diRobotError_OnSignalChanged(IoSensor arg1, bool arg2)
  343. {
  344. if (arg1.Value == false)
  345. {
  346. lock (_locker)
  347. {
  348. _lstHandlers.AddLast(new GM201LVPRobotReadHandler(this, "RSTS"));
  349. }
  350. OnError("RobotError");
  351. }
  352. }
  353. private void ResetPropertiesAndResponses()
  354. {
  355. }
  356. private void RegisterSpecialData()
  357. {
  358. if(Name != "CarrierRobot")
  359. {
  360. DATA.Subscribe($"{Name}.CurrentArm1Position", () => CurrentArm1Position);
  361. DATA.Subscribe($"{Name}.CurrentArm2Position", () => CurrentArm2Position);
  362. DATA.Subscribe($"{Name}.CurrentZPosition", () => CurrentZPosition);
  363. DATA.Subscribe($"{Name}.IsWaferPresenceOnBlade2", () => IsWaferPresenceOnBlade2);
  364. DATA.Subscribe($"{Name}.IsWaferPresenceOnBlade3", () => IsWaferPresenceOnBlade3);
  365. DATA.Subscribe($"{Name}.IsWaferPresenceOnBlade4", () => IsWaferPresenceOnBlade4);
  366. DATA.Subscribe($"{Name}.IsWaferPresenceOnBlade5", () => IsWaferPresenceOnBlade5);
  367. }
  368. DATA.Subscribe($"{Name}.TPStatus", () => _tpStatus != null&& _tpStatus.Value);
  369. DATA.Subscribe($"{Name}.CurrentExtensionPosition", () => CurrentExtensionPosition);
  370. DATA.Subscribe($"{Name}.CurrentThetaPosition", () => CurrentThetaPosition);
  371. DATA.Subscribe($"{Name}.IsManipulatorBatteryLow", () => IsManipulatorBatteryLow);
  372. DATA.Subscribe($"{Name}.IsCommandExecutionReady", () => IsCommandExecutionReady);
  373. DATA.Subscribe($"{Name}.IsServoON", () => IsServoON);
  374. DATA.Subscribe($"{Name}.IsErrorOccurred", () => IsErrorOccurred);
  375. DATA.Subscribe($"{Name}.IsControllerBatteryLow", () => IsControllerBatteryLow);
  376. DATA.Subscribe($"{Name}.IsWaferPresenceOnBlade1", () => IsWaferPresenceOnBlade1);
  377. DATA.Subscribe($"{Name}.MappingResult", () => ReadSlotMap);
  378. DATA.Subscribe($"{Name}.ReadRobotParameterResultDict", () => ReadRobotParameterResult);
  379. DATA.Subscribe($"{Name}.ErrorCode", () => ErrorCode);
  380. DATA.Subscribe($"{Name}.RobotSpeed", () => SpeedLevelSetting.ToString());
  381. OP.Subscribe($"{Name}.SetSpeed", InvokeSetSpeed);
  382. }
  383. private bool OnTimer()
  384. {
  385. try
  386. {
  387. _connection.MonitorTimeout();
  388. if (!_connection.IsConnected || _connection.IsCommunicationError)
  389. {
  390. lock (_locker)
  391. {
  392. _lstHandlers.Clear();
  393. _lstMonitorHandler.Clear();
  394. }
  395. _trigRetryConnect.CLK = !_connection.IsConnected;
  396. if (_trigRetryConnect.Q)
  397. {
  398. if (!_connection.Connect())
  399. {
  400. EV.PostAlarmLog(RobotModuleName.ToString(), $"Can not connect with {_connection.Address}, {Name}");
  401. }
  402. else
  403. {
  404. //_lstHandler.AddLast(new RobotHirataR4QueryPinHandler(this, _deviceAddress));
  405. //_lstHandler.AddLast(new RobotHirataR4SetCommModeHandler(this, _deviceAddress, EnumRfPowerCommunicationMode.Host));
  406. }
  407. }
  408. return true;
  409. }
  410. HandlerBase handler = null;
  411. lock (_locker)
  412. {
  413. if (!_connection.IsBusy)
  414. {
  415. if (_lstHandlers.Count > 0)
  416. {
  417. handler = _lstHandlers.First.Value;
  418. _connection.Execute(handler);
  419. _lstHandlers.RemoveFirst();
  420. }
  421. else
  422. {
  423. if (_lstMonitorHandler.Count > 0)
  424. {
  425. handler = _lstMonitorHandler.First.Value;
  426. _connection.Execute(handler);
  427. _lstMonitorHandler.RemoveFirst();
  428. }
  429. }
  430. }
  431. else
  432. {
  433. _connection.MonitorTimeout();
  434. _trigCommunicationError.CLK = _connection.IsCommunicationError;
  435. if (_trigCommunicationError.Q)
  436. {
  437. _lstHandlers.Clear();
  438. _lstMonitorHandler.Clear();
  439. //EV.PostAlarmLog(RobotModuleName.ToString(), $"{Module}.{Name} communication error, {_connection.LastCommunicationError}");
  440. OnError($"{Name} communication error, {_connection.LastCommunicationError}");
  441. //_trigActionDone.CLK = true;
  442. }
  443. }
  444. }
  445. }
  446. catch (Exception ex)
  447. {
  448. LOG.Write(ex);
  449. }
  450. return true;
  451. }
  452. public bool Connect()
  453. {
  454. return _connection.Connect();
  455. }
  456. public bool Disconnect()
  457. {
  458. return _connection.Disconnect();
  459. }
  460. public override bool IsReady()
  461. {
  462. //if (_diRobotReady!=null && !_diRobotReady.Value)
  463. // return false;
  464. if (_diRobotError != null && !_diRobotError.Value)
  465. return false;
  466. if (_diTPinUse != null && !_diTPinUse.Value)
  467. return false;
  468. return RobotState == RobotStateEnum.Idle && !IsBusy && !_connection.IsBusy && _lstHandlers.Count == 0 && !_connection.IsCommunicationError && _connection.IsConnected;
  469. }
  470. public override bool IsReady(out string reason)
  471. {
  472. reason = "";
  473. //if (_diRobotReady!=null && !_diRobotReady.Value)
  474. // return false;
  475. if (_diRobotError != null && !_diRobotError.Value)
  476. return false;
  477. if (_diTPinUse != null && !_diTPinUse.Value)
  478. return false;
  479. var ret = RobotState == RobotStateEnum.Idle && !IsBusy && !_connection.IsBusy && _lstHandlers.Count == 0 && !_connection.IsCommunicationError && _connection.IsConnected;
  480. if (!ret)
  481. {
  482. if (RobotState != RobotStateEnum.Idle)
  483. reason = "RobotState != RobotStateEnum.Idle";
  484. if (IsBusy)
  485. reason = "IsBusy";
  486. if (_lstHandlers.Count != 0)
  487. reason = "_lstHandlers.Count != 0";
  488. if (_connection.IsCommunicationError)
  489. reason = "_connection.IsCommunicationError";
  490. if (!_connection.IsConnected)
  491. reason = "!_connection.IsConnected";
  492. }
  493. return ret;
  494. }
  495. public bool ParseReadData(string _command, string[] rdata)
  496. {
  497. try
  498. {
  499. if (_command == "RSTS")
  500. {
  501. return ((rdata.Length == 3 || rdata.Length == 2) && ParseRSTSStatus(rdata));
  502. }
  503. if (_command == "RSLV") //Read the speed level
  504. {
  505. return (rdata.Length == 3 && ParseSpeedLevel(rdata[2]));
  506. }
  507. if (_command == "RPOS") //Reference current postion
  508. {
  509. return (rdata.Length > 1 && ParsePositionData(rdata));
  510. }
  511. if (_command == "RSTP") //Reference registered position, read the save postion for station
  512. {
  513. if (rdata.Length == 5)
  514. {
  515. return ParsePositionAxisDataV2(rdata);
  516. }
  517. if (rdata.Length ==7)
  518. {
  519. return ParsePositionAxisData(rdata);
  520. }
  521. // return (rdata.Length > 6 && ParseRegisteredPositionData(rdata));
  522. }
  523. if (_command == "RSTR") //Reference station item value
  524. {
  525. return (rdata.Length == 4 && ParseStationData(rdata));
  526. }
  527. if (_command == "RPRM") //Reference the parameter values of the specified unit
  528. {
  529. return (rdata.Length == 3 && ParseParameterData(rdata));
  530. }
  531. if (_command == "RMSK") //Reference the interlock information
  532. {
  533. return (rdata.Length == 1 && ParseInterlockInfo(rdata));
  534. }
  535. if (_command == "RVER") //Reference the software version
  536. {
  537. return (rdata.Length == 2 && ParseSoftwareVersion(rdata));
  538. }
  539. if (_command == "RMAP") //Reference the slot map
  540. {
  541. return (rdata.Length > 2 && ParseSlotMap(rdata));
  542. }
  543. if (_command == "RMPD") //reference the mapping data
  544. {
  545. return (rdata.Length > 1 && ParseMappingData(rdata));
  546. }
  547. if (_command == "RMCA") // Reference the mapping calibration result
  548. {
  549. return (rdata.Length > 1 && ParseMappingCalibrationResult(rdata));
  550. }
  551. if (_command == "RERR") // Request ERR
  552. {
  553. return (rdata.Length > 2 && ParseERR(rdata));
  554. }
  555. return true;
  556. }
  557. catch (Exception ex)
  558. {
  559. LOG.Write(ex);
  560. return true;
  561. }
  562. }
  563. public bool ParseRSTSStatus(string[] status)
  564. {
  565. try
  566. {
  567. if (status.Length > 2)
  568. {
  569. //wafer robot
  570. int intstatus = Convert.ToInt16(status[2].Substring(5, 2), 16);
  571. IsWaferPresenceOnBlade5 = (((intstatus >> 4) & 0x1) == 0x1);
  572. IsWaferPresenceOnBlade4 = (((intstatus >> 3) & 0x1) == 0x1);
  573. IsWaferPresenceOnBlade3 = (((intstatus >> 2) & 0x1) == 0x1);
  574. IsWaferPresenceOnBlade2 = (((intstatus >> 1) & 0x1) == 0x1);
  575. IsWaferPresenceOnBlade1 = (((intstatus >> 0) & 0x1) == 0x1);
  576. }
  577. else
  578. {
  579. //foup robot
  580. int intstatus = Convert.ToInt16(status[1].Substring(5, 2), 16);
  581. IsWaferPresenceOnBlade5 = (((intstatus >> 4) & 0x1) == 0x1);
  582. IsWaferPresenceOnBlade4 = (((intstatus >> 3) & 0x1) == 0x1);
  583. IsWaferPresenceOnBlade3 = (((intstatus >> 2) & 0x1) == 0x1);
  584. IsWaferPresenceOnBlade2 = (((intstatus >> 1) & 0x1) == 0x1);
  585. IsWaferPresenceOnBlade1 = (((intstatus >> 0) & 0x1) == 0x1);
  586. }
  587. return true;
  588. }
  589. catch (Exception ex)
  590. {
  591. LOG.Write(ex);
  592. return true;
  593. }
  594. }
  595. public bool ParseSpeedLevel(string speedlevel)
  596. {
  597. try
  598. {
  599. int level = Convert.ToInt32(speedlevel);
  600. if (level < 1 || level > 100) return false;
  601. SpeedLevel = level;
  602. return true;
  603. }
  604. catch (Exception ex)
  605. {
  606. LOG.Write(ex);
  607. return false;
  608. }
  609. }
  610. public bool ParsePositionData(string[] pdata)
  611. {
  612. try
  613. {
  614. if (pdata[1] == "R" || pdata[1] == "F")
  615. {
  616. CommandZPosition = Convert.ToSingle(pdata[1]) / 1000;
  617. CommandThetaPosition = Convert.ToSingle(pdata[2]) / 1000;
  618. CommandExtensionPosition = Convert.ToSingle(pdata[3]) / 1000;
  619. return true;
  620. }
  621. return false;
  622. }
  623. catch (Exception ex)
  624. {
  625. LOG.Write(ex);
  626. return false;
  627. }
  628. }
  629. public bool ParsePositionAxisData(string[] pdata)
  630. {
  631. try
  632. {
  633. ReadMemorySpec = pdata[0];
  634. ReadTransferStation = pdata[1];
  635. if (ReadStationItemValues.ContainsKey(pdata[2]))
  636. ReadStationItemValues.Remove(pdata[2]);
  637. ReadStationItemValues.Add(pdata[2], pdata[3]);
  638. if (ReadRobotParameterResult.ContainsKey(ReadTransferStation))
  639. {
  640. ReadRobotParameterResult[ReadTransferStation] = $"{pdata[2]},{pdata[3]},{pdata[4]},{pdata[5]},{pdata[6]}";
  641. }
  642. else
  643. {
  644. ReadRobotParameterResult.Add(ReadTransferStation, $"{pdata[2]},{pdata[3]},{pdata[4]},{pdata[5]},{pdata[6]}");
  645. }
  646. return true;
  647. }
  648. catch (Exception ex)
  649. {
  650. LOG.Write(ex);
  651. return false;
  652. }
  653. }
  654. public bool ParsePositionAxisDataV2(string[] pdata)
  655. {
  656. try
  657. {
  658. ReadMemorySpec = pdata[0];
  659. ReadTransferStation = pdata[1];
  660. if (ReadStationItemValues.ContainsKey(pdata[2]))
  661. ReadStationItemValues.Remove(pdata[2]);
  662. ReadStationItemValues.Add(pdata[2], pdata[3]);
  663. if (ReadRobotParameterResult.ContainsKey(ReadTransferStation))
  664. {
  665. ReadRobotParameterResult[ReadTransferStation] = $"{pdata[2]},{pdata[3]},{pdata[4]}";
  666. }
  667. else
  668. {
  669. ReadRobotParameterResult.Add(ReadTransferStation, $"{pdata[2]},{pdata[3]},{pdata[4]}");
  670. }
  671. return true;
  672. }
  673. catch (Exception ex)
  674. {
  675. LOG.Write(ex);
  676. return false;
  677. }
  678. }
  679. public bool ParseRegisteredPositionData(string[] pdata)
  680. {
  681. try
  682. {
  683. ReadMemorySpec = pdata[0];
  684. ReadTransferStation = pdata[1];
  685. ReadSlotNumber = Convert.ToInt16(pdata[2]);
  686. ReadArmPosture = pdata[3];
  687. ReadBladeNo = (RobotArmEnum)(Convert.ToInt16(pdata[4]) - 1);
  688. if (pdata[5] == "S")
  689. ReadPositionType = GM201LVPPositonEnum.RegisteredPosition;
  690. if (pdata[5] == "R")
  691. ReadPositionType = GM201LVPPositonEnum.ReadyPosition;
  692. if (pdata[5] == "M")
  693. ReadPositionType = GM201LVPPositonEnum.IntermediatePosition;
  694. if (pdata[5] == "B")
  695. ReadPositionType = GM201LVPPositonEnum.MappingStartPosition;
  696. if (pdata[5] == "E")
  697. ReadPositionType = GM201LVPPositonEnum.MappingFinishPosition;
  698. return true;
  699. }
  700. catch (Exception ex)
  701. {
  702. LOG.Write(ex);
  703. return false;
  704. }
  705. }
  706. public bool ParseStationData(string[] pdata)
  707. {
  708. try
  709. {
  710. ReadMemorySpec = pdata[0];
  711. ReadTransferStation = pdata[1];
  712. if (ReadStationItemValues.ContainsKey(pdata[2]))
  713. ReadStationItemValues.Remove(pdata[2]);
  714. ReadStationItemValues.Add(pdata[2], pdata[3]);
  715. if (ReadRobotParameterResult.ContainsKey(ReadTransferStation))
  716. {
  717. ReadRobotParameterResult[ReadTransferStation] = $"{pdata[2]},{pdata[3]}";
  718. }
  719. else
  720. {
  721. ReadRobotParameterResult.Add(ReadTransferStation, $"{pdata[2]},{pdata[3]}");
  722. }
  723. return true;
  724. }
  725. catch (Exception ex)
  726. {
  727. LOG.Write(ex);
  728. return false;
  729. }
  730. }
  731. public bool ParseParameterData(string[] pdata)
  732. {
  733. try
  734. {
  735. ReadParameterType = pdata[0];
  736. ReadParameterNo = pdata[1];
  737. ReadParameterValue = pdata[2];
  738. if (ReadRobotParameterResult.ContainsKey(ReadParameterNo))
  739. {
  740. ReadRobotParameterResult[ReadParameterNo] = ReadParameterValue;
  741. }
  742. else
  743. {
  744. ReadRobotParameterResult.Add(ReadParameterNo, ReadParameterValue);
  745. }
  746. return true;
  747. }
  748. catch (Exception ex)
  749. {
  750. LOG.Write(ex);
  751. return false;
  752. }
  753. }
  754. public bool ParseInterlockInfo(string[] pdata)
  755. {
  756. try
  757. {
  758. int intdata = Convert.ToInt16(pdata[1]);
  759. IsCheckInterlockWaferPresenceOnBlade1 = (intdata & 0x1) == 0;
  760. IsCheckInterlockWaferPresenceOnBlade2 = (intdata & 0x2) == 0;
  761. IsCheckInterlockWaferPresenceOnBlade3 = (intdata & 0x4) == 0;
  762. IsCheckInterlockWaferPresenceOnBlade4 = (intdata & 0x8) == 0;
  763. IsCheckInterlockWaferPresenceOnBlade5 = (intdata & 0x16) == 0;
  764. return true;
  765. }
  766. catch (Exception ex)
  767. {
  768. LOG.Write(ex);
  769. return false;
  770. }
  771. }
  772. public bool ParseSoftwareVersion(string[] pdata)
  773. {
  774. try
  775. {
  776. //RobotSystemVersion = pdata[0];
  777. RobotSoftwareVersion = pdata[1];
  778. return true;
  779. }
  780. catch (Exception ex)
  781. {
  782. LOG.Write(ex);
  783. return false;
  784. }
  785. }
  786. public bool ParseERR(string[] pdata)
  787. {
  788. try
  789. {
  790. var index = pdata[1];
  791. var code = pdata[2];
  792. if (code != "000")
  793. {
  794. EV.Notify($"{Name}Error{code}");
  795. LOG.Write($"{Name} Error {index} {code}");
  796. _isError = true;
  797. }
  798. else
  799. {
  800. _isError = false;
  801. }
  802. return true;
  803. }
  804. catch (Exception ex)
  805. {
  806. LOG.Write(ex);
  807. return false;
  808. }
  809. }
  810. public bool ParseSlotMap(string[] pdata)
  811. {
  812. try
  813. {
  814. ReadMappingTransferStation = pdata[1];
  815. ReadMappingSlotNumbers = pdata[2].Length - 1;
  816. StringBuilder sb = new StringBuilder();
  817. for (int i = 1; i < pdata[2].Length; i++)
  818. {
  819. string value = pdata[2][i].ToString();
  820. switch (value)
  821. {
  822. case "0":
  823. sb.Append("0");
  824. break;
  825. case "1":
  826. sb.Append("1");
  827. break;
  828. case "C":
  829. sb.Append("C");
  830. break;
  831. case "D":
  832. sb.Append("D");
  833. break;
  834. }
  835. }
  836. SlotMap = ReadSlotMap = sb.ToString();
  837. NotifySlotMapResult(CurrentInteractiveModule, ReadSlotMap);
  838. return true;
  839. }
  840. catch (Exception ex)
  841. {
  842. LOG.Write(ex);
  843. return false;
  844. }
  845. }
  846. public bool ParseMappingData(string[] pdata)
  847. {
  848. try
  849. {
  850. ReadMappingTransferStation = pdata[0];
  851. List<string> lstupdata = new List<string>();
  852. List<string> lstdowndata = new List<string>();
  853. for (int i = 0; i < (pdata.Length - 1) / 2; i++)
  854. {
  855. lstupdata.Add(pdata[2 * i + 1].Remove(0, 3));
  856. lstdowndata.Add(pdata[2 * i + 2]);
  857. }
  858. ReadMappingDownData = lstdowndata.ToArray();
  859. ReadMappingUpData = lstupdata.ToArray();
  860. return true;
  861. }
  862. catch (Exception ex)
  863. {
  864. LOG.Write(ex);
  865. return false;
  866. }
  867. }
  868. public bool ParseMappingCalibrationResult(string[] pdata)
  869. {
  870. try
  871. {
  872. ReadMappingTransferStation = pdata[0];
  873. ReadMappingCalibrationResult.Clear();
  874. ReadMappingCalibrationResult.Add("LowestLaySlotPosition", Convert.ToInt32(pdata[1]) / 1000);
  875. ReadMappingCalibrationResult.Add("HighestLaySlotPosition", Convert.ToInt32(pdata[2]) / 1000);
  876. ReadMappingCalibrationResult.Add("WaferWidth", Convert.ToInt32(pdata[3]) / 1000);
  877. ReadMappingCalibrationResult.Add("ThreshhholdValueofDoubleInsertion", Convert.ToInt32(pdata[4]) / 1000);
  878. ReadMappingCalibrationResult.Add("ThreshhholdValueofSlantingInsertion1", Convert.ToInt32(pdata[5]) / 1000);
  879. ReadMappingCalibrationResult.Add("ThreshhholdValueofSlantingInsertion2", Convert.ToInt32(pdata[6]) / 1000);
  880. return true;
  881. }
  882. catch (Exception ex)
  883. {
  884. LOG.Write(ex);
  885. return false;
  886. }
  887. }
  888. protected override bool fClear(object[] param)
  889. {
  890. if (!_connection.IsConnected)
  891. {
  892. EV.PostAlarmLog(RobotModuleName.ToString(), $"{RobotModuleName} clear failed for not connect with {_connection.Address}");
  893. return false;
  894. }
  895. lock (_locker)
  896. {
  897. _lstHandlers.Clear();
  898. _connection.ForceClear();
  899. //_lstHandlers.AddLast(new GM201LVPRobotMotionHandler(this, "CCLR", "E"));
  900. string strpara = "1,1,N";
  901. _lstHandlers.AddLast(new GM201LVPRobotMotionHandler(this, "INIT", strpara));
  902. _lstHandlers.AddLast(new GM201LVPRobotReadHandler(this, "RSTS"));
  903. }
  904. return true;
  905. }
  906. protected override bool fStartReadData(object[] param)
  907. {
  908. if (!_connection.IsConnected)
  909. {
  910. EV.PostAlarmLog(RobotModuleName.ToString(), $"{RobotModuleName} read data failed for not connect with {_connection.Address}");
  911. return false;
  912. }
  913. if (param.Length < 1) return false;
  914. string readcommand = param[0].ToString();
  915. switch (readcommand)
  916. {
  917. case "CurrentStatus":
  918. lock (_locker)
  919. {
  920. _lstHandlers.AddLast(new GM201LVPRobotReadHandler(this, "RSTS"));
  921. //_lstHandlers.AddLast(new GM201LVPRobotReadHandler(this, "RPOS", "F"));
  922. //_lstHandlers.AddLast(new GM201LVPRobotReadHandler(this, "RPOS", "R"));
  923. }
  924. break;
  925. case "CurrentRobotParameters":
  926. lock (_locker)
  927. {
  928. var parameters = param[1].ToString().Split(';').ToList();
  929. foreach (var item in parameters)
  930. {
  931. _lstMonitorHandler.AddLast(new GM201LVPRobotReadHandler(this, "RPRM", item));
  932. }
  933. }
  934. break;
  935. case "CurrentRobotPositionConfig":
  936. lock (_locker)
  937. {
  938. var parameters = param[1].ToString().Split(';').ToList();
  939. foreach (var item in parameters)
  940. {
  941. _lstMonitorHandler.AddLast(new GM201LVPRobotReadHandler(this, "RSTR", item));
  942. }
  943. }
  944. break;
  945. case "CurrentRobotPositionAxis":
  946. lock (_locker)
  947. {
  948. var parameters = param[1].ToString().Split(';').ToList();
  949. foreach (var item in parameters)
  950. {
  951. _lstMonitorHandler.AddLast(new GM201LVPRobotReadHandler(this, "RSTP", item));
  952. }
  953. }
  954. break;
  955. default:
  956. break;
  957. }
  958. return true;
  959. }
  960. protected override bool fMonitorReadData(object[] param)
  961. {
  962. IsBusy = false;
  963. return _lstHandlers.Count == 0 && !_connection.IsBusy;
  964. }
  965. private void ExecuteHandler(HandlerBase handler)
  966. {
  967. _connection.Execute(handler);
  968. }
  969. private string Checksum(byte[] bytes)
  970. {
  971. int sum = 0;
  972. foreach (byte code in bytes)
  973. {
  974. sum += code;
  975. }
  976. string hex = String.Format("{0:X2}", sum % 256);
  977. return hex;
  978. }
  979. private Stopwatch _timerActionMonitor = new Stopwatch();
  980. protected override bool fStartSetParameters(object[] param)
  981. {
  982. if (!_connection.IsConnected)
  983. {
  984. EV.PostAlarmLog(RobotModuleName.ToString(), $"{RobotModuleName} set parameter failed for not connect with {_connection.Address}");
  985. return false;
  986. }
  987. try
  988. {
  989. string strParameter;
  990. string setcommand = param[0].ToString();
  991. switch (setcommand)
  992. {
  993. case "SetSpeed": // SSPD Set the motion speed
  994. int speedLevel = Convert.ToInt32(param[1]);
  995. if (speedLevel > 100) speedLevel = 100;
  996. if (speedLevel < 1) speedLevel = 1;
  997. lock (_locker)
  998. {
  999. _lstHandlers.AddLast(new GM201LVPRobotSetHandler(this, "SSLV", $"1,{SpeedLevelSetting.ToString("D3")}"));
  1000. }
  1001. break;
  1002. case "SetParameter": // SPRM
  1003. lock (_locker)
  1004. {
  1005. var data = param[1].ToString().Split(';').ToList();
  1006. foreach (var item in data)
  1007. {
  1008. if (!string.IsNullOrEmpty(item))
  1009. {
  1010. _lstMonitorHandler.AddLast(new GM201LVPRobotSetHandler(this, "SPRM", item));
  1011. }
  1012. }
  1013. }
  1014. break;
  1015. case "SetPositionConfig": //SSTR,C01,000,00000000025
  1016. lock (_locker)
  1017. {
  1018. var data = param[1].ToString().Split(';').ToList();
  1019. foreach (var item in data)
  1020. {
  1021. if (!string.IsNullOrEmpty(item))
  1022. {
  1023. _lstMonitorHandler.AddLast(new GM201LVPRobotSetHandler(this, "SSTR", item));
  1024. }
  1025. }
  1026. }
  1027. break;
  1028. case "SetPositionAxis": //SABS,C01,00000100000,00000090000,00000000000,00000450000,00000010000
  1029. lock (_locker)
  1030. {
  1031. var data = param[1].ToString().Split(';').ToList();
  1032. foreach (var item in data)
  1033. {
  1034. if (!string.IsNullOrEmpty(item))
  1035. {
  1036. _lstMonitorHandler.AddLast(new GM201LVPRobotSetHandler(this, "SABS", item));
  1037. }
  1038. }
  1039. }
  1040. break;
  1041. case "EnableInterLock": //SMSK
  1042. int smskValid = Convert.ToInt16(param[1].ToString());
  1043. lock (_locker)
  1044. {
  1045. _lstHandlers.AddLast(new GM201LVPRobotSetHandler(this, "SPRM", smskValid.ToString("D4")));
  1046. }
  1047. break;
  1048. }
  1049. _timerActionMonitor.Restart();
  1050. }
  1051. catch (Exception)
  1052. {
  1053. string reason = "";
  1054. if (param != null)
  1055. {
  1056. foreach (var para in param)
  1057. {
  1058. reason += para.ToString() + ",";
  1059. }
  1060. }
  1061. EV.PostAlarmLog(Name, "Set command parameter invalid:" + reason);
  1062. return false;
  1063. }
  1064. return true;
  1065. }
  1066. protected override bool fMonitorSetParamter(object[] param)
  1067. {
  1068. IsBusy = false;
  1069. if (_timerActionMonitor.IsRunning && _timerActionMonitor.Elapsed > TimeSpan.FromSeconds(_timeLimitMotion))
  1070. {
  1071. _timerActionMonitor.Stop();
  1072. OnError("SetParameterTimeOut");
  1073. return true;
  1074. }
  1075. if (_lstHandlers.Count == 0 && !_connection.IsBusy)
  1076. {
  1077. //EV.PostInfoLog(Name, "SetParameter complete");
  1078. return true;
  1079. }
  1080. return false;
  1081. }
  1082. protected override bool fStartTransferWafer(object[] param)
  1083. {
  1084. return false;
  1085. }
  1086. protected override bool fStartUnGrip(object[] param)
  1087. {
  1088. if (!_connection.IsConnected)
  1089. {
  1090. EV.PostAlarmLog(RobotModuleName.ToString(), $"{RobotModuleName} ungrip failed for not connect with {_connection.Address}");
  1091. return false;
  1092. }
  1093. lock (_locker)
  1094. {
  1095. RobotArmEnum arm = (RobotArmEnum)param[0];
  1096. string strpara = (arm == RobotArmEnum.Both ? "F" : ((int)arm + 1).ToString()) + ",0,0";
  1097. _lstHandlers.AddLast(new GM201LVPRobotMotionHandler(this, "CSOL", strpara));
  1098. }
  1099. _timerActionMonitor.Restart();
  1100. return true;
  1101. }
  1102. protected override bool fMonitorUnGrip(object[] param)
  1103. {
  1104. IsBusy = false;
  1105. if (_timerActionMonitor.IsRunning && _timerActionMonitor.Elapsed > TimeSpan.FromSeconds(_timeLimitMotion))
  1106. {
  1107. _timerActionMonitor.Stop();
  1108. OnError("UngripTimeOut");
  1109. return true;
  1110. }
  1111. if (_lstHandlers.Count == 0 && !_connection.IsBusy)
  1112. {
  1113. //EV.PostInfoLog(Name, "Ungrip complete");
  1114. return true;
  1115. }
  1116. return false;
  1117. }
  1118. protected override bool fStartGrip(object[] param)
  1119. {
  1120. if (!_connection.IsConnected)
  1121. {
  1122. EV.PostAlarmLog(RobotModuleName.ToString(), $"{RobotModuleName} grip failed for not connect with {_connection.Address}");
  1123. return false;
  1124. }
  1125. lock (_locker)
  1126. {
  1127. RobotArmEnum arm = (RobotArmEnum)param[0];
  1128. string strpara = (arm == RobotArmEnum.Both ? "F" : ((int)arm + 1).ToString()) + ",1,0";
  1129. _lstHandlers.AddLast(new GM201LVPRobotMotionHandler(this, "CSOL", strpara));
  1130. }
  1131. return true;
  1132. }
  1133. protected override bool fMonitorGrip(object[] param)
  1134. {
  1135. IsBusy = false;
  1136. if (_timerActionMonitor.IsRunning && _timerActionMonitor.Elapsed > TimeSpan.FromSeconds(_timeLimitMotion))
  1137. {
  1138. _timerActionMonitor.Stop();
  1139. OnError("GripTimeOut");
  1140. return true;
  1141. }
  1142. if (_lstHandlers.Count == 0 && !_connection.IsBusy)
  1143. {
  1144. //EV.PostInfoLog(Name, "Grip complete");
  1145. return true;
  1146. }
  1147. return false;
  1148. }
  1149. protected override bool fStartInit(object[] param)
  1150. {
  1151. if (!_connection.IsConnected)
  1152. {
  1153. EV.PostAlarmLog(RobotModuleName.ToString(), $"{RobotModuleName} init failed for not connect with {_connection.Address}");
  1154. return false;
  1155. }
  1156. lock (_locker)
  1157. {
  1158. if (_doRobotHold != null)
  1159. {
  1160. _doRobotHold.SetTrigger(true, out _);
  1161. Thread.Sleep(100);
  1162. }
  1163. //ExecuteHandler(new GM201LVPRobotReadHandler(this, "RERR", "001"));
  1164. if (_isError)
  1165. {
  1166. string strparaReset = "1,1,N";
  1167. _lstHandlers.AddLast(new GM201LVPRobotMotionHandler(this, "INIT", strparaReset));
  1168. _isError = false;
  1169. }
  1170. string strpara = "1,1,G";
  1171. _lstHandlers.AddLast(new GM201LVPRobotMotionHandler(this, "INIT", strpara));
  1172. if (SpeedLevelSetting >= 1 && SpeedLevelSetting <= 100)
  1173. _lstHandlers.AddLast(new GM201LVPRobotSetHandler(this, "SSLV", $"1,{SpeedLevelSetting.ToString("D3")}"));
  1174. _lstHandlers.AddLast(new GM201LVPRobotReadHandler(this, "RSTS"));
  1175. }
  1176. _timerActionMonitor.Restart();
  1177. return true;
  1178. }
  1179. protected override bool fMonitorInit(object[] param)
  1180. {
  1181. IsBusy = false;
  1182. if (_timerActionMonitor.IsRunning && _timerActionMonitor.Elapsed > TimeSpan.FromSeconds(_timeLimitHome))
  1183. {
  1184. _timerActionMonitor.Stop();
  1185. OnError("InitTimeOut");
  1186. return true;
  1187. }
  1188. if (_lstHandlers.Count == 0 && !_connection.IsBusy)
  1189. {
  1190. BladeTarget = ModuleName.System;
  1191. Blade1Target = ModuleName.System;
  1192. Blade2Target = ModuleName.System;
  1193. CmdTarget = ModuleName.System;
  1194. MoveInfo = new RobotMoveInfo()
  1195. {
  1196. Action = RobotAction.Moving,
  1197. ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
  1198. BladeTarget = BuildBladeTarget(),
  1199. };
  1200. //EV.PostInfoLog(Name, "Init complete");
  1201. return true;
  1202. }
  1203. return false;
  1204. }
  1205. protected override bool fStartHome(object[] param)
  1206. {
  1207. if (!_connection.IsConnected)
  1208. {
  1209. EV.PostAlarmLog(RobotModuleName.ToString(), $"{RobotModuleName} init failed for not connect with {_connection.Address}");
  1210. return false;
  1211. }
  1212. lock (_locker)
  1213. {
  1214. if (_doRobotHold != null)
  1215. {
  1216. _doRobotHold.SetTrigger(true, out _);
  1217. Thread.Sleep(100);
  1218. }
  1219. //ExecuteHandler(new GM201LVPRobotReadHandler(this, "RERR", "001"));
  1220. if (_isError)
  1221. {
  1222. string strparaReset = "1,1,N";
  1223. _lstHandlers.AddLast(new GM201LVPRobotMotionHandler(this, "INIT", strparaReset));
  1224. _isError = false;
  1225. }
  1226. string strpara = "1,1,G";
  1227. _lstHandlers.AddLast(new GM201LVPRobotMotionHandler(this, "INIT", strpara, _timeLimitHome));
  1228. if (SpeedLevelSetting >= 1 && SpeedLevelSetting <= 100)
  1229. _lstHandlers.AddLast(new GM201LVPRobotSetHandler(this, "SSLV", $"1,{SpeedLevelSetting.ToString("D3")}"));
  1230. _lstHandlers.AddLast(new GM201LVPRobotReadHandler(this, "RSTS"));
  1231. }
  1232. _timerActionMonitor.Restart();
  1233. return true;
  1234. }
  1235. protected override bool fMonitorHome(object[] param)
  1236. {
  1237. IsBusy = false;
  1238. if (_timerActionMonitor.IsRunning && _timerActionMonitor.Elapsed > TimeSpan.FromSeconds(_timeLimitHome))
  1239. {
  1240. _timerActionMonitor.Stop();
  1241. OnError("HomeTimeOut");
  1242. return true;
  1243. }
  1244. if (_lstHandlers.Count == 0 && !_connection.IsBusy)
  1245. {
  1246. BladeTarget = ModuleName.System;
  1247. Blade1Target = ModuleName.System;
  1248. Blade2Target = ModuleName.System;
  1249. CmdTarget = ModuleName.System;
  1250. MoveInfo = new RobotMoveInfo()
  1251. {
  1252. Action = RobotAction.Moving,
  1253. ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
  1254. BladeTarget = BuildBladeTarget(),
  1255. };
  1256. //EV.PostInfoLog(Name, "Home complete");
  1257. return true;
  1258. }
  1259. return false;
  1260. }
  1261. protected override bool fStartGoTo(object[] param)
  1262. {
  1263. if (!_connection.IsConnected)
  1264. {
  1265. EV.PostAlarmLog(RobotModuleName.ToString(), $"{RobotModuleName} move failed for not connect with {_connection.Address}");
  1266. return false;
  1267. }
  1268. try
  1269. {
  1270. RobotArmEnum arm = (RobotArmEnum)param[0];
  1271. ModuleName module = (ModuleName)Enum.Parse(typeof(ModuleName), param[1].ToString());
  1272. BladeTarget = module;
  1273. Blade1Target = module;
  1274. Blade2Target = module;
  1275. int slot = (int)param[2] + 1;
  1276. //RobotPostionEnum postype = (RobotPostionEnum)param[3];
  1277. RobotPostionEnum postype = (RobotPostionEnum)Enum.Parse(typeof(RobotPostionEnum), param[3].ToString());
  1278. string strpara = string.Empty;
  1279. //bool isFromOriginal = (bool)param[8];
  1280. //bool isJumpToNextMotion = (bool)param[9];
  1281. //if ((int)postype >= 0 && (int)postype < 10)
  1282. //{
  1283. // strpara = "G";
  1284. //}
  1285. //if ((int)postype >= 10 && (int)postype < 20)
  1286. //{
  1287. // strpara = "P";
  1288. //}
  1289. //if ((int)postype >= 20 && (int)postype < 30)
  1290. //{
  1291. // strpara = "E";
  1292. //}
  1293. string trsSt = GetStationsName(module);
  1294. if (string.IsNullOrEmpty(trsSt))
  1295. {
  1296. LOG.Write("invalid transfer paramter");
  1297. return false;
  1298. }
  1299. string TrsPnt = string.Empty;
  1300. if (postype == RobotPostionEnum.PickReady)
  1301. {
  1302. TrsPnt = "G";
  1303. }
  1304. if (postype == RobotPostionEnum.PlaceReady)
  1305. {
  1306. TrsPnt = "P";
  1307. }
  1308. //strCmd = "MTCH";
  1309. if (_MaterialType == MaterialType.Wafer)
  1310. {
  1311. int bladeNo = (arm == RobotArmEnum.Blade1 || arm == RobotArmEnum.Lower) ? 4 : 31;
  1312. strpara += $"{TrsPnt},{trsSt},{slot:D3},{bladeNo:D3}";
  1313. }
  1314. else if (_MaterialType == MaterialType.Carrier)
  1315. {
  1316. //strpara = $"{TrsPnt},{trsSt},001,000";
  1317. string strHand = GetHandsName(module);
  1318. if (string.IsNullOrEmpty(strHand))
  1319. {
  1320. LOG.Write("Invalid Paramter.");
  1321. return false;
  1322. }
  1323. strpara = $"{TrsPnt},{trsSt},001,{strHand},001";
  1324. }
  1325. lock (_locker)
  1326. {
  1327. {
  1328. _lstHandlers.AddLast(new GM201LVPRobotMotionHandler(this, "MTCH", strpara));
  1329. _lstHandlers.AddLast(new GM201LVPRobotReadHandler(this, "RSTS"));
  1330. }
  1331. }
  1332. _timerActionMonitor.Restart();
  1333. return true;
  1334. }
  1335. catch (Exception ex)
  1336. {
  1337. LOG.Write(ex);
  1338. return false;
  1339. }
  1340. }
  1341. protected override bool fMonitorGoTo(object[] param)
  1342. {
  1343. if (_timerActionMonitor.IsRunning && _timerActionMonitor.Elapsed > TimeSpan.FromSeconds(_timeLimitMotion))
  1344. {
  1345. _timerActionMonitor.Stop();
  1346. OnError("GotoTimeOut");
  1347. return true;
  1348. }
  1349. if (_lstHandlers.Count != 0 || _connection.IsBusy) return false;
  1350. IsBusy = false;
  1351. return true;
  1352. }
  1353. protected override bool fGoToComplete(object[] param)
  1354. {
  1355. try
  1356. {
  1357. if (_lstHandlers.Count > 0) return false;
  1358. RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
  1359. ModuleName sourcemodule = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[1].ToString());
  1360. int SourceslotIndex = (int)CurrentParamter[2];
  1361. RobotPostionEnum postype = (RobotPostionEnum)CurrentParamter[3];
  1362. //bool isFromOriginal = (bool)CurrentParamter[8];
  1363. //bool isJumpToNextMotion = (bool)CurrentParamter[9];
  1364. }
  1365. catch (Exception ex)
  1366. {
  1367. LOG.Write(ex);
  1368. }
  1369. return base.fGoToComplete(param);
  1370. }
  1371. protected override bool fStop(object[] param)
  1372. {
  1373. lock (_locker)
  1374. {
  1375. if (_doRobotHold != null)
  1376. _doRobotHold.SetTrigger(false, out _);
  1377. _lstHandlers.Clear();
  1378. _connection.ForceClear();
  1379. //ExecuteHandler(new GM201LVPRobotMotionHandler(this, "CSTP", "E"));
  1380. }
  1381. return true; ;
  1382. }
  1383. protected override bool fMonitorStop(object[] param)
  1384. {
  1385. return true;
  1386. }
  1387. protected override bool fStartMove(object[] param)
  1388. {
  1389. if (!_connection.IsConnected)
  1390. {
  1391. EV.PostAlarmLog(RobotModuleName.ToString(), $"{RobotModuleName} move failed for not connect with {_connection.Address}");
  1392. return false;
  1393. }
  1394. try
  1395. {
  1396. string strCmd = param[0].ToString();
  1397. string strpara = string.Empty;
  1398. for (int i = 1; i < param.Length; i++)
  1399. {
  1400. if (i == 1)
  1401. strpara += param[i].ToString();
  1402. else
  1403. strpara += "," + param[i].ToString();
  1404. }
  1405. lock (_locker)
  1406. {
  1407. _lstHandlers.AddLast(new GM201LVPRobotMotionHandler(this, strCmd, strpara));
  1408. _lstHandlers.AddLast(new GM201LVPRobotReadHandler(this, "RPOS", "F"));
  1409. }
  1410. _timerActionMonitor.Restart();
  1411. return true;
  1412. }
  1413. catch (Exception ex)
  1414. {
  1415. LOG.Write(ex);
  1416. return false;
  1417. }
  1418. }
  1419. private string GetStationsName(ModuleName chamber)
  1420. {
  1421. if (!_moduleAssociateStationDic.ContainsKey(chamber.ToString()))
  1422. {
  1423. LOG.Error($"not define teach position {chamber}");
  1424. return "";
  1425. }
  1426. var moduleIndex = _moduleAssociateStationDic[chamber.ToString()];
  1427. return moduleIndex.ToString();
  1428. }
  1429. private string GetHandsName(ModuleName chamber)
  1430. {
  1431. if (!_moduleAssociateHandDic.ContainsKey(chamber.ToString()))
  1432. {
  1433. LOG.Error($"not define teach position {chamber}");
  1434. return "";
  1435. }
  1436. var moduleIndex = _moduleAssociateHandDic[chamber.ToString()];
  1437. return moduleIndex.ToString();
  1438. }
  1439. private int GetSlotsNumber(ModuleName module)
  1440. {
  1441. try
  1442. {
  1443. if (ModuleHelper.IsLoadPort(module))
  1444. {
  1445. return DEVICE.GetDevice<LoadPortBaseDevice>(module.ToString()).ValidSlotsNumber;
  1446. }
  1447. return SC.GetValue<int>($"CarrierInfo.{module}SlotsNumber");
  1448. }
  1449. catch (Exception ex)
  1450. {
  1451. LOG.Write(ex);
  1452. return -1;
  1453. }
  1454. }
  1455. private bool _isNeedMappignData
  1456. {
  1457. get
  1458. {
  1459. if (SC.ContainsItem($"Robot.{RobotModuleName}.NeedReadMapData"))
  1460. return SC.GetValue<bool>($"Robot.{RobotModuleName}.NeedReadMapData");
  1461. return true;
  1462. }
  1463. }
  1464. protected override bool fStartMapWafer(object[] param)
  1465. {
  1466. if (!_connection.IsConnected)
  1467. {
  1468. EV.PostAlarmLog(RobotModuleName.ToString(), $"{RobotModuleName} map failed for not connect with {_connection.Address}");
  1469. return false;
  1470. }
  1471. try
  1472. {
  1473. ReadSlotMap = "";
  1474. //RobotArmEnum pickarm = (RobotArmEnum)param[0];
  1475. ModuleName module = (ModuleName)Enum.Parse(typeof(ModuleName), param[0].ToString());
  1476. BladeTarget = module;
  1477. Blade1Target = module;
  1478. Blade2Target = module;
  1479. //int slotsNumber = GetSlotsNumber(module);
  1480. //if (slotsNumber == -1)
  1481. //{
  1482. // LOG.Write("Invalid mapping paramter slots number");
  1483. // return false;
  1484. //}
  1485. string TrsSt = GetStationsName(module);
  1486. if (string.IsNullOrEmpty(TrsSt))
  1487. {
  1488. LOG.Write("Invalid Paramter.");
  1489. return false;
  1490. }
  1491. string strpara = $"{TrsSt},1";
  1492. lock (_locker)
  1493. {
  1494. CurrentInteractiveModule = module;
  1495. _lstHandlers.AddLast(new GM201LVPRobotMotionHandler(this, "MMAP", strpara, _timeLimitMotion));
  1496. //if (_isNeedMappignData)
  1497. // _lstHandlers.AddLast(new GM201LVPRobotReadHandler(this, "RMPD", $"{GetStationsName(module)},025"));
  1498. _lstHandlers.AddLast(new GM201LVPRobotReadHandler(this, "RMAP", $"{GetStationsName(module)}"));
  1499. }
  1500. _timerActionMonitor.Restart();
  1501. return true;
  1502. }
  1503. catch (Exception ex)
  1504. {
  1505. LOG.Write(ex);
  1506. return false;
  1507. }
  1508. }
  1509. protected override bool fMonitorMap(object[] param)
  1510. {
  1511. if (_timerActionMonitor.IsRunning && _timerActionMonitor.Elapsed > TimeSpan.FromSeconds(_timeLimitMotion))
  1512. {
  1513. _timerActionMonitor.Stop();
  1514. OnError("PlaceTimeOut");
  1515. return true;
  1516. }
  1517. if (_lstHandlers.Count != 0 || _connection.IsBusy) return false;
  1518. IsBusy = false;
  1519. BladeTarget = ModuleName.System;
  1520. Blade1Target = ModuleName.System;
  1521. Blade2Target = ModuleName.System;
  1522. CmdTarget = ModuleName.System;
  1523. MoveInfo = new RobotMoveInfo()
  1524. {
  1525. Action = RobotAction.Moving,
  1526. ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
  1527. BladeTarget = BuildBladeTarget(),
  1528. };
  1529. return true;
  1530. }
  1531. protected override bool fStartSwapWafer(object[] param)
  1532. {
  1533. if (!_connection.IsConnected)
  1534. {
  1535. EV.PostAlarmLog(RobotModuleName.ToString(), $"{RobotModuleName} move failed for not connect with {_connection.Address}");
  1536. return false;
  1537. }
  1538. try
  1539. {
  1540. RobotArmEnum arm = (RobotArmEnum)param[0];
  1541. ModuleName module = (ModuleName)Enum.Parse(typeof(ModuleName), param[1].ToString());
  1542. BladeTarget = module;
  1543. Blade1Target = module;
  1544. Blade2Target = module;
  1545. if (ModuleHelper.IsLoadPort(module))
  1546. {
  1547. var lp = DEVICE.GetDevice<LoadPortBaseDevice>(module.ToString());
  1548. if (lp != null)
  1549. lp.NoteTransferStart();
  1550. }
  1551. int slot = (int)param[2] + 1;
  1552. float x = 0, y = 0, z = 0, w = 0;
  1553. if (param.Length > 3)
  1554. {
  1555. x = (float)param[3];
  1556. y = (float)param[4];
  1557. z = (float)param[5];
  1558. w = (float)param[6];
  1559. }
  1560. int intXvalue = (int)(x * 1000);
  1561. int intYvalue = (int)(y * 1000);
  1562. int intZvalue = (int)(z * 1000);
  1563. int intWvalue = (int)(w * 1000);
  1564. string TrsSt = GetStationsName(module);
  1565. if (string.IsNullOrEmpty(TrsSt))
  1566. {
  1567. LOG.Write("Invalid Paramter.");
  1568. return false;
  1569. }
  1570. string strpara = $"E,{TrsSt},{slot:D2},A,{(arm == RobotArmEnum.Both ? "F" : ((int)arm + 1).ToString())},P4";
  1571. if (x != 0 || y != 0 || z != 0)
  1572. {
  1573. strpara += $",{intXvalue:D8},{intYvalue:D8},{intZvalue:D8}";
  1574. }
  1575. if (w != 0)
  1576. {
  1577. strpara += $",{intWvalue:D8}";
  1578. }
  1579. lock (_locker)
  1580. {
  1581. if (_lstHandlers.Count == 0 && !_connection.IsBusy)
  1582. {
  1583. ExecuteHandler(new GM201LVPRobotMotionHandler(this, "MTRS", strpara, _timeLimitMotion));
  1584. }
  1585. else
  1586. {
  1587. _lstHandlers.AddLast(new GM201LVPRobotMotionHandler(this, "MTRS", strpara));
  1588. }
  1589. }
  1590. return true;
  1591. }
  1592. catch (Exception ex)
  1593. {
  1594. LOG.Write(ex);
  1595. return false;
  1596. }
  1597. }
  1598. protected override bool fSwapComplete(object[] param)
  1599. {
  1600. RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
  1601. ModuleName sourcemodule;
  1602. if (!Enum.TryParse(CurrentParamter[1].ToString(), out sourcemodule)) return false;
  1603. int Sourceslotindex;
  1604. if (!int.TryParse(CurrentParamter[2].ToString(), out Sourceslotindex)) return false;
  1605. int delayCount = 0;
  1606. if (arm == RobotArmEnum.Lower)
  1607. {
  1608. //WaferManager.Instance.WaferMoved(sourcemodule, Sourceslotindex, RobotModuleName, 0);
  1609. //WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, Sourceslotindex);
  1610. while (!isSimulatorMode && !(GetWaferState(RobotArmEnum.Lower) == RobotArmWaferStateEnum.Present
  1611. && GetWaferState(RobotArmEnum.Upper) == RobotArmWaferStateEnum.Absent))
  1612. {
  1613. delayCount++;
  1614. Thread.Sleep(50);
  1615. LOG.Write($"{RobotModuleName} delay {delayCount} time to detect wafer");
  1616. if (delayCount > 100)
  1617. {
  1618. OnError("Wafer detect error");
  1619. return true;
  1620. }
  1621. }
  1622. WaferManager.Instance.WaferMoved(sourcemodule, Sourceslotindex, RobotModuleName, 0);
  1623. WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, Sourceslotindex);
  1624. }
  1625. if (arm == RobotArmEnum.Upper)
  1626. {
  1627. //WaferManager.Instance.WaferMoved(sourcemodule, Sourceslotindex, RobotModuleName, 1);
  1628. //WaferManager.Instance.WaferMoved(RobotModuleName, 0, sourcemodule, Sourceslotindex);
  1629. delayCount = 0;
  1630. while (!isSimulatorMode && !(GetWaferState(RobotArmEnum.Upper) == RobotArmWaferStateEnum.Present &&
  1631. GetWaferState(RobotArmEnum.Lower) == RobotArmWaferStateEnum.Absent))
  1632. {
  1633. delayCount++;
  1634. Thread.Sleep(50);
  1635. LOG.Write($"{RobotModuleName} delay {delayCount} time to detect wafer");
  1636. if (delayCount > 100)
  1637. {
  1638. OnError("Wafer detect error");
  1639. return true;
  1640. }
  1641. }
  1642. WaferManager.Instance.WaferMoved(sourcemodule, Sourceslotindex, RobotModuleName, 1);
  1643. WaferManager.Instance.WaferMoved(RobotModuleName, 0, sourcemodule, Sourceslotindex);
  1644. }
  1645. return base.fSwapComplete(param);
  1646. }
  1647. protected override bool fStartPlaceWafer(object[] param)
  1648. {
  1649. if (!_connection.IsConnected)
  1650. {
  1651. EV.PostAlarmLog(RobotModuleName.ToString(), $"{RobotModuleName} place failed for not connect with {_connection.Address}");
  1652. return false;
  1653. }
  1654. try
  1655. {
  1656. RobotArmEnum arm = (RobotArmEnum)param[0];
  1657. ModuleName module = (ModuleName)Enum.Parse(typeof(ModuleName), param[1].ToString());
  1658. if (ModuleHelper.IsLoadPort(module))
  1659. {
  1660. var lp = DEVICE.GetDevice<LoadPortBaseDevice>(module.ToString());
  1661. if (lp != null)
  1662. lp.NoteTransferStart();
  1663. }
  1664. BladeTarget = module;
  1665. Blade1Target = module;
  1666. Blade2Target = module;
  1667. int slot = (int)param[2] + 1;
  1668. string TrsSt = GetStationsName(module);
  1669. if (string.IsNullOrEmpty(TrsSt))
  1670. {
  1671. LOG.Write("Invalid Parameter.");
  1672. return false;
  1673. }
  1674. string strpara = "";
  1675. if (_MaterialType == MaterialType.Wafer)
  1676. {
  1677. int bladeNo = (arm == RobotArmEnum.Blade1 || arm == RobotArmEnum.Lower) ? 4 : 31;
  1678. strpara = $"P,{TrsSt},{slot:D3},{bladeNo:D3}";
  1679. }
  1680. else if (_MaterialType == MaterialType.Carrier)
  1681. {
  1682. string strHand = GetHandsName(module);
  1683. if (string.IsNullOrEmpty(strHand))
  1684. {
  1685. LOG.Write("Invalid Paramter.");
  1686. return false;
  1687. }
  1688. strpara = $"P,{TrsSt},001,{strHand}";
  1689. }
  1690. lock (_locker)
  1691. {
  1692. {
  1693. _lstHandlers.AddLast(new GM201LVPRobotMotionHandler(this, "MTRS", strpara, _timeLimitPlace));
  1694. _lstHandlers.AddLast(new GM201LVPRobotReadHandler(this, "RSTS"));
  1695. }
  1696. }
  1697. CmdTarget = module;
  1698. MoveInfo = new RobotMoveInfo()
  1699. {
  1700. Action = RobotAction.Moving,
  1701. ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
  1702. BladeTarget = BuildBladeTarget(),
  1703. };
  1704. _timerActionMonitor.Restart();
  1705. return true;
  1706. }
  1707. catch (Exception ex)
  1708. {
  1709. LOG.Write(ex);
  1710. return false;
  1711. }
  1712. }
  1713. protected override bool fMonitorPlace(object[] param)
  1714. {
  1715. IsBusy = false;
  1716. if (_timerActionMonitor.IsRunning && _timerActionMonitor.Elapsed > TimeSpan.FromSeconds(_timeLimitPlace))
  1717. {
  1718. _timerActionMonitor.Stop();
  1719. OnError("PlaceTimeOut");
  1720. return true;
  1721. }
  1722. if (_lstHandlers.Count == 0 && !_connection.IsBusy)
  1723. {
  1724. _timerActionMonitor.Stop();
  1725. //EV.PostInfoLog(Name, "Place complete");
  1726. fPlaceComplete(param);
  1727. BladeTarget = ModuleName.System;
  1728. Blade1Target = ModuleName.System;
  1729. Blade2Target = ModuleName.System;
  1730. CmdTarget = ModuleName.System;
  1731. MoveInfo = new RobotMoveInfo()
  1732. {
  1733. Action = RobotAction.Moving,
  1734. ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
  1735. BladeTarget = BuildBladeTarget(),
  1736. };
  1737. return true;
  1738. }
  1739. return false;
  1740. }
  1741. protected override bool fPlaceComplete(object[] param)
  1742. {
  1743. if (_isError)
  1744. {
  1745. OnError("RobotError");
  1746. return true;
  1747. }
  1748. if (_lstHandlers.Count > 0) return false;
  1749. RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
  1750. ModuleName sourcemodule;
  1751. if (!Enum.TryParse(CurrentParamter[1].ToString(), out sourcemodule)) return false;
  1752. int Sourceslotindex;
  1753. if (!int.TryParse(CurrentParamter[2].ToString(), out Sourceslotindex)) return false;
  1754. int delayCount = 0;
  1755. if (arm == RobotArmEnum.Lower || arm == RobotArmEnum.Blade1)
  1756. {
  1757. //WaferManager.Instance.WaferMoved(RobotModuleName, 0, sourcemodule, Sourceslotindex);
  1758. while (!isSimulatorMode && GetWaferState(arm) != RobotArmWaferStateEnum.Absent)
  1759. {
  1760. delayCount++;
  1761. Thread.Sleep(50);
  1762. LOG.Write($"{RobotModuleName} delay {delayCount} time to detect wafer");
  1763. if (delayCount > 100)
  1764. {
  1765. OnError("Wafer detect error");
  1766. return true;
  1767. }
  1768. }
  1769. if (_MaterialType == MaterialType.Wafer)
  1770. {
  1771. WaferManager.Instance.WaferMoved(RobotModuleName, 2, sourcemodule, Sourceslotindex);
  1772. }
  1773. else if (_MaterialType == MaterialType.Carrier)
  1774. {
  1775. if (CarrierManager.Instance.CheckHasCarrier(RobotModuleName.ToString(), 0))
  1776. {
  1777. CarrierManager.Instance.CarrierMoved(RobotModuleName.ToString(), sourcemodule.ToString(), true);
  1778. for (int i = 0; i < WaferManager.Instance.GetWafers(RobotModuleName).Length; i++)
  1779. {
  1780. if (WaferManager.Instance.CheckHasWafer(RobotModuleName, i))
  1781. WaferManager.Instance.WaferMoved(RobotModuleName, i, sourcemodule, i, false);
  1782. }
  1783. }
  1784. }
  1785. }
  1786. if (arm == RobotArmEnum.Upper || arm == RobotArmEnum.Blade2)
  1787. {
  1788. //WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, Sourceslotindex);
  1789. delayCount = 0;
  1790. while (!isSimulatorMode && GetWaferState(arm) != RobotArmWaferStateEnum.Absent)
  1791. {
  1792. delayCount++;
  1793. Thread.Sleep(50);
  1794. LOG.Write($"{RobotModuleName} delay {delayCount} time to detect wafer");
  1795. if (delayCount > 100)
  1796. {
  1797. OnError("Wafer detect error");
  1798. return true;
  1799. }
  1800. }
  1801. WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, Sourceslotindex);
  1802. }
  1803. if (arm == RobotArmEnum.Both)
  1804. {
  1805. //WaferManager.Instance.WaferMoved(RobotModuleName, 0, sourcemodule, Sourceslotindex);
  1806. //WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, Sourceslotindex);
  1807. while (!isSimulatorMode && GetWaferState(arm) != RobotArmWaferStateEnum.Absent)
  1808. {
  1809. delayCount++;
  1810. Thread.Sleep(50);
  1811. LOG.Write($"{RobotModuleName} delay {delayCount} time to detect wafer");
  1812. if (delayCount > 100)
  1813. {
  1814. OnError("Wafer detect error");
  1815. return true;
  1816. }
  1817. }
  1818. WaferManager.Instance.WaferMoved(RobotModuleName, 0, sourcemodule, Sourceslotindex);
  1819. WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, Sourceslotindex + 1);
  1820. WaferManager.Instance.WaferMoved(RobotModuleName, 2, sourcemodule, Sourceslotindex + 2);
  1821. WaferManager.Instance.WaferMoved(RobotModuleName, 3, sourcemodule, Sourceslotindex + 3);
  1822. WaferManager.Instance.WaferMoved(RobotModuleName, 4, sourcemodule, Sourceslotindex + 4);
  1823. }
  1824. return base.fPlaceComplete(param);
  1825. }
  1826. protected override bool fStartPickWafer(object[] param)
  1827. {
  1828. if (!_connection.IsConnected)
  1829. {
  1830. EV.PostAlarmLog(RobotModuleName.ToString(), $"{RobotModuleName} move failed for not connect with {_connection.Address}");
  1831. return false;
  1832. }
  1833. try
  1834. {
  1835. RobotArmEnum arm = (RobotArmEnum)param[0];
  1836. ModuleName module = (ModuleName)Enum.Parse(typeof(ModuleName), param[1].ToString());
  1837. if (ModuleHelper.IsLoadPort(module))
  1838. {
  1839. var lp = DEVICE.GetDevice<LoadPortBaseDevice>(module.ToString());
  1840. if (lp != null)
  1841. lp.NoteTransferStart();
  1842. }
  1843. BladeTarget = module;
  1844. Blade1Target = module;
  1845. Blade2Target = module;
  1846. int slot = (int)param[2] + 1;
  1847. string TrsSt = GetStationsName(module);
  1848. if (string.IsNullOrEmpty(TrsSt))
  1849. {
  1850. LOG.Write("Invalid Paramter.");
  1851. return false;
  1852. }
  1853. string strpara = "";
  1854. if (_MaterialType == MaterialType.Wafer)
  1855. {
  1856. int bladeNo = (arm == RobotArmEnum.Blade1 || arm == RobotArmEnum.Lower) ? 4 : 31;
  1857. strpara = $"G,{TrsSt},{slot:D3},{bladeNo:D3}";
  1858. }
  1859. else if (_MaterialType == MaterialType.Carrier)
  1860. {
  1861. string strHand = GetHandsName(module);
  1862. if (string.IsNullOrEmpty(strHand))
  1863. {
  1864. LOG.Write("Invalid Paramter.");
  1865. return false;
  1866. }
  1867. strpara = $"G,{TrsSt},001,{strHand}";
  1868. }
  1869. lock (_locker)
  1870. {
  1871. _lstHandlers.AddLast(new GM201LVPRobotMotionHandler(this, "MTRS", strpara, _timeLimitPick));
  1872. _lstHandlers.AddLast(new GM201LVPRobotReadHandler(this, "RSTS"));
  1873. }
  1874. CmdTarget = module;
  1875. MoveInfo = new RobotMoveInfo()
  1876. {
  1877. Action = RobotAction.Moving,
  1878. ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
  1879. BladeTarget = BuildBladeTarget(),
  1880. };
  1881. _timerActionMonitor.Restart();
  1882. return true;
  1883. }
  1884. catch (Exception ex)
  1885. {
  1886. LOG.Write(ex);
  1887. return false;
  1888. }
  1889. }
  1890. protected override bool fMonitorPick(object[] param)
  1891. {
  1892. IsBusy = false;
  1893. if (_timerActionMonitor.IsRunning && _timerActionMonitor.Elapsed > TimeSpan.FromSeconds(_timeLimitPick))
  1894. {
  1895. _timerActionMonitor.Stop();
  1896. OnError("PickTimeOut");
  1897. return true;
  1898. }
  1899. if (_lstHandlers.Count == 0 && !_connection.IsBusy)
  1900. {
  1901. _timerActionMonitor.Stop();
  1902. //EV.PostInfoLog(Name, "Pick complete");
  1903. fPickComplete(param);
  1904. BladeTarget = ModuleName.System;
  1905. Blade1Target = ModuleName.System;
  1906. Blade2Target = ModuleName.System;
  1907. CmdTarget = ModuleName.System;
  1908. MoveInfo = new RobotMoveInfo()
  1909. {
  1910. Action = RobotAction.Moving,
  1911. ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
  1912. BladeTarget = BuildBladeTarget(),
  1913. };
  1914. return true;
  1915. }
  1916. return false;
  1917. }
  1918. protected override bool fPickComplete(object[] param)
  1919. {
  1920. if(_isError)
  1921. {
  1922. OnError("RobotError");
  1923. return true;
  1924. }
  1925. RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
  1926. ModuleName module = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[1].ToString());
  1927. ModuleName sourcemodule;
  1928. if (!Enum.TryParse(CurrentParamter[1].ToString(), out sourcemodule)) return false;
  1929. int SourceslotIndex;
  1930. if (!int.TryParse(CurrentParamter[2].ToString(), out SourceslotIndex)) return false;
  1931. int delayCount = 0;
  1932. if (arm == RobotArmEnum.Lower || arm == RobotArmEnum.Blade1)
  1933. {
  1934. //WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 0);
  1935. while (!isSimulatorMode && GetWaferState(arm) != RobotArmWaferStateEnum.Present)
  1936. {
  1937. delayCount++;
  1938. LOG.Write($"{RobotModuleName} delay {delayCount} time to detect wafer");
  1939. Thread.Sleep(50);
  1940. if (delayCount > 100)
  1941. {
  1942. OnError("Wafer detect error");
  1943. return true;
  1944. }
  1945. }
  1946. if (_MaterialType == MaterialType.Wafer)
  1947. {
  1948. WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 2);
  1949. }
  1950. else if (_MaterialType == MaterialType.Carrier)
  1951. {
  1952. if (CarrierManager.Instance.CheckHasCarrier(sourcemodule.ToString(), 0))
  1953. {
  1954. CarrierManager.Instance.CarrierMoved(sourcemodule.ToString(), RobotModuleName.ToString(), true);
  1955. for (int i = 0; i < WaferManager.Instance.GetWafers(sourcemodule).Length; i++)
  1956. {
  1957. if (WaferManager.Instance.CheckHasWafer(sourcemodule, i))
  1958. WaferManager.Instance.WaferMoved(sourcemodule, i, RobotModuleName, i, false);
  1959. }
  1960. }
  1961. }
  1962. }
  1963. if (arm == RobotArmEnum.Upper || arm == RobotArmEnum.Blade2)
  1964. {
  1965. //WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 1);
  1966. while (!isSimulatorMode && GetWaferState(arm) != RobotArmWaferStateEnum.Present)
  1967. {
  1968. delayCount++;
  1969. LOG.Write($"{RobotModuleName} delay {delayCount} time to detect wafer");
  1970. Thread.Sleep(50);
  1971. if (delayCount > 100)
  1972. {
  1973. OnError("Wafer detect error");
  1974. return true;
  1975. }
  1976. }
  1977. WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 1);
  1978. }
  1979. if (arm == RobotArmEnum.Both)
  1980. {
  1981. //WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 0);
  1982. //WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 1);
  1983. while (!isSimulatorMode && GetWaferState(arm) != RobotArmWaferStateEnum.Present)
  1984. {
  1985. delayCount++;
  1986. LOG.Write($"{RobotModuleName} delay {delayCount} time to detect wafer");
  1987. Thread.Sleep(50);
  1988. if (delayCount > 100)
  1989. {
  1990. OnError("Wafer detect error");
  1991. return true;
  1992. }
  1993. }
  1994. WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 0);
  1995. WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex + 1, RobotModuleName, 1);
  1996. WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex + 2, RobotModuleName, 2);
  1997. WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex + 3, RobotModuleName, 3);
  1998. WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex + 4, RobotModuleName, 4);
  1999. }
  2000. return base.fPickComplete(param);
  2001. }
  2002. protected override bool fResetToReady(object[] param)
  2003. {
  2004. if (_doRobotHold != null)
  2005. _doRobotHold.SetTrigger(true, out _);
  2006. return true;
  2007. }
  2008. protected override bool fReset(object[] param)
  2009. {
  2010. if (!_connection.IsConnected)
  2011. {
  2012. _address = SC.GetStringValue($"{Name}.Address");
  2013. _enableLog = SC.GetValue<bool>($"{Name}.EnableLogMessage");
  2014. _connection = new GM201LVPRobotConnection(this, _address);
  2015. _connection.EnableLog(_enableLog);
  2016. _connection.Connect();
  2017. }
  2018. var alarmSignaRobotAlarm = DEVICE.GetDevice<IoAlarmSignal>($"PM1.AlarmSignaFOUPRobotAlarm");
  2019. if(Name == "WaferRobot")
  2020. alarmSignaRobotAlarm = DEVICE.GetDevice<IoAlarmSignal>($"PM1.AlarmSignaWaferRobotAlarm");
  2021. if (_isError || (alarmSignaRobotAlarm != null && alarmSignaRobotAlarm.Value))
  2022. {
  2023. lock (_locker)
  2024. {
  2025. string strpara = "1,1,N";
  2026. _lstHandlers.AddLast(new GM201LVPRobotMotionHandler(this, "INIT", strpara));
  2027. }
  2028. _isError = false;
  2029. return true;
  2030. }
  2031. lock (_locker)
  2032. {
  2033. if (_doRobotHold != null)
  2034. _doRobotHold.SetTrigger(true, out _);
  2035. _lstHandlers.Clear();
  2036. _connection.ForceClear();
  2037. //_lstHandlers.AddLast(new GM201LVPRobotMotionHandler(this, "CCLR", "E", _timeLimitMotion));
  2038. //string strpara = "1,1,N";
  2039. //_lstHandlers.AddLast(new GM201LVPRobotMotionHandler(this, "INIT", strpara));
  2040. //string strpara = "1,0,N";
  2041. //_lstHandlers.AddLast(new GM201LVPRobotMotionHandler(this, "INIT", strpara, _timeLimitMotion));
  2042. //_lstHandlers.AddLast(new GM201LVPRobotReadHandler(this, "RSTS"));
  2043. _timerActionMonitor.Restart();
  2044. }
  2045. return true;
  2046. }
  2047. protected override bool fMonitorReset(object[] param)
  2048. {
  2049. IsBusy = false;
  2050. if (_timerActionMonitor.IsRunning && _timerActionMonitor.Elapsed > TimeSpan.FromSeconds(_timeLimitMotion))
  2051. {
  2052. _timerActionMonitor.Stop();
  2053. OnError("ResetTimeOut");
  2054. return true;
  2055. }
  2056. if (_lstHandlers.Count == 0 && !_connection.IsBusy)
  2057. {
  2058. return true;
  2059. }
  2060. return false;
  2061. }
  2062. protected override bool fError(object[] param)
  2063. {
  2064. return true;
  2065. }
  2066. protected override bool fStartExtendForPick(object[] param)
  2067. {
  2068. return false;
  2069. }
  2070. protected override bool fStartExtendForPlace(object[] param)
  2071. {
  2072. return false;
  2073. }
  2074. protected override bool fStartRetractFromPick(object[] param)
  2075. {
  2076. return false;
  2077. }
  2078. protected override bool fStartRetractFromPlace(object[] param)
  2079. {
  2080. return false;
  2081. }
  2082. public void CheckWaferPresentAndGrip()
  2083. {
  2084. if (GetWaferState(RobotArmEnum.Lower) == RobotArmWaferStateEnum.Present)
  2085. {
  2086. if (WaferManager.Instance.CheckNoWafer(RobotModuleName, 0))
  2087. {
  2088. EV.PostWarningLog($"{RobotModuleName}", $"System detec wafer on lower arm, will create wafer automatically.");
  2089. WaferManager.Instance.CreateWafer(RobotModuleName, 0, WaferStatus.Normal);
  2090. }
  2091. }
  2092. if (GetWaferState(RobotArmEnum.Lower) == RobotArmWaferStateEnum.Absent)
  2093. {
  2094. _lstHandlers.AddLast(new GM201LVPRobotMotionHandler(this, "CSOL", "1,0,0"));
  2095. if (WaferManager.Instance.CheckHasWafer(RobotModuleName, 0))
  2096. {
  2097. EV.PostWarningLog($"{RobotModuleName}", $"System didn't detect wafer on lower arm, but it has record.");
  2098. }
  2099. }
  2100. if (GetWaferState(RobotArmEnum.Upper) == RobotArmWaferStateEnum.Present)
  2101. {
  2102. if (WaferManager.Instance.CheckNoWafer(RobotModuleName, 1))
  2103. {
  2104. EV.PostWarningLog($"{RobotModuleName}", $"System detect wafer on upper arm, will create wafer automatically.");
  2105. WaferManager.Instance.CreateWafer(RobotModuleName, 1, WaferStatus.Normal);
  2106. }
  2107. }
  2108. if (GetWaferState(RobotArmEnum.Upper) == RobotArmWaferStateEnum.Absent)
  2109. {
  2110. _lstHandlers.AddLast(new GM201LVPRobotMotionHandler(this, "CSOL", "2,0,0"));
  2111. if (WaferManager.Instance.CheckHasWafer(RobotModuleName, 1))
  2112. {
  2113. EV.PostWarningLog($"{RobotModuleName}", $"System didn't detect wafer on upper arm, but it has record.");
  2114. }
  2115. }
  2116. }
  2117. public override RobotArmWaferStateEnum GetWaferState(RobotArmEnum arm)
  2118. {
  2119. if (arm == RobotArmEnum.Lower || arm == RobotArmEnum.Blade1)
  2120. {
  2121. if (_diRobotBlade1WaferOn != null)
  2122. {
  2123. if (_diRobotBlade1WaferOn.Value) return RobotArmWaferStateEnum.Absent;
  2124. else return RobotArmWaferStateEnum.Present;
  2125. }
  2126. var waferPresenceOnBlade1 = _MaterialType == MaterialType.Wafer ? IsWaferPresenceOnBlade3 : IsWaferPresenceOnBlade1;
  2127. return waferPresenceOnBlade1 ? RobotArmWaferStateEnum.Present : RobotArmWaferStateEnum.Absent;
  2128. }
  2129. if (arm == RobotArmEnum.Upper || arm == RobotArmEnum.Blade2)
  2130. {
  2131. if (_diRobotBlade2WaferOn != null)
  2132. {
  2133. if (_diRobotBlade2WaferOn.Value) return RobotArmWaferStateEnum.Absent;
  2134. else return RobotArmWaferStateEnum.Present;
  2135. }
  2136. return IsWaferPresenceOnBlade2 ? RobotArmWaferStateEnum.Present : RobotArmWaferStateEnum.Absent;
  2137. }
  2138. if (arm == RobotArmEnum.Both)
  2139. {
  2140. if (_diRobotBlade1WaferOn != null && _diRobotBlade2WaferOn != null)
  2141. {
  2142. if (_diRobotBlade2WaferOn.Value && _diRobotBlade1WaferOn.Value)
  2143. return RobotArmWaferStateEnum.Absent;
  2144. else if (!_diRobotBlade2WaferOn.Value && !_diRobotBlade1WaferOn.Value)
  2145. return RobotArmWaferStateEnum.Present;
  2146. else return RobotArmWaferStateEnum.Unknown;
  2147. }
  2148. if (IsWaferPresenceOnBlade1 && IsWaferPresenceOnBlade2 && IsWaferPresenceOnBlade3 && IsWaferPresenceOnBlade4 && IsWaferPresenceOnBlade5)
  2149. {
  2150. return RobotArmWaferStateEnum.Present;
  2151. }
  2152. if ((!IsWaferPresenceOnBlade1) && !IsWaferPresenceOnBlade2 && !IsWaferPresenceOnBlade3 && !IsWaferPresenceOnBlade4 && !IsWaferPresenceOnBlade5)
  2153. {
  2154. return RobotArmWaferStateEnum.Absent;
  2155. }
  2156. }
  2157. return RobotArmWaferStateEnum.Unknown;
  2158. }
  2159. public override void NoteError(string errortext)
  2160. {
  2161. _isError = true;
  2162. if(!string.IsNullOrEmpty(errortext))
  2163. OnError(errortext);
  2164. //lock (_locker)
  2165. {
  2166. _lstHandlers.Clear();
  2167. _connection.ForceClear();
  2168. if(_tpStatus != null && _tpStatus.Value)
  2169. {
  2170. //true是TP状态
  2171. //TP状态,不需要发
  2172. }
  2173. else
  2174. {
  2175. _lstHandlers.AddLast(new GM201LVPRobotReadHandler(this, "RERR", "001"));
  2176. }
  2177. }
  2178. }
  2179. //public void SenACK()
  2180. //{
  2181. // _connection.SendAck();
  2182. //}
  2183. public override bool OnActionDone(object[] param)
  2184. {
  2185. return true;
  2186. }
  2187. public override void Terminate()
  2188. {
  2189. _thread.Stop();
  2190. if (!SC.ContainsItem($"{Name}.CloseConnectionOnShutDown") || SC.GetValue<bool>($"{Name}.CloseConnectionOnShutDown"))
  2191. {
  2192. LOG.Write("Close connection for" + RobotModuleName.ToString());
  2193. _connection.Disconnect();
  2194. }
  2195. base.Terminate();
  2196. }
  2197. private string BuildBladeTarget()
  2198. {
  2199. return (CmdRobotArm == RobotArmEnum.Upper ? "ArmB" : "ArmA") + "." + CmdTarget;
  2200. }
  2201. public override void SetPauseResume(bool isPause)
  2202. {
  2203. _connection.SendMessage($"{(isPause ? "CSTP,H" : "CRSM")}\r");
  2204. if (_connection.ActiveHandler != null)
  2205. {
  2206. if (isPause)
  2207. {
  2208. _connection.ActiveHandler.TimerAck?.Stop();
  2209. _connection.ActiveHandler.TimerComplete?.Stop();
  2210. }
  2211. else
  2212. {
  2213. _connection.ActiveHandler.TimerAck?.Start();
  2214. _connection.ActiveHandler.TimerComplete?.Start();
  2215. }
  2216. }
  2217. }
  2218. public void NotePause(bool isPause)
  2219. {
  2220. IsPause = isPause;
  2221. }
  2222. }
  2223. public class GM201LVPTokenGenerator
  2224. {
  2225. private int _last = 0;
  2226. List<int> _pool = new List<int>();
  2227. SCConfigItem scToken = null;
  2228. public int CurrentToken => _last;
  2229. public GM201LVPTokenGenerator(string scName)
  2230. {
  2231. scToken = SC.GetConfigItem(scName);
  2232. if (scToken == null)
  2233. _last = scToken.IntValue;
  2234. Random r = new Random();
  2235. _last = r.Next() % 20;
  2236. }
  2237. public int create()
  2238. {
  2239. int first = _last;
  2240. int token = first;
  2241. do
  2242. {
  2243. token = (token + 1) % 100;
  2244. if (_pool.Contains(token))
  2245. continue;
  2246. _pool.Add(token);
  2247. _last = token;
  2248. scToken.IntValue = _last;
  2249. return _last;
  2250. } while (token != first);
  2251. throw (new ExcuteFailedException("Get token failed,pool is full"));
  2252. }
  2253. public void release(int token)
  2254. {
  2255. _pool.Remove(token);
  2256. }
  2257. public void release()
  2258. {
  2259. _last = 0;
  2260. _pool.Clear();
  2261. }
  2262. }
  2263. public enum GM201LVPPositonEnum
  2264. {
  2265. RegisteredPosition,
  2266. ReadyPosition,
  2267. IntermediatePosition,
  2268. MappingStartPosition,
  2269. MappingFinishPosition,
  2270. }
  2271. }