YaskawaAlignerHandler.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 YaskawaAlignerHandler : HandlerBase
  12. {
  13. public YaskawaAligner Device { get; }
  14. public string _commandType;
  15. public string _command;
  16. public string _parameter;
  17. private int _seqNO;
  18. public YaskawaAlignerHandler(YaskawaAligner 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. YaskawaRobotMessage response = msg as YaskawaRobotMessage;
  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)
  57. {
  58. SetState(EnumHandlerState.Completed);
  59. //Device.SenACK();
  60. Device.OnActionDone(null);
  61. transactionComplete = true;
  62. return true;
  63. }
  64. transactionComplete = false;
  65. return false;
  66. }
  67. protected virtual void NoteCommandResult(YaskawaRobotMessage response)
  68. {
  69. }
  70. }
  71. public class YaskawaAlignerReadHandler : YaskawaAlignerHandler
  72. {
  73. public YaskawaAlignerReadHandler(YaskawaAligner aligner, string command, string parameter = null)
  74. : base(aligner, command, parameter)
  75. {
  76. string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
  77. LOG.Write($"{aligner.Name} execute read command {command} {temp} in ASCII.");
  78. }
  79. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  80. {
  81. YaskawaRobotMessage response = msg as YaskawaRobotMessage;
  82. if (Device.ParseReadData(_command, response.Data))
  83. {
  84. Device.OnActionDone(null);
  85. transactionComplete = true;
  86. return true;
  87. }
  88. response.IsError = true;
  89. return base.HandleMessage(response, out transactionComplete);
  90. }
  91. }
  92. public class YaskawaAlignerSetHandler : YaskawaAlignerHandler
  93. {
  94. public YaskawaAlignerSetHandler(YaskawaAligner pa, string command, string parameter = null)
  95. : base(pa, command, parameter)
  96. {
  97. string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
  98. LOG.Write($"{pa.Name} execute set command {command} {temp} in ASCII.");
  99. }
  100. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  101. {
  102. YaskawaRobotMessage response = msg as YaskawaRobotMessage;
  103. if (response.IsComplete)
  104. {
  105. Device.OnActionDone(null);
  106. transactionComplete = true;
  107. return true;
  108. }
  109. return base.HandleMessage(response, out transactionComplete);
  110. }
  111. }
  112. public class YaskawaAlignerMotionHandler : YaskawaAlignerHandler
  113. {
  114. public YaskawaAlignerMotionHandler(YaskawaAligner pa, string command, string parameter = null)
  115. : base(pa, command, parameter)
  116. {
  117. string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
  118. LOG.Write($"{pa.Name} execute motion command {command} {temp} in ASCII.");
  119. }
  120. }
  121. public class YaskawaAlignerGripAndDetectHandler : YaskawaAlignerHandler
  122. {
  123. public YaskawaAlignerGripAndDetectHandler(YaskawaAligner pa)
  124. : base(pa, "CSOL", "1,1,0")
  125. {
  126. LOG.Write($"{pa.Name} execute motion command CSOL 1,1,0 in ASCII.");
  127. }
  128. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  129. {
  130. YaskawaRobotMessage response = msg as YaskawaRobotMessage;
  131. ResponseMessage = msg;
  132. if (msg.IsError)
  133. {
  134. Device.OnError(response.RawMessage);
  135. transactionComplete = true;
  136. return true;
  137. }
  138. if (msg.IsAck)
  139. {
  140. SetState(EnumHandlerState.Acked);
  141. }
  142. if (response.IsComplete)
  143. {
  144. SetState(EnumHandlerState.Completed);
  145. //Device.SenACK();
  146. Thread.Sleep(1000);
  147. Device.CheckWaferPresentAndGrip();
  148. Device.OnActionDone(null);
  149. transactionComplete = true;
  150. return true;
  151. }
  152. transactionComplete = false;
  153. return false;
  154. }
  155. }
  156. }