PufMotionViewModel.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. using Aitex.Core.UI.MVVM;
  2. using Aitex.Core.Util;
  3. using Aitex.Core.Utilities;
  4. using ExcelLibrary.BinaryFileFormat;
  5. using MECF.Framework.Common.Beckhoff.AxisProvider;
  6. using MECF.Framework.Common.Beckhoff.IOAxis;
  7. using MECF.Framework.Common.CommonData.PUF;
  8. using MECF.Framework.Common.DataCenter;
  9. using MECF.Framework.Common.OperationCenter;
  10. using MECF.Framework.Common.Utilities;
  11. using CyberX8_Core;
  12. using CyberX8_MainPages.Model;
  13. using CyberX8_MainPages.Unity;
  14. using Prism.Mvvm;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Linq;
  18. using System.Reflection;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. using System.Timers;
  22. using System.Windows.Input;
  23. using System.Windows.Threading;
  24. namespace CyberX8_MainPages.ViewModels
  25. {
  26. public class PufMotionViewModel : BindableBase
  27. {
  28. #region 常量
  29. private const string MOTION_DATA = "MotionData";
  30. #endregion
  31. #region 内部变量
  32. #region flip
  33. /// <summary>
  34. /// flip模块名称
  35. /// </summary>
  36. private string _flipModuleName;
  37. /// <summary>
  38. /// 数据
  39. /// </summary>
  40. private CommandMotionData _flipMotionData;
  41. #endregion
  42. #region rotation
  43. /// <summary>
  44. /// rotation模块名称
  45. /// </summary>
  46. private string _rotationModuleName;
  47. /// <summary>
  48. ///
  49. /// </summary>
  50. private CommandMotionData _rotationMotionData;
  51. #endregion
  52. #region Vertical
  53. /// <summary>
  54. /// vertical模块名称
  55. /// </summary>
  56. private string _verticalModuleName;
  57. /// <summary>
  58. ///
  59. /// </summary>
  60. private CommandMotionData _verticalMotionData;
  61. #endregion
  62. /// <summary>
  63. /// 模块名称
  64. /// </summary>
  65. private string _module = "";
  66. /// <summary>
  67. /// 增加
  68. /// </summary>
  69. private double _incrementValue = 0.01;
  70. /// <summary>
  71. ///
  72. /// </summary>
  73. private PufDistanceData _distanceData;
  74. /// <summary>
  75. /// 定时器
  76. /// </summary>
  77. DispatcherTimer _timer;
  78. /// <summary>
  79. /// RT查询key集合
  80. /// </summary>
  81. private List<string> _rtDataKeys = new List<string>();
  82. /// <summary>
  83. /// rt查询key数值字典
  84. /// </summary>
  85. private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
  86. #endregion
  87. #region 属性
  88. #region Flip
  89. /// <summary>
  90. /// Filp名称
  91. /// </summary>
  92. public string FlipModuleName
  93. {
  94. get { return _flipModuleName; }
  95. set { SetProperty(ref _flipModuleName, value); }
  96. }
  97. /// <summary>
  98. ///
  99. /// </summary>
  100. public CommandMotionData FlipMotionData
  101. {
  102. get { return _flipMotionData; }
  103. set { SetProperty(ref _flipMotionData, value); }
  104. }
  105. #endregion
  106. #region Rotation
  107. /// <summary>
  108. /// Rotate名称
  109. /// </summary>
  110. public string RotationModuleName
  111. {
  112. get { return _rotationModuleName; }
  113. set { SetProperty(ref _rotationModuleName, value); }
  114. }
  115. public CommandMotionData RotationMotionData
  116. {
  117. get { return _rotationMotionData; }
  118. set { SetProperty(ref _rotationMotionData, value); }
  119. }
  120. #endregion
  121. #region Vertical
  122. /// <summary>
  123. /// Vertical名称
  124. /// </summary>
  125. public string VerticalModuleName
  126. {
  127. get { return _verticalModuleName; }
  128. set { SetProperty(ref _verticalModuleName, value); }
  129. }
  130. /// <summary>
  131. ///
  132. /// </summary>
  133. public CommandMotionData VerticalMotionData
  134. {
  135. get { return _verticalMotionData; }
  136. set { SetProperty(ref _verticalMotionData, value); }
  137. }
  138. #endregion
  139. /// <summary>
  140. /// 模块名称
  141. /// </summary>
  142. public string Module
  143. {
  144. get { return _module; }
  145. set { SetProperty(ref _module, value); }
  146. }
  147. /// <summary>
  148. /// 步进
  149. /// </summary>
  150. public double IncrementValue
  151. {
  152. get { return _incrementValue; }
  153. set { SetProperty(ref _incrementValue, value); }
  154. }
  155. public PufDistanceData DistanceData
  156. {
  157. get { return _distanceData; }
  158. set { SetProperty(ref _distanceData, value); }
  159. }
  160. #endregion
  161. /// <summary>
  162. /// 构造函数
  163. /// </summary>
  164. public PufMotionViewModel()
  165. {
  166. IncrementValue = (double)QueryDataClient.Instance.Service.GetConfig("System.Increment");
  167. FlipMotionData = new CommandMotionData();
  168. RotationMotionData = new CommandMotionData();
  169. VerticalMotionData = new CommandMotionData();
  170. }
  171. /// <summary>
  172. /// 加载数据
  173. /// </summary>
  174. public void LoadData(string systemName)
  175. {
  176. Module = systemName;
  177. FlipModuleName = $"{Module}.Flip";
  178. RotationModuleName = $"{Module}.Rotation";
  179. VerticalModuleName = $"{Module}.Vertical";
  180. _rtDataKeys.Clear();
  181. _rtDataKeys.Add($"{FlipModuleName}.IsHomed");
  182. _rtDataKeys.Add($"{FlipModuleName}.IsSwitchOn");
  183. _rtDataKeys.Add($"{FlipModuleName}.{MOTION_DATA}");
  184. _rtDataKeys.Add($"{RotationModuleName}.IsHomed");
  185. _rtDataKeys.Add($"{RotationModuleName}.IsSwitchOn");
  186. _rtDataKeys.Add($"{RotationModuleName}.{MOTION_DATA}");
  187. _rtDataKeys.Add($"{VerticalModuleName}.IsHomed");
  188. _rtDataKeys.Add($"{VerticalModuleName}.IsSwitchOn");
  189. _rtDataKeys.Add($"{VerticalModuleName}.{MOTION_DATA}");
  190. if (_timer == null)
  191. {
  192. _timer = new DispatcherTimer();
  193. _timer.Interval = TimeSpan.FromMilliseconds(100);
  194. _timer.Tick += Timer_Tick; ;
  195. }
  196. _timer.Start();
  197. }
  198. /// <summary>
  199. /// 定时器执行
  200. /// </summary>
  201. /// <param name="sender"></param>
  202. /// <param name="e"></param>
  203. private void Timer_Tick(object sender, EventArgs e)
  204. {
  205. if (_rtDataKeys.Count != 0)
  206. {
  207. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  208. if (_rtDataValueDic != null)
  209. {
  210. FlipMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{FlipModuleName}.{MOTION_DATA}");
  211. RotationMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{RotationModuleName}.{MOTION_DATA}");
  212. VerticalMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{VerticalModuleName}.{MOTION_DATA}");
  213. }
  214. }
  215. }
  216. /// <summary>
  217. /// 隐藏
  218. /// </summary>
  219. public void Hide()
  220. {
  221. _timer.Stop();
  222. }
  223. }
  224. }