TDKBLoadPortHandler.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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 Aitex.Sorter.Common;
  10. using MECF.Framework.Common.Communications;
  11. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.TDKB
  12. {
  13. public class TDKBLoadPortHandler : HandlerBase
  14. {
  15. public TDKBLoadPort Device { get; set; }
  16. public string Command;
  17. protected TDKBLoadPortHandler(TDKBLoadPort device, string command, string para) : base(BuildMesage(command, para))
  18. {
  19. Device = device;
  20. Command = command;
  21. Name = command;
  22. }
  23. public static string BuildMesage(string command, string para)
  24. {
  25. if(string.IsNullOrEmpty(para))
  26. return $"s00{command};\r";
  27. return $"s00{command}{para};\r";
  28. }
  29. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  30. {
  31. TDKBLoadPortMessage response = msg as TDKBLoadPortMessage;
  32. ResponseMessage = msg;
  33. transactionComplete = false;
  34. if (response.IsAck)
  35. {
  36. SetState(EnumHandlerState.Acked);
  37. transactionComplete = true;
  38. }
  39. if (response.IsError)
  40. {
  41. SetState(EnumHandlerState.Completed);
  42. transactionComplete = true;
  43. }
  44. if (response.IsNak)
  45. {
  46. SetState(EnumHandlerState.Completed);
  47. transactionComplete = true;
  48. }
  49. if (response.IsEvent)
  50. {
  51. SendAck();
  52. if (response.Command.Contains(Command))
  53. {
  54. SetState(EnumHandlerState.Completed);
  55. transactionComplete = true;
  56. }
  57. }
  58. return true;
  59. }
  60. public void HandleEvent(string content)
  61. {
  62. }
  63. public void SendAck()
  64. {
  65. //Device.Connection.SendMessage(new byte[] { 0x06 });
  66. }
  67. public void Retry()
  68. {
  69. }
  70. public virtual bool PaseData(byte[] data)
  71. {
  72. return true;
  73. }
  74. }
  75. public class TDKBSetHandler : TDKBLoadPortHandler
  76. {
  77. private string setcommand;
  78. public TDKBSetHandler(TDKBLoadPort device, string command, string para) : base(device, BuildData(command), para)
  79. {
  80. setcommand = command;
  81. }
  82. private static string BuildData(string command)
  83. {
  84. return "SET:" + command;
  85. }
  86. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  87. {
  88. TDKBLoadPortMessage response = msg as TDKBLoadPortMessage;
  89. ResponseMessage = msg;
  90. //Device.TaExecuteSuccss = true;
  91. transactionComplete = false;
  92. if (response.IsAck)
  93. {
  94. SetState(EnumHandlerState.Acked);
  95. transactionComplete = false;
  96. if (setcommand.Contains("FSB"))
  97. transactionComplete = true;
  98. }
  99. if (response.IsBusy)
  100. {
  101. SetState(EnumHandlerState.Completed);
  102. transactionComplete = true;
  103. }
  104. if (response.IsNak)
  105. {
  106. SetState(EnumHandlerState.Completed);
  107. transactionComplete = true;
  108. //ParseError(response.Data);
  109. }
  110. if (response.IsError)
  111. {
  112. SetState(EnumHandlerState.Completed);
  113. transactionComplete = true;
  114. }
  115. if (response.IsEvent)
  116. {
  117. SendAck();
  118. if (response.Command.Contains(setcommand))
  119. {
  120. SetState(EnumHandlerState.Completed);
  121. transactionComplete = true;
  122. }
  123. else
  124. HandleEvent(response.Command);
  125. transactionComplete = true;
  126. }
  127. //if (setcommand == "RESET")
  128. //{
  129. // transactionComplete = true;
  130. //}
  131. return true;
  132. }
  133. }
  134. public class TDKBGetHandler : TDKBLoadPortHandler
  135. {
  136. public TDKBGetHandler(TDKBLoadPort device, string command, string para) : base(device, BuildData(command), para)
  137. {
  138. }
  139. private static string BuildData(string command)
  140. {
  141. return "GET:" + command;
  142. }
  143. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  144. {
  145. TDKBLoadPortMessage response = msg as TDKBLoadPortMessage;
  146. ResponseMessage = msg;
  147. //Device.TaExecuteSuccss = true;
  148. transactionComplete = false;
  149. if (response.IsAck)
  150. {
  151. SetState(EnumHandlerState.Acked);
  152. transactionComplete = true;
  153. ParseData(response.Command);
  154. }
  155. if (response.IsNak)
  156. {
  157. SetState(EnumHandlerState.Completed);
  158. transactionComplete = true;
  159. //ParseError(response.Data);
  160. }
  161. return true;
  162. }
  163. public void ParseData(string cmddata)
  164. {
  165. try
  166. {
  167. if (cmddata.Contains("STATE"))
  168. {
  169. Device.ParseState(cmddata);
  170. }
  171. if (cmddata.Contains("VERSN/"))
  172. {
  173. }
  174. if (cmddata.Contains("LEDST/"))
  175. {
  176. char[] ledstate = cmddata.Replace("LEDST/", "").ToArray();
  177. if (ledstate.Length == 9)
  178. {
  179. IndicatorState[] lpledstate = new IndicatorState[]
  180. {
  181. Device.IndicatiorLoad,
  182. Device.IndicatiorUnload,
  183. Device.IndicatiorAccessManual,
  184. Device.IndicatiorPresence,
  185. Device.IndicatiorPlacement,
  186. Device.IndicatiorAccessAuto,
  187. Device.IndicatiorStatus1,
  188. Device.IndicatorAlarm,
  189. };
  190. for (int i = 0; i < (lpledstate.Length > ledstate.Length ? ledstate.Length : lpledstate.Length); i++)
  191. {
  192. if (ledstate[i] == '0') lpledstate[i] = IndicatorState.OFF;
  193. if (ledstate[i] == '1') lpledstate[i] = IndicatorState.ON;
  194. if (ledstate[i] == '2') lpledstate[i] = IndicatorState.BLINK;
  195. }
  196. }
  197. else
  198. {
  199. IndicatorState[] lpledstate = new IndicatorState[]
  200. {
  201. Device.IndicatiorPresence,
  202. Device.IndicatiorPlacement,
  203. Device.IndicatiorLoad,
  204. Device.IndicatiorUnload,
  205. Device.IndicatiorOpAccess,
  206. Device.IndicatiorStatus1,
  207. Device.IndicatiorStatus2,
  208. };
  209. for (int i = 0; i < (lpledstate.Length > ledstate.Length ? ledstate.Length : lpledstate.Length); i++)
  210. {
  211. if (ledstate[i] == '0') lpledstate[i] = IndicatorState.OFF;
  212. if (ledstate[i] == '1') lpledstate[i] = IndicatorState.ON;
  213. if (ledstate[i] == '2') lpledstate[i] = IndicatorState.BLINK;
  214. }
  215. }
  216. }
  217. if (cmddata.Contains("MAPRD/"))
  218. {
  219. string str1 = cmddata.Replace("MAPRD/", "");
  220. Device.RecordCurrentSlotMap(str1);
  221. }
  222. if (cmddata.Contains("WFCNT/"))
  223. {
  224. Device.WaferCount = Convert.ToInt16(cmddata.Replace("WFCNT/", ""));
  225. }
  226. if (cmddata.Contains("MDAH/"))
  227. {
  228. }
  229. if (cmddata.Contains("LPIOI/"))
  230. {
  231. }
  232. if (cmddata.Contains("FSBxx/"))
  233. {
  234. if (cmddata.Contains("ON"))
  235. Device.IsFosbModeActual = true;
  236. if (cmddata.Contains("OF"))
  237. Device.IsFosbModeActual = false;
  238. }
  239. }
  240. catch(Exception ex)
  241. {
  242. LOG.Write(ex);
  243. }
  244. }
  245. private void SetIEDValue(int index, IndicatorState state)
  246. {
  247. switch (index)
  248. {
  249. case 0:
  250. Device.IndicatiorPresence = state;
  251. break;
  252. case 1:
  253. Device.IndicatiorPlacement = state;
  254. break;
  255. case 2:
  256. Device.IndicatiorLoad = state;
  257. break;
  258. case 3:
  259. Device.IndicatiorUnload = state;
  260. break;
  261. case 4:
  262. Device.IndicatiorOpAccess = state;
  263. break;
  264. case 5:
  265. Device.IndicatiorStatus1 = state;
  266. break;
  267. case 6:
  268. Device.IndicatiorStatus2 = state;
  269. break;
  270. default:
  271. break;
  272. }
  273. }
  274. }
  275. public class TDKBModHandler : TDKBLoadPortHandler
  276. {
  277. public TDKBModHandler(TDKBLoadPort device, string command, string para) : base(device, BuildData(command), para)
  278. {
  279. }
  280. private static string BuildData(string command)
  281. {
  282. return "MOD:" + command;
  283. }
  284. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  285. {
  286. TDKBLoadPortMessage response = msg as TDKBLoadPortMessage;
  287. ResponseMessage = msg;
  288. //Device.TaExecuteSuccss = true;
  289. transactionComplete = false;
  290. if (response.IsAck)
  291. {
  292. SetState(EnumHandlerState.Acked);
  293. transactionComplete = true;
  294. }
  295. if (response.IsNak)
  296. {
  297. SetState(EnumHandlerState.Completed);
  298. transactionComplete = true;
  299. //ParseError(response.Data);
  300. }
  301. return true;
  302. }
  303. public void ParseData(byte[] cmd)
  304. {
  305. }
  306. }
  307. public class TDKBMoveHandler : TDKBLoadPortHandler
  308. {
  309. private string moveCommand;
  310. public TDKBMoveHandler(TDKBLoadPort device, string command, string para) : base(device, BuildData(command), para)
  311. {
  312. moveCommand = command;
  313. }
  314. private static string BuildData(string command)
  315. {
  316. return "MOV:" + command;
  317. }
  318. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  319. {
  320. TDKBLoadPortMessage response = msg as TDKBLoadPortMessage;
  321. ResponseMessage = msg;
  322. //Device.TaExecuteSuccss = true;
  323. transactionComplete = false;
  324. if (response.IsAck)
  325. {
  326. SetState(EnumHandlerState.Acked);
  327. transactionComplete = false;
  328. }
  329. if (response.IsNak)
  330. {
  331. Device.OnCommandFailed(moveCommand);
  332. SetState(EnumHandlerState.Completed);
  333. transactionComplete = true;
  334. //ParseError(response.Data);
  335. }
  336. if (response.IsError)
  337. {
  338. Device.OnCommandFailed(moveCommand);
  339. SetState(EnumHandlerState.Completed);
  340. transactionComplete = true;
  341. }
  342. if (response.IsEvent)
  343. {
  344. if (response.Command.Contains("ORGSH") || response.Command.Contains("ABORG"))
  345. {
  346. Device.OnHomed();
  347. }
  348. if (response.Command.Contains(moveCommand))
  349. {
  350. SetState(EnumHandlerState.Completed);
  351. transactionComplete = true;
  352. Device.OnCommandSuccess(moveCommand);
  353. }
  354. }
  355. return true;
  356. }
  357. public void ParseData(byte[] cmd)
  358. {
  359. }
  360. }
  361. }