VPWMotionViewModel.cs 6.1 KB

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