using Aitex.Core.Common; using Aitex.Core.UI.MVVM; using Aitex.Core.Util; using Aitex.Core.Utilities; using LiveCharts; using MECF.Framework.Common.Beckhoff.AxisProvider; using MECF.Framework.Common.Beckhoff.Station; using MECF.Framework.Common.CommonData.PUF; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.OperationCenter; using MECF.Framework.Common.Utilities; using CyberX8_MainPages.Unity; using Prism.Mvvm; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Timers; using System.Windows.Input; using System.Windows.Threading; namespace CyberX8_MainPages.ViewModels { public class LoaderCycleViewModel : BindableBase { #region 常量 #endregion #region 内部变量 /// /// 模块名称 /// private string _module = ""; /// /// 定时器 /// private DispatcherTimer _timer; /// /// RT查询key集合 /// private List _rtDataKeys = new List(); /// /// rt查询key数值字典 /// private Dictionary _rtDataValueDic = new Dictionary(); /// /// A面循环次数 /// private string _sideACurrentCycle; /// /// A面当前状态 /// private string _sideAState; /// /// A面总共循环次数 /// private int _sideATotalCycle; /// /// A面当前步骤 /// private string _sideACurrentStep; /// /// B面循环次数 /// private string _sideBCurrentCycle; /// /// B面当前状态 /// private string _sideBState; /// /// B面总共循环次数 /// private int _sideBTotalCycle; /// /// B面当前步聚 /// private string _sideBCurrentStep; #endregion #region 属性 /// /// 模块名称 /// public string Module { get { return _module; } set { SetProperty(ref _module, value); } } /// /// A面当前循环次数 /// public string SideACurrentCycle { get { return _sideACurrentCycle; } set { SetProperty(ref _sideACurrentCycle, value);} } /// /// A面当前状态 /// public string SideAState { get { return _sideAState; } set { SetProperty(ref _sideAState, value); } } /// /// A面总共循环次数 /// public int SideATotalCycle { get { return _sideATotalCycle; } set { SetProperty(ref _sideATotalCycle, value); } } /// /// A面当前步骤 /// public string SideACurrentStep { get { return _sideACurrentStep; } set { SetProperty(ref _sideACurrentStep, value); } } /// /// B面当前循环次数 /// public string SideBCurrentCycle { get { return _sideBCurrentCycle; } set { SetProperty(ref _sideBCurrentCycle, value); } } /// /// B面当前状态 /// public string SideBState { get { return _sideBState; } set { SetProperty(ref _sideBState, value); } } /// /// B面总共循环次数 /// public int SideBTotalCycle { get { return _sideBTotalCycle; } set { SetProperty(ref _sideBTotalCycle, value); } } /// /// B面当前步骤 /// public string SideBCurrentStep { get { return _sideBCurrentStep; } set { SetProperty(ref _sideBCurrentStep, value); } } #endregion #region 指令 /// /// A面启动循环Command /// public ICommand SideAStartCycleCommand { get;private set; } /// /// A面启动循环Command /// public ICommand SideAStopCycleCommand { get; private set; } /// /// B面启动循环Command /// public ICommand SideBStartCycleCommand { get; private set; } /// /// B面启动循环Command /// public ICommand SideBStopCycleCommand { get; private set; } #endregion /// /// 构造函数 /// public LoaderCycleViewModel() { SideAStartCycleCommand = new DelegateCommand(SideAStartCycleAction); SideAStopCycleCommand = new DelegateCommand(SideAStopCycleAction); SideBStartCycleCommand = new DelegateCommand(SideBStartCycleAction); SideBStopCycleCommand = new DelegateCommand(SideBStopCycleAction); } /// /// 加载数据 /// public void LoadData(string systemName) { Module = systemName; if (_timer == null) { _timer = new DispatcherTimer(); _timer.Interval = TimeSpan.FromMilliseconds(100); _timer.Tick += Timer_Tick; ; } _rtDataKeys.Add($"{Module}.SideA.CurrentCycle"); _rtDataKeys.Add($"{Module}.SideA.CurrentCycleStep"); _rtDataKeys.Add($"{Module}.SideB.CurrentCycle"); _rtDataKeys.Add($"{Module}.SideB.CurrentCycleStep"); _timer.Start(); } /// /// 定时器执行 /// /// /// private void Timer_Tick(object sender, EventArgs e) { if (_rtDataKeys.Count != 0) { _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys); if (_rtDataValueDic != null) { SideACurrentCycle = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.SideA.CurrentCycle"); SideBCurrentCycle = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.SideB.CurrentCycle"); SideACurrentStep = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.SideA.CurrentCycleStep"); SideBCurrentStep = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.SideB.CurrentCycleStep"); } } } /// /// 隐藏 /// public void Hide() { if (_timer != null) { _timer.Stop(); } } #region Action private void SideAStartCycleAction(object param) { InvokeClient.Instance.Service.DoOperation($"{Module}.SideA.StartCycle",SideATotalCycle); } private void SideAStopCycleAction(object param) { InvokeClient.Instance.Service.DoOperation($"{Module}.SideA.StopCycle"); } private void SideBStartCycleAction(object param) { InvokeClient.Instance.Service.DoOperation($"{Module}.SideB.StartCycle",SideBTotalCycle); } private void SideBStopCycleAction(object param) { InvokeClient.Instance.Service.DoOperation($"{Module}.SideB.StopCycle"); } #endregion } }