RobotCycleViewModel.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. using Aitex.Core.UI.MVVM;
  2. using PunkHPX8_Core;
  3. using PunkHPX8_MainPages.Roles;
  4. using PunkHPX8_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. using MECF.Framework.Common.CommonData;
  23. using Newtonsoft.Json;
  24. namespace PunkHPX8_MainPages.ViewModels
  25. {
  26. public class RobotCycleViewModel : BindableBase
  27. {
  28. #region 内部变量
  29. /// <summary>
  30. /// 选择的LP
  31. /// </summary>
  32. private ModuleName _selectedLPName = ModuleName.LP1;
  33. private ModuleName _selectedAlignerName = ModuleName.Aligner1;
  34. /// <summary>
  35. /// 选择的Dummy
  36. /// </summary>
  37. private ModuleName _selectedDummyName = ModuleName.Dummy1;
  38. private ModuleName _selectedSrdName = ModuleName.SRD1;
  39. private ModuleName _selectedPufName = ModuleName.PUF1;
  40. /// <summary>
  41. /// 输入的Cycle次数
  42. /// </summary>
  43. private int _inPutCycleTimes = 1;
  44. /// <summary>
  45. /// Align调整角度度数
  46. /// </summary>
  47. private int _inPutAlignDegree = 0;
  48. /// <summary>
  49. /// 当前正在执行第几次Cycle
  50. /// </summary>
  51. private int _currentCycle;
  52. /// <summary>
  53. /// 是否选中dummy
  54. /// </summary>
  55. private bool _isDummySelected = false;
  56. /// <summary>
  57. /// 是否选中srd
  58. /// </summary>
  59. private bool _isSrdSelected = false ;
  60. /// <summary>
  61. /// 是否选中puf
  62. /// </summary>
  63. private bool _isPufSelected = false;
  64. private bool _isSrd1Checked = true;
  65. private bool _isSrd2Checked = false;
  66. private bool _isDummy1Checked = true;
  67. private bool _isDummy2Checked = false;
  68. #region 系统数据
  69. /// <summary>
  70. /// 定时器
  71. /// </summary>
  72. DispatcherTimer _timer;
  73. /// <summary>
  74. /// 查询后台数据集合
  75. /// </summary>
  76. private List<string> _rtDataKeys = new List<string>();
  77. /// <summary>
  78. /// rt查询key数值字典
  79. /// </summary>
  80. private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
  81. #endregion
  82. #endregion
  83. #region 属性
  84. public ModuleName SelectedLPName
  85. {
  86. get { return _selectedLPName; }
  87. set { SetProperty(ref _selectedLPName, value); }
  88. }
  89. public ModuleName SelectedAlignerName
  90. {
  91. get { return _selectedAlignerName; }
  92. set { SetProperty(ref _selectedAlignerName, value); }
  93. }
  94. public ModuleName SelectedDummyName
  95. {
  96. get { return _selectedDummyName; }
  97. set { SetProperty(ref _selectedDummyName, value); }
  98. }
  99. public ModuleName SelectedSrdName
  100. {
  101. get { return _selectedSrdName; }
  102. set { SetProperty(ref _selectedSrdName, value); }
  103. }
  104. public ModuleName SelectedPufName
  105. {
  106. get { return _selectedPufName; }
  107. set { SetProperty(ref _selectedPufName, value); }
  108. }
  109. public int InPutCycleTimes
  110. {
  111. get { return _inPutCycleTimes; }
  112. set { SetProperty(ref _inPutCycleTimes, value); }
  113. }
  114. public int CurrentCycle
  115. {
  116. get { return _currentCycle; }
  117. set { SetProperty(ref _currentCycle, value); }
  118. }
  119. public int InPutAlignDegree
  120. {
  121. get { return _inPutAlignDegree; }
  122. set { SetProperty(ref _inPutAlignDegree, value); }
  123. }
  124. public bool IsDummySelected
  125. {
  126. get { return _isDummySelected; }
  127. set { SetProperty(ref _isDummySelected, value); }
  128. }
  129. public bool IsSrdSelected
  130. {
  131. get { return _isSrdSelected; }
  132. set { SetProperty(ref _isSrdSelected, value); }
  133. }
  134. public bool IsPufSelected
  135. {
  136. get { return _isPufSelected; }
  137. set { SetProperty(ref _isPufSelected, value); }
  138. }
  139. public bool IsSrd1Checkd
  140. {
  141. get { return _isSrd1Checked; }
  142. set { SetProperty(ref _isSrd1Checked, value); }
  143. }
  144. public bool IsSrd2Checkd
  145. {
  146. get { return _isSrd2Checked; }
  147. set { SetProperty(ref _isSrd2Checked, value); }
  148. }
  149. public bool IsDummy1Checkd
  150. {
  151. get { return _isDummy1Checked; }
  152. set { SetProperty(ref _isDummy1Checked, value); }
  153. }
  154. public bool IsDummy2Checkd
  155. {
  156. get { return _isDummy2Checked; }
  157. set { SetProperty(ref _isDummy2Checked, value); }
  158. }
  159. #endregion
  160. #region 命令
  161. public ICommand RobotCycleStartCommand { get; set; }
  162. public ICommand RobotCycleAbortCommand { get; set; }
  163. public ICommand LPChangeCommand { get; set; }
  164. public ICommand AlignerChangeCommand { get; set; }
  165. public ICommand PufChangeCommand { get; set; }
  166. public ICommand DummyChangeCommand { get; set; }
  167. public ICommand SrdChangeCommand { get; set; }
  168. #endregion
  169. /// <summary>
  170. /// 构造器
  171. /// </summary>
  172. public RobotCycleViewModel()
  173. {
  174. RobotCycleStartCommand = new DelegateCommand<object>(RobotCycleStartAction);
  175. RobotCycleAbortCommand = new DelegateCommand<object>(RobotCycleAbortAction);
  176. LPChangeCommand = new DelegateCommand<object>(LPChangeAction);
  177. AlignerChangeCommand = new DelegateCommand<object>(AlignerChangeAction);
  178. //PufChangeCommand = new DelegateCommand<object>(PufChangeAction);
  179. //DummyChangeCommand = new DelegateCommand<object>(DummyChangeAction);
  180. //SrdChangeCommand = new DelegateCommand<object>(SrdChangeAction);
  181. }
  182. private void RobotCycleStartAction(object param)
  183. {
  184. if (!IsDummySelected)
  185. {
  186. SelectedDummyName = ModuleName.Unknown;
  187. }
  188. else
  189. {
  190. if (IsDummy1Checkd)
  191. {
  192. SelectedDummyName = ModuleName.Dummy1;
  193. }
  194. else
  195. {
  196. SelectedDummyName = ModuleName.Dummy2;
  197. }
  198. }
  199. if (!IsSrdSelected)
  200. {
  201. SelectedSrdName = ModuleName.Unknown;
  202. }
  203. else
  204. {
  205. if (IsSrd1Checkd)
  206. {
  207. SelectedSrdName = ModuleName.SRD1;
  208. }
  209. else
  210. {
  211. SelectedSrdName = ModuleName.SRD2;
  212. }
  213. }
  214. if (!IsPufSelected)
  215. {
  216. SelectedPufName = ModuleName.Unknown;
  217. }
  218. else
  219. {
  220. SelectedPufName = ModuleName.PUF1;
  221. }
  222. if (!IsDummySelected && !IsSrdSelected)
  223. {
  224. MessageBox.Show("Selected at least on module between srd and dummy!");
  225. return;
  226. }
  227. List<string> sequences = new List<string>();
  228. sequences.Add(SelectedLPName.ToString());
  229. sequences.Add(SelectedAlignerName.ToString());
  230. if (SelectedPufName != ModuleName.Unknown)
  231. {
  232. sequences.Add(SelectedPufName.ToString());
  233. }
  234. if (SelectedSrdName != ModuleName.Unknown)
  235. {
  236. sequences.Add(SelectedSrdName.ToString());
  237. }
  238. if (SelectedDummyName != ModuleName.Unknown)
  239. {
  240. sequences.Add(SelectedDummyName.ToString());
  241. }
  242. List<RobotCycleParameter> parameters = new List<RobotCycleParameter>();
  243. RobotCycleParameter lpParameter = new RobotCycleParameter();
  244. lpParameter.ModuleName = SelectedLPName;
  245. parameters.Add(lpParameter);
  246. InvokeClient.Instance.Service.DoOperation($"EFEM.{EfemOperation.RobotCycle}",JsonConvert.SerializeObject(parameters), InPutCycleTimes, InPutAlignDegree);
  247. }
  248. private void RobotCycleAbortAction(object param)
  249. {
  250. InvokeClient.Instance.Service.DoOperation($"{ModuleName.EfemRobot}.{EfemOperation.Abort}");
  251. }
  252. private void LPChangeAction(object param)
  253. {
  254. if ("LP1".Equals((string)param))
  255. {
  256. SelectedLPName = ModuleName.LP1;
  257. }
  258. else if ("LP2".Equals((string)param))
  259. {
  260. SelectedLPName = ModuleName.LP2;
  261. }
  262. else
  263. {
  264. SelectedLPName = ModuleName.LP3;
  265. }
  266. }
  267. private void AlignerChangeAction(object param)
  268. {
  269. }
  270. private void PufChangeAction(object param)
  271. {
  272. }
  273. private void DummyChangeAction(object param)
  274. {
  275. if ("Dummy1".Equals((string)param))
  276. {
  277. SelectedDummyName = ModuleName.Dummy1;
  278. }
  279. else
  280. {
  281. SelectedDummyName = ModuleName.Dummy2;
  282. }
  283. }
  284. private void SrdChangeAction(object param)
  285. {
  286. if ("SRD1".Equals((string)param))
  287. {
  288. SelectedSrdName = ModuleName.SRD1;
  289. }
  290. else
  291. {
  292. SelectedSrdName = ModuleName.SRD2;
  293. }
  294. }
  295. /// <summary>
  296. /// 加载数据
  297. /// </summary>
  298. public void LoadData(string systemName)
  299. {
  300. _rtDataKeys.Clear();
  301. _rtDataKeys.Add("EFEM.CurrentRobotCycleTime");
  302. if (_timer == null)
  303. {
  304. _timer = new DispatcherTimer();
  305. _timer.Interval = TimeSpan.FromMilliseconds(200);
  306. _timer.Tick += Timer_Tick;
  307. }
  308. _timer.Start();
  309. }
  310. /// <summary>
  311. /// 定时器执行
  312. /// </summary>
  313. /// <param name="sender"></param>
  314. /// <param name="e"></param>
  315. private void Timer_Tick(object sender, EventArgs e)
  316. {
  317. if (_rtDataKeys.Count != 0)
  318. {
  319. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  320. if (_rtDataValueDic != null)
  321. {
  322. CurrentCycle = CommonFunction.GetValue<int>(_rtDataValueDic, $"EFEM.CurrentRobotCycleTime");
  323. }
  324. }
  325. }
  326. /// <summary>
  327. /// 隐藏
  328. /// </summary>
  329. public void Hide()
  330. {
  331. }
  332. }
  333. }