HirataLoadPortHandler.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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.Hirata
  12. {
  13. public class HirataLoadPortHandler: HandlerBase
  14. {
  15. public HirataLoadPort Device { get; set; }
  16. public string Command;
  17. protected HirataLoadPortHandler(HirataLoadPort 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 data, string para)
  24. {
  25. List<byte> ret = new List<byte>();
  26. ret.Add(0x1);
  27. List<byte> cmd = new List<byte>();
  28. foreach (char c in data)
  29. {
  30. cmd.Add((byte)c);
  31. }
  32. //cmd.Add((byte)(':')); //3A
  33. if(!string.IsNullOrEmpty(para))
  34. foreach(char c in para)
  35. {
  36. cmd.Add((byte)c);
  37. }
  38. cmd.Add((byte)(';')); //3B
  39. int length = cmd.Count + 4;
  40. int checksum = length + 0x30 +0x30;
  41. foreach(byte bvalue in cmd)
  42. {
  43. checksum += bvalue;
  44. }
  45. byte[] byteschecksum = Encoding.ASCII.GetBytes(Convert.ToString((int)((byte)(checksum & 0xFF)), 16));
  46. byte[] blength = BitConverter.GetBytes((short)length);
  47. ret.Add(blength[1]);
  48. ret.Add(blength[0]);
  49. //ret.AddRange(new byte[] { 0x30, 0x30 });
  50. ret.AddRange(new byte[] { 0x30, 0x30 });
  51. ret.AddRange(cmd);
  52. ret.AddRange(byteschecksum);
  53. ret.Add(0xD);
  54. return Encoding.ASCII.GetString(ret.ToArray());
  55. }
  56. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  57. {
  58. HirataLoadPortMessage response = msg as HirataLoadPortMessage;
  59. ResponseMessage = msg;
  60. transactionComplete = false;
  61. if (response.IsAck)
  62. {
  63. SetState(EnumHandlerState.Acked);
  64. transactionComplete = true;
  65. }
  66. if (response.IsError)
  67. {
  68. SetState(EnumHandlerState.Completed);
  69. transactionComplete = true;
  70. }
  71. if (response.IsNak)
  72. {
  73. SetState(EnumHandlerState.Completed);
  74. transactionComplete = true;
  75. }
  76. if (response.IsEvent)
  77. {
  78. SendAck();
  79. if (response.Command.Contains(Command))
  80. {
  81. SetState(EnumHandlerState.Completed);
  82. transactionComplete = true;
  83. }
  84. }
  85. return true;
  86. }
  87. public void HandleEvent(string content)
  88. {
  89. }
  90. public void SendAck()
  91. {
  92. //Device.Connection.SendMessage(new byte[] { 0x06 });
  93. }
  94. public void Retry()
  95. {
  96. }
  97. public virtual bool PaseData(byte[] data)
  98. {
  99. return true;
  100. }
  101. }
  102. public class SetHandler:HirataLoadPortHandler
  103. {
  104. private string setcommand;
  105. public SetHandler(HirataLoadPort device, string command, string para) : base(device, BuildData(command), para)
  106. {
  107. setcommand = command;
  108. }
  109. private static string BuildData(string command)
  110. {
  111. return "SET:"+command;
  112. }
  113. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  114. {
  115. HirataLoadPortMessage response = msg as HirataLoadPortMessage;
  116. ResponseMessage = msg;
  117. //Device.TaExecuteSuccss = true;
  118. transactionComplete = false;
  119. if (response.IsAck)
  120. {
  121. SetState(EnumHandlerState.Acked);
  122. transactionComplete = false;
  123. }
  124. if (response.IsBusy)
  125. {
  126. SetState(EnumHandlerState.Completed);
  127. transactionComplete = true;
  128. }
  129. if (response.IsNak)
  130. {
  131. SetState(EnumHandlerState.Completed);
  132. transactionComplete = true;
  133. //ParseError(response.Data);
  134. }
  135. if (response.IsError)
  136. {
  137. SetState(EnumHandlerState.Completed);
  138. transactionComplete = true;
  139. }
  140. if (response.IsEvent)
  141. {
  142. SendAck();
  143. if (response.Command.Contains(setcommand))
  144. {
  145. SetState(EnumHandlerState.Completed);
  146. transactionComplete = true;
  147. }
  148. else
  149. HandleEvent(response.Command);
  150. transactionComplete = true;
  151. }
  152. if(setcommand == "RESET")
  153. {
  154. transactionComplete = true;
  155. }
  156. return true;
  157. }
  158. }
  159. public class GetHandler : HirataLoadPortHandler
  160. {
  161. public GetHandler(HirataLoadPort device, string command, string para) : base(device, BuildData(command), para)
  162. {
  163. }
  164. private static string BuildData(string command)
  165. {
  166. return "GET:"+command;
  167. }
  168. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  169. {
  170. HirataLoadPortMessage response = msg as HirataLoadPortMessage;
  171. ResponseMessage = msg;
  172. //Device.TaExecuteSuccss = true;
  173. transactionComplete = false;
  174. if (response.IsAck)
  175. {
  176. SetState(EnumHandlerState.Acked);
  177. transactionComplete = true;
  178. ParseData(response.Command);
  179. }
  180. if (response.IsNak)
  181. {
  182. SetState(EnumHandlerState.Completed);
  183. transactionComplete = true;
  184. //ParseError(response.Data);
  185. }
  186. return true;
  187. }
  188. public void ParseData(string cmddata)
  189. {
  190. if (cmddata.Contains("STATE"))
  191. {
  192. byte[] data = Encoding.ASCII.GetBytes(cmddata.Replace("STATE/",""));
  193. if (data.Length < 20) return;
  194. Device.SystemStatus = (HirataSystemStatus)data[0];
  195. Device.Mode = (HirataMode)data[1];
  196. Device.InitPosMovement = (HirataInitPosMovement)data[2];
  197. Device.OperationStatus = (HirataOperationStatus)data[3];
  198. Device.HostErrorCode = data[4];
  199. Device.LoadPortErrorCode = data[5];
  200. Device.ContainerStatus = (HirataContainerStatus)data[6];
  201. Device.ClampPosition = (HirataPosition)data[7];
  202. Device.DoorLatchPosition = (HirataPosition)data[8];
  203. Device.VacuumStatus = (HirataVacummStatus)data[9];
  204. Device.DoorPosition = (HirataPosition)data[10];
  205. Device.WaferProtrusion = (HirataWaferProtrusion)data[11];
  206. Device.ElevatorAxisPosition = (HirataElevatorAxisPosition)data[12];
  207. Device.DockPosition = (HirataDockPosition)data[13];
  208. Device.MapperPostion = (HirataMapPosition)data[14];
  209. Device.MappingStatus = (HirataMappingStatus)data[17];
  210. Device.Model = (HirataModel)data[18];
  211. Device.Error = Device.SystemStatus != HirataSystemStatus.Normal;
  212. Device.ErrorCode = Encoding.ASCII.GetString(new byte[] { data[4], data[5] });
  213. LoadportCassetteState st = LoadportCassetteState.None;
  214. if (Device.ContainerStatus == HirataContainerStatus.Absence) st = LoadportCassetteState.Absent;
  215. if (Device.ContainerStatus == HirataContainerStatus.NormalMount) st = LoadportCassetteState.Normal;
  216. if (Device.ContainerStatus == HirataContainerStatus.MountError) st = LoadportCassetteState.Unknown;
  217. Device.SetCassetteState(st);
  218. if (Device.ClampPosition == HirataPosition.Close)
  219. Device.ClampState = FoupClampState.Close;
  220. else if (Device.ClampPosition == HirataPosition.Open)
  221. Device.ClampState = FoupClampState.Open;
  222. else if(Device.ClampPosition == HirataPosition.TBD)
  223. Device.ClampState = FoupClampState.Unknown;
  224. if (Device.DoorPosition == HirataPosition.Close)
  225. Device.DoorState = FoupDoorState.Close;
  226. if (Device.DoorPosition == HirataPosition.Open)
  227. Device.DoorState = FoupDoorState.Open;
  228. if (Device.DoorPosition == HirataPosition.TBD)
  229. Device.DoorState = FoupDoorState.Unknown;
  230. Device.DockState = ConvertHirataDockPositin(Device.DockPosition); // Load port dock state
  231. if (Device.ElevatorAxisPosition == HirataElevatorAxisPosition.UP)
  232. Device.DoorPOS = TDKZ_AxisPos.Up;
  233. if (Device.ElevatorAxisPosition == HirataElevatorAxisPosition.Down)
  234. Device.DoorPOS = TDKZ_AxisPos.Down;
  235. if (Device.ElevatorAxisPosition == HirataElevatorAxisPosition.MappingEndPos)
  236. Device.DoorPOS = TDKZ_AxisPos.End;
  237. if (Device.ElevatorAxisPosition == HirataElevatorAxisPosition.MappingStartPos)
  238. Device.DoorPOS = TDKZ_AxisPos.Start;
  239. if (Device.ElevatorAxisPosition == HirataElevatorAxisPosition.TBD)
  240. Device.DoorPOS = TDKZ_AxisPos.Unknown;
  241. }
  242. if (cmddata.Contains("VERSN/"))
  243. {
  244. }
  245. if (cmddata.Contains("LEDST/"))
  246. {
  247. IndicatorState[] lpledstate = new IndicatorState[]
  248. {
  249. Device.IndicatiorPresence,
  250. Device.IndicatiorPlacement,
  251. Device.IndicatiorLoad,
  252. Device.IndicatiorUnload,
  253. Device.IndicatiorOpAccess,
  254. Device.IndicatiorStatus1,
  255. Device.IndicatiorStatus2,
  256. };
  257. char[] ledstate = cmddata.Replace("LEDST/", "").ToArray();
  258. for(int i=0; i< (lpledstate.Length> ledstate.Length? ledstate.Length:lpledstate.Length);i++)
  259. {
  260. if (ledstate[i] == '0') lpledstate[i] = IndicatorState.OFF;
  261. if (ledstate[i] == '1') lpledstate[i] = IndicatorState.ON;
  262. if (ledstate[i] == '2') lpledstate[i] = IndicatorState.BLINK;
  263. }
  264. }
  265. if (cmddata.Contains("MAPDT/"))
  266. {
  267. string str1 = cmddata.Replace("MAPDT/", "");
  268. string str2 = string.Empty;
  269. foreach (char c in str1)
  270. str2 = c.ToString() + str1;
  271. Device.OnSlotMapRead(str2);
  272. }
  273. if (cmddata.Contains("WFCNT/"))
  274. {
  275. Device.WaferCount = Convert.ToInt16(cmddata.Replace("WFCNT/", ""));
  276. }
  277. if (cmddata.Contains("MDAH/"))
  278. {
  279. }
  280. if (cmddata.Contains("LPIOI/"))
  281. {
  282. }
  283. }
  284. private FoupDockState ConvertHirataDockPositin(HirataDockPosition dockPosition)
  285. {
  286. if(dockPosition == HirataDockPosition.Dock) return FoupDockState.Docked;
  287. if (dockPosition == HirataDockPosition.Undock) return FoupDockState.Undocked;
  288. return FoupDockState.Unknown;
  289. }
  290. }
  291. public class ModHandler : HirataLoadPortHandler
  292. {
  293. public ModHandler(HirataLoadPort device, string command, string para) : base(device, BuildData(command), para)
  294. {
  295. }
  296. private static string BuildData(string command)
  297. {
  298. return "MOD:"+command;
  299. }
  300. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  301. {
  302. HirataLoadPortMessage response = msg as HirataLoadPortMessage;
  303. ResponseMessage = msg;
  304. //Device.TaExecuteSuccss = true;
  305. transactionComplete = false;
  306. if (response.IsAck)
  307. {
  308. SetState(EnumHandlerState.Acked);
  309. transactionComplete = true;
  310. }
  311. if (response.IsNak)
  312. {
  313. SetState(EnumHandlerState.Completed);
  314. transactionComplete = true;
  315. //ParseError(response.Data);
  316. }
  317. return true;
  318. }
  319. public void ParseData(byte[] cmd)
  320. {
  321. }
  322. }
  323. public class MoveHandler : HirataLoadPortHandler
  324. {
  325. private string moveCommand;
  326. public MoveHandler(HirataLoadPort device, string command, string para) : base(device, BuildData(command), para)
  327. {
  328. moveCommand = command;
  329. }
  330. private static string BuildData(string command)
  331. {
  332. return "MOV:"+command;
  333. }
  334. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  335. {
  336. HirataLoadPortMessage response = msg as HirataLoadPortMessage;
  337. ResponseMessage = msg;
  338. //Device.TaExecuteSuccss = true;
  339. transactionComplete = false;
  340. if (response.IsAck)
  341. {
  342. SetState(EnumHandlerState.Acked);
  343. transactionComplete = false;
  344. }
  345. if (response.IsNak)
  346. {
  347. Device.ExecuteError = true;
  348. SetState(EnumHandlerState.Completed);
  349. transactionComplete = true;
  350. //ParseError(response.Data);
  351. }
  352. if(response.IsError)
  353. {
  354. Device.ExecuteError = true;
  355. SetState(EnumHandlerState.Completed);
  356. transactionComplete = true;
  357. }
  358. if(response.IsEvent)
  359. {
  360. if(response.Command.Contains("ORGSH")|| response.Command.Contains("ABORG"))
  361. {
  362. Device.Initalized = true;
  363. Device.OnHomed();
  364. }
  365. if(response.Command.Contains(moveCommand))
  366. {
  367. SetState(EnumHandlerState.Completed);
  368. transactionComplete = true;
  369. }
  370. }
  371. return true;
  372. }
  373. public void ParseData(byte[] cmd)
  374. {
  375. }
  376. }
  377. }