123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427 |
- 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 PlatingCellSetupViewModel : BindableBase
- {
- #region 常量
- private const string MOTION_DATA = "MotionData";
- private const string IS_SWITCH_ON = "IsSwitchOn";
- private const string CURRENT_STATION = "CurrentStation";
- #endregion
- #region 内部变量
- #region PlatingCell1_2Vertical
- /// <summary>
- /// 模块名称
- /// </summary>
- private string _platingCell1_2VerticalName;
- /// <summary>
- /// 运动数据
- /// </summary>
- private CommandMotionData _platingCell1_2VerticalMotionData;
- /// <summary>
- /// 当前位置
- /// </summary>
- private string _platingCell1_2VerticalCurrentStation;
- #endregion
- #region PlatingCell3_4Vertical
- /// <summary>
- /// 模块名称
- /// </summary>
- private string _platingCell3_4VerticalName;
- /// <summary>
- /// 运动数据
- /// </summary>
- private CommandMotionData _platingCell3_4VerticalMotionData;
- /// <summary>
- /// 当前位置
- /// </summary>
- private string _platingCell3_4VerticalCurrentStation;
- #endregion
- #region PlatingCell1Rotation
- /// <summary>
- /// 模块名称
- /// </summary>
- private string _platingCell1RotationName;
- /// <summary>
- /// 运动数据
- /// </summary>
- private CommandMotionData _platingCell1RotationMotionData;
- /// <summary>
- /// 当前位置
- /// </summary>
- private string _platingCell1RotationCurrentStation;
- #endregion
-
- #region PlatingCell2Rotation
- /// <summary>
- /// 模块名称
- /// </summary>
- private string _platingCell2RotationName;
- /// <summary>
- /// 运动数据
- /// </summary>
- private CommandMotionData _platingCell2RotationMotionData;
- /// <summary>
- /// 当前位置
- /// </summary>
- private string _platingCell2RotationCurrentStation;
- #endregion
- #region PlatingCell3Rotation
- /// <summary>
- /// 模块名称
- /// </summary>
- private string _platingCell3RotationName;
- /// <summary>
- /// 运动数据
- /// </summary>
- private CommandMotionData _platingCell3RotationMotionData;
- /// <summary>
- /// 当前位置
- /// </summary>
- private string _platingCell3RotationCurrentStation;
- #endregion
- #region PlatingCell4Rotation
- /// <summary>
- /// 模块名称
- /// </summary>
- private string _platingCell4RotationName;
- /// <summary>
- /// 运动数据
- /// </summary>
- private CommandMotionData _platingCell4RotationMotionData;
- /// <summary>
- /// 当前位置
- /// </summary>
- private string _platingCell4RotationCurrentStation;
- #endregion
- #endregion
- #region 系统数据
- /// <summary>
- /// 定时器
- /// </summary>
- DispatcherTimer _timer;
- /// <summary>
- /// 查询后台数据集合
- /// </summary>
- private List<string> _rtDataKeys = new List<string>();
- /// <summary>
- /// rt查询key数值字典
- /// </summary>
- private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
- #endregion
- #region 属性
- #region PlatingCell1_2Vertical
- /// <summary>
- ///名称
- /// </summary>
- public string PlatingCell1_2VerticalName
- {
- get { return _platingCell1_2VerticalName; }
- set { SetProperty(ref _platingCell1_2VerticalName, value); }
- }
- /// <summary>
- /// 运动数据
- /// </summary>
- public CommandMotionData PlatingCell1_2VerticalMotionData
- {
- get { return _platingCell1_2VerticalMotionData; }
- set { SetProperty(ref _platingCell1_2VerticalMotionData, value); }
- }
- /// <summary>
- ///当前位置
- /// </summary>
- public string PlatingCell1_2VerticalCurrentStation
- {
- get { return _platingCell1_2VerticalCurrentStation; }
- set { SetProperty(ref _platingCell1_2VerticalCurrentStation, value); }
- }
- #endregion
- #region PlatingCell3_4Vertical
- /// <summary>
- ///名称
- /// </summary>
- public string PlatingCell3_4VerticalName
- {
- get { return _platingCell3_4VerticalName; }
- set { SetProperty(ref _platingCell3_4VerticalName, value); }
- }
- /// <summary>
- /// 运动数据
- /// </summary>
- public CommandMotionData PlatingCell3_4VerticalMotionData
- {
- get { return _platingCell3_4VerticalMotionData; }
- set { SetProperty(ref _platingCell3_4VerticalMotionData, value); }
- }
- /// <summary>
- /// 当前位置
- /// </summary>
- public string PlatingCell3_4VerticalCurrentStation
- {
- get { return _platingCell3_4VerticalCurrentStation; }
- set { SetProperty(ref _platingCell3_4VerticalCurrentStation, value); }
- }
- #endregion
- #region PlatingCell1Rotation
- /// <summary>
- ///名称
- /// </summary>
- public string PlatingCell1RotationName
- {
- get { return _platingCell1RotationName; }
- set { SetProperty(ref _platingCell1RotationName, value); }
- }
- /// <summary>
- /// 运动数据
- /// </summary>
- public CommandMotionData PlatingCell1RotationMotionData
- {
- get { return _platingCell1RotationMotionData; }
- set { SetProperty(ref _platingCell1RotationMotionData, value); }
- }
- /// <summary>
- /// 当前位置
- /// </summary>
- public string PlatingCell1RotationCurrentStation
- {
- get { return _platingCell1RotationCurrentStation; }
- set { SetProperty(ref _platingCell1RotationCurrentStation, value); }
- }
- #endregion
- #region PlatingCell2Rotation
- /// <summary>
- ///名称
- /// </summary>
- public string PlatingCell2RotationName
- {
- get { return _platingCell2RotationName; }
- set { SetProperty(ref _platingCell2RotationName, value); }
- }
- /// <summary>
- /// 运动数据
- /// </summary>
- public CommandMotionData PlatingCell2RotationMotionData
- {
- get { return _platingCell2RotationMotionData; }
- set { SetProperty(ref _platingCell2RotationMotionData, value); }
- }
- /// <summary>
- /// 当前位置
- /// </summary>
- public string PlatingCell2RotationCurrentStation
- {
- get { return _platingCell2RotationCurrentStation; }
- set { SetProperty(ref _platingCell2RotationCurrentStation, value); }
- }
- #endregion
- #region PlatingCell3Rotation
- /// <summary>
- ///名称
- /// </summary>
- public string PlatingCell3RotationName
- {
- get { return _platingCell3RotationName; }
- set { SetProperty(ref _platingCell3RotationName, value); }
- }
- /// <summary>
- /// 运动数据
- /// </summary>
- public CommandMotionData PlatingCell3RotationMotionData
- {
- get { return _platingCell3RotationMotionData; }
- set { SetProperty(ref _platingCell3RotationMotionData, value); }
- }
- /// <summary>
- /// 当前位置
- /// </summary>
- public string PlatingCell3RotationCurrentStation
- {
- get { return _platingCell3RotationCurrentStation; }
- set { SetProperty(ref _platingCell3RotationCurrentStation, value); }
- }
- #endregion
- #region PlatingCell4Rotation
- /// <summary>
- ///名称
- /// </summary>
- public string PlatingCell4RotationName
- {
- get { return _platingCell4RotationName; }
- set { SetProperty(ref _platingCell4RotationName, value); }
- }
- /// <summary>
- /// 运动数据
- /// </summary>
- public CommandMotionData PlatingCell4RotationMotionData
- {
- get { return _platingCell4RotationMotionData; }
- set { SetProperty(ref _platingCell4RotationMotionData, value); }
- }
- /// <summary>
- /// 当前位置
- /// </summary>
- public string PlatingCell4RotationCurrentStation
- {
- get { return _platingCell4RotationCurrentStation; }
- set { SetProperty(ref _platingCell4RotationCurrentStation, value); }
- }
- #endregion
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- public PlatingCellSetupViewModel()
- {
- }
- /// <summary>
- /// 加载数据
- /// </summary>
- public void LoadData(string systemName)
- {
- PlatingCell1_2VerticalName = $"PlatingCell1_2.Vertical";
- PlatingCell3_4VerticalName = $"PlatingCell3_4.Vertical";
-
- PlatingCell1RotationName = $"PlatingCell1.Rotation";
- PlatingCell2RotationName = $"PlatingCell2.Rotation";
- PlatingCell3RotationName = $"PlatingCell3.Rotation";
- PlatingCell4RotationName = $"PlatingCell4.Rotation";
- AddDataKeys();
- if (_timer == null)
- {
- _timer = new DispatcherTimer();
- _timer.Interval = TimeSpan.FromMilliseconds(200);
- _timer.Tick += Timer_Tick;
- }
- _timer.Start();
- }
- /// <summary>
- /// 定时器执行
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Timer_Tick(object sender, EventArgs e)
- {
- OnTimer();
- }
- /// <summary>
- /// 隐藏
- /// </summary>
- public void Hide()
- {
- if (_timer != null)
- {
- _timer.Stop();
- }
- }
- /// <summary>
- /// 初始化查询数据集合
- /// </summary>
- private void AddDataKeys()
- {
- _rtDataKeys.Clear();
- _rtDataKeys.Add($"{PlatingCell1_2VerticalName}.{MOTION_DATA}");
- _rtDataKeys.Add($"{PlatingCell1_2VerticalName}.{IS_SWITCH_ON}");
- _rtDataKeys.Add($"{PlatingCell1_2VerticalName}.{CURRENT_STATION}");
- _rtDataKeys.Add($"{PlatingCell3_4VerticalName}.{MOTION_DATA}");
- _rtDataKeys.Add($"{PlatingCell3_4VerticalName}.{IS_SWITCH_ON}");
- _rtDataKeys.Add($"{PlatingCell3_4VerticalName}.{CURRENT_STATION}");
- _rtDataKeys.Add($"{PlatingCell1RotationName}.{MOTION_DATA}");
- _rtDataKeys.Add($"{PlatingCell1RotationName}.{IS_SWITCH_ON}");
- _rtDataKeys.Add($"{PlatingCell1RotationName}.{CURRENT_STATION}");
- _rtDataKeys.Add($"{PlatingCell2RotationName}.{MOTION_DATA}");
- _rtDataKeys.Add($"{PlatingCell2RotationName}.{IS_SWITCH_ON}");
- _rtDataKeys.Add($"{PlatingCell2RotationName}.{CURRENT_STATION}");
- _rtDataKeys.Add($"{PlatingCell3RotationName}.{MOTION_DATA}");
- _rtDataKeys.Add($"{PlatingCell3RotationName}.{IS_SWITCH_ON}");
- _rtDataKeys.Add($"{PlatingCell3RotationName}.{CURRENT_STATION}");
- _rtDataKeys.Add($"{PlatingCell4RotationName}.{MOTION_DATA}");
- _rtDataKeys.Add($"{PlatingCell4RotationName}.{IS_SWITCH_ON}");
- _rtDataKeys.Add($"{PlatingCell4RotationName}.{CURRENT_STATION}");
- }
- /// <summary>
- /// 定时器
- /// </summary>
- /// <returns></returns>
- private Boolean OnTimer()
- {
- if (_rtDataKeys.Count != 0)
- {
- _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
- if (_rtDataValueDic != null)
- {
- PlatingCell1_2VerticalMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{PlatingCell1_2VerticalName}.{MOTION_DATA}");
- PlatingCell1_2VerticalCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{PlatingCell1_2VerticalName}.{CURRENT_STATION}"), PlatingCell1_2VerticalName);
- PlatingCell3_4VerticalMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{PlatingCell3_4VerticalName}.{MOTION_DATA}");
- PlatingCell3_4VerticalCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{PlatingCell3_4VerticalName}.{CURRENT_STATION}"), PlatingCell3_4VerticalName);
- PlatingCell1RotationMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{PlatingCell1RotationName}.{MOTION_DATA}");
- PlatingCell1RotationCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{PlatingCell1RotationName}.{CURRENT_STATION}"), PlatingCell1RotationName);
- PlatingCell2RotationMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{PlatingCell2RotationName}.{MOTION_DATA}");
- PlatingCell2RotationCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{PlatingCell2RotationName}.{CURRENT_STATION}"), PlatingCell2RotationName);
- PlatingCell3RotationMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{PlatingCell3RotationName}.{MOTION_DATA}");
- PlatingCell3RotationCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{PlatingCell3RotationName}.{CURRENT_STATION}"), PlatingCell3RotationName);
- PlatingCell3RotationMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{PlatingCell4RotationName}.{MOTION_DATA}");
- PlatingCell3RotationCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{PlatingCell4RotationName}.{CURRENT_STATION}"), PlatingCell4RotationName);
- }
- }
- return true;
- }
- }
- }
|