RorzeRobot751.cs 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Device.Unit;
  5. using Aitex.Core.RT.Event;
  6. using Aitex.Core.RT.Log;
  7. using Aitex.Core.RT.OperationCenter;
  8. using Aitex.Core.RT.SCCore;
  9. using Aitex.Core.Util;
  10. using MECF.Framework.Common.Communications;
  11. using MECF.Framework.Common.Equipment;
  12. using MECF.Framework.Common.SubstrateTrackings;
  13. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
  14. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  15. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Text;
  19. using System.Threading;
  20. using EventType = Aitex.Core.RT.Event.EventType;
  21. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.Rorze
  22. {
  23. public class RorzeRobot751 : RobotBaseDevice, IConnection
  24. {
  25. private bool isSimulatorMode;
  26. private string _scRoot;
  27. public RROpModeEnum CurrentOpMode { get; set; }
  28. public bool IsOrgshCompleted { get; set; }
  29. public bool IsCmdProcessing { get; set; }
  30. public RROpStatusEnum CurrentOpStatus { get; set; }
  31. public int CurrentOperationSpeed { get; set; } //0:Normal, 1-K Set Speed
  32. public string CurrentIdCodeForErrorController { get; set; }
  33. public bool _diEms { get; set; }
  34. public bool _diTempStop { get; set; }
  35. public bool _diVacuumPressure { get; set; }
  36. public bool _diAirSourcePressure { get; set; }
  37. public bool _diZaxisFan { get; set; }
  38. public bool _diUpperArmFan { get; set;}
  39. public bool _diLowerArmFan { get; set; }
  40. public bool _diUpperFinger1ArmWaferExistence1 { get; set; }
  41. public bool _diUpperFinger1ArmWaferExistence2 { get; set; }
  42. public bool _diLowerArmWaferExistence1 { get; set; }
  43. public bool _diLowerArmWaferExistence2 { get; set; }
  44. public bool _diTPEms { get; set; }
  45. public bool _diDeadmanSwitch { get; set; }
  46. public bool _diModeKey { get; set; }
  47. public bool IsEnableSeqNo { get; private set; }
  48. public bool IsEnableCheckSum { get; private set; }
  49. public int CurrentSeqNo { get; set; }
  50. public string PortName;
  51. internal void OnEventReceived(string rawMessage)
  52. {
  53. try
  54. {
  55. string eventname = rawMessage.Split('.')[1].Split(':')[0];
  56. string[] data = rawMessage.Split('.')[1].Split(':')[1].Split('/');
  57. switch (eventname)
  58. {
  59. case "STAT":
  60. ParseSTATStatus(data);
  61. break;
  62. case "GPIO":
  63. break;
  64. }
  65. }
  66. catch(Exception ex)
  67. {
  68. LOG.Write(ex);
  69. }
  70. }
  71. private string _address;
  72. private bool _enableLog;
  73. private RorzeRobot751Connection _connection;
  74. private R_TRIG _trigError = new R_TRIG();
  75. private R_TRIG _trigCommunicationError = new R_TRIG();
  76. private R_TRIG _trigRetryConnect = new R_TRIG();
  77. public string Address => _address;
  78. private PeriodicJob _thread;
  79. private object _locker = new object();
  80. private LinkedList<HandlerBase> _lstHandlers = new LinkedList<HandlerBase>();
  81. private IoSensor _diRobotReady = null; //Normal ON
  82. private IoSensor _diRobotBlade1WaferOn = null; //Off when wafer present
  83. private IoSensor _diRobotBlade2WaferOn = null;
  84. private IoSensor _diRobotError = null; //Normal ON
  85. private IoSensor _diTPinUse = null;
  86. private IoTrigger _doRobotHold = null; // Normal ON
  87. public ModuleName CurrentInteractiveModule { get; private set; }
  88. public bool IsConnected => throw new NotImplementedException();
  89. public bool IsGrippedBlade1 { get; private set; }
  90. public bool IsGrippedBlade2 { get; private set; }
  91. public bool IsPermittedInterlock1 { get; private set; }
  92. public bool IsPermittedInterlock2 { get; private set; }
  93. public bool IsPermittedInterlock3 { get; private set; }
  94. public bool IsPermittedInterlock4 { get; private set; }
  95. public bool IsPermittedInterlock5 { get; private set; }
  96. public bool IsPermittedInterlock6 { get; private set; }
  97. public bool IsPermittedInterlock7 { get; private set; }
  98. public bool IsPermittedInterlock8 { get; private set; }
  99. public float CurrentThetaPosition { get; private set; }
  100. public float CurrentExtensionPosition { get; private set; }
  101. public float CurrentArm1Position { get; private set; }
  102. public float CurrentArm2Position { get; private set; }
  103. public float CurrentZPosition { get; private set; }
  104. public float CommandThetaPosition { get; private set; }
  105. public float CommandExtensionPosition { get; private set; }
  106. public float CommandArm1Position { get; private set; }
  107. public float CommandArm2Position { get; private set; }
  108. public float CommandZPosition { get; private set; }
  109. public int SpeedLevel { get; private set; }
  110. public int SpeedLevelSetting { get; private set; }
  111. public string ReadMemorySpec { get; private set; }
  112. public string ReadTransferStation { get; private set; }
  113. public int ReadSlotNumber { get; private set; }
  114. public string ReadArmPosture { get; private set; }
  115. public RobotArmEnum ReadBladeNo { get; private set; }
  116. public float ReadThetaPosition { get; private set; }
  117. public float ReadExtensionPosition { get; private set; }
  118. public float ReadArm1Position { get; private set; }
  119. public float ReadArm2Position { get; private set; }
  120. public float ReadZPosition { get; private set; }
  121. public Dictionary<string, string> ReadStationItemValues { get; private set; } = new Dictionary<string, string>();
  122. public Dictionary<string, string> ReadStationItemContents { get; private set; } = new Dictionary<string, string>();
  123. public string ReadParameterType { get; private set; }
  124. public string ReadParameterNo { get; private set; }
  125. public string ReadParameterValue { get; private set; }
  126. public bool IsManipulatorBatteryLow { get; private set; }
  127. public bool IsCommandExecutionReady { get; private set; }
  128. public bool IsServoON { get; private set; }
  129. public bool IsErrorOccurred { get; private set; }
  130. public bool IsControllerBatteryLow { get; private set; }
  131. public bool IsCheckInterlockWaferPresenceOnBlade1 { get; private set; }
  132. public bool IsCheckInterlockWaferPresenceOnBlade2 { get; private set; }
  133. public bool IsCheckInterlockPAOp { get; private set; }
  134. public bool IsCheckInterlockPAWaferStatus { get; private set; }
  135. public bool IsCheckInterlockPAWaferStatusByCCD { get; private set; }
  136. public string RobotSystemVersion { get; private set; }
  137. public string RobotSoftwareVersion { get; private set; }
  138. public string ReadMappingTransferStation { get; private set; }
  139. public int ReadMappingSlotNumbers { get; private set; }
  140. public string ReadSlotMap { get; private set; }
  141. public int RobotBodyNumber { get; private set; }
  142. public Dictionary<string, float> ReadMappingCalibrationResult { get; private set; }
  143. public RorzeRobot751(string module, string name, string scRoot, IoSensor[] dis, IoTrigger[] dos) : base(module, name)
  144. {
  145. Module = module;
  146. Name = name;
  147. isSimulatorMode = SC.ContainsItem("System.IsSimulatorMode") ? SC.GetValue<bool>("System.IsSimulatorMode") : false;
  148. _scRoot = scRoot;
  149. _address = SC.GetStringValue($"{_scRoot}.{Name}.Address");
  150. _enableLog = SC.GetValue<bool>($"{_scRoot}.{Name}.EnableLogMessage");
  151. RobotBodyNumber = SC.GetValue<int>($"{_scRoot}.{Name}.BodyNumber");
  152. SpeedLevelSetting = SC.GetValue<int>($"{_scRoot}.{Name}.SpeedLevel");
  153. _connection = new RorzeRobot751Connection(this, _address);
  154. _connection.EnableLog(_enableLog);
  155. if (dis != null && dis.Length >= 5)
  156. {
  157. _diRobotReady = dis[0];
  158. _diRobotBlade1WaferOn = dis[1];
  159. _diRobotBlade2WaferOn = dis[2];
  160. _diRobotError = dis[3];
  161. _diTPinUse = dis[4];
  162. _diRobotError.OnSignalChanged += _diRobotError_OnSignalChanged;
  163. _diTPinUse.OnSignalChanged += _diTPinUse_OnSignalChanged;
  164. }
  165. if (dos != null && dos.Length >= 1)
  166. {
  167. _doRobotHold = dos[0];
  168. }
  169. ConnectionManager.Instance.Subscribe($"{Name}", _connection);
  170. _thread = new PeriodicJob(1, OnTimer, $"{_scRoot}.{Name} MonitorHandler", true);
  171. ResetPropertiesAndResponses();
  172. RegisterSpecialData();
  173. RegisterAlarm();
  174. }
  175. public void HandlerMotion(string command, string[] pdata)
  176. {
  177. switch (command)
  178. {
  179. case "MMAP":
  180. try
  181. {
  182. StringBuilder sb = new StringBuilder();
  183. for (int i = 6; i < pdata.Length; i++)
  184. {
  185. string value = pdata[i].Substring(3);
  186. switch (value)
  187. {
  188. case "--":
  189. sb.Append("0");
  190. break;
  191. case "OK":
  192. sb.Append("1");
  193. break;
  194. case "CW":
  195. sb.Append("2");
  196. break;
  197. case "DW":
  198. sb.Append("W");
  199. break;
  200. }
  201. }
  202. ReadSlotMap = sb.ToString();
  203. NotifySlotMapResult(CurrentInteractiveModule, ReadSlotMap);
  204. return;
  205. }
  206. catch (Exception ex)
  207. {
  208. LOG.Write(ex);
  209. }
  210. break;
  211. default:
  212. break;
  213. }
  214. }
  215. private void RegisterAlarm()
  216. {
  217. }
  218. public void NotifyAlarmByErrorCode(string errorcode)
  219. {
  220. EV.Notify($"{Name}Error{errorcode}");
  221. }
  222. private void _diTPinUse_OnSignalChanged(IoSensor arg1, bool arg2)
  223. {
  224. SetMaintenanceMode(!arg1.Value);
  225. }
  226. private void _diRobotError_OnSignalChanged(IoSensor arg1, bool arg2)
  227. {
  228. if (arg1.Value == false)
  229. {
  230. lock (_locker)
  231. {
  232. _lstHandlers.AddLast(new RorzeRobot751ReadHandler(this, "STAT"));
  233. }
  234. OnError("RobotError");
  235. }
  236. }
  237. private void ResetPropertiesAndResponses()
  238. {
  239. }
  240. private void RegisterSpecialData()
  241. {
  242. DATA.Subscribe($"{Module}.{Name}.CurrentArm1Position", () => CurrentArm1Position);
  243. DATA.Subscribe($"{Module}.{Name}.CurrentArm2Position", () => CurrentArm2Position);
  244. DATA.Subscribe($"{Module}.{Name}.CurrentExtensionPosition", () => CurrentExtensionPosition);
  245. DATA.Subscribe($"{Module}.{Name}.CurrentThetaPosition", () => CurrentThetaPosition);
  246. DATA.Subscribe($"{Module}.{Name}.CurrentZPosition", () => CurrentZPosition);
  247. DATA.Subscribe($"{Module}.{Name}.IsManipulatorBatteryLow", () => IsManipulatorBatteryLow);
  248. DATA.Subscribe($"{Module}.{Name}.IsCommandExecutionReady", () => IsCommandExecutionReady);
  249. DATA.Subscribe($"{Module}.{Name}.IsServoON", () => IsServoON);
  250. DATA.Subscribe($"{Module}.{Name}.IsErrorOccurred", () => IsErrorOccurred);
  251. DATA.Subscribe($"{Module}.{Name}.IsControllerBatteryLow", () => IsControllerBatteryLow);
  252. DATA.Subscribe($"{Module}.{Name}.IsWaferPresenceOnBlade1", () => IsWaferPresenceOnBlade1);
  253. DATA.Subscribe($"{Module}.{Name}.IsWaferPresenceOnBlade2", () => IsWaferPresenceOnBlade2);
  254. DATA.Subscribe($"{Module}.{Name}.ErrorCode", () => ErrorCode);
  255. DATA.Subscribe($"{Module}.{Name}.IsGrippedBlade1", () => IsGrippedBlade1);
  256. DATA.Subscribe($"{Module}.{Name}.IsGrippedBlade2", () => IsGrippedBlade2);
  257. DATA.Subscribe($"{Module}.{Name}.IsPermittedInterlock1", () => IsPermittedInterlock1);
  258. DATA.Subscribe($"{Module}.{Name}.IsPermittedInterlock2", () => IsPermittedInterlock2);
  259. DATA.Subscribe($"{Module}.{Name}.IsPermittedInterlock3", () => IsPermittedInterlock3);
  260. DATA.Subscribe($"{Module}.{Name}.IsPermittedInterlock4", () => IsPermittedInterlock4);
  261. DATA.Subscribe($"{Module}.{Name}.IsPermittedInterlock5", () => IsPermittedInterlock5);
  262. DATA.Subscribe($"{Module}.{Name}.IsPermittedInterlock6", () => IsPermittedInterlock6);
  263. DATA.Subscribe($"{Module}.{Name}.IsPermittedInterlock7", () => IsPermittedInterlock7);
  264. DATA.Subscribe($"{Module}.{Name}.IsPermittedInterlock8", () => IsPermittedInterlock8);
  265. DATA.Subscribe($"{Module}.{Name}.RobotSpeed", () => SpeedLevelSetting.ToString());
  266. DATA.Subscribe($"{Name}.RobotSpeed", () =>
  267. {
  268. return SpeedLevelSetting.ToString();
  269. });
  270. OP.Subscribe("SetSpeed", InvokeSetSpeed);
  271. }
  272. private bool OnTimer()
  273. {
  274. try
  275. {
  276. if (!_connection.IsConnected || _connection.IsCommunicationError)
  277. {
  278. lock (_locker)
  279. {
  280. _lstHandlers.Clear();
  281. }
  282. _trigRetryConnect.CLK = !_connection.IsConnected;
  283. if (_trigRetryConnect.Q)
  284. {
  285. if (!_connection.Connect())
  286. {
  287. EV.PostAlarmLog(Module, $"Can not connect with {_connection.Address}, {Module}.{Name}");
  288. }
  289. else
  290. {
  291. //_lstHandler.AddLast(new RobotHirataR4QueryPinHandler(this, _deviceAddress));
  292. //_lstHandler.AddLast(new RobotHirataR4SetCommModeHandler(this, _deviceAddress, EnumRfPowerCommunicationMode.Host));
  293. }
  294. }
  295. return true;
  296. }
  297. HandlerBase handler = null;
  298. lock (_locker)
  299. {
  300. if (!_connection.IsBusy)
  301. {
  302. if (_lstHandlers.Count > 0)
  303. {
  304. handler = _lstHandlers.First.Value;
  305. ExecuteHandler(handler);
  306. _lstHandlers.RemoveFirst();
  307. }
  308. }
  309. else
  310. {
  311. _connection.MonitorTimeout();
  312. _trigCommunicationError.CLK = _connection.IsCommunicationError;
  313. if (_trigCommunicationError.Q)
  314. {
  315. _lstHandlers.Clear();
  316. //EV.PostAlarmLog(Module, $"{Module}.{Name} communication error, {_connection.LastCommunicationError}");
  317. OnError($"{Module}.{Name} communication error, {_connection.LastCommunicationError}");
  318. //_trigActionDone.CLK = true;
  319. }
  320. }
  321. }
  322. }
  323. catch (Exception ex)
  324. {
  325. LOG.Write(ex);
  326. }
  327. return true;
  328. }
  329. public bool Connect()
  330. {
  331. return _connection.Connect();
  332. }
  333. public bool Disconnect()
  334. {
  335. return _connection.Disconnect();
  336. }
  337. public override bool IsReady()
  338. {
  339. //if (_diRobotReady!=null && !_diRobotReady.Value)
  340. // return false;
  341. if (_diRobotError != null && !_diRobotError.Value)
  342. return false;
  343. if (_diTPinUse != null && !_diTPinUse.Value)
  344. return false;
  345. return RobotState == RobotStateEnum.Idle && !IsBusy;
  346. }
  347. public bool ParseReadData(string _command, string[] rdata)
  348. {
  349. try
  350. {
  351. switch(_command)
  352. {
  353. case "STAT":
  354. ParseSTATStatus(rdata);
  355. break;
  356. case "GPIO":
  357. ParseDioStatus(rdata);
  358. break;
  359. case "GMAP":
  360. ParseSlotMap(rdata);
  361. break;
  362. }
  363. //if (_command == "RSLV") //Read the speed level
  364. //{
  365. // return (rdata.Length == 1 && ParseSpeedLevel(rdata[0]));
  366. //}
  367. //if (_command == "RPOS") //Reference current postion
  368. //{
  369. // return (rdata.Length > 1 && ParsePositionData(rdata));
  370. //}
  371. //if (_command == "RSTP") //Reference registered position, read the save postion for station
  372. //{
  373. // return (rdata.Length > 6 && ParseRegisteredPositionData(rdata));
  374. //}
  375. //if (_command == "RSTR") //Reference station item value
  376. //{
  377. // return (rdata.Length == 4 && ParseStationData(rdata));
  378. //}
  379. //if (_command == "RPRM") //Reference the parameter values of the specified unit
  380. //{
  381. // return (rdata.Length == 3 && ParseParameterData(rdata));
  382. //}
  383. //if (_command == "RMSK") //Reference the interlock information
  384. //{
  385. // return (rdata.Length == 1 && ParseInterlockInfo(rdata));
  386. //}
  387. //if (_command == "RVER") //Reference the software version
  388. //{
  389. // return (rdata.Length == 2 && ParseSoftwareVersion(rdata));
  390. //}
  391. //if (_command == "RMAP") //Reference the slot map
  392. //{
  393. // return (rdata.Length > 2 && ParseSlotMap(rdata));
  394. //}
  395. //if (_command == "RMPD") //reference the mapping data
  396. //{
  397. // return (rdata.Length > 1 && ParseMappingData(rdata));
  398. //}
  399. //if (_command == "RMCA") // Reference the mapping calibration result
  400. //{
  401. // return (rdata.Length > 1 && ParseMappingCalibrationResult(rdata));
  402. //}
  403. //if (_command == "RALN") // Reference the alignment result
  404. //{
  405. // return true;
  406. //}
  407. //if (_command == "RACA") // Reference calibration result for alignment
  408. //{
  409. // return true;
  410. //}
  411. return true;
  412. }
  413. catch (Exception ex)
  414. {
  415. LOG.Write(ex);
  416. return true;
  417. }
  418. }
  419. private void ParseDioStatus(string[] rdata)
  420. {
  421. }
  422. public bool ParseSTATStatus(string[] status)
  423. {
  424. try
  425. {
  426. CurrentOpMode = (RROpModeEnum)int.Parse(status[0].Substring(0,1));
  427. IsOrgshCompleted = status[0][1] == '1';
  428. IsCmdProcessing = status[0][2] == '1';
  429. CurrentOpStatus = (RROpStatusEnum)int.Parse(status[0].Substring(3, 1));
  430. CurrentOperationSpeed = int.Parse(status[0].Substring(4, 1));
  431. CurrentIdCodeForErrorController = status[1].Substring(0, 2);
  432. CurrentIdCodeForErrorController = status[1].Substring(2, 2);
  433. return true;
  434. }
  435. catch (Exception ex)
  436. {
  437. LOG.Write(ex);
  438. return true;
  439. }
  440. }
  441. public bool ParseSpeedLevel(string speedlevel)
  442. {
  443. try
  444. {
  445. int level = Convert.ToInt32(speedlevel);
  446. if (level < 1 || level > 3) return false;
  447. SpeedLevel = level;
  448. return true;
  449. }
  450. catch (Exception ex)
  451. {
  452. LOG.Write(ex);
  453. return false;
  454. }
  455. }
  456. public bool ParsePositionData(string[] pdata)
  457. {
  458. try
  459. {
  460. if (pdata[0] == "R")
  461. {
  462. CommandThetaPosition = Convert.ToSingle(pdata[1]) / 1000;
  463. CommandExtensionPosition = Convert.ToSingle(pdata[2]) / 1000;
  464. CommandArm1Position = Convert.ToSingle(pdata[3]) / 1000;
  465. CommandArm2Position = Convert.ToSingle(pdata[4]) / 1000;
  466. CommandZPosition = Convert.ToSingle(pdata[5]) / 1000;
  467. return true;
  468. }
  469. if (pdata[0] == "F")
  470. {
  471. CurrentThetaPosition = Convert.ToSingle(pdata[1]) / 1000;
  472. PositionAxis1 = CurrentThetaPosition;
  473. CurrentExtensionPosition = Convert.ToSingle(pdata[2]) / 1000;
  474. PositionAxis2 = CurrentExtensionPosition;
  475. CurrentArm1Position = Convert.ToSingle(pdata[3]) / 1000;
  476. PositionAxis3 = CurrentArm1Position;
  477. CurrentArm2Position = Convert.ToSingle(pdata[4]) / 1000;
  478. PositionAxis4 = CurrentArm2Position;
  479. CurrentZPosition = Convert.ToSingle(pdata[5]) / 1000;
  480. PositionAxis5 = CurrentZPosition;
  481. return true;
  482. }
  483. return false;
  484. }
  485. catch (Exception ex)
  486. {
  487. LOG.Write(ex);
  488. return false;
  489. }
  490. }
  491. public bool ParseRegisteredPositionData(string[] pdata)
  492. {
  493. return true;
  494. }
  495. public bool ParseStationData(string[] pdata)
  496. {
  497. try
  498. {
  499. ReadMemorySpec = pdata[0];
  500. ReadTransferStation = pdata[1];
  501. if (ReadStationItemValues.ContainsKey(pdata[2]))
  502. ReadStationItemValues.Remove(pdata[2]);
  503. ReadStationItemValues.Add(pdata[2], pdata[3]);
  504. return true;
  505. }
  506. catch (Exception ex)
  507. {
  508. LOG.Write(ex);
  509. return false;
  510. }
  511. }
  512. public bool ParseParameterData(string[] pdata)
  513. {
  514. try
  515. {
  516. ReadParameterType = pdata[0];
  517. ReadParameterNo = pdata[1];
  518. ReadParameterValue = pdata[2];
  519. return true;
  520. }
  521. catch (Exception ex)
  522. {
  523. LOG.Write(ex);
  524. return false;
  525. }
  526. }
  527. public bool ParseInterlockInfo(string[] pdata)
  528. {
  529. try
  530. {
  531. int intdata = Convert.ToInt16(pdata[0]);
  532. IsCheckInterlockWaferPresenceOnBlade1 = (intdata & 0x1) == 0;
  533. IsCheckInterlockWaferPresenceOnBlade2 = (intdata & 0x2) == 0;
  534. IsCheckInterlockPAOp = (intdata & 0x10) == 0;
  535. IsCheckInterlockPAWaferStatus = (intdata & 0x20) == 0;
  536. IsCheckInterlockPAWaferStatusByCCD = (intdata & 0x40) == 0;
  537. return true;
  538. }
  539. catch (Exception ex)
  540. {
  541. LOG.Write(ex);
  542. return false;
  543. }
  544. }
  545. public bool ParseSoftwareVersion(string[] pdata)
  546. {
  547. try
  548. {
  549. RobotSystemVersion = pdata[0];
  550. RobotSoftwareVersion = pdata[1];
  551. return true;
  552. }
  553. catch (Exception ex)
  554. {
  555. LOG.Write(ex);
  556. return false;
  557. }
  558. }
  559. public bool ParseSlotMap(string[] pdata)
  560. {
  561. // n = 0 : Wafer does not exist.
  562. //1 : Wafer exists.
  563. //2 : Thickness abnormal(thick)
  564. //3 : Cross
  565. //4 : Bow / Lift
  566. //7 : Multiple wafers
  567. //8 : Thickness abnormal(thin)
  568. //9 : Mapping failure
  569. try
  570. {
  571. ReadSlotMap = pdata[0].Replace("2","W").Replace("3","2").Replace("4","?").Replace("7","W").Replace("8","?").Replace("9","?");
  572. NotifySlotMapResult(CurrentInteractiveModule, ReadSlotMap);
  573. return true;
  574. }
  575. catch (Exception ex)
  576. {
  577. LOG.Write(ex);
  578. return false;
  579. }
  580. }
  581. public bool ParseMappingData(string[] pdata)
  582. {
  583. try
  584. {
  585. ReadMappingTransferStation = pdata[0];
  586. List<string> lstupdata = new List<string>();
  587. List<string> lstdowndata = new List<string>();
  588. for (int i = 0; i < (pdata.Length - 1) / 2; i++)
  589. {
  590. lstupdata.Add(pdata[2 * i + 1].Remove(0, 3));
  591. lstdowndata.Add(pdata[2 * i + 2]);
  592. }
  593. ReadMappingDownData = lstdowndata.ToArray();
  594. ReadMappingUpData = lstupdata.ToArray();
  595. return true;
  596. }
  597. catch (Exception ex)
  598. {
  599. LOG.Write(ex);
  600. return false;
  601. }
  602. }
  603. public bool ParseMappingCalibrationResult(string[] pdata)
  604. {
  605. try
  606. {
  607. ReadMappingTransferStation = pdata[0];
  608. ReadMappingCalibrationResult.Clear();
  609. ReadMappingCalibrationResult.Add("LowestLaySlotPosition", Convert.ToInt32(pdata[1]) / 1000);
  610. ReadMappingCalibrationResult.Add("HighestLaySlotPosition", Convert.ToInt32(pdata[2]) / 1000);
  611. ReadMappingCalibrationResult.Add("WaferWidth", Convert.ToInt32(pdata[3]) / 1000);
  612. ReadMappingCalibrationResult.Add("ThreshhholdValueofDoubleInsertion", Convert.ToInt32(pdata[4]) / 1000);
  613. ReadMappingCalibrationResult.Add("ThreshhholdValueofSlantingInsertion1", Convert.ToInt32(pdata[5]) / 1000);
  614. ReadMappingCalibrationResult.Add("ThreshhholdValueofSlantingInsertion2", Convert.ToInt32(pdata[6]) / 1000);
  615. return true;
  616. }
  617. catch (Exception ex)
  618. {
  619. LOG.Write(ex);
  620. return false;
  621. }
  622. }
  623. protected override bool fClear(object[] param)
  624. {
  625. lock (_locker)
  626. {
  627. _lstHandlers.Clear();
  628. _connection.ForceClear();
  629. _lstHandlers.AddLast(new RorzeRobot751MotionHandler(this, "CCLR", "E"));
  630. _lstHandlers.AddLast(new RorzeRobot751ReadHandler(this, "STAT"));
  631. }
  632. return true;
  633. }
  634. protected override bool fStartReadData(object[] param)
  635. {
  636. if (param.Length < 1) return false;
  637. string readcommand = param[0].ToString();
  638. switch (readcommand)
  639. {
  640. case "CurrentStatus":
  641. lock (_locker)
  642. {
  643. _lstHandlers.AddLast(new RorzeRobot751ReadHandler(this, "STAT"));
  644. }
  645. break;
  646. default:
  647. break;
  648. }
  649. return true;
  650. }
  651. private void ExecuteHandler(HandlerBase handler)
  652. {
  653. _connection.Execute(handler);
  654. }
  655. private string Checksum(byte[] bytes)
  656. {
  657. int sum = 0;
  658. foreach (byte code in bytes)
  659. {
  660. sum += code;
  661. }
  662. string hex = String.Format("{0:X2}", sum % 256);
  663. return hex;
  664. }
  665. protected override bool fStartSetParameters(object[] param)
  666. {
  667. try
  668. {
  669. string strParameter;
  670. string setcommand = param[0].ToString();
  671. _setParameter = setcommand;
  672. switch (setcommand)
  673. {
  674. case "RobotSpeed": // SSPD Set the motion speed
  675. int speedlevel = Convert.ToInt32(param[2]);
  676. lock (_locker)
  677. {
  678. _lstHandlers.AddLast(new RorzeRobot751SetHandler(this, "SSPD", $"(0,{speedlevel})"));
  679. }
  680. if (SC.ContainsItem($"{_scRoot}.{Name}.SpeedLevel"))
  681. {
  682. SC.SetItemValue($"{_scRoot}.{Name}.SpeedLevel", Convert.ToInt32(speedlevel));
  683. SpeedLevelSetting = SC.GetValue<int>($"{_scRoot}.{Name}.SpeedLevel");
  684. }
  685. break;
  686. case "TransferSpeedLevel": //SSLV Select the transfer speed level
  687. string sslvlevel = param[1].ToString();
  688. int nSpeed = 100;
  689. if (sslvlevel == "1") nSpeed = 100;
  690. if (sslvlevel == "2") nSpeed = 50;
  691. if (sslvlevel == "3") nSpeed = 10;
  692. if (!"123".Contains(sslvlevel))
  693. {
  694. EV.PostAlarmLog(Name, $"Set {setcommand} with invalid parameter:" + sslvlevel);
  695. return false;
  696. }
  697. lock (_locker)
  698. {
  699. _lstHandlers.AddLast(new RorzeRobot751SetHandler(this, "SSPD", $"(0,{nSpeed})"));
  700. }
  701. if (SC.ContainsItem($"{_scRoot}.{Name}.SpeedLevel"))
  702. {
  703. SC.SetItemValue($"{_scRoot}.{Name}.SpeedLevel", Convert.ToInt32(sslvlevel));
  704. SpeedLevelSetting = SC.GetValue<int>($"{_scRoot}.{Name}.SpeedLevel");
  705. }
  706. break;
  707. case "WaferSize":
  708. _setSizeArm = (RobotArmEnum)param[1];
  709. _setSize = (WaferSize)param[2];
  710. break;
  711. }
  712. }
  713. catch (Exception)
  714. {
  715. string reason = "";
  716. if (param != null)
  717. {
  718. foreach (var para in param)
  719. {
  720. reason += para.ToString() + ",";
  721. }
  722. }
  723. EV.PostAlarmLog(Name, "Set command parameter invalid:" + reason);
  724. return false;
  725. }
  726. return true;
  727. }
  728. private string _setParameter;
  729. private RobotArmEnum _setSizeArm;
  730. private WaferSize _setSize;
  731. protected override bool fMonitorSetParamter(object[] param)
  732. {
  733. IsBusy = false;
  734. switch (_setParameter)
  735. {
  736. case "WaferSize":
  737. if (_setSizeArm == RobotArmEnum.Lower || _setSizeArm == RobotArmEnum.Blade1)
  738. WaferManager.Instance.UpdateWaferSize(RobotModuleName, 0, _setSize);
  739. if (_setSizeArm == RobotArmEnum.Upper || _setSizeArm == RobotArmEnum.Upper)
  740. WaferManager.Instance.UpdateWaferSize(RobotModuleName, 1, _setSize);
  741. if (_setSizeArm == RobotArmEnum.Both)
  742. {
  743. WaferManager.Instance.UpdateWaferSize(RobotModuleName, 0, _setSize);
  744. WaferManager.Instance.UpdateWaferSize(RobotModuleName, 1, _setSize);
  745. }
  746. Size = _setSize;
  747. break;
  748. }
  749. return true;
  750. }
  751. protected override bool fStartTransferWafer(object[] param)
  752. {
  753. return false;
  754. }
  755. protected override bool fStartUnGrip(object[] param)
  756. {
  757. lock (_locker)
  758. {
  759. RobotArmEnum arm = (RobotArmEnum)param[0];
  760. switch(arm)
  761. {
  762. case RobotArmEnum.Lower:
  763. _lstHandlers.AddLast(new RorzeRobot751MotionHandler(this, "UCLM", "(2)"));
  764. break;
  765. case RobotArmEnum.Upper:
  766. _lstHandlers.AddLast(new RorzeRobot751MotionHandler(this, "UCLM", "(1)"));
  767. break;
  768. case RobotArmEnum.Both:
  769. _lstHandlers.AddLast(new RorzeRobot751MotionHandler(this, "UCLM", "(3)"));
  770. break;
  771. }
  772. }
  773. return true;
  774. }
  775. protected override bool fStartGrip(object[] param)
  776. {
  777. lock (_locker)
  778. {
  779. RobotArmEnum arm = (RobotArmEnum)param[0];
  780. switch (arm)
  781. {
  782. case RobotArmEnum.Lower:
  783. _lstHandlers.AddLast(new RorzeRobot751MotionHandler(this, "CLMP", "(2)"));
  784. break;
  785. case RobotArmEnum.Upper:
  786. _lstHandlers.AddLast(new RorzeRobot751MotionHandler(this, "CLMP", "(1)"));
  787. break;
  788. case RobotArmEnum.Both:
  789. _lstHandlers.AddLast(new RorzeRobot751MotionHandler(this, "CLMP", "(3)"));
  790. break;
  791. }
  792. }
  793. return true;
  794. }
  795. protected override bool fStartInit(object[] param)
  796. {
  797. SpeedLevelSetting = SC.GetValue<int>($"{_scRoot}.{Name}.SpeedLevel");
  798. lock (_locker)
  799. {
  800. if (_doRobotHold != null)
  801. {
  802. _doRobotHold.SetTrigger(true, out _);
  803. Thread.Sleep(100);
  804. }
  805. _lstHandlers.AddLast(new RorzeRobot751SetHandler(this, "EVNT", "(0,1)"));
  806. _lstHandlers.AddLast(new RorzeRobot751MotionHandler(this, "INIT"));
  807. _lstHandlers.AddLast(new RorzeRobot751SetHandler(this, "MODE","(1,0)"));
  808. _lstHandlers.AddLast(new RorzeRobot751SetHandler(this, "SSPD", $"(0,{SpeedLevelSetting})"));
  809. _lstHandlers.AddLast(new RorzeRobot751MotionHandler(this, "ORGN","(0,0)"));
  810. }
  811. return true;
  812. }
  813. protected override bool fStartHome(object[] param)
  814. {
  815. SpeedLevelSetting = SC.GetValue<int>($"{_scRoot}.{Name}.SpeedLevel");
  816. lock (_locker)
  817. {
  818. if (_doRobotHold != null)
  819. {
  820. _doRobotHold.SetTrigger(true, out _);
  821. Thread.Sleep(100);
  822. }
  823. //_lstHandlers.AddLast(new SR100RobotMotionHandler(this, "CSOL", "F,1,0"));
  824. _lstHandlers.AddLast(new RorzeRobot751SetHandler(this, "EVNT", "(0,1)"));
  825. _lstHandlers.AddLast(new RorzeRobot751SetHandler(this, "INIT"));
  826. _lstHandlers.AddLast(new RorzeRobot751SetHandler(this, "MODE", "(1,0)"));
  827. _lstHandlers.AddLast(new RorzeRobot751SetHandler(this, "SSPD", $"(0,{SpeedLevelSetting})"));
  828. _lstHandlers.AddLast(new RorzeRobot751MotionHandler(this, "ORGN", "(0,0)"));
  829. }
  830. return true;
  831. }
  832. protected override bool fStartGoTo(object[] param)
  833. {
  834. try
  835. {
  836. RobotArmEnum arm = (RobotArmEnum)param[0];
  837. ModuleName module = (ModuleName)Enum.Parse(typeof(ModuleName), param[1].ToString());
  838. BladeTarget = module;
  839. Blade1Target = module;
  840. Blade2Target = module;
  841. int slot = (int)param[2] + 1;
  842. RobotPostionEnum postype = (RobotPostionEnum)param[3];
  843. float x = (float)param[4];
  844. float y = (float)param[5];
  845. float z = (float)param[6];
  846. float w = (float)param[7];
  847. int intXvalue = (int)(x * 1000);
  848. int intYvalue = (int)(y * 1000);
  849. int intZvalue = (int)(z * 1000);
  850. int intWvalue = (int)(w * 1000);
  851. bool isFromOriginal = (bool)param[8];
  852. bool isJumpToNextMotion = (bool)param[9];
  853. string strpara = string.Empty;
  854. if ((int)postype >= 0 && (int)postype < 10)
  855. {
  856. strpara = "G";
  857. }
  858. if ((int)postype >= 10 && (int)postype < 20)
  859. {
  860. strpara = "P";
  861. }
  862. if ((int)postype >= 20 && (int)postype < 30)
  863. {
  864. strpara = "E";
  865. }
  866. int trsSt = GetStationsName(module);
  867. string TrsPnt = string.Empty;
  868. if (postype == RobotPostionEnum.PickReady)
  869. {
  870. TrsPnt = "G1";
  871. }
  872. if (postype == RobotPostionEnum.PickExtendLow)
  873. {
  874. TrsPnt = "G2";
  875. }
  876. if (postype == RobotPostionEnum.PickAtWafer)
  877. {
  878. TrsPnt = "Gb";
  879. }
  880. if (postype == RobotPostionEnum.PickExtendUp)
  881. {
  882. TrsPnt = "G3";
  883. }
  884. if (postype == RobotPostionEnum.PickRetracted)
  885. {
  886. TrsPnt = "G4";
  887. }
  888. if (postype == RobotPostionEnum.PlaceReady)
  889. {
  890. TrsPnt = "P1";
  891. }
  892. if (postype == RobotPostionEnum.PlaceExtendUp)
  893. {
  894. TrsPnt = "P2";
  895. }
  896. if (postype == RobotPostionEnum.PlaceExtendAtWafer)
  897. {
  898. TrsPnt = "Pb";
  899. }
  900. if (postype == RobotPostionEnum.PlaceExtendDown)
  901. {
  902. TrsPnt = "P3";
  903. }
  904. if (postype == RobotPostionEnum.PlaceRetract)
  905. {
  906. TrsPnt = "P4";
  907. }
  908. string strCmd = string.Empty;
  909. if (isFromOriginal)
  910. {
  911. strCmd = "MTRS";
  912. }
  913. else if (isJumpToNextMotion)
  914. {
  915. strCmd = "MCTR";
  916. }
  917. else
  918. {
  919. strCmd = "MPNT";
  920. }
  921. if (string.IsNullOrEmpty(strpara) || string.IsNullOrEmpty(TrsPnt))
  922. {
  923. EV.PostAlarmLog("Robot", "invalid transfer paramter");
  924. return false;
  925. }
  926. strpara += $",{trsSt},{slot:D2},A,{(arm == RobotArmEnum.Both ? "F" : ((int)arm + 1).ToString())}," +
  927. $"{TrsPnt}";
  928. if (x != 0 || y != 0 || z != 0 || w != 0)
  929. {
  930. string strxoffset = intXvalue >= 0 ? $"{intXvalue:D8}" : $"{intXvalue:D7}";
  931. string stryoffset = intYvalue >= 0 ? $"{intYvalue:D8}" : $"{intYvalue:D7}";
  932. string strzoffset = intZvalue >= 0 ? $"{intZvalue:D8}" : $"{intZvalue:D7}";
  933. string strwoffset = intWvalue >= 0 ? $"{intWvalue:D8}" : $"{intWvalue:D7}";
  934. strpara += $",{strxoffset},{stryoffset},{strzoffset},{strwoffset}";
  935. }
  936. if (strCmd == "MPNT")
  937. strpara = TrsPnt;
  938. lock (_locker)
  939. {
  940. //if (_lstHandlers.Count == 0 && !_connection.IsBusy)
  941. //{
  942. // ExecuteHandler(new SR100RobotMotionHandler(this, strCmd, strpara));
  943. //}
  944. //else
  945. //{
  946. // _lstHandlers.AddLast(new SR100RobotMotionHandler(this, strCmd, strpara));
  947. //}
  948. }
  949. return true;
  950. }
  951. catch (Exception ex)
  952. {
  953. LOG.Write(ex);
  954. return false;
  955. }
  956. }
  957. protected override bool fGoToComplete(object[] param)
  958. {
  959. try
  960. {
  961. RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
  962. ModuleName sourcemodule = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[1].ToString());
  963. int SourceslotIndex = (int)CurrentParamter[2];
  964. RobotPostionEnum postype = (RobotPostionEnum)CurrentParamter[3];
  965. bool isFromOriginal = (bool)CurrentParamter[8];
  966. bool isJumpToNextMotion = (bool)CurrentParamter[9];
  967. switch (postype)
  968. {
  969. case RobotPostionEnum.PickExtendUp:
  970. case RobotPostionEnum.PickRetracted:
  971. if (arm == RobotArmEnum.Lower)
  972. {
  973. WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 0);
  974. //if (isSimulatorMode || GetWaferState(arm) == RobotArmWaferStateEnum.Present)
  975. // WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 0);
  976. //else
  977. // OnError("Wafer detect error");
  978. }
  979. if (arm == RobotArmEnum.Upper)
  980. {
  981. WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 1);
  982. //if (isSimulatorMode || GetWaferState(arm) == RobotArmWaferStateEnum.Present)
  983. // WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 1);
  984. //else
  985. // OnError("Wafer detect error");
  986. }
  987. if (arm == RobotArmEnum.Both)
  988. {
  989. WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 0);
  990. WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 1);
  991. //if (isSimulatorMode || GetWaferState(arm) == RobotArmWaferStateEnum.Present)
  992. //{
  993. // WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 0);
  994. // WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 1);
  995. //}
  996. //else
  997. // OnError("Wafer detect error");
  998. }
  999. break;
  1000. case RobotPostionEnum.PlaceExtendDown:
  1001. case RobotPostionEnum.PlaceRetract:
  1002. if (arm == RobotArmEnum.Lower)
  1003. {
  1004. WaferManager.Instance.WaferMoved(RobotModuleName, 0, sourcemodule, SourceslotIndex);
  1005. //if (isSimulatorMode || GetWaferState(arm) == RobotArmWaferStateEnum.Absent)
  1006. // WaferManager.Instance.WaferMoved(RobotModuleName, 0, sourcemodule, SourceslotIndex);
  1007. //else
  1008. // OnError("Wafer detect error");
  1009. }
  1010. if (arm == RobotArmEnum.Upper)
  1011. {
  1012. WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, SourceslotIndex);
  1013. //if (isSimulatorMode || GetWaferState(arm) == RobotArmWaferStateEnum.Absent)
  1014. // WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, SourceslotIndex);
  1015. //else
  1016. // OnError("Wafer detect error");
  1017. }
  1018. if (arm == RobotArmEnum.Both)
  1019. {
  1020. WaferManager.Instance.WaferMoved(RobotModuleName, 0, sourcemodule, SourceslotIndex);
  1021. WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, SourceslotIndex);
  1022. //if (isSimulatorMode || GetWaferState(arm) == RobotArmWaferStateEnum.Absent)
  1023. //{
  1024. // WaferManager.Instance.WaferMoved(RobotModuleName, 0, sourcemodule, SourceslotIndex);
  1025. // WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, SourceslotIndex);
  1026. //}
  1027. //else
  1028. // OnError("Wafer detect error");
  1029. }
  1030. break;
  1031. }
  1032. }
  1033. catch (Exception ex)
  1034. {
  1035. LOG.Write(ex);
  1036. }
  1037. return base.fGoToComplete(param);
  1038. }
  1039. protected override bool fStop(object[] param)
  1040. {
  1041. lock (_locker)
  1042. {
  1043. if (_doRobotHold != null)
  1044. _doRobotHold.SetTrigger(false, out _);
  1045. _lstHandlers.Clear();
  1046. _connection.ForceClear();
  1047. //ExecuteHandler(new SR100RobotMotionHandler(this, "CSTP", "E"));
  1048. }
  1049. return true; ;
  1050. }
  1051. protected override bool fStartMove(object[] param)
  1052. {
  1053. try
  1054. {
  1055. string strCmd = param[0].ToString();
  1056. string strpara = string.Empty;
  1057. for (int i = 1; i < param.Length; i++)
  1058. {
  1059. if (i == 1)
  1060. strpara += param[i].ToString();
  1061. else
  1062. strpara += "," + param[i].ToString();
  1063. }
  1064. lock (_locker)
  1065. {
  1066. //_lstHandlers.AddLast(new SR100RobotMotionHandler(this, strCmd, strpara));
  1067. //_lstHandlers.AddLast(new SR100RobotReadHandler(this, "RPOS", "F"));
  1068. }
  1069. return true;
  1070. }
  1071. catch (Exception ex)
  1072. {
  1073. LOG.Write(ex);
  1074. return false;
  1075. }
  1076. }
  1077. private int GetStationsName(ModuleName module)
  1078. {
  1079. try
  1080. {
  1081. if (ModuleHelper.IsLoadPort(module))
  1082. {
  1083. int infopadindex = DEVICE.GetDevice<LoadPortBaseDevice>(module.ToString()).InfoPadCarrierIndex;
  1084. return SC.GetValue<int>($"CarrierInfo.{module}Station{infopadindex}");
  1085. }
  1086. int nvalue = SC.GetValue<int>($"CarrierInfo.{module}Station");
  1087. return nvalue;
  1088. }
  1089. catch (Exception ex)
  1090. {
  1091. LOG.Write(ex);
  1092. return 0;
  1093. }
  1094. }
  1095. private int GetSlotsNumber(ModuleName module)
  1096. {
  1097. try
  1098. {
  1099. if (ModuleHelper.IsLoadPort(module))
  1100. {
  1101. return DEVICE.GetDevice<LoadPortBaseDevice>(module.ToString()).ValidSlotsNumber;
  1102. }
  1103. return SC.GetValue<int>($"CarrierInfo.{module}SlotsNumber");
  1104. }
  1105. catch (Exception ex)
  1106. {
  1107. LOG.Write(ex);
  1108. return -1;
  1109. }
  1110. }
  1111. private bool _isNeedMappignData
  1112. {
  1113. get
  1114. {
  1115. if (SC.ContainsItem($"Robot.{RobotModuleName}.NeedReadMapData"))
  1116. return SC.GetValue<bool>($"Robot.{RobotModuleName}.NeedReadMapData");
  1117. return true;
  1118. }
  1119. }
  1120. protected override bool fStartMapWafer(object[] param)
  1121. {
  1122. try
  1123. {
  1124. //RobotArmEnum pickarm = (RobotArmEnum)param[0];
  1125. ModuleName module = (ModuleName)Enum.Parse(typeof(ModuleName), param[0].ToString());
  1126. BladeTarget = module;
  1127. Blade1Target = module;
  1128. Blade2Target = module;
  1129. int slotsNumber = GetSlotsNumber(module);
  1130. if (slotsNumber == -1)
  1131. {
  1132. EV.PostAlarmLog("Robot", "Invalid mapping paramter slots number");
  1133. return false;
  1134. }
  1135. //int slot = 25;// (int)param[2];
  1136. string strpara = $"({GetStationsName(module)},0,0)";
  1137. lock (_locker)
  1138. {
  1139. CurrentInteractiveModule = module;
  1140. _lstHandlers.AddLast(new RorzeRobot751MotionHandler(this, "WMAP", strpara));
  1141. _lstHandlers.AddLast(new RorzeRobot751ReadHandler(this, "GMAP"));
  1142. }
  1143. return true;
  1144. }
  1145. catch (Exception ex)
  1146. {
  1147. LOG.Write(ex);
  1148. return false;
  1149. }
  1150. }
  1151. protected override bool fStartSwapWafer(object[] param)
  1152. {
  1153. try
  1154. {
  1155. RobotArmEnum arm = (RobotArmEnum)param[0];
  1156. ModuleName module = (ModuleName)Enum.Parse(typeof(ModuleName), param[1].ToString());
  1157. BladeTarget = module;
  1158. Blade1Target = module;
  1159. Blade2Target = module;
  1160. if (ModuleHelper.IsLoadPort(module))
  1161. {
  1162. var lp = DEVICE.GetDevice<LoadPortBaseDevice>(module.ToString());
  1163. if (lp != null)
  1164. lp.NoteTransferStart();
  1165. }
  1166. int slot = (int)param[2] + 1;
  1167. int TrsSt = GetStationsName(module);
  1168. int nArm = 0;
  1169. if (arm == RobotArmEnum.Lower)
  1170. nArm = 2;
  1171. if (arm == RobotArmEnum.Upper)
  1172. nArm = 1;
  1173. if (nArm == 0)
  1174. return false;
  1175. string strpara = $"({nArm},{TrsSt},{slot})";
  1176. lock (_locker)
  1177. {
  1178. if (_lstHandlers.Count == 0 && !_connection.IsBusy)
  1179. {
  1180. ExecuteHandler(new RorzeRobot751MotionHandler(this, "EXCH", strpara));
  1181. }
  1182. else
  1183. {
  1184. _lstHandlers.AddLast(new RorzeRobot751MotionHandler(this, "EXCH", strpara));
  1185. }
  1186. }
  1187. return true;
  1188. }
  1189. catch (Exception ex)
  1190. {
  1191. LOG.Write(ex);
  1192. return false;
  1193. }
  1194. }
  1195. protected override bool fSwapComplete(object[] param)
  1196. {
  1197. RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
  1198. ModuleName sourcemodule;
  1199. if (!Enum.TryParse(CurrentParamter[1].ToString(), out sourcemodule)) return false;
  1200. int Sourceslotindex;
  1201. if (!int.TryParse(CurrentParamter[2].ToString(), out Sourceslotindex)) return false;
  1202. int delayCount = 0;
  1203. if (arm == RobotArmEnum.Lower)
  1204. {
  1205. //WaferManager.Instance.WaferMoved(sourcemodule, Sourceslotindex, RobotModuleName, 0);
  1206. //WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, Sourceslotindex);
  1207. while (!isSimulatorMode && !(GetWaferState(RobotArmEnum.Lower) == RobotArmWaferStateEnum.Present
  1208. && GetWaferState(RobotArmEnum.Upper) == RobotArmWaferStateEnum.Absent))
  1209. {
  1210. delayCount++;
  1211. Thread.Sleep(50);
  1212. LOG.Write($"{RobotModuleName} delay {delayCount} time to detect wafer");
  1213. if (delayCount > 100)
  1214. {
  1215. OnError("Wafer detect error");
  1216. return true;
  1217. }
  1218. }
  1219. WaferManager.Instance.WaferMoved(sourcemodule, Sourceslotindex, RobotModuleName, 0);
  1220. WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, Sourceslotindex);
  1221. }
  1222. if (arm == RobotArmEnum.Upper)
  1223. {
  1224. //WaferManager.Instance.WaferMoved(sourcemodule, Sourceslotindex, RobotModuleName, 1);
  1225. //WaferManager.Instance.WaferMoved(RobotModuleName, 0, sourcemodule, Sourceslotindex);
  1226. delayCount = 0;
  1227. while (!isSimulatorMode && !(GetWaferState(RobotArmEnum.Upper) == RobotArmWaferStateEnum.Present &&
  1228. GetWaferState(RobotArmEnum.Lower) == RobotArmWaferStateEnum.Absent))
  1229. {
  1230. delayCount++;
  1231. Thread.Sleep(50);
  1232. LOG.Write($"{RobotModuleName} delay {delayCount} time to detect wafer");
  1233. if (delayCount > 100)
  1234. {
  1235. OnError("Wafer detect error");
  1236. return true;
  1237. }
  1238. }
  1239. WaferManager.Instance.WaferMoved(sourcemodule, Sourceslotindex, RobotModuleName, 1);
  1240. WaferManager.Instance.WaferMoved(RobotModuleName, 0, sourcemodule, Sourceslotindex);
  1241. }
  1242. return base.fSwapComplete(param);
  1243. }
  1244. protected override bool fStartPlaceWafer(object[] param)
  1245. {
  1246. try
  1247. {
  1248. RobotArmEnum arm = (RobotArmEnum)param[0];
  1249. ModuleName module = (ModuleName)Enum.Parse(typeof(ModuleName), param[1].ToString());
  1250. if (ModuleHelper.IsLoadPort(module))
  1251. {
  1252. var lp = DEVICE.GetDevice<LoadPortBaseDevice>(module.ToString());
  1253. if (lp != null)
  1254. lp.NoteTransferStart();
  1255. }
  1256. BladeTarget = module;
  1257. Blade1Target = module;
  1258. Blade2Target = module;
  1259. int slot = (int)param[2] + 1;
  1260. int TrsSt = GetStationsName(module);
  1261. int nArm = 0;
  1262. if (arm == RobotArmEnum.Lower)
  1263. nArm = 2;
  1264. if (arm == RobotArmEnum.Upper)
  1265. nArm = 1;
  1266. if (arm == RobotArmEnum.Both)
  1267. nArm = 3;
  1268. if (nArm == 0)
  1269. return false;
  1270. string strpara = $"{nArm},{TrsSt},{slot}";
  1271. lock (_locker)
  1272. {
  1273. if (_lstHandlers.Count == 0 && !_connection.IsBusy)
  1274. {
  1275. ExecuteHandler(new RorzeRobot751MotionHandler(this, "UNLD", strpara));
  1276. }
  1277. else
  1278. {
  1279. _lstHandlers.AddLast(new RorzeRobot751MotionHandler(this, "UNLD", strpara));
  1280. }
  1281. }
  1282. return true;
  1283. }
  1284. catch (Exception ex)
  1285. {
  1286. LOG.Write(ex);
  1287. return false;
  1288. }
  1289. }
  1290. protected override bool fPlaceComplete(object[] param)
  1291. {
  1292. RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
  1293. ModuleName sourcemodule;
  1294. if (!Enum.TryParse(CurrentParamter[1].ToString(), out sourcemodule)) return false;
  1295. int Sourceslotindex;
  1296. if (!int.TryParse(CurrentParamter[2].ToString(), out Sourceslotindex)) return false;
  1297. if (arm == RobotArmEnum.Lower)
  1298. {
  1299. WaferManager.Instance.WaferMoved(RobotModuleName, 0, sourcemodule, Sourceslotindex);
  1300. }
  1301. if (arm == RobotArmEnum.Upper)
  1302. {
  1303. WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, Sourceslotindex);
  1304. }
  1305. if (arm == RobotArmEnum.Both)
  1306. {
  1307. WaferManager.Instance.WaferMoved(RobotModuleName, 0, sourcemodule, Sourceslotindex);
  1308. WaferManager.Instance.WaferMoved(RobotModuleName, 1, sourcemodule, Sourceslotindex + 1);
  1309. }
  1310. return true;
  1311. }
  1312. protected override bool fStartPickWafer(object[] param)
  1313. {
  1314. try
  1315. {
  1316. RobotArmEnum arm = (RobotArmEnum)param[0];
  1317. ModuleName module = (ModuleName)Enum.Parse(typeof(ModuleName), param[1].ToString());
  1318. if (ModuleHelper.IsLoadPort(module))
  1319. {
  1320. var lp = DEVICE.GetDevice<LoadPortBaseDevice>(module.ToString());
  1321. if (lp != null)
  1322. lp.NoteTransferStart();
  1323. }
  1324. BladeTarget = module;
  1325. Blade1Target = module;
  1326. Blade2Target = module;
  1327. int slot = (int)param[2] + 1;
  1328. string TrsSt = GetStationsName(module).ToString();
  1329. if (string.IsNullOrEmpty(TrsSt))
  1330. {
  1331. EV.PostAlarmLog("Robot", "Invalid Parameter.");
  1332. return false;
  1333. }
  1334. int nArm = 0;
  1335. if (arm == RobotArmEnum.Lower)
  1336. nArm = 2;
  1337. if (arm == RobotArmEnum.Upper)
  1338. nArm = 1;
  1339. if (arm == RobotArmEnum.Both)
  1340. nArm = 3;
  1341. if (nArm == 0)
  1342. return false;
  1343. string strpara = $"{nArm},{TrsSt},{slot}";
  1344. lock (_locker)
  1345. {
  1346. if (_lstHandlers.Count == 0 && !_connection.IsBusy)
  1347. {
  1348. ExecuteHandler(new RorzeRobot751MotionHandler(this, "LOAD", strpara));
  1349. }
  1350. else
  1351. {
  1352. _lstHandlers.AddLast(new RorzeRobot751MotionHandler(this, "LOAD", strpara));
  1353. }
  1354. }
  1355. return true;
  1356. }
  1357. catch (Exception ex)
  1358. {
  1359. LOG.Write(ex);
  1360. return false;
  1361. }
  1362. }
  1363. protected override bool fPickComplete(object[] param)
  1364. {
  1365. RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
  1366. ModuleName module = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[1].ToString());
  1367. ModuleName sourcemodule;
  1368. if (!Enum.TryParse(CurrentParamter[1].ToString(), out sourcemodule)) return false;
  1369. int SourceslotIndex;
  1370. if (!int.TryParse(CurrentParamter[2].ToString(), out SourceslotIndex)) return false;
  1371. if (arm == RobotArmEnum.Lower)
  1372. {
  1373. WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 0);
  1374. }
  1375. if (arm == RobotArmEnum.Upper)
  1376. {
  1377. WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 1);
  1378. }
  1379. if (arm == RobotArmEnum.Both)
  1380. {
  1381. WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex, RobotModuleName, 0);
  1382. WaferManager.Instance.WaferMoved(sourcemodule, SourceslotIndex + 1, RobotModuleName, 1);
  1383. }
  1384. return true;
  1385. }
  1386. protected override bool fResetToReady(object[] param)
  1387. {
  1388. if (_doRobotHold != null)
  1389. _doRobotHold.SetTrigger(true, out _);
  1390. return true;
  1391. }
  1392. protected override bool fReset(object[] param)
  1393. {
  1394. if (!_connection.IsConnected)
  1395. {
  1396. _address = SC.GetStringValue($"{_scRoot}.{Name}.Address");
  1397. _enableLog = SC.GetValue<bool>($"{_scRoot}.{Name}.EnableLogMessage");
  1398. _connection = new RorzeRobot751Connection(this, _address);
  1399. _connection.EnableLog(_enableLog);
  1400. _connection.Connect();
  1401. }
  1402. lock (_locker)
  1403. {
  1404. if (_doRobotHold != null)
  1405. _doRobotHold.SetTrigger(true, out _);
  1406. _lstHandlers.Clear();
  1407. _connection.ForceClear();
  1408. _lstHandlers.AddLast(new RorzeRobot751SetHandler(this, "RSTA","(1)"));
  1409. _lstHandlers.AddLast(new RorzeRobot751SetHandler(this, "EVNT","(0,1)"));
  1410. _lstHandlers.AddLast(new RorzeRobot751ReadHandler(this, "STAT"));
  1411. }
  1412. return true;
  1413. }
  1414. protected override bool fError(object[] param)
  1415. {
  1416. return true;
  1417. }
  1418. protected override bool fStartExtendForPick(object[] param)
  1419. {
  1420. return false;
  1421. }
  1422. protected override bool fStartExtendForPlace(object[] param)
  1423. {
  1424. return false;
  1425. }
  1426. protected override bool fStartRetractFromPick(object[] param)
  1427. {
  1428. return false;
  1429. }
  1430. protected override bool fStartRetractFromPlace(object[] param)
  1431. {
  1432. return false;
  1433. }
  1434. public override RobotArmWaferStateEnum GetWaferState(RobotArmEnum arm)
  1435. {
  1436. if (arm == RobotArmEnum.Lower)
  1437. {
  1438. if (_diRobotBlade1WaferOn != null)
  1439. {
  1440. if (_diRobotBlade1WaferOn.Value) return RobotArmWaferStateEnum.Absent;
  1441. else return RobotArmWaferStateEnum.Present;
  1442. }
  1443. return IsWaferPresenceOnBlade1 ? RobotArmWaferStateEnum.Present : RobotArmWaferStateEnum.Absent;
  1444. }
  1445. if (arm == RobotArmEnum.Upper)
  1446. {
  1447. if (_diRobotBlade2WaferOn != null)
  1448. {
  1449. if (_diRobotBlade2WaferOn.Value) return RobotArmWaferStateEnum.Absent;
  1450. else return RobotArmWaferStateEnum.Present;
  1451. }
  1452. return IsWaferPresenceOnBlade2 ? RobotArmWaferStateEnum.Present : RobotArmWaferStateEnum.Absent;
  1453. }
  1454. if (arm == RobotArmEnum.Both)
  1455. {
  1456. if (_diRobotBlade1WaferOn != null && _diRobotBlade2WaferOn != null)
  1457. {
  1458. if (_diRobotBlade2WaferOn.Value && _diRobotBlade1WaferOn.Value)
  1459. return RobotArmWaferStateEnum.Absent;
  1460. else if (!_diRobotBlade2WaferOn.Value && !_diRobotBlade1WaferOn.Value)
  1461. return RobotArmWaferStateEnum.Present;
  1462. else return RobotArmWaferStateEnum.Unknown;
  1463. }
  1464. if (IsWaferPresenceOnBlade1 && IsWaferPresenceOnBlade2)
  1465. {
  1466. return RobotArmWaferStateEnum.Present;
  1467. }
  1468. if ((!IsWaferPresenceOnBlade1) && !IsWaferPresenceOnBlade2)
  1469. {
  1470. return RobotArmWaferStateEnum.Absent;
  1471. }
  1472. }
  1473. return RobotArmWaferStateEnum.Unknown;
  1474. }
  1475. public void NoteError(string errortext)
  1476. {
  1477. OnError(errortext);
  1478. }
  1479. public override bool OnActionDone(object[] param)
  1480. {
  1481. BladeTarget = ModuleName.System;
  1482. Blade1Target = ModuleName.System;
  1483. Blade2Target = ModuleName.System;
  1484. IsBusy = false;
  1485. ModuleName sourcemodule;
  1486. if (CurrentParamter != null && CurrentParamter.Length > 2 && Enum.TryParse(CurrentParamter[1].ToString(), out sourcemodule))
  1487. {
  1488. if (ModuleHelper.IsLoadPort(sourcemodule))
  1489. {
  1490. var lp = DEVICE.GetDevice<LoadPortBaseDevice>(sourcemodule.ToString());
  1491. if (lp != null)
  1492. lp.NoteTransferStop();
  1493. }
  1494. }
  1495. if (_lstHandlers.Count == 0)
  1496. {
  1497. IsBusy = false;
  1498. return base.OnActionDone(param);
  1499. }
  1500. return true;
  1501. }
  1502. public override void Terminate()
  1503. {
  1504. _thread.Stop();
  1505. if (!SC.ContainsItem($"{_scRoot}.{Name}.CloseConnectionOnShutDown") || SC.GetValue<bool>($"{_scRoot}.{Name}.CloseConnectionOnShutDown"))
  1506. {
  1507. LOG.Write("Close connection for" + RobotModuleName.ToString());
  1508. _connection.Disconnect();
  1509. }
  1510. base.Terminate();
  1511. }
  1512. }
  1513. public enum RROpModeEnum
  1514. {
  1515. Initializing,
  1516. Remote,
  1517. Maitanance,
  1518. Recovery,
  1519. }
  1520. public enum RROpStatusEnum
  1521. {
  1522. Stop,
  1523. Moving,
  1524. TempStop,
  1525. }
  1526. }