123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- using MECF.Framework.Common.CommonData.DeviceData;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.Common.OperationCenter;
- using Prism.Commands;
- using Prism.Mvvm;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Threading;
- namespace Venus_MainPages.ViewModels
- {
- public class ButterflyValveViewModel : BindableBase
- {
- #region 私有字段
- public string ModuleName = "PMA";
- private string m_DeviceName = "PendulumValve";
- private bool m_IsPositionMode;
- private int m_SetValue;
- private int? m_FeedBackValue;
- private List<string> m_RtDataKeys;
- private Dictionary<string, object> m_RtDataValues;
- #endregion
- #region 属性
- public bool IsPositionMode
- {
- get { return m_IsPositionMode; }
- set
- {
- if (SetValue > 1000&&value==true)
- {
- SetValue = 1000;
- }
- SetProperty(ref m_IsPositionMode, value);
- }
- }
- public int SetValue
- {
- get { return m_SetValue; }
- set
- {
- if (value > 1000 && IsPositionMode==true)
- {
- value = 1000;
- }
- if (value < 0 && IsPositionMode == true)
- {
- value = 0;
- }
- SetProperty(ref m_SetValue, value);
- }
- }
- public int? FeedBackValue
- {
- get { return m_FeedBackValue; }
- set { SetProperty(ref m_FeedBackValue, value); }
- }
- public string DeviceName
- {
- get { return m_DeviceName; }
- set { SetProperty(ref m_DeviceName, value); }
- }
- public Dictionary<string, object> RtDataValues
- {
- get { return m_RtDataValues; }
- set { SetProperty(ref m_RtDataValues, value); }
- }
- #endregion
- #region 命令
- private DelegateCommand _SetCommand;
- public DelegateCommand SetCommand =>
- _SetCommand ?? (_SetCommand = new DelegateCommand(OnSet));
- #endregion
- public ButterflyValveViewModel()
- {
-
- DispatcherTimer timer = new DispatcherTimer();
- timer.Interval = TimeSpan.FromSeconds(1);
- timer.Tick += timer_Tick;
- timer.Start();
- }
- #region 命令方法
- private void OnSet()
- {
- if (IsPositionMode == true)
- {
- InvokeClient.Instance.Service.DoOperation($"{ModuleName}.SetPVPostion",SetValue);
- }
- else
- {
- InvokeClient.Instance.Service.DoOperation($"{ModuleName}.SetPVPressure",SetValue);
- }
- }
- void timer_Tick(object sender, EventArgs e)
- {
- var pendulumValveData= (AITPendulumValveData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.PendulumValve.DeviceData");
- if (IsPositionMode == true)
- {
- FeedBackValue = pendulumValveData.Position;
- }
- else
- {
- FeedBackValue = pendulumValveData.Pressure;
- }
- }
- #endregion
- }
- }
|