ProcessChamberViewModel.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. using Aitex.Core.Util;
  2. using LiveCharts.Wpf;
  3. using MECF.Framework.Common.Beckhoff.Station;
  4. using MECF.Framework.Common.CommonData.PUF;
  5. using MECF.Framework.Common.DataCenter;
  6. using MECF.Framework.Common.Equipment;
  7. using MECF.Framework.Common.Layout;
  8. using MECF.Framework.Common.ProcessCell;
  9. using MECF.Framework.Common.Reservior;
  10. using MECF.Framework.Common.Utilities;
  11. using PunkHPX8_Core;
  12. using PunkHPX8_Themes.UserControls;
  13. using Prism.Mvvm;
  14. using System;
  15. using System.Collections.Concurrent;
  16. using System.Collections.Generic;
  17. using System.IO;
  18. using System.Linq;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. using System.Timers;
  22. using System.Windows.Threading;
  23. using System.Windows;
  24. using System.Windows.Markup;
  25. namespace PunkHPX8_MainPages.ViewModels
  26. {
  27. public class ProcessChamberViewModel : BindableBase
  28. {
  29. #region 常量
  30. private const string CURRENT_STATION = "CurrentStation";
  31. private const string MOTION_DATA = "MotionData";
  32. /// <summary>
  33. /// Transporter盒子的宽度85
  34. /// </summary>
  35. private const int TRANSPORTER_BOX_LENGTH = 85;
  36. /// <summary>
  37. /// Loader Buffer元素宽度的一半(12/2)
  38. /// </summary>
  39. private const int LOADER_BUFFER_HALF_LENGTH = 6;
  40. /// <summary>
  41. /// Transporter中线最高位置到Cell之间的距离
  42. /// </summary>
  43. private const int VERTICAL_DISTANCE = 115;
  44. #endregion
  45. #region 内部变量
  46. private ProcessLayout _processLayout;
  47. /// <summary>
  48. /// Loader Gantry运动数据
  49. /// </summary>
  50. private CommandMotionData _loaderGantryMotionData;
  51. /// <summary>
  52. /// Loader Elevator运动数据
  53. /// </summary>
  54. private CommandMotionData _loaderElevatorMotionData;
  55. /// <summary>
  56. /// Loader Transporter Gantry当前位置
  57. /// </summary>
  58. private double _loaderTransporterGantryPosition;
  59. /// <summary>
  60. /// Loader transporter Elevator当前位置
  61. /// </summary>
  62. private double _loaderTransporterElevatorPosition;
  63. /// <summary>
  64. /// Process Gantry运动数据
  65. /// </summary>
  66. private CommandMotionData _processGantryMotionData;
  67. /// <summary>
  68. /// Process Elevator运动数据
  69. /// </summary>
  70. private CommandMotionData _processElevatorMotionData;
  71. /// <summary>
  72. /// Process transporter Gantry当前位置
  73. /// </summary>
  74. private double _processTransporterGantryPosition;
  75. /// <summary>
  76. /// Process transporter Elevator当前位置
  77. /// </summary>
  78. private double _processTransporterElevatorPosition;
  79. /// <summary>
  80. /// UI水平距离
  81. /// </summary>
  82. private int _transporterLayoutHorizontalDistance;
  83. /// <summary>
  84. /// ui 水平比例
  85. /// </summary>
  86. private double _horizontalRatio;
  87. /// <summary>
  88. /// ui垂直比例
  89. /// </summary>
  90. private double _verticalRatio;
  91. /// <summary>
  92. /// Loader UI的位置
  93. /// </summary>
  94. private int _loaderPosition;
  95. /// <summary>
  96. /// Cell 工位最左侧的位置
  97. /// </summary>
  98. private double _stationMin;
  99. /// <summary>
  100. /// Process与Loader偏差距离
  101. /// </summary>
  102. private int _biasDistanceBetweenLoaderAndProcess;
  103. /// <summary>
  104. /// RT查询key集合
  105. /// </summary>
  106. private List<string> _rtDataKeys = new List<string>();
  107. /// <summary>
  108. /// rt查询key数值字典
  109. /// </summary>
  110. private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
  111. /// <summary>
  112. /// 定时器
  113. /// </summary>
  114. private DispatcherTimer _timer;
  115. /// <summary>
  116. /// Process控件是否加载
  117. /// </summary>
  118. private bool _processControlLoaded;
  119. #endregion
  120. #region 属性
  121. public ProcessLayout ProcessLayout { get { return _processLayout; } set { SetProperty(ref _processLayout, value); } }
  122. public bool ProcessControlLoaded
  123. {
  124. get { return _processControlLoaded; }
  125. set { SetProperty(ref _processControlLoaded, value); }
  126. }
  127. #endregion
  128. public ProcessChamberViewModel()
  129. {
  130. }
  131. /// <summary>
  132. /// 加载数据
  133. /// </summary>
  134. public void LoadData(object obj)
  135. {
  136. if (obj==null)
  137. {
  138. return;
  139. }
  140. ProcessControlLoaded = true;
  141. _rtDataKeys.Clear();
  142. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  143. if(_rtDataValueDic!=null)
  144. {
  145. }
  146. InitialKeys();
  147. if (_timer == null)
  148. {
  149. _timer = new DispatcherTimer();
  150. _timer.Interval = TimeSpan.FromMilliseconds(100);
  151. _timer.Tick += Timer_Tick;
  152. }
  153. _timer.Start();
  154. }
  155. /// <summary>
  156. /// 隐藏
  157. /// </summary>
  158. public void Hide()
  159. {
  160. if(_timer!=null)
  161. {
  162. _timer.Stop();
  163. }
  164. }
  165. /// <summary>
  166. /// 定时器执行
  167. /// </summary>
  168. /// <param name="sender"></param>
  169. /// <param name="e"></param>
  170. private void Timer_Tick(object sender, EventArgs e)
  171. {
  172. if (_rtDataKeys.Count != 0)
  173. {
  174. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  175. if (_rtDataValueDic != null)
  176. {
  177. }
  178. }
  179. }
  180. /// <summary>
  181. /// 计算Tansporter水平最大值最小值
  182. /// </summary>
  183. /// <param name="loaderTransporterAxis"></param>
  184. /// <param name="processTransporterAxis"></param>
  185. /// <returns></returns>
  186. private (double max,double min) CalculateTransporterMaxMin(BeckhoffStationAxis loaderTransporterAxis,BeckhoffStationAxis processTransporterAxis)
  187. {
  188. double max = 0;
  189. double min = double.MaxValue;
  190. return (max,min);
  191. }
  192. /// <summary>
  193. /// 初始化Keys
  194. /// </summary>
  195. private void InitialKeys()
  196. {
  197. _rtDataKeys.Clear();
  198. }
  199. }
  200. }