RobotCycleViewModel.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. List<string> sequences = new List<string>();
  155. sequences.Add(SelectedLPName.ToString());
  156. sequences.Add(SelectedAlignerName.ToString());
  157. if (SelectedSrdName != ModuleName.Unknown)
  158. {
  159. sequences.Add(SelectedSrdName.ToString());
  160. }
  161. if (SelectedDummyName != ModuleName.Unknown)
  162. {
  163. sequences.Add(SelectedDummyName.ToString());
  164. }
  165. InvokeClient.Instance.Service.DoOperation($"EFEM.{EfemOperation.RobotCycle}",string.Join("-",sequences), InPutCycleTimes, InPutAlignDegree);
  166. }
  167. private void RobotCycleAbortAction(object param)
  168. {
  169. InvokeClient.Instance.Service.DoOperation($"{ModuleName.EfemRobot}.{EfemOperation.Abort}");
  170. }
  171. private void LPChangeAction(object param)
  172. {
  173. if ("LP1".Equals((string)param))
  174. {
  175. SelectedLPName = ModuleName.LP1;
  176. }
  177. else if ("LP2".Equals((string)param))
  178. {
  179. SelectedLPName = ModuleName.LP2;
  180. }
  181. else
  182. {
  183. SelectedLPName = ModuleName.LP3;
  184. }
  185. }
  186. private void AlignerChangeAction(object param)
  187. {
  188. }
  189. private void DummyChangeAction(object param)
  190. {
  191. if ("Dummy1".Equals((string)param))
  192. {
  193. SelectedDummyName = ModuleName.Dummy1;
  194. }
  195. else
  196. {
  197. SelectedDummyName = ModuleName.Dummy2;
  198. }
  199. }
  200. private void SrdChangeAction(object param)
  201. {
  202. if ("SRD1".Equals((string)param))
  203. {
  204. SelectedSrdName = ModuleName.SRD1;
  205. }
  206. else
  207. {
  208. SelectedSrdName = ModuleName.SRD2;
  209. }
  210. }
  211. /// <summary>
  212. /// 加载数据
  213. /// </summary>
  214. public void LoadData(string systemName)
  215. {
  216. _rtDataKeys.Clear();
  217. _rtDataKeys.Add("EFEM.CurrentRobotCycleTime");
  218. if (_timer == null)
  219. {
  220. _timer = new DispatcherTimer();
  221. _timer.Interval = TimeSpan.FromMilliseconds(200);
  222. _timer.Tick += Timer_Tick;
  223. }
  224. _timer.Start();
  225. }
  226. /// <summary>
  227. /// 定时器执行
  228. /// </summary>
  229. /// <param name="sender"></param>
  230. /// <param name="e"></param>
  231. private void Timer_Tick(object sender, EventArgs e)
  232. {
  233. if (_rtDataKeys.Count != 0)
  234. {
  235. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  236. if (_rtDataValueDic != null)
  237. {
  238. CurrentCycle = CommonFunction.GetValue<int>(_rtDataValueDic, $"EFEM.CurrentRobotCycleTime");
  239. }
  240. }
  241. }
  242. /// <summary>
  243. /// 隐藏
  244. /// </summary>
  245. public void Hide()
  246. {
  247. }
  248. }
  249. }