LoaderSideDevice.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. using Aitex.Core.RT.DataCenter;
  2. using Aitex.Core.RT.Device;
  3. using Aitex.Core.RT.Event;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.RT.OperationCenter;
  6. using Aitex.Core.RT.Routine;
  7. using Aitex.Core.RT.SCCore;
  8. using Aitex.Core.Util;
  9. using MECF.Framework.Common.Beckhoff.ModuleIO;
  10. using MECF.Framework.Common.CommonData.Loader;
  11. using MECF.Framework.Common.TwinCat;
  12. using MECF.Framework.Common.Utilities;
  13. using CyberX8_Core;
  14. using CyberX8_RT.Devices.AXIS.CANOpen;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Linq;
  18. using System.Reflection;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. using MECF.Framework.Common.IOCore;
  22. namespace CyberX8_RT.Devices.Loader
  23. {
  24. public class LoaderSideDevice : BaseDevice, IDevice
  25. {
  26. /// <summary>
  27. ///
  28. /// </summary>
  29. private enum LoaderSideOperation
  30. {
  31. None,
  32. DoorOn,
  33. DoorOff,
  34. VacuumOn,
  35. VacuumOff,
  36. WhBladderOn,
  37. WhBladderOff,
  38. TransBladderOn,
  39. TransBladderOff,
  40. TransHighOn,
  41. TransHighOff,
  42. BernoulliBladderOn,
  43. BernoulliBladderOff,
  44. BernoulliN2On,
  45. BernoulliN2Off,
  46. Load,
  47. Unload,
  48. InstallCRS,
  49. StartCycle,
  50. StopCycle
  51. }
  52. #region 常量
  53. private const string WAFER_PRESENT = "WaferPresent";
  54. private const string DOOR_UNLOCK = "DoorUnlock";
  55. private const string DOOR_UPPER_LOCKED = "DoorUpperLocked";
  56. private const string DOOR_UPPER_UNLOCKED = "DoorUpperUnlocked";
  57. private const string DOOR_LOWER_LOCKED = "DoorLowerLocked";
  58. private const string DOOR_LOWER_UNLOCKED = "DoorLowerUnlocked";
  59. private const string CRS_VACUUM="CRSVacuum";
  60. private const string CRS_VACUUM_VALUE = "CRSVacuumValue";
  61. private const string WH_BLADDER = "WHBladder";
  62. private const string WH_BLADDER_PRESSURE="WHBladderPressure";
  63. private const string TRANS_BLADDER="TransBladder";
  64. private const string TRANS_HIGH="TransHigh";
  65. private const string TRANS_RETRACTED="TransRetracted";
  66. private const string TRANS_PRESSURE = "TransPressure";
  67. private const string BERNOULLI_BLADDER= "BernoulliBladder";
  68. private const string BERNOULLI_EXTENDED="BernoulliExtended";
  69. private const string BERNOULLI_N2="BernoulliN2";
  70. private const string BERNOULLI_N2_SECOND = "BernoulliN2Second";
  71. private const string BERNOULLI_PRESSURE="BernoulliPressure";
  72. private const string WAFER_HOLDER_LOCKED = "WaferHolderLocked";
  73. private const string BERNOULLI_BLADDER_PRESSURE="BernoulliBladderPressure";
  74. private const string SIDE_DATA = "SideData";
  75. private const string CURRENT_OPERATION = "CurrentOperation";
  76. #endregion
  77. #region 内部变量
  78. /// <summary>
  79. /// 数据
  80. /// </summary>
  81. private LoaderSideData _siderData=new LoaderSideData();
  82. /// <summary>
  83. /// 状态
  84. /// </summary>
  85. private RState _status;
  86. /// <summary>
  87. /// 当前操作
  88. /// </summary>
  89. private LoaderSideOperation _currentOperation;
  90. /// <summary>
  91. /// 变量是否初始化字典
  92. /// </summary>
  93. private Dictionary<string, bool> _variableInitializeDic = new Dictionary<string, bool>();
  94. /// <summary>
  95. /// 当前次数
  96. /// </summary>
  97. private string _currentCycle = "";
  98. #region routine
  99. /// <summary>
  100. /// door lock routine
  101. /// </summary>
  102. private LoaderSideDoorLockRoutine _doorlockRoutine;
  103. /// <summary>
  104. /// Vacuum Routine
  105. /// </summary>
  106. private LoaderSideVacuumRoutine _vacuumRoutine;
  107. /// <summary>
  108. /// WH Bladder Routine
  109. /// </summary>
  110. private LoaderSideWhBladderRoutine _whBladderRoutine;
  111. /// <summary>
  112. /// Bernoulli Bladder Routine
  113. /// </summary>
  114. private LoaderSideBernoulliBladderRoutine _bernoulliBladderRoutine;
  115. /// <summary>
  116. /// Load Routine
  117. /// </summary>
  118. private LoaderLoadRoutine _loadRoutine;
  119. /// <summary>
  120. /// Unload Routine
  121. /// </summary>
  122. private LoaderUnloadRoutine _unloadRoutine;
  123. /// <summary>
  124. /// Install Routine
  125. /// </summary>
  126. private LoaderInstallCRSRoutine _installCRSRoutine;
  127. /// <summary>
  128. /// Cycle Routine
  129. /// </summary>
  130. private LoaderSideCycleRoutine _cycleRoutine;
  131. #endregion
  132. #endregion
  133. #region 属性
  134. /// <summary>
  135. /// 数据
  136. /// </summary>
  137. public LoaderSideData SideData
  138. {
  139. get { return _siderData; }
  140. set { _siderData = value; }
  141. }
  142. /// <summary>
  143. /// 状态
  144. /// </summary>
  145. public RState Status { get { return _status; } }
  146. /// <summary>
  147. /// 当前次数
  148. /// </summary>
  149. public String CurrentCycle { get { return _currentCycle; } }
  150. /// <summary>
  151. /// 所有io变量是否初始化
  152. /// </summary>
  153. public bool IOInitialized { get { return IOVariableDictionaryUtil.AllIoVariableInitialized(eEvent.ERR_LOADER,Module,_variableInitializeDic); } }
  154. #endregion
  155. /// <summary>
  156. /// 构造函数
  157. /// </summary>
  158. /// <param name="moduleName"></param>
  159. /// <param name="name"></param>
  160. public LoaderSideDevice(string moduleName,string name):base(moduleName,name,name,name)
  161. {
  162. }
  163. /// <summary>
  164. /// 初始化
  165. /// </summary>
  166. /// <returns></returns>
  167. public bool Initialize()
  168. {
  169. SubscribeData();
  170. SubscribeValueAction();
  171. InitializeRoutine();
  172. InitializeOperation();
  173. return true;
  174. }
  175. /// <summary>
  176. /// 初始化Routine
  177. /// </summary>
  178. private void InitializeRoutine()
  179. {
  180. _doorlockRoutine = new LoaderSideDoorLockRoutine($"{Module}.{Name}");
  181. _vacuumRoutine = new LoaderSideVacuumRoutine($"{Module}.{Name}");
  182. _whBladderRoutine = new LoaderSideWhBladderRoutine($"{Module}.{Name}");
  183. _bernoulliBladderRoutine = new LoaderSideBernoulliBladderRoutine($"{Module}.{Name}");
  184. _loadRoutine = new LoaderLoadRoutine(Module,Name);
  185. _unloadRoutine = new LoaderUnloadRoutine(Module,Name);
  186. _installCRSRoutine = new LoaderInstallCRSRoutine(Module,Name);
  187. _cycleRoutine = new LoaderSideCycleRoutine(Module, Name);
  188. }
  189. /// <summary>
  190. /// 订阅数据
  191. /// </summary>
  192. private void SubscribeData()
  193. {
  194. DATA.Subscribe($"{Module}.{Name}.{SIDE_DATA}", () => _siderData,SubscriptionAttribute.FLAG.IgnoreSaveDB);
  195. DATA.Subscribe($"{Module}.{Name}.CurrentCycle", () => _currentCycle, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  196. DATA.Subscribe($"{Module}.{Name}.CurrentCycleStep", () =>
  197. {
  198. if(_currentOperation==LoaderSideOperation.StartCycle)
  199. {
  200. return _cycleRoutine.CurrentStep;
  201. }
  202. else
  203. {
  204. return "";
  205. }
  206. }, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  207. DATA.Subscribe($"{Module}.{Name}.{CURRENT_OPERATION}", () => _currentOperation.ToString(), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  208. DATA.Subscribe($"{Module}.{Name}.CRSVacuumValue",()=>_siderData.CRSVacuumValue, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  209. DATA.Subscribe($"{Module}.{Name}.CRSVacuum", () => _siderData.CRSVacuum, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  210. DATA.Subscribe($"{Module}.{Name}.BernoulliPressure", () => _siderData.BernoulliPressure, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  211. DATA.Subscribe($"{Module}.{Name}.BernoulliBladder", () => _siderData.BernoulliBladder, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  212. DATA.Subscribe($"{Module}.{Name}.BernoulliBladderPressure", () => _siderData.BernoulliBladderPressure, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  213. DATA.Subscribe($"{Module}.{Name}.BernoulliExtended", () => _siderData.BernoulliExtended, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  214. DATA.Subscribe($"{Module}.{Name}.BernoulliN2", () => _siderData.BernoulliN2, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  215. DATA.Subscribe($"{Module}.{Name}.BernoulliN2Second", () => _siderData.BernoulliN2Second, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  216. DATA.Subscribe($"{Module}.{Name}.DoorLowerLocked", () => _siderData.DoorLowerLocked, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  217. DATA.Subscribe($"{Module}.{Name}.DoorLowerUnlocked", () => _siderData.DoorLowerUnlocked, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  218. DATA.Subscribe($"{Module}.{Name}.DoorUpperLocked", () => _siderData.DoorUpperLocked, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  219. DATA.Subscribe($"{Module}.{Name}.DoorUpperUnlocked", () => _siderData.DoorUpperUnlocked, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  220. DATA.Subscribe($"{Module}.{Name}.TransBladder", () => _siderData.TransBladder, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  221. DATA.Subscribe($"{Module}.{Name}.TransHigh", () => _siderData.TransHigh, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  222. DATA.Subscribe($"{Module}.{Name}.TransPressure", () => _siderData.TransPressure, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  223. DATA.Subscribe($"{Module}.{Name}.TransRetracted", () => _siderData.TransRetracted, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  224. DATA.Subscribe($"{Module}.{Name}.WaferPresent", () => _siderData.WaferPresent, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  225. DATA.Subscribe($"{Module}.{Name}.WSBladder", () => _siderData.WHBladder, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  226. DATA.Subscribe($"{Module}.{Name}.WSBladderPressure", () => _siderData.WHBladderPressure, SubscriptionAttribute.FLAG.IgnoreSaveDB);
  227. }
  228. /// <summary>
  229. /// 订阅变量数值发生变化
  230. /// </summary>
  231. private void SubscribeValueAction()
  232. {
  233. BeckhoffIoSubscribeUpdateVariable(WAFER_PRESENT);
  234. BeckhoffIoSubscribeUpdateVariable(DOOR_UNLOCK);
  235. BeckhoffIoSubscribeUpdateVariable(DOOR_UPPER_LOCKED);
  236. BeckhoffIoSubscribeUpdateVariable(DOOR_UPPER_UNLOCKED);
  237. BeckhoffIoSubscribeUpdateVariable(DOOR_LOWER_LOCKED);
  238. BeckhoffIoSubscribeUpdateVariable(DOOR_LOWER_UNLOCKED);
  239. BeckhoffIoSubscribeUpdateVariable(CRS_VACUUM);
  240. BeckhoffIoSubscribeUpdateVariable(CRS_VACUUM_VALUE);
  241. BeckhoffIoSubscribeUpdateVariable(WH_BLADDER);
  242. BeckhoffIoSubscribeUpdateVariable(WH_BLADDER_PRESSURE);
  243. BeckhoffIoSubscribeUpdateVariable(TRANS_BLADDER);
  244. BeckhoffIoSubscribeUpdateVariable(TRANS_HIGH);
  245. BeckhoffIoSubscribeUpdateVariable(TRANS_RETRACTED);
  246. BeckhoffIoSubscribeUpdateVariable(TRANS_PRESSURE);
  247. BeckhoffIoSubscribeUpdateVariable(BERNOULLI_BLADDER);
  248. BeckhoffIoSubscribeUpdateVariable(BERNOULLI_EXTENDED);
  249. BeckhoffIoSubscribeUpdateVariable(BERNOULLI_N2);
  250. BeckhoffIoSubscribeUpdateVariable(BERNOULLI_N2_SECOND);
  251. BeckhoffIoSubscribeUpdateVariable(BERNOULLI_PRESSURE);
  252. BeckhoffIoSubscribeUpdateVariable(WAFER_HOLDER_LOCKED);
  253. BeckhoffIoSubscribeUpdateVariable(BERNOULLI_BLADDER_PRESSURE);
  254. }
  255. /// <summary>
  256. /// 订阅IO变量
  257. /// </summary>
  258. /// <param name="variable"></param>
  259. private void BeckhoffIoSubscribeUpdateVariable(string variable)
  260. {
  261. _variableInitializeDic[variable] = false;
  262. IOModuleManager.Instance.SubscribeModuleVariable($"{Module}.{Name}", variable, UpdateVariableValue);
  263. }
  264. /// <summary>
  265. /// 初始化操作
  266. /// </summary>
  267. private void InitializeOperation()
  268. {
  269. OP.Subscribe($"{Module}.{Name}.DoorLockOn",(cmd,args)=> { return DoorLockOnAction(); });
  270. OP.Subscribe($"{Module}.{Name}.DoorLockOff",(cmd,args)=> { return DoorLockOffAction(); });
  271. OP.Subscribe($"{Module}.{Name}.VacuumOn", VacuumOnAction);
  272. OP.Subscribe($"{Module}.{Name}.VacuumOff", VacuumOffAction);
  273. OP.Subscribe($"{Module}.{Name}.WhBladderOn", WhBladderOnAction);
  274. OP.Subscribe($"{Module}.{Name}.WhBladderOff", WhBladderOffAction);
  275. OP.Subscribe($"{Module}.{Name}.BernoulliBladderOn", BernoulliBladderOnAction);
  276. OP.Subscribe($"{Module}.{Name}.BernoulliBladderOff", BernoulliBladderOffAction);
  277. OP.Subscribe($"{Module}.{Name}.BernoulliN2On", BernoulliN2OnAction);
  278. OP.Subscribe($"{Module}.{Name}.BernoulliN2Off", BernoulliN2OffAction);
  279. OP.Subscribe($"{Module}.{Name}.Load", LoadAction);
  280. OP.Subscribe($"{Module}.{Name}.Unload", UnloadAction);
  281. OP.Subscribe($"{Module}.{Name}.InstallCRS", InstallCRSAction);
  282. OP.Subscribe($"{Module}.{Name}.StartCycle", StartCycleAction);
  283. OP.Subscribe($"{Module}.{Name}.StopCycle", StopCycleAction);
  284. }
  285. #region Operation
  286. /// <summary>
  287. /// Door Lock On操作
  288. /// </summary>
  289. public bool DoorLockOnAction()
  290. {
  291. if (!JudgeRunningState(LoaderSideOperation.DoorOn))
  292. {
  293. _currentOperation = LoaderSideOperation.DoorOn;
  294. _status = _doorlockRoutine.Start(true);
  295. return true;
  296. }
  297. else
  298. {
  299. return false;
  300. }
  301. }
  302. /// <summary>
  303. /// Door Lock Off操作
  304. /// </summary>
  305. public bool DoorLockOffAction()
  306. {
  307. if (!JudgeRunningState(LoaderSideOperation.DoorOff))
  308. {
  309. _currentOperation = LoaderSideOperation.DoorOff;
  310. _status = _doorlockRoutine.Start(false);
  311. return true;
  312. }
  313. else
  314. {
  315. return false;
  316. }
  317. }
  318. /// <summary>
  319. /// Vacuum On 操作
  320. /// </summary>
  321. private bool VacuumOnAction(string cmd, object[] args)
  322. {
  323. if (!JudgeRunningState(LoaderSideOperation.VacuumOn))
  324. {
  325. _currentOperation = LoaderSideOperation.VacuumOn;
  326. _status = _vacuumRoutine.Start(true);
  327. return true;
  328. }
  329. else
  330. {
  331. return false;
  332. }
  333. }
  334. /// <summary>
  335. /// Vacuum On 操作
  336. /// </summary>
  337. private bool VacuumOffAction(string cmd, object[] args)
  338. {
  339. if (!JudgeRunningState(LoaderSideOperation.VacuumOff))
  340. {
  341. _currentOperation = LoaderSideOperation.VacuumOff;
  342. _status = _vacuumRoutine.Start(false);
  343. return true;
  344. }
  345. else
  346. {
  347. return false;
  348. }
  349. }
  350. /// <summary>
  351. /// WH Bladder On 操作
  352. /// </summary>
  353. private bool WhBladderOnAction(string cmd, object[] args)
  354. {
  355. if (!JudgeRunningState(LoaderSideOperation.WhBladderOn))
  356. {
  357. _currentOperation = LoaderSideOperation.WhBladderOn;
  358. _status = _whBladderRoutine.Start(true);
  359. return true;
  360. }
  361. else
  362. {
  363. return false;
  364. }
  365. }
  366. /// <summary>
  367. /// WH Bladder Off 操作
  368. /// </summary>
  369. private bool WhBladderOffAction(string cmd, object[] args)
  370. {
  371. if (!JudgeRunningState(LoaderSideOperation.WhBladderOff))
  372. {
  373. _currentOperation = LoaderSideOperation.WhBladderOff;
  374. _status = _whBladderRoutine.Start(false);
  375. return true;
  376. }
  377. else
  378. {
  379. return false;
  380. }
  381. }
  382. /// <summary>
  383. /// Bernoulli Bladder On 操作
  384. /// </summary>
  385. private bool BernoulliBladderOnAction(string cmd, object[] args)
  386. {
  387. if (!JudgeRunningState(LoaderSideOperation.BernoulliBladderOn))
  388. {
  389. _currentOperation = LoaderSideOperation.BernoulliBladderOn;
  390. _status = _bernoulliBladderRoutine.Start(true);
  391. return true;
  392. }
  393. else
  394. {
  395. return false;
  396. }
  397. }
  398. /// <summary>
  399. /// Bernoulli Bladder Off 操作
  400. /// </summary>
  401. private bool BernoulliBladderOffAction(string cmd, object[] args)
  402. {
  403. if (!JudgeRunningState(LoaderSideOperation.BernoulliBladderOff))
  404. {
  405. _currentOperation = LoaderSideOperation.BernoulliBladderOff;
  406. _status = _bernoulliBladderRoutine.Start(false);
  407. return true;
  408. }
  409. else
  410. {
  411. return false;
  412. }
  413. }
  414. /// <summary>
  415. /// Bernoulli N2 On 操作
  416. /// </summary>
  417. public bool BernoulliN2OnAction(string cmd, object[] args)
  418. {
  419. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{Name}.{BERNOULLI_N2}");
  420. bool result = IOModuleManager.Instance.WriteIoValue(ioName, true);
  421. return result;
  422. }
  423. /// <summary>
  424. /// Bernoulli N2 Off 操作
  425. /// </summary>
  426. public bool BernoulliN2OffAction(string cmd, object[] args)
  427. {
  428. string ioName = BeckhoffModuleIOManager.Instance.GetIoNameByInnerModuleName($"{Module}.{Name}.{BERNOULLI_N2}");
  429. bool result = IOModuleManager.Instance.WriteIoValue(ioName, false);
  430. return result;
  431. }
  432. /// <summary>
  433. /// Load 操作
  434. /// </summary>
  435. public bool LoadAction(string cmd, object[] args)
  436. {
  437. if (!JudgeRunningState(LoaderSideOperation.Load))
  438. {
  439. _currentOperation = LoaderSideOperation.Load;
  440. _status = _loadRoutine.Start();
  441. return true;
  442. }
  443. else
  444. {
  445. return false;
  446. }
  447. }
  448. /// <summary>
  449. /// Unload 操作
  450. /// </summary>
  451. public bool UnloadAction(string cmd, object[] args)
  452. {
  453. if (!JudgeRunningState(LoaderSideOperation.Unload))
  454. {
  455. _currentOperation = LoaderSideOperation.Unload;
  456. _status = _unloadRoutine.Start();
  457. return true;
  458. }
  459. else
  460. {
  461. return false;
  462. }
  463. }
  464. /// <summary>
  465. /// Install CRS 操作
  466. /// </summary>
  467. private bool InstallCRSAction(string cmd, object[] args)
  468. {
  469. if (!JudgeRunningState(LoaderSideOperation.InstallCRS))
  470. {
  471. _currentOperation = LoaderSideOperation.InstallCRS;
  472. _status = _installCRSRoutine.Start();
  473. return true;
  474. }
  475. else
  476. {
  477. return false;
  478. }
  479. }
  480. /// <summary>
  481. /// StartCycle 操作
  482. /// </summary>
  483. private bool StartCycleAction(string cmd, object[] args)
  484. {
  485. if (!JudgeRunningState(LoaderSideOperation.StartCycle))
  486. {
  487. _currentOperation = LoaderSideOperation.StartCycle;
  488. _status = _cycleRoutine.Start(args);
  489. bool result= _status == RState.Running ;
  490. if(result)
  491. {
  492. _currentCycle = _cycleRoutine.CurrentCycle.ToString();
  493. }
  494. else
  495. {
  496. _currentCycle = "";
  497. }
  498. return result;
  499. }
  500. else
  501. {
  502. return false;
  503. }
  504. }
  505. /// <summary>
  506. /// StopCycle 操作
  507. /// </summary>
  508. private bool StopCycleAction(string cmd, object[] args)
  509. {
  510. if (_currentOperation==LoaderSideOperation.StartCycle)
  511. {
  512. AbortRoutine();
  513. return true;
  514. }
  515. else
  516. {
  517. return true;
  518. }
  519. }
  520. /// <summary>
  521. /// 判定运行状态
  522. /// </summary>
  523. /// <returns></returns>
  524. private bool JudgeRunningState(LoaderSideOperation operation)
  525. {
  526. if (_status == RState.Running)
  527. {
  528. EV.PostAlarmLog($"{Module}.{Name}", eEvent.ERR_LOADER, $"{Module}.{Name} current execute {_currentOperation},cannot {operation}");
  529. return true;
  530. }
  531. return false;
  532. }
  533. #endregion
  534. /// 更新变量数值
  535. /// </summary>
  536. /// <param name="variable"></param>
  537. /// <param name="value"></param>
  538. private void UpdateVariableValue(string variable, object value)
  539. {
  540. PropertyInfo property = SideData.GetType().GetProperty(variable);
  541. if (property != null)
  542. {
  543. property.SetValue(SideData, value);
  544. }
  545. }
  546. /// <summary>
  547. /// 定时器
  548. /// </summary>
  549. /// <returns></returns>
  550. public bool OnTimer()
  551. {
  552. if (_status == RState.Running)
  553. {
  554. if (_currentOperation != LoaderSideOperation.None)
  555. {
  556. IRoutine routine = GetCurrentRoutine(_currentOperation);
  557. if (routine != null)
  558. {
  559. CheckRoutineState(routine, _currentOperation);
  560. }
  561. else
  562. {
  563. EndOperation(RState.End);
  564. }
  565. if(_currentOperation==LoaderSideOperation.StartCycle)
  566. {
  567. _currentCycle = _cycleRoutine.CurrentCycle.ToString();
  568. }
  569. }
  570. }
  571. return true;
  572. }
  573. /// <summary>
  574. /// 获取当前操作对应的Routine
  575. /// </summary>
  576. /// <param name="currentOperation"></param>
  577. /// <returns></returns>
  578. private IRoutine GetCurrentRoutine(LoaderSideOperation currentOperation)
  579. {
  580. switch (currentOperation)
  581. {
  582. case LoaderSideOperation.DoorOn:
  583. case LoaderSideOperation.DoorOff:
  584. return _doorlockRoutine;
  585. case LoaderSideOperation.VacuumOn:
  586. case LoaderSideOperation.VacuumOff:
  587. return _vacuumRoutine;
  588. case LoaderSideOperation.WhBladderOn:
  589. case LoaderSideOperation.WhBladderOff:
  590. return _whBladderRoutine;
  591. case LoaderSideOperation.BernoulliBladderOn:
  592. case LoaderSideOperation.BernoulliBladderOff:
  593. return _bernoulliBladderRoutine;
  594. case LoaderSideOperation.Load:
  595. return _loadRoutine;
  596. case LoaderSideOperation.Unload:
  597. return _unloadRoutine;
  598. case LoaderSideOperation.InstallCRS:
  599. return _installCRSRoutine;
  600. case LoaderSideOperation.StartCycle:
  601. return _cycleRoutine;
  602. default:
  603. return null;
  604. }
  605. }
  606. /// <summary>
  607. /// 检验Routine状态
  608. /// </summary>
  609. /// <param name="routine"></param>
  610. /// <param name="currentOperation"></param>
  611. private void CheckRoutineState(IRoutine routine, LoaderSideOperation currentOperation)
  612. {
  613. RState state = routine.Monitor();
  614. if (state == RState.End)
  615. {
  616. EndOperation(RState.End);
  617. }
  618. else if (state == RState.Failed || state == RState.Timeout)
  619. {
  620. LOG.WriteLog(eEvent.ERR_LOADER, $"{Module}.{Name}", $"{currentOperation} error");
  621. EndOperation(RState.Failed);
  622. }
  623. }
  624. /// <summary>
  625. /// 结束操作
  626. /// </summary>
  627. private void EndOperation(RState state)
  628. {
  629. _status = state;
  630. _currentOperation = LoaderSideOperation.None;
  631. }
  632. /// <summary>
  633. /// 中止Routine
  634. /// </summary>
  635. public void AbortRoutine()
  636. {
  637. IRoutine routine = GetCurrentRoutine(_currentOperation);
  638. if(routine!=null)
  639. {
  640. routine.Abort();
  641. _currentOperation=LoaderSideOperation.None;
  642. _status = RState.End;
  643. _currentCycle = "";
  644. }
  645. }
  646. #region 设备接口
  647. /// <summary>
  648. /// 监控
  649. /// </summary>
  650. public void Monitor()
  651. {
  652. }
  653. public void Reset()
  654. {
  655. }
  656. public void Terminate()
  657. {
  658. AbortRoutine();
  659. }
  660. #endregion
  661. }
  662. }