JelRobot.cs 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO.Ports;
  4. using System.Linq;
  5. using System.Text;
  6. using Aitex.Core.Common.DeviceData;
  7. using Aitex.Core.RT.Device;
  8. using Aitex.Core.RT.Device.Unit;
  9. using Aitex.Core.RT.Event;
  10. using Aitex.Core.RT.Log;
  11. using Aitex.Core.RT.OperationCenter;
  12. using Aitex.Core.RT.SCCore;
  13. using Aitex.Core.Util;
  14. using MECF.Framework.Common.Communications;
  15. using MECF.Framework.Common.Device.Bases;
  16. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Common;
  17. using Newtonsoft.Json;
  18. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
  19. using MECF.Framework.Common.Equipment;
  20. using MECF.Framework.Common.SubstrateTrackings;
  21. using System.Threading;
  22. using Aitex.Core.Common;
  23. using Aitex.Core.RT.DataCenter;
  24. using System.Text.RegularExpressions;
  25. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts;
  26. using MECF.Framework.Common.CommonData;
  27. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
  28. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Flipper.FlipperBase;
  29. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.JEL
  30. {
  31. public class JelRobot : RobotBaseDevice, IConnection
  32. {
  33. private int _bodyNumber;
  34. private string _robotModel; //T-00902H
  35. public int BodyNumber { get => _bodyNumber; }
  36. private string _address = "";
  37. public string Address { get => _address; }
  38. private bool isSimulatorMode;
  39. private string _scRoot;
  40. private PeriodicJob _thread;
  41. protected JelRobotConnection _connection;
  42. private R_TRIG _trigError = new R_TRIG();
  43. private R_TRIG _trigCommunicationError = new R_TRIG();
  44. private R_TRIG _trigRetryConnect = new R_TRIG();
  45. private R_TRIG _trigActionDone = new R_TRIG();
  46. protected LinkedList<HandlerBase> _lstMonitorHandler = new LinkedList<HandlerBase>();
  47. protected DateTime _dtActionStart;
  48. protected object _locker = new object();
  49. private bool _enableLog;
  50. public string PortName;
  51. public event Action<ModuleName, string> OnRobotEvent;
  52. public bool IsConnected { get; }
  53. public bool Connect()
  54. {
  55. return true;
  56. }
  57. public bool Disconnect()
  58. {
  59. return true;
  60. }
  61. public override event Action<ModuleName, string> OnDeviceEvent;
  62. public void OnEventReceived(JelRobotMessage msg)
  63. {
  64. if(OnDeviceEvent != null)
  65. {
  66. OnDeviceEvent(RobotModuleName, msg.Data);
  67. }
  68. }
  69. public JelRobot(string module, string name, string scRoot, string robotModel = "", int armCount = 2) : base(module, name, "Robot", armCount)
  70. {
  71. _robotModel = robotModel;
  72. isSimulatorMode = SC.ContainsItem("System.IsSimulatorMode") ? SC.GetValue<bool>("System.IsSimulatorMode") : false;
  73. _scRoot = scRoot;
  74. ResetPropertiesAndResponses();
  75. RegisterSpecialData();
  76. _enableLog = SC.GetValue<bool>($"{_scRoot}.{Name}.EnableLogMessage");
  77. _bodyNumber = SC.GetValue<int>($"{_scRoot}.{Name}.BodyNumber");
  78. PortName = SC.GetStringValue($"{_scRoot}.{Name}.PortName");
  79. _connection = new JelRobotConnection(PortName);
  80. _connection.Robot = this;
  81. _connection.EnableLog(_enableLog);
  82. if (_connection.Connect())
  83. {
  84. EV.PostInfoLog(Module, $"{Module}.{Name} connected");
  85. }
  86. _thread = new PeriodicJob(100, OnTimer, $"{Module}.{Name} MonitorHandler", true);
  87. }
  88. public JelRobot(string module, string name, string scRoot, string portName,string robotModel = "",int armCount=2) : base(module, name,"Robot",armCount)
  89. {
  90. _robotModel = robotModel;
  91. isSimulatorMode = SC.ContainsItem("System.IsSimulatorMode") ? SC.GetValue<bool>("System.IsSimulatorMode") : false;
  92. _scRoot = scRoot;
  93. ResetPropertiesAndResponses();
  94. RegisterSpecialData();
  95. _enableLog = SC.GetValue<bool>($"{_scRoot}.{Name}.EnableLogMessage");
  96. _bodyNumber = SC.GetValue<int>($"{_scRoot}.{Name}.BodyNumber");
  97. PortName = SC.GetStringValue($"{_scRoot}.{Name}.PortName");
  98. _connection = new JelRobotConnection(PortName);
  99. _connection.EnableLog(_enableLog);
  100. if (_connection.Connect())
  101. {
  102. EV.PostInfoLog(Module, $"{Module}.{Name} connected");
  103. }
  104. _thread = new PeriodicJob(100, OnTimer, $"{Module}.{Name} MonitorHandler", true);
  105. }
  106. #region Properties
  107. public JelAxisStatus RightarmAndThetaarmStatus { get; private set; }
  108. public JelAxisStatus LeftarmAndZaxisStatus { get; private set; }
  109. public float RightArmPostion { get; private set; }
  110. public float ThetaAxisPostion { get; private set; }
  111. public float LeftArmPostion { get; private set; }
  112. public float ZAxisPostion { get; private set; }
  113. public Int32[] AData { get; private set; } = new Int32[1000];
  114. public JelParameterData[] RobotParameters { get; private set; } = new JelParameterData[2000];
  115. public string ReadBankNumber { get; private set; } = "";
  116. public int ReadCassetNumber { get; private set; }
  117. public int ReadSlotNumber { get; private set; }
  118. public bool IsRightArmPressureSensorON { get; private set; }
  119. public bool IsLeftArmPressureSensorON { get; private set; }
  120. public bool IsEchoBack { get; private set; }
  121. public JelCommandStatus CurrentCompoundCommandStatus { get; private set; }
  122. public string StopPostionOfCompoundCommand { get; private set; }
  123. public string[] MainRoutines { get; private set; } = new string[320];
  124. public string[] SubRoutines { get; private set; } = new string[16];
  125. public string CurrentReadRoutine { get; private set; }
  126. public int HighSpeed { get; private set; }
  127. public int LowSpeed { get; private set; }
  128. public int DomainOfAccDec { get; private set; }
  129. public int AccDecSpeed { get; private set; }
  130. public int MagnificationOfFrequency { get; private set; }
  131. public int PulsePostionOfManualSlowDown { get; private set; }
  132. public int CurrentReadSpeedData
  133. {
  134. get;set;
  135. }
  136. public Int32 CurrentReadAData { get; private set; }
  137. public Int32 ReadPosRightArmPostion { get; private set; }
  138. public Int32 ReadPosThetaAxisPostion { get; private set; }
  139. public Int32 ReadPosLeftArmPostion { get; private set; }
  140. public Int32 ReadPosZAxisPostion { get; private set; }
  141. public float ReadParameterMin { get; private set; }
  142. public float ReadParameterMax { get; private set; }
  143. public float ReadParameterValue { get; private set; }
  144. //Mapping Data
  145. public float MappingFirstSlotPosition { get; private set; }
  146. public float MappingTopSlotPostion { get; private set; }
  147. public int MappingSlotsNumber { get; private set; }
  148. public float MappingMinDetectWidth { get; private set; }
  149. public float MappingMaxDetectWidth { get; private set; }
  150. public float MappingGateWidth { get; private set; }
  151. public float MappingStopPostion { get; private set; }
  152. public float MappingSpeed { get; private set; }
  153. public bool IsMappingSensorON { get; private set; }
  154. public string MappingWaferResult { get; private set; } = string.Empty;
  155. public string MappingWidthResult { get; private set; } = string.Empty;
  156. protected bool ResetBeforeCmd
  157. {
  158. get
  159. {
  160. if (SC.ContainsItem($"Robot.{RobotModuleName}.ResetBeforeCmd") && SC.GetValue<bool>($"Robot.{RobotModuleName}.ResetBeforeCmd"))
  161. return true;
  162. return false;
  163. }
  164. }
  165. protected bool GotoSafePositionBeforeCmd
  166. {
  167. get
  168. {
  169. if (SC.ContainsItem($"Robot.{RobotModuleName}.GotoSafePositionBeforeCmd"))
  170. return SC.GetValue<bool>($"Robot.{RobotModuleName}.GotoSafePositionBeforeCmd");
  171. return true;
  172. }
  173. }
  174. #endregion
  175. #region ParseHandler
  176. public void ParseData(string command,string parameter,string data)
  177. {
  178. try
  179. {
  180. string datavalue = data.Replace($"${BodyNumber}", "").Replace("\r", "");
  181. if (command == "SPA")
  182. {
  183. CurrentReadSpeedData = Convert.ToInt32(datavalue);
  184. }
  185. if (command == "") ParseRobotStatus(datavalue); // Read Robot Status
  186. if (command == "6" || command == "6M")
  187. ParseRobotPostion(parameter, datavalue); //Read Postion Data
  188. if (command == "A") // Read A data
  189. {
  190. int _index;
  191. if (!int.TryParse(parameter.Replace("D", ""), out _index)) return;
  192. AData[_index] = Convert.ToInt32(datavalue);
  193. CurrentReadAData = Convert.ToInt32(datavalue);
  194. }
  195. if (command == "BC")
  196. {
  197. ReadBankNumber = datavalue;
  198. }
  199. if (command == "WCP")
  200. {
  201. string[] strvalues = datavalue.Split(',');
  202. ReadCassetNumber = Convert.ToInt32(strvalues[0]);
  203. ReadSlotNumber = Convert.ToInt32(strvalues[1]);
  204. }
  205. if (command == "CS")
  206. {
  207. if (parameter == "1")
  208. IsRightArmPressureSensorON = datavalue == "1";
  209. if (parameter == "2")
  210. IsLeftArmPressureSensorON = datavalue == "1";
  211. }
  212. if (command == "DTD")
  213. {
  214. int _index;
  215. if (!int.TryParse(parameter, out _index)) return;
  216. string[] paradata = datavalue.Split(',');
  217. //if (paradata.Length < 3) return;
  218. RobotParameters[_index].Value = paradata[0];
  219. RobotParameters[_index].MinValue = paradata[1];
  220. RobotParameters[_index].MaxValue = paradata[2];
  221. }
  222. if (command == "EE")
  223. {
  224. IsEchoBack = datavalue == "E";
  225. }
  226. if (command == "G")
  227. {
  228. if (datavalue == "0") CurrentCompoundCommandStatus = JelCommandStatus.NormalEnd;
  229. if (datavalue == "1") CurrentCompoundCommandStatus = JelCommandStatus.InExecution;
  230. if (datavalue == "P") CurrentCompoundCommandStatus = JelCommandStatus.InPause;
  231. if (datavalue == "E") CurrentCompoundCommandStatus = JelCommandStatus.InError;
  232. }
  233. if (command == "GER")
  234. {
  235. LOG.Write("Compaund command stop postion:" + datavalue);
  236. }
  237. if (command == "IR")
  238. {
  239. int _index;
  240. if (!int.TryParse(parameter, out _index)) return;
  241. if (_index < 0 || _index > 319) return;
  242. MainRoutines[_index] = datavalue;
  243. CurrentReadRoutine = datavalue;
  244. }
  245. if (command == "IRS")
  246. {
  247. int _index = Convert.ToInt32(parameter, 16);
  248. if (_index < 0 || _index > 15) return;
  249. SubRoutines[_index] = datavalue;
  250. CurrentReadRoutine = datavalue;
  251. }
  252. if (command == "O")
  253. {
  254. //CurrentReadSpeedData = Convert.ToInt32(datavalue);
  255. if (parameter == "H")
  256. HighSpeed = Convert.ToInt32(datavalue);
  257. if (parameter == "L")
  258. LowSpeed = Convert.ToInt32(datavalue);
  259. if (parameter == "S")
  260. DomainOfAccDec = Convert.ToInt32(datavalue);
  261. if (parameter == "G")
  262. AccDecSpeed = Convert.ToInt32(datavalue);
  263. if (parameter == "X")
  264. MagnificationOfFrequency = Convert.ToInt32(datavalue);
  265. if (parameter == "D")
  266. PulsePostionOfManualSlowDown = Convert.ToInt32(datavalue);
  267. }
  268. if (command == "PSD")
  269. {
  270. string[] stradata = datavalue.Split(',');
  271. ReadPosRightArmPostion = Convert.ToInt32(stradata[0].ToString());
  272. ReadPosThetaAxisPostion = Convert.ToInt32(stradata[1].ToString());
  273. ReadPosLeftArmPostion = Convert.ToInt32(stradata[2].ToString());
  274. ReadPosZAxisPostion = Convert.ToInt32(stradata[3].ToString());
  275. }
  276. if (command == "DTD")
  277. {
  278. string[] stradata = datavalue.Split(',');
  279. ReadParameterValue = Convert.ToSingle(stradata[0].ToString());
  280. ReadParameterMin = Convert.ToSingle(stradata[1].ToString());
  281. ReadParameterMax = Convert.ToSingle(stradata[2].ToString());
  282. }
  283. if (command == "WLO") // Obtaining the postion data of mapping 1st slot detected
  284. MappingFirstSlotPosition = Convert.ToSingle(datavalue);
  285. if(command == "WHI")
  286. MappingTopSlotPostion = Convert.ToSingle(datavalue);
  287. if(command == "WFC")
  288. MappingSlotsNumber = Convert.ToInt32(datavalue);
  289. if(command == "WWN")
  290. MappingMinDetectWidth = Convert.ToSingle(datavalue);
  291. if(command == "WWM")
  292. MappingMaxDetectWidth = Convert.ToSingle(datavalue);
  293. if(command == "WWG")
  294. MappingGateWidth = Convert.ToSingle(datavalue);
  295. if(command == "WEND")
  296. MappingStopPostion = Convert.ToSingle(datavalue);
  297. if(command == "WSP")
  298. MappingSpeed = Convert.ToSingle(datavalue);
  299. if(command == "WFK")
  300. {
  301. MappingWaferResult = datavalue;
  302. NotifySlotMapResult(CurrentInteractModule, datavalue.Replace(",", "").Replace("E", "?"));
  303. }
  304. if (command == "WFW")
  305. MappingWidthResult = datavalue;
  306. }
  307. catch(Exception ex)
  308. {
  309. LOG.Write($"Parse {command}.{parameter??parameter} data {data} error:" + ex.ToString());
  310. OnError($"Parse data error:{command}.{parameter ?? parameter} data {data}");
  311. }
  312. }
  313. public void HandlerWaferCheckResult(bool checkError, RobotArmEnum arm, bool iswaferOn)
  314. {
  315. if(checkError)
  316. {
  317. OnError("CheckWaferError");
  318. return;
  319. }
  320. if (iswaferOn && WaferManager.Instance.CheckNoWafer(RobotModuleName, (int)arm))
  321. {
  322. EV.PostAlarmLog("Robot", $"There's unknown wafer on {RobotModuleName} {arm}");
  323. WaferManager.Instance.CreateWafer(RobotModuleName, (int)arm, WaferStatus.Normal);
  324. }
  325. if (!iswaferOn && WaferManager.Instance.CheckHasWafer(RobotModuleName, (int)arm))
  326. {
  327. EV.PostAlarmLog("Robot", $"There's a wafer on {RobotModuleName} {arm} but robot didn't detect");
  328. }
  329. }
  330. private void ParseRobotStatus(string data)
  331. {
  332. if (data.Length < 2) return;
  333. RightarmAndThetaarmStatus = (JelAxisStatus)Convert.ToInt16(data.ToArray()[0].ToString(), 16);
  334. LeftarmAndZaxisStatus = (JelAxisStatus)Convert.ToInt16(data.ToArray()[1].ToString(), 16);
  335. }
  336. private void ParseRobotPostion(string axis,string data)
  337. {
  338. float _floatvalue;
  339. if (!float.TryParse(data, out _floatvalue)) return;
  340. if (axis == "1")
  341. {
  342. RightArmPostion = _floatvalue;
  343. PositionAxis1 = _floatvalue;
  344. }
  345. if (axis == "2")
  346. {
  347. ThetaAxisPostion = _floatvalue;
  348. PositionAxis2 = _floatvalue;
  349. }
  350. if (axis == "3")
  351. {
  352. LeftArmPostion = _floatvalue;
  353. PositionAxis3 = _floatvalue;
  354. }
  355. if (axis == "4")
  356. {
  357. ZAxisPostion = _floatvalue;
  358. PositionAxis4 = _floatvalue;
  359. }
  360. }
  361. #endregion
  362. public virtual bool OnTimer()
  363. {
  364. try
  365. {
  366. if (!_connection.IsConnected || _connection.IsCommunicationError)
  367. {
  368. lock (_locker)
  369. {
  370. _lstMonitorHandler.Clear();
  371. }
  372. if (_connection.IsCommunicationError)
  373. {
  374. _connection.Disconnect();
  375. Thread.Sleep(500);
  376. if (!_connection.Connect())
  377. {
  378. EV.PostAlarmLog(Module, $"Can not connect with {_connection.Address}, {Module}.{Name}");
  379. }
  380. else
  381. {
  382. EV.PostInfoLog(Module, $"Success to re-connect with {_connection.Address}, {Module}.{Name} on communication error");
  383. }
  384. _connection.ForceClear();
  385. }
  386. //_trigRetryConnect.CLK = !_connection.IsConnected;
  387. if (!_connection.IsConnected)
  388. {
  389. _connection.SetPortAddress(SC.GetStringValue($"{_scRoot}.{Name}.PortName"));
  390. if (!_connection.Connect())
  391. {
  392. EV.PostAlarmLog(Module, $"Can not connect with {_connection.Address}, {Module}.{Name}");
  393. }
  394. else
  395. {
  396. EV.PostInfoLog(Module, $"Success to re-connect with {_connection.Address}, {Module}.{Name}");
  397. }
  398. }
  399. return true;
  400. }
  401. HandlerBase handler = null;
  402. DateTime dtstart = DateTime.Now;
  403. if (_lstMonitorHandler.Count > 0)
  404. {
  405. if (!_connection.IsBusy)
  406. {
  407. lock (_locker)
  408. {
  409. handler = _lstMonitorHandler.First.Value;
  410. _connection.Execute(handler);
  411. _lstMonitorHandler.RemoveFirst();
  412. }
  413. }
  414. else
  415. {
  416. _connection.MonitorTimeout();
  417. _trigCommunicationError.CLK = _connection.IsCommunicationError;
  418. if (_trigCommunicationError.Q)
  419. {
  420. _lstMonitorHandler.Clear();
  421. OnError($"{Module}.{Name} communication error, {_connection.LastCommunicationError}");
  422. }
  423. }
  424. }
  425. }
  426. catch (Exception ex)
  427. {
  428. LOG.Write(ex);
  429. }
  430. return true;
  431. }
  432. private void RegisterSpecialData()
  433. {
  434. DATA.Subscribe($"{Module}.{Name}.CurrentReadRoutine", () => CurrentReadRoutine);
  435. DATA.Subscribe($"{Module}.{Name}.CurrentReadSpeedData", () => CurrentReadSpeedData);
  436. DATA.Subscribe($"{Module}.{Name}.CurrentReadAData", () => CurrentReadAData);
  437. DATA.Subscribe($"{Module}.{Name}.IsLeftArmPressureSensorON", () => IsLeftArmPressureSensorON);
  438. DATA.Subscribe($"{Module}.{Name}.IsRightArmPressureSensorON", () => IsRightArmPressureSensorON);
  439. DATA.Subscribe($"{Module}.{Name}.LeftarmAndZaxisStatus", () => LeftarmAndZaxisStatus.ToString());
  440. DATA.Subscribe($"{Module}.{Name}.RightarmAndThetaarmStatus", () => RightarmAndThetaarmStatus.ToString());
  441. DATA.Subscribe($"{Module}.{Name}.CurrentCompoundCommandStatus", () => CurrentCompoundCommandStatus.ToString());
  442. DATA.Subscribe($"{Module}.{Name}.ReadCassetNumber", () => ReadCassetNumber.ToString());
  443. DATA.Subscribe($"{Module}.{Name}.ReadSlotNumber", () => ReadSlotNumber.ToString());
  444. DATA.Subscribe($"{Module}.{Name}.ReadBankNumber", () => ReadBankNumber.ToString());
  445. DATA.Subscribe($"{Module}.{Name}.ReadPosLeftArmPostion", () => ReadPosLeftArmPostion);
  446. DATA.Subscribe($"{Module}.{Name}.ReadPosRightArmPostion", () => ReadPosRightArmPostion.ToString());
  447. DATA.Subscribe($"{Module}.{Name}.ReadPosZAxisPostion", () => ReadPosZAxisPostion.ToString());
  448. DATA.Subscribe($"{Module}.{Name}.ReadPosThetaAxisPostion", () => ReadPosThetaAxisPostion.ToString());
  449. DATA.Subscribe($"{Module}.{Name}.ReadParameterMax", () => ReadParameterMax.ToString());
  450. DATA.Subscribe($"{Module}.{Name}.ReadParameterMin", () => ReadParameterMin.ToString());
  451. DATA.Subscribe($"{Module}.{Name}.ReadParameterValue", () => ReadParameterValue.ToString());
  452. DATA.Subscribe($"{Module}.{Name}.MappingFirstSlotPosition", () => MappingFirstSlotPosition.ToString());
  453. DATA.Subscribe($"{Module}.{Name}.MappingGateWidth", () => MappingGateWidth.ToString());
  454. DATA.Subscribe($"{Module}.{Name}.MappingMaxDetectWidth", () => MappingMaxDetectWidth.ToString());
  455. DATA.Subscribe($"{Module}.{Name}.MappingMinDetectWidth", () => MappingMinDetectWidth.ToString());
  456. DATA.Subscribe($"{Module}.{Name}.MappingSlotsNumber", () => MappingSlotsNumber.ToString());
  457. DATA.Subscribe($"{Module}.{Name}.MappingSpeed", () => MappingSpeed.ToString());
  458. DATA.Subscribe($"{Module}.{Name}.MappingStopPostion", () => MappingStopPostion.ToString());
  459. DATA.Subscribe($"{Module}.{Name}.MappingTopSlotPostion", () => MappingTopSlotPostion.ToString());
  460. DATA.Subscribe($"{Module}.{Name}.IsMappingSensorON", () => IsMappingSensorON.ToString());
  461. DATA.Subscribe($"{Module}.{Name}.MappingWaferResult", () => MappingWaferResult.ToString());
  462. DATA.Subscribe($"{Module}.{Name}.MappingWidthResult", () => MappingWidthResult.ToString());
  463. DATA.Subscribe($"{Name}.RobotSpeed", () => CurrentReadSpeedData);
  464. }
  465. private void ResetPropertiesAndResponses()
  466. {
  467. }
  468. protected override bool fReset(object[] param)
  469. {
  470. _dtActionStart = DateTime.Now;
  471. _trigError.RST = true;
  472. _connection.SetCommunicationError(false, "");
  473. _trigCommunicationError.RST = true;
  474. _enableLog = SC.GetValue<bool>($"{_scRoot}.{Name}.EnableLogMessage");
  475. _connection.EnableLog(_enableLog);
  476. _trigRetryConnect.RST = true;
  477. _lstMonitorHandler.Clear();
  478. _connection.ForceClear();
  479. lock (_locker)
  480. {
  481. _lstMonitorHandler.AddLast(new JelRobotRawCommandHandler(this, $"${BodyNumber}RD\r"));
  482. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, ""));
  483. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "6M", "1"));
  484. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "6M", "2"));
  485. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "6M", "3"));
  486. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "6M", "4"));
  487. }
  488. return true;
  489. }
  490. protected override bool fMonitorReset(object[] param)
  491. {
  492. IsBusy = false;
  493. if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(RobotCommandTimeout))
  494. {
  495. HandlerError("ResetTimeout");
  496. return true;
  497. }
  498. if (RightarmAndThetaarmStatus == JelAxisStatus.NormalEnd
  499. && LeftarmAndZaxisStatus == JelAxisStatus.NormalEnd
  500. && _lstMonitorHandler.Count == 0
  501. && !_connection.IsBusy)
  502. {
  503. IsBusy = false;
  504. return true;
  505. }
  506. if (_lstMonitorHandler.Count == 0 && !_connection.IsBusy)
  507. _connection.Execute(new JelRobotReadHandler(this, ""));
  508. return false;
  509. }
  510. protected override bool fStartMove(object[] param)
  511. {
  512. _dtActionStart = DateTime.Now;
  513. if (param.Length < 4) return false;
  514. int axis,intdirect;
  515. if (!int.TryParse(param[0].ToString(), out axis)) return false;
  516. if (axis > 4 || axis < 0) return false;
  517. if (!int.TryParse(param[1].ToString(), out intdirect)) return false;
  518. if (intdirect > 1 || intdirect < 0) return false;
  519. RobotMoveDirectionEnum direction = (RobotMoveDirectionEnum)Convert.ToInt16(param[1].ToString());
  520. uint instance;
  521. if (!uint.TryParse(param[2].ToString(), out instance)) return false;
  522. if (instance > 8388607) instance = 8388607;
  523. string movebasetype = Regex.Replace(param[3].ToString().Replace("(", "(").Replace(")", ")"), @"\([^\(]*\)", "");
  524. if (movebasetype != "0" && movebasetype != "1") return false;
  525. string commandstr = "";
  526. if (movebasetype == "0") commandstr = "3";
  527. if(movebasetype == "1")
  528. {
  529. if (direction == RobotMoveDirectionEnum.Fwd) commandstr = "4";
  530. else commandstr = "5";
  531. }
  532. if (string.IsNullOrEmpty(commandstr)) return false;
  533. string speedtype = string.Empty;
  534. if (param.Length > 4)
  535. speedtype = Regex.Replace(param[4].ToString().Replace("(", "(").Replace(")", ")"), @"\([^\(]*\)", "");
  536. if (speedtype != "" && speedtype != "M" && speedtype != "L") return false;
  537. lock (_locker)
  538. {
  539. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "2", instance.ToString()));
  540. _lstMonitorHandler.AddLast(new JelRobotMoveHandler(this, commandstr + "M", axis.ToString() + speedtype));
  541. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, ""));
  542. }
  543. return true;
  544. }
  545. protected override bool fMonitorMoving(object[] param)
  546. {
  547. IsBusy = false;
  548. if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(RobotCommandTimeout))
  549. {
  550. HandlerError("MoveTimeout");
  551. return true;
  552. }
  553. if (RightarmAndThetaarmStatus == JelAxisStatus.NormalEnd
  554. && (LeftarmAndZaxisStatus == JelAxisStatus.NormalEnd)
  555. && _lstMonitorHandler.Count == 0
  556. && !_connection.IsBusy)
  557. {
  558. IsBusy = false;
  559. return true;
  560. }
  561. if (_lstMonitorHandler.Count == 0 &&!_connection.IsBusy)
  562. _connection.Execute(new JelRobotReadHandler(this, ""));
  563. return false;
  564. }
  565. protected override bool fStartInit(object[] param)
  566. {
  567. _dtActionStart = DateTime.Now;
  568. int compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.InitCmdNO");
  569. int Robotspeed = SC.GetValue<int>($"Robot.{Name}.RobotSpeed");
  570. if (Robotspeed < 0)
  571. Robotspeed = 0;
  572. if (Robotspeed > 9)
  573. Robotspeed = 9;
  574. if(GetForbidHomeArea() != null && GetForbidHomeArea().Count >1)
  575. {
  576. lock (_locker)
  577. {
  578. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "6M", "1"));
  579. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "6M", "2"));
  580. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "6M", "3"));
  581. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "6M", "4"));
  582. }
  583. int waitCount = 0;
  584. while(true)
  585. {
  586. waitCount++;
  587. if(waitCount >100)
  588. {
  589. OnError("InitErrorWhenGetPostionData");
  590. return false;
  591. }
  592. if(_lstMonitorHandler.Count ==0 && !_connection.IsBusy)
  593. {
  594. break;
  595. }
  596. Thread.Sleep(100);
  597. }
  598. foreach(var forbidData in GetForbidHomeArea())
  599. {
  600. if(RightArmPostion >= forbidData[0].Item1 && RightArmPostion<= forbidData[0].Item2
  601. && ThetaAxisPostion >= forbidData[1].Item1 && ThetaAxisPostion <= forbidData[1].Item2
  602. && ZAxisPostion >= forbidData[2].Item1 && ZAxisPostion <= forbidData[2].Item2)
  603. {
  604. OnError("RobotIsInForbidHomeArea");
  605. return false;
  606. }
  607. if (ReadPosLeftArmPostion >= forbidData[0].Item1 && ReadPosLeftArmPostion <= forbidData[0].Item2
  608. && ThetaAxisPostion >= forbidData[1].Item1 && ThetaAxisPostion <= forbidData[1].Item2
  609. && ZAxisPostion >= forbidData[2].Item1 && ZAxisPostion <= forbidData[2].Item2)
  610. {
  611. OnError("RobotIsInForbidHomeArea");
  612. return false;
  613. }
  614. }
  615. }
  616. lock (_locker)
  617. {
  618. _lstMonitorHandler.AddLast(new JelRobotCompaundCommandHandler(this, compaundcmdNO.ToString()));
  619. _lstMonitorHandler.AddLast(new JelRobotMoveHandler(this, ""));
  620. _lstMonitorHandler.AddLast(new JelRobotMoveHandler(this, "G"));
  621. _lstMonitorHandler.AddLast(new JelRobotMoveHandler(this, "CS1"));
  622. _lstMonitorHandler.AddLast(new JelRobotMoveHandler(this, "BC")); // Read bank number
  623. _lstMonitorHandler.AddLast(new JelRobotMoveHandler(this, "WCP")); // Read Cassette Number
  624. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "6M", "1"));
  625. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "6M", "2"));
  626. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "6M", "3"));
  627. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "6M", "4"));
  628. _lstMonitorHandler.AddLast(new JelRobotMoveHandler(this, "SP", Robotspeed.ToString()));
  629. if(SC.ContainsItem($"Robot.{Name}.UpperCheckWaferCmdNO") &&
  630. SC.GetValue<int>($"Robot.{Name}.UpperCheckWaferCmdNO")!=0)
  631. {
  632. compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.UpperCheckWaferCmdNO");
  633. _lstMonitorHandler.AddLast(new JelRobotCheckWaferCommandHandler(this, compaundcmdNO.ToString(), RobotArmEnum.Upper));
  634. }
  635. if (SC.ContainsItem($"Robot.{Name}.LowerCheckWaferCmdNO") &&
  636. SC.GetValue<int>($"Robot.{Name}.UpperCheckWaferCmdNO") != 0)
  637. {
  638. compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.LowerCheckWaferCmdNO");
  639. _lstMonitorHandler.AddLast(new JelRobotCheckWaferCommandHandler(this, compaundcmdNO.ToString(), RobotArmEnum.Lower));
  640. }
  641. //_lstMonitorHandler.AddLast(new JelRobotMoveHandler(this, "SPA"));
  642. }
  643. return true;
  644. }
  645. private List<Tuple<float,float>[]> GetForbidHomeArea()
  646. {
  647. List<Tuple<float, float>[]> retValue = new List<Tuple<float, float>[]>();
  648. int i = 0;
  649. while(SC.ContainsItem($"Robot.{RobotModuleName}.ForbidHomeArea{++i}"))
  650. {
  651. string[] strData = SC.GetStringValue($"Robot.{RobotModuleName}.ForbidHomeArea{i}").Split('|');
  652. if (strData.Length < 3) continue;
  653. List<Tuple<float, float>> sValue = new List<Tuple<float, float>>();
  654. bool datavalid = true;
  655. foreach(var sdata in strData)
  656. {
  657. string[] strDatas1 = sdata.Split(',');
  658. if (strDatas1.Length < 2)
  659. {
  660. datavalid = false;
  661. break;
  662. }
  663. if(!float.TryParse(strDatas1[0],out float lowlimit))
  664. {
  665. datavalid = false;
  666. break;
  667. }
  668. if (!float.TryParse(strDatas1[1], out float highlimit))
  669. {
  670. datavalid = false;
  671. break;
  672. }
  673. sValue.Add(new Tuple<float, float>(lowlimit, highlimit));
  674. }
  675. if (!datavalid) continue;
  676. retValue.Add(sValue.ToArray());
  677. }
  678. return retValue;
  679. }
  680. protected override bool fMonitorInit(object[] param)
  681. {
  682. IsBusy = false;
  683. if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(RobotCommandTimeout))
  684. {
  685. HandlerError("InitTimeout");
  686. return true;
  687. }
  688. if (!_connection.IsBusy && _lstMonitorHandler.Count ==0)
  689. {
  690. if (CurrentCompoundCommandStatus == JelCommandStatus.InError)
  691. {
  692. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "GER"));
  693. OnError("Init Compaund Comand execution failed");
  694. }
  695. Blade1Target = ModuleName.System;
  696. Blade2Target = ModuleName.System;
  697. CmdTarget = ModuleName.System;
  698. MoveInfo = new RobotMoveInfo()
  699. {
  700. Action = RobotAction.Moving,
  701. ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
  702. BladeTarget = BuildBladeTarget(),
  703. };
  704. IsBusy = false;
  705. EV.PostInfoLog("Robot", $"{RobotModuleName} init complete");
  706. return true;
  707. }
  708. return false;
  709. }
  710. protected override bool fStartReadData(object[] param)
  711. {
  712. _dtActionStart = DateTime.Now;
  713. if(param.Length <1) return false;
  714. string readcommand = param[0].ToString();
  715. switch(readcommand)
  716. {
  717. case "CurrentStatus":
  718. lock (_locker)
  719. {
  720. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, ""));
  721. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "CS", "1"));
  722. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "CS", "2"));
  723. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "G"));
  724. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "BC"));
  725. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WCP"));
  726. }
  727. break;
  728. case "CurrentPositionData":
  729. lock(_locker)
  730. {
  731. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "6M", "1"));
  732. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "6M", "2"));
  733. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "6M", "3"));
  734. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "6M", "4"));
  735. }
  736. break;
  737. case "CompaundCommand":
  738. if (param.Length < 3) return false;
  739. string routineselction = param[1].ToString();
  740. if(routineselction == "MainRoutine")
  741. {
  742. int routineno;
  743. if (!int.TryParse(param[2].ToString(), out routineno)) return false;
  744. if (routineno > 319 || routineno < 1) return false;
  745. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "IR",routineno.ToString().PadLeft(3,'0')));
  746. }
  747. if (routineselction == "SubRoutine")
  748. {
  749. char routineno;
  750. if (!char.TryParse(param[2].ToString(), out routineno)) return false;
  751. if (routineno > 'F' || routineno < 1) return false;
  752. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "IRS", routineno.ToString()));
  753. }
  754. break;
  755. case "RobotSpeed":
  756. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "SPA"));
  757. break;
  758. case "AData":
  759. if (param.Length < 2) return false;
  760. int datano;
  761. if (!int.TryParse(param[1].ToString(), out datano)) return false;
  762. if (datano < 0 || datano > 999) return false;
  763. lock(_locker)
  764. {
  765. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "A", datano.ToString("D3")+"D"));
  766. }
  767. break;
  768. case "EPData":
  769. if (param.Length < 2) return false;
  770. if (param[1].ToString() == "AData")
  771. {
  772. lock (_locker)
  773. {
  774. _lstMonitorHandler.AddLast(new JelRobotRawCommandHandler (this, $"${BodyNumber}AL"));
  775. }
  776. }
  777. break;
  778. case "PositionData":
  779. if (param.Length < 2) return false;
  780. int posNO;
  781. if (!int.TryParse(param[1].ToString(), out posNO)) return false;
  782. if (posNO > 999 || posNO < 0) return false;
  783. lock (_locker)
  784. {
  785. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "PSD", posNO.ToString("D3")));
  786. }
  787. break;
  788. case "RobotParameter":
  789. if (param.Length < 2) return false;
  790. uint parano;
  791. if(!uint.TryParse(param[1].ToString(), out parano)) return false;
  792. lock(_locker)
  793. {
  794. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "DTD", parano.ToString()));
  795. }
  796. break;
  797. case "MappingData":
  798. lock(_locker)
  799. {
  800. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WLO"));
  801. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WHI"));
  802. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WFC"));
  803. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WWN"));
  804. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WWM"));
  805. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WWG"));
  806. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WEND"));
  807. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WSP"));
  808. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WFK"));
  809. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WFW"));
  810. }
  811. break;
  812. }
  813. return true;
  814. }
  815. protected override bool fMonitorReadData(object[] param)
  816. {
  817. IsBusy = false;
  818. if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(RobotCommandTimeout))
  819. {
  820. HandlerError("ReadDataTimeout");
  821. return true;
  822. }
  823. if (_lstMonitorHandler.Count == 0 && !_connection.IsBusy)
  824. {
  825. IsBusy = false;
  826. return true;
  827. }
  828. return false;
  829. }
  830. protected override bool fStartSetParameters(object[] param)
  831. {
  832. try
  833. {
  834. string setcommand = param[0].ToString();
  835. switch (setcommand)
  836. {
  837. case "CompaundCommand":
  838. if (param.Length < 4) return false;
  839. string routineselction = param[1].ToString();
  840. if (routineselction == "MainRoutine")
  841. {
  842. int routineno;
  843. if (!int.TryParse(param[2].ToString(), out routineno)) return false;
  844. if (routineno > 319 || routineno < 1) return false;
  845. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "I", routineno.ToString().PadLeft(3, '0')));
  846. _lstMonitorHandler.AddLast(new JelRobotRawCommandHandler(this, param[3].ToString()));
  847. }
  848. if (routineselction == "SubRoutine")
  849. {
  850. char routineno;
  851. if (!char.TryParse(param[2].ToString(), out routineno)) return false;
  852. if (routineno > 'F' || routineno < 1) return false;
  853. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "IS", routineno.ToString()));
  854. _lstMonitorHandler.AddLast(new JelRobotRawCommandHandler(this, param[3].ToString()));
  855. }
  856. break;
  857. case "RobotSpeed":
  858. Int32 speedvalue;
  859. if (!Int32.TryParse(param[2].ToString(), out speedvalue)) return false;
  860. if (SC.ContainsItem($"Robot.{RobotModuleName}.RobotSpeed"))
  861. {
  862. SC.SetItemValue($"Robot.{RobotModuleName}.RobotSpeed", speedvalue);
  863. }
  864. if (speedvalue < 0)
  865. speedvalue = 0;
  866. if (speedvalue > 9)
  867. speedvalue = 9;
  868. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "SPA", speedvalue.ToString()));
  869. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "SPA"));
  870. break;
  871. case "AData":
  872. if (param.Length < 3) return false;
  873. Int32 datano, datavalue;
  874. if (!Int32.TryParse(param[1].ToString(), out datano)) return false;
  875. if (!Int32.TryParse(param[2].ToString(), out datavalue)) return false;
  876. if (datano > 999 || datano < 0) return false;
  877. if (datavalue > 8388607 || datavalue < -8388608) return false;
  878. lock (_locker)
  879. {
  880. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "A", datano.ToString("D3") + datavalue.ToString()));
  881. }
  882. break;
  883. case "EPData":
  884. if (param.Length < 2) return false;
  885. if (param[1].ToString() == "AData")
  886. {
  887. lock (_locker)
  888. {
  889. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "AW"));
  890. }
  891. }
  892. break;
  893. case "PositionData":
  894. if (param.Length < 6) return false;
  895. Int32 posno, rightarmpos, thetapos, leftarmpos, zpos;
  896. if (!Int32.TryParse(param[1].ToString(), out posno)) return false;
  897. if (!Int32.TryParse(param[2].ToString(), out rightarmpos)) return false;
  898. if (!Int32.TryParse(param[3].ToString(), out thetapos)) return false;
  899. if (!Int32.TryParse(param[4].ToString(), out leftarmpos)) return false;
  900. if (!Int32.TryParse(param[5].ToString(), out zpos)) return false;
  901. if (posno > 999 || posno < 0) return false;
  902. lock (_locker)
  903. {
  904. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "PS",
  905. $"{posno.ToString("D3")}{rightarmpos},{thetapos},{leftarmpos},{zpos}"));
  906. }
  907. return true;
  908. case "CurrentPositionData":
  909. Int32 currentpos = Int32.Parse(param[1].ToString());
  910. if (currentpos > 999 || currentpos < 0) return false;
  911. lock (_locker)
  912. {
  913. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "PS",
  914. $"{currentpos.ToString("D3")}"));
  915. }
  916. break;
  917. case "RobotParameter":
  918. if (param.Length < 3) return false;
  919. Int32 parano, paravalue;
  920. if (!Int32.TryParse(param[1].ToString(), out parano)) return false;
  921. if (!Int32.TryParse(param[2].ToString(), out paravalue)) return false;
  922. lock (_locker)
  923. {
  924. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "DTSVAL", $"{parano},{paravalue}"));
  925. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "DW"));
  926. }
  927. break;
  928. case "MappingData":
  929. lock(_locker)
  930. {
  931. if (!string.IsNullOrEmpty(param[1].ToString()))
  932. {
  933. float tempvalue = float.Parse(param[1].ToString());
  934. string strtempvalue;
  935. if (tempvalue <0)
  936. {
  937. strtempvalue = "-" +(-tempvalue).ToString().PadLeft(7, '0');
  938. }
  939. else
  940. strtempvalue = tempvalue.ToString().PadLeft(8, '0');
  941. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WLO",strtempvalue));
  942. }
  943. if (!string.IsNullOrEmpty(param[2].ToString()))
  944. {
  945. float tempvalue = float.Parse(param[2].ToString());
  946. string strtempvalue;
  947. if (tempvalue < 0)
  948. {
  949. strtempvalue = "-" + (-tempvalue).ToString().PadLeft(7, '0');
  950. }
  951. else
  952. strtempvalue = tempvalue.ToString().PadLeft(8, '0');
  953. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WHI",strtempvalue));
  954. }
  955. if (!string.IsNullOrEmpty(param[3].ToString()))
  956. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WFC",
  957. (Convert.ToInt16(param[3].ToString()).ToString("D2"))));
  958. if (!string.IsNullOrEmpty(param[4].ToString()))
  959. {
  960. float tempvalue = float.Parse(param[4].ToString());
  961. string strtempvalue;
  962. if (tempvalue < 0)
  963. {
  964. strtempvalue = "-" + (-tempvalue).ToString().PadLeft(7, '0');
  965. }
  966. else
  967. strtempvalue = tempvalue.ToString().PadLeft(8, '0');
  968. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WWN", strtempvalue));
  969. }
  970. if (!string.IsNullOrEmpty(param[5].ToString()))
  971. {
  972. float tempvalue = float.Parse(param[5].ToString());
  973. string strtempvalue;
  974. if (tempvalue < 0)
  975. {
  976. strtempvalue = "-" + (-tempvalue).ToString().PadLeft(7, '0');
  977. }
  978. else
  979. strtempvalue = tempvalue.ToString().PadLeft(8, '0');
  980. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WWM", strtempvalue));
  981. }
  982. if (!string.IsNullOrEmpty(param[6].ToString()))
  983. {
  984. float tempvalue = float.Parse(param[6].ToString());
  985. string strtempvalue;
  986. if (tempvalue < 0)
  987. {
  988. strtempvalue = "-" + (-tempvalue).ToString().PadLeft(7, '0');
  989. }
  990. else
  991. strtempvalue = tempvalue.ToString().PadLeft(8, '0');
  992. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WWG", strtempvalue));
  993. }
  994. if (!string.IsNullOrEmpty(param[7].ToString()))
  995. {
  996. float tempvalue = float.Parse(param[7].ToString());
  997. string strtempvalue;
  998. if (tempvalue < 0)
  999. {
  1000. strtempvalue = "-" + (-tempvalue).ToString().PadLeft(7, '0');
  1001. }
  1002. else
  1003. strtempvalue = tempvalue.ToString().PadLeft(8, '0');
  1004. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WEND", strtempvalue));
  1005. }
  1006. if (!string.IsNullOrEmpty(param[8].ToString()))
  1007. {
  1008. float tempvalue = float.Parse(param[8].ToString());
  1009. string strtempvalue;
  1010. if (tempvalue < 0)
  1011. {
  1012. strtempvalue = "-" + (-tempvalue).ToString().PadLeft(7, '0');
  1013. }
  1014. else
  1015. strtempvalue = tempvalue.ToString().PadLeft(8, '0');
  1016. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WSP", strtempvalue));
  1017. }
  1018. }
  1019. break;
  1020. case "MappingCommand":
  1021. lock(_locker)
  1022. {
  1023. _lstMonitorHandler.AddLast(new JelRobotMoveHandler(this, "WFS"));
  1024. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WFK"));
  1025. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WFW"));
  1026. }
  1027. break;
  1028. case "BankNumber":
  1029. lock (_locker)
  1030. {
  1031. if (param.Length > 1 && !string.IsNullOrEmpty(param[1].ToString()))
  1032. {
  1033. int bankno = Convert.ToInt16(param[1].ToString());
  1034. if (bankno <= 15 && bankno >= 0)
  1035. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "BC", bankno.ToString("X")));
  1036. }
  1037. if (param.Length > 2 && !string.IsNullOrEmpty(param[2].ToString()))
  1038. {
  1039. int cassetteno = Convert.ToInt16(param[2].ToString());
  1040. if (cassetteno <=5 && cassetteno <= 1)
  1041. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCP", cassetteno.ToString()));
  1042. }
  1043. if (param.Length > 3 && !string.IsNullOrEmpty(param[3].ToString()))
  1044. {
  1045. int slotno = Convert.ToInt16(param[3].ToString());
  1046. if (slotno <= 25 && slotno >= 1)
  1047. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCD", slotno.ToString()));
  1048. }
  1049. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "BC"));
  1050. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WCP"));
  1051. }
  1052. break;
  1053. }
  1054. }
  1055. catch (Exception )
  1056. {
  1057. string reason = "";
  1058. if(param!=null)
  1059. {
  1060. foreach(var para in param)
  1061. {
  1062. reason += para.ToString() + ",";
  1063. }
  1064. }
  1065. EV.PostAlarmLog(Name, "Set command parameter valid:" + reason);
  1066. return false;
  1067. }
  1068. return true;
  1069. }
  1070. protected override bool fMonitorSetParamter(object[] param)
  1071. {
  1072. if (_lstMonitorHandler.Count == 0 && !_connection.IsBusy)
  1073. {
  1074. IsBusy = false;
  1075. return true;
  1076. }
  1077. return base.fMonitorSetParamter(param);
  1078. }
  1079. public override bool IsReady()
  1080. {
  1081. return RobotState == RobotStateEnum.Idle && !IsBusy;
  1082. }
  1083. protected override bool fClear(object[] param)
  1084. {
  1085. return true;
  1086. }
  1087. protected override bool fStartTransferWafer(object[] param)
  1088. {
  1089. return true;
  1090. }
  1091. protected override bool fStartUnGrip(object[] param)
  1092. {
  1093. if (param == null || param.Length < 1) return false;
  1094. RobotArmEnum arm = (RobotArmEnum)((int)param[0]);
  1095. lock (_locker)
  1096. {
  1097. if (arm == RobotArmEnum.Lower)
  1098. {
  1099. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "DS", "20"));
  1100. }
  1101. if (arm == RobotArmEnum.Upper)
  1102. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "DS", "10"));
  1103. if (arm == RobotArmEnum.Both)
  1104. {
  1105. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "DS", "20"));
  1106. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "DS", "10"));
  1107. }
  1108. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "CS", "1"));
  1109. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "CS", "2"));
  1110. }
  1111. return true;
  1112. }
  1113. protected override bool fMonitorUnGrip(object[] param)
  1114. {
  1115. if (_lstMonitorHandler.Count == 0 && !_connection.IsBusy)
  1116. {
  1117. RobotArmEnum arm = (RobotArmEnum)((int)CurrentParamter[0]);
  1118. if (arm == RobotArmEnum.Lower && IsLeftArmPressureSensorON)
  1119. {
  1120. OnError("Grip wafer failed!");
  1121. }
  1122. if (arm == RobotArmEnum.Upper && IsRightArmPressureSensorON)
  1123. {
  1124. OnError("Grip wafer failed!");
  1125. }
  1126. if (arm == RobotArmEnum.Both && ((IsRightArmPressureSensorON) || IsLeftArmPressureSensorON))
  1127. OnError("Grip wafer failed!");
  1128. IsBusy = false;
  1129. return true;
  1130. }
  1131. return false;
  1132. }
  1133. protected override bool fStartGrip(object[] param)
  1134. {
  1135. if(param == null || param.Length <1) return false;
  1136. RobotArmEnum arm = (RobotArmEnum)((int)param[0]);
  1137. lock (_locker)
  1138. {
  1139. if (arm == RobotArmEnum.Lower)
  1140. {
  1141. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "DS", "21"));
  1142. }
  1143. if(arm == RobotArmEnum.Upper)
  1144. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "DS", "11"));
  1145. if(arm == RobotArmEnum.Both)
  1146. {
  1147. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "DS", "21"));
  1148. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "DS", "11"));
  1149. }
  1150. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "CS", "1"));
  1151. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "CS", "2"));
  1152. }
  1153. _dtActionStart = DateTime.Now;
  1154. return true;
  1155. }
  1156. protected override bool fMonitorGrip(object[] param)
  1157. {
  1158. IsBusy = false;
  1159. if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(RobotCommandTimeout))
  1160. {
  1161. HandlerError("GripTimeout");
  1162. return true;
  1163. }
  1164. if (_lstMonitorHandler.Count == 0 && !_connection.IsBusy)
  1165. {
  1166. RobotArmEnum arm = (RobotArmEnum)((int)CurrentParamter[0]);
  1167. if (arm == RobotArmEnum.Lower && !IsLeftArmPressureSensorON)
  1168. {
  1169. OnError("Grip wafer failed!");
  1170. }
  1171. if (arm == RobotArmEnum.Upper && !IsRightArmPressureSensorON)
  1172. {
  1173. OnError("Grip wafer failed!");
  1174. }
  1175. if(arm == RobotArmEnum.Both &&((!IsRightArmPressureSensorON) || !IsLeftArmPressureSensorON))
  1176. OnError("Grip wafer failed!");
  1177. IsBusy = false;
  1178. return true;
  1179. }
  1180. return false;
  1181. }
  1182. protected override bool fStop(object[] param)
  1183. {
  1184. _lstMonitorHandler.Clear();
  1185. _connection.ForceClear();
  1186. _connection.Execute(new JelRobotSetHandler(this, "S"));
  1187. return ReadStatus();
  1188. }
  1189. protected override bool fStartGoTo(object[] param)
  1190. {
  1191. try
  1192. {
  1193. _dtActionStart = DateTime.Now;
  1194. RobotArmEnum arm = (RobotArmEnum)param[0];
  1195. ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), param[1].ToString());
  1196. BladeTarget = tempmodule;
  1197. Blade1Target = tempmodule;
  1198. Blade2Target = tempmodule;
  1199. int slot = (int)param[2] + 1;
  1200. RobotPostionEnum postype = (RobotPostionEnum)param[3];
  1201. var wz = WaferManager.Instance.GetWaferSize(RobotModuleName, (int)arm);
  1202. if (ModuleHelper.IsLoadPort(tempmodule))
  1203. {
  1204. var lp = DEVICE.GetDevice<LoadPortBaseDevice>(tempmodule.ToString());
  1205. if (lp != null) lp.NoteTransferStart();
  1206. }
  1207. int bankno;
  1208. int cassetteNO;
  1209. if(!GetBankAndCassetteNumber(tempmodule,wz,out bankno,out cassetteNO))
  1210. {
  1211. EV.PostAlarmLog("Robot", $"{RobotModuleName} can't find the bankno or cassette no for {tempmodule}");
  1212. OnError($"Can't find the bankno or cassette no for {tempmodule}");
  1213. return false;
  1214. }
  1215. int compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.{arm}Goto{postype}CmdNO");
  1216. int compaundcmdNOforSafe = SC.GetValue<int>($"Robot.{Name}.SafeCmdNO");
  1217. lock (_locker)
  1218. {
  1219. if (ResetBeforeCmd)
  1220. _lstMonitorHandler.AddLast(new JelRobotRawCommandHandler(this, $"RD"));
  1221. if (GotoSafePositionBeforeCmd && (ReadBankNumber != bankno.ToString("X") || cassetteNO != ReadCassetNumber))
  1222. {
  1223. _lstMonitorHandler.AddLast(new JelRobotCompaundCommandHandler(this, compaundcmdNOforSafe.ToString()));
  1224. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "G"));
  1225. }
  1226. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "BC", bankno.ToString("X")));
  1227. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCP", cassetteNO.ToString()));
  1228. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCD", slot.ToString()));
  1229. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "BC"));
  1230. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WCP"));
  1231. _lstMonitorHandler.AddLast(new JelRobotCompaundCommandHandler(this, compaundcmdNO.ToString()));
  1232. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "G"));
  1233. }
  1234. Blade1Target = tempmodule;
  1235. Blade2Target = tempmodule;
  1236. CmdTarget = tempmodule;
  1237. MoveInfo = new RobotMoveInfo()
  1238. {
  1239. Action = RobotAction.Picking,
  1240. ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
  1241. BladeTarget = BuildBladeTarget(),
  1242. };
  1243. return true;
  1244. }
  1245. catch (Exception ex)
  1246. {
  1247. IsBusy = false;
  1248. LOG.Write(ex);
  1249. return false;
  1250. }
  1251. }
  1252. protected override bool fMonitorGoTo(object[] param)
  1253. {
  1254. IsBusy = false;
  1255. if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(RobotCommandTimeout))
  1256. {
  1257. OnError("Robot Goto timeout");
  1258. return true;
  1259. }
  1260. if (_lstMonitorHandler.Count == 0 && !_connection.IsBusy)
  1261. {
  1262. if (CurrentCompoundCommandStatus == JelCommandStatus.NormalEnd)
  1263. {
  1264. RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
  1265. ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[1].ToString());
  1266. ModuleName sourcemodule = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[1].ToString());
  1267. int SourceslotIndex = (int)CurrentParamter[2];
  1268. RobotPostionEnum postype = (RobotPostionEnum)CurrentParamter[3];
  1269. //bool isFromOriginal = (bool)CurrentParamter[8];
  1270. //bool isJumpToNextMotion = (bool)CurrentParamter[9];
  1271. switch (postype)
  1272. {
  1273. case RobotPostionEnum.PickExtendUp:
  1274. case RobotPostionEnum.PickRetracted:
  1275. if (arm == RobotArmEnum.Lower)
  1276. {
  1277. WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 0);
  1278. //if (isSimulatorMode || GetWaferState(arm) == RobotArmWaferStateEnum.Present)
  1279. // WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 0);
  1280. //else
  1281. // OnError("Wafer detect error");
  1282. }
  1283. if (arm == RobotArmEnum.Upper)
  1284. {
  1285. WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 1);
  1286. //if (isSimulatorMode || GetWaferState(arm) == RobotArmWaferStateEnum.Present)
  1287. // WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 1);
  1288. //else
  1289. // OnError("Wafer detect error");
  1290. }
  1291. if (arm == RobotArmEnum.Both)
  1292. {
  1293. WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 0);
  1294. WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 1);
  1295. //if (isSimulatorMode || GetWaferState(arm) == RobotArmWaferStateEnum.Present)
  1296. //{
  1297. // WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 0);
  1298. // WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 1);
  1299. //}
  1300. //else
  1301. // OnError("Wafer detect error");
  1302. }
  1303. break;
  1304. case RobotPostionEnum.PlaceExtendDown:
  1305. case RobotPostionEnum.PlaceRetract:
  1306. if (arm == RobotArmEnum.Lower)
  1307. {
  1308. WaferManager.Instance.WaferMoved(RobotModuleName, 0, sourcemodule, SourceslotIndex);
  1309. //if (isSimulatorMode || GetWaferState(arm) == RobotArmWaferStateEnum.Absent)
  1310. // WaferManager.Instance.WaferMoved(RobotModuleName, 0, sourcemodule, SourceslotIndex);
  1311. //else
  1312. // OnError("Wafer detect error");
  1313. }
  1314. if (arm == RobotArmEnum.Upper)
  1315. {
  1316. WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, SourceslotIndex);
  1317. //if (isSimulatorMode || GetWaferState(arm) == RobotArmWaferStateEnum.Absent)
  1318. // WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, SourceslotIndex);
  1319. //else
  1320. // OnError("Wafer detect error");
  1321. }
  1322. if (arm == RobotArmEnum.Both)
  1323. {
  1324. WaferManager.Instance.WaferMoved(RobotModuleName, 0, sourcemodule, SourceslotIndex);
  1325. WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, SourceslotIndex);
  1326. //if (isSimulatorMode || GetWaferState(arm) == RobotArmWaferStateEnum.Absent)
  1327. //{
  1328. // WaferManager.Instance.WaferMoved(RobotModuleName, 0, sourcemodule, SourceslotIndex);
  1329. // WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, SourceslotIndex);
  1330. //}
  1331. //else
  1332. // OnError("Wafer detect error");
  1333. }
  1334. break;
  1335. }
  1336. BladeTarget = ModuleName.System;
  1337. Blade1Target = ModuleName.System;
  1338. Blade2Target = ModuleName.System;
  1339. CmdTarget = ModuleName.System;
  1340. MoveInfo = new RobotMoveInfo()
  1341. {
  1342. Action = RobotAction.Moving,
  1343. ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
  1344. BladeTarget = BuildBladeTarget(),
  1345. };
  1346. if (ModuleHelper.IsLoadPort(tempmodule))
  1347. {
  1348. var lp = DEVICE.GetDevice<LoadPortBaseDevice>(tempmodule.ToString());
  1349. if (lp != null) lp.NoteTransferStop();
  1350. }
  1351. return true;
  1352. }
  1353. if (CurrentCompoundCommandStatus == JelCommandStatus.InError)
  1354. {
  1355. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "GER"));
  1356. HandlerError("GoToFailed");
  1357. }
  1358. }
  1359. return false;
  1360. }
  1361. protected override bool fStartMapWafer(object[] param)
  1362. {
  1363. try
  1364. {
  1365. _dtActionStart = DateTime.Now;
  1366. ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), param[0].ToString());
  1367. if(ModuleHelper.IsLoadPort(tempmodule))
  1368. {
  1369. var lp = DEVICE.GetDevice<LoadPortBaseDevice>(tempmodule.ToString());
  1370. if (lp != null) lp.NoteTransferStart();
  1371. }
  1372. WaferSize wz = WaferManager.Instance.GetWaferSize(tempmodule, 0);
  1373. int bankno;
  1374. int cassetteNO;
  1375. if (!GetBankAndCassetteNumber(tempmodule, wz, out bankno, out cassetteNO))
  1376. {
  1377. EV.PostAlarmLog("Robot", $"{RobotModuleName} can't find the bankno or cassette no for {tempmodule}");
  1378. OnError($"Can't find the bankno or cassette no for {tempmodule}");
  1379. return false;
  1380. }
  1381. int compaundcmdNO = -1;
  1382. if(SC.ContainsItem($"Robot.{Name}.MapCmdNO"))
  1383. {
  1384. compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.MapCmdNO");
  1385. }
  1386. else if(SC.ContainsItem($"Robot.{Name}.{tempmodule}MapCmdNO"))
  1387. {
  1388. compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.{tempmodule}MapCmdNO");
  1389. }
  1390. else
  1391. {
  1392. EV.PostAlarmLog("Robot", $"{RobotModuleName} can't find the map command for {tempmodule}");
  1393. return false;
  1394. }
  1395. lock (_locker)
  1396. {
  1397. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "BC", bankno.ToString("X")));
  1398. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCP", cassetteNO.ToString()));
  1399. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "BC"));
  1400. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WCP"));
  1401. _lstMonitorHandler.AddLast(new JelRobotCompaundCommandHandler(this, compaundcmdNO.ToString()));
  1402. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, ""));
  1403. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WFK"));
  1404. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WFW"));
  1405. }
  1406. }
  1407. catch (Exception ex)
  1408. {
  1409. string reason = "";
  1410. if (param != null)
  1411. foreach (var strpara in param)
  1412. reason += strpara.ToString();
  1413. OnError($"{Name} Map command valid:" + reason);
  1414. LOG.Write(ex);
  1415. return false;
  1416. }
  1417. return true;
  1418. }
  1419. protected override bool fMonitorMap(object[] param)
  1420. {
  1421. IsBusy = false;
  1422. if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(RobotCommandTimeout))
  1423. {
  1424. HandlerError("MapTimeout");
  1425. return true;
  1426. }
  1427. if (_lstMonitorHandler.Count == 0 && !_connection.IsBusy)
  1428. {
  1429. ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[0].ToString());
  1430. if (ModuleHelper.IsLoadPort(tempmodule))
  1431. {
  1432. var lp = DEVICE.GetDevice<LoadPortBaseDevice>(tempmodule.ToString());
  1433. if (lp != null) lp.NoteTransferStop();
  1434. }
  1435. IsBusy = false;
  1436. return true;
  1437. }
  1438. return false;
  1439. }
  1440. private bool IsSupportSwapCmd
  1441. {
  1442. get
  1443. {
  1444. if (SC.ContainsItem($"Robot.{Name}.IsSupportSwapCmd"))
  1445. return SC.GetValue<bool>($"Robot.{Name}.IsSupportSwapCmd");
  1446. return true;
  1447. }
  1448. }
  1449. protected override bool fStartSwapWafer(object[] param)
  1450. {
  1451. try
  1452. {
  1453. _dtActionStart = DateTime.Now;
  1454. RobotArmEnum arm = (RobotArmEnum)param[0];
  1455. ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), param[1].ToString());
  1456. int slotindex = int.Parse(param[2].ToString());
  1457. JelRobotArm jelarm = (JelRobotArm)(int)arm;
  1458. var wz = WaferManager.Instance.GetWaferSize(RobotModuleName, arm == RobotArmEnum.Both ? 0 : (int)arm);
  1459. if (ModuleHelper.IsLoadPort(tempmodule))
  1460. {
  1461. var lp = DEVICE.GetDevice<LoadPortBaseDevice>(tempmodule.ToString());
  1462. if (lp != null)
  1463. lp.NoteTransferStart();
  1464. }
  1465. int bankno;
  1466. int cassetteNO;
  1467. if (!GetBankAndCassetteNumber(tempmodule, wz, out bankno, out cassetteNO))
  1468. {
  1469. EV.PostAlarmLog("Robot", $"{RobotModuleName} can't find the bankno or cassette no for {tempmodule}");
  1470. OnError($"Can't find the bankno or cassette no for {tempmodule}");
  1471. return false;
  1472. }
  1473. if(IsSupportSwapCmd)
  1474. {
  1475. int compaundcmdNO = -1;
  1476. if (SC.ContainsItem($"Robot.{Name}.{jelarm}PickSwapCmdNO"))
  1477. {
  1478. compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.{jelarm}PickSwapCmdNO");
  1479. }
  1480. else if (SC.ContainsItem($"Robot.{Name}.{arm}PickSwapCmdNO"))
  1481. {
  1482. compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.{arm}PickSwapCmdNO");
  1483. }
  1484. else
  1485. {
  1486. EV.PostAlarmLog("Robot", $"Can't find the compaund command for swap");
  1487. OnError("CompaundCommandError");
  1488. return false;
  1489. }
  1490. lock (_locker)
  1491. {
  1492. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "BC", bankno.ToString("X")));
  1493. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCP", cassetteNO.ToString()));
  1494. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCD", (slotindex + 1).ToString()));
  1495. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "BC"));
  1496. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WCP"));
  1497. _lstMonitorHandler.AddLast(new JelRobotCompaundCommandHandler(this, compaundcmdNO.ToString()));
  1498. }
  1499. }
  1500. else
  1501. {
  1502. int pickCmdNO = -1;
  1503. if (SC.ContainsItem($"Robot.{Name}.{arm}PickCmdNO"))
  1504. {
  1505. pickCmdNO = SC.GetValue<int>($"Robot.{Name}.{arm}PickCmdNO");
  1506. }
  1507. else
  1508. {
  1509. EV.PostAlarmLog("Robot", $"Can't find the compaund command for pick");
  1510. OnError("CompaundCommandError");
  1511. return false;
  1512. }
  1513. int placeCmdNO =-1;
  1514. RobotArmEnum placeArm = RobotArmEnum.Lower;
  1515. if (arm == RobotArmEnum.Lower)
  1516. placeArm = RobotArmEnum.Upper;
  1517. if (SC.ContainsItem($"Robot.{Name}.{placeArm}PlaceCmdNO"))
  1518. {
  1519. placeCmdNO = SC.GetValue<int>($"Robot.{Name}.{placeArm}PlaceCmdNO");
  1520. }
  1521. else
  1522. {
  1523. EV.PostAlarmLog("Robot", $"Can't find the compaund command for pick");
  1524. OnError("CompaundCommandError");
  1525. return false;
  1526. }
  1527. lock (_locker)
  1528. {
  1529. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "BC", bankno.ToString("X")));
  1530. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCP", cassetteNO.ToString()));
  1531. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCD", (slotindex + 1).ToString()));
  1532. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "BC"));
  1533. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WCP"));
  1534. _lstMonitorHandler.AddLast(new JelRobotCompaundCommandHandler(this, pickCmdNO.ToString()));
  1535. _lstMonitorHandler.AddLast(new JelRobotCompaundCommandHandler(this, placeCmdNO.ToString()));
  1536. }
  1537. }
  1538. Blade1Target = tempmodule;
  1539. Blade2Target = tempmodule;
  1540. CmdTarget = tempmodule;
  1541. MoveInfo = new RobotMoveInfo()
  1542. {
  1543. Action = RobotAction.Moving,
  1544. ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
  1545. BladeTarget = BuildBladeTarget(),
  1546. };
  1547. }
  1548. catch (Exception ex)
  1549. {
  1550. string reason = "";
  1551. if (param != null)
  1552. foreach (var strpara in param)
  1553. reason += strpara.ToString();
  1554. OnError($"{Name} Swap command valid:" + reason);
  1555. LOG.Write(ex);
  1556. return false;
  1557. }
  1558. return true;
  1559. }
  1560. protected override bool fMonitorSwap(object[] param)
  1561. {
  1562. IsBusy = false;
  1563. if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(RobotCommandTimeout))
  1564. {
  1565. HandlerError("SwapTimeout");
  1566. return true;
  1567. }
  1568. if (_lstMonitorHandler.Count == 0 && !_connection.IsBusy)
  1569. {
  1570. if (CurrentCompoundCommandStatus == JelCommandStatus.InError)
  1571. {
  1572. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "GER"));
  1573. OnError("Compaund Comand execution failed");
  1574. }
  1575. RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
  1576. ModuleName sourcemodule;
  1577. if (!Enum.TryParse(CurrentParamter[1].ToString(), out sourcemodule)) return false;
  1578. int Sourceslotindex;
  1579. if (!int.TryParse(CurrentParamter[2].ToString(), out Sourceslotindex)) return false;
  1580. if (arm == RobotArmEnum.Lower)
  1581. {
  1582. WaferManager.Instance.WaferMoved(sourcemodule, Sourceslotindex, RobotModuleName, 0);
  1583. WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, Sourceslotindex);
  1584. }
  1585. if (arm == RobotArmEnum.Upper)
  1586. {
  1587. WaferManager.Instance.WaferMoved(sourcemodule, Sourceslotindex, RobotModuleName, 1);
  1588. WaferManager.Instance.WaferMoved(RobotModuleName, 0, sourcemodule, Sourceslotindex);
  1589. }
  1590. if (arm == RobotArmEnum.Both)
  1591. {
  1592. }
  1593. Blade1Target = ModuleName.System;
  1594. Blade2Target = ModuleName.System;
  1595. CmdTarget = ModuleName.System;
  1596. MoveInfo = new RobotMoveInfo()
  1597. {
  1598. Action = RobotAction.Moving,
  1599. ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
  1600. BladeTarget = BuildBladeTarget(),
  1601. };
  1602. ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[1].ToString());
  1603. if (ModuleHelper.IsLoadPort(tempmodule))
  1604. {
  1605. var lp = DEVICE.GetDevice<LoadPortBaseDevice>(tempmodule.ToString());
  1606. if (lp != null) lp.NoteTransferStop();
  1607. }
  1608. IsBusy = false;
  1609. return true;
  1610. }
  1611. return false;
  1612. }
  1613. protected override bool fStartPlaceWafer(object[] param)
  1614. {
  1615. try
  1616. {
  1617. _dtActionStart = DateTime.Now;
  1618. RobotArmEnum arm = (RobotArmEnum)param[0];
  1619. ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), param[1].ToString());
  1620. int slotindex = int.Parse(param[2].ToString());
  1621. JelRobotArm jelarm = (JelRobotArm)(int)arm;
  1622. var wz = WaferManager.Instance.GetWaferSize(RobotModuleName, arm == RobotArmEnum.Both ? 0 : (int)arm);
  1623. if (ModuleHelper.IsLoadPort(tempmodule))
  1624. {
  1625. var lp = DEVICE.GetDevice<LoadPortBaseDevice>(tempmodule.ToString());
  1626. if (lp != null)
  1627. lp.NoteTransferStart();
  1628. }
  1629. int bankno;
  1630. int cassetteNO;
  1631. if (!GetBankAndCassetteNumber(tempmodule, wz, out bankno, out cassetteNO))
  1632. {
  1633. EV.PostAlarmLog("Robot", $"{RobotModuleName} can't find the bankno or cassette no for {tempmodule}");
  1634. OnError($"Can't find the bankno or cassette no for {tempmodule}");
  1635. return false;
  1636. }
  1637. int compaundcmdNO = -1;
  1638. if (SC.ContainsItem($"Robot.{Name}.{jelarm}PlaceCmdNO"))
  1639. {
  1640. compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.{jelarm}PlaceCmdNO");
  1641. }
  1642. else if (SC.ContainsItem($"Robot.{Name}.{arm}PlaceCmdNO"))
  1643. {
  1644. compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.{arm}PlaceCmdNO");
  1645. }
  1646. else
  1647. {
  1648. EV.PostAlarmLog("Robot", $"Can't find the compaund command for place");
  1649. OnError("CompaundCommandError");
  1650. return false;
  1651. }
  1652. if (SC.ContainsItem($"Robot.{Name}.{arm}PlaceAt{tempmodule}CmdNO"))
  1653. {
  1654. compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.{arm}PlaceAt{tempmodule}CmdNO");
  1655. }
  1656. if (IsOnSwap && SC.ContainsItem($"Robot.{Name}.{arm}PlaceForSwapAt{tempmodule}CmdNO"))
  1657. {
  1658. compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.{arm}PlaceForSwapAt{tempmodule}CmdNO");
  1659. }
  1660. lock (_locker)
  1661. {
  1662. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "BC", bankno.ToString("X")));
  1663. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCP", cassetteNO.ToString()));
  1664. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCD", (slotindex+1).ToString()));
  1665. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "BC"));
  1666. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WCP"));
  1667. _lstMonitorHandler.AddLast(new JelRobotCompaundCommandHandler(this, compaundcmdNO.ToString()));
  1668. }
  1669. Blade1Target = tempmodule;
  1670. Blade2Target = tempmodule;
  1671. CmdTarget = tempmodule;
  1672. MoveInfo = new RobotMoveInfo()
  1673. {
  1674. Action = RobotAction.Moving,
  1675. ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
  1676. BladeTarget = BuildBladeTarget(),
  1677. };
  1678. }
  1679. catch (Exception ex)
  1680. {
  1681. string reason = "";
  1682. if (param != null)
  1683. foreach (var strpara in param)
  1684. reason += strpara.ToString();
  1685. OnError($"{Name} Pick command valid:" + reason);
  1686. LOG.Write(ex);
  1687. return false;
  1688. }
  1689. return true;
  1690. }
  1691. protected override bool fStartPickWafer(object[] param)
  1692. {
  1693. try
  1694. {
  1695. _dtActionStart = DateTime.Now;
  1696. RobotArmEnum arm = (RobotArmEnum)param[0];
  1697. ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), param[1].ToString());
  1698. int slotindex = int.Parse(param[2].ToString());
  1699. JelRobotArm jelarm = (JelRobotArm)(int)arm;
  1700. var wz = WaferManager.Instance.GetWaferSize(tempmodule, slotindex);
  1701. if (ModuleHelper.IsLoadPort(tempmodule))
  1702. {
  1703. var lp = DEVICE.GetDevice<LoadPortBaseDevice>(tempmodule.ToString());
  1704. if (lp != null)
  1705. lp.NoteTransferStart();
  1706. }
  1707. int bankno;
  1708. int cassetteNO;
  1709. if (!GetBankAndCassetteNumber(tempmodule, wz, out bankno, out cassetteNO))
  1710. {
  1711. EV.PostAlarmLog("Robot", $"{RobotModuleName} can't find the bankno or cassette no for {tempmodule}");
  1712. OnError($"Can't find the bankno or cassette no for {tempmodule}");
  1713. return false;
  1714. }
  1715. int compaundcmdNO = -1;
  1716. if(SC.ContainsItem($"Robot.{Name}.{jelarm}PickCmdNO"))
  1717. {
  1718. compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.{jelarm}PickCmdNO");
  1719. }
  1720. else if(SC.ContainsItem($"Robot.{Name}.{arm}PickCmdNO"))
  1721. {
  1722. compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.{arm}PickCmdNO");
  1723. }
  1724. else
  1725. {
  1726. EV.PostAlarmLog("Robot", $"Can't find the compaund command for pick");
  1727. OnError("CompaundCommandError");
  1728. return false;
  1729. }
  1730. if (SC.ContainsItem($"Robot.{Name}.{arm}PickAt{tempmodule}CmdNO"))
  1731. {
  1732. compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.{arm}PickAt{tempmodule}CmdNO");
  1733. }
  1734. if(IsOnSwap && SC.ContainsItem($"Robot.{Name}.{arm}PickForSwapAt{tempmodule}CmdNO"))
  1735. {
  1736. compaundcmdNO = SC.GetValue<int>($"Robot.{Name}.{arm}PickForSwapAt{tempmodule}CmdNO");
  1737. }
  1738. lock (_locker)
  1739. {
  1740. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "BC", bankno.ToString("X")));
  1741. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCP", cassetteNO.ToString()));
  1742. _lstMonitorHandler.AddLast(new JelRobotSetHandler(this, "WCD", (slotindex+1).ToString()));
  1743. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "BC"));
  1744. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "WCP"));
  1745. _lstMonitorHandler.AddLast(new JelRobotCompaundCommandHandler(this,compaundcmdNO.ToString()));
  1746. }
  1747. Blade1Target = tempmodule;
  1748. Blade2Target = tempmodule;
  1749. CmdTarget = tempmodule;
  1750. MoveInfo = new RobotMoveInfo()
  1751. {
  1752. Action = RobotAction.Moving,
  1753. ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
  1754. BladeTarget = BuildBladeTarget(),
  1755. };
  1756. }
  1757. catch (Exception ex)
  1758. {
  1759. string reason = "";
  1760. if (param != null)
  1761. {
  1762. foreach (var strpara in param)
  1763. reason += strpara.ToString();
  1764. }
  1765. LOG.Write(ex);
  1766. OnError($"{Name} Pick command valid:" + reason);
  1767. return false;
  1768. }
  1769. return true;
  1770. }
  1771. protected override bool fMonitorPlace(object[] param)
  1772. {
  1773. IsBusy = false;
  1774. if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(RobotCommandTimeout))
  1775. {
  1776. HandlerError("PlaceTimeout");
  1777. return true;
  1778. }
  1779. if ( _lstMonitorHandler.Count == 0 && !_connection.IsBusy)
  1780. {
  1781. if (CurrentCompoundCommandStatus == JelCommandStatus.InError)
  1782. {
  1783. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "GER"));
  1784. OnError("Compaund Comand execution failed");
  1785. }
  1786. RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
  1787. ModuleName sourcemodule;
  1788. if (!Enum.TryParse(CurrentParamter[1].ToString(), out sourcemodule)) return false;
  1789. int Sourceslotindex;
  1790. if (!int.TryParse(CurrentParamter[2].ToString(), out Sourceslotindex)) return false;
  1791. if (arm == RobotArmEnum.Lower)
  1792. WaferManager.Instance.WaferMoved(RobotModuleName, 0, sourcemodule, Sourceslotindex);
  1793. if (arm == RobotArmEnum.Upper)
  1794. WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, Sourceslotindex);
  1795. if (arm == RobotArmEnum.Both)
  1796. {
  1797. WaferManager.Instance.WaferMoved(RobotModuleName, 0, sourcemodule, Sourceslotindex);
  1798. WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, Sourceslotindex);
  1799. }
  1800. Blade1Target = ModuleName.System;
  1801. Blade2Target = ModuleName.System;
  1802. CmdTarget = ModuleName.System;
  1803. MoveInfo = new RobotMoveInfo()
  1804. {
  1805. Action = RobotAction.Moving,
  1806. ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
  1807. BladeTarget = BuildBladeTarget(),
  1808. };
  1809. ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[1].ToString());
  1810. if (ModuleHelper.IsLoadPort(tempmodule))
  1811. {
  1812. var lp = DEVICE.GetDevice<LoadPortBaseDevice>(tempmodule.ToString());
  1813. if (lp != null) lp.NoteTransferStop();
  1814. }
  1815. IsBusy = false;
  1816. return true;
  1817. }
  1818. return false;
  1819. }
  1820. protected override bool fMonitorPick(object[] param)
  1821. {
  1822. IsBusy = false;
  1823. if (DateTime.Now - _dtActionStart > TimeSpan.FromSeconds(RobotCommandTimeout))
  1824. {
  1825. HandlerError("PickTimeout");
  1826. return true;
  1827. }
  1828. if (_lstMonitorHandler.Count == 0 && !_connection.IsBusy)
  1829. {
  1830. if (CurrentCompoundCommandStatus == JelCommandStatus.InError)
  1831. {
  1832. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "GER"));
  1833. OnError("Compaund Comand execution failed");
  1834. }
  1835. RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
  1836. ModuleName sourcemodule;
  1837. if (!Enum.TryParse(CurrentParamter[1].ToString(), out sourcemodule)) return false;
  1838. int SourceslotIndex;
  1839. if (!int.TryParse(CurrentParamter[2].ToString(), out SourceslotIndex)) return false;
  1840. if (arm == RobotArmEnum.Lower)
  1841. WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 0);
  1842. if (arm == RobotArmEnum.Upper)
  1843. WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 1);
  1844. if(arm == RobotArmEnum.Both)
  1845. {
  1846. WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 0);
  1847. WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 1);
  1848. }
  1849. Blade1Target = ModuleName.System;
  1850. Blade2Target = ModuleName.System;
  1851. CmdTarget = ModuleName.System;
  1852. MoveInfo = new RobotMoveInfo()
  1853. {
  1854. Action = RobotAction.Moving,
  1855. ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
  1856. BladeTarget = BuildBladeTarget(),
  1857. };
  1858. ModuleName tempmodule = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[1].ToString());
  1859. if (ModuleHelper.IsLoadPort(tempmodule))
  1860. {
  1861. var lp = DEVICE.GetDevice<LoadPortBaseDevice>(tempmodule.ToString());
  1862. if (lp != null) lp.NoteTransferStop();
  1863. }
  1864. IsBusy = false;
  1865. return true;
  1866. }
  1867. return false;
  1868. }
  1869. protected override bool fResetToReady(object[] param)
  1870. {
  1871. return true;
  1872. }
  1873. protected override bool fError(object[] param)
  1874. {
  1875. return true;
  1876. }
  1877. protected override bool fStartExtendForPick(object[] param)
  1878. {
  1879. return true;
  1880. }
  1881. protected override bool fStartExtendForPlace(object[] param)
  1882. {
  1883. return true;
  1884. }
  1885. protected override bool fStartRetractFromPick(object[] param)
  1886. {
  1887. return true;
  1888. }
  1889. protected override bool fStartRetractFromPlace(object[] param)
  1890. {
  1891. return true;
  1892. }
  1893. public override RobotArmWaferStateEnum GetWaferState(RobotArmEnum arm)
  1894. {
  1895. if (arm == RobotArmEnum.Lower)
  1896. return IsLeftArmPressureSensorON? RobotArmWaferStateEnum.Present: RobotArmWaferStateEnum.Absent;
  1897. if (arm == RobotArmEnum.Upper)
  1898. return IsRightArmPressureSensorON ? RobotArmWaferStateEnum.Present : RobotArmWaferStateEnum.Absent; ;
  1899. return RobotArmWaferStateEnum.ArmInvalid;
  1900. }
  1901. public bool ReadStatus()
  1902. {
  1903. lock(_locker)
  1904. {
  1905. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, ""));
  1906. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "CS", "1"));
  1907. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "CS", "2"));
  1908. _lstMonitorHandler.AddLast(new JelRobotReadHandler(this, "G"));
  1909. }
  1910. return true;
  1911. }
  1912. public void HandlerError(string errorMsg)
  1913. {
  1914. _lstMonitorHandler.Clear();
  1915. OnError(errorMsg);
  1916. }
  1917. protected string BuildBladeTarget()
  1918. {
  1919. return (CmdRobotArm == RobotArmEnum.Upper ? "ArmB" : "ArmA") + "." + CmdTarget;
  1920. }
  1921. public bool GetBankAndCassetteNumber(ModuleName module, WaferSize wz, out int BankNum,out int CassetteNum)
  1922. {
  1923. BankNum = 0;
  1924. CassetteNum = 0;
  1925. int wzindex = 0;
  1926. if (ModuleHelper.IsLoadPort(module))
  1927. {
  1928. var lp = DEVICE.GetDevice<LoadPortBaseDevice>(module.ToString());
  1929. if (lp != null)
  1930. {
  1931. wzindex = lp.InfoPadCarrierIndex;
  1932. }
  1933. else
  1934. {
  1935. var lp1 = DEVICE.GetDevice<LoadPort>(module.ToString());
  1936. wzindex = lp.InfoPadCarrierIndex;
  1937. }
  1938. if (SC.ContainsItem($"CarrierInfo.{module}BankNumber{wzindex}"))
  1939. BankNum = SC.GetValue<int>($"CarrierInfo.{module}BankNumber{wzindex}");
  1940. else if (SC.ContainsItem($"CarrierInfo.Carrier{wzindex}.{module}BankNumber"))
  1941. BankNum = SC.GetValue<int>($"CarrierInfo.Carrier{wzindex}.{module}BankNumber");
  1942. else
  1943. {
  1944. if(SC.ContainsItem($"CarrierInfo.Carrier{wzindex}.{module}Station"))
  1945. {
  1946. string[] stationInfo = SC.GetStringValue($"CarrierInfo.Carrier{wzindex}.{module}Station").Split('.');
  1947. if (stationInfo.Length < 2)
  1948. {
  1949. EV.PostAlarmLog("Robot", $"{RobotModuleName} parse bank number failed");
  1950. return false;
  1951. }
  1952. if (!int.TryParse(stationInfo[0], out BankNum))
  1953. {
  1954. EV.PostAlarmLog("Robot", $"{RobotModuleName} parse bank number failed");
  1955. return false;
  1956. }
  1957. if (!int.TryParse(stationInfo[1], out CassetteNum))
  1958. {
  1959. EV.PostAlarmLog("Robot", $"{RobotModuleName} parse cassette number failed");
  1960. return false;
  1961. }
  1962. return true;
  1963. }
  1964. }
  1965. if (SC.ContainsItem($"CarrierInfo.{module}CassetteNumber{wzindex}"))
  1966. CassetteNum = SC.GetValue<int>($"CarrierInfo.{module}CassetteNumber{wzindex}");
  1967. else if (SC.ContainsItem($"CarrierInfo.Carrier{wzindex}.{module}CassetteNumber"))
  1968. CassetteNum = SC.GetValue<int>($"CarrierInfo.Carrier{wzindex}.{module}CassetteNumber");
  1969. else
  1970. {
  1971. EV.PostAlarmLog("Robot", $"{RobotModuleName} parse cassette number failed");
  1972. return false;
  1973. }
  1974. return true;
  1975. }
  1976. if(ModuleHelper.IsTurnOverStation(module))
  1977. {
  1978. var flipper = DEVICE.GetDevice<FlipperBaseDevice>(module.ToString());
  1979. if (SC.ContainsItem($"CarrierInfo.{module}{flipper.CurrentFlipperPosition}Station"))
  1980. {
  1981. string[] stationInfo = SC.GetStringValue($"CarrierInfo.{module}{flipper.CurrentFlipperPosition}Station").Split('.');
  1982. if (stationInfo.Length < 2)
  1983. {
  1984. EV.PostAlarmLog("Robot", $"{RobotModuleName} parse bank number failed");
  1985. return false;
  1986. }
  1987. if (!int.TryParse(stationInfo[0], out BankNum))
  1988. {
  1989. EV.PostAlarmLog("Robot", $"{RobotModuleName} parse bank number failed");
  1990. return false;
  1991. }
  1992. if (!int.TryParse(stationInfo[1], out CassetteNum))
  1993. {
  1994. EV.PostAlarmLog("Robot", $"{RobotModuleName} parse cassette number failed");
  1995. return false;
  1996. }
  1997. return true;
  1998. }
  1999. }
  2000. if (wz == WaferSize.WS12) wzindex = 12;
  2001. if (wz == WaferSize.WS8) wzindex = 8;
  2002. if (wz == WaferSize.WS6) wzindex = 6;
  2003. if (wz == WaferSize.WS4) wzindex = 4;
  2004. if (wz == WaferSize.WS3) wzindex = 3;
  2005. if (SC.ContainsItem($"CarrierInfo.{module}Station"))
  2006. {
  2007. string[] stationInfo = SC.GetStringValue($"CarrierInfo.{module}Station").Split('.');
  2008. if (stationInfo.Length < 2)
  2009. {
  2010. EV.PostAlarmLog("Robot", $"{RobotModuleName} parse bank number failed");
  2011. return false;
  2012. }
  2013. if (!int.TryParse(stationInfo[0], out BankNum))
  2014. {
  2015. EV.PostAlarmLog("Robot", $"{RobotModuleName} parse bank number failed");
  2016. return false;
  2017. }
  2018. if (!int.TryParse(stationInfo[1], out CassetteNum))
  2019. {
  2020. EV.PostAlarmLog("Robot", $"{RobotModuleName} parse cassette number failed");
  2021. return false;
  2022. }
  2023. return true;
  2024. }
  2025. if (SC.ContainsItem($"CarrierInfo.{module}Station{wzindex}"))
  2026. {
  2027. string[] stationInfo = SC.GetStringValue($"CarrierInfo.{module}Station{wzindex}").Split('.');
  2028. if (stationInfo.Length < 2)
  2029. {
  2030. EV.PostAlarmLog("Robot", $"{RobotModuleName} parse bank number failed");
  2031. return false;
  2032. }
  2033. if (!int.TryParse(stationInfo[0], out BankNum))
  2034. {
  2035. EV.PostAlarmLog("Robot", $"{RobotModuleName} parse bank number failed");
  2036. return false;
  2037. }
  2038. if (!int.TryParse(stationInfo[1], out CassetteNum))
  2039. {
  2040. EV.PostAlarmLog("Robot", $"{RobotModuleName} parse cassette number failed");
  2041. return false;
  2042. }
  2043. return true;
  2044. }
  2045. if (SC.ContainsItem($"CarrierInfo.{module}BankNumber{wzindex}"))
  2046. BankNum = SC.GetValue<int>($"CarrierInfo.{module}BankNumber{wzindex}");
  2047. else
  2048. {
  2049. EV.PostAlarmLog("Robot", $"{RobotModuleName} parse bank number failed");
  2050. return false;
  2051. }
  2052. if (SC.ContainsItem($"CarrierInfo.{module}CassetteNumber{wzindex}"))
  2053. CassetteNum = SC.GetValue<int>($"CarrierInfo.{module}CassetteNumber{wzindex}");
  2054. else
  2055. {
  2056. EV.PostAlarmLog("Robot", $"{RobotModuleName} parse bank number failed");
  2057. return false;
  2058. }
  2059. return true;
  2060. }
  2061. }
  2062. public enum JelAxisStatus
  2063. {
  2064. NormalEnd,
  2065. InOperation,
  2066. SensorError,
  2067. SensorErrorOrStoppedByAlarm = 4,
  2068. CommandError = 8,
  2069. }
  2070. public enum JelCommandStatus
  2071. {
  2072. None,
  2073. NormalEnd,
  2074. InExecution,
  2075. InPause,
  2076. InError,
  2077. }
  2078. public struct JelParameterData
  2079. {
  2080. public string Value;
  2081. public string MinValue;
  2082. public string MaxValue;
  2083. }
  2084. public enum JelRobotArm
  2085. {
  2086. Left =0,
  2087. Right,
  2088. Dual,
  2089. }
  2090. }