RobotCycleViewModel.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. private ModuleName _selectedPufName = ModuleName.PUF1;
  38. /// <summary>
  39. /// 输入的Cycle次数
  40. /// </summary>
  41. private int _inPutCycleTimes = 1;
  42. /// <summary>
  43. /// Align调整角度度数
  44. /// </summary>
  45. private int _inPutAlignDegree = 0;
  46. /// <summary>
  47. /// 当前正在执行第几次Cycle
  48. /// </summary>
  49. private int _currentCycle;
  50. /// <summary>
  51. /// 是否选中dummy
  52. /// </summary>
  53. private bool _isDummySelected = false;
  54. /// <summary>
  55. /// 是否选中srd
  56. /// </summary>
  57. private bool _isSrdSelected = false ;
  58. /// <summary>
  59. /// 是否选中puf
  60. /// </summary>
  61. private bool _isPufSelected = false;
  62. #region 系统数据
  63. /// <summary>
  64. /// 定时器
  65. /// </summary>
  66. DispatcherTimer _timer;
  67. /// <summary>
  68. /// 查询后台数据集合
  69. /// </summary>
  70. private List<string> _rtDataKeys = new List<string>();
  71. /// <summary>
  72. /// rt查询key数值字典
  73. /// </summary>
  74. private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
  75. #endregion
  76. #endregion
  77. #region 属性
  78. public ModuleName SelectedLPName
  79. {
  80. get { return _selectedLPName; }
  81. set { SetProperty(ref _selectedLPName, value); }
  82. }
  83. public ModuleName SelectedAlignerName
  84. {
  85. get { return _selectedAlignerName; }
  86. set { SetProperty(ref _selectedAlignerName, value); }
  87. }
  88. public ModuleName SelectedDummyName
  89. {
  90. get { return _selectedDummyName; }
  91. set { SetProperty(ref _selectedDummyName, value); }
  92. }
  93. public ModuleName SelectedSrdName
  94. {
  95. get { return _selectedSrdName; }
  96. set { SetProperty(ref _selectedSrdName, value); }
  97. }
  98. public ModuleName SelectedPufName
  99. {
  100. get { return _selectedPufName; }
  101. set { SetProperty(ref _selectedPufName, value); }
  102. }
  103. public int InPutCycleTimes
  104. {
  105. get { return _inPutCycleTimes; }
  106. set { SetProperty(ref _inPutCycleTimes, value); }
  107. }
  108. public int CurrentCycle
  109. {
  110. get { return _currentCycle; }
  111. set { SetProperty(ref _currentCycle, value); }
  112. }
  113. public int InPutAlignDegree
  114. {
  115. get { return _inPutAlignDegree; }
  116. set { SetProperty(ref _inPutAlignDegree, value); }
  117. }
  118. public bool IsDummySelected
  119. {
  120. get { return _isDummySelected; }
  121. set { SetProperty(ref _isDummySelected, value); }
  122. }
  123. public bool IsSrdSelected
  124. {
  125. get { return _isSrdSelected; }
  126. set { SetProperty(ref _isSrdSelected, value); }
  127. }
  128. public bool IsPufSelected
  129. {
  130. get { return _isPufSelected; }
  131. set { SetProperty(ref _isPufSelected, value); }
  132. }
  133. #endregion
  134. #region 命令
  135. public ICommand RobotCycleStartCommand { get; set; }
  136. public ICommand RobotCycleAbortCommand { get; set; }
  137. public ICommand LPChangeCommand { get; set; }
  138. public ICommand AlignerChangeCommand { get; set; }
  139. public ICommand PufChangeCommand { get; set; }
  140. public ICommand DummyChangeCommand { get; set; }
  141. public ICommand SrdChangeCommand { get; set; }
  142. #endregion
  143. /// <summary>
  144. /// 构造器
  145. /// </summary>
  146. public RobotCycleViewModel()
  147. {
  148. RobotCycleStartCommand = new DelegateCommand<object>(RobotCycleStartAction);
  149. RobotCycleAbortCommand = new DelegateCommand<object>(RobotCycleAbortAction);
  150. LPChangeCommand = new DelegateCommand<object>(LPChangeAction);
  151. AlignerChangeCommand = new DelegateCommand<object>(AlignerChangeAction);
  152. PufChangeCommand = new DelegateCommand<object>(PufChangeAction);
  153. DummyChangeCommand = new DelegateCommand<object>(DummyChangeAction);
  154. SrdChangeCommand = new DelegateCommand<object>(SrdChangeAction);
  155. }
  156. private void RobotCycleStartAction(object param)
  157. {
  158. if (!IsDummySelected)
  159. {
  160. SelectedDummyName = ModuleName.Unknown;
  161. }
  162. if (!IsSrdSelected)
  163. {
  164. SelectedSrdName = ModuleName.Unknown;
  165. }
  166. if (!IsPufSelected)
  167. {
  168. SelectedPufName = ModuleName.Unknown;
  169. }
  170. if (!IsDummySelected && !IsSrdSelected)
  171. {
  172. MessageBox.Show("Selected at least on module between srd and dummy!");
  173. return;
  174. }
  175. List<string> sequences = new List<string>();
  176. sequences.Add(SelectedLPName.ToString());
  177. sequences.Add(SelectedAlignerName.ToString());
  178. if (SelectedPufName != ModuleName.Unknown)
  179. {
  180. sequences.Add(SelectedPufName.ToString());
  181. }
  182. if (SelectedSrdName != ModuleName.Unknown)
  183. {
  184. sequences.Add(SelectedSrdName.ToString());
  185. }
  186. if (SelectedDummyName != ModuleName.Unknown)
  187. {
  188. sequences.Add(SelectedDummyName.ToString());
  189. }
  190. InvokeClient.Instance.Service.DoOperation($"EFEM.{EfemOperation.RobotCycle}",string.Join("-",sequences), InPutCycleTimes, InPutAlignDegree);
  191. }
  192. private void RobotCycleAbortAction(object param)
  193. {
  194. InvokeClient.Instance.Service.DoOperation($"{ModuleName.EfemRobot}.{EfemOperation.Abort}");
  195. }
  196. private void LPChangeAction(object param)
  197. {
  198. if ("LP1".Equals((string)param))
  199. {
  200. SelectedLPName = ModuleName.LP1;
  201. }
  202. else if ("LP2".Equals((string)param))
  203. {
  204. SelectedLPName = ModuleName.LP2;
  205. }
  206. else
  207. {
  208. SelectedLPName = ModuleName.LP3;
  209. }
  210. }
  211. private void AlignerChangeAction(object param)
  212. {
  213. }
  214. private void PufChangeAction(object param)
  215. {
  216. }
  217. private void DummyChangeAction(object param)
  218. {
  219. if ("Dummy1".Equals((string)param))
  220. {
  221. SelectedDummyName = ModuleName.Dummy1;
  222. }
  223. else
  224. {
  225. SelectedDummyName = ModuleName.Dummy2;
  226. }
  227. }
  228. private void SrdChangeAction(object param)
  229. {
  230. if ("SRD1".Equals((string)param))
  231. {
  232. SelectedSrdName = ModuleName.SRD1;
  233. }
  234. else
  235. {
  236. SelectedSrdName = ModuleName.SRD2;
  237. }
  238. }
  239. /// <summary>
  240. /// 加载数据
  241. /// </summary>
  242. public void LoadData(string systemName)
  243. {
  244. _rtDataKeys.Clear();
  245. _rtDataKeys.Add("EFEM.CurrentRobotCycleTime");
  246. if (_timer == null)
  247. {
  248. _timer = new DispatcherTimer();
  249. _timer.Interval = TimeSpan.FromMilliseconds(200);
  250. _timer.Tick += Timer_Tick;
  251. }
  252. _timer.Start();
  253. }
  254. /// <summary>
  255. /// 定时器执行
  256. /// </summary>
  257. /// <param name="sender"></param>
  258. /// <param name="e"></param>
  259. private void Timer_Tick(object sender, EventArgs e)
  260. {
  261. if (_rtDataKeys.Count != 0)
  262. {
  263. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  264. if (_rtDataValueDic != null)
  265. {
  266. CurrentCycle = CommonFunction.GetValue<int>(_rtDataValueDic, $"EFEM.CurrentRobotCycleTime");
  267. }
  268. }
  269. }
  270. /// <summary>
  271. /// 隐藏
  272. /// </summary>
  273. public void Hide()
  274. {
  275. }
  276. }
  277. }