TazmoAlignerIIHandler.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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 MECF.Framework.Common.Communications;
  10. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TazmoAligners;
  11. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.TazmoAlignerIIs
  12. {
  13. public class TazmoAlignerIIHandler : HandlerBase
  14. {
  15. public TazmoAlignerII Device { get; set; }
  16. public string Command;
  17. protected TazmoAlignerIIHandler(TazmoAlignerII device, string command,string para) : base(BuildMesage(command,para))
  18. {
  19. Device = device;
  20. Command = command;
  21. Name = command;
  22. }
  23. public static byte[] BuildMesage(string data, string para)
  24. {
  25. List<byte> ret = new List<byte>();
  26. foreach(char c in data)
  27. {
  28. ret.Add((byte)c);
  29. }
  30. if (!string.IsNullOrEmpty(para))
  31. {
  32. ret.Add((byte)0x2C);
  33. foreach (char b in para) ret.Add((byte)b);
  34. }
  35. ret.Add(0x0D);
  36. return ret.ToArray();
  37. }
  38. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  39. {
  40. TazmoAlignerIIMessageBIN response = msg as TazmoAlignerIIMessageBIN;
  41. ResponseMessage = msg;
  42. transactionComplete = false;
  43. if (response.IsAck)
  44. {
  45. SetState(EnumHandlerState.Acked);
  46. transactionComplete = true;
  47. }
  48. if(response.IsBusy)
  49. {
  50. SetState(EnumHandlerState.Completed);
  51. transactionComplete = true;
  52. }
  53. if(response.IsComplete)
  54. {
  55. SetState(EnumHandlerState.Completed);
  56. transactionComplete = true;
  57. }
  58. if(response.IsError)
  59. {
  60. SetState(EnumHandlerState.Completed);
  61. transactionComplete = true;
  62. }
  63. if(response.IsNak)
  64. {
  65. SetState(EnumHandlerState.Completed);
  66. transactionComplete = true;
  67. }
  68. if(response.IsEvent)
  69. {
  70. SendAck();
  71. if (response.CMD == Encoding.ASCII.GetBytes(Command))
  72. {
  73. }
  74. SetState(EnumHandlerState.Completed);
  75. transactionComplete = true;
  76. }
  77. if(response.IsResponse)
  78. {
  79. SendAck();
  80. SetState(EnumHandlerState.Completed);
  81. transactionComplete = true;
  82. }
  83. return true;
  84. }
  85. public void SendAck()
  86. {
  87. Device.Connection.SendMessage(new byte[] { 0x06 });
  88. }
  89. public virtual void ParseStatus1(byte[] data)
  90. {
  91. try
  92. {
  93. if (data.Length < 3) return;
  94. int state1code = Convert.ToInt32(Encoding.ASCII.GetString(data), 16);
  95. Device.TaAlignerStatus1 = (TazmoState1)state1code;
  96. if (state1code >= 0x111) EV.PostAlarmLog("Aligner", $"Tazmo Aligner occurred error:{((TazmoState1)state1code).ToString()}");
  97. }
  98. catch(Exception ex)
  99. {
  100. LOG.Write("Parse Tazmo Status1 exception:" +ex);
  101. }
  102. }
  103. public virtual void ParseStatus2(byte[] data)
  104. {
  105. if (data == null || data.Length < 10) return;
  106. try
  107. {
  108. Device.TaAlignerStatus2Status = (TazmoStatus)Convert.ToInt32(Encoding.ASCII.GetString(new byte[]{ data[0]}));
  109. Device.TaAlignerStatus2Lift = (LiftStatus)Convert.ToInt32(Encoding.ASCII.GetString(new byte[] { data[2] }));
  110. Device.TaAlignerStatus2Notch = (NotchDetectionStatus)Convert.ToInt32(Encoding.ASCII.GetString(new byte[] { data[3] }));
  111. Device.TaAlignerStatus2DeviceStatus = Convert.ToInt32(Encoding.ASCII.GetString(new byte[] { data[7] }),16);
  112. Device.TaAlignerStatus2ErrorCode = Convert.ToInt32(Encoding.ASCII.GetString(new byte[] { data[8] }),16);
  113. Device.TaAlignerStatus2LastErrorCode = data[9];
  114. }
  115. catch (Exception ex)
  116. {
  117. LOG.Write($"Parse status2 exception:{ex}");
  118. }
  119. }
  120. public virtual bool PaserData(byte[] data)
  121. {
  122. return true;
  123. }
  124. }
  125. public class SingleTransactionHandler : TazmoAlignerIIHandler
  126. {
  127. public SingleTransactionHandler(TazmoAlignerII device, string command,string para) : base(device, BuildData(command),para)
  128. {
  129. }
  130. private static string BuildData(string command)
  131. {
  132. return command;
  133. }
  134. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  135. {
  136. TazmoAlignerIIMessageBIN response = msg as TazmoAlignerIIMessageBIN;
  137. ResponseMessage = msg;
  138. Device.TaExecuteSuccss = true;
  139. transactionComplete = false;
  140. if (response.IsAck)
  141. {
  142. SetState(EnumHandlerState.Completed);
  143. transactionComplete = true;
  144. }
  145. if(response.IsBusy)
  146. {
  147. SetState(EnumHandlerState.Completed);
  148. transactionComplete = true;
  149. }
  150. if(response.IsNak)
  151. {
  152. SetState(EnumHandlerState.Completed);
  153. Device.TaExecuteSuccss = false;
  154. transactionComplete = true;
  155. //ParseError(response.Data);
  156. }
  157. if(response.IsError)
  158. {
  159. SetState(EnumHandlerState.Completed);
  160. Device.TaExecuteSuccss = false;
  161. transactionComplete = true;
  162. ParseStatus1(response.Data);
  163. Device.OnError(Command + "Execute Error");
  164. }
  165. if(response.IsResponse)
  166. {
  167. SetState(EnumHandlerState.Completed);
  168. Device.TaExecuteSuccss = true;
  169. transactionComplete = true;
  170. if (Encoding.Default.GetString(response.CMD) == "STS") ParseStatus1(response.Data);
  171. if (Encoding.Default.GetString(response.CMD) == "STU") ParseStatus2(response.Data);
  172. }
  173. return true;
  174. }
  175. }
  176. public class TwinTransactionHandler:TazmoAlignerIIHandler
  177. {
  178. public TwinTransactionHandler(TazmoAlignerII device,string command,string para): base(device, BuildData(command),para)
  179. {
  180. }
  181. private static string BuildData(string command)
  182. {
  183. return command;
  184. }
  185. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  186. {
  187. TazmoAlignerIIMessageBIN response = msg as TazmoAlignerIIMessageBIN;
  188. ResponseMessage = msg;
  189. Device.TaExecuteSuccss = true;
  190. transactionComplete = false;
  191. if (response.IsAck)
  192. {
  193. SetState(EnumHandlerState.Acked);
  194. transactionComplete = false;
  195. }
  196. if (response.IsBusy)
  197. {
  198. SetState(EnumHandlerState.Completed);
  199. transactionComplete = false;
  200. Device.OnError("Busy");
  201. }
  202. if (response.IsNak)
  203. {
  204. SetState(EnumHandlerState.Completed);
  205. Device.TaExecuteSuccss = false;
  206. transactionComplete = false;
  207. Device.OnError("NAK");
  208. }
  209. if (response.IsError)
  210. {
  211. SetState(EnumHandlerState.Completed);
  212. Device.TaExecuteSuccss = false;
  213. transactionComplete = true;
  214. ParseStatus1(response.Data);
  215. Device.OnError(Command + "Execute Error");
  216. }
  217. if (response.IsResponse)
  218. {
  219. string command = Encoding.Default.GetString(response.CMD);
  220. if (command == "RST" || command == "HOM")
  221. Device.Initalized = true;
  222. SetState(EnumHandlerState.Completed);
  223. SendAck();
  224. Device.TaExecuteSuccss = true;
  225. transactionComplete = true;
  226. }
  227. return true;
  228. }
  229. }
  230. public class MoveToPickHandler : TazmoAlignerIIHandler
  231. {
  232. public MoveToPickHandler(TazmoAlignerII device, string specPos) : base(device, BuildData(specPos),null)
  233. { }
  234. private static string BuildData(string data)
  235. {
  236. return TazmoCommand.MovetopickpositionMotion + "," + data;
  237. }
  238. }
  239. public class QueryStatus1 : TazmoAlignerIIHandler
  240. {
  241. public QueryStatus1(TazmoAlignerII device) : base(device, BuildData(),null)
  242. { }
  243. private static string BuildData()
  244. {
  245. return TazmoCommand.RequeststatusStatus;
  246. }
  247. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  248. {
  249. TazmoAlignerIIMessageBIN response = msg as TazmoAlignerIIMessageBIN;
  250. ResponseMessage = msg;
  251. if (response.RawMessage == new byte[] { 0x06 }) //ACK
  252. {
  253. SetState(EnumHandlerState.Completed);
  254. transactionComplete = false; ;
  255. return true;
  256. }
  257. if (response.RawMessage == new byte[] { 0x11 })
  258. {
  259. SetState(EnumHandlerState.Completed);
  260. transactionComplete = true;
  261. //Device.Busy = true;
  262. return true;
  263. }
  264. if (response.RawMessage.Length >= 8 && Encoding.ASCII.GetString(response.RawMessage.Take(3).ToArray()) == Command)
  265. {
  266. byte[] data = response.RawMessage.Skip(4).Take(3).ToArray();
  267. ParseStatus1(data);
  268. SetState(EnumHandlerState.Completed);
  269. transactionComplete = true;
  270. //Device.Busy = false;
  271. SendAck();
  272. return true;
  273. }
  274. transactionComplete = false;
  275. return false;
  276. }
  277. }
  278. public class QueryStatus2 : TazmoAlignerIIHandler
  279. {
  280. public QueryStatus2(TazmoAlignerII device) : base(device, BuildData(), null)
  281. { }
  282. private static string BuildData()
  283. {
  284. return TazmoCommand.Requeststatus2Status;
  285. }
  286. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  287. {
  288. TazmoAlignerIIMessageBIN response = msg as TazmoAlignerIIMessageBIN;
  289. ResponseMessage = msg;
  290. if (response.RawMessage == new byte[] { 0x06 }) //ACK
  291. {
  292. SetState(EnumHandlerState.Completed);
  293. transactionComplete = false; ;
  294. return true;
  295. }
  296. if (response.RawMessage == new byte[] { 0x11 })
  297. {
  298. SetState(EnumHandlerState.Completed);
  299. transactionComplete = true;
  300. //Device.Busy = true;
  301. return true;
  302. }
  303. if(response.RawMessage.Length >= 15 && Encoding.ASCII.GetString(response.RawMessage.Take(3).ToArray()) == Command)
  304. {
  305. byte[] data = response.RawMessage.Skip(4).Take(3).ToArray();
  306. int state1code = Convert.ToInt32(Encoding.ASCII.GetString(data),16);
  307. Device.TaAlignerStatus1 = (TazmoState1)state1code;
  308. SetState(EnumHandlerState.Completed);
  309. transactionComplete = true;
  310. //Device.Busy = false;
  311. SendAck();
  312. return true;
  313. }
  314. transactionComplete = false;
  315. return false;
  316. }
  317. }
  318. public class CheckWaferPresentHandler : TazmoAlignerIIHandler
  319. {
  320. public CheckWaferPresentHandler(TazmoAlignerII device,string command) : base(device, command, null)
  321. { }
  322. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  323. {
  324. TazmoAlignerIIMessageBIN response = msg as TazmoAlignerIIMessageBIN;
  325. ResponseMessage = msg;
  326. if (response.RawMessage == new byte[] { 0x06 }) //ACK
  327. {
  328. SetState(EnumHandlerState.Completed);
  329. transactionComplete = false; ;
  330. return true;
  331. }
  332. if (response.RawMessage == new byte[] { 0x11 })
  333. {
  334. SetState(EnumHandlerState.Completed);
  335. transactionComplete = true;
  336. //Device.Busy = true;
  337. return true;
  338. }
  339. if (response.RawMessage.Length >= 5 && Encoding.ASCII.GetString(response.RawMessage.Take(3).ToArray()) == Command)
  340. {
  341. byte[] data = response.RawMessage.Skip(4).Take(1).ToArray();
  342. string strPresent = Encoding.ASCII.GetString(data);
  343. Device.IsWaferPresentByCheckResult = strPresent =="1";
  344. SetState(EnumHandlerState.Completed);
  345. transactionComplete = true;
  346. return true;
  347. }
  348. transactionComplete = false;
  349. return false;
  350. }
  351. }
  352. }