ButterflyValveViewModel.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using MECF.Framework.Common.CommonData.DeviceData;
  2. using MECF.Framework.Common.DataCenter;
  3. using MECF.Framework.Common.OperationCenter;
  4. using Prism.Commands;
  5. using Prism.Mvvm;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Threading;
  12. namespace Venus_MainPages.ViewModels
  13. {
  14. public class ButterflyValveViewModel : BindableBase
  15. {
  16. #region 私有字段
  17. public string ModuleName = "PMA";
  18. private string m_DeviceName = "PendulumValve";
  19. private bool m_IsPositionMode;
  20. private int m_SetValue;
  21. private int? m_FeedBackValue;
  22. private List<string> m_RtDataKeys;
  23. private Dictionary<string, object> m_RtDataValues;
  24. #endregion
  25. #region 属性
  26. public bool IsPositionMode
  27. {
  28. get { return m_IsPositionMode; }
  29. set
  30. {
  31. if (SetValue > 1000&&value==true)
  32. {
  33. SetValue = 1000;
  34. }
  35. SetProperty(ref m_IsPositionMode, value);
  36. }
  37. }
  38. public int SetValue
  39. {
  40. get { return m_SetValue; }
  41. set
  42. {
  43. if (value > 1000 && IsPositionMode==true)
  44. {
  45. value = 1000;
  46. }
  47. if (value < 0 && IsPositionMode == true)
  48. {
  49. value = 0;
  50. }
  51. SetProperty(ref m_SetValue, value);
  52. }
  53. }
  54. public int? FeedBackValue
  55. {
  56. get { return m_FeedBackValue; }
  57. set { SetProperty(ref m_FeedBackValue, value); }
  58. }
  59. public string DeviceName
  60. {
  61. get { return m_DeviceName; }
  62. set { SetProperty(ref m_DeviceName, value); }
  63. }
  64. public Dictionary<string, object> RtDataValues
  65. {
  66. get { return m_RtDataValues; }
  67. set { SetProperty(ref m_RtDataValues, value); }
  68. }
  69. #endregion
  70. #region 命令
  71. private DelegateCommand _SetCommand;
  72. public DelegateCommand SetCommand =>
  73. _SetCommand ?? (_SetCommand = new DelegateCommand(OnSet));
  74. #endregion
  75. public ButterflyValveViewModel()
  76. {
  77. DispatcherTimer timer = new DispatcherTimer();
  78. timer.Interval = TimeSpan.FromSeconds(1);
  79. timer.Tick += timer_Tick;
  80. timer.Start();
  81. }
  82. #region 命令方法
  83. private void OnSet()
  84. {
  85. if (IsPositionMode == true)
  86. {
  87. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.SetPVPostion",SetValue);
  88. }
  89. else
  90. {
  91. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.SetPVPressure",SetValue);
  92. }
  93. }
  94. void timer_Tick(object sender, EventArgs e)
  95. {
  96. var pendulumValveData= (AITPendulumValveData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.PendulumValve.DeviceData");
  97. if (IsPositionMode == true)
  98. {
  99. FeedBackValue = pendulumValveData.Position;
  100. }
  101. else
  102. {
  103. FeedBackValue = pendulumValveData.Pressure;
  104. }
  105. }
  106. #endregion
  107. }
  108. }