123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using Aitex.Core.Common;
- using LiveCharts;
- using System.Windows;
- using MECF.Framework.Common.CommonData.PUF;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.Common.Equipment;
- using Prism.Mvvm;
- using System.Timers;
- using Aitex.Core.RT.DataCenter;
- using MECF.Framework.Common.Utilities;
- using MECF.Framework.Common.CommonData.Loader;
- using MECF.Framework.Common.OperationCenter;
- using Aitex.Core.Utilities;
- using System.Windows.Input;
- using Aitex.Core.UI.MVVM;
- using System.Windows.Threading;
- namespace CyberX8_MainPages.ViewModels
- {
- public class SRDStationSetupViewModel:BindableBase
- {
- #region 常量
- private const string MOTION_DATA = "MotionData";
- private const string IS_SWITCH_ON = "IsSwitchOn";
- private const string CURRENT_STATION = "CurrentStation";
- #endregion
- #region 内部变量
- #region SRD1Arm
- /// <summary>
- /// sRD1Arm模块名称
- /// </summary>
- private string _sRD1ArmModuleName;
- /// <summary>
- /// sRD1Arm运动数据
- /// </summary>
- private CommandMotionData _sRD1ArmMotionData;
- /// <summary>
- /// sRD1Arm当前位置
- /// </summary>
- private string _sRD1ArmCurrentStation;
- #endregion
- #region SRD1Rotation
- /// <summary>
- /// sRD1Rotation模块名称
- /// </summary>
- private string _sRD1RotationModuleName;
- /// <summary>
- /// sRD1Rotation运动数据
- /// </summary>
- private CommandMotionData _sRD1RotationMotionData;
- /// <summary>
- /// sRD1Rotation当前位置
- /// </summary>
- private string _sRD1RotationCurrentStation;
- #endregion
- #region SRD2Arm
- /// <summary>
- /// sRD2Arm模块名称
- /// </summary>
- private string _sRD2ArmModuleName;
- /// <summary>
- /// sRD2Arm运动数据
- /// </summary>
- private CommandMotionData _sRD2ArmMotionData;
- /// <summary>
- /// sRD2Arm当前位置
- /// </summary>
- private string _sRD2ArmCurrentStation;
- #endregion
- #region SRD2Rotation
- /// <summary>
- /// sRD2Rotation模块名称
- /// </summary>
- private string _sRD2RotationModuleName;
- /// <summary>
- /// sRD2Rotation运动数据
- /// </summary>
- private CommandMotionData _sRD2RotationMotionData;
- /// <summary>
- /// sRD2Rotation当前位置
- /// </summary>
- private string _sRD2RotationCurrentStation;
- #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 AWC
- /// <summary>
- /// AWC ModuleName
- /// </summary>
- private ModuleName _awcModuleName;
- /// <summary>
- /// Is AWC Cycle runnning
- /// </summary>
- private bool _isAWCCycling;
- #endregion
- #endregion
- #region 属性
- #region SRD1Arm
- /// <summary>
- /// SRD1Arm名称
- /// </summary>
- public string SRD1ArmModuleName
- {
- get { return _sRD1ArmModuleName; }
- set { SetProperty(ref _sRD1ArmModuleName, value); }
- }
- /// <summary>
- /// SRD1Arm运动数据
- /// </summary>
- public CommandMotionData SRD1ArmMotionData
- {
- get { return _sRD1ArmMotionData; }
- set { SetProperty(ref _sRD1ArmMotionData, value); }
- }
- /// <summary>
- /// SRD1Arm当前位置
- /// </summary>
- public string SRD1ArmCurrentStation
- {
- get { return _sRD1ArmCurrentStation; }
- set { SetProperty(ref _sRD1ArmCurrentStation, value); }
- }
- #endregion
- #region SRD1Rotation
- /// <summary>
- /// SRD1Rotation名称
- /// </summary>
- public string SRD1RotationModuleName
- {
- get { return _sRD1RotationModuleName; }
- set { SetProperty(ref _sRD1RotationModuleName, value); }
- }
- /// <summary>
- /// SRD1Rotation运动数据
- /// </summary>
- public CommandMotionData SRD1RotationMotionData
- {
- get { return _sRD1RotationMotionData; }
- set { SetProperty(ref _sRD1RotationMotionData, value); }
- }
- /// <summary>
- /// SRD1Rotation当前位置
- /// </summary>
- public string SRD1RotationCurrentStation
- {
- get { return _sRD1RotationCurrentStation; }
- set { SetProperty(ref _sRD1RotationCurrentStation, value); }
- }
- #endregion
- #region SRD2Arm
- /// <summary>
- /// SRD2Arm名称
- /// </summary>
- public string SRD2ArmModuleName
- {
- get { return _sRD2ArmModuleName; }
- set { SetProperty(ref _sRD2ArmModuleName, value); }
- }
- /// <summary>
- /// SRD2Arm运动数据
- /// </summary>
- public CommandMotionData SRD2ArmMotionData
- {
- get { return _sRD2ArmMotionData; }
- set { SetProperty(ref _sRD2ArmMotionData, value); }
- }
- /// <summary>
- /// SRD2Arm当前位置
- /// </summary>
- public string SRD2ArmCurrentStation
- {
- get { return _sRD2ArmCurrentStation; }
- set { SetProperty(ref _sRD2ArmCurrentStation, value); }
- }
- #endregion
- #region SRD2Rotation
- /// <summary>
- /// SRD2Rotation名称
- /// </summary>
- public string SRD2RotationModuleName
- {
- get { return _sRD2RotationModuleName; }
- set { SetProperty(ref _sRD2RotationModuleName, value); }
- }
- /// <summary>
- /// SRD1Rotation运动数据
- /// </summary>
- public CommandMotionData SRD2RotationMotionData
- {
- get { return _sRD2RotationMotionData; }
- set { SetProperty(ref _sRD2RotationMotionData, value); }
- }
- /// <summary>
- /// SRD2Rotation当前位置
- /// </summary>
- public string SRD2RotationCurrentStation
- {
- get { return _sRD2RotationCurrentStation; }
- set { SetProperty(ref _sRD2RotationCurrentStation, value); }
- }
- #endregion
- #region AWC
- /// <summary>
- /// AWC ModuleName
- /// </summary>
- public ModuleName AWCModuleName
- {
- get { return _awcModuleName; }
- set { SetProperty(ref _awcModuleName, value); }
- }
- /// <summary>
- /// Is AWC Cycle runnning
- /// </summary>
- public bool IsAWCCycling
- {
- get { return _isAWCCycling; }
- set { SetProperty(ref _isAWCCycling, value); }
- }
- #endregion
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- public SRDStationSetupViewModel()
- {
- }
- /// <summary>
- /// 加载数据
- /// </summary>
- public void LoadData(string systemName)
- {
- SRD1ArmModuleName = $"{ModuleName.SRD1}.Arm";
- SRD1RotationModuleName = $"{ModuleName.SRD1}.Rotation";
- SRD2ArmModuleName = $"{ModuleName.SRD2}.Arm";
- SRD2RotationModuleName = $"{ModuleName.SRD2}.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($"{SRD1ArmModuleName}.{MOTION_DATA}");
- _rtDataKeys.Add($"{SRD1ArmModuleName}.{IS_SWITCH_ON}");
- _rtDataKeys.Add($"{SRD1ArmModuleName}.{CURRENT_STATION}");
- _rtDataKeys.Add($"{SRD2ArmModuleName}.{MOTION_DATA}");
- _rtDataKeys.Add($"{SRD2ArmModuleName}.{IS_SWITCH_ON}");
- _rtDataKeys.Add($"{SRD2ArmModuleName}.{CURRENT_STATION}");
- _rtDataKeys.Add($"{SRD1RotationModuleName}.{MOTION_DATA}");
- _rtDataKeys.Add($"{SRD1RotationModuleName}.{IS_SWITCH_ON}");
- _rtDataKeys.Add($"{SRD1RotationModuleName}.{CURRENT_STATION}");
- _rtDataKeys.Add($"{SRD2RotationModuleName}.{MOTION_DATA}");
- _rtDataKeys.Add($"{SRD2RotationModuleName}.{IS_SWITCH_ON}");
- _rtDataKeys.Add($"{SRD2RotationModuleName}.{CURRENT_STATION}");
- _rtDataKeys.Add($"{SRD2RotationModuleName}.{CURRENT_STATION}");
- _rtDataKeys.Add($"SRD1.IsAWCCycling");
- _rtDataKeys.Add($"SRD2.IsAWCCycling");
- }
- /// <summary>
- /// 定时器
- /// </summary>
- /// <returns></returns>
- private Boolean OnTimer()
- {
- if(_rtDataKeys.Count != 0)
- {
- _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
- if (_rtDataValueDic != null)
- {
- SRD1ArmMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{SRD1ArmModuleName}.{MOTION_DATA}");
- SRD1ArmCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{SRD1ArmModuleName}.{CURRENT_STATION}"), SRD1ArmModuleName);
- SRD2ArmMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{SRD2ArmModuleName}.{MOTION_DATA}");
- SRD2ArmCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{SRD2ArmModuleName}.{CURRENT_STATION}"), SRD2ArmModuleName);
- SRD1RotationMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{SRD1RotationModuleName}.{MOTION_DATA}");
- SRD1RotationCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{SRD1RotationModuleName}.{CURRENT_STATION}"), SRD1RotationModuleName);
- SRD2RotationMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{SRD2RotationModuleName}.{MOTION_DATA}");
- SRD2RotationCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{SRD2RotationModuleName}.{CURRENT_STATION}"), SRD2RotationModuleName);
- //判断AWC是否在running
- if(AWCModuleName == ModuleName.SRD1)
- {
- IsAWCCycling = CommonFunction.GetValue<bool>(_rtDataValueDic, $"SRD1.IsAWCCycling"); ;
- }else if(AWCModuleName == ModuleName.SRD2)
- {
- IsAWCCycling = CommonFunction.GetValue<bool>(_rtDataValueDic, $"SRD2.IsAWCCycling"); ;
- }
- else
- {
- IsAWCCycling = false;
- }
- }
- }
- return true;
- }
- }
- }
|