TazmoAlignerHandler.cs 15 KB

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