using MECF.Framework.Common.CommonData.PUF; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.Equipment; using MECF.Framework.Common.Utilities; using Prism.Mvvm; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Threading; namespace PunkHPX8_MainPages.ViewModels { public class VPWMotionViewModel : BindableBase { #region 常量 private const string MOTION_DATA = "MotionData"; private const int ACCEL_FACTOR = 10; #endregion #region 内部变量 #region VPW1Rotation /// /// VPW1Rotation模块名称 /// private string _vPW1RotationModuleName; /// /// 数据 /// private CommandMotionData _vPW1RotationMotionData; #endregion #region VPW2Rotation /// /// VPW2Rotation模块名称 /// private string _vPW2RotationModuleName; /// /// 数据 /// private CommandMotionData _vPW2RotationMotionData; #endregion /// /// 增加 /// private double _incrementValue = 0.01; /// /// 定时器 /// DispatcherTimer _timer; /// /// RT查询key集合 /// private List _rtDataKeys = new List(); /// /// rt查询key数值字典 /// private Dictionary _rtDataValueDic = new Dictionary(); #endregion #region 属性 #region VPW1Rotation /// /// VPW1Rotation名称 /// public string VPW1RotationModuleName { get { return _vPW1RotationModuleName; } set { SetProperty(ref _vPW1RotationModuleName, value); } } /// /// /// public CommandMotionData VPW1RotationMotionData { get { return _vPW1RotationMotionData; } set { SetProperty(ref _vPW1RotationMotionData, value); } } #endregion #region VPW2Rotation /// /// VPW2Rotation /// public string VPW2RotationModuleName { get { return _vPW2RotationModuleName; } set { SetProperty(ref _vPW2RotationModuleName, value); } } /// /// /// public CommandMotionData VPW2RotationMotionData { get { return _vPW2RotationMotionData; } set { SetProperty(ref _vPW2RotationMotionData, value); } } #endregion /// /// 步进 /// public double IncrementValue { get { return _incrementValue; } set { SetProperty(ref _incrementValue, value); } } #endregion /// /// 加载数据 /// public void LoadData(string systemName) { VPW1RotationModuleName = $"{ModuleName.VpwCell1}.Rotation"; VPW2RotationModuleName = $"{ModuleName.VpwCell2}.Rotation"; _rtDataKeys.Clear(); _rtDataKeys.Add($"{VPW1RotationModuleName}.IsHomed"); _rtDataKeys.Add($"{VPW1RotationModuleName}.IsSwitchOn"); _rtDataKeys.Add($"{VPW1RotationModuleName}.{MOTION_DATA}"); _rtDataKeys.Add($"{VPW2RotationModuleName}.IsHomed"); _rtDataKeys.Add($"{VPW2RotationModuleName}.IsSwitchOn"); _rtDataKeys.Add($"{VPW2RotationModuleName}.{MOTION_DATA}"); if (_timer == null) { _timer = new DispatcherTimer(); _timer.Interval = TimeSpan.FromMilliseconds(500); _timer.Tick += Timer_Tick; } _timer.Start(); } /// /// 定时器执行 /// /// /// private void Timer_Tick(object sender, EventArgs e) { if (_rtDataKeys.Count != 0) { _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys); if (_rtDataValueDic != null) { CommandMotionData tmp1 = CommonFunction.GetValue(_rtDataValueDic, $"{VPW1RotationModuleName}.{MOTION_DATA}"); if (tmp1 != null) { tmp1.ActualVelocity = Math.Round(tmp1.ActualVelocity / 6, 2); tmp1.ProfileVelocity = Math.Round(tmp1.ProfileVelocity / 6, 2); tmp1.HomingVelocity = Math.Round(tmp1.HomingVelocity / 6, 2); tmp1.HomingVelocitySlow = Math.Round(tmp1.HomingVelocitySlow / 6, 2); tmp1.ProfileDecel = tmp1.ProfileDecel * ACCEL_FACTOR; tmp1.ProfileAccel = tmp1.ProfileAccel * ACCEL_FACTOR; } VPW1RotationMotionData = tmp1; CommandMotionData tmp2 = CommonFunction.GetValue(_rtDataValueDic, $"{VPW2RotationModuleName}.{MOTION_DATA}"); if (tmp2 != null) { tmp2.ActualVelocity = Math.Round(tmp1.ActualVelocity / 6, 2); tmp2.ProfileVelocity = Math.Round(tmp1.ProfileVelocity / 6, 2); tmp2.HomingVelocity = Math.Round(tmp1.HomingVelocity / 6, 2); tmp2.HomingVelocitySlow = Math.Round(tmp1.HomingVelocitySlow / 6, 2); tmp2.ProfileDecel = tmp1.ProfileDecel * ACCEL_FACTOR; tmp2.ProfileAccel = tmp1.ProfileAccel * ACCEL_FACTOR; } VPW2RotationMotionData = tmp2; } } } /// /// 隐藏 /// public void Hide() { _timer.Stop(); } } }