TDKB200LoadPortHandler.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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 TDKB200LoadPortHandler : HandlerBase
  14. {
  15. public TDKB200LoadPort Device { get; set; }
  16. public string Command;
  17. protected TDKB200LoadPortHandler(TDKB200LoadPort 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. TDKB200LoadPortMessage response = msg as TDKB200LoadPortMessage;
  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 TDKB200SetHandler : TDKB200LoadPortHandler
  76. {
  77. private string setcommand;
  78. public TDKB200SetHandler(TDKB200LoadPort 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. TDKB200LoadPortMessage response = msg as TDKB200LoadPortMessage;
  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 TDKB200GetHandler : TDKB200LoadPortHandler
  135. {
  136. public TDKB200GetHandler(TDKB200LoadPort 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. TDKB200LoadPortMessage response = msg as TDKB200LoadPortMessage;
  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. byte[] data = Encoding.ASCII.GetBytes(cmddata.Replace("STATE/", ""));
  170. if (data.Length < 20) return;
  171. Device.SystemStatus = (TDKSystemStatus)data[0];
  172. Device.Mode = (TDKMode)data[1];
  173. Device.InitPosMovement = (TDKInitPosMovement)data[2];
  174. Device.OperationStatus = (TDKOperationStatus)data[3];
  175. Device.ErrorCode = Encoding.ASCII.GetString(new byte[] { data[4], data[5] });
  176. Device.ContainerStatus = (TDKContainerStatus)data[6];
  177. Device.ClampPosition = (TDKPosition)data[7];
  178. Device.LPDoorLatchPosition = (TDKPosition)data[8];
  179. Device.VacuumStatus = (TDKVacummStatus)data[9];
  180. Device.LPDoorState = (TDKPosition)data[10];
  181. Device.WaferProtrusion = (TDKWaferProtrusion)data[11];
  182. Device.ElevatorAxisPosition = (TDKElevatorAxisPosition)data[12];
  183. Device.DockPosition = (TDKDockPosition)data[13];
  184. Device.MapperPostion = (TDKMapPosition)data[14];
  185. Device.MappingStatus = (TDKMappingStatus)data[17];
  186. Device.Model = (TDKModel)data[18];
  187. if (Device.InfoPadType == 0 && Device.IsAutoDetectCarrierType)
  188. {
  189. int infopadstatus = Convert.ToInt16($"0x{Encoding.ASCII.GetString(new byte[] { data[19] })}", 16);
  190. if ((infopadstatus & 1) != 0) Device.IsInfoPadAOn = true;
  191. else Device.IsInfoPadAOn = false;
  192. if ((infopadstatus & 2) != 0) Device.IsInfoPadBOn = true;
  193. else Device.IsInfoPadBOn = false;
  194. if ((infopadstatus & 4) != 0) Device.IsInfoPadCOn = true;
  195. else Device.IsInfoPadCOn = false;
  196. if ((infopadstatus & 8) != 0) Device.IsInfoPadDOn = true;
  197. else Device.IsInfoPadDOn = false;
  198. Device.InfoPadCarrierIndex = (Device.IsInfoPadAOn? 8:0) + (Device.IsInfoPadBOn ? 4 : 0) +
  199. (Device.IsInfoPadCOn ? 2 : 0) + (Device.IsInfoPadDOn ? 1 : 0);
  200. }
  201. Device.IsError = Device.SystemStatus != TDKSystemStatus.Normal;
  202. Device.ErrorCode = Encoding.ASCII.GetString(new byte[] { data[4], data[5] });
  203. LoadportCassetteState st = LoadportCassetteState.None;
  204. if (Device.ContainerStatus == TDKContainerStatus.Absence) st = LoadportCassetteState.Absent;
  205. if (Device.ContainerStatus == TDKContainerStatus.NormalMount) st = LoadportCassetteState.Normal;
  206. if (Device.ContainerStatus == TDKContainerStatus.MountError) st = LoadportCassetteState.Unknown;
  207. Device.SetCassetteState(st);
  208. if (Device.ClampPosition == TDKPosition.Close)
  209. Device.ClampState = FoupClampState.Close;
  210. else if (Device.ClampPosition == TDKPosition.Open)
  211. Device.ClampState = FoupClampState.Open;
  212. else if (Device.ClampPosition == TDKPosition.TBD)
  213. Device.ClampState = FoupClampState.Unknown;
  214. if (Device.LPDoorState == TDKPosition.Close)
  215. Device.DoorState = FoupDoorState.Close;
  216. if (Device.LPDoorState == TDKPosition.Open)
  217. Device.DoorState = FoupDoorState.Open;
  218. if (Device.LPDoorState == TDKPosition.TBD)
  219. Device.DoorState = FoupDoorState.Unknown;
  220. Device.DockState = ConvertTDKDockPositin(Device.DockPosition); // Load port dock state
  221. if (Device.ElevatorAxisPosition == TDKElevatorAxisPosition.UP)
  222. Device.DoorPosition = FoupDoorPostionEnum.Up;
  223. if (Device.ElevatorAxisPosition == TDKElevatorAxisPosition.Down)
  224. Device.DoorPosition = FoupDoorPostionEnum.Down; // = TDKZ_AxisPos.Down;
  225. if (Device.ElevatorAxisPosition == TDKElevatorAxisPosition.MappingEndPos)
  226. Device.DoorPosition = FoupDoorPostionEnum.MapEnd;// = TDKZ_AxisPos.End;
  227. if (Device.ElevatorAxisPosition == TDKElevatorAxisPosition.MappingStartPos)
  228. Device.DoorPosition = FoupDoorPostionEnum.MapStart;// = TDKZ_AxisPos.Start;
  229. if (Device.ElevatorAxisPosition == TDKElevatorAxisPosition.TBD)
  230. Device.DoorPosition = FoupDoorPostionEnum.Unknown;// = TDKZ_AxisPos.Unknown;
  231. }
  232. if (cmddata.Contains("VERSN/"))
  233. {
  234. }
  235. if (cmddata.Contains("LEDST/"))
  236. {
  237. IndicatorState[] lpledstate = new IndicatorState[]
  238. {
  239. Device.IndicatiorPresence,
  240. Device.IndicatiorPlacement,
  241. Device.IndicatiorLoad,
  242. Device.IndicatiorUnload,
  243. Device.IndicatiorOpAccess,
  244. Device.IndicatiorStatus1,
  245. Device.IndicatiorStatus2,
  246. };
  247. char[] ledstate = cmddata.Replace("LEDST/", "").ToArray();
  248. for (int i = 0; i < (lpledstate.Length > ledstate.Length ? ledstate.Length : lpledstate.Length); i++)
  249. {
  250. if (ledstate[i] == '0') SetIEDValue(i, IndicatorState.OFF);
  251. if (ledstate[i] == '1') SetIEDValue(i, IndicatorState.ON);
  252. if (ledstate[i] == '2') SetIEDValue(i, IndicatorState.BLINK);
  253. }
  254. }
  255. if (cmddata.Contains("MAPRD/"))
  256. {
  257. string str1 = cmddata.Replace("MAPRD/", "");
  258. Device.OnSlotMapRead(str1);
  259. }
  260. if (cmddata.Contains("WFCNT/"))
  261. {
  262. Device.WaferCount = Convert.ToInt16(cmddata.Replace("WFCNT/", ""));
  263. }
  264. if (cmddata.Contains("MDAH/"))
  265. {
  266. }
  267. if (cmddata.Contains("LPIOI/"))
  268. {
  269. }
  270. if (cmddata.Contains("FSBxx/"))
  271. {
  272. if (cmddata.Contains("ON"))
  273. Device.IsFosbModeActual = true;
  274. if (cmddata.Contains("OF"))
  275. Device.IsFosbModeActual = false;
  276. }
  277. }
  278. catch(Exception ex)
  279. {
  280. LOG.Write(ex);
  281. }
  282. }
  283. private void SetIEDValue(int index, IndicatorState state)
  284. {
  285. switch (index)
  286. {
  287. case 0:
  288. Device.IndicatiorPresence = state;
  289. break;
  290. case 1:
  291. Device.IndicatiorPlacement = state;
  292. break;
  293. case 2:
  294. Device.IndicatiorLoad = state;
  295. break;
  296. case 3:
  297. Device.IndicatiorUnload = state;
  298. break;
  299. case 4:
  300. Device.IndicatiorOpAccess = state;
  301. break;
  302. case 5:
  303. Device.IndicatiorStatus1 = state;
  304. break;
  305. case 6:
  306. Device.IndicatiorStatus2 = state;
  307. break;
  308. default:
  309. break;
  310. }
  311. }
  312. private FoupDockState ConvertTDKDockPositin(TDKDockPosition dockPosition)
  313. {
  314. if (dockPosition == TDKDockPosition.Dock) return FoupDockState.Docked;
  315. if (dockPosition == TDKDockPosition.Undock) return FoupDockState.Undocked;
  316. return FoupDockState.Unknown;
  317. }
  318. }
  319. public class TDKB200ModHandler : TDKB200LoadPortHandler
  320. {
  321. public TDKB200ModHandler(TDKB200LoadPort device, string command, string para) : base(device, BuildData(command), para)
  322. {
  323. }
  324. private static string BuildData(string command)
  325. {
  326. return "MOD:" + command;
  327. }
  328. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  329. {
  330. TDKBLoadPortMessage response = msg as TDKBLoadPortMessage;
  331. ResponseMessage = msg;
  332. //Device.TaExecuteSuccss = true;
  333. transactionComplete = false;
  334. if (response.IsAck)
  335. {
  336. SetState(EnumHandlerState.Acked);
  337. transactionComplete = true;
  338. }
  339. if (response.IsNak)
  340. {
  341. SetState(EnumHandlerState.Completed);
  342. transactionComplete = true;
  343. //ParseError(response.Data);
  344. }
  345. return true;
  346. }
  347. public void ParseData(byte[] cmd)
  348. {
  349. }
  350. }
  351. public class TDKB200MoveHandler : TDKB200LoadPortHandler
  352. {
  353. private string moveCommand;
  354. public TDKB200MoveHandler(TDKB200LoadPort device, string command, string para) : base(device, BuildData(command), para)
  355. {
  356. moveCommand = command;
  357. }
  358. private static string BuildData(string command)
  359. {
  360. return "MOV:" + command;
  361. }
  362. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  363. {
  364. TDKB200LoadPortMessage response = msg as TDKB200LoadPortMessage;
  365. ResponseMessage = msg;
  366. //Device.TaExecuteSuccss = true;
  367. transactionComplete = false;
  368. if (response.IsAck)
  369. {
  370. SetState(EnumHandlerState.Acked);
  371. transactionComplete = false;
  372. }
  373. if (response.IsNak)
  374. {
  375. SetState(EnumHandlerState.Completed);
  376. transactionComplete = true;
  377. //ParseError(response.Data);
  378. }
  379. if (response.IsError)
  380. {
  381. SetState(EnumHandlerState.Completed);
  382. transactionComplete = true;
  383. }
  384. if (response.IsEvent)
  385. {
  386. if (response.Command.Contains("ORGSH") || response.Command.Contains("ABORG"))
  387. {
  388. Device.OnHomed();
  389. }
  390. if (response.Command.Contains(moveCommand))
  391. {
  392. SetState(EnumHandlerState.Completed);
  393. transactionComplete = true;
  394. }
  395. }
  396. return true;
  397. }
  398. public void ParseData(byte[] cmd)
  399. {
  400. }
  401. }
  402. }