OperationViewModel.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. using Aitex.Core.Common;
  2. using Aitex.Core.Common.DeviceData;
  3. using Aitex.Core.UI.Dialog;
  4. using Aitex.Core.UI.MVVM;
  5. using Aitex.Core.Util;
  6. using Aitex.Core.Utilities;
  7. using Aitex.Sorter.Common;
  8. using MECF.Framework.Common.OperationCenter;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Windows;
  12. using System.Windows.Input;
  13. using Aitex.Core.RT.SCCore;
  14. using MECF.Framework.Common.DataCenter;
  15. using MECF.Framework.Common.Equipment;
  16. using MECF.Framework.Common.RecipeCenter;
  17. namespace Aitex.Sorter.UI.ViewModel
  18. {
  19. class OperationViewModel : UIViewModelBase
  20. {
  21. private WaferInfo[] foupAWaferInfo;
  22. private WaferInfo[] foupBWaferInfo;
  23. #region command
  24. public ICommand OperationCommand
  25. {
  26. get;
  27. private set;
  28. }
  29. public ICommand RecipeSelectCommand
  30. {
  31. get;
  32. private set;
  33. }
  34. public ICommand RecipeStartCommand
  35. {
  36. get;
  37. private set;
  38. }
  39. public ICommand RecipePauseCommand
  40. {
  41. get;
  42. private set;
  43. }
  44. public ICommand RecipeResumeCommand
  45. {
  46. get;
  47. private set;
  48. }
  49. public ICommand RecipeStopCommand
  50. {
  51. get;
  52. private set;
  53. }
  54. #endregion
  55. #region Subscription
  56. [Subscription(ParamName.TranserThroughput, SystemStateModule)]
  57. public int TranserThroughput
  58. {
  59. get;
  60. set;
  61. }
  62. [Subscription(ParamName.TransferCount, SystemStateModule)]
  63. public int TransferCount
  64. {
  65. get;
  66. set;
  67. }
  68. [Subscription(ParamName.CycleCount, SystemStateModule)]
  69. public int CycleCount
  70. {
  71. get;
  72. set;
  73. }
  74. [Subscription(ParamName.TransferTime, SystemStateModule)]
  75. public int TransferTime
  76. {
  77. get;
  78. set;
  79. }
  80. [Subscription(ParamName.TotalWaferCount, SystemStateModule)]
  81. public int TotalWaferCount
  82. {
  83. get;
  84. set;
  85. }
  86. [Subscription(ParamName.RTStatus, SystemStateModule)]
  87. public int RoutManagerState
  88. {
  89. get;
  90. set;
  91. }
  92. [Subscription(ParamName.WaferInfoFoupA, "System")]
  93. public WaferInfo[] FoupAWaferInfo
  94. {
  95. get
  96. {
  97. return foupAWaferInfo;
  98. }
  99. set
  100. {
  101. foupAWaferInfo = value.Reverse().ToArray();
  102. }
  103. }
  104. [Subscription(ParamName.WaferInfoFoupB, "System")]
  105. public WaferInfo[] FoupBWaferInfo
  106. {
  107. get
  108. {
  109. return foupBWaferInfo;
  110. }
  111. set
  112. {
  113. foupBWaferInfo = value.Reverse().ToArray();
  114. }
  115. }
  116. [Subscription(ParamName.WaferInfoRobotSlot01, "System")]
  117. public WaferInfo RobotWaferInfo1
  118. {
  119. get;
  120. set;
  121. }
  122. [Subscription(ParamName.WaferInfoRobotSlot02, "System")]
  123. public WaferInfo RobotWaferInfo2
  124. {
  125. get;
  126. set;
  127. }
  128. [Subscription(ParamName.WaferInfoRobotAligner01, "System")]
  129. public WaferInfo AlignerWaferInfo
  130. {
  131. get;
  132. set;
  133. }
  134. [Subscription(ParamName.LoadportState, DeviceName.LoadportA)]
  135. public string LoadportAState
  136. {
  137. get;
  138. set;
  139. }
  140. [Subscription(ParamName.LoadportState, DeviceName.LoadportB)]
  141. public string LoadportBState
  142. {
  143. get;
  144. set;
  145. }
  146. [Subscription(ParamName.AlignerState, DeviceName.Aligner)]
  147. public string AlignerState
  148. {
  149. get;
  150. set;
  151. }
  152. [Subscription(ParamName.RobotState, DeviceName.Robot)]
  153. public string RobotState
  154. {
  155. get;
  156. set;
  157. }
  158. [Subscription(ParamName.FoupID, DeviceName.RFIDReaderA)]
  159. public string FoupAID
  160. {
  161. get;
  162. set;
  163. }
  164. [Subscription(ParamName.FoupID, DeviceName.RFIDReaderB)]
  165. public string FoupBID
  166. {
  167. get;
  168. set;
  169. }
  170. [Subscription(ParamName.RobotSpeed, DeviceName.Robot)]
  171. public string RobotSpeed
  172. {
  173. get;
  174. set;
  175. }
  176. [Subscription(ParamName.CassetteState, DeviceName.LoadportA)]
  177. public LoadportCassetteState LPACassetteState
  178. {
  179. get;
  180. set;
  181. }
  182. [Subscription(ParamName.CassetteState, DeviceName.LoadportB)]
  183. public LoadportCassetteState LPBCassetteState
  184. {
  185. get;
  186. set;
  187. }
  188. [Subscription(DeviceName.SensorPreAlignerWaferOn, SystemDeviceModule)]
  189. public AITSensorData SensorPreAlignerWaferOn
  190. {
  191. get;
  192. set;
  193. }
  194. [Subscription(DeviceName.SensorRobotFork2WaferOn, SystemDeviceModule)]
  195. public AITSensorData SensorRobotFork2WaferOn
  196. {
  197. get;
  198. set;
  199. }
  200. [Subscription(DeviceName.SensorRobotFork1WaferOn, SystemDeviceModule)]
  201. public AITSensorData SensorRobotFork1WaferOn
  202. {
  203. get;
  204. set;
  205. }
  206. private bool isVacuumSensorON;
  207. [Subscription("IsVacuumSensorON", DeviceName.Robot)]
  208. public bool IsVacuumSensorON
  209. {
  210. get { return isVacuumSensorON; }
  211. set
  212. {
  213. isVacuumSensorON = value;
  214. isVacuumSensorONAITSensor.Value = value;
  215. IsVacuumSensorONAITSensor = isVacuumSensorONAITSensor;
  216. }
  217. }
  218. private AITSensorData isVacuumSensorONAITSensor = new AITSensorData();
  219. public AITSensorData IsVacuumSensorONAITSensor
  220. {
  221. get { return isVacuumSensorONAITSensor; }
  222. set {
  223. isVacuumSensorONAITSensor = value;
  224. InvokePropertyChanged("IsVacuumSensorONAITSensor");
  225. }
  226. }
  227. public ICommand LoadPortACommand
  228. {
  229. get; set;
  230. }
  231. public ICommand LoadPortBCommand
  232. {
  233. get; set;
  234. }
  235. [Subscription(ParamName.IsAutoMode, SystemStateModule)]
  236. public bool IsAutoMode { get; set; }
  237. [Subscription(ParamName.LocalControlJob, SystemStateModule)]
  238. public SorterRecipeXml LocalControlJob { get; set; }
  239. [Subscription(ParamName.FoupDoorState, DeviceName.LoadportA)]
  240. public FoupDoorState LPADoorState
  241. {
  242. get;
  243. set;
  244. }
  245. [Subscription(ParamName.FoupDoorState, DeviceName.LoadportB)]
  246. public FoupDoorState LPBDoorState
  247. {
  248. get;
  249. set;
  250. }
  251. [Subscription(ParamName.FoupClampState, DeviceName.LoadportA)]
  252. public FoupClampState FoupAClampState
  253. {
  254. get;
  255. set;
  256. }
  257. [Subscription(ParamName.FoupClampState, DeviceName.LoadportB)]
  258. public FoupClampState FoupBClampState
  259. {
  260. get;
  261. set;
  262. }
  263. #endregion
  264. #region Logic
  265. public Visibility CycleVisibility { get; set; }
  266. public bool IsHomeAllButtonEnabled
  267. {
  268. get
  269. {
  270. return !IsAutoMode;
  271. }
  272. }
  273. public bool IsAbortHomeAllButtonEnabled
  274. {
  275. get
  276. {
  277. return !IsAutoMode && RoutManagerState != (int)RtState.Idle && RoutManagerState != (int)RtState.Init;
  278. }
  279. }
  280. public bool IsStartCycleButtonEnabled
  281. {
  282. get
  283. {
  284. return IsAutoMode;
  285. }
  286. }
  287. public bool IsReturnWaferButtonEnabled
  288. {
  289. get
  290. {
  291. return !IsAutoMode;
  292. }
  293. }
  294. public bool IsStopCycleButtonEnabled
  295. {
  296. get
  297. {
  298. return IsAutoMode;
  299. }
  300. }
  301. public bool IsManualMode
  302. {
  303. get
  304. {
  305. return !IsAutoMode;
  306. }
  307. }
  308. [IgnorePropertyChange]
  309. public string SelectedRecipeName
  310. {
  311. get;
  312. set;
  313. }
  314. public bool IsProcessing
  315. {
  316. get
  317. {
  318. return (RtState)RoutManagerState == RtState.PauseProcess || (RtState)RoutManagerState == RtState.Processing;
  319. }
  320. }
  321. public string RtStatus
  322. {
  323. get { return ((RtState)RoutManagerState).ToString(); }
  324. }
  325. public bool IsManualButtonEnabled
  326. {
  327. get
  328. {
  329. return IsAutoMode;
  330. }
  331. }
  332. public bool IsAutoButtonEnabled
  333. {
  334. get
  335. {
  336. return !IsAutoMode;
  337. }
  338. }
  339. public bool IsEnableSelectRecipe
  340. {
  341. get
  342. {
  343. return IsAutoMode && !IsProcessing;
  344. }
  345. }
  346. public bool IsEnableStartRecipe
  347. {
  348. get
  349. {
  350. return IsAutoMode && !string.IsNullOrEmpty(SelectedRecipeName) && !IsProcessing;
  351. }
  352. }
  353. public bool IsEnablePauseRecipe
  354. {
  355. get
  356. {
  357. return IsAutoMode && IsProcessing;
  358. }
  359. }
  360. public bool IsEnableResumeRecipe
  361. {
  362. get
  363. {
  364. return IsAutoMode && IsProcessing;
  365. }
  366. }
  367. public bool IsEnableStopRecipe
  368. {
  369. get
  370. {
  371. return IsAutoMode && IsProcessing;
  372. }
  373. }
  374. public bool IsMaintenanceMode
  375. {
  376. get => RoutManagerState == (int)RtState.Maintenance;
  377. }
  378. #endregion
  379. public OperationViewModel() : base("OperationViewModal")
  380. {
  381. OperationCommand = new DelegateCommand<string>(Operation, x =>
  382. {
  383. if (IsMaintenanceMode)
  384. {
  385. return false;
  386. }
  387. switch (x)
  388. {
  389. case "HomeAll":
  390. return IsHomeAllButtonEnabled;
  391. case "AbortHomeAll":
  392. return IsAbortHomeAllButtonEnabled;
  393. case "ReturnWafer":
  394. return IsReturnWaferButtonEnabled;
  395. case "Cycle":
  396. return IsStartCycleButtonEnabled;
  397. case "Stop":
  398. return IsStopCycleButtonEnabled;
  399. default:
  400. break;
  401. }
  402. return true;
  403. });
  404. LoadPortACommand = new DelegateCommand<string>(DoLoadPortACmd, x =>
  405. {
  406. if (IsMaintenanceMode)
  407. {
  408. return false;
  409. }
  410. bool result = (LoadportAState == DeviceState.Idle.ToString());
  411. if (result)
  412. {
  413. switch (x)
  414. {
  415. case OperationName.ReadFoupID:
  416. result = (LPACassetteState == LoadportCassetteState.Normal && FoupAClampState != FoupClampState.Close);
  417. break;
  418. case OperationName.LoadFoup:
  419. result = (FoupAClampState == FoupClampState.Close && LPADoorState != FoupDoorState.Open);
  420. break;
  421. case OperationName.UnloadFoup:
  422. result = (LPACassetteState == LoadportCassetteState.Normal && FoupAClampState == FoupClampState.Close);
  423. break;
  424. default:
  425. result = false;
  426. break;
  427. }
  428. }
  429. return result;
  430. });
  431. LoadPortBCommand = new DelegateCommand<string>(DoLoadPortBCmd, x =>
  432. {
  433. if (IsMaintenanceMode)
  434. {
  435. return false;
  436. }
  437. bool result = (LoadportBState == DeviceState.Idle.ToString());
  438. if (result)
  439. {
  440. switch (x)
  441. {
  442. case OperationName.ReadFoupID:
  443. result = (LPBCassetteState == LoadportCassetteState.Normal && FoupBClampState == FoupClampState.Open);
  444. break;
  445. case OperationName.LoadFoup:
  446. result = (FoupBClampState == FoupClampState.Close && LPBDoorState == FoupDoorState.Close);
  447. break;
  448. case OperationName.UnloadFoup:
  449. result = (LPBCassetteState == LoadportCassetteState.Normal && FoupBClampState == FoupClampState.Close);
  450. break;
  451. default:
  452. result = false;
  453. break;
  454. }
  455. }
  456. return result;
  457. });
  458. RecipeSelectCommand = new DelegateCommand<object>(SelectRecipe, x => !IsMaintenanceMode && IsEnableSelectRecipe);
  459. RecipeStartCommand = new DelegateCommand<object>(StartRecipe, x => !IsMaintenanceMode && IsEnableStartRecipe);
  460. RecipePauseCommand = new DelegateCommand<object>(PauseRecipe, x => !IsMaintenanceMode && IsEnablePauseRecipe);
  461. RecipeResumeCommand = new DelegateCommand<object>(ResumeRecipe, x => !IsMaintenanceMode && IsEnableResumeRecipe);
  462. RecipeStopCommand = new DelegateCommand<object>(StopRecipe, x => !IsMaintenanceMode && IsEnableStopRecipe);
  463. }
  464. private void DoLoadPortACmd(string cmd)
  465. {
  466. var deviceName = ModuleName.LP1;
  467. var param = new object[] { deviceName };
  468. DeviceOperation(cmd, param);
  469. }
  470. private void DoLoadPortBCmd(string cmd)
  471. {
  472. var deviceName = ModuleName.LP2;
  473. var param = new object[] { deviceName };
  474. DeviceOperation(cmd, param);
  475. }
  476. private void DeviceOperation(string cmd, object[] param)
  477. {
  478. InvokeClient.Instance.Service.DoOperation(cmd, param);
  479. }
  480. void Operation(string param)
  481. {
  482. InvokeClient.Instance.Service.DoOperation(param);
  483. }
  484. protected override void InvokeBeforeUpdateProperty(Dictionary<string, object> data)
  485. {
  486. CycleVisibility = ((bool)QueryDataClient.Instance.Service.GetConfig(SorterCommon.ScPathName.Process_CycleEnable)) ? Visibility.Visible : Visibility.Hidden;
  487. //data[UIKey(UnitName.LoadportA.ToString(), ParamName.FoupDoorState)] = FoupDoorState.Close;
  488. }
  489. #region recipe
  490. private void SelectRecipe(object param)
  491. {
  492. RecipeSelectDialog dialog = new RecipeSelectDialog(RecipeClient.Instance.Service.GetXmlRecipeList(ModuleName.System, false))
  493. {
  494. Owner = Application.Current.MainWindow
  495. };
  496. var ret = dialog.ShowDialog();
  497. if (ret.HasValue && ret.Value)
  498. {
  499. SelectedRecipeName = dialog.SelectedRecipe;
  500. InvokePropertyChanged("SelectedRecipeName");
  501. InvokeClient.Instance.Service.DoOperation(OperationName.SelectRecipe, SelectedRecipeName);
  502. }
  503. }
  504. private void StartRecipe(object param)
  505. {
  506. if (string.IsNullOrEmpty(SelectedRecipeName))
  507. {
  508. return;
  509. }
  510. InvokeClient.Instance.Service.DoOperation(OperationName.StartRecipe, SelectedRecipeName);
  511. }
  512. private void PauseRecipe(object param)
  513. {
  514. if (MessageBox.Show("Are you sure you want to pause the process?", "Sorter", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
  515. {
  516. InvokeClient.Instance.Service.DoOperation(OperationName.PauseRecipe);
  517. }
  518. }
  519. private void ResumeRecipe(object param)
  520. {
  521. if (MessageBox.Show("Are you sure you want to resume the process?", "Sorter", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
  522. {
  523. InvokeClient.Instance.Service.DoOperation(OperationName.ResumeRecipe);
  524. }
  525. }
  526. private void StopRecipe(object param)
  527. {
  528. if (MessageBox.Show("Are you sure you want to abort the process?", "Sorter", MessageBoxButton.YesNo) ==
  529. MessageBoxResult.Yes)
  530. {
  531. InvokeClient.Instance.Service.DoOperation(OperationName.StopRecipe);
  532. }
  533. }
  534. #endregion
  535. }
  536. }