BrooksSMIFHandler.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. using Aitex.Core.RT.Device;
  2. using MECF.Framework.Common.Communications;
  3. using Newtonsoft.Json.Linq;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.SMIFs.Brooks
  8. {
  9. public abstract class BrooksSMIFHandler : HandlerBase
  10. {
  11. public BrooksSMIF Device { get; }
  12. public string _commandType;
  13. public string _command;
  14. public string _parameter;
  15. protected string _completeEvent;
  16. protected BrooksSMIFHandler(BrooksSMIF device, string commandType,string command, string completeEvent = null,string parameter = null)
  17. : base(BuildMessage(commandType, command, parameter))
  18. {
  19. Device = device;
  20. _commandType = commandType;
  21. _command = command;
  22. _completeEvent = completeEvent;
  23. _parameter = parameter;
  24. Name = command;
  25. }
  26. private static string BuildMessage(string commandType, string command, string parameter)
  27. {
  28. string commandStr = commandType;
  29. if(command != null)
  30. {
  31. commandStr += " " + command;
  32. }
  33. if (parameter != null)
  34. {
  35. commandStr += " " + parameter;
  36. }
  37. return commandStr + "\r\n";
  38. }
  39. protected static string F2S(float value)
  40. {
  41. return value < 0 ? value.ToString() : " " + value.ToString();
  42. }
  43. public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
  44. {
  45. BrooksSMIFMessage response = msg as BrooksSMIFMessage;
  46. ResponseMessage = msg;
  47. if (msg.IsError)
  48. {
  49. Device.NoteError(response.Data);
  50. }
  51. else
  52. {
  53. Device.NoteError(null);
  54. if(msg.IsAck)
  55. {
  56. this.SetState(EnumHandlerState.Acked);
  57. }
  58. if (_completeEvent == null)
  59. {
  60. if (this.IsAcked)
  61. {
  62. SetState(EnumHandlerState.Completed);
  63. transactionComplete = true;
  64. return true;
  65. }
  66. }
  67. else if (this.IsAcked && msg.IsEvent && _completeEvent == response.Data)
  68. {
  69. SetState(EnumHandlerState.Completed);
  70. transactionComplete = true;
  71. return true;
  72. }
  73. }
  74. transactionComplete = false;
  75. return false;
  76. }
  77. }
  78. public class BrooksSMIFRawCommandHandler : BrooksSMIFHandler
  79. {
  80. public BrooksSMIFRawCommandHandler(BrooksSMIF device, string commandType, string command, string completeEvent,string parameter = null)
  81. : base(device, commandType, command, completeEvent,parameter)
  82. {
  83. }
  84. public override bool HandleMessage(MessageBase msg, out bool handled)
  85. {
  86. if (base.HandleMessage(msg, out handled))
  87. {
  88. var result = msg as BrooksSMIFMessage;
  89. Device.NoteRawCommandInfo(_commandType,_command, result.RawMessage, msg.IsAck);
  90. ResponseMessage = msg;
  91. handled = true;
  92. }
  93. return true;
  94. }
  95. }
  96. public class BrooksSMIFEnableActionHandler : BrooksSMIFHandler
  97. {
  98. public BrooksSMIFEnableActionHandler(BrooksSMIF device, string action, bool isEnable)
  99. : base(device, "HCS", isEnable? "ENABLE":"DISABLE",null, action)
  100. {
  101. }
  102. public override bool HandleMessage(MessageBase msg, out bool handled)
  103. {
  104. if (base.HandleMessage(msg, out handled))
  105. {
  106. var result = msg as BrooksSMIFMessage;
  107. Device.NoteEnable(_parameter, _command == "ENABLE");
  108. }
  109. return true;
  110. }
  111. }
  112. public class BrooksSMIFFetchCassetteHandler : BrooksSMIFHandler
  113. {
  114. public BrooksSMIFFetchCassetteHandler(BrooksSMIF device)
  115. : base(device, "HCS", "FETCH", "CMPL_FETCH")
  116. {
  117. }
  118. }
  119. public class BrooksSMIFLoadCassetteHandler : BrooksSMIFHandler
  120. {
  121. public BrooksSMIFLoadCassetteHandler(BrooksSMIF device)
  122. : base(device, "HCS", "LOAD", null)
  123. {
  124. }
  125. public override bool HandleMessage(MessageBase msg, out bool handled)
  126. {
  127. if (!base.HandleMessage(msg, out handled))
  128. {
  129. BrooksSMIFMessage response = msg as BrooksSMIFMessage;
  130. if (response.Data.Contains("ABORT_LOAD"))
  131. {
  132. Device.NoteError("ABORT_LOAD");
  133. handled = true;
  134. }
  135. }
  136. return true;
  137. }
  138. }
  139. public class BrooksSMIFHomeHandler : BrooksSMIFHandler
  140. {
  141. public BrooksSMIFHomeHandler(BrooksSMIF device)
  142. : base(device, "HCS", "HOME", null)
  143. {
  144. }
  145. }
  146. public class BrooksSMIFRecoveryHandler : BrooksSMIFHandler
  147. {
  148. public BrooksSMIFRecoveryHandler(BrooksSMIF device)
  149. : base(device, "HCS", "RECOVERY", null)
  150. {
  151. }
  152. }
  153. public class BrooksSMIFStopHandler : BrooksSMIFHandler
  154. {
  155. public BrooksSMIFStopHandler(BrooksSMIF device)
  156. : base(device, "HCS", "STOP", null)
  157. {
  158. }
  159. }
  160. public class BrooksSMIFResetHandler : BrooksSMIFHandler
  161. {
  162. public BrooksSMIFResetHandler(BrooksSMIF device)
  163. : base(device, "HCS", "RESET", null)
  164. {
  165. }
  166. }
  167. public class BrooksSMIFOpenPodHandler : BrooksSMIFHandler
  168. {
  169. public BrooksSMIFOpenPodHandler(BrooksSMIF device)
  170. : base(device, "HCS", "OPEN", "CMPL_OPEN")
  171. {
  172. }
  173. }
  174. public class BrooksSMIFUnloadCassetteHandler : BrooksSMIFHandler
  175. {
  176. public BrooksSMIFUnloadCassetteHandler(BrooksSMIF device)
  177. : base(device, "HCS", "UNLOAD", null)
  178. {
  179. }
  180. //mabye need and the guide document miss this info ??
  181. //public override bool HandleMessage(MessageBase msg, out bool handled)
  182. //{
  183. // if (!base.HandleMessage(msg, out handled))
  184. // {
  185. // BrooksSMIFMessage response = msg as BrooksSMIFMessage;
  186. // if (response.Data.Contains("ABORT_UNLOAD"))
  187. // {
  188. // Device.NoteError("ABORT_UNLOAD");
  189. // handled = true;
  190. // }
  191. // }
  192. // return true;
  193. //}
  194. }
  195. public class BrooksSMIFClosePodHandler : BrooksSMIFHandler
  196. {
  197. public BrooksSMIFClosePodHandler(BrooksSMIF device)
  198. : base(device, "HCS", "CLOSE", "CMPL_UNLOAD")
  199. {
  200. }
  201. }
  202. public class BrooksSMIFRequestConstantHandler : BrooksSMIFHandler
  203. {
  204. public BrooksSMIFRequestConstantHandler(BrooksSMIF device, string constantId)
  205. : base(device, "ECR", null, null, constantId)
  206. {
  207. }
  208. public override bool HandleMessage(MessageBase msg, out bool handled)
  209. {
  210. var result = msg as BrooksSMIFMessage;
  211. if (result.MessagePart[0] == "ECD")
  212. {
  213. msg.IsAck = true;
  214. }
  215. else
  216. {
  217. handled = false;
  218. return false;
  219. }
  220. if (base.HandleMessage(msg, out handled))
  221. {
  222. Device.NoteConstant(result.MessagePart[1]);
  223. }
  224. return true;
  225. }
  226. }
  227. public class BrooksSMIFRequestStatusHandler : BrooksSMIFHandler
  228. {
  229. int _formCode;
  230. string AlarmId = "ALMID";//0000 = No alarm
  231. string Mode = "MODE";//AUTO,MANUAL
  232. string PodPresent = "PIP";//FALSE=no pod present,TRUE=pod present
  233. string PortStatus = "PRTST";//UNLK=port unlocked,LOCK=port locked,OTHER=none of the above
  234. string GripperStatus = "GRPST";//OPEN=gripper opened;CLOSE=gripper closed;OT=overtraveled;OTHER=none of the above
  235. string Ready = "READY";//FALSE=busy;TRUE=ready for new command
  236. string Home = "HOME";//FALSE=not home;TRUE=home
  237. string Elevator = "ELUP";//FALSE=elevator not at home limit;TRUE=elevator at home limit
  238. string ArmRetract = "ARM_RETR";//TRUE=arm retract;FALSE=arm not retract
  239. public BrooksSMIFRequestStatusHandler(BrooksSMIF device, int formCode)
  240. : base(device, "FSR", null, null, "FC="+formCode.ToString())
  241. {
  242. _formCode = formCode;
  243. }
  244. public override bool HandleMessage(MessageBase msg, out bool handled)
  245. {
  246. var result = msg as BrooksSMIFMessage;
  247. if (result.MessagePart[0].Contains($"FSD{_formCode}"))
  248. {
  249. msg.IsAck = true;
  250. }
  251. else
  252. {
  253. handled = false;
  254. return false;
  255. }
  256. bool isPodPresent = false;
  257. bool isReady = false;
  258. bool isArmRetract = false;
  259. bool isHomed = false;
  260. for (int i = 0;i< result.MessagePart.Length;i++)
  261. {
  262. var statusArray = result.MessagePart[i].Split('=');
  263. if (statusArray.Length != 2)
  264. continue;
  265. if (statusArray[0] == AlarmId)
  266. {
  267. if (statusArray[1] != "0000")
  268. Device.SetError(statusArray[1]);
  269. }
  270. else if (statusArray[0] == Mode)
  271. {
  272. }
  273. else if (statusArray[0] == PodPresent)
  274. {
  275. if (statusArray[1].ToUpper() == "TRUE")
  276. isPodPresent = true;
  277. }
  278. else if (statusArray[0] == PortStatus)
  279. {
  280. }
  281. else if (statusArray[0] == GripperStatus)
  282. {
  283. }
  284. else if (statusArray[0] == Ready)
  285. {
  286. if (statusArray[1].ToUpper() == "TRUE")
  287. isReady = true;
  288. }
  289. else if (statusArray[0] == Home)
  290. {
  291. if (statusArray[1].ToUpper() == "TRUE")
  292. isHomed = true;
  293. }
  294. else if (statusArray[0] == Elevator)
  295. {
  296. }
  297. else if (statusArray[0] == ArmRetract)
  298. {
  299. if (statusArray[1].ToUpper() == "TRUE")
  300. isArmRetract = true;
  301. }
  302. }
  303. Device.SetStatus(isReady, isHomed, isPodPresent, isArmRetract);
  304. if (base.HandleMessage(msg, out handled))
  305. {
  306. Device.NoteStatus(result.MessagePart[0], result.Data);
  307. }
  308. return true;
  309. }
  310. }
  311. }