RobotCycleViewModel.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. using Aitex.Core.UI.MVVM;
  2. using CyberX8_Core;
  3. using CyberX8_MainPages.Roles;
  4. using CyberX8_MainPages.Views;
  5. using MECF.Framework.Common.ControlDataContext;
  6. using MECF.Framework.Common.DataCenter;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.OperationCenter;
  9. using MECF.Framework.Common.Utilities;
  10. using OpenSEMI.ClientBase.Command;
  11. using Prism.Mvvm;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Collections.ObjectModel;
  15. using System.Linq;
  16. using System.Reflection;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. using System.Windows.Forms;
  20. using System.Windows.Input;
  21. using System.Windows.Threading;
  22. namespace CyberX8_MainPages.ViewModels
  23. {
  24. public class RobotCycleViewModel : BindableBase
  25. {
  26. #region 内部变量
  27. /// <summary>
  28. /// 选择的LP
  29. /// </summary>
  30. private ModuleName _selectedLPName = ModuleName.LP1;
  31. private ModuleName _selectedAlignerName = ModuleName.Aligner1;
  32. /// <summary>
  33. /// 选择的Dummy
  34. /// </summary>
  35. private ModuleName _selectedDummyName = ModuleName.Dummy1;
  36. private ModuleName _selectedSrdName = ModuleName.SRD1;
  37. /// <summary>
  38. /// 输入的Cycle次数
  39. /// </summary>
  40. private int _inPutCycleTimes = 1;
  41. /// <summary>
  42. /// Align调整角度度数
  43. /// </summary>
  44. private int _inPutAlignDegree = 0;
  45. /// <summary>
  46. /// 当前正在执行第几次Cycle
  47. /// </summary>
  48. private int _currentCycle;
  49. /// <summary>
  50. /// 是否选中dummy
  51. /// </summary>
  52. private bool _isDummySelected = false;
  53. /// <summary>
  54. /// 是否选中srd
  55. /// </summary>
  56. private bool _isSrdSelected = false ;
  57. #region 系统数据
  58. /// <summary>
  59. /// 定时器
  60. /// </summary>
  61. DispatcherTimer _timer;
  62. /// <summary>
  63. /// 查询后台数据集合
  64. /// </summary>
  65. private List<string> _rtDataKeys = new List<string>();
  66. /// <summary>
  67. /// rt查询key数值字典
  68. /// </summary>
  69. private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
  70. #endregion
  71. #endregion
  72. #region 属性
  73. public ModuleName SelectedLPName
  74. {
  75. get { return _selectedLPName; }
  76. set { SetProperty(ref _selectedLPName, value); }
  77. }
  78. public ModuleName SelectedAlignerName
  79. {
  80. get { return _selectedAlignerName; }
  81. set { SetProperty(ref _selectedAlignerName, value); }
  82. }
  83. public ModuleName SelectedDummyName
  84. {
  85. get { return _selectedDummyName; }
  86. set { SetProperty(ref _selectedDummyName, value); }
  87. }
  88. public ModuleName SelectedSrdName
  89. {
  90. get { return _selectedSrdName; }
  91. set { SetProperty(ref _selectedSrdName, value); }
  92. }
  93. public int InPutCycleTimes
  94. {
  95. get { return _inPutCycleTimes; }
  96. set { SetProperty(ref _inPutCycleTimes, value); }
  97. }
  98. public int CurrentCycle
  99. {
  100. get { return _currentCycle; }
  101. set { SetProperty(ref _currentCycle, value); }
  102. }
  103. public int InPutAlignDegree
  104. {
  105. get { return _inPutAlignDegree; }
  106. set { SetProperty(ref _inPutAlignDegree, value); }
  107. }
  108. public bool IsDummySelected
  109. {
  110. get { return _isDummySelected; }
  111. set { SetProperty(ref _isDummySelected, value); }
  112. }
  113. public bool IsSrdSelected
  114. {
  115. get { return _isSrdSelected; }
  116. set { SetProperty(ref _isSrdSelected, value); }
  117. }
  118. #endregion
  119. #region 命令
  120. public ICommand RobotCycleStartCommand { get; set; }
  121. public ICommand RobotCycleAbortCommand { get; set; }
  122. public ICommand LPChangeCommand { get; set; }
  123. public ICommand AlignerChangeCommand { get; set; }
  124. public ICommand DummyChangeCommand { get; set; }
  125. public ICommand SrdChangeCommand { get; set; }
  126. #endregion
  127. /// <summary>
  128. /// 构造器
  129. /// </summary>
  130. public RobotCycleViewModel()
  131. {
  132. RobotCycleStartCommand = new DelegateCommand<object>(RobotCycleStartAction);
  133. RobotCycleAbortCommand = new DelegateCommand<object>(RobotCycleAbortAction);
  134. LPChangeCommand = new DelegateCommand<object>(LPChangeAction);
  135. AlignerChangeCommand = new DelegateCommand<object>(AlignerChangeAction);
  136. DummyChangeCommand = new DelegateCommand<object>(DummyChangeAction);
  137. SrdChangeCommand = new DelegateCommand<object>(SrdChangeAction);
  138. }
  139. private void RobotCycleStartAction(object param)
  140. {
  141. if (!IsDummySelected)
  142. {
  143. SelectedDummyName = ModuleName.Unknown;
  144. }
  145. if (!IsSrdSelected)
  146. {
  147. SelectedSrdName = ModuleName.Unknown;
  148. }
  149. if(!IsDummySelected && !IsSrdSelected)
  150. {
  151. MessageBox.Show("Selected at least on module between srd and dummy!");
  152. return;
  153. }
  154. InvokeClient.Instance.Service.DoOperation($"EFEM.{EfemOperation.RobotCycle}",SelectedLPName, SelectedAlignerName,SelectedDummyName, SelectedSrdName, InPutCycleTimes, InPutAlignDegree);
  155. }
  156. private void RobotCycleAbortAction(object param)
  157. {
  158. InvokeClient.Instance.Service.DoOperation($"{ModuleName.EfemRobot}.{EfemOperation.Abort}");
  159. }
  160. private void LPChangeAction(object param)
  161. {
  162. if ("LP1".Equals((string)param))
  163. {
  164. SelectedLPName = ModuleName.LP1;
  165. }
  166. else if ("LP2".Equals((string)param))
  167. {
  168. SelectedLPName = ModuleName.LP2;
  169. }
  170. else
  171. {
  172. SelectedLPName = ModuleName.LP3;
  173. }
  174. }
  175. private void AlignerChangeAction(object param)
  176. {
  177. }
  178. private void DummyChangeAction(object param)
  179. {
  180. if ("Dummy1".Equals((string)param))
  181. {
  182. SelectedDummyName = ModuleName.Dummy1;
  183. }
  184. else
  185. {
  186. SelectedDummyName = ModuleName.Dummy2;
  187. }
  188. }
  189. private void SrdChangeAction(object param)
  190. {
  191. if ("SRD1".Equals((string)param))
  192. {
  193. SelectedSrdName = ModuleName.SRD1;
  194. }
  195. else
  196. {
  197. SelectedSrdName = ModuleName.SRD2;
  198. }
  199. }
  200. /// <summary>
  201. /// 加载数据
  202. /// </summary>
  203. public void LoadData(string systemName)
  204. {
  205. _rtDataKeys.Clear();
  206. _rtDataKeys.Add($"EFEM.CurrentRobotCycleTime");
  207. if (_timer == null)
  208. {
  209. _timer = new DispatcherTimer();
  210. _timer.Interval = TimeSpan.FromMilliseconds(200);
  211. _timer.Tick += Timer_Tick;
  212. }
  213. _timer.Start();
  214. }
  215. /// <summary>
  216. /// 定时器执行
  217. /// </summary>
  218. /// <param name="sender"></param>
  219. /// <param name="e"></param>
  220. private void Timer_Tick(object sender, EventArgs e)
  221. {
  222. if (_rtDataKeys.Count != 0)
  223. {
  224. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  225. if (_rtDataValueDic != null)
  226. {
  227. CurrentCycle = CommonFunction.GetValue<int>(_rtDataValueDic, $"EFEM.CurrentRobotCycleTime");
  228. }
  229. }
  230. }
  231. /// <summary>
  232. /// 隐藏
  233. /// </summary>
  234. public void Hide()
  235. {
  236. }
  237. }
  238. }