using MECF.Framework.Common.CommonData.PowerSupplier;
using MECF.Framework.Common.CommonData.PUF;
using MECF.Framework.Common.DataCenter;
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 PlatingCellMotionViewModel : BindableBase
{
#region 常量
private const string MOTION_DATA = "MotionData";
#endregion
#region 内部变量
///
/// 模块名称
///
private string _module = "";
///
/// 增加
///
private double _incrementValue = 0.01;
///
/// 定时器
///
private DispatcherTimer _timer;
///
/// RT查询key集合
///
private List _rtDataKeys = new List();
///
/// rt查询key数值字典
///
private Dictionary _rtDataValueDic = new Dictionary();
#region PlatingCell1_2Vertical
///
/// PlatingCell1_2Vertical moduleName
///
private string _platingCell1_2VerticalName;
///
/// PlatingCell1_2Vertical 数据
///
private CommandMotionData _platingCell1_2VerticalMotionData;
#endregion
#region PlatingCell3_4Vertical
///
/// PlatingCell3_4Vertical moduleName
///
private string _platingCell3_4VerticalName;
///
/// PlatingCell3_4Vertical 数据
///
private CommandMotionData _platingCell3_4VerticalMotionData;
#endregion
#region PlatingCell1Rotation
///
/// PlatingCell1Rotation moduleName
///
private string _platingCell1RotationName;
///
/// PlatingCell1Rotation 数据
///
private CommandMotionData _platingCell1RotationMotionData;
#endregion
#region PlatingCell2Rotation
///
/// PlatingCell2Rotation moduleName
///
private string _platingCell2RotationName;
///
/// PlatingCell2Rotation 数据
///
private CommandMotionData _platingCell2RotationMotionData;
#endregion
#region PlatingCell3Rotation
///
/// PlatingCell3Rotation moduleName
///
private string _platingCell3RotationName;
///
/// PlatingCell1Rotation 数据
///
private CommandMotionData _platingCell3RotationMotionData;
#region PlatingCell4Rotation
///
/// PlatingCell1Rotation moduleName
///
private string _platingCell4RotationName;
///
/// PlatingCell1Rotation 数据
///
private CommandMotionData _platingCell4RotationMotionData;
#endregion
#endregion
#endregion
#region 属性
///
/// 模块名称
///
public string Module
{
get { return _module; }
set { SetProperty(ref _module, value); }
}
///
/// 步进
///
public double IncrementValue
{
get { return _incrementValue; }
set { SetProperty(ref _incrementValue, value); }
}
#region PlatingCell1_2 Vertical
///
/// ModuleName
///
public string PlatingCell1_2VerticalName { get { return _platingCell1_2VerticalName; } set { SetProperty(ref _platingCell1_2VerticalName, value); } }
///
/// 数据
///
public CommandMotionData PlatingCell1_2VerticalMotionData { get { return _platingCell1_2VerticalMotionData; } set { SetProperty(ref _platingCell1_2VerticalMotionData, value); } }
#endregion
#region PlatingCell3_4 Vertical
///
/// ModuleName
///
public string PlatingCell3_4VerticalName { get { return _platingCell3_4VerticalName; } set { SetProperty(ref _platingCell3_4VerticalName, value); } }
///
/// 数据
///
public CommandMotionData PlatingCell3_4VerticalMotionData { get { return _platingCell3_4VerticalMotionData; } set { SetProperty(ref _platingCell3_4VerticalMotionData, value); } }
#endregion
#region PlatingCell1Rotaiton
///
/// ModuleName
///
public string PlatingCell1RotationName { get { return _platingCell1RotationName; } set { SetProperty(ref _platingCell1RotationName, value); } }
///
/// 数据
///
public CommandMotionData PlatingCell1RotationMotionData { get { return _platingCell1RotationMotionData; } set { SetProperty(ref _platingCell1RotationMotionData, value); } }
#endregion
#region PlatingCell2Rotaiton
///
/// ModuleName
///
public string PlatingCell2RotationName { get { return _platingCell2RotationName; } set { SetProperty(ref _platingCell2RotationName, value); } }
///
/// 数据
///
public CommandMotionData PlatingCell2RotationMotionData { get { return _platingCell2RotationMotionData; } set { SetProperty(ref _platingCell2RotationMotionData, value); } }
#endregion
#region PlatingCell3Rotaiton
///
/// ModuleName
///
public string PlatingCell3RotationName { get { return _platingCell3RotationName; } set { SetProperty(ref _platingCell3RotationName, value); } }
///
/// 数据
///
public CommandMotionData PlatingCell3RotationMotionData { get { return _platingCell3RotationMotionData; } set { SetProperty(ref _platingCell3RotationMotionData, value); } }
#endregion
#region PlatingCell4Rotaiton
///
/// ModuleName
///
public string PlatingCell4RotationName { get { return _platingCell4RotationName; } set { SetProperty(ref _platingCell4RotationName, value); } }
///
/// 数据
///
public CommandMotionData PlatingCell4RotationMotionData { get { return _platingCell4RotationMotionData; } set { SetProperty(ref _platingCell4RotationMotionData, value); } }
#endregion
#endregion
///
/// 构造函数
///
public PlatingCellMotionViewModel()
{
}
///
/// 加载数据
///
public void LoadData(string systemName)
{
Module = systemName;
PlatingCell1_2VerticalName = $"PlatingCell1_2.Vertical";
PlatingCell3_4VerticalName = $"PlatingCell3_4.Vertical";
PlatingCell1RotationName = "PlatingCell1.Rotation";
PlatingCell2RotationName = "PlatingCell2.Rotation";
PlatingCell3RotationName = "PlatingCell3.Rotation";
PlatingCell4RotationName = "PlatingCell4.Rotation";
_rtDataKeys.Clear();
_rtDataKeys.Add($"{PlatingCell1_2VerticalName}.IsHomed");
_rtDataKeys.Add($"{PlatingCell1_2VerticalName}.IsSwitchOn");
_rtDataKeys.Add($"{PlatingCell1_2VerticalName}.{MOTION_DATA}");
_rtDataKeys.Add($"{PlatingCell3_4VerticalName}.IsHomed");
_rtDataKeys.Add($"{PlatingCell3_4VerticalName}.IsSwitchOn");
_rtDataKeys.Add($"{PlatingCell3_4VerticalName}.{MOTION_DATA}");
_rtDataKeys.Add($"{PlatingCell1RotationName}.IsHomed");
_rtDataKeys.Add($"{PlatingCell1RotationName}.IsSwitchOn");
_rtDataKeys.Add($"{PlatingCell1RotationName}.{MOTION_DATA}");
_rtDataKeys.Add($"{PlatingCell2RotationName}.IsHomed");
_rtDataKeys.Add($"{PlatingCell2RotationName}.IsSwitchOn");
_rtDataKeys.Add($"{PlatingCell2RotationName}.{MOTION_DATA}");
_rtDataKeys.Add($"{PlatingCell3RotationName}.IsHomed");
_rtDataKeys.Add($"{PlatingCell3RotationName}.IsSwitchOn");
_rtDataKeys.Add($"{PlatingCell3RotationName}.{MOTION_DATA}");
_rtDataKeys.Add($"{PlatingCell4RotationName}.IsHomed");
_rtDataKeys.Add($"{PlatingCell4RotationName}.IsSwitchOn");
_rtDataKeys.Add($"{PlatingCell4RotationName}.{MOTION_DATA}");
if (_timer == null)
{
_timer = new DispatcherTimer();
_timer.Interval = TimeSpan.FromMilliseconds(100);
_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)
{
PlatingCell1_2VerticalMotionData = CommonFunction.GetValue(_rtDataValueDic, $"{PlatingCell1_2VerticalName}.{MOTION_DATA}");
PlatingCell3_4VerticalMotionData = CommonFunction.GetValue(_rtDataValueDic, $"{PlatingCell3_4VerticalName}.{MOTION_DATA}");
PlatingCell1RotationMotionData = CommonFunction.GetValue(_rtDataValueDic, $"{PlatingCell1RotationName}.{MOTION_DATA}");
PlatingCell2RotationMotionData = CommonFunction.GetValue(_rtDataValueDic, $"{PlatingCell2RotationName}.{MOTION_DATA}");
PlatingCell3RotationMotionData = CommonFunction.GetValue(_rtDataValueDic, $"{PlatingCell3RotationName}.{MOTION_DATA}");
PlatingCell4RotationMotionData = CommonFunction.GetValue(_rtDataValueDic, $"{PlatingCell4RotationName}.{MOTION_DATA}");
}
}
}
///
/// 隐藏
///
public void Hide()
{
if (_timer != null)
{
_timer.Stop();
}
}
}
}