VPWStationSetupViewModel.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. using MECF.Framework.Common.CommonData.PUF;
  2. using MECF.Framework.Common.DataCenter;
  3. using MECF.Framework.Common.Equipment;
  4. using MECF.Framework.Common.Utilities;
  5. using Prism.Mvvm;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Threading;
  12. namespace PunkHPX8_MainPages.ViewModels
  13. {
  14. public class VPWStationSetupViewModel : BindableBase
  15. {
  16. #region 常量
  17. private const string MOTION_DATA = "MotionData";
  18. private const string IS_SWITCH_ON = "IsSwitchOn";
  19. private const string CURRENT_STATION = "CurrentStation";
  20. #endregion
  21. #region 内部变量
  22. #region VPW1Rotation
  23. /// <summary>
  24. /// VPW1Rotation模块名称
  25. /// </summary>
  26. private string _vPW1RotationModuleName;
  27. /// <summary>
  28. /// VPW1Rotation运动数据
  29. /// </summary>
  30. private CommandMotionData _vPW1RotationMotionData;
  31. /// <summary>
  32. /// VPW1Rotation当前位置
  33. /// </summary>
  34. private string _vPW1RotationCurrentStation;
  35. #endregion
  36. #region VPW2Rotation
  37. /// <summary>
  38. /// VPW2Rotation模块名称
  39. /// </summary>
  40. private string _vPW2RotationModuleName;
  41. /// <summary>
  42. /// VPW1Rotation运动数据
  43. /// </summary>
  44. private CommandMotionData _vPW2RotationMotionData;
  45. /// <summary>
  46. /// VPW1Rotation当前位置
  47. /// </summary>
  48. private string _vPW2RotationCurrentStation;
  49. #endregion
  50. #region 系统数据
  51. /// <summary>
  52. /// 定时器
  53. /// </summary>
  54. DispatcherTimer _timer;
  55. /// <summary>
  56. /// 查询后台数据集合
  57. /// </summary>
  58. private List<string> _rtDataKeys = new List<string>();
  59. /// <summary>
  60. /// rt查询key数值字典
  61. /// </summary>
  62. private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
  63. #endregion
  64. #endregion
  65. #region 属性
  66. #region VPW1Rotation
  67. /// <summary>
  68. /// VPW1Rotation名称
  69. /// </summary>
  70. public string VPW1RotationModuleName
  71. {
  72. get { return _vPW1RotationModuleName; }
  73. set { SetProperty(ref _vPW1RotationModuleName, value); }
  74. }
  75. /// <summary>
  76. /// VPW1Rotation运动数据
  77. /// </summary>
  78. public CommandMotionData VPW1RotationMotionData
  79. {
  80. get { return _vPW1RotationMotionData; }
  81. set { SetProperty(ref _vPW1RotationMotionData, value); }
  82. }
  83. /// <summary>
  84. /// VPW1Rotation当前位置
  85. /// </summary>
  86. public string VPW1RotationCurrentStation
  87. {
  88. get { return _vPW1RotationCurrentStation; }
  89. set { SetProperty(ref _vPW1RotationCurrentStation, value); }
  90. }
  91. #endregion
  92. #region VPW2Rotation
  93. /// <summary>
  94. /// VPW2Rotation名称
  95. /// </summary>
  96. public string VPW2RotationModuleName
  97. {
  98. get { return _vPW2RotationModuleName; }
  99. set { SetProperty(ref _vPW2RotationModuleName, value); }
  100. }
  101. /// <summary>
  102. /// VPW2Rotation运动数据
  103. /// </summary>
  104. public CommandMotionData VPW2RotationMotionData
  105. {
  106. get { return _vPW2RotationMotionData; }
  107. set { SetProperty(ref _vPW2RotationMotionData, value); }
  108. }
  109. /// <summary>
  110. /// VPW1Rotation当前位置
  111. /// </summary>
  112. public string VPW2RotationCurrentStation
  113. {
  114. get { return _vPW2RotationCurrentStation; }
  115. set { SetProperty(ref _vPW2RotationCurrentStation, value); }
  116. }
  117. #endregion
  118. #endregion
  119. /// <summary>
  120. /// 加载数据
  121. /// </summary>
  122. public void LoadData(string systemName)
  123. {
  124. VPW1RotationModuleName = $"{ModuleName.VpwCell1}.Rotation";
  125. VPW2RotationModuleName = $"{ModuleName.VpwCell2}.Rotation";
  126. AddDataKeys();
  127. if (_timer == null)
  128. {
  129. _timer = new DispatcherTimer();
  130. _timer.Interval = TimeSpan.FromMilliseconds(200);
  131. _timer.Tick += Timer_Tick; ;
  132. }
  133. _timer.Start();
  134. }
  135. /// <summary>
  136. /// 定时器执行
  137. /// </summary>
  138. /// <param name="sender"></param>
  139. /// <param name="e"></param>
  140. private void Timer_Tick(object sender, EventArgs e)
  141. {
  142. OnTimer();
  143. }
  144. /// <summary>
  145. /// 隐藏
  146. /// </summary>
  147. public void Hide()
  148. {
  149. if (_timer != null)
  150. {
  151. _timer.Stop();
  152. }
  153. }
  154. /// <summary>
  155. /// 初始化查询数据集合
  156. /// </summary>
  157. private void AddDataKeys()
  158. {
  159. _rtDataKeys.Clear();
  160. _rtDataKeys.Add($"{VPW1RotationModuleName}.{MOTION_DATA}");
  161. _rtDataKeys.Add($"{VPW1RotationModuleName}.{IS_SWITCH_ON}");
  162. _rtDataKeys.Add($"{VPW1RotationModuleName}.{CURRENT_STATION}");
  163. _rtDataKeys.Add($"{VPW2RotationModuleName}.{MOTION_DATA}");
  164. _rtDataKeys.Add($"{VPW2RotationModuleName}.{IS_SWITCH_ON}");
  165. _rtDataKeys.Add($"{VPW2RotationModuleName}.{CURRENT_STATION}");
  166. _rtDataKeys.Add($"{VPW2RotationModuleName}.{CURRENT_STATION}");
  167. }
  168. /// <summary>
  169. /// 定时器
  170. /// </summary>
  171. /// <returns></returns>
  172. private Boolean OnTimer()
  173. {
  174. if (_rtDataKeys.Count != 0)
  175. {
  176. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  177. if (_rtDataValueDic != null)
  178. {
  179. VPW1RotationMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{VPW1RotationModuleName}.{MOTION_DATA}");
  180. VPW1RotationCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{VPW1RotationModuleName}.{CURRENT_STATION}"), VPW1RotationModuleName);
  181. VPW2RotationMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{VPW2RotationModuleName}.{MOTION_DATA}");
  182. VPW2RotationCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{VPW2RotationModuleName}.{CURRENT_STATION}"), VPW2RotationModuleName);
  183. }
  184. }
  185. return true;
  186. }
  187. }
  188. }