HirataIILoadPortHandler.cs 19 KB

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