LoaderCycleViewModel.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. using Aitex.Core.Common;
  2. using Aitex.Core.UI.MVVM;
  3. using Aitex.Core.Util;
  4. using Aitex.Core.Utilities;
  5. using LiveCharts;
  6. using MECF.Framework.Common.Beckhoff.AxisProvider;
  7. using MECF.Framework.Common.Beckhoff.Station;
  8. using MECF.Framework.Common.CommonData.PUF;
  9. using MECF.Framework.Common.DataCenter;
  10. using MECF.Framework.Common.OperationCenter;
  11. using MECF.Framework.Common.Utilities;
  12. using CyberX8_MainPages.Unity;
  13. using Prism.Mvvm;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. using System.Timers;
  20. using System.Windows.Input;
  21. using System.Windows.Threading;
  22. namespace CyberX8_MainPages.ViewModels
  23. {
  24. public class LoaderCycleViewModel : BindableBase
  25. {
  26. #region 常量
  27. #endregion
  28. #region 内部变量
  29. /// <summary>
  30. /// 模块名称
  31. /// </summary>
  32. private string _module = "";
  33. /// <summary>
  34. /// 定时器
  35. /// </summary>
  36. private DispatcherTimer _timer;
  37. /// <summary>
  38. /// RT查询key集合
  39. /// </summary>
  40. private List<string> _rtDataKeys = new List<string>();
  41. /// <summary>
  42. /// rt查询key数值字典
  43. /// </summary>
  44. private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
  45. /// <summary>
  46. /// A面循环次数
  47. /// </summary>
  48. private string _sideACurrentCycle;
  49. /// <summary>
  50. /// A面当前状态
  51. /// </summary>
  52. private string _sideAState;
  53. /// <summary>
  54. /// A面总共循环次数
  55. /// </summary>
  56. private int _sideATotalCycle;
  57. /// <summary>
  58. /// A面当前步骤
  59. /// </summary>
  60. private string _sideACurrentStep;
  61. /// <summary>
  62. /// B面循环次数
  63. /// </summary>
  64. private string _sideBCurrentCycle;
  65. /// <summary>
  66. /// B面当前状态
  67. /// </summary>
  68. private string _sideBState;
  69. /// <summary>
  70. /// B面总共循环次数
  71. /// </summary>
  72. private int _sideBTotalCycle;
  73. /// <summary>
  74. /// B面当前步聚
  75. /// </summary>
  76. private string _sideBCurrentStep;
  77. #endregion
  78. #region 属性
  79. /// <summary>
  80. /// 模块名称
  81. /// </summary>
  82. public string Module
  83. {
  84. get { return _module; }
  85. set { SetProperty(ref _module, value); }
  86. }
  87. /// <summary>
  88. /// A面当前循环次数
  89. /// </summary>
  90. public string SideACurrentCycle
  91. {
  92. get { return _sideACurrentCycle; }
  93. set { SetProperty(ref _sideACurrentCycle, value);}
  94. }
  95. /// <summary>
  96. /// A面当前状态
  97. /// </summary>
  98. public string SideAState
  99. {
  100. get { return _sideAState; }
  101. set { SetProperty(ref _sideAState, value); }
  102. }
  103. /// <summary>
  104. /// A面总共循环次数
  105. /// </summary>
  106. public int SideATotalCycle
  107. {
  108. get { return _sideATotalCycle; }
  109. set { SetProperty(ref _sideATotalCycle, value); }
  110. }
  111. /// <summary>
  112. /// A面当前步骤
  113. /// </summary>
  114. public string SideACurrentStep
  115. {
  116. get { return _sideACurrentStep; }
  117. set { SetProperty(ref _sideACurrentStep, value); }
  118. }
  119. /// <summary>
  120. /// B面当前循环次数
  121. /// </summary>
  122. public string SideBCurrentCycle
  123. {
  124. get { return _sideBCurrentCycle; }
  125. set { SetProperty(ref _sideBCurrentCycle, value); }
  126. }
  127. /// <summary>
  128. /// B面当前状态
  129. /// </summary>
  130. public string SideBState
  131. {
  132. get { return _sideBState; }
  133. set { SetProperty(ref _sideBState, value); }
  134. }
  135. /// <summary>
  136. /// B面总共循环次数
  137. /// </summary>
  138. public int SideBTotalCycle
  139. {
  140. get { return _sideBTotalCycle; }
  141. set { SetProperty(ref _sideBTotalCycle, value); }
  142. }
  143. /// <summary>
  144. /// B面当前步骤
  145. /// </summary>
  146. public string SideBCurrentStep
  147. {
  148. get { return _sideBCurrentStep; }
  149. set { SetProperty(ref _sideBCurrentStep, value); }
  150. }
  151. #endregion
  152. #region 指令
  153. /// <summary>
  154. /// A面启动循环Command
  155. /// </summary>
  156. public ICommand SideAStartCycleCommand { get;private set; }
  157. /// <summary>
  158. /// A面启动循环Command
  159. /// </summary>
  160. public ICommand SideAStopCycleCommand { get; private set; }
  161. /// <summary>
  162. /// B面启动循环Command
  163. /// </summary>
  164. public ICommand SideBStartCycleCommand { get; private set; }
  165. /// <summary>
  166. /// B面启动循环Command
  167. /// </summary>
  168. public ICommand SideBStopCycleCommand { get; private set; }
  169. #endregion
  170. /// <summary>
  171. /// 构造函数
  172. /// </summary>
  173. public LoaderCycleViewModel()
  174. {
  175. SideAStartCycleCommand = new DelegateCommand<object>(SideAStartCycleAction);
  176. SideAStopCycleCommand = new DelegateCommand<object>(SideAStopCycleAction);
  177. SideBStartCycleCommand = new DelegateCommand<object>(SideBStartCycleAction);
  178. SideBStopCycleCommand = new DelegateCommand<object>(SideBStopCycleAction);
  179. }
  180. /// <summary>
  181. /// 加载数据
  182. /// </summary>
  183. public void LoadData(string systemName)
  184. {
  185. Module = systemName;
  186. if (_timer == null)
  187. {
  188. _timer = new DispatcherTimer();
  189. _timer.Interval = TimeSpan.FromMilliseconds(100);
  190. _timer.Tick += Timer_Tick; ;
  191. }
  192. _rtDataKeys.Add($"{Module}.SideA.CurrentCycle");
  193. _rtDataKeys.Add($"{Module}.SideA.CurrentCycleStep");
  194. _rtDataKeys.Add($"{Module}.SideB.CurrentCycle");
  195. _rtDataKeys.Add($"{Module}.SideB.CurrentCycleStep");
  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. SideACurrentCycle = CommonFunction.GetValue<string>(_rtDataValueDic, $"{Module}.SideA.CurrentCycle");
  211. SideBCurrentCycle = CommonFunction.GetValue<string>(_rtDataValueDic, $"{Module}.SideB.CurrentCycle");
  212. SideACurrentStep = CommonFunction.GetValue<string>(_rtDataValueDic, $"{Module}.SideA.CurrentCycleStep");
  213. SideBCurrentStep = CommonFunction.GetValue<string>(_rtDataValueDic, $"{Module}.SideB.CurrentCycleStep");
  214. }
  215. }
  216. }
  217. /// <summary>
  218. /// 隐藏
  219. /// </summary>
  220. public void Hide()
  221. {
  222. if (_timer != null)
  223. {
  224. _timer.Stop();
  225. }
  226. }
  227. #region Action
  228. private void SideAStartCycleAction(object param)
  229. {
  230. InvokeClient.Instance.Service.DoOperation($"{Module}.SideA.StartCycle",SideATotalCycle);
  231. }
  232. private void SideAStopCycleAction(object param)
  233. {
  234. InvokeClient.Instance.Service.DoOperation($"{Module}.SideA.StopCycle");
  235. }
  236. private void SideBStartCycleAction(object param)
  237. {
  238. InvokeClient.Instance.Service.DoOperation($"{Module}.SideB.StartCycle",SideBTotalCycle);
  239. }
  240. private void SideBStopCycleAction(object param)
  241. {
  242. InvokeClient.Instance.Service.DoOperation($"{Module}.SideB.StopCycle");
  243. }
  244. #endregion
  245. }
  246. }