TDKBLoadPortConnection.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. using Aitex.Core.RT.Log;
  2. using MECF.Framework.Common.Communications;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO.Ports;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Text.RegularExpressions;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.TDKB
  12. {
  13. public class TDKBLoadPortMessage : AsciiMessage
  14. {
  15. public string CommandType { get; set; }
  16. public string Command { get; set; }
  17. public string Data { get; set; }
  18. }
  19. public class TDKBLoadPortConnection : SerialPortConnectionBase
  20. {
  21. private TDKBLoadPort _device;
  22. public TDKBLoadPortConnection(TDKBLoadPort device, string portName, int baudRate = 9600, int dataBits = 8, Parity parity = Parity.None, StopBits stopBits = StopBits.One)
  23. : base(portName, baudRate, dataBits, parity, stopBits, "\r", true)
  24. {
  25. _device = device;
  26. IsEnableHandlerRetry = true;
  27. }
  28. protected override MessageBase ParseResponse(string rawMsg)
  29. {
  30. TDKBLoadPortMessage msg = new TDKBLoadPortMessage();
  31. msg.RawMessage = rawMsg;
  32. msg.IsAck = false;
  33. msg.IsResponse = false;
  34. msg.IsComplete = false;
  35. msg.IsResponse = false;
  36. msg.IsNak = false;
  37. msg.IsError = false;
  38. msg.CommandType = rawMsg.Split(':')[0].Replace("s00", "");
  39. msg.Command = Regex.Match(rawMsg, "(?<=:).*?(?=;)").Value;
  40. if (msg.CommandType.Contains("ACK")) msg.IsAck = true;
  41. if (msg.CommandType.Contains("NAK"))
  42. {
  43. msg.IsNak = true;
  44. _device.OnNak(rawMsg);
  45. _device.OnError($"Received NAK:{rawMsg}");
  46. }
  47. if (msg.CommandType.Contains("MOV")) msg.IsAck = true;
  48. if (msg.CommandType.Contains("GET")) msg.IsAck = true;
  49. if (msg.CommandType.Contains("INF"))
  50. {
  51. msg.IsEvent = true;
  52. }
  53. if (msg.CommandType.Contains("ABS"))
  54. {
  55. _device.OnAbs(rawMsg);
  56. msg.IsError = true;
  57. }
  58. if(!msg.CommandType.Contains("s00ACK:STATE"))
  59. LOG.Write($"{_device.LPModuleName} {Address} received message:{rawMsg}");
  60. return msg;
  61. }
  62. protected override void OnEventArrived(MessageBase msg)
  63. {
  64. TDKBLoadPortMessage message = msg as TDKBLoadPortMessage;
  65. string evtcontent = message.RawMessage;
  66. if (evtcontent.Contains("PODON"))
  67. {
  68. //_device.OnCarrierPresent();
  69. //_device.OnCarrierPlaced();
  70. }
  71. if (evtcontent.Contains("PODOF"))
  72. {
  73. _device.OnCarrierNotPlaced();
  74. _device.OnCarrierNotPresent();
  75. }
  76. if (evtcontent.Contains("ABNST"))
  77. {
  78. _device.OnCarrierNotPlaced();
  79. _device.OnCarrierPresent();
  80. }
  81. if (evtcontent.Contains("SMTON"))
  82. {
  83. _device.OnCarrierNotPlaced();
  84. _device.OnCarrierPresent();
  85. }
  86. if (evtcontent.Contains("MANSW"))
  87. {
  88. _device.OnSwitchKey1();
  89. }
  90. if (evtcontent.Contains("PRSIN"))
  91. {
  92. //_device.IsWaferProtrude = true;
  93. }
  94. if (evtcontent.Contains("PRSCL"))
  95. {
  96. //_device.IsWaferProtrude = false;
  97. }
  98. if(evtcontent.Contains("E84IO"))
  99. {
  100. _device.OnE84IOEvent(evtcontent);
  101. }
  102. if(evtcontent.Contains("E84ER"))
  103. {
  104. _device.OnE84Error(evtcontent);
  105. }
  106. if (evtcontent.Contains("E84EV"))
  107. {
  108. _device.OnE84Load(evtcontent);
  109. }
  110. if (evtcontent.Contains("E84ev"))
  111. {
  112. _device.OnE84Unload(evtcontent);
  113. }
  114. _device.OnEvent(out _);
  115. }
  116. }
  117. public class TDKBLoadPortTCPConnection : TCPPortConnectionBase
  118. {
  119. private TDKBLoadPort _device;
  120. public TDKBLoadPortTCPConnection(TDKBLoadPort device, string ipaddress)
  121. : base(ipaddress)
  122. {
  123. _device = device;
  124. }
  125. protected override MessageBase ParseResponse(string rawMsg)
  126. {
  127. TDKBLoadPortMessage msg = new TDKBLoadPortMessage();
  128. msg.RawMessage = rawMsg;
  129. msg.IsAck = false;
  130. msg.IsResponse = false;
  131. msg.IsComplete = false;
  132. msg.IsResponse = false;
  133. msg.IsNak = false;
  134. msg.IsError = false;
  135. msg.CommandType = rawMsg.Split(':')[0].Replace("s00","");
  136. msg.Command = Regex.Match(rawMsg, "(?<=:).*?(?=;)").Value;
  137. if (msg.CommandType.Contains("ACK")) msg.IsAck = true;
  138. if (msg.CommandType.Contains("NAK"))
  139. {
  140. msg.IsNak = true;
  141. _device.OnError($"Received NAK:{rawMsg}");
  142. }
  143. if (msg.CommandType.Contains("MOV")) msg.IsAck = true;
  144. if (msg.CommandType.Contains("GET")) msg.IsAck = true;
  145. if (msg.CommandType.Contains("INF"))
  146. {
  147. msg.IsEvent = true;
  148. }
  149. if (msg.CommandType.Contains("ABS"))
  150. {
  151. _device.OnAbs(rawMsg);
  152. msg.IsError = true;
  153. }
  154. LOG.Write($"{Address} received message:{rawMsg}");
  155. return msg;
  156. }
  157. protected override void OnEventArrived(MessageBase msg)
  158. {
  159. TDKBLoadPortMessage message = msg as TDKBLoadPortMessage;
  160. string evtcontent = message.RawMessage;
  161. if (evtcontent.Contains("PODON"))
  162. {
  163. //_device.OnCarrierPresent();
  164. //_device.OnCarrierPlaced();
  165. }
  166. if (evtcontent.Contains("PODOF"))
  167. {
  168. _device.OnCarrierNotPlaced();
  169. _device.OnCarrierNotPresent();
  170. }
  171. if (evtcontent.Contains("ABNST"))
  172. {
  173. _device.OnCarrierNotPlaced();
  174. _device.OnCarrierPresent();
  175. }
  176. if (evtcontent.Contains("SMTON"))
  177. {
  178. _device.OnCarrierNotPlaced();
  179. _device.OnCarrierPresent();
  180. }
  181. if (evtcontent.Contains("MANSW"))
  182. {
  183. _device.OnSwitchKey1();
  184. }
  185. if (evtcontent.Contains("PRSIN"))
  186. {
  187. _device.IsWaferProtrude = true;
  188. }
  189. if (evtcontent.Contains("PRSCL"))
  190. {
  191. _device.IsWaferProtrude = false;
  192. }
  193. if (evtcontent.Contains("E84IO"))
  194. {
  195. _device.OnE84IOEvent(evtcontent);
  196. }
  197. if (evtcontent.Contains("E84ER"))
  198. {
  199. _device.OnE84Error(evtcontent);
  200. }
  201. if (evtcontent.Contains("E84EV"))
  202. {
  203. _device.OnE84Load(evtcontent);
  204. }
  205. if (evtcontent.Contains("E84ev"))
  206. {
  207. _device.OnE84Unload(evtcontent);
  208. }
  209. }
  210. }
  211. }