OperationOverNewViewModel.cs 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155
  1. using MECF.Framework.Common.CommonData;
  2. using MECF.Framework.Common.DataCenter;
  3. using MECF.Framework.Common.Equipment;
  4. using MECF.Framework.Common.OperationCenter;
  5. using OpenSEMI.ClientBase;
  6. using Prism.Commands;
  7. using Prism.Mvvm;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Windows.Threading;
  15. using PunkHPX8_Core;
  16. using PunkHPX8_MainPages.Unity;
  17. using PunkHPX8_MainPages.Views;
  18. using PunkHPX8_Themes.CustomControls;
  19. using PunkHPX8_Themes.Unity;
  20. using PunkHPX8_Themes.UserControls;
  21. using Aitex.Core.RT.Log;
  22. using MECF.Framework.Common.Reservior;
  23. using MECF.Framework.Common.ProcessCell;
  24. using MECF.Framework.Common.Utilities;
  25. using Aitex.Sorter.Common;
  26. using MECF.Framework.Common.Schedulers;
  27. using MECF.Framework.Common.Beckhoff.Station;
  28. using MECF.Framework.Common.Layout;
  29. using Aitex.Core.RT.Routine;
  30. using Aitex.Core.RT.Device;
  31. using System.Reflection;
  32. using MECF.Framework.Common.Beckhoff.IOAxis;
  33. using MECF.Framework.Common.TwinCat;
  34. using LiveCharts.Wpf;
  35. using MECF.Framework.Common.Beckhoff.AxisProvider;
  36. using QiHe.CodeLib;
  37. using MECF.Framework.Common.Jobs;
  38. using ExcelLibrary.BinaryFileFormat;
  39. namespace PunkHPX8_MainPages.ViewModels
  40. {
  41. public class OperationOverNewViewModel : BindableBase
  42. {
  43. #region 常量
  44. private const string CURRENT_STATION = "CurrentStation";
  45. private const string MOTOR_POSITION = "MotorPosition";
  46. private const string MOTION_DATA = "MotionData";
  47. private const double LOADER_ROTATION_DIFFER = 90;
  48. #endregion
  49. #region 私有字段
  50. private bool _isLp1Unable;
  51. private bool _isLp2Unable;
  52. private ModuleInfo _LP1ModuleInfo;
  53. private ModuleInfo _LP2ModuleInfo;
  54. private ModuleInfo _EFEMModuleInfo;
  55. private ModuleInfo _srd1ModuleInfo;
  56. private ModuleInfo _srd2ModuleInfo;
  57. private ModuleInfo _dummy1ModuleInfo;
  58. private ModuleInfo _dummy2ModuleInfo;
  59. private WaferRobotTAction m_Robot1TAction;
  60. private WaferRobotXAction m_Robot1XAction;
  61. private WaferRobotTAction m_Robot2TAction;
  62. private WaferRobotXAction m_Robot2XAction;
  63. private WaferRobotFAction m_Robot2FAction;
  64. private RobotMoveInfo m_robotMoveInfo;
  65. private WaferInfo m_srd1Wafer;
  66. private WaferInfo m_srd2Wafer;
  67. private List<string> m_RtDataKeys = new List<string>();
  68. private Dictionary<string, object> m_RtDataValues;
  69. private bool m_EFEMIsInstalled;
  70. private WaferInfo m_EFEMBladeAWafer;
  71. private WaferInfo m_EFEMBladeBWafer;
  72. private WaferInfo m_Aligner1Wafer;
  73. private WaferInfo m_vpw1Wafer;
  74. private WaferInfo m_vpw2Wafer;
  75. private WaferInfo m_platingCell1Wafer;
  76. private WaferInfo m_platingCell2Wafer;
  77. private WaferInfo m_platingCell3Wafer;
  78. private WaferInfo m_platingCell4Wafer;
  79. private int m_LP1WaferCount;
  80. private int m_LP2WaferCount;
  81. private int m_dummy1WaferCount;
  82. private int m_dummy2WaferCount;
  83. private int m_CycledWafer;
  84. private int m_CycleCountDisplay;
  85. private EFEM.RobotPosition m_CurrentRobotPosition;
  86. private WaferInfo m_BladeAWafer;
  87. private WaferInfo m_BladeBWafer;
  88. private string m_RouteState;
  89. /// <summary>
  90. /// 定时器
  91. /// </summary>
  92. private DispatcherTimer _timer;
  93. /// <summary>
  94. /// 是否存在Job
  95. /// </summary>
  96. private bool _isLp1HasNoJob;
  97. private bool _isLp2HasNoJob;
  98. #endregion
  99. #region 属性
  100. public bool IsLP1Unable
  101. {
  102. get { return _isLp1Unable; }
  103. set { SetProperty(ref _isLp1Unable, value); }
  104. }
  105. public bool IsLP2Unable
  106. {
  107. get { return _isLp2Unable; }
  108. set { SetProperty(ref _isLp2Unable, value); }
  109. }
  110. public ModuleInfo LP1ModuleInfo
  111. {
  112. get { return _LP1ModuleInfo; }
  113. set { SetProperty(ref _LP1ModuleInfo, value); }
  114. }
  115. public ModuleInfo EFEMModuleInfo
  116. {
  117. get { return _EFEMModuleInfo; }
  118. set { SetProperty(ref _EFEMModuleInfo, value); }
  119. }
  120. public ModuleInfo LP2ModuleInfo
  121. {
  122. get { return _LP2ModuleInfo; }
  123. set { SetProperty(ref _LP2ModuleInfo, value); }
  124. }
  125. public ModuleInfo SRD1ModuleInfo
  126. {
  127. get { return _srd1ModuleInfo; }
  128. set { SetProperty(ref _srd1ModuleInfo, value); }
  129. }
  130. public ModuleInfo SRD2ModuleInfo
  131. {
  132. get { return _srd2ModuleInfo; }
  133. set { SetProperty(ref _srd2ModuleInfo, value); }
  134. }
  135. public ModuleInfo Dummy1ModuleInfo
  136. {
  137. get { return _dummy1ModuleInfo; }
  138. set { SetProperty(ref _dummy1ModuleInfo, value); }
  139. }
  140. public ModuleInfo Dummy2ModuleInfo
  141. {
  142. get { return _dummy2ModuleInfo; }
  143. set { SetProperty(ref _dummy2ModuleInfo, value); }
  144. }
  145. public WaferRobotTAction Robot1TAction
  146. {
  147. get { return m_Robot1TAction; }
  148. set { SetProperty(ref m_Robot1TAction, value); }
  149. }
  150. public WaferRobotXAction Robot1XAction
  151. {
  152. get { return m_Robot1XAction; }
  153. set { SetProperty(ref m_Robot1XAction, value); }
  154. }
  155. public WaferRobotTAction Robot2TAction
  156. {
  157. get { return m_Robot2TAction; }
  158. set { SetProperty(ref m_Robot2TAction, value); }
  159. }
  160. public WaferRobotXAction Robot2XAction
  161. {
  162. get { return m_Robot2XAction; }
  163. set { SetProperty(ref m_Robot2XAction, value); }
  164. }
  165. public WaferRobotFAction Robot2FAction
  166. {
  167. get { return m_Robot2FAction; }
  168. set { SetProperty(ref m_Robot2FAction, value); }
  169. }
  170. public RobotMoveInfo RobotMoveInfo
  171. {
  172. get { return m_robotMoveInfo; }
  173. set
  174. {
  175. RobotMoveInfoChanged(m_robotMoveInfo, value);
  176. //m_robotMoveInfo = value;
  177. SetProperty(ref m_robotMoveInfo, value);
  178. }
  179. }
  180. public Dictionary<string, object> RtDataValues
  181. {
  182. get { return m_RtDataValues; }
  183. set { SetProperty(ref m_RtDataValues, value); }
  184. }
  185. public bool EFEMIsInstalled
  186. {
  187. get { return m_EFEMIsInstalled; }
  188. set { SetProperty(ref m_EFEMIsInstalled, value); }
  189. }
  190. public WaferInfo EFEMBladeAWafer
  191. {
  192. get { return m_EFEMBladeAWafer; }
  193. set { SetProperty(ref m_EFEMBladeAWafer, value); }
  194. }
  195. public WaferInfo EFEMBladeBWafer
  196. {
  197. get { return m_EFEMBladeBWafer; }
  198. set { SetProperty(ref m_EFEMBladeBWafer, value); }
  199. }
  200. public WaferInfo Aligner1Wafer
  201. {
  202. get { return m_Aligner1Wafer; }
  203. set { SetProperty(ref m_Aligner1Wafer, value); }
  204. }
  205. public WaferInfo VPW1Wafer
  206. {
  207. get { return m_vpw1Wafer; }
  208. set { SetProperty(ref m_vpw1Wafer, value); }
  209. }
  210. public WaferInfo VPW2Wafer
  211. {
  212. get { return m_vpw2Wafer; }
  213. set { SetProperty(ref m_vpw2Wafer, value); }
  214. }
  215. public WaferInfo PlatingCell1Wafer
  216. {
  217. get { return m_platingCell1Wafer; }
  218. set { SetProperty(ref m_platingCell1Wafer, value); }
  219. }
  220. public WaferInfo PlatingCell2Wafer
  221. {
  222. get { return m_platingCell2Wafer; }
  223. set { SetProperty(ref m_platingCell2Wafer, value); }
  224. }
  225. public WaferInfo PlatingCell3Wafer
  226. {
  227. get { return m_platingCell3Wafer; }
  228. set { SetProperty(ref m_platingCell3Wafer, value); }
  229. }
  230. public WaferInfo PlatingCell4Wafer
  231. {
  232. get { return m_platingCell4Wafer; }
  233. set { SetProperty(ref m_platingCell4Wafer, value); }
  234. }
  235. public WaferInfo SRD1Wafer
  236. {
  237. get { return m_srd1Wafer; }
  238. set { SetProperty(ref m_srd1Wafer, value); }
  239. }
  240. public WaferInfo SRD2Wafer
  241. {
  242. get { return m_srd2Wafer; }
  243. set { SetProperty(ref m_srd2Wafer, value); }
  244. }
  245. public int LP1WaferCount
  246. {
  247. get { return m_LP1WaferCount; }
  248. set { SetProperty(ref m_LP1WaferCount, value); }
  249. }
  250. public int LP2WaferCount
  251. {
  252. get { return m_LP2WaferCount; }
  253. set { SetProperty(ref m_LP2WaferCount, value); }
  254. }
  255. public int Dummy1WaferCount
  256. {
  257. get { return m_dummy1WaferCount; }
  258. set { SetProperty(ref m_dummy1WaferCount, value); }
  259. }
  260. public int Dummy2WaferCount
  261. {
  262. get { return m_dummy2WaferCount; }
  263. set { SetProperty(ref m_dummy2WaferCount, value); }
  264. }
  265. public int CycledWafer
  266. {
  267. get { return m_CycledWafer; }
  268. set { SetProperty(ref m_CycledWafer, value); }
  269. }
  270. public int CycleCountDisplay
  271. {
  272. get { return m_CycleCountDisplay; }
  273. set { SetProperty(ref m_CycleCountDisplay, value); }
  274. }
  275. public RobotMoveInfo m_EfemRobotMoveInfo;
  276. public RobotMoveInfo EfemRobotMoveInfo
  277. {
  278. get { return m_EfemRobotMoveInfo; }
  279. set
  280. {
  281. EFEMRobotMoveInfoChanged(m_EfemRobotMoveInfo, value);
  282. //m_EfemRobotMoveInfo = value;
  283. SetProperty(ref m_EfemRobotMoveInfo, value);
  284. }
  285. }
  286. public EFEM.RobotPosition CurrentRobotPosition
  287. {
  288. get { return m_CurrentRobotPosition; }
  289. set { SetProperty(ref m_CurrentRobotPosition, value); }
  290. }
  291. public WaferInfo BladeAWafer
  292. {
  293. get { return m_BladeAWafer; }
  294. set { SetProperty(ref m_BladeAWafer, value); }
  295. }
  296. public WaferInfo BladeBWafer
  297. {
  298. get { return m_BladeBWafer; }
  299. set { SetProperty(ref m_BladeBWafer, value); }
  300. }
  301. public string RouteState
  302. {
  303. get { return m_RouteState; }
  304. set { SetProperty(ref m_RouteState, value); }
  305. }
  306. public bool IsLP1HasNoJob
  307. {
  308. get { return _isLp1HasNoJob; }
  309. set { SetProperty(ref _isLp1HasNoJob, value); }
  310. }
  311. public bool IsLP2HasNoJob
  312. {
  313. get { return _isLp2HasNoJob; }
  314. set { SetProperty(ref _isLp2HasNoJob, value); }
  315. }
  316. #endregion
  317. #region 命令
  318. private DelegateCommand<object> _MapCommand;
  319. public DelegateCommand<object> MapCommand =>
  320. _MapCommand ?? (_MapCommand = new DelegateCommand<object>(OnMap));
  321. private DelegateCommand<object> _StartCommand;
  322. public DelegateCommand<object> StartCommand =>
  323. _StartCommand ?? (_StartCommand = new DelegateCommand<object>(OnStart));
  324. private DelegateCommand<object> _StopCommand;
  325. public DelegateCommand<object> StopCommand =>
  326. _StopCommand ?? (_StopCommand = new DelegateCommand<object>(OnStop));
  327. private DelegateCommand<object> _AbortCommand;
  328. public DelegateCommand<object> AbortCommand =>
  329. _AbortCommand ?? (_AbortCommand = new DelegateCommand<object>(OnAbort));
  330. private DelegateCommand _HomeAllCommand;
  331. public DelegateCommand HomeAllCommand =>
  332. _HomeAllCommand ?? (_HomeAllCommand = new DelegateCommand(OnHomeAll));
  333. private DelegateCommand _ResumeAllJobCommand;
  334. public DelegateCommand ResumeAllJobCommand =>
  335. _ResumeAllJobCommand ?? (_ResumeAllJobCommand = new DelegateCommand(OnResumeAllJob));
  336. private DelegateCommand _AbortAllCommand;
  337. public DelegateCommand AbortAllCommand =>
  338. _AbortAllCommand ?? (_AbortAllCommand = new DelegateCommand(OnAbortAll));
  339. private DelegateCommand _ReturnAllWaferCommand;
  340. public DelegateCommand ReturnAllWaferCommand =>
  341. _ReturnAllWaferCommand ?? (_ReturnAllWaferCommand = new DelegateCommand(OnReturnAllWafer));
  342. private DelegateCommand<object> _SetSequenceCommand;
  343. public DelegateCommand<object> SetSequenceCommand =>
  344. _SetSequenceCommand ?? (_SetSequenceCommand = new DelegateCommand<object>(OnSetSequence));
  345. private DelegateCommand _EnableAutoCommand;
  346. public DelegateCommand EnableAutoCommand =>
  347. _EnableAutoCommand ?? (_EnableAutoCommand = new DelegateCommand(OnEnableAuto));
  348. private DelegateCommand _EnableManualCommand;
  349. public DelegateCommand EnableManualCommand =>
  350. _EnableManualCommand ?? (_EnableManualCommand = new DelegateCommand(OnEnableManual));
  351. private DelegateCommand<object> _GotoSrdViewCommond;
  352. public DelegateCommand<object> GotoSrdViewCommond =>
  353. _GotoSrdViewCommond ?? (_GotoSrdViewCommond = new DelegateCommand<object>(GotoSrdViewAction));
  354. public bool SwitchFlag;
  355. #endregion
  356. #region 构造函数
  357. public OperationOverNewViewModel()
  358. {
  359. addDataKeys();
  360. }
  361. #endregion
  362. #region 命令方法
  363. /// <summary>
  364. /// 加载数据
  365. /// </summary>
  366. public void LoadData(string systemName)
  367. {
  368. Dictionary<string, object> allModulesDictionary = QueryDataClient.Instance.Service.PollData(new List<string>() { "System.InstalledModules" });
  369. if (allModulesDictionary != null)
  370. {
  371. List<string> allModules = CommonFunction.GetValue<List<string>>(allModulesDictionary, "System.InstalledModules");
  372. EFEMIsInstalled = allModules.Contains("EFEM");
  373. }
  374. if (_timer == null)
  375. {
  376. _timer = new DispatcherTimer();
  377. _timer.Interval = TimeSpan.FromMilliseconds(100);
  378. _timer.Tick += Timer_Tick;
  379. }
  380. _timer.Start();
  381. RtDataValues = QueryDataClient.Instance.Service.PollData(m_RtDataKeys);
  382. }
  383. /// <summary>
  384. /// 隐藏
  385. /// </summary>
  386. public void Hide()
  387. {
  388. if (_timer != null)
  389. {
  390. _timer.Stop();
  391. }
  392. }
  393. private void OnMap(object obj)
  394. {
  395. InvokeClient.Instance.Service.DoOperation($"{obj.ToString()}.Map");
  396. }
  397. private void OnStart(object obj)
  398. {
  399. var info = obj as WaferAssociationInfo;
  400. InvokeClient.Instance.Service.DoOperation("System.StartJob", info.LotId);
  401. }
  402. private void OnStop(object obj)
  403. {
  404. var info = obj as WaferAssociationInfo;
  405. InvokeClient.Instance.Service.DoOperation("System.PauseJob", info.JobID);
  406. }
  407. private void OnAbort(object obj)
  408. {
  409. var info = obj as WaferAssociationInfo;
  410. InvokeClient.Instance.Service.DoOperation("System.ResumeJob", info.JobID);
  411. }
  412. private void OnHomeAll()
  413. {
  414. InvokeClient.Instance.Service.DoOperation("System.HomeAll");
  415. }
  416. private void OnResumeAllJob()
  417. {
  418. if (CommonFunction.GetValue<int>(RtDataValues, "EquipmentStatus") == 4)
  419. {
  420. InvokeClient.Instance.Service.DoOperation("System.ResumeAllJob");
  421. }
  422. else
  423. {
  424. InvokeClient.Instance.Service.DoOperation("System.PauseAllJob");
  425. }
  426. }
  427. private void OnAbortAll()
  428. {
  429. InvokeClient.Instance.Service.DoOperation("System.Abort");
  430. }
  431. private void OnReturnAllWafer()
  432. {
  433. //Dialog
  434. WaferDialogView dialog = new WaferDialogView()
  435. {
  436. Owner = Application.Current.MainWindow,
  437. };
  438. dialog.Height = 300;
  439. dialog.Width = 400;
  440. double angel = 0;
  441. double coolingtime = 0;
  442. string message = "Please Confirm Return Wafer";
  443. WaferDialogViewModel vm = new WaferDialogViewModel();
  444. vm.ConfirmText = message;
  445. dialog.DataContext = vm;
  446. if (dialog.ShowDialog() == true)
  447. {
  448. if ((bool)dialog.AlignFlag == true && !string.IsNullOrEmpty(dialog.Angle))
  449. {
  450. angel = Convert.ToDouble(dialog.Angle);
  451. }
  452. if ((bool)dialog.CoolingFlag == true && !string.IsNullOrEmpty(dialog.CoolingTime))
  453. {
  454. coolingtime = Convert.ToDouble(dialog.CoolingTime);
  455. }
  456. InvokeClient.Instance.Service.DoOperation("System.ReturnAllWafer", dialog.CoolingFlag, coolingtime, dialog.AlignFlag, angel);
  457. }
  458. }
  459. private void OnSetSequence(object obj)
  460. {
  461. var info = obj as WaferInfo;
  462. bool flag = info.SequenceName != "" ? false : true;
  463. }
  464. private void OnEnableAuto()
  465. {
  466. InvokeClient.Instance.Service.DoOperation("System.SetAutoMode");
  467. }
  468. private void OnEnableManual()
  469. {
  470. InvokeClient.Instance.Service.DoOperation("System.SetManualMode");
  471. }
  472. private void GotoSrdViewAction(object obj)
  473. {
  474. PunkHPX8_Core.GlobalEvents.OnSwitchFixedTabItem("HardWare", "SRD", $"{obj.ToString()}");
  475. }
  476. #endregion
  477. #region 私有方法
  478. /// <summary>
  479. /// 定时器
  480. /// </summary>
  481. /// <param name="sender"></param>
  482. /// <param name="e"></param>
  483. private void Timer_Tick(object sender, EventArgs e)
  484. {
  485. LP1ModuleInfo = ModuleManager.ModuleInfos["LP1"];
  486. LP2ModuleInfo = ModuleManager.ModuleInfos["LP2"];
  487. EFEMModuleInfo = ModuleManager.ModuleInfos["EfemRobot"];
  488. SRD1ModuleInfo = ModuleManager.ModuleInfos["SRD1"];
  489. SRD2ModuleInfo = ModuleManager.ModuleInfos["SRD2"];
  490. Dummy1ModuleInfo = ModuleManager.ModuleInfos["Dummy1"];
  491. Dummy2ModuleInfo = ModuleManager.ModuleInfos["Dummy2"];
  492. if (ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers.Count != 0)
  493. {
  494. BladeAWafer = ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers[0];
  495. BladeBWafer = ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers[1];
  496. }
  497. if (EFEMIsInstalled == true)
  498. {
  499. if (ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers.Count != 0)
  500. {
  501. EFEMBladeAWafer = ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers[0];
  502. EFEMBladeBWafer = ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers[1];
  503. }
  504. if (ModuleManager.ModuleInfos["Aligner1"].WaferManager.Wafers.Count != 0)
  505. {
  506. Aligner1Wafer = ModuleManager.ModuleInfos["Aligner1"].WaferManager.Wafers[0];
  507. }
  508. }
  509. if (ModuleManager.ModuleInfos["VPW1"].WaferManager.Wafers.Count != 0)
  510. {
  511. VPW1Wafer = ModuleManager.ModuleInfos["VPW1"].WaferManager.Wafers[0];
  512. }
  513. if (ModuleManager.ModuleInfos["VPW2"].WaferManager.Wafers.Count != 0)
  514. {
  515. VPW2Wafer = ModuleManager.ModuleInfos["VPW2"].WaferManager.Wafers[0];
  516. }
  517. if (ModuleManager.ModuleInfos["PlatingCell1"].WaferManager.Wafers.Count!=0)
  518. {
  519. PlatingCell1Wafer = ModuleManager.ModuleInfos["PlatingCell1"].WaferManager.Wafers[0];
  520. }
  521. if (ModuleManager.ModuleInfos["PlatingCell2"].WaferManager.Wafers.Count != 0)
  522. {
  523. PlatingCell2Wafer = ModuleManager.ModuleInfos["PlatingCell2"].WaferManager.Wafers[0];
  524. }
  525. if (ModuleManager.ModuleInfos["PlatingCell3"].WaferManager.Wafers.Count != 0)
  526. {
  527. PlatingCell3Wafer = ModuleManager.ModuleInfos["PlatingCell3"].WaferManager.Wafers[0];
  528. }
  529. if (ModuleManager.ModuleInfos["PlatingCell4"].WaferManager.Wafers.Count != 0)
  530. {
  531. PlatingCell4Wafer = ModuleManager.ModuleInfos["PlatingCell4"].WaferManager.Wafers[0];
  532. }
  533. if (SRD1ModuleInfo != null&& SRD1ModuleInfo.WaferManager.Wafers.Count!=0)
  534. {
  535. SRD1Wafer = SRD1ModuleInfo.WaferManager.Wafers[0];
  536. }
  537. if (SRD2ModuleInfo != null&& SRD2ModuleInfo.WaferManager.Wafers.Count!=0)
  538. {
  539. SRD2Wafer = SRD2ModuleInfo.WaferManager.Wafers[0];
  540. }
  541. EfemRobotMoveInfo = (RobotMoveInfo)QueryDataClient.Instance.Service.GetData("EFEM.RobotMoveAction");
  542. LP1WaferCount = LP1ModuleInfo.WaferManager.Wafers.Where(x => x.WaferStatus != 0).Count();
  543. LP2WaferCount = LP2ModuleInfo.WaferManager.Wafers.Where(x => x.WaferStatus != 0).Count();
  544. //Dummy1WaferCount = 15;
  545. Dummy1WaferCount = Dummy1ModuleInfo.WaferManager.Wafers.Where(x => x.WaferStatus != 0).Count();
  546. Dummy2WaferCount = Dummy2ModuleInfo.WaferManager.Wafers.Where(x => x.WaferStatus != 0).Count();
  547. RtDataValues = QueryDataClient.Instance.Service.PollData(m_RtDataKeys);
  548. IsLP1Unable = (bool)QueryDataClient.Instance.Service.GetConfig("EFEM.IsLoadPort1Unable");
  549. IsLP2Unable = (bool)QueryDataClient.Instance.Service.GetConfig("EFEM.IsLoadPort2Unable");
  550. if (RtDataValues != null)
  551. {
  552. if (CommonFunction.GetValue<int>(RtDataValues, "EquipmentStatus") == 4)
  553. {
  554. RouteState = "Resume";
  555. }
  556. else
  557. {
  558. RouteState = "Pause";
  559. }
  560. ControlJobInfo lp1Cj = CommonFunction.GetValue<ControlJobInfo>(RtDataValues, "LP1.CurrentControlJob");
  561. IsLP1HasNoJob = lp1Cj == null ? true : false;
  562. ControlJobInfo lp2Cj = CommonFunction.GetValue<ControlJobInfo>(RtDataValues, "LP2.CurrentControlJob");
  563. IsLP2HasNoJob = lp2Cj == null ? true : false;
  564. }
  565. }
  566. int count = 0;
  567. private async void RobotMoveInfoChanged(RobotMoveInfo oldValue, RobotMoveInfo newValue)
  568. {
  569. string RobotTarget;
  570. if (oldValue == null || newValue == null)
  571. {
  572. return;
  573. }
  574. #region Rotating
  575. if ((oldValue.Action == RobotAction.None || oldValue.ArmTarget != newValue.ArmTarget) && (newValue.Action == RobotAction.Rotating))
  576. {
  577. var TMRobotMoveActionBladeTarget = newValue.BladeTarget;
  578. if (TMRobotMoveActionBladeTarget != null)
  579. {
  580. RobotTarget = TMRobotMoveActionBladeTarget.ToString();
  581. }
  582. else
  583. {
  584. return;
  585. }
  586. var values = RobotTarget.Split('.');
  587. var arm = values[0];
  588. var module = values[1];
  589. if (arm == "ArmA")
  590. {
  591. Robot1TAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true);
  592. }
  593. else if (arm == "ArmB")
  594. {
  595. Robot2TAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true);
  596. }
  597. }
  598. #endregion
  599. #region pick 和 place LL
  600. else if ((oldValue.Action == RobotAction.None || oldValue.ArmTarget != newValue.ArmTarget) && (newValue.Action == RobotAction.Placing || newValue.Action == RobotAction.Picking))
  601. {
  602. var TMRobotMoveActionBladeTarget = newValue.BladeTarget;
  603. if (TMRobotMoveActionBladeTarget != null)
  604. {
  605. RobotTarget = TMRobotMoveActionBladeTarget.ToString();
  606. }
  607. else
  608. {
  609. return;
  610. }
  611. var values = RobotTarget.Split('.');
  612. var arm = values[0];
  613. var module = values[1];
  614. if (arm == "ArmA")
  615. {
  616. var waferRobotTAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true);
  617. if (waferRobotTAction != Robot1TAction)
  618. {
  619. Robot1TAction = waferRobotTAction;
  620. }
  621. else
  622. {
  623. //await Task.Delay(100);
  624. }
  625. await Task.Delay(600);
  626. //Robot1TAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true);
  627. //await Task.Delay(600);
  628. Robot1XAction = WaferRobotXAction.Extend;
  629. while ((newValue.Action == RobotAction.Placing && ModuleManager.ModuleInfos["TMRobot"].WaferManager.Wafers[0].WaferStatus != 0) || (newValue.Action == RobotAction.Picking && ModuleManager.ModuleInfos["TMRobot"].WaferManager.Wafers[0].WaferStatus == 0))
  630. {
  631. await Task.Delay(100);
  632. }
  633. Robot1XAction = WaferRobotXAction.Retract;
  634. }
  635. else if (arm == "ArmB")
  636. {
  637. var waferRobotTAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true);
  638. if (waferRobotTAction != Robot2TAction)
  639. {
  640. Robot2TAction = waferRobotTAction;
  641. }
  642. else
  643. {
  644. //await Task.Delay(100);
  645. }
  646. await Task.Delay(600);
  647. //Robot2TAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true);
  648. //await Task.Delay(600);
  649. Robot2XAction = WaferRobotXAction.Extend;
  650. while ((newValue.Action == RobotAction.Placing && ModuleManager.ModuleInfos["TMRobot"].WaferManager.Wafers[1].WaferStatus != 0) || (newValue.Action == RobotAction.Picking && ModuleManager.ModuleInfos["TMRobot"].WaferManager.Wafers[1].WaferStatus == 0))
  651. {
  652. await Task.Delay(100);
  653. }
  654. Robot2XAction = WaferRobotXAction.Retract;
  655. }
  656. }
  657. #endregion
  658. #region pick 和 place pm
  659. else if ((oldValue.Action == RobotAction.None || oldValue.ArmTarget != newValue.ArmTarget) && newValue.Action == RobotAction.Extending)
  660. {
  661. var TMRobotMoveActionBladeTarget = newValue.BladeTarget;
  662. if (TMRobotMoveActionBladeTarget != null)
  663. {
  664. RobotTarget = TMRobotMoveActionBladeTarget.ToString();
  665. }
  666. else
  667. {
  668. return;
  669. }
  670. var values = RobotTarget.Split('.');
  671. var arm = values[0];
  672. var module = values[1];
  673. if (arm == "ArmA")
  674. {
  675. var waferRobotTAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true);
  676. if (waferRobotTAction != Robot1TAction)
  677. {
  678. Robot1TAction = waferRobotTAction;
  679. }
  680. else
  681. {
  682. // await Task.Delay(100);
  683. }
  684. await Task.Delay(600);
  685. Robot1XAction = WaferRobotXAction.Extend;
  686. }
  687. else if (arm == "ArmB")
  688. {
  689. var waferRobotTAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true);
  690. if (waferRobotTAction != Robot2TAction)
  691. {
  692. Robot2TAction = waferRobotTAction;
  693. }
  694. else
  695. {
  696. // await Task.Delay(100);
  697. }
  698. await Task.Delay(600);
  699. Robot2XAction = WaferRobotXAction.Extend;
  700. }
  701. }
  702. else if ((oldValue.Action == RobotAction.None || oldValue.ArmTarget != newValue.ArmTarget) && newValue.Action == RobotAction.Retracting)
  703. {
  704. var TMRobotMoveActionBladeTarget = newValue.BladeTarget;
  705. if (TMRobotMoveActionBladeTarget != null)
  706. {
  707. RobotTarget = TMRobotMoveActionBladeTarget.ToString();
  708. }
  709. else
  710. {
  711. return;
  712. }
  713. var values = RobotTarget.Split('.');
  714. var arm = values[0];
  715. if (arm == "ArmA")
  716. {
  717. Robot1XAction = WaferRobotXAction.Retract;
  718. }
  719. else if (arm == "ArmB")
  720. {
  721. Robot2XAction = WaferRobotXAction.Retract;
  722. }
  723. }
  724. #endregion
  725. #region Home
  726. else if (oldValue.Action == RobotAction.None && newValue.Action == RobotAction.Homing)
  727. {
  728. if (Robot1XAction == WaferRobotXAction.Extend)
  729. {
  730. Robot1XAction = WaferRobotXAction.Retract;
  731. }
  732. if (Robot2XAction == WaferRobotXAction.Extend)
  733. {
  734. Robot2XAction = WaferRobotXAction.Retract;
  735. }
  736. await Task.Delay(2000);
  737. if (Robot1TAction != WaferRobotTAction.T_Origin)
  738. {
  739. Robot1TAction = WaferRobotTAction.T_Origin;
  740. }
  741. if (Robot2TAction != WaferRobotTAction.T_Origin)
  742. {
  743. Robot2TAction = WaferRobotTAction.T_Origin;
  744. }
  745. }
  746. #endregion
  747. }
  748. private async void EFEMRobotMoveInfoChanged(RobotMoveInfo oldValue, RobotMoveInfo newValue)
  749. {
  750. string RobotTarget;
  751. if (oldValue == null || newValue == null)
  752. {
  753. return;
  754. }
  755. if ((oldValue.Action == RobotAction.None || oldValue.ArmTarget != newValue.ArmTarget) && (newValue.Action == RobotAction.Placing || newValue.Action == RobotAction.Picking))
  756. {
  757. var TMRobotMoveActionBladeTarget = newValue.BladeTarget;
  758. if (TMRobotMoveActionBladeTarget != null)
  759. {
  760. RobotTarget = TMRobotMoveActionBladeTarget.ToString();
  761. }
  762. else
  763. {
  764. return;
  765. }
  766. var values = RobotTarget.Split('.');
  767. var arm = values[0];
  768. var module = values[1];
  769. if (arm == "ArmA")
  770. {
  771. var robot1Robot1TAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true);
  772. //Robot整体平移动画
  773. await ChangePosition(robot1Robot1TAction, newValue.Action);
  774. if (Robot1TAction != robot1Robot1TAction)
  775. {
  776. Robot1TAction = robot1Robot1TAction;
  777. await Task.Delay(600);
  778. }
  779. //await Task.Delay(1500);
  780. Robot1XAction = WaferRobotXAction.Extend;
  781. while ((newValue.Action == RobotAction.Placing && ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers[0].WaferStatus != 0) || (newValue.Action == RobotAction.Picking && ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers[0].WaferStatus == 0))
  782. {
  783. await Task.Delay(100);
  784. }
  785. Robot1XAction = WaferRobotXAction.Retract;
  786. if (newValue.Action == RobotAction.Placing)
  787. {
  788. await ChangePosition(WaferRobotTAction.T_Origin, newValue.Action);
  789. }
  790. }
  791. else //使用上手臂
  792. {
  793. //实现翻转动画
  794. if (newValue.BladeTarget.Split('.')[2] == "Down")
  795. {
  796. Robot2FAction = WaferRobotFAction.UpperToDown;
  797. }
  798. else if (newValue.BladeTarget.Split('.')[2] == "Upper")
  799. {
  800. Robot2FAction = WaferRobotFAction.DownToUpper;
  801. }
  802. var robot1Robot1TAction = (WaferRobotTAction)Enum.Parse(typeof(WaferRobotTAction), module, true);
  803. //Robot整体平移动画
  804. await ChangePosition(robot1Robot1TAction, newValue.Action);
  805. if (Robot1TAction != robot1Robot1TAction)
  806. {
  807. Robot1TAction = robot1Robot1TAction;
  808. await Task.Delay(600);
  809. }
  810. //await Task.Delay(1500);
  811. Robot1XAction = WaferRobotXAction.Extend2;
  812. while ((newValue.Action == RobotAction.Placing && ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers[1].WaferStatus != 0) || (newValue.Action == RobotAction.Picking && ModuleManager.ModuleInfos["EfemRobot"].WaferManager.Wafers[1].WaferStatus == 0))
  813. {
  814. await Task.Delay(100);
  815. }
  816. Robot1XAction = WaferRobotXAction.Retract2;
  817. if (newValue.Action == RobotAction.Placing)
  818. {
  819. await ChangePosition(WaferRobotTAction.T_Origin, newValue.Action);
  820. }
  821. }
  822. }
  823. #region Home
  824. else if (oldValue.Action == RobotAction.None && newValue.Action == RobotAction.Homing)
  825. {
  826. if (Robot1XAction == WaferRobotXAction.Extend || Robot2XAction == WaferRobotXAction.Extend2)
  827. {
  828. Robot1XAction = WaferRobotXAction.Retract2;
  829. }
  830. if (Robot2XAction == WaferRobotXAction.Extend || Robot2XAction == WaferRobotXAction.Extend2)
  831. {
  832. Robot2XAction = WaferRobotXAction.Retract2;
  833. }
  834. await Task.Delay(2000);
  835. if (Robot1TAction != WaferRobotTAction.T_Origin)
  836. {
  837. Robot1TAction = WaferRobotTAction.T_Origin;
  838. }
  839. if (Robot2TAction != WaferRobotTAction.T_Origin)
  840. {
  841. Robot2TAction = WaferRobotTAction.T_Origin;
  842. }
  843. if (CurrentRobotPosition != EFEM.RobotPosition.Origin)
  844. {
  845. CurrentRobotPosition = EFEM.RobotPosition.Origin;
  846. }
  847. await ChangePosition(WaferRobotTAction.T_Origin, newValue.Action);
  848. }
  849. #endregion
  850. }
  851. private void addDataKeys()
  852. {
  853. m_RtDataKeys.Add("LP1.IsLoaded");
  854. m_RtDataKeys.Add("LP2.IsLoaded");
  855. m_RtDataKeys.Add("LP1.CassettePlaced");
  856. m_RtDataKeys.Add("LP2.CassettePlaced");
  857. m_RtDataKeys.Add("LP1.CurrentControlJob");
  858. m_RtDataKeys.Add("LP2.CurrentControlJob");
  859. m_RtDataKeys.Add("LP1.WaferSize");
  860. m_RtDataKeys.Add("LP2.WaferSize");
  861. m_RtDataKeys.Add("Dummy1.CassettePlaced");
  862. m_RtDataKeys.Add("Dummy2.CassettePlaced");
  863. m_RtDataKeys.Add("Dummy1.WaferSize");
  864. m_RtDataKeys.Add("Dummy2.WaferSize");
  865. m_RtDataKeys.Add("System.IsAutoMode");
  866. m_RtDataKeys.Add("System.IsBusy");
  867. m_RtDataKeys.Add("Scheduler.CycledCount");
  868. m_RtDataKeys.Add("Scheduler.CycledWafer");
  869. m_RtDataKeys.Add("Scheduler.CycleSetPoint");
  870. m_RtDataKeys.Add("Scheduler.Throughput");
  871. m_RtDataKeys.Add("EquipmentStatus");
  872. m_RtDataKeys.Add("Scheduler.PjNameList");
  873. m_RtDataKeys.Add("Scheduler.CjNameList");
  874. }
  875. private bool HasWaferOnSlot(List<WaferInfo> wafers, int index)
  876. {
  877. if (wafers[index].WaferStatus == 0)
  878. return false;
  879. return true;
  880. }
  881. private async Task ChangePosition(WaferRobotTAction waferRobotTAction, RobotAction robotAction)
  882. {
  883. //CurrentRobotPosition = RobotPosition.Origin;
  884. //await Task.Delay(1000);
  885. if (robotAction == RobotAction.Placing)
  886. {
  887. if (waferRobotTAction == WaferRobotTAction.LP1)
  888. {
  889. CurrentRobotPosition = EFEM.RobotPosition.Left_Place;
  890. }
  891. else if (waferRobotTAction == WaferRobotTAction.LP2)
  892. {
  893. CurrentRobotPosition = EFEM.RobotPosition.Middle_Place;
  894. }
  895. else if (waferRobotTAction == WaferRobotTAction.Aligner1)
  896. {
  897. CurrentRobotPosition = EFEM.RobotPosition.Aligner_Place;
  898. }
  899. else if (waferRobotTAction == WaferRobotTAction.SRD1 || waferRobotTAction == WaferRobotTAction.SRD2)
  900. {
  901. CurrentRobotPosition = EFEM.RobotPosition.SRD_Place;
  902. }
  903. else if (waferRobotTAction == WaferRobotTAction.Dummy1 || waferRobotTAction == WaferRobotTAction.Dummy2)
  904. {
  905. CurrentRobotPosition = EFEM.RobotPosition.Dummy_Place;
  906. }
  907. else if (waferRobotTAction == WaferRobotTAction.VPW1)
  908. {
  909. CurrentRobotPosition = EFEM.RobotPosition.VPW1_Place;
  910. }
  911. else if (waferRobotTAction == WaferRobotTAction.VPW2)
  912. {
  913. CurrentRobotPosition = EFEM.RobotPosition.VPW2_Place;
  914. }
  915. else if (waferRobotTAction == WaferRobotTAction.PlatingCell1)
  916. {
  917. CurrentRobotPosition = EFEM.RobotPosition.PlatingCell1_Place;
  918. }
  919. else if (waferRobotTAction == WaferRobotTAction.PlatingCell2)
  920. {
  921. CurrentRobotPosition = EFEM.RobotPosition.PlatingCell2_Place;
  922. }
  923. else if (waferRobotTAction == WaferRobotTAction.PlatingCell3)
  924. {
  925. CurrentRobotPosition = EFEM.RobotPosition.PlatingCell3_Place;
  926. }
  927. else if (waferRobotTAction == WaferRobotTAction.PlatingCell4)
  928. {
  929. CurrentRobotPosition = EFEM.RobotPosition.PlatingCell4_Place;
  930. }
  931. else
  932. {
  933. CurrentRobotPosition = EFEM.RobotPosition.Origin;
  934. }
  935. }
  936. else
  937. {
  938. if (waferRobotTAction == WaferRobotTAction.LP1)
  939. {
  940. CurrentRobotPosition = EFEM.RobotPosition.Left;
  941. }
  942. else if (waferRobotTAction == WaferRobotTAction.LP2)
  943. {
  944. CurrentRobotPosition = EFEM.RobotPosition.Middle;
  945. }
  946. else if (waferRobotTAction == WaferRobotTAction.Aligner1)
  947. {
  948. CurrentRobotPosition = EFEM.RobotPosition.Aligner;
  949. }
  950. else if (waferRobotTAction == WaferRobotTAction.SRD1 || waferRobotTAction == WaferRobotTAction.SRD2)
  951. {
  952. CurrentRobotPosition = EFEM.RobotPosition.SRD;
  953. }
  954. else if (waferRobotTAction == WaferRobotTAction.Dummy1 || waferRobotTAction == WaferRobotTAction.Dummy2)
  955. {
  956. CurrentRobotPosition = EFEM.RobotPosition.Dummy;
  957. }
  958. else if (waferRobotTAction == WaferRobotTAction.VPW1)
  959. {
  960. CurrentRobotPosition = EFEM.RobotPosition.VPW1;
  961. }
  962. else if (waferRobotTAction == WaferRobotTAction.VPW2)
  963. {
  964. CurrentRobotPosition = EFEM.RobotPosition.VPW2;
  965. }
  966. else if (waferRobotTAction == WaferRobotTAction.PlatingCell1)
  967. {
  968. CurrentRobotPosition = EFEM.RobotPosition.PlatingCell1;
  969. }
  970. else if (waferRobotTAction == WaferRobotTAction.PlatingCell2)
  971. {
  972. CurrentRobotPosition = EFEM.RobotPosition.PlatingCell2;
  973. }
  974. else if (waferRobotTAction == WaferRobotTAction.PlatingCell3)
  975. {
  976. CurrentRobotPosition = EFEM.RobotPosition.PlatingCell3;
  977. }
  978. else if (waferRobotTAction == WaferRobotTAction.PlatingCell4)
  979. {
  980. CurrentRobotPosition = EFEM.RobotPosition.PlatingCell4;
  981. }
  982. else
  983. {
  984. CurrentRobotPosition = EFEM.RobotPosition.Origin;
  985. }
  986. }
  987. await Task.Delay(600);
  988. }
  989. /// <summary>
  990. /// 计算最大值最小值
  991. /// </summary>
  992. /// <param name="Puf1RotationAxis"></param>
  993. /// <returns></returns>
  994. private (double right, double left) CalculatePufMaxMin(BeckhoffStationAxis pufAxis)
  995. {
  996. if (pufAxis == null || pufAxis.Stations.Count == 0) return (-1,-1);
  997. double max = double.Parse(pufAxis.Stations[0].Position);
  998. double min = double.Parse(pufAxis.Stations[0].Position);
  999. double home = 0;
  1000. double pickup = 0;
  1001. foreach (Station item in pufAxis.Stations)
  1002. {
  1003. if (item.Name.ToLower().Contains("home")) home = double.Parse(item.Position);
  1004. if (item.Name.ToLower().Contains("pickup")) pickup = double.Parse(item.Position);
  1005. double position = double.Parse(item.Position);
  1006. if (position > max)
  1007. {
  1008. max = position;
  1009. }
  1010. if (position < min)
  1011. {
  1012. min = position;
  1013. }
  1014. }
  1015. return pickup < home ? (min, max):(max, min);
  1016. }
  1017. /// <summary>
  1018. /// 计算PufFlip差值
  1019. /// </summary>
  1020. /// <param name="pufAxis"></param>
  1021. /// <returns></returns>
  1022. private double CalculatePufFlipDiff(BeckhoffStationAxis pufAxis)
  1023. {
  1024. double sideAangle = 0;
  1025. double sideBangle = 0; ;
  1026. return sideAangle > sideBangle ? 180 : 0;
  1027. }
  1028. /// <summary>
  1029. /// 判定是否在station位置
  1030. /// </summary>
  1031. private bool JudgeAtStation(double targetPosition, double currentPosition, double tolerance)
  1032. {
  1033. if (Math.Abs(currentPosition - targetPosition) <= tolerance)
  1034. {
  1035. return true;
  1036. }
  1037. else
  1038. {
  1039. return false;
  1040. }
  1041. }
  1042. #endregion
  1043. }
  1044. }