BufferRobotViewModel.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using Aitex.Core.Util;
  2. using Caliburn.Micro.Core;
  3. using Caliburn.Micro;
  4. using FurnaceUI.Models;
  5. using FurnaceUI.Views.Operations;
  6. using MECF.Framework.Common.DataCenter;
  7. using MECF.Framework.Common.Equipment;
  8. using MECF.Framework.Common.OperationCenter;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows.Controls;
  15. using OpenSEMI.ClientBase;
  16. namespace FurnaceUI.Views.Maintenances
  17. {
  18. public class BufferRobotViewModel : FurnaceUIViewModelBase
  19. {
  20. #region Buffer Data
  21. [Subscription("PM1.BufferServo.CurrentPosition")]
  22. public float BufferCurrentPosition { get; set; }
  23. [Subscription("PM1.BufferServo.CurrentSpeed")]
  24. public float BufferCurrentSpeed { get; set; }
  25. [Subscription("PM1.BufferServo.IsServoOn")]
  26. public bool BufferIsServoOn { get; set; }
  27. [Subscription("PM1.BufferServo.IsReady")]
  28. public bool BufferIsReady { get; set; }
  29. [Subscription("PM1.BufferServo.Status")]
  30. public string BufferStatus { get; set; }
  31. [Subscription("PM1.BufferServo.IsMotorRun")]
  32. public bool BufferIsMotorRun { get; set; }
  33. #endregion
  34. [Subscription("Rt.Status")]
  35. public string RtStatus { get; set; }
  36. public bool IsSystemStaus => (RtStatus != "AutoRunning");
  37. //public bool IsPermission { get => this.Permission >= 3 && ClientApp.Instance.UserContext.RoleName == "Service"; }
  38. public bool IsPermission { get => this.Permission >= 3; }
  39. private List<string> _targetPosition = new List<string>();
  40. public List<string> TargetPosition
  41. {
  42. get => _targetPosition;
  43. set
  44. {
  45. _targetPosition = value;
  46. NotifyOfPropertyChange(nameof(TargetPosition));
  47. }
  48. }
  49. public double BufferAxisMoveSpeed { get; set; }
  50. public double BufferAxisLimitSpeed { get; set; }
  51. private string _selectedTargetPosition;
  52. public string SelectedTargetPosition
  53. {
  54. get => _selectedTargetPosition;
  55. set
  56. {
  57. _selectedTargetPosition = value;
  58. NotifyOfPropertyChange(nameof(SelectedTargetPosition));
  59. }
  60. }
  61. private BufferRobotView _view;
  62. protected override void OnViewLoaded(object view)
  63. {
  64. base.OnViewLoaded(view);
  65. _view = view as BufferRobotView;
  66. BufferAxisLimitSpeed = (double)QueryDataClient.Instance.Service.GetConfig($"BufferServo.BufferAxisLimitSpeed");
  67. }
  68. private void InitData()
  69. {
  70. BufferAxisMoveSpeed = (double)QueryDataClient.Instance.Service.GetConfig($"BufferServo.MoveSpeed");
  71. }
  72. protected override void InvokeAfterUpdateProperty(Dictionary<string, object> data)
  73. {
  74. InitData();
  75. if (_view != null)
  76. {
  77. var rsetValueBool = double.TryParse(_view?.tbMoveSpeed.Text, out double setZValue);
  78. if (!rsetValueBool)
  79. _view.tbMoveSpeed.Text = "0";
  80. if (!string.IsNullOrEmpty(_view?.tbMoveSpeed.Text) && rsetValueBool && setZValue > BufferAxisLimitSpeed)
  81. {
  82. _view.tbMoveSpeed.Text = "0";
  83. DialogBox.ShowWarning($"Max Move Speed is {BufferAxisLimitSpeed}");
  84. }
  85. }
  86. }
  87. private Dictionary<string, string> _targetPositionDic = new Dictionary<string, string>()
  88. {
  89. { "1-A", "1" },
  90. { "1-B", "2" },
  91. { "1-C", "3" },
  92. { "1-D", "4" },
  93. { "2-A", "5" },
  94. { "2-B", "6" },
  95. { "2-C", "7" },
  96. { "2-D", "8" },
  97. { "3-A", "9" },
  98. { "3-B", "10" },
  99. { "3-C", "11" },
  100. { "3-D", "12" },
  101. { "4-A", "13" },
  102. { "4-B", "14" },
  103. { "4-C", "15" },
  104. { "4-D", "16" },
  105. };
  106. public BufferRobotViewModel()
  107. {
  108. foreach(var target in _targetPositionDic.Keys)
  109. {
  110. _targetPosition.Add(target);
  111. }
  112. }
  113. public void SetValue()
  114. {
  115. var target = _targetPositionDic.ContainsKey(SelectedTargetPosition) ? _targetPositionDic[SelectedTargetPosition] : SelectedTargetPosition;
  116. InvokeClient.Instance.Service.DoOperation($"PM1.BufferServo.ServoTargetPosition", target);
  117. }
  118. public void MoveTo()
  119. {
  120. InvokeClient.Instance.Service.DoOperation($"PM1.BufferServo.ServoMoveTo", "");
  121. }
  122. public void SetServoOn(object target, object isOn)
  123. {
  124. InvokeClient.Instance.Service.DoOperation($"{target}", $"{isOn}");
  125. }
  126. public void BufferSaveValue(object obj, object tb)
  127. {
  128. switch (obj)
  129. {
  130. case "MoveSpeed":
  131. var setValue = double.Parse((tb as TextBox)?.Text);
  132. if (setValue > BufferAxisLimitSpeed)
  133. {
  134. DialogBox.ShowWarning($"Max MoveSpeed is {BufferAxisLimitSpeed}");
  135. break;
  136. }
  137. InvokeClient.Instance.Service.DoOperation("System.SetConfig", $"BufferServo.{obj}", (tb as TextBox)?.Text);
  138. break;
  139. }
  140. }
  141. public void Stop(object target)
  142. {
  143. InvokeClient.Instance.Service.DoOperation($"{target}.ServoStop");
  144. }
  145. public void Reset(object target)
  146. {
  147. InvokeClient.Instance.Service.DoOperation($"{target}.ServoResetAlarm");
  148. }
  149. }
  150. }