123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- using Aitex.Core.Common;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.Log;
- using Aitex.Core.UI.Dialog;
- using Aitex.Core.UI.MVVM;
- using Aitex.Core.Util;
- using Aitex.Core.Utilities;
- using Caliburn.Micro.Core;
- using MECF.Framework.Common.CommonData.PUF;
- using MECF.Framework.Common.CommonData.Transporter;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.Layout;
- using MECF.Framework.Common.RecipeCenter;
- using MECF.Framework.Common.Utilities;
- using CyberX8_Core;
- using CyberX8_MainPages.PMs;
- using CyberX8_Themes.UserControls;
- using Prism.Mvvm;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- using System.Timers;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using System.Windows.Threading;
- namespace CyberX8_MainPages.ViewModels
- {
- public class TransporterTeachViewModel : BindableBase
- {
- #region 常量
- private const string MOTOR_POSITION = "MotorPosition";
- private const string IS_SWITCH_ON = "IsSwitchOn";
- private const string IS_HOMED = "IsHomed";
- private const string IS_MOVING = "IsMoving";
- private const string CURRENT_STATION = "CurrentStation";
- private const string TRANSPORTER_DATA = "TransporterData";
- private const string MOTION_DATA = "MotionData";
- #endregion
- #region 内部变量
- private string _module;
- #region Gantry
- private string _gantryModuleName;
- private double _gantryMotionPosition;
- private string _gantryCurrentStation;
- private string _gantryCurrentCellName;
- private bool _gantryIsHomed;
- private bool _gantryIsMoving;
- private bool _gantryIsSwitchOn;
- private bool _gantryTorqueLimited;
- private CommandMotionData _gantryMotionData;
- #endregion
- #region Elevator
- private string _elevatorModuleName;
- private double _elevatorMotionPosition;
- private string _elevatorCurrentStation;
- private string _elevatorCurrentCellName;
- private bool _elevatorIsHomed;
- private bool _elevatorIsMoving;
- private bool _elevatorIsSwitchOn;
- private bool _elevatorTorqueLimited;
- private bool _elevatorIsInUpPlace;
- private CommandMotionData _elevatorMotionData;
- #endregion
- private TransporterData _transporterData;
- private bool _locked;
- private bool _unlocked;
- private bool _clamped;
- private bool _unclamped;
- private List<string> _teachPositionList=new List<string>();
- private ProcessLayout _processLayout;
- /// <summary>
- /// 名称与Cell字典(key-Cell Id,value-cell 名称)
- /// </summary>
- private Dictionary<string, string> _cellIdCellNameDic = new Dictionary<string, string>();
- /// RT查询key集合
- /// </summary>
- private List<string> _rtDataKeys = new List<string>();
- /// <summary>
- /// rt查询key数值字典
- /// </summary>
- private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
- /// <summary>
- /// 定时器
- /// </summary>
- private DispatcherTimer _timer;
- #endregion
- #region 属性
- public string Module { get { return _module; } set { SetProperty(ref _module, value); } }
- public List<string> TeachPositionList { get { return _teachPositionList; } set { SetProperty(ref _teachPositionList, value); } }
- public bool Locked { get { return _locked; } set { SetProperty(ref _locked, value); } }
- public bool Unlocked { get { return _unlocked; } set { SetProperty(ref _unlocked, value); } }
- public bool Clamped { get { return _clamped; } set { SetProperty(ref _clamped, value); } }
- public bool Unclamped { get { return _unclamped; } set { SetProperty(ref _unclamped, value); } }
- #region Gantry
- /// <summary>
- /// Gantry 模块名称
- /// </summary>
- public string GantryModuleName { get { return _gantryModuleName; } set { SetProperty(ref _gantryModuleName, value); } }
- /// <summary>
- /// Gantry Motion Position
- /// </summary>
- public double GantryMotionPosition{ get { return _gantryMotionPosition; } set { SetProperty(ref _gantryMotionPosition, value); } }
- /// <summary>
- /// Gantry当前位置
- /// </summary>
- public string GantryCurrentStation{ get { return _gantryCurrentStation; } set { SetProperty(ref _gantryCurrentStation, value); } }
- /// <summary>
- /// Gantry 当前Cell名称
- /// </summary>
- public string GantryCurrentCellName { get { return _gantryCurrentCellName; } set { SetProperty(ref _gantryCurrentCellName, value); } }
- public bool GantryIsHomed { get { return _gantryIsHomed; } set { SetProperty(ref _gantryIsHomed, value); } }
- public bool GantryIsSwitchOn { get { return _gantryIsSwitchOn; } set { SetProperty(ref _gantryIsSwitchOn, value); } }
- public bool GantryIsMoving { get { return _gantryIsMoving; } set { SetProperty(ref _gantryIsMoving, value); } }
-
- public bool GantryTorqueLimited { get { return _gantryTorqueLimited; } set { SetProperty(ref _gantryTorqueLimited , value); } }
- public CommandMotionData GantryMotionData { get { return _gantryMotionData; } set { SetProperty(ref _gantryMotionData, value); } }
- #endregion
- #region Elevator
- public string ElevatorModuleName { get { return _elevatorModuleName; } set { SetProperty(ref _elevatorModuleName, value); } }
- /// <summary>
- /// Elevator Motion Position
- /// </summary>
- public double ElevatorMotionPosition { get { return _elevatorMotionPosition; } set { SetProperty(ref _elevatorMotionPosition, value); } }
- /// <summary>
- /// Elevator当前位置
- /// </summary>
- public string ElevatorCurrentStation { get { return _elevatorCurrentStation; } set { SetProperty(ref _elevatorCurrentStation, value); } }
- /// <summary>
- /// Elevator当前位置
- /// </summary>
- public string ElevatorCurrentCellName { get { return _elevatorCurrentCellName; } set { SetProperty(ref _elevatorCurrentCellName, value); } }
- public bool ElevatorIsHomed { get { return _elevatorIsHomed; } set { SetProperty(ref _elevatorIsHomed, value); } }
- public bool ElevatorIsSwitchOn { get { return _elevatorIsSwitchOn; } set { SetProperty(ref _elevatorIsSwitchOn, value); } }
- public bool ElevatorIsMoving { get { return _elevatorIsMoving; } set { SetProperty(ref _elevatorIsMoving, value); } }
- public bool ElevatorTorqueLimited { get { return _elevatorTorqueLimited; } set { SetProperty(ref _elevatorTorqueLimited , value); } }
-
- public bool ElevatorIsInUpPlace { get { return _elevatorIsInUpPlace; } set { SetProperty(ref _elevatorIsInUpPlace, value); } }
- public CommandMotionData ElevatorMotionData { get { return _elevatorMotionData; } set { SetProperty(ref _elevatorMotionData, value); } }
- #endregion
- /// <summary>
- /// Transporter数据
- /// </summary>
- public TransporterData TransporterData { get { return _transporterData; } set { SetProperty(ref _transporterData, value); } }
- #endregion
- /// <summary>
- /// 构造函数
- /// </summary>
- public TransporterTeachViewModel()
- {
- }
- /// <summary>
- /// 加载数据
- /// </summary>
- public void LoadData(string systemName)
- {
- Module = systemName;
- LoadLayout();
- int startCellId = (int)QueryDataClient.Instance.Service.GetConfig($"Transporter.{Module}.StartCellId");
- int endCellId= (int)QueryDataClient.Instance.Service.GetConfig($"Transporter.{Module}.EndCellId");
- if(_processLayout!=null&&TeachPositionList.Count==0)
- {
- List<string> lst = GetCellItemsByRange(startCellId, endCellId, _processLayout.Items);
- TeachPositionList.AddRange(lst);
- }
- GantryModuleName = $"{Module}.Gantry";
- ElevatorModuleName = $"{Module}.Elevator" ;
- 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>
- /// <exception cref="NotImplementedException"></exception>
- private void Timer_Tick(object sender, EventArgs e)
- {
- if (_rtDataKeys.Count != 0)
- {
- _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
- if (_rtDataValueDic != null)
- {
- GantryMotionPosition = CommonFunction.GetValue<double>(_rtDataValueDic, $"{GantryModuleName}.{MOTOR_POSITION}");
- GantryIsHomed = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{GantryModuleName}.{IS_HOMED}");
- GantryIsSwitchOn = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{GantryModuleName}.{IS_SWITCH_ON}");
- GantryIsMoving = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{GantryModuleName}.{IS_MOVING}");
- GantryCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{GantryModuleName}.{CURRENT_STATION}"), GantryModuleName);
- GantryMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{GantryModuleName}.{MOTION_DATA}");
- if (GantryMotionData != null)
- {
- GantryTorqueLimited = GantryMotionData.TorqueLimited;
- }
- if (_cellIdCellNameDic.ContainsKey(GantryCurrentStation))
- {
- GantryCurrentCellName = _cellIdCellNameDic[GantryCurrentStation];
- }
- else
- {
- GantryCurrentCellName = GantryCurrentStation;
- }
- ElevatorMotionPosition = CommonFunction.GetValue<double>(_rtDataValueDic, $"{ElevatorModuleName}.{MOTOR_POSITION}");
- ElevatorIsHomed = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{ElevatorModuleName}.{IS_HOMED}");
- ElevatorIsSwitchOn = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{ElevatorModuleName}.{IS_SWITCH_ON}");
- ElevatorIsMoving = CommonFunction.GetValue<bool>(_rtDataValueDic, $"{ElevatorModuleName}.{IS_MOVING}");
- ElevatorCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{ElevatorModuleName}.{CURRENT_STATION}"), ElevatorModuleName);
-
- ElevatorIsInUpPlace = "UP".Equals(ElevatorCurrentStation) ? true : false;
-
- if (_cellIdCellNameDic.ContainsKey(ElevatorCurrentStation))
- {
- ElevatorCurrentCellName = _cellIdCellNameDic[ElevatorCurrentStation];
- }
- else
- {
- ElevatorCurrentCellName = ElevatorCurrentStation;
- }
- ElevatorMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{ElevatorModuleName}.{MOTION_DATA}");
- if (ElevatorMotionData != null)
- {
- ElevatorTorqueLimited = ElevatorMotionData.TorqueLimited;
- }
- TransporterData = CommonFunction.GetValue<TransporterData>(_rtDataValueDic, $"{Module}.{TRANSPORTER_DATA}");
- if (TransporterData != null)
- {
- Locked = TransporterData.Locked1 && TransporterData.Locked2;
- Unlocked = TransporterData.Unlocked1 && TransporterData.Unlocked2;
- Clamped = TransporterData.ImmobilizeExtended1 && TransporterData.ImmobilizeExtended2;
- Unclamped = TransporterData.ImmobilizeRetracted1 && TransporterData.ImmobilizeRetracted2;
- }
- }
- }
- }
- /// <summary>
- /// 获取指定范围的单元项集合
- /// </summary>
- /// <param name="startCellId"></param>
- /// <param name="endCellId"></param>
- /// <param name="items"></param>
- /// <returns></returns>
- private List<string> GetCellItemsByRange(int startCellId, int endCellId, List<ProcessLayoutCellItem> items)
- {
- List<string> lst = new List<string>();
- foreach (ProcessLayoutCellItem item in items)
- {
- if (item.CellId >= startCellId && item.CellId <= endCellId)
- {
- if (!string.IsNullOrEmpty(item.ModuleName))
- {
- lst.Add(item.ModuleName);
- _cellIdCellNameDic[$"Cell{item.CellId}"] = item.ModuleName;
- }
- }
- }
- return lst;
- }
- /// <summary>
- /// 隐藏
- /// </summary>
- public void Hide()
- {
- if (_timer != null)
- {
- _timer.Stop();
- }
- }
- /// <summary>
- /// 加载Layout
- /// </summary>
- private void LoadLayout()
- {
- _rtDataKeys.Clear();
- _rtDataKeys.Add("System.Layout");
- _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
- if (_rtDataValueDic != null)
- {
- _processLayout = CommonFunction.GetValue<ProcessLayout>(_rtDataValueDic, "System.Layout");
- }
- }
- /// <summary>
- /// 初始化查询数据集合
- /// </summary>
- private void AddDataKeys()
- {
- _rtDataKeys.Clear();
- _rtDataKeys.Add($"{GantryModuleName}.{MOTOR_POSITION}");
- _rtDataKeys.Add($"{GantryModuleName}.{IS_SWITCH_ON}");
- _rtDataKeys.Add($"{GantryModuleName}.{IS_HOMED}");
- _rtDataKeys.Add($"{GantryModuleName}.{IS_MOVING}");
- _rtDataKeys.Add($"{GantryModuleName}.{CURRENT_STATION}");
- _rtDataKeys.Add($"{GantryModuleName}.{MOTION_DATA}");
- _rtDataKeys.Add($"{ElevatorModuleName}.{MOTOR_POSITION}");
- _rtDataKeys.Add($"{ElevatorModuleName}.{IS_SWITCH_ON}");
- _rtDataKeys.Add($"{ElevatorModuleName}.{IS_HOMED}");
- _rtDataKeys.Add($"{ElevatorModuleName}.{IS_MOVING}");
- _rtDataKeys.Add($"{ElevatorModuleName}.{CURRENT_STATION}");
- _rtDataKeys.Add($"{ElevatorModuleName}.{MOTION_DATA}");
- _rtDataKeys.Add($"{Module}.{TRANSPORTER_DATA}");
- }
- }
- }
|