SPaceTRanRobot.cs 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Device;
  4. using Aitex.Core.RT.Device.Unit;
  5. using Aitex.Core.RT.Event;
  6. using Aitex.Core.RT.Log;
  7. using Aitex.Core.RT.OperationCenter;
  8. using Aitex.Core.RT.SCCore;
  9. using Aitex.Core.Util;
  10. using MECF.Framework.Common.CommonData;
  11. using MECF.Framework.Common.Communications;
  12. using MECF.Framework.Common.Equipment;
  13. using MECF.Framework.Common.SubstrateTrackings;
  14. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.LoadPortBase;
  15. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  16. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.RobotBase;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Globalization;
  20. using System.Text;
  21. using System.Threading;
  22. using MECF.Framework.Common.CommonData;
  23. using EventType = Aitex.Core.RT.Event.EventType;
  24. using Aitex.Sorter.Common;
  25. using System.Text.RegularExpressions;
  26. using System.Linq;
  27. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.SUNWAY
  28. {
  29. public class SPaceTRanRobot : RobotBaseDevice, IConnection
  30. {
  31. private bool isSimulatorMode;
  32. private string _scRoot;
  33. public TokenGenerator SeqnoGenerator { get; private set; }
  34. public RROpModeEnum CurrentOpMode { get; set; }
  35. public bool IsOrgshCompleted { get; set; }
  36. public bool IsCmdProcessing { get; set; }
  37. public RROpStatusEnum CurrentOpStatus { get; set; }
  38. public int CurrentOperationSpeed { get; set; } //0:Normal, 1-K Set Speed
  39. public string CurrentIdCodeForErrorController { get; set; }
  40. public bool _diEms { get; set; }
  41. public bool _diTempStop { get; set; }
  42. public bool _diVacuumPressure { get; set; }
  43. public bool _diAirSourcePressure { get; set; }
  44. public bool _diZaxisFan { get; set; }
  45. public bool _diUpperArmFan { get; set; }
  46. public bool _diLowerArmFan { get; set; }
  47. public bool _diUpperFinger1ArmWaferExistence1 { get; set; }
  48. public bool _diUpperFinger1ArmWaferExistence2 { get; set; }
  49. public bool _diLowerArmWaferExistence1 { get; set; }
  50. public bool _diLowerArmWaferExistence2 { get; set; }
  51. public bool _diTPEms { get; set; }
  52. public bool _diDeadmanSwitch { get; set; }
  53. public bool _diModeKey { get; set; }
  54. public bool IsEnableSeqNo { get; private set; }
  55. public bool IsEnableCheckSum { get; private set; }
  56. public int CurrentSeqNo { get; set; }
  57. public RobotArmEnum chcekingArm { get; set; }
  58. private int _existInterval = SC.GetValue<int>("TM.TMRobot.ExistInterval");
  59. public string PortName;
  60. private string _address;
  61. private bool _enableLog;
  62. private SPaceTRanRobotConnection _connection;
  63. private R_TRIG _trigError = new R_TRIG();
  64. private R_TRIG _trigCommunicationError = new R_TRIG();
  65. private R_TRIG _trigRetryConnect = new R_TRIG();
  66. public string Address => _address;
  67. private PeriodicJob _thread;
  68. private object _locker = new object();
  69. private LinkedList<HandlerBase> _lstHandlers = new LinkedList<HandlerBase>();
  70. private IoSensor _diRobotReady = null; //0=OK,1=Busy
  71. private IoSensor _diRobotBlade1WaferOn = null; //0为下手臂无片,1为有片
  72. private IoSensor _diRobotBlade2WaferOn = null; //0为上手臂无片,1为有片
  73. private IoSensor _diRobotError = null; //Normal ON
  74. private IoSensor _diTPinUse = null;
  75. Dictionary<RobotArmEnum, Tuple<IoSensor, string>> _armSensors = null;
  76. private IoTrigger _doRobotHold = null; // Normal ON
  77. public ModuleName CurrentInteractiveModule { get; private set; }
  78. public bool IsConnected => throw new NotImplementedException();
  79. public bool IsGrippedBlade1 { get; private set; }
  80. public bool IsGrippedBlade2 { get; private set; }
  81. public bool IsPermittedInterlock1 { get; private set; }
  82. public bool IsPermittedInterlock2 { get; private set; }
  83. public bool IsPermittedInterlock3 { get; private set; }
  84. public bool IsPermittedInterlock4 { get; private set; }
  85. public bool IsPermittedInterlock5 { get; private set; }
  86. public bool IsPermittedInterlock6 { get; private set; }
  87. public bool IsPermittedInterlock7 { get; private set; }
  88. public bool IsPermittedInterlock8 { get; private set; }
  89. public float CurrentThetaPosition { get; private set; }
  90. public float CurrentExtensionPosition { get; private set; }
  91. public float CurrentArm1Position { get; private set; }
  92. public float CurrentArm2Position { get; private set; }
  93. public float CurrentZPosition { get; private set; }
  94. public float CommandThetaPosition { get; private set; }
  95. public float CommandExtensionPosition { get; private set; }
  96. public float CommandArm1Position { get; private set; }
  97. public float CommandArm2Position { get; private set; }
  98. public float CommandZPosition { get; private set; }
  99. public int SpeedLevel { get; private set; }
  100. public int SpeedLevelSetting { get; private set; }
  101. public string ReadMemorySpec { get; private set; }
  102. public string ReadTransferStation { get; private set; }
  103. public int ReadSlotNumber { get; private set; }
  104. public string ReadArmPosture { get; private set; }
  105. public RobotArmEnum ReadBladeNo { get; private set; }
  106. public float ReadThetaPosition { get; private set; }
  107. public float ReadExtensionPosition { get; private set; }
  108. public float ReadArm1Position { get; private set; }
  109. public float ReadArm2Position { get; private set; }
  110. public float ReadZPosition { get; private set; }
  111. public Dictionary<string, string> ReadStationItemValues { get; private set; } = new Dictionary<string, string>();
  112. public Dictionary<string, string> ReadStationItemContents { get; private set; } = new Dictionary<string, string>();
  113. public string ReadParameterType { get; private set; }
  114. public string ReadParameterNo { get; private set; }
  115. public string ReadParameterValue { get; private set; }
  116. public bool IsManipulatorBatteryLow { get; private set; }
  117. public bool IsCommandExecutionReady { get; private set; }
  118. public bool IsServoON { get; private set; }
  119. public bool IsErrorOccurred { get; private set; }
  120. public bool IsControllerBatteryLow { get; private set; }
  121. public bool IsCheckInterlockWaferPresenceOnBlade1 { get; private set; }
  122. public bool IsCheckInterlockWaferPresenceOnBlade2 { get; private set; }
  123. public bool IsCheckInterlockPAOp { get; private set; }
  124. public bool IsCheckInterlockPAWaferStatus { get; private set; }
  125. public bool IsCheckInterlockPAWaferStatusByCCD { get; private set; }
  126. public string RobotSystemVersion { get; private set; }
  127. public string RobotSoftwareVersion { get; private set; }
  128. public string ReadMappingTransferStation { get; private set; }
  129. public int ReadMappingSlotNumbers { get; private set; }
  130. public string ReadSlotMap { get; private set; }
  131. public int RobotBodyNumber { get; private set; }
  132. public string TMGripStateBlade1
  133. {
  134. get;
  135. set;
  136. }
  137. public string TMGripStateBlade2
  138. {
  139. get;
  140. set;
  141. }
  142. public Dictionary<string, float> ReadMappingCalibrationResult { get; private set; }
  143. protected override void SubscribeWaferLocation()
  144. {
  145. WaferManager.Instance.SubscribeLocation(Name, 4);
  146. }
  147. public SPaceTRanRobot(string module, string name, string scRoot, IoSensor[] dis, IoTrigger[] dos) : base(module, name)
  148. {
  149. Module = module;
  150. Name = name;
  151. isSimulatorMode = SC.ContainsItem("System.IsSimulatorMode") ? SC.GetValue<bool>("System.IsSimulatorMode") : false;
  152. _scRoot = scRoot;
  153. _address = SC.GetStringValue($"{_scRoot}.{Name}.Address");
  154. _enableLog = SC.GetValue<bool>($"{_scRoot}.{Name}.EnableLogMessage");
  155. RobotBodyNumber = SC.GetValue<int>($"{_scRoot}.{Name}.BodyNumber");
  156. SpeedLevelSetting = SC.GetValue<int>($"{_scRoot}.{Name}.SpeedLevel");
  157. _connection = new SPaceTRanRobotConnection(this, _address);
  158. _connection.EnableLog(_enableLog);
  159. if (dis != null && dis.Length >= 5)
  160. {
  161. _diRobotReady = dis[0];
  162. _diRobotBlade1WaferOn = dis[1];
  163. _diRobotBlade2WaferOn = dis[2];
  164. _diRobotError = dis[3];
  165. _diTPinUse = dis[4];
  166. _diRobotError.OnSignalChanged += _diRobotError_OnSignalChanged;
  167. _diTPinUse.OnSignalChanged += _diTPinUse_OnSignalChanged;
  168. }
  169. if (dos != null && dos.Length >= 1)
  170. {
  171. _doRobotHold = dos[0];
  172. }
  173. ConnectionManager.Instance.Subscribe($"{Name}", _connection);
  174. _thread = new PeriodicJob(1, OnTimer, $"{_scRoot}.{Name} MonitorHandler", true);
  175. RegisterSpecialData();
  176. }
  177. public void NotifyAlarmByErrorCode(string errorcode)
  178. {
  179. EV.Notify($"{Name}Error{errorcode}");
  180. }
  181. private void _diTPinUse_OnSignalChanged(IoSensor arg1, bool arg2)
  182. {
  183. SetMaintenanceMode(!arg1.Value);
  184. }
  185. private void _diRobotError_OnSignalChanged(IoSensor arg1, bool arg2)
  186. {
  187. if (arg1.Value == false)
  188. {
  189. OnError("RobotError");
  190. }
  191. }
  192. private void RegisterSpecialData()
  193. {
  194. DATA.Subscribe($"{Module}.{Name}.CurrentArm1Position", () => CurrentArm1Position);
  195. DATA.Subscribe($"{Module}.{Name}.CurrentArm2Position", () => CurrentArm2Position);
  196. DATA.Subscribe($"{Module}.{Name}.CurrentExtensionPosition", () => CurrentExtensionPosition);
  197. DATA.Subscribe($"{Module}.{Name}.CurrentThetaPosition", () => CurrentThetaPosition);
  198. DATA.Subscribe($"{Module}.{Name}.CurrentZPosition", () => CurrentZPosition);
  199. DATA.Subscribe($"{Module}.{Name}.IsManipulatorBatteryLow", () => IsManipulatorBatteryLow);
  200. DATA.Subscribe($"{Module}.{Name}.IsCommandExecutionReady", () => IsCommandExecutionReady);
  201. DATA.Subscribe($"{Module}.{Name}.IsServoON", () => IsServoON);
  202. DATA.Subscribe($"{Module}.{Name}.IsErrorOccurred", () => IsErrorOccurred);
  203. DATA.Subscribe($"{Module}.{Name}.IsControllerBatteryLow", () => IsControllerBatteryLow);
  204. DATA.Subscribe($"{Module}.{Name}.IsWaferPresenceOnBlade1", () => IsWaferPresenceOnBlade1);
  205. DATA.Subscribe($"{Module}.{Name}.IsWaferPresenceOnBlade2", () => IsWaferPresenceOnBlade2);
  206. DATA.Subscribe($"{Module}.{Name}.ErrorCode", () => ErrorCode);
  207. DATA.Subscribe($"{Module}.{Name}.IsGrippedBlade1", () => IsGrippedBlade1);
  208. DATA.Subscribe($"{Module}.{Name}.IsGrippedBlade2", () => IsGrippedBlade2);
  209. DATA.Subscribe($"{Module}.{Name}.IsPermittedInterlock1", () => IsPermittedInterlock1);
  210. DATA.Subscribe($"{Module}.{Name}.IsPermittedInterlock2", () => IsPermittedInterlock2);
  211. DATA.Subscribe($"{Module}.{Name}.IsPermittedInterlock3", () => IsPermittedInterlock3);
  212. DATA.Subscribe($"{Module}.{Name}.IsPermittedInterlock4", () => IsPermittedInterlock4);
  213. DATA.Subscribe($"{Module}.{Name}.IsPermittedInterlock5", () => IsPermittedInterlock5);
  214. DATA.Subscribe($"{Module}.{Name}.IsPermittedInterlock6", () => IsPermittedInterlock6);
  215. DATA.Subscribe($"{Module}.{Name}.IsPermittedInterlock7", () => IsPermittedInterlock7);
  216. DATA.Subscribe($"{Module}.{Name}.IsPermittedInterlock8", () => IsPermittedInterlock8);
  217. DATA.Subscribe($"{Module}.{Name}.RobotSpeed", () => SpeedLevelSetting.ToString());
  218. DATA.Subscribe($"{Name}.RobotSpeed", () =>
  219. {
  220. return SpeedLevelSetting.ToString();
  221. });
  222. DATA.Subscribe($"{Name}.GripStateBlade1", () => TMGripStateBlade1);
  223. DATA.Subscribe($"{Name}.GripStateBlade2", () => TMGripStateBlade2);
  224. OP.Subscribe("SetSpeed", InvokeSetSpeed);
  225. }
  226. private bool OnTimer()
  227. {
  228. try
  229. {
  230. if (!_connection.IsConnected || _connection.IsCommunicationError)
  231. {
  232. lock (_locker)
  233. {
  234. _lstHandlers.Clear();
  235. }
  236. _trigRetryConnect.CLK = !_connection.IsConnected;
  237. if (_trigRetryConnect.Q && !_connection.Connect())
  238. {
  239. EV.PostAlarmLog(Module, $"Can not connect with {_connection.Address}, {Module}.{Name}");
  240. }
  241. return true;
  242. }
  243. HandlerBase handler = null;
  244. lock (_locker)
  245. {
  246. if (!_connection.IsBusy)
  247. {
  248. if (_lstHandlers.Count > 0)
  249. {
  250. handler = _lstHandlers.First.Value;
  251. ExecuteHandler(handler);
  252. _lstHandlers.RemoveFirst();
  253. }
  254. }
  255. else
  256. {
  257. _connection.MonitorTimeout();
  258. _trigCommunicationError.CLK = _connection.IsCommunicationError;
  259. if (_trigCommunicationError.Q)
  260. {
  261. _lstHandlers.Clear();
  262. OnError($"{Module}.{Name} communication error, {_connection.LastCommunicationError}");
  263. }
  264. }
  265. }
  266. }
  267. catch (Exception ex)
  268. {
  269. LOG.Write(ex);
  270. }
  271. return true;
  272. }
  273. public bool Connect()
  274. {
  275. return _connection.Connect();
  276. }
  277. public bool Disconnect()
  278. {
  279. return _connection.Disconnect();
  280. }
  281. public override bool IsReady()
  282. {
  283. //if (_diRobotReady!=null && !_diRobotReady.Value)
  284. // return false;
  285. if (_diRobotError != null && !_diRobotError.Value)
  286. return false;
  287. if (_diTPinUse != null && !_diTPinUse.Value)
  288. return false;
  289. return RobotState == RobotStateEnum.Idle && !IsBusy;
  290. }
  291. private readonly Regex _rex_check_load = new Regex(@"LOAD\s+(A|B)\s+PAN\s+(L|R)\s+(OFF|ON)\s*");
  292. public bool ParseReadData(string command, string rdata)
  293. {
  294. try
  295. {
  296. if (_rex_check_load.IsMatch(rdata))
  297. {
  298. return ParseWaferIsPresence(command, rdata);
  299. }
  300. return true;
  301. }
  302. catch (Exception ex)
  303. {
  304. LOG.Write(ex);
  305. return true;
  306. }
  307. }
  308. Dictionary<string, List<Tuple<string, int>>> _handToFork = new Dictionary<string, List<Tuple<string, int>>>()
  309. {
  310. { "A",new List<Tuple<string, int>>(){ { new Tuple<string, int>("R", (int)ArmBlade.ArmAFork0) },{ new Tuple<string, int>("L", (int)ArmBlade.ArmAFork2) } } },
  311. { "B",new List<Tuple<string, int>>(){ { new Tuple<string, int>("R", (int)ArmBlade.ArmBFork1) },{ new Tuple<string, int>("L", (int)ArmBlade.ArmBFork3) } } },
  312. };
  313. private bool ParseWaferIsPresence(string command, string rdata)
  314. {
  315. try
  316. {
  317. var results = _rex_check_load.Match(rdata);
  318. var arm = results.Groups[1].Value;
  319. var pan = command.Split(' ')[5];
  320. var waferStatus = results.Groups[3].Value;
  321. if (_handToFork.ContainsKey(arm))
  322. {
  323. var fork = _handToFork[arm].FirstOrDefault(p=>p.Item1 == pan);
  324. if(fork != null)
  325. {
  326. if (WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, fork.Item2))
  327. {
  328. WaferManager.Instance.DeleteWafer(ModuleName.TMRobot, fork.Item2);
  329. }
  330. if (waferStatus == "ON" || waferStatus =="?")
  331. {
  332. if (!WaferManager.Instance.CheckHasWafer(ModuleName.TMRobot, fork.Item2))
  333. {
  334. WaferManager.Instance.CreateWafer(ModuleName.TMRobot, fork.Item2, waferStatus == "ON" ? WaferStatus.Normal : WaferStatus.Unknown);
  335. }
  336. }
  337. }
  338. }
  339. return true;
  340. }
  341. catch (Exception ex)
  342. {
  343. LOG.Write(ex);
  344. return true;
  345. }
  346. }
  347. protected override bool fClear(object[] param)
  348. {
  349. lock (_locker)
  350. {
  351. _lstHandlers.Clear();
  352. _connection.ForceClear();
  353. _lstHandlers.AddLast(new SPaceTRanRobotSetHandler(this, "RESET"));
  354. }
  355. return true;
  356. }
  357. protected override bool fStartReadData(object[] param)
  358. {
  359. if (param.Length < 1) return false;
  360. string readcommand = param[0].ToString();
  361. switch (readcommand)
  362. {
  363. case "CurrentStatus":
  364. break;
  365. case "CheckWaferIsPresence":
  366. {
  367. lock (_locker)
  368. {
  369. IsBusy = true;
  370. RobotArmEnum arm = chcekingArm = (RobotArmEnum)param[1];
  371. int interval = Convert.ToInt16(param[2]);
  372. switch (arm)
  373. {
  374. case RobotArmEnum.Lower:
  375. _lstHandlers.AddLast(new SPaceTRanRobotReadHandler(this, "RQ LOAD ARM A PAN L"));
  376. _lstHandlers.AddLast(new SPaceTRanRobotReadHandler(this, "RQ LOAD ARM A PAN R"));
  377. break;
  378. case RobotArmEnum.Upper:
  379. _lstHandlers.AddLast(new SPaceTRanRobotReadHandler(this, "RQ LOAD ARM B PAN L"));
  380. _lstHandlers.AddLast(new SPaceTRanRobotReadHandler(this, "RQ LOAD ARM B PAN R"));
  381. break;
  382. }
  383. }
  384. }
  385. break;
  386. default:
  387. break;
  388. }
  389. return true;
  390. }
  391. private void ExecuteHandler(HandlerBase handler)
  392. {
  393. _connection.Execute(handler);
  394. }
  395. protected override bool fStartSetParameters(object[] param)
  396. {
  397. try
  398. {
  399. string strParameter;
  400. string setcommand = param[0].ToString();
  401. _setParameter = setcommand;
  402. switch (setcommand)
  403. {
  404. case "MotionSpeed": // SSPD Set the motion speed
  405. break;
  406. case "TransferSpeedLevel": //SSLV Select the transfer speed level
  407. string sslvlevel = param[1].ToString();
  408. int nSpeed = 100;
  409. nSpeed = Convert.ToInt32(sslvlevel);
  410. if (nSpeed > 100 || 0 > nSpeed)
  411. {
  412. EV.PostAlarmLog(Name, $"Set {setcommand} with invalid parameter:" + nSpeed);
  413. return false;
  414. }
  415. lock (_locker)
  416. {
  417. _lstHandlers.AddLast(new SPaceTRanRobotSetHandler(this, "SET ACTION SPEEDS ", $"{nSpeed}"));
  418. }
  419. if (SC.ContainsItem($"{_scRoot}.{Name}.SpeedLevel"))
  420. {
  421. SC.SetItemValue($"{_scRoot}.{Name}.SpeedLevel", Convert.ToInt32(sslvlevel));
  422. SpeedLevelSetting = SC.GetValue<int>($"{_scRoot}.{Name}.SpeedLevel");
  423. }
  424. break;
  425. case "WaferSize":
  426. _setSizeArm = (RobotArmEnum)param[1];
  427. _setSize = (WaferSize)param[2];
  428. break;
  429. }
  430. }
  431. catch (Exception)
  432. {
  433. string reason = "";
  434. if (param != null)
  435. {
  436. foreach (var para in param)
  437. {
  438. reason += para.ToString() + ",";
  439. }
  440. }
  441. EV.PostAlarmLog(Name, "Set command parameter invalid:" + reason);
  442. return false;
  443. }
  444. return true;
  445. }
  446. private string _setParameter;
  447. private RobotArmEnum _setSizeArm;
  448. private WaferSize _setSize;
  449. protected override bool fMonitorSetParamter(object[] param)
  450. {
  451. IsBusy = false;
  452. switch (_setParameter)
  453. {
  454. case "WaferSize":
  455. if (_setSizeArm == RobotArmEnum.Lower || _setSizeArm == RobotArmEnum.Blade1)
  456. WaferManager.Instance.UpdateWaferSize(RobotModuleName, 0, _setSize);
  457. if (_setSizeArm == RobotArmEnum.Upper || _setSizeArm == RobotArmEnum.Upper)
  458. WaferManager.Instance.UpdateWaferSize(RobotModuleName, 1, _setSize);
  459. if (_setSizeArm == RobotArmEnum.Both)
  460. {
  461. WaferManager.Instance.UpdateWaferSize(RobotModuleName, 0, _setSize);
  462. WaferManager.Instance.UpdateWaferSize(RobotModuleName, 1, _setSize);
  463. }
  464. Size = _setSize;
  465. break;
  466. }
  467. return true;
  468. }
  469. protected override bool fStartTransferWafer(object[] param)
  470. {
  471. return false;
  472. }
  473. protected override bool fStartUnGrip(object[] param)
  474. {
  475. lock (_locker)
  476. {
  477. RobotArmEnum arm = (RobotArmEnum)param[0];
  478. var fork = (string)param[1];
  479. switch (arm)
  480. {
  481. case RobotArmEnum.Lower:
  482. _lstHandlers.AddLast(new SPaceTRanRobotMotionHandler(this, "VAC", $" OFF ARM A{ForkMapToRightOrLeft(fork)}"));
  483. break;
  484. case RobotArmEnum.Upper:
  485. _lstHandlers.AddLast(new SPaceTRanRobotMotionHandler(this, "VAC", $" OFF ARM B{ForkMapToRightOrLeft(fork)}"));
  486. break;
  487. case RobotArmEnum.Both:
  488. _lstHandlers.AddLast(new SPaceTRanRobotMotionHandler(this, "VAC", $" OFF ARM A{ForkMapToRightOrLeft(fork)}"));
  489. _lstHandlers.AddLast(new SPaceTRanRobotMotionHandler(this, "VAC", $" OFF ARM B{ForkMapToRightOrLeft(fork)}"));
  490. break;
  491. }
  492. }
  493. RobotArmEnum armenum = (RobotArmEnum)param[0];
  494. switch (armenum)
  495. {
  496. case RobotArmEnum.Lower:
  497. TMGripStateBlade1 = "OFF";
  498. break;
  499. case RobotArmEnum.Upper:
  500. TMGripStateBlade2 = "OFF";
  501. break;
  502. case RobotArmEnum.Both:
  503. TMGripStateBlade1 = "OFF";
  504. TMGripStateBlade2 = "OFF";
  505. break;
  506. }
  507. return true;
  508. }
  509. private string ForkMapToRightOrLeft(string fork)
  510. {
  511. //{ Hand.Blade1,new Tuple<string, string, string>("A", "l", "r") },
  512. //{ Hand.Blade2,new Tuple<string, string, string>("B", "L", "R") },
  513. if (fork == "A" || fork == "B") return "";
  514. return $" PAN {fork.ToUpper()}";
  515. }
  516. protected override bool fStartGrip(object[] param)
  517. {
  518. lock (_locker)
  519. {
  520. RobotArmEnum arm = (RobotArmEnum)param[0];
  521. var fork = (string)param[1];
  522. switch (arm)
  523. {
  524. case RobotArmEnum.Lower:
  525. _lstHandlers.AddLast(new SPaceTRanRobotMotionHandler(this, "VAC", $" ON ARM A{ForkMapToRightOrLeft(fork)}"));
  526. break;
  527. case RobotArmEnum.Upper:
  528. _lstHandlers.AddLast(new SPaceTRanRobotMotionHandler(this, "VAC", $" ON ARM B{ForkMapToRightOrLeft(fork)}"));
  529. break;
  530. case RobotArmEnum.Both:
  531. _lstHandlers.AddLast(new SPaceTRanRobotMotionHandler(this, "VAC", $" ON ARM A{ForkMapToRightOrLeft(fork)}"));
  532. _lstHandlers.AddLast(new SPaceTRanRobotMotionHandler(this, "VAC", $" ON ARM B{ForkMapToRightOrLeft(fork)}"));
  533. break;
  534. }
  535. }
  536. RobotArmEnum armenum = (RobotArmEnum)param[0];
  537. switch (armenum)
  538. {
  539. case RobotArmEnum.Lower:
  540. TMGripStateBlade1 = "ON";
  541. break;
  542. case RobotArmEnum.Upper:
  543. TMGripStateBlade2 = "ON";
  544. break;
  545. case RobotArmEnum.Both:
  546. TMGripStateBlade1 = "ON";
  547. TMGripStateBlade2 = "ON";
  548. break;
  549. }
  550. return true;
  551. }
  552. protected override bool fStartInit(object[] param)
  553. {
  554. SpeedLevelSetting = SC.GetValue<int>($"{_scRoot}.{Name}.SpeedLevel");
  555. int nSpeed = SC.GetValue<int>($"{_scRoot}.{Name}.SpeedLevel"); ;
  556. if (nSpeed > 100 || 0 > nSpeed)
  557. {
  558. EV.PostAlarmLog(Name, $"Set Speed with invalid parameter:" + nSpeed);
  559. return false;
  560. }
  561. lock (_locker)
  562. {
  563. if (_doRobotHold != null)
  564. {
  565. _doRobotHold.SetTrigger(true, out _);
  566. }
  567. _lstHandlers.AddLast(new SPaceTRanRobotMotionHandler(this, "HOME ALL"));
  568. _lstHandlers.AddLast(new SPaceTRanRobotSetHandler(this, $"SET ACTION SPEEDS {nSpeed}"));
  569. }
  570. return true;
  571. }
  572. protected override bool fStartHome(object[] param)
  573. {
  574. SpeedLevelSetting = SC.GetValue<int>($"{_scRoot}.{Name}.SpeedLevel");
  575. int nSpeed = SC.GetValue<int>($"{_scRoot}.{Name}.SpeedLevel"); ;
  576. if (nSpeed > 100 || 0 > nSpeed)
  577. {
  578. EV.PostAlarmLog(Name, $"Set Speed with invalid parameter:" + nSpeed);
  579. return false;
  580. }
  581. lock (_locker)
  582. {
  583. if (_doRobotHold != null)
  584. {
  585. _doRobotHold.SetTrigger(true, out _);
  586. Thread.Sleep(100);
  587. }
  588. _lstHandlers.AddLast(new SPaceTRanRobotMotionHandler(this, "HOME ALL"));
  589. _lstHandlers.AddLast(new SPaceTRanRobotSetHandler(this, $"SET ACTION SPEEDS {nSpeed}"));
  590. }
  591. return true;
  592. }
  593. protected override bool fStartGoTo(object[] param)
  594. {
  595. try
  596. {
  597. RobotArmEnum arm = (RobotArmEnum)param[0];
  598. ModuleName module = (ModuleName)Enum.Parse(typeof(ModuleName), param[1].ToString());
  599. if (!CheckArm(arm)) return false;
  600. var slots = (int[])param[2];
  601. int slot = slots[0];
  602. int trsSlot = GetTargetSlotByModule(module, slots);
  603. string trsStation = GetWaferSizeIndex(module, slot, module, slot);
  604. if (string.IsNullOrWhiteSpace(trsStation))
  605. {
  606. EV.PostAlarmLog("Robot", "Invalid Parameter.");
  607. return false;
  608. }
  609. var nArm = (arm == RobotArmEnum.Lower) ? "A" : (arm == RobotArmEnum.Upper) ? "B" : "";
  610. if (string.IsNullOrWhiteSpace(nArm))
  611. {
  612. EV.PostAlarmLog(Module, $"Start go to error:[{nArm}] Invalid Parameter.");
  613. return false;
  614. }
  615. string strpara = $" N {trsStation} R RE Z DN SLOT {trsSlot} ARM {nArm}";
  616. lock (_locker)
  617. {
  618. if (_lstHandlers.Count == 0 && !_connection.IsBusy)
  619. {
  620. ExecuteHandler(new SPaceTRanRobotMotionHandler(this, "GOTO", strpara));
  621. }
  622. else
  623. {
  624. _lstHandlers.AddLast(new SPaceTRanRobotMotionHandler(this, "GOTO", strpara));
  625. }
  626. }
  627. return true;
  628. }
  629. catch (Exception ex)
  630. {
  631. LOG.Write(ex);
  632. return false;
  633. }
  634. }
  635. protected override bool fGoToComplete(object[] param)
  636. {
  637. try
  638. {
  639. RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
  640. ModuleName module = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[1].ToString());
  641. if (!CheckArm(arm)) return false;
  642. var slots = (int[])CurrentParamter[2];
  643. SetRobotMoveInfo(arm, module, slots[0], RobotAction.Moving);
  644. }
  645. catch (Exception ex)
  646. {
  647. LOG.Write(ex);
  648. return false;
  649. }
  650. return base.fGoToComplete(param);
  651. }
  652. protected override bool fStop(object[] param)
  653. {
  654. lock (_locker)
  655. {
  656. if (_doRobotHold != null)
  657. _doRobotHold.SetTrigger(false, out _);
  658. _lstHandlers.Clear();
  659. _connection.ForceClear();
  660. ExecuteHandler(new SPaceTRanRobotMotionHandler(this, "HALT"));
  661. }
  662. return true; ;
  663. }
  664. protected override bool fStartMove(object[] param)
  665. {
  666. return false;
  667. }
  668. protected override bool fStartMapWafer(object[] param)
  669. {
  670. return false;
  671. }
  672. protected override bool fStartSwapWafer(object[] param)
  673. {
  674. return false;
  675. }
  676. protected override bool fSwapComplete(object[] param)
  677. {
  678. return base.fSwapComplete(param);
  679. }
  680. protected override bool fStartPlaceWafer(object[] param)
  681. {
  682. try
  683. {
  684. RobotArmEnum arm = (RobotArmEnum)param[0];
  685. if (!CheckArm(arm)) return false;
  686. ModuleName module = (ModuleName)Enum.Parse(typeof(ModuleName), param[1].ToString());
  687. var slots = (int[])param[2];
  688. int slot = slots[0];
  689. var pan = (Pan)CurrentParamter[3];
  690. int trsSlot = GetTargetSlotByModule(module, slots);
  691. string trsStation = GetWaferSizeIndex(module, slot, module, slot);
  692. if (string.IsNullOrWhiteSpace(trsStation))
  693. {
  694. EV.PostAlarmLog("Robot", "Invalid Parameter.");
  695. return false;
  696. }
  697. if (pan == Pan.None)
  698. {
  699. EV.PostAlarmLog("Robot", "Place error:Pan Invalid Parameter");
  700. return false;
  701. }
  702. ExectueCommand("PLACE", GetParam(arm, pan, trsSlot, trsStation));
  703. SetRobotMoveInfo(arm, module, slot, RobotAction.Placing);
  704. return true;
  705. }
  706. catch (Exception ex)
  707. {
  708. LOG.Write(ex);
  709. return false;
  710. }
  711. }
  712. protected override bool fPlaceComplete(object[] param)
  713. {
  714. RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
  715. if (arm == RobotArmEnum.Both)
  716. {
  717. EV.PostAlarmLog("Robot", "Invalid Parameter.");
  718. return false;
  719. }
  720. ModuleName sourcemodule;
  721. if (!Enum.TryParse(CurrentParamter[1].ToString(), out sourcemodule)) return false;
  722. var sourceSlots = (int[])CurrentParamter[2];
  723. var pan = (Pan)CurrentParamter[3];
  724. if (sourceSlots == null || pan == Pan.None)
  725. {
  726. EV.PostAlarmLog("Robot", "Place error:Invalid Parameter");
  727. return false;
  728. }
  729. Array.Sort(sourceSlots);
  730. var handSlots = Converter.MapBladeAndPanToSlot((int)CurrentParamter[0], pan);
  731. for (int i = 0; i < handSlots.Length; i++)
  732. {
  733. WaferManager.Instance.WaferMoved(RobotModuleName, handSlots[i], sourcemodule, sourceSlots[i]);
  734. }
  735. SetRobotMoveInfo(arm, ModuleName.System, 0, RobotAction.Moving);
  736. return true;
  737. }
  738. protected override bool fStartPickWafer(object[] param)
  739. {
  740. try
  741. {
  742. RobotArmEnum arm = (RobotArmEnum)param[0];
  743. if (!CheckArm(arm)) return false;
  744. ModuleName module = (ModuleName)Enum.Parse(typeof(ModuleName), param[1].ToString());
  745. var slots = (int[])param[2];
  746. int slot = slots[0];
  747. var pan = (Pan)CurrentParamter[3];
  748. int trsSlot = GetTargetSlotByModule(module, slots);
  749. string trsStation = GetWaferSizeIndex(module, slot, module, slot);
  750. if (string.IsNullOrWhiteSpace(trsStation))
  751. {
  752. EV.PostAlarmLog("Robot", "Invalid Parameter.");
  753. return false;
  754. }
  755. if (pan == Pan.None)
  756. {
  757. EV.PostAlarmLog("Robot", "Pick error:Pan Invalid Parameter");
  758. return false;
  759. }
  760. ExectueCommand("PICK", GetParam(arm, pan, trsSlot, trsStation));
  761. SetRobotMoveInfo(arm, module, slot, RobotAction.Picking);
  762. return true;
  763. }
  764. catch (Exception ex)
  765. {
  766. LOG.Write(ex);
  767. return false;
  768. }
  769. }
  770. protected override bool fPickComplete(object[] param)
  771. {
  772. RobotArmEnum arm = (RobotArmEnum)CurrentParamter[0];
  773. if (arm == RobotArmEnum.Both)
  774. {
  775. EV.PostAlarmLog("Robot", "Invalid Parameter.");
  776. return false;
  777. }
  778. ModuleName module = (ModuleName)Enum.Parse(typeof(ModuleName), CurrentParamter[1].ToString());
  779. ModuleName sourcemodule;
  780. if (!Enum.TryParse(CurrentParamter[1].ToString(), out sourcemodule)) return false;
  781. if (arm == RobotArmEnum.Both)
  782. {
  783. EV.PostAlarmLog("Robot", "Invalid Parameter.");
  784. return false;
  785. }
  786. var sourceSlots = (int[])CurrentParamter[2];
  787. var pan = (Pan)CurrentParamter[3];
  788. if (sourceSlots == null || pan == Pan.None)
  789. {
  790. EV.PostAlarmLog("Robot", "Pick error:Invalid Parameter");
  791. return false;
  792. }
  793. Array.Sort(sourceSlots);
  794. var handSlots = Converter.MapBladeAndPanToSlot((int)CurrentParamter[0], pan);
  795. for (int i = 0; i < handSlots.Length; i++)
  796. {
  797. WaferManager.Instance.WaferMoved(sourcemodule, sourceSlots[i], RobotModuleName, handSlots[i]);
  798. }
  799. SetRobotMoveInfo(arm, ModuleName.System, 0, RobotAction.Moving);
  800. return true;
  801. }
  802. protected override bool fResetToReady(object[] param)
  803. {
  804. if (_doRobotHold != null)
  805. _doRobotHold.SetTrigger(true, out _);
  806. return true;
  807. }
  808. public override void Reset()
  809. {
  810. CheckToPostMessage(RobotMsg.Reset);
  811. }
  812. protected override bool fReset(object[] param)
  813. {
  814. if (!_connection.IsConnected)
  815. {
  816. _address = SC.GetStringValue($"{_scRoot}.{Name}.Address");
  817. _enableLog = SC.GetValue<bool>($"{_scRoot}.{Name}.EnableLogMessage");
  818. _connection = new SPaceTRanRobotConnection(this, _address);
  819. _connection.EnableLog(_enableLog);
  820. _connection.Connect();
  821. }
  822. lock (_locker)
  823. {
  824. if (_doRobotHold != null)
  825. _doRobotHold.SetTrigger(true, out _);
  826. _lstHandlers.Clear();
  827. _connection.ForceClear();
  828. _lstHandlers.AddLast(new SPaceTRanRobotSetHandler(this, "RESET"));
  829. _lstHandlers.AddLast(new SPaceTRanRobotSetHandler(this, "SET SERVOS ON"));
  830. }
  831. return true;
  832. }
  833. protected override bool fError(object[] param)
  834. {
  835. return true;
  836. }
  837. protected override bool fStartExtendForPick(object[] param)
  838. {
  839. try
  840. {
  841. RobotArmEnum arm = (RobotArmEnum)param[0];
  842. if (!CheckArm(arm)) return false;
  843. ModuleName module = (ModuleName)Enum.Parse(typeof(ModuleName), param[1].ToString());
  844. var slots = (int[])param[2];
  845. int slot = slots[0];
  846. var pan = (Pan)CurrentParamter[3];
  847. int trsSlot = GetTargetSlotByModule(module, slots);
  848. string trsStation = GetWaferSizeIndex(module, slot, module, slot);
  849. if (string.IsNullOrWhiteSpace(trsStation))
  850. {
  851. EV.PostAlarmLog("Robot", "Invalid Parameter.");
  852. return false;
  853. }
  854. if (pan == Pan.None)
  855. {
  856. EV.PostAlarmLog("Robot", "ExtendForPick error:Pan Invalid Parameter");
  857. return false;
  858. }
  859. ExecuteComand(arm, pan, trsSlot, trsStation, "PICK", "ENRT");
  860. SetRobotMoveInfo(arm, module, slot, RobotAction.Extending);
  861. return true;
  862. }
  863. catch (Exception ex)
  864. {
  865. LOG.Write(ex);
  866. return false;
  867. }
  868. }
  869. protected override bool fStartExtendForPlace(object[] param)
  870. {
  871. try
  872. {
  873. RobotArmEnum arm = (RobotArmEnum)param[0];
  874. if (!CheckArm(arm)) return false;
  875. ModuleName module = (ModuleName)Enum.Parse(typeof(ModuleName), param[1].ToString());
  876. var slots = (int[])param[2];
  877. int slot = slots[0];
  878. var pan = (Pan)CurrentParamter[3];
  879. int trsSlot = GetTargetSlotByModule(module, slots);
  880. string trsStation = GetWaferSizeIndex(RobotModuleName, (int)arm, module, slot);
  881. if (string.IsNullOrWhiteSpace(trsStation))
  882. {
  883. EV.PostAlarmLog("Robot", "Invalid Parameter.");
  884. return false;
  885. }
  886. ExecuteComand(arm, pan, trsSlot, trsStation, "PLACE", "ENRT");
  887. SetRobotMoveInfo(arm, module, slot, RobotAction.Extending);
  888. return true;
  889. }
  890. catch (Exception ex)
  891. {
  892. LOG.Write(ex);
  893. return false;
  894. }
  895. }
  896. protected override bool fStartRetractFromPick(object[] param)
  897. {
  898. try
  899. {
  900. RobotArmEnum arm = (RobotArmEnum)param[0];
  901. if (arm == RobotArmEnum.Both)
  902. {
  903. EV.PostAlarmLog("Robot", "Invalid Parameter.");
  904. return false;
  905. }
  906. ModuleName module = (ModuleName)Enum.Parse(typeof(ModuleName), param[1].ToString());
  907. var slots = (int[])param[2];
  908. int slot = slots[0];
  909. ModuleName sourcemodule;
  910. if (!Enum.TryParse(CurrentParamter[1].ToString(), out sourcemodule)) return false;
  911. var pan = (Pan)CurrentParamter[3];
  912. if (slots == null || pan == Pan.None)
  913. {
  914. EV.PostAlarmLog("Robot", "Retract Pick error:Invalid Parameter");
  915. return false;
  916. }
  917. Array.Sort(slots);
  918. var handSlots = Converter.MapBladeAndPanToSlot((int)CurrentParamter[0], pan);
  919. for (int i = 0; i < handSlots.Length; i++)
  920. {
  921. WaferManager.Instance.WaferMoved(sourcemodule, slots[i], RobotModuleName, handSlots[i]);
  922. }
  923. int trsSlot = GetTargetSlotByModule(module, slots);
  924. string trsStation = GetWaferSizeIndex(module, slot, module, slot);
  925. if (string.IsNullOrWhiteSpace(trsStation))
  926. {
  927. EV.PostAlarmLog("Robot", "Invalid Parameter.");
  928. return false;
  929. }
  930. ExecuteComand(arm, pan, trsSlot, trsStation, "PICK", "STRT");
  931. SetRobotMoveInfo(arm, module, slot, RobotAction.Retracting);
  932. return true;
  933. }
  934. catch (Exception ex)
  935. {
  936. LOG.Write(ex);
  937. return false;
  938. }
  939. }
  940. protected override bool fStartRetractFromPlace(object[] param)
  941. {
  942. try
  943. {
  944. RobotArmEnum arm = (RobotArmEnum)param[0];
  945. if (arm == RobotArmEnum.Both)
  946. {
  947. EV.PostAlarmLog("Robot", "Invalid Parameter.");
  948. return false;
  949. }
  950. ModuleName module = (ModuleName)Enum.Parse(typeof(ModuleName), param[1].ToString());
  951. var slots = (int[])param[2];
  952. int slot = slots[0];
  953. ModuleName sourcemodule;
  954. if (!Enum.TryParse(CurrentParamter[1].ToString(), out sourcemodule)) return false;
  955. var pan = (Pan)CurrentParamter[3];
  956. if (slots == null || pan == Pan.None)
  957. {
  958. EV.PostAlarmLog("Robot", "Retract Place error:Invalid Parameter");
  959. return false;
  960. }
  961. Array.Sort(slots);
  962. var handSlots = Converter.MapBladeAndPanToSlot((int)CurrentParamter[0], pan);
  963. for (int i = 0; i < handSlots.Length; i++)
  964. {
  965. WaferManager.Instance.WaferMoved(RobotModuleName, handSlots[i], sourcemodule, slots[i]);
  966. }
  967. int trsSlot = GetTargetSlotByModule(module, slots);
  968. string trsStation = GetWaferSizeIndex(module, slot, module, slot);
  969. if (string.IsNullOrWhiteSpace(trsStation))
  970. {
  971. EV.PostAlarmLog("Robot", "Invalid Parameter.");
  972. return false;
  973. }
  974. ExecuteComand(arm, pan, trsSlot, trsStation, "PLACE", "STRT");
  975. SetRobotMoveInfo(arm, module, slot, RobotAction.Retracting);
  976. return true;
  977. }
  978. catch (Exception ex)
  979. {
  980. LOG.Write(ex);
  981. return false;
  982. }
  983. }
  984. protected override bool fRetractFromPickComplete(object[] param)
  985. {
  986. Blade1Target = ModuleName.System;
  987. Blade2Target = ModuleName.System;
  988. CmdTarget = ModuleName.System;
  989. MoveInfo = new RobotMoveInfo()
  990. {
  991. Action = RobotAction.Moving,
  992. ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
  993. BladeTarget = BuildBladeTarget(),
  994. };
  995. return true;
  996. }
  997. protected override bool fRetractFromPlaceComplete(object[] param)
  998. {
  999. Blade1Target = ModuleName.System;
  1000. Blade2Target = ModuleName.System;
  1001. CmdTarget = ModuleName.System;
  1002. MoveInfo = new RobotMoveInfo()
  1003. {
  1004. Action = RobotAction.Moving,
  1005. ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
  1006. BladeTarget = BuildBladeTarget(),
  1007. };
  1008. return true;
  1009. }
  1010. public override RobotArmWaferStateEnum GetWaferState(RobotArmEnum arm)
  1011. {
  1012. if (arm == RobotArmEnum.Lower)
  1013. {
  1014. if (_diRobotBlade1WaferOn != null)
  1015. {
  1016. if (_diRobotBlade1WaferOn.Value) return RobotArmWaferStateEnum.Absent;
  1017. else return RobotArmWaferStateEnum.Present;
  1018. }
  1019. return IsWaferPresenceOnBlade1 ? RobotArmWaferStateEnum.Present : RobotArmWaferStateEnum.Absent;
  1020. }
  1021. if (arm == RobotArmEnum.Upper)
  1022. {
  1023. if (_diRobotBlade2WaferOn != null)
  1024. {
  1025. if (_diRobotBlade2WaferOn.Value) return RobotArmWaferStateEnum.Absent;
  1026. else return RobotArmWaferStateEnum.Present;
  1027. }
  1028. return IsWaferPresenceOnBlade2 ? RobotArmWaferStateEnum.Present : RobotArmWaferStateEnum.Absent;
  1029. }
  1030. if (arm == RobotArmEnum.Both)
  1031. {
  1032. if (_diRobotBlade1WaferOn != null && _diRobotBlade2WaferOn != null)
  1033. {
  1034. if (_diRobotBlade2WaferOn.Value && _diRobotBlade1WaferOn.Value)
  1035. return RobotArmWaferStateEnum.Absent;
  1036. else if (!_diRobotBlade2WaferOn.Value && !_diRobotBlade1WaferOn.Value)
  1037. return RobotArmWaferStateEnum.Present;
  1038. else return RobotArmWaferStateEnum.Unknown;
  1039. }
  1040. if (IsWaferPresenceOnBlade1 && IsWaferPresenceOnBlade2)
  1041. {
  1042. return RobotArmWaferStateEnum.Present;
  1043. }
  1044. if ((!IsWaferPresenceOnBlade1) && !IsWaferPresenceOnBlade2)
  1045. {
  1046. return RobotArmWaferStateEnum.Absent;
  1047. }
  1048. }
  1049. return RobotArmWaferStateEnum.Unknown;
  1050. }
  1051. public void NoteError(string errortext)
  1052. {
  1053. OnError(errortext);
  1054. }
  1055. protected string BuildBladeTarget()
  1056. {
  1057. return (CmdRobotArm == RobotArmEnum.Upper ? "ArmB" : "ArmA") + "." + CmdTarget;
  1058. }
  1059. public override bool OnActionDone(object[] param)
  1060. {
  1061. BladeTarget = ModuleName.System;
  1062. Blade1Target = ModuleName.System;
  1063. Blade2Target = ModuleName.System;
  1064. IsBusy = false;
  1065. if (_lstHandlers.Count == 0)
  1066. {
  1067. return base.OnActionDone(param);
  1068. }
  1069. return true;
  1070. }
  1071. public override void Terminate()
  1072. {
  1073. _thread.Stop();
  1074. if (!SC.ContainsItem($"{_scRoot}.{Name}.CloseConnectionOnShutDown") || SC.GetValue<bool>($"{_scRoot}.{Name}.CloseConnectionOnShutDown"))
  1075. {
  1076. LOG.Write("Close connection for" + RobotModuleName.ToString());
  1077. _connection.Disconnect();
  1078. }
  1079. base.Terminate();
  1080. }
  1081. private bool CheckArm(RobotArmEnum arm)
  1082. {
  1083. if (arm != RobotArmEnum.Lower && arm != RobotArmEnum.Upper)
  1084. {
  1085. EV.PostAlarmLog("Robot", "Invalid Parameter.");
  1086. return false;
  1087. }
  1088. return true;
  1089. }
  1090. private Dictionary<string, int> _pairSlot = new Dictionary<string, int>()
  1091. {
  1092. {"01",1 },
  1093. {"23",2 },
  1094. {"45",3 },
  1095. {"67",4 },
  1096. };
  1097. private int GetTargetSlotByModule(ModuleName module, int[] slots)
  1098. {
  1099. if (ModuleHelper.IsPm(module)) return 1;
  1100. if (ModuleHelper.IsLoadLock(module))
  1101. {
  1102. Array.Sort(slots);
  1103. string str = string.Join("", slots);
  1104. foreach (var item in _pairSlot)
  1105. {
  1106. if (item.Key == str || item.Key.Contains(str))
  1107. {
  1108. int slot = item.Value;
  1109. if (module == ModuleName.LLB) slot += 4;
  1110. return slot;
  1111. }
  1112. }
  1113. }
  1114. EV.PostAlarmLog(Module, "TM robot get slot error ");
  1115. return 0;
  1116. }
  1117. private void ExectueCommand(string command, string strpara)
  1118. {
  1119. lock (_locker)
  1120. {
  1121. if (_lstHandlers.Count == 0 && !_connection.IsBusy)
  1122. {
  1123. ExecuteHandler(new SPaceTRanRobotMotionHandler(this, command, strpara));
  1124. }
  1125. else
  1126. {
  1127. _lstHandlers.AddLast(new SPaceTRanRobotMotionHandler(this, command, strpara));
  1128. }
  1129. }
  1130. }
  1131. private void ExecuteComand(RobotArmEnum arm, Pan pan, int trsSlot, string trsStation, string action, string flag)
  1132. {
  1133. ExectueCommand(action, GetParam(arm, pan, trsSlot, trsStation, flag));
  1134. }
  1135. private string GetWaferSizeIndex(ModuleName sourceModule, int sourceSlot, ModuleName targetModule, int targetSlot)
  1136. {
  1137. var wz = WaferManager.Instance.GetWaferSize(sourceModule, sourceSlot);
  1138. int wzindex = 0;
  1139. if (wz == WaferSize.WS12) wzindex = 12;
  1140. if (wz == WaferSize.WS8) wzindex = 8;
  1141. if (wz == WaferSize.WS6) wzindex = 6;
  1142. if (wz == WaferSize.WS4) wzindex = 4;
  1143. if (wz == WaferSize.WS3) wzindex = 3;
  1144. if (wz == WaferSize.WS0) wzindex = 8;
  1145. return ModuleHelper.IsPm(targetModule) ? SC.GetStringValue($"CarrierInfo.{targetModule}{targetSlot + 1}Station{wzindex}") : SC.GetStringValue($"CarrierInfo.{targetModule}Station{wzindex}");
  1146. }
  1147. private void SetRobotMoveInfo(RobotArmEnum arm, ModuleName module, int slot, RobotAction action)
  1148. {
  1149. CmdRobotArm = arm;
  1150. CmdTarget = module;
  1151. Blade1Target = module;
  1152. Blade2Target = module;
  1153. MoveInfo = new RobotMoveInfo()
  1154. {
  1155. Action = action,
  1156. ArmTarget = CmdRobotArm == RobotArmEnum.Lower ? RobotArm.ArmA : RobotArm.ArmB,
  1157. BladeTarget = ModuleHelper.IsPm(module) ? (BuildBladeTarget() + slot) : BuildBladeTarget(),
  1158. };
  1159. }
  1160. private string GetParam(RobotArmEnum arm, Pan pan, int slot, string station)
  1161. {
  1162. var nArm = (arm == RobotArmEnum.Lower) ? "A" : (arm == RobotArmEnum.Upper) ? "B" : "";
  1163. string strpara = $" {station} SLOT {slot} ARM {nArm}";
  1164. if (pan != Pan.Both)
  1165. {
  1166. strpara += $" PAN {Converter.MapBladeAndPanToFork((int)arm, pan).ToUpper()}";
  1167. }
  1168. return strpara;
  1169. }
  1170. private string GetParam(RobotArmEnum arm, Pan pan, int slot, string station, string flag)
  1171. {
  1172. return GetParam(arm, pan, slot, station) + $" {flag} NR";
  1173. }
  1174. }
  1175. public enum RROpModeEnum
  1176. {
  1177. Initializing,
  1178. Remote,
  1179. Maitanance,
  1180. Recovery,
  1181. }
  1182. public enum RROpStatusEnum
  1183. {
  1184. Stop,
  1185. Moving,
  1186. TempStop,
  1187. }
  1188. }