VPWMotionViewModel.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 VPWMotionViewModel : BindableBase
  15. {
  16. #region 常量
  17. private const string MOTION_DATA = "MotionData";
  18. private const int ACCEL_FACTOR = 10;
  19. #endregion
  20. #region 内部变量
  21. #region VPW1Rotation
  22. /// <summary>
  23. /// VPW1Rotation模块名称
  24. /// </summary>
  25. private string _vPW1RotationModuleName;
  26. /// <summary>
  27. /// 数据
  28. /// </summary>
  29. private CommandMotionData _vPW1RotationMotionData;
  30. #endregion
  31. #region VPW2Rotation
  32. /// <summary>
  33. /// VPW2Rotation模块名称
  34. /// </summary>
  35. private string _vPW2RotationModuleName;
  36. /// <summary>
  37. /// 数据
  38. /// </summary>
  39. private CommandMotionData _vPW2RotationMotionData;
  40. #endregion
  41. /// <summary>
  42. /// 增加
  43. /// </summary>
  44. private double _incrementValue = 0.01;
  45. /// <summary>
  46. /// 定时器
  47. /// </summary>
  48. DispatcherTimer _timer;
  49. /// <summary>
  50. /// RT查询key集合
  51. /// </summary>
  52. private List<string> _rtDataKeys = new List<string>();
  53. /// <summary>
  54. /// rt查询key数值字典
  55. /// </summary>
  56. private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
  57. #endregion
  58. #region 属性
  59. #region VPW1Rotation
  60. /// <summary>
  61. /// VPW1Rotation名称
  62. /// </summary>
  63. public string VPW1RotationModuleName
  64. {
  65. get { return _vPW1RotationModuleName; }
  66. set { SetProperty(ref _vPW1RotationModuleName, value); }
  67. }
  68. /// <summary>
  69. ///
  70. /// </summary>
  71. public CommandMotionData VPW1RotationMotionData
  72. {
  73. get { return _vPW1RotationMotionData; }
  74. set { SetProperty(ref _vPW1RotationMotionData, value); }
  75. }
  76. #endregion
  77. #region VPW2Rotation
  78. /// <summary>
  79. /// VPW2Rotation
  80. /// </summary>
  81. public string VPW2RotationModuleName
  82. {
  83. get { return _vPW2RotationModuleName; }
  84. set { SetProperty(ref _vPW2RotationModuleName, value); }
  85. }
  86. /// <summary>
  87. ///
  88. /// </summary>
  89. public CommandMotionData VPW2RotationMotionData
  90. {
  91. get { return _vPW2RotationMotionData; }
  92. set { SetProperty(ref _vPW2RotationMotionData, value); }
  93. }
  94. #endregion
  95. /// <summary>
  96. /// 步进
  97. /// </summary>
  98. public double IncrementValue
  99. {
  100. get { return _incrementValue; }
  101. set { SetProperty(ref _incrementValue, value); }
  102. }
  103. #endregion
  104. /// <summary>
  105. /// 加载数据
  106. /// </summary>
  107. public void LoadData(string systemName)
  108. {
  109. VPW1RotationModuleName = $"{ModuleName.VpwCell1}.Rotation";
  110. VPW2RotationModuleName = $"{ModuleName.VpwCell2}.Rotation";
  111. _rtDataKeys.Clear();
  112. _rtDataKeys.Add($"{VPW1RotationModuleName}.IsHomed");
  113. _rtDataKeys.Add($"{VPW1RotationModuleName}.IsSwitchOn");
  114. _rtDataKeys.Add($"{VPW1RotationModuleName}.{MOTION_DATA}");
  115. _rtDataKeys.Add($"{VPW2RotationModuleName}.IsHomed");
  116. _rtDataKeys.Add($"{VPW2RotationModuleName}.IsSwitchOn");
  117. _rtDataKeys.Add($"{VPW2RotationModuleName}.{MOTION_DATA}");
  118. if (_timer == null)
  119. {
  120. _timer = new DispatcherTimer();
  121. _timer.Interval = TimeSpan.FromMilliseconds(500);
  122. _timer.Tick += Timer_Tick;
  123. }
  124. _timer.Start();
  125. }
  126. /// <summary>
  127. /// 定时器执行
  128. /// </summary>
  129. /// <param name="sender"></param>
  130. /// <param name="e"></param>
  131. private void Timer_Tick(object sender, EventArgs e)
  132. {
  133. if (_rtDataKeys.Count != 0)
  134. {
  135. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  136. if (_rtDataValueDic != null)
  137. {
  138. CommandMotionData tmp1 = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{VPW1RotationModuleName}.{MOTION_DATA}");
  139. if (tmp1 != null)
  140. {
  141. tmp1.ActualVelocity = Math.Round(tmp1.ActualVelocity / 6, 2);
  142. tmp1.ProfileVelocity = Math.Round(tmp1.ProfileVelocity / 6, 2);
  143. tmp1.HomingVelocity = Math.Round(tmp1.HomingVelocity / 6, 2);
  144. tmp1.HomingVelocitySlow = Math.Round(tmp1.HomingVelocitySlow / 6, 2);
  145. tmp1.ProfileDecel = tmp1.ProfileDecel * ACCEL_FACTOR;
  146. tmp1.ProfileAccel = tmp1.ProfileAccel * ACCEL_FACTOR;
  147. }
  148. VPW1RotationMotionData = tmp1;
  149. CommandMotionData tmp2 = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{VPW2RotationModuleName}.{MOTION_DATA}");
  150. if (tmp2 != null)
  151. {
  152. tmp2.ActualVelocity = Math.Round(tmp1.ActualVelocity / 6, 2);
  153. tmp2.ProfileVelocity = Math.Round(tmp1.ProfileVelocity / 6, 2);
  154. tmp2.HomingVelocity = Math.Round(tmp1.HomingVelocity / 6, 2);
  155. tmp2.HomingVelocitySlow = Math.Round(tmp1.HomingVelocitySlow / 6, 2);
  156. tmp2.ProfileDecel = tmp1.ProfileDecel * ACCEL_FACTOR;
  157. tmp2.ProfileAccel = tmp1.ProfileAccel * ACCEL_FACTOR;
  158. }
  159. VPW2RotationMotionData = tmp2;
  160. }
  161. }
  162. }
  163. /// <summary>
  164. /// 隐藏
  165. /// </summary>
  166. public void Hide()
  167. {
  168. _timer.Stop();
  169. }
  170. }
  171. }