TDKLoadPortHandler.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  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.TDKII
  12. {
  13. public class TDKLoadPortHandler : HandlerBase
  14. {
  15. public TDKIILoadPort Device { get; set; }
  16. public string Command;
  17. protected TDKLoadPortHandler(TDKIILoadPort 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 data, string para)
  24. {
  25. List<byte> ret = new List<byte>();
  26. ret.Add(0x1);
  27. List<byte> cmd = new List<byte>();
  28. foreach (char c in data)
  29. {
  30. cmd.Add((byte)c);
  31. }
  32. //cmd.Add((byte)(':')); //3A
  33. if (!string.IsNullOrEmpty(para))
  34. foreach (char c in para)
  35. {
  36. cmd.Add((byte)c);
  37. }
  38. cmd.Add((byte)(';')); //3B
  39. int length = cmd.Count + 4;
  40. int checksum = length + 0x30 + 0x30;
  41. foreach (byte bvalue in cmd)
  42. {
  43. checksum += bvalue;
  44. }
  45. byte[] byteschecksum = Encoding.ASCII.GetBytes(Convert.ToString((int)((byte)(checksum & 0xFF)), 16));
  46. byte[] blength = BitConverter.GetBytes((short)length);
  47. ret.Add(blength[1]);
  48. ret.Add(blength[0]);
  49. //ret.AddRange(new byte[] { 0x30, 0x30 });
  50. ret.AddRange(new byte[] { 0x30, 0x30 });
  51. ret.AddRange(cmd);
  52. ret.AddRange(byteschecksum);
  53. ret.Add(0xD);
  54. return Encoding.ASCII.GetString(ret.ToArray());
  55. }
  56. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  57. {
  58. TDKLoadPortMessage response = msg as TDKLoadPortMessage;
  59. ResponseMessage = msg;
  60. transactionComplete = false;
  61. if (response.IsAck)
  62. {
  63. SetState(EnumHandlerState.Acked);
  64. transactionComplete = true;
  65. }
  66. if (response.IsError)
  67. {
  68. SetState(EnumHandlerState.Completed);
  69. transactionComplete = true;
  70. }
  71. if (response.IsNak)
  72. {
  73. SetState(EnumHandlerState.Completed);
  74. transactionComplete = true;
  75. }
  76. if (response.IsEvent)
  77. {
  78. SendAck();
  79. if (response.Command.Contains(Command))
  80. {
  81. SetState(EnumHandlerState.Completed);
  82. transactionComplete = true;
  83. }
  84. }
  85. return true;
  86. }
  87. public void HandleEvent(string content)
  88. {
  89. }
  90. public void SendAck()
  91. {
  92. //Device.Connection.SendMessage(new byte[] { 0x06 });
  93. }
  94. public void Retry()
  95. {
  96. }
  97. public virtual bool PaseData(byte[] data)
  98. {
  99. return true;
  100. }
  101. }
  102. public class TDKSetHandler : TDKLoadPortHandler
  103. {
  104. private string setcommand;
  105. public TDKSetHandler(TDKIILoadPort device, string command, string para) : base(device, BuildData(command), para)
  106. {
  107. setcommand = command;
  108. }
  109. private static string BuildData(string command)
  110. {
  111. return "SET:" + command;
  112. }
  113. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  114. {
  115. TDKLoadPortMessage response = msg as TDKLoadPortMessage;
  116. ResponseMessage = msg;
  117. //Device.TaExecuteSuccss = true;
  118. transactionComplete = false;
  119. if (response.IsAck)
  120. {
  121. SetState(EnumHandlerState.Acked);
  122. transactionComplete = false;
  123. if(setcommand.Contains("FSB"))
  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 TDKGetHandler : TDKLoadPortHandler
  162. {
  163. public TDKGetHandler(TDKIILoadPort 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. TDKLoadPortMessage response = msg as TDKLoadPortMessage;
  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. if(Device.InfoPadType == 0)
  213. Device.InfoPadCarrierIndex = Convert.ToInt16($"0x{data[19]}", 16);
  214. Device.IsError = Device.SystemStatus != TDKSystemStatus.Normal;
  215. Device.ErrorCode = Encoding.ASCII.GetString(new byte[] { data[4], data[5] });
  216. LoadportCassetteState st = LoadportCassetteState.None;
  217. if (Device.ContainerStatus == TDKContainerStatus.Absence) st = LoadportCassetteState.Absent;
  218. if (Device.ContainerStatus == TDKContainerStatus.NormalMount) st = LoadportCassetteState.Normal;
  219. if (Device.ContainerStatus == TDKContainerStatus.MountError) st = LoadportCassetteState.Unknown;
  220. Device.SetCassetteState(st);
  221. if (Device.ClampPosition == TDKPosition.Close)
  222. Device.ClampState = FoupClampState.Close;
  223. else if (Device.ClampPosition == TDKPosition.Open)
  224. Device.ClampState = FoupClampState.Open;
  225. else if (Device.ClampPosition == TDKPosition.TBD)
  226. Device.ClampState = FoupClampState.Unknown;
  227. if (Device.LPDoorState == TDKPosition.Close)
  228. Device.DoorState = FoupDoorState.Close;
  229. if (Device.LPDoorState == TDKPosition.Open)
  230. Device.DoorState = FoupDoorState.Open;
  231. if (Device.LPDoorState == TDKPosition.TBD)
  232. Device.DoorState = FoupDoorState.Unknown;
  233. Device.DockState = ConvertTDKDockPositin(Device.DockPosition); // Load port dock state
  234. if (Device.ElevatorAxisPosition == TDKElevatorAxisPosition.UP)
  235. Device.DoorPosition = FoupDoorPostionEnum.Up;
  236. if (Device.ElevatorAxisPosition == TDKElevatorAxisPosition.Down)
  237. Device.DoorPosition = FoupDoorPostionEnum.Down; // = TDKZ_AxisPos.Down;
  238. if (Device.ElevatorAxisPosition == TDKElevatorAxisPosition.MappingEndPos)
  239. Device.DoorPosition = FoupDoorPostionEnum.MapEnd;// = TDKZ_AxisPos.End;
  240. if (Device.ElevatorAxisPosition == TDKElevatorAxisPosition.MappingStartPos)
  241. Device.DoorPosition = FoupDoorPostionEnum.MapStart;// = TDKZ_AxisPos.Start;
  242. if (Device.ElevatorAxisPosition == TDKElevatorAxisPosition.TBD)
  243. Device.DoorPosition = FoupDoorPostionEnum.Unknown;// = TDKZ_AxisPos.Unknown;
  244. }
  245. if (cmddata.Contains("VERSN/"))
  246. {
  247. }
  248. if (cmddata.Contains("LEDST/"))
  249. {
  250. IndicatorState[] lpledstate = new IndicatorState[]
  251. {
  252. Device.IndicatiorPresence,
  253. Device.IndicatiorPlacement,
  254. Device.IndicatiorLoad,
  255. Device.IndicatiorUnload,
  256. Device.IndicatiorOpAccess,
  257. Device.IndicatiorStatus1,
  258. Device.IndicatiorStatus2,
  259. };
  260. char[] ledstate = cmddata.Replace("LEDST/", "").ToArray();
  261. for (int i = 0; i < (lpledstate.Length > ledstate.Length ? ledstate.Length : lpledstate.Length); i++)
  262. {
  263. if (ledstate[i] == '0') lpledstate[i] = IndicatorState.OFF;
  264. if (ledstate[i] == '1') lpledstate[i] = IndicatorState.ON;
  265. if (ledstate[i] == '2') lpledstate[i] = IndicatorState.BLINK;
  266. }
  267. }
  268. if (cmddata.Contains("MAPRD/"))
  269. {
  270. string str1 = cmddata.Replace("MAPRD/", "");
  271. Device.OnSlotMapRead(str1);
  272. }
  273. if (cmddata.Contains("WFCNT/"))
  274. {
  275. Device.WaferCount = Convert.ToInt16(cmddata.Replace("WFCNT/", ""));
  276. }
  277. if (cmddata.Contains("MDAH/"))
  278. {
  279. }
  280. if (cmddata.Contains("LPIOI/"))
  281. {
  282. }
  283. if(cmddata.Contains("FSBxx/"))
  284. {
  285. if (cmddata.Contains("ON"))
  286. Device.IsFosbModeActual = true;
  287. if (cmddata.Contains("OF"))
  288. Device.IsFosbModeActual = false;
  289. }
  290. }
  291. private FoupDockState ConvertTDKDockPositin(TDKDockPosition dockPosition)
  292. {
  293. if (dockPosition == TDKDockPosition.Dock) return FoupDockState.Docked;
  294. if (dockPosition == TDKDockPosition.Undock) return FoupDockState.Undocked;
  295. return FoupDockState.Unknown;
  296. }
  297. }
  298. public class TDKModHandler : TDKLoadPortHandler
  299. {
  300. public TDKModHandler(TDKIILoadPort device, string command, string para) : base(device, BuildData(command), para)
  301. {
  302. }
  303. private static string BuildData(string command)
  304. {
  305. return "MOD:" + command;
  306. }
  307. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  308. {
  309. TDKLoadPortMessage response = msg as TDKLoadPortMessage;
  310. ResponseMessage = msg;
  311. //Device.TaExecuteSuccss = true;
  312. transactionComplete = false;
  313. if (response.IsAck)
  314. {
  315. SetState(EnumHandlerState.Acked);
  316. transactionComplete = true;
  317. }
  318. if (response.IsNak)
  319. {
  320. SetState(EnumHandlerState.Completed);
  321. transactionComplete = true;
  322. //ParseError(response.Data);
  323. }
  324. return true;
  325. }
  326. public void ParseData(byte[] cmd)
  327. {
  328. }
  329. }
  330. public class TDKMoveHandler : TDKLoadPortHandler
  331. {
  332. private string moveCommand;
  333. public TDKMoveHandler(TDKIILoadPort device, string command, string para) : base(device, BuildData(command), para)
  334. {
  335. moveCommand = command;
  336. }
  337. private static string BuildData(string command)
  338. {
  339. return "MOV:" + command;
  340. }
  341. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  342. {
  343. TDKLoadPortMessage response = msg as TDKLoadPortMessage;
  344. ResponseMessage = msg;
  345. //Device.TaExecuteSuccss = true;
  346. transactionComplete = false;
  347. if (response.IsAck)
  348. {
  349. SetState(EnumHandlerState.Acked);
  350. transactionComplete = false;
  351. }
  352. if (response.IsNak)
  353. {
  354. SetState(EnumHandlerState.Completed);
  355. transactionComplete = true;
  356. //ParseError(response.Data);
  357. }
  358. if (response.IsError)
  359. {
  360. SetState(EnumHandlerState.Completed);
  361. transactionComplete = true;
  362. }
  363. if (response.IsEvent)
  364. {
  365. if (response.Command.Contains("ORGSH") || response.Command.Contains("ABORG"))
  366. {
  367. Device.OnHomed();
  368. }
  369. if (response.Command.Contains(moveCommand))
  370. {
  371. SetState(EnumHandlerState.Completed);
  372. transactionComplete = true;
  373. }
  374. }
  375. return true;
  376. }
  377. public void ParseData(byte[] cmd)
  378. {
  379. }
  380. }
  381. }