123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- using Aitex.Core.UI.MVVM;
- using Aitex.Core.Util;
- using Aitex.Core.Utilities;
- using ExcelLibrary.BinaryFileFormat;
- using MECF.Framework.Common.Beckhoff.AxisProvider;
- using MECF.Framework.Common.Beckhoff.IOAxis;
- using MECF.Framework.Common.CommonData.PUF;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.Common.OperationCenter;
- using MECF.Framework.Common.Utilities;
- using CyberX8_Core;
- using CyberX8_MainPages.Model;
- using CyberX8_MainPages.Unity;
- using Prism.Mvvm;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using System.Timers;
- using System.Windows.Input;
- using System.Windows.Threading;
- namespace CyberX8_MainPages.ViewModels
- {
- public class PufMotionViewModel : BindableBase
- {
- #region 常量
- private const string MOTION_DATA = "MotionData";
- #endregion
- #region 内部变量
- #region flip
- /// <summary>
- /// flip模块名称
- /// </summary>
- private string _flipModuleName;
- /// <summary>
- /// 数据
- /// </summary>
- private CommandMotionData _flipMotionData;
- #endregion
- #region rotation
- /// <summary>
- /// rotation模块名称
- /// </summary>
- private string _rotationModuleName;
- /// <summary>
- ///
- /// </summary>
- private CommandMotionData _rotationMotionData;
- #endregion
- #region Vertical
- /// <summary>
- /// vertical模块名称
- /// </summary>
- private string _verticalModuleName;
- /// <summary>
- ///
- /// </summary>
- private CommandMotionData _verticalMotionData;
- #endregion
- /// <summary>
- /// 模块名称
- /// </summary>
- private string _module = "";
- /// <summary>
- /// 增加
- /// </summary>
- private double _incrementValue = 0.01;
- /// <summary>
- ///
- /// </summary>
- private PufDistanceData _distanceData;
- /// <summary>
- /// 定时器
- /// </summary>
- DispatcherTimer _timer;
- /// <summary>
- /// RT查询key集合
- /// </summary>
- private List<string> _rtDataKeys = new List<string>();
- /// <summary>
- /// rt查询key数值字典
- /// </summary>
- private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
- #endregion
- #region 属性
- #region Flip
- /// <summary>
- /// Filp名称
- /// </summary>
- public string FlipModuleName
- {
- get { return _flipModuleName; }
- set { SetProperty(ref _flipModuleName, value); }
- }
- /// <summary>
- ///
- /// </summary>
- public CommandMotionData FlipMotionData
- {
- get { return _flipMotionData; }
- set { SetProperty(ref _flipMotionData, value); }
- }
- #endregion
- #region Rotation
- /// <summary>
- /// Rotate名称
- /// </summary>
- public string RotationModuleName
- {
- get { return _rotationModuleName; }
- set { SetProperty(ref _rotationModuleName, value); }
- }
- public CommandMotionData RotationMotionData
- {
- get { return _rotationMotionData; }
- set { SetProperty(ref _rotationMotionData, value); }
- }
- #endregion
- #region Vertical
- /// <summary>
- /// Vertical名称
- /// </summary>
- public string VerticalModuleName
- {
- get { return _verticalModuleName; }
- set { SetProperty(ref _verticalModuleName, value); }
- }
- /// <summary>
- ///
- /// </summary>
- public CommandMotionData VerticalMotionData
- {
- get { return _verticalMotionData; }
- set { SetProperty(ref _verticalMotionData, value); }
- }
- #endregion
- /// <summary>
- /// 模块名称
- /// </summary>
- public string Module
- {
- get { return _module; }
- set { SetProperty(ref _module, value); }
- }
- /// <summary>
- /// 步进
- /// </summary>
- public double IncrementValue
- {
- get { return _incrementValue; }
- set { SetProperty(ref _incrementValue, value); }
- }
- public PufDistanceData DistanceData
- {
- get { return _distanceData; }
- set { SetProperty(ref _distanceData, value); }
- }
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- public PufMotionViewModel()
- {
- IncrementValue = (double)QueryDataClient.Instance.Service.GetConfig("System.Increment");
- FlipMotionData = new CommandMotionData();
- RotationMotionData = new CommandMotionData();
- VerticalMotionData = new CommandMotionData();
- }
- /// <summary>
- /// 加载数据
- /// </summary>
- public void LoadData(string systemName)
- {
- Module = systemName;
- FlipModuleName = $"{Module}.Flip";
- RotationModuleName = $"{Module}.Rotation";
- VerticalModuleName = $"{Module}.Vertical";
- _rtDataKeys.Clear();
- _rtDataKeys.Add($"{FlipModuleName}.IsHomed");
- _rtDataKeys.Add($"{FlipModuleName}.IsSwitchOn");
- _rtDataKeys.Add($"{FlipModuleName}.{MOTION_DATA}");
- _rtDataKeys.Add($"{RotationModuleName}.IsHomed");
- _rtDataKeys.Add($"{RotationModuleName}.IsSwitchOn");
- _rtDataKeys.Add($"{RotationModuleName}.{MOTION_DATA}");
- _rtDataKeys.Add($"{VerticalModuleName}.IsHomed");
- _rtDataKeys.Add($"{VerticalModuleName}.IsSwitchOn");
- _rtDataKeys.Add($"{VerticalModuleName}.{MOTION_DATA}");
- if (_timer == null)
- {
- _timer = new DispatcherTimer();
- _timer.Interval = TimeSpan.FromMilliseconds(100);
- _timer.Tick += Timer_Tick; ;
- }
- _timer.Start();
- }
- /// <summary>
- /// 定时器执行
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Timer_Tick(object sender, EventArgs e)
- {
- if (_rtDataKeys.Count != 0)
- {
- _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
- if (_rtDataValueDic != null)
- {
- FlipMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{FlipModuleName}.{MOTION_DATA}");
- RotationMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{RotationModuleName}.{MOTION_DATA}");
- VerticalMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{VerticalModuleName}.{MOTION_DATA}");
- }
- }
- }
- /// <summary>
- /// 隐藏
- /// </summary>
- public void Hide()
- {
- _timer.Stop();
- }
- }
- }
|