YaskawaNxcAlignerHandler.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. using Aitex.Core.RT.Log;
  2. using MECF.Framework.Common.Communications;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.YaskawaAligner
  10. {
  11. public abstract class YaskawaNxcAlignerHandler : HandlerBase
  12. {
  13. public YaskawaNxcAligner Device { get; }
  14. public string _commandType;
  15. public string _command;
  16. public string _parameter;
  17. private int _seqNO;
  18. public YaskawaNxcAlignerHandler(YaskawaNxcAligner device, string command, string parameter = null)
  19. : base(BuildMessage(command, parameter))
  20. {
  21. Device = device;
  22. _command = command;
  23. _parameter = parameter;
  24. Name = command;
  25. }
  26. protected static string BuildMessage(string command, string parameter)
  27. {
  28. if (string.IsNullOrEmpty(parameter))
  29. return command;
  30. return $"{command}{parameter}";
  31. }
  32. private static string Checksum(byte[] bytes)
  33. {
  34. int sum = 0;
  35. foreach (byte code in bytes)
  36. {
  37. sum += code;
  38. }
  39. string hex = String.Format("{0:X2}", sum % 256);
  40. return hex;
  41. }
  42. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  43. {
  44. YaskawaNxcAlignerMessage response = msg as YaskawaNxcAlignerMessage;
  45. ResponseMessage = msg;
  46. if (msg.IsError)
  47. {
  48. Device.OnError(response.RawMessage);
  49. transactionComplete = true;
  50. return true;
  51. }
  52. if (msg.IsAck)
  53. {
  54. SetState(EnumHandlerState.Acked);
  55. }
  56. if (response.IsComplete && response.RawMessage.Contains(_command))
  57. {
  58. SetState(EnumHandlerState.Completed);
  59. Device.OnActionDone(null);
  60. transactionComplete = true;
  61. return true;
  62. }
  63. transactionComplete = false;
  64. return false;
  65. }
  66. protected virtual void NoteCommandResult(YaskawaRobotMessage response)
  67. {
  68. }
  69. }
  70. public class YaskawaNxcAlignerReadHandler : YaskawaNxcAlignerHandler
  71. {
  72. public YaskawaNxcAlignerReadHandler(YaskawaNxcAligner aligner, string command, string parameter = null)
  73. : base(aligner, command, parameter)
  74. {
  75. string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
  76. LOG.Write($"{aligner.Name} execute read command {command} {temp} in ASCII.");
  77. }
  78. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  79. {
  80. YaskawaNxcAlignerMessage response = msg as YaskawaNxcAlignerMessage;
  81. if (Device.ParseReadData(_command, response.Data))
  82. {
  83. Device.OnActionDone(null);
  84. transactionComplete = true;
  85. return true;
  86. }
  87. response.IsError = true;
  88. return base.HandleMessage(response, out transactionComplete);
  89. }
  90. }
  91. public class YaskawaNxcAlignerSetHandler : YaskawaNxcAlignerHandler
  92. {
  93. public YaskawaNxcAlignerSetHandler(YaskawaNxcAligner pa, string command, string parameter = null)
  94. : base(pa, command, parameter)
  95. {
  96. string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
  97. LOG.Write($"{pa.Name} execute set command {command} {temp} in ASCII.");
  98. }
  99. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  100. {
  101. YaskawaRobotMessage response = msg as YaskawaRobotMessage;
  102. if (response.IsComplete && response.RawMessage.Contains(_command))
  103. {
  104. Device.OnActionDone(null);
  105. transactionComplete = true;
  106. return true;
  107. }
  108. return base.HandleMessage(response, out transactionComplete);
  109. }
  110. }
  111. public class YaskawaNxcAlignerMotionHandler : YaskawaNxcAlignerHandler
  112. {
  113. public YaskawaNxcAlignerMotionHandler(YaskawaNxcAligner pa, string command, string parameter = null)
  114. : base(pa, command, parameter)
  115. {
  116. string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
  117. LOG.Write($"{pa.Name} execute motion command {command} {temp} in ASCII.");
  118. }
  119. }
  120. public class YaskawaNxcAlignerGripAndDetectHandler : YaskawaNxcAlignerHandler
  121. {
  122. public YaskawaNxcAlignerGripAndDetectHandler(YaskawaNxcAligner pa)
  123. : base(pa, "CSOL", "A1")
  124. {
  125. LOG.Write($"{pa.Name} execute motion command CSOL A1 in ASCII.");
  126. }
  127. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  128. {
  129. YaskawaRobotMessage response = msg as YaskawaRobotMessage;
  130. ResponseMessage = msg;
  131. if (msg.IsError)
  132. {
  133. Device.OnError(response.RawMessage);
  134. transactionComplete = true;
  135. return true;
  136. }
  137. if (msg.IsAck)
  138. {
  139. SetState(EnumHandlerState.Acked);
  140. }
  141. if (response.IsComplete && response.RawMessage.Contains(_command))
  142. {
  143. SetState(EnumHandlerState.Completed);
  144. Thread.Sleep(1000);
  145. Device.CheckWaferPresentAndGrip();
  146. Device.OnActionDone(null);
  147. transactionComplete = true;
  148. return true;
  149. }
  150. transactionComplete = false;
  151. return false;
  152. }
  153. }
  154. }