SELP8LoadPortHandler.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Aitex.Core.Common.DeviceData;
  7. using Aitex.Core.RT.Event;
  8. using Aitex.Core.RT.Log;
  9. using Aitex.Sorter.Common;
  10. using MECF.Framework.Common.Communications;
  11. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.SG
  12. {
  13. public class SELP8LoadPortHandler : HandlerBase
  14. {
  15. public SELP8LoadPort Device { get; set; }
  16. public string Command;
  17. protected SELP8LoadPortHandler(SELP8LoadPort device, string command, string para) : base(BuildMesage(command, para))
  18. {
  19. Device = device;
  20. Command = command;
  21. Name = command;
  22. }
  23. public static string BuildMesage(string command, string para)
  24. {
  25. if(string.IsNullOrEmpty(para))
  26. return $"s00{command};\r\n";
  27. return $"s00{command}{para};\r\n";
  28. }
  29. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  30. {
  31. SELP8LoadPortMessage response = msg as SELP8LoadPortMessage;
  32. ResponseMessage = msg;
  33. transactionComplete = false;
  34. if (response.IsAck)
  35. {
  36. SetState(EnumHandlerState.Acked);
  37. transactionComplete = true;
  38. }
  39. if (response.IsError)
  40. {
  41. SetState(EnumHandlerState.Completed);
  42. transactionComplete = true;
  43. }
  44. if (response.IsNak)
  45. {
  46. SetState(EnumHandlerState.Completed);
  47. transactionComplete = true;
  48. }
  49. if (response.IsEvent)
  50. {
  51. SendAck();
  52. if (response.Command.Contains(Command))
  53. {
  54. SetState(EnumHandlerState.Completed);
  55. transactionComplete = true;
  56. }
  57. }
  58. return true;
  59. }
  60. public void HandleEvent(string content)
  61. {
  62. }
  63. public void SendAck()
  64. {
  65. //Device.Connection.SendMessage(new byte[] { 0x06 });
  66. }
  67. public void Retry()
  68. {
  69. }
  70. public virtual bool PaseData(byte[] data)
  71. {
  72. return true;
  73. }
  74. }
  75. public class SELP8SetHandler : SELP8LoadPortHandler
  76. {
  77. private string setcommand;
  78. public SELP8SetHandler(SELP8LoadPort device, string command, string para) : base(device, BuildData(command), para)
  79. {
  80. setcommand = command;
  81. }
  82. private static string BuildData(string command)
  83. {
  84. return "SET:" + command;
  85. }
  86. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  87. {
  88. SELP8LoadPortMessage response = msg as SELP8LoadPortMessage;
  89. ResponseMessage = msg;
  90. //Device.TaExecuteSuccss = true;
  91. transactionComplete = false;
  92. if (response.IsAck)
  93. {
  94. SetState(EnumHandlerState.Acked);
  95. transactionComplete = true;
  96. if (setcommand.Contains("RESET")
  97. || setcommand.Contains("INITL"))
  98. transactionComplete = false;
  99. }
  100. if (response.IsBusy)
  101. {
  102. SetState(EnumHandlerState.Completed);
  103. transactionComplete = true;
  104. }
  105. if (response.IsNak)
  106. {
  107. SetState(EnumHandlerState.Completed);
  108. transactionComplete = true;
  109. //ParseError(response.Data);
  110. }
  111. if (response.IsError)
  112. {
  113. SetState(EnumHandlerState.Completed);
  114. transactionComplete = true;
  115. }
  116. if (response.IsEvent)
  117. {
  118. SendAck();
  119. if (response.Command.Contains(setcommand))
  120. {
  121. SetState(EnumHandlerState.Completed);
  122. transactionComplete = true;
  123. }
  124. else
  125. HandleEvent(response.Command);
  126. transactionComplete = true;
  127. }
  128. //if (setcommand == "RESET")
  129. //{
  130. // transactionComplete = true;
  131. //}
  132. return true;
  133. }
  134. }
  135. public class SELP8GetHandler : SELP8LoadPortHandler
  136. {
  137. public SELP8GetHandler(SELP8LoadPort device, string command, string para) : base(device, BuildData(command), para)
  138. {
  139. }
  140. private static string BuildData(string command)
  141. {
  142. return "GET:" + command;
  143. }
  144. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  145. {
  146. SELP8LoadPortMessage response = msg as SELP8LoadPortMessage;
  147. ResponseMessage = msg;
  148. //Device.TaExecuteSuccss = true;
  149. transactionComplete = false;
  150. if (response.IsAck)
  151. {
  152. SetState(EnumHandlerState.Acked);
  153. transactionComplete = true;
  154. ParseData(response.Command);
  155. }
  156. if (response.IsNak)
  157. {
  158. SetState(EnumHandlerState.Completed);
  159. transactionComplete = true;
  160. //ParseNakData(response.Command);
  161. }
  162. return true;
  163. }
  164. public void ParseData(string cmddata)
  165. {
  166. try
  167. {
  168. if (cmddata.Contains("STATE"))
  169. {
  170. byte[] data = Encoding.ASCII.GetBytes(cmddata.Replace("STATE/", ""));
  171. if (data.Length < 20) return;
  172. Device.SystemStatus = (TDKSystemStatus)data[0];
  173. Device.Mode = (TDKMode)data[1];
  174. Device.InitPosMovement = (TDKInitPosMovement)data[2];
  175. Device.OperationStatus = (TDKOperationStatus)data[3];
  176. Device.ErrorCode = Encoding.ASCII.GetString(new byte[] { data[4], data[5] });
  177. Device.ContainerStatus = (TDKContainerStatus)data[6];
  178. Device.ClampPosition = (TDKPosition)data[7];
  179. Device.LPDoorLatchPosition = (TDKPosition)data[8];
  180. Device.VacuumStatus = (TDKVacummStatus)data[9];
  181. Device.LPDoorState = (TDKPosition)data[10];
  182. Device.WaferProtrusion = (TDKWaferProtrusion)data[11];
  183. Device.ElevatorAxisPosition = (TDKElevatorAxisPosition)data[12];
  184. Device.DockPosition = (TDKDockPosition)data[13];
  185. Device.MapperPostion = (TDKMapPosition)data[14];
  186. Device.MappingStatus = (TDKMappingStatus)data[17];
  187. Device.Model = (TDKModel)data[18];
  188. int infopadstatus = Convert.ToInt16($"0x{Encoding.ASCII.GetString(new byte[] { data[19] })}", 16);
  189. int indexValue = (((infopadstatus & 1) != 0) ? 8 : 0) + (((infopadstatus & 2) != 0) ? 4 : 0) +
  190. (((infopadstatus & 4) != 0) ? 2 : 0) + (((infopadstatus & 8) != 0) ? 1 : 0);
  191. Device.LPSetInfoPadSensorIndex(indexValue);
  192. Device.IsError = Device.SystemStatus != TDKSystemStatus.Normal;
  193. Device.ErrorCode = Encoding.ASCII.GetString(new byte[] { data[4], data[5] });
  194. LoadportCassetteState st = LoadportCassetteState.None;
  195. if (Device.ContainerStatus == TDKContainerStatus.Absence) st = LoadportCassetteState.Absent;
  196. if (Device.ContainerStatus == TDKContainerStatus.NormalMount) st = LoadportCassetteState.Normal;
  197. if (Device.ContainerStatus == TDKContainerStatus.MountError) st = LoadportCassetteState.Unknown;
  198. Device.SetCassetteState(st);
  199. if (Device.ClampPosition == TDKPosition.Close)
  200. Device.ClampState = FoupClampState.Close;
  201. else if (Device.ClampPosition == TDKPosition.Open)
  202. Device.ClampState = FoupClampState.Open;
  203. else if (Device.ClampPosition == TDKPosition.TBD)
  204. Device.ClampState = FoupClampState.Unknown;
  205. if (Device.LPDoorState == TDKPosition.Close)
  206. Device.DoorState = FoupDoorState.Close;
  207. if (Device.LPDoorState == TDKPosition.Open)
  208. Device.DoorState = FoupDoorState.Open;
  209. if (Device.LPDoorState == TDKPosition.TBD)
  210. Device.DoorState = FoupDoorState.Unknown;
  211. Device.DockState = ConvertTDKDockPositin(Device.DockPosition); // Load port dock state
  212. if (Device.ElevatorAxisPosition == TDKElevatorAxisPosition.UP)
  213. Device.DoorPosition = FoupDoorPostionEnum.Up;
  214. if (Device.ElevatorAxisPosition == TDKElevatorAxisPosition.Down)
  215. Device.DoorPosition = FoupDoorPostionEnum.Down; // = TDKZ_AxisPos.Down;
  216. if (Device.ElevatorAxisPosition == TDKElevatorAxisPosition.MappingEndPos)
  217. Device.DoorPosition = FoupDoorPostionEnum.MapEnd;// = TDKZ_AxisPos.End;
  218. if (Device.ElevatorAxisPosition == TDKElevatorAxisPosition.MappingStartPos)
  219. Device.DoorPosition = FoupDoorPostionEnum.MapStart;// = TDKZ_AxisPos.Start;
  220. if (Device.ElevatorAxisPosition == TDKElevatorAxisPosition.TBD)
  221. Device.DoorPosition = FoupDoorPostionEnum.Unknown;// = TDKZ_AxisPos.Unknown;
  222. }
  223. if (cmddata.Contains("VERSN/"))
  224. {
  225. }
  226. if (cmddata.Contains("LEDST/"))
  227. {
  228. IndicatorState[] lpledstate = new IndicatorState[]
  229. {
  230. Device.IndicatiorPresence,
  231. Device.IndicatiorPlacement,
  232. Device.IndicatiorLoad,
  233. Device.IndicatiorUnload,
  234. Device.IndicatiorOpAccess,
  235. Device.IndicatiorStatus1,
  236. Device.IndicatiorStatus2,
  237. };
  238. char[] ledstate = cmddata.Replace("LEDST/", "").ToArray();
  239. for (int i = 0; i < (lpledstate.Length > ledstate.Length ? ledstate.Length : lpledstate.Length); i++)
  240. {
  241. if (ledstate[i] == '0') SetIEDValue(i, IndicatorState.OFF);
  242. if (ledstate[i] == '1') SetIEDValue(i, IndicatorState.ON);
  243. if (ledstate[i] == '2') SetIEDValue(i, IndicatorState.BLINK);
  244. }
  245. }
  246. if (cmddata.Contains("MAPRD/"))
  247. {
  248. string str1 = cmddata.Replace("MAPRD/", "");
  249. Device.OnSlotMapRead(str1);
  250. }
  251. if (cmddata.Contains("MPENC/"))
  252. {
  253. string str1 = cmddata.Replace("MPENC/", "");
  254. if (str1.Contains("NOMAP"))
  255. {
  256. Device.WaferPositionData.AddFirst(new Tuple<int, int>(0, 0));
  257. return;
  258. }
  259. if (str1.Length <= 7) return;
  260. int startPos = Convert.ToInt32(str1.Substring(0, 7));
  261. int endPos = Convert.ToInt32(str1.Substring(7));
  262. Device.WaferPositionData.AddFirst(new Tuple<int, int>(startPos, endPos));
  263. }
  264. if (cmddata.Contains("WFCNT/"))
  265. {
  266. Device.WaferCount = Convert.ToInt16(cmddata.Replace("WFCNT/", ""));
  267. }
  268. if (cmddata.Contains("MDAH/"))
  269. {
  270. }
  271. if (cmddata.Contains("LPIOI/"))
  272. {
  273. }
  274. if (cmddata.Contains("FSBxx/"))
  275. {
  276. if (cmddata.Contains("ON"))
  277. Device.IsFosbModeActual = true;
  278. if (cmddata.Contains("OF"))
  279. Device.IsFosbModeActual = false;
  280. }
  281. }
  282. catch(Exception ex)
  283. {
  284. LOG.Write(ex);
  285. }
  286. }
  287. public void ParseNakData(string cmddata)
  288. {
  289. try
  290. {
  291. if (cmddata.Contains("MPENC/NOMAP"))
  292. {
  293. Device.WaferPositionData.AddFirst(new Tuple<int, int>(0, 0));
  294. return;
  295. }
  296. }
  297. catch (Exception ex)
  298. {
  299. LOG.Write(ex);
  300. }
  301. }
  302. private void SetIEDValue(int index, IndicatorState state)
  303. {
  304. switch (index)
  305. {
  306. case 0:
  307. Device.IndicatiorPresence = state;
  308. break;
  309. case 1:
  310. Device.IndicatiorPlacement = state;
  311. break;
  312. case 2:
  313. Device.IndicatiorLoad = state;
  314. break;
  315. case 3:
  316. Device.IndicatiorUnload = state;
  317. break;
  318. case 4:
  319. Device.IndicatiorOpAccess = state;
  320. break;
  321. case 5:
  322. Device.IndicatiorStatus1 = state;
  323. break;
  324. case 6:
  325. Device.IndicatiorStatus2 = state;
  326. break;
  327. default:
  328. break;
  329. }
  330. }
  331. private FoupDockState ConvertTDKDockPositin(TDKDockPosition dockPosition)
  332. {
  333. if (dockPosition == TDKDockPosition.Dock) return FoupDockState.Docked;
  334. if (dockPosition == TDKDockPosition.Undock) return FoupDockState.Undocked;
  335. return FoupDockState.Unknown;
  336. }
  337. }
  338. public class SELP8ModHandler : SELP8LoadPortHandler
  339. {
  340. public SELP8ModHandler(SELP8LoadPort device, string command, string para) : base(device, BuildData(command), para)
  341. {
  342. }
  343. private static string BuildData(string command)
  344. {
  345. return "MOD:" + command;
  346. }
  347. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  348. {
  349. SELP8LoadPortMessage response = msg as SELP8LoadPortMessage;
  350. ResponseMessage = msg;
  351. //Device.TaExecuteSuccss = true;
  352. transactionComplete = false;
  353. if (response.IsAck)
  354. {
  355. SetState(EnumHandlerState.Acked);
  356. transactionComplete = true;
  357. }
  358. if (response.IsNak)
  359. {
  360. SetState(EnumHandlerState.Completed);
  361. transactionComplete = true;
  362. //ParseError(response.Data);
  363. }
  364. return true;
  365. }
  366. public void ParseData(byte[] cmd)
  367. {
  368. }
  369. }
  370. public class SELP8MoveHandler : SELP8LoadPortHandler
  371. {
  372. private string moveCommand;
  373. public SELP8MoveHandler(SELP8LoadPort device, string command, string para) : base(device, BuildData(command), para)
  374. {
  375. moveCommand = command;
  376. }
  377. private static string BuildData(string command)
  378. {
  379. return "MOV:" + command;
  380. }
  381. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  382. {
  383. SELP8LoadPortMessage response = msg as SELP8LoadPortMessage;
  384. ResponseMessage = msg;
  385. //Device.TaExecuteSuccss = true;
  386. transactionComplete = false;
  387. if (response.IsAck)
  388. {
  389. SetState(EnumHandlerState.Acked);
  390. transactionComplete = false;
  391. }
  392. if (response.IsNak)
  393. {
  394. SetState(EnumHandlerState.Completed);
  395. transactionComplete = true;
  396. //ParseError(response.Data);
  397. }
  398. if (response.IsError)
  399. {
  400. SetState(EnumHandlerState.Completed);
  401. transactionComplete = true;
  402. }
  403. if (response.IsEvent)
  404. {
  405. if (response.Command.Contains("ORGSH") || response.Command.Contains("ABORG"))
  406. {
  407. Device.OnHomed();
  408. }
  409. if (response.Command.Contains(moveCommand))
  410. {
  411. SetState(EnumHandlerState.Completed);
  412. transactionComplete = true;
  413. }
  414. }
  415. return true;
  416. }
  417. public void ParseData(byte[] cmd)
  418. {
  419. }
  420. }
  421. public class SELP8EvtHandler : SELP8LoadPortHandler
  422. {
  423. private string setcommand;
  424. public SELP8EvtHandler(SELP8LoadPort device, string command, string para) : base(device, BuildData(command), para)
  425. {
  426. setcommand = command;
  427. }
  428. private static string BuildData(string command)
  429. {
  430. return "EVT:" + command;
  431. }
  432. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  433. {
  434. SELP8LoadPortMessage response = msg as SELP8LoadPortMessage;
  435. ResponseMessage = msg;
  436. //Device.TaExecuteSuccss = true;
  437. transactionComplete = false;
  438. if (response.IsAck)
  439. {
  440. SetState(EnumHandlerState.Acked);
  441. transactionComplete = true;
  442. }
  443. if (response.IsBusy)
  444. {
  445. SetState(EnumHandlerState.Completed);
  446. transactionComplete = true;
  447. }
  448. if (response.IsNak)
  449. {
  450. SetState(EnumHandlerState.Completed);
  451. transactionComplete = true;
  452. //ParseError(response.Data);
  453. }
  454. if (response.IsError)
  455. {
  456. SetState(EnumHandlerState.Completed);
  457. transactionComplete = true;
  458. }
  459. if (response.IsEvent)
  460. {
  461. SendAck();
  462. if (response.Command.Contains(setcommand))
  463. {
  464. SetState(EnumHandlerState.Completed);
  465. }
  466. else
  467. HandleEvent(response.Command);
  468. transactionComplete = true;
  469. }
  470. return true;
  471. }
  472. }
  473. }