AlignerHandler.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. using System;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Sorter.Common;
  4. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot.NX100.AL
  5. {
  6. public class AlignerHandler : ITransferMsg
  7. {
  8. public bool background { get; protected set; }
  9. public bool evt { get { return false; } }
  10. public string deviceID { private get; set; }
  11. public string _cmd = string.Empty;
  12. public IDevice Robot { set { _device = (Aligner)value; } }
  13. protected Aligner _device;
  14. public AlignerHandler()
  15. {
  16. background = false;
  17. }
  18. public virtual string package(params object[] args)
  19. {
  20. return "";
  21. }
  22. public bool unpackage(string type, string[] items)
  23. {
  24. int value = Convert.ToInt32(items[3], 16);
  25. _device.Status = value;
  26. int error = Convert.ToInt32(items[4], 16);
  27. _device.ErrorCode = error;
  28. if (error > 0)
  29. _device.LastErrorCode = error;
  30. if (type.Equals(ProtocolTag.resp_tag_excute))
  31. {
  32. if (error == 0)
  33. {
  34. update(items);
  35. }
  36. return true;
  37. }
  38. return !background;
  39. }
  40. protected virtual void update(string[] data)
  41. {
  42. }
  43. }
  44. public class AlInitHandler : AlignerHandler
  45. {
  46. public AlInitHandler()
  47. {
  48. background = true;
  49. }
  50. public override string package(params object[] args)
  51. {
  52. return ",INIT,00,";
  53. }
  54. protected override void update(string[] data)
  55. {
  56. _device.Initalized = true;
  57. }
  58. }
  59. public class AlHomeHandler : AlignerHandler
  60. {
  61. public AlHomeHandler()
  62. {
  63. background = true;
  64. }
  65. public override string package(params object[] args)
  66. {
  67. return ",MHOM,F,";
  68. }
  69. protected override void update(string[] data)
  70. {
  71. _device.Initalized = true;
  72. }
  73. }
  74. public class AlClearErrorHandler : AlignerHandler
  75. {
  76. public AlClearErrorHandler()
  77. {
  78. background = true;
  79. }
  80. //$,<UNo>(,<SeqNo>),CCLR,<CMode>(,<Sum>)<CR>
  81. public override string package(params object[] args)
  82. {
  83. return ",CCLR,E,";
  84. }
  85. }
  86. public class AlGripHandler : AlignerHandler
  87. {
  88. public AlGripHandler()
  89. {
  90. background = true;
  91. }
  92. //Command wafer hold/release signal to the solenoid of the specified unit.
  93. //$ <UNo> (<SeqNo>) CSOL <Fork> <Sw> <Sum> <CR>
  94. //• Fork: Fork specified(1 byte)
  95. //• ‘A’: Extension axis 1 (Blade 1), pre-aligner
  96. //• ‘B’: Extension axis 2 (Blade 2)
  97. //• Sw: Chucking command(1 byte)
  98. //• ‘0’: Chucking OFF
  99. //• ‘1’: Chucking ON
  100. public override string package(params object[] args)
  101. {
  102. bool bHold = (bool)args[1];
  103. // bool bHold = (bool)args[0];
  104. if (bHold)
  105. return ",CSOL,A,1,";
  106. return ",CSOL,A,0,";
  107. }
  108. }
  109. public class ALLiftHandler : AlignerHandler
  110. {
  111. public ALLiftHandler()
  112. {
  113. background = true;
  114. }
  115. //$ <UNo> (<SeqNo>) CLFT<Sw> <Sum> <CR>
  116. //• UNo: Unit number(1 byte)
  117. //• ‘1’ to ‘4’: Unit specified
  118. //• SeqNo: Sequence number(Non/1/2/3 byte)
  119. //• Sw: Lifter command(1 byte)
  120. //• ‘0’: Lifter down
  121. //• ‘1’: Lifter up
  122. public override string package(params object[] args)
  123. {
  124. bool bUp = (bool)args[0];
  125. if (bUp)
  126. return ",CLFT,1,";
  127. return ",CLFT,0,";
  128. }
  129. }
  130. public class AlStopHandler : AlignerHandler
  131. {
  132. public AlStopHandler()
  133. {
  134. background = true;
  135. }
  136. public override string package(params object[] args)
  137. {
  138. return ",CHLT,";
  139. }
  140. }
  141. public class ALQueryStateHandler : ITransferMsg
  142. {
  143. public bool background { get; protected set; }
  144. public bool evt { get { return false; } }
  145. public string deviceID { private get; set; }
  146. public string _cmd = string.Empty;
  147. public IDevice Robot { set { _device = (Aligner)value; } }
  148. protected Aligner _device;
  149. public ALQueryStateHandler()
  150. {
  151. background = false;
  152. }
  153. //$,<UNo>(,<SeqNo>),RSTS(,<Sum>)<CR>
  154. public string package(params object[] args)
  155. {
  156. return ",RSTS,";
  157. }
  158. public bool unpackage(string type, string[] items)
  159. {
  160. return !background;
  161. }
  162. }
  163. public class AlAlignHandler : AlignerHandler
  164. {
  165. private int _angle = 0;
  166. public AlAlignHandler()
  167. {
  168. background = true;
  169. }
  170. // $ <UNo> (<SeqNo>) MALN <TUNo> <TrsSt> <Angle> <Sum> <CR>
  171. //Mode : Motion mode (1 byte) If the case of edge grip type pre-alinger, specify ‘0’.
  172. public override string package(params object[] args)
  173. {
  174. // • TUNo: Unit number to be compensated for (1 byte)
  175. //• ‘1’ to ‘4’: Unit specified
  176. //• TrsSt: Target station(2 Byte)
  177. //• ”P1” - ”P2”: At the time of PA stage specification
  178. //Note: P1 and P2 station are effective only when two or more PA stations exist.
  179. //When it does not exist in addition to P1 station, specification of an target station is nothing.
  180. //• Angle: Positioning angle(6 bytes)
  181. //• Relative angle from the position set by alignment calibration as the reference point.
  182. //• Specified in the range between "000000" and "035999"(0 to 359.99 degree.Resolution: 0.01[deg])
  183. //• If a value is less than specified digits, fill the higher digit with ‘0’ so that the field always has specfied digits
  184. //_angle is 0.001 pecent
  185. _angle =(int)Math.Round((double)args[0]* 100.0,2);
  186. return string.Format(",MALN,1,{0:D6},",_angle);
  187. //return string.Format(",MALN,2,{0:D6},", _angle);
  188. }
  189. //!,<UNo>(,<SeqNo>),<Sts>,<Errcd>,MALN,<ExeTime>,<PosData1>…,<PosDataN>,<Value1>…,<Value10>(,<Sum>)<CR>
  190. protected override void update(string[] data)
  191. {
  192. /*
  193. $ <UNo> (<SeqNo>) <StsN> <Ackcd> <Sum> <CR>
  194. */
  195. _device.Notch = _angle;
  196. }
  197. }
  198. public class ALEventHandler : ITransferMsg
  199. {
  200. public bool background { get { return false; } }
  201. public bool evt { get { return true; } }
  202. public string deviceID { private get; set; }
  203. public string _cmd = string.Empty;
  204. public IDevice Robot { set { _device = (Aligner)value; } }
  205. protected Aligner _device;
  206. public ALEventHandler()
  207. {
  208. }
  209. //$,<UNo>(,<SeqNo>),RSTS(,<Sum>)<CR>
  210. public string package(params object[] args)
  211. {
  212. return "";
  213. }
  214. public bool unpackage(string type, string[] items)
  215. {
  216. string evtType = items[3];
  217. if (evtType.Equals(ProtocolTag.resp_evt_error))
  218. {
  219. int error = Convert.ToInt32(items[5], 16);
  220. _device.ErrorCode = error;
  221. if (error > 0)
  222. _device.LastErrorCode = error;
  223. return true;
  224. }
  225. return false;
  226. }
  227. }
  228. }