ClampTask.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.Util;
  3. using Aitex.Sorter.Common;
  4. using Aitex.Sorter.RT.EFEMs.Servers;
  5. using MECF.Framework.Common.Equipment;
  6. using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
  7. namespace Aitex.Sorter.RT.EFEMs.Tasks
  8. {
  9. public class SetClampTask : RobotImp, ITask
  10. {
  11. public SetClampTask()
  12. {
  13. HasInfoMessage = false;
  14. }
  15. public bool Execute(out string result, params string[] args)
  16. {
  17. if (args.Length < 2)
  18. {
  19. result = PARAM_NG;
  20. return false;
  21. }
  22. string device = DeviceName.Robot;
  23. if (args[1].StartsWith("ALIGN"))
  24. device = DeviceName.Aligner;
  25. if (!Check<NoReadyPolicy>(device, out result))
  26. {
  27. return false;
  28. }
  29. if (!Check<NoInitCompletedPolicy>(device, out result))
  30. {
  31. return false;
  32. }
  33. if (!Check<NoOriginCompletedPolicy>(device, out result))
  34. {
  35. return false;
  36. }
  37. if (!Check<VacPolicy>(device, out result))
  38. {
  39. return false;
  40. }
  41. if (!Check<EMSPolicy>(device, out result))
  42. {
  43. return false;
  44. }
  45. if (!Check<ErrorPolicy>(device, out result))
  46. {
  47. return false;
  48. }
  49. if (!Check<BusyPolicy>(device, out result))
  50. {
  51. return false;
  52. }
  53. if (!Check<HoldPolicy>(device, out result))
  54. {
  55. return false;
  56. }
  57. if (!Check<MaintenancePolicy>(device, out result))
  58. {
  59. return false;
  60. }
  61. if (!Check<LinkPolicy>(device, out result))
  62. {
  63. return false;
  64. }
  65. if (!Check<ArmExtendPolicy>(device, out result))
  66. {
  67. return false;
  68. }
  69. if (!Check<PowerDownPolicy>(device, out result))
  70. {
  71. return false;
  72. }
  73. bool isGrip = false;
  74. if (args[0] == "ON")
  75. {
  76. isGrip = true;
  77. }
  78. else if (args[0] == "OFF")
  79. {
  80. isGrip = false;
  81. }
  82. else
  83. {
  84. result = PARAM_NG;
  85. return false;
  86. }
  87. if (args[1].StartsWith("ARM"))
  88. {
  89. Hand arm = Hand.Blade2;
  90. if (!ParseMoveArm(args[1], out arm) || arm == Hand.Both)
  91. {
  92. result = PARAM_NG;
  93. return false;
  94. }
  95. if (isGrip)
  96. {
  97. if (!Singleton<EfemEntity>.Instance.EfemDevice.Grip(ModuleName.Robot, arm, out result))
  98. {
  99. return false;
  100. }
  101. }
  102. else
  103. {
  104. if (!Singleton<EfemEntity>.Instance.EfemDevice.Release(ModuleName.Robot, arm, out result))
  105. {
  106. return false;
  107. }
  108. }
  109. }
  110. else if (args[1].StartsWith("ALIGN"))
  111. {
  112. AlignerServerModule serverAligner = (AlignerServerModule)GetEntity(device);
  113. if (serverAligner != null)
  114. {
  115. if (isGrip)
  116. {
  117. if (!serverAligner.Grip(out result))
  118. {
  119. return false;
  120. }
  121. }
  122. else
  123. {
  124. if (!serverAligner.Release(out result))
  125. {
  126. return false;
  127. }
  128. }
  129. }
  130. }
  131. else
  132. {
  133. result = PARAM_NG;
  134. return false;
  135. }
  136. return true;
  137. }
  138. public bool? Monitor(out string result, params string[] args)
  139. {
  140. result = "";
  141. string device = DeviceName.Robot;
  142. if (args[1].StartsWith("ALIGN"))
  143. device = DeviceName.Aligner;
  144. if (args[1].StartsWith("ARM"))
  145. {
  146. Hand arm = Hand.Blade2;
  147. if (!ParseMoveArm(args[1], out arm) || arm == Hand.Both)
  148. {
  149. result = PARAM_NG;
  150. return false;
  151. }
  152. Robot robot = DEVICE.GetDevice<Robot>(device);
  153. if (robot.Error)
  154. {
  155. return false;
  156. }
  157. if (!robot.Moving)
  158. {
  159. //if (arm == Hand.Blade1)
  160. // result = robot.StateBlade1Gripped ? "ON" : "OFF";
  161. //else if (arm == Hand.Blade2)
  162. // result = robot.StateBlade2Gripped ? "ON" : "OFF";
  163. return true;
  164. }
  165. }
  166. else if (args[1].StartsWith("ALIGN"))
  167. {
  168. AlignerServerModule serverAligner = (AlignerServerModule)GetEntity(device);
  169. if (serverAligner != null)
  170. {
  171. if (serverAligner.Error)
  172. {
  173. return false;
  174. }
  175. if (!serverAligner.Moving)
  176. {
  177. return true;
  178. }
  179. }
  180. else
  181. {
  182. return true;
  183. }
  184. }
  185. else
  186. {
  187. return true;
  188. }
  189. return null;
  190. }
  191. }
  192. public class GetClampTask : RobotImp, ITask
  193. {
  194. public GetClampTask()
  195. {
  196. }
  197. public bool Execute(out string result, params string[] args)
  198. {
  199. if (args.Length < 1)
  200. {
  201. result = PARAM_NG;
  202. return false;
  203. }
  204. string device = DeviceName.Robot;
  205. if (args[0].StartsWith("ALIGN"))
  206. device = DeviceName.Aligner;
  207. if (!Check<NoReadyPolicy>(device, out result))
  208. {
  209. return false;
  210. }
  211. if (args[0].StartsWith("ARM"))
  212. {
  213. Hand arm = Hand.Blade2;
  214. Robot robot = DEVICE.GetDevice<Robot>(device);
  215. if (!ParseMoveArm(args[0], out arm) || arm == Hand.Both)
  216. {
  217. result = PARAM_NG;
  218. return false;
  219. }
  220. if (!robot.QueryState(out result))
  221. {
  222. return false;
  223. }
  224. }
  225. else if (args[0].StartsWith("ALIGN"))
  226. {
  227. ///??? to be done
  228. }
  229. else
  230. {
  231. result = PARAM_NG;
  232. return false;
  233. }
  234. return true;
  235. }
  236. public bool? Monitor(out string result, params string[] args)
  237. {
  238. result = string.Empty;
  239. string device = DeviceName.Robot;
  240. if (args[0].StartsWith("ALIGN"))
  241. device = DeviceName.Aligner;
  242. if (args[0].StartsWith("ARM"))
  243. {
  244. Hand arm = Hand.Blade2;
  245. if (!ParseMoveArm(args[0], out arm) || arm == Hand.Both)
  246. {
  247. result = PARAM_NG;
  248. return false;
  249. }
  250. Robot robot = DEVICE.GetDevice<Robot>(device);
  251. if (robot.Error)
  252. {
  253. return false;
  254. }
  255. if (!robot.Moving)
  256. {
  257. if (arm == Hand.Blade1)
  258. result = robot.StateBlade1Gripped ? "ON" : "OFF";
  259. else if (arm == Hand.Blade2)
  260. result = robot.StateBlade2Gripped ? "ON" : "OFF";
  261. return true;
  262. }
  263. }
  264. else if (args[0].StartsWith("ALIGN"))
  265. {
  266. AlignerServerModule serverAligner = (AlignerServerModule)GetEntity(device);
  267. if (serverAligner != null)
  268. {
  269. if (serverAligner.Error)
  270. {
  271. return false;
  272. }
  273. if (!serverAligner.Moving)
  274. {
  275. result = serverAligner.IsGripped ? "ON" : "OFF";
  276. return true;
  277. }
  278. }
  279. else
  280. {
  281. return true;
  282. }
  283. }
  284. else
  285. {
  286. return true;
  287. }
  288. return null;
  289. }
  290. }
  291. }