SystemSafetyViewModel.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. using Aitex.Core.UI.MVVM;
  2. using MECF.Framework.Common.CommonData;
  3. using MECF.Framework.Common.DataCenter;
  4. using MECF.Framework.Common.Device.Safety;
  5. using MECF.Framework.Common.Equipment;
  6. using MECF.Framework.Common.OperationCenter;
  7. using MECF.Framework.Common.Utilities;
  8. using OpenSEMI.ClientBase.Command;
  9. using Prism.Mvvm;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Input;
  16. using System.Windows.Threading;
  17. namespace PunkHPX8_MainPages.ViewModels
  18. {
  19. public class SystemSafetyViewModel : BindableBase
  20. {
  21. #region 常量
  22. private const string SAFETY_DATA = "SafetyData";
  23. private const string IS_SWITCH_ON = "IsSwitchOn";
  24. private const string IS_INITIALIZED = "IsInitialized";
  25. private const string IS_MOVING = "IsMoving";
  26. #endregion
  27. #region 内部变量
  28. private SafetyData _commonSafetyData;
  29. #region VPW
  30. private bool _isVpw1RotationOn;
  31. private bool _isVpw2RotationOn;
  32. private bool _isSrd1RotationOn;
  33. private bool _isSrd2RotationOn;
  34. private bool _isPlatingCell1RotationOn;
  35. private bool _isPlatingCell2RotationOn;
  36. private bool _isPlatingCell3RotationOn;
  37. private bool _isPlatingCell4RotationOn;
  38. private bool _isPlatingCell1_2VerticalOn;
  39. private bool _isPlatingCell3_4VerticalOn;
  40. #endregion
  41. #endregion
  42. #region 属性
  43. #region VPW
  44. public bool IsVpw1RotationOn { get { return _isVpw1RotationOn; } set { SetProperty(ref _isVpw1RotationOn, value); } }
  45. public bool IsVpw2RotationOn { get { return _isVpw2RotationOn; } set { SetProperty(ref _isVpw2RotationOn, value); } }
  46. public bool IsSRD1RotationOn { get { return _isSrd1RotationOn; } set { SetProperty(ref _isSrd1RotationOn, value); } }
  47. public bool IsSRD2RotationOn { get { return _isSrd2RotationOn; } set { SetProperty(ref _isSrd2RotationOn, value); } }
  48. public bool IsPlatingCell1RotationOn { get { return _isPlatingCell1RotationOn; } set { SetProperty(ref _isPlatingCell1RotationOn, value); } }
  49. public bool IsPlatingCell2RotationOn { get { return _isPlatingCell2RotationOn; } set { SetProperty(ref _isPlatingCell2RotationOn, value); } }
  50. public bool IsPlatingCell3RotationOn { get { return _isPlatingCell3RotationOn; } set { SetProperty(ref _isPlatingCell3RotationOn, value); } }
  51. public bool IsPlatingCell4RotationOn { get { return _isPlatingCell4RotationOn; } set { SetProperty(ref _isPlatingCell4RotationOn, value); } }
  52. public bool IsPlatingCell1_2VerticalOn { get { return _isPlatingCell1_2VerticalOn; } set { SetProperty(ref _isPlatingCell1_2VerticalOn, value); } }
  53. public bool IsPlatingCell3_4VerticalOn { get { return _isPlatingCell3_4VerticalOn; } set { SetProperty(ref _isPlatingCell3_4VerticalOn, value); } }
  54. #endregion
  55. public SafetyData CommonSafetyData { get { return _commonSafetyData; } set { SetProperty(ref _commonSafetyData, value); } }
  56. #endregion
  57. /// <summary>
  58. /// 定时器
  59. /// </summary>
  60. DispatcherTimer _timer;
  61. /// <summary>
  62. /// 查询后台数据集合
  63. /// </summary>
  64. private List<string> _rtDataKeys = new List<string>();
  65. /// <summary>
  66. /// rt查询key数值字典
  67. /// </summary>
  68. private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
  69. #region 指令
  70. public ICommand PauseCommand { get; private set; }
  71. public ICommand ResumeCommand { get; private set; }
  72. public ICommand ResetCommand { get; private set; }
  73. public ICommand LockCassetteDoorsCommand { get; private set; }
  74. public ICommand UnlockCassetteDoorsCommand { get; private set; }
  75. public ICommand LockCell12DoorsCommand { get; private set; }
  76. public ICommand UnlockCell12DoorsCommand { get; private set; }
  77. public ICommand LockCell34DoorsCommand { get; private set; }
  78. public ICommand UnlockCell34DoorsCommand { get; private set; }
  79. public ICommand LockAlignerDoorsCommand { get; private set; }
  80. public ICommand UnlockAlignerDoorsCommand { get; private set; }
  81. public ICommand AllOnCommand { get; private set; }
  82. #endregion
  83. /// <summary>
  84. /// 构造函数
  85. /// </summary>
  86. public SystemSafetyViewModel()
  87. {
  88. PauseCommand = new DelegateCommand<Object>(PauseAction);
  89. ResumeCommand = new DelegateCommand<Object>(ResumeAction);
  90. ResetCommand = new DelegateCommand<Object>(ResetAction);
  91. LockCassetteDoorsCommand = new DelegateCommand<Object>(LockCassetteDoorsAction);
  92. UnlockCassetteDoorsCommand = new DelegateCommand<Object>(UnlockCassetteDoorsAction);
  93. LockCell12DoorsCommand = new DelegateCommand<Object>(LockCell12DoorsAction);
  94. UnlockCell12DoorsCommand = new DelegateCommand<Object>(UnlockCell12DoorsAction);
  95. LockCell34DoorsCommand = new DelegateCommand<Object>(LockCell34DoorsAction);
  96. UnlockCell34DoorsCommand = new DelegateCommand<Object>(UnlockCell34DoorsAction);
  97. LockAlignerDoorsCommand = new DelegateCommand<Object>(LockAlignerDoorsAction);
  98. UnlockAlignerDoorsCommand = new DelegateCommand<Object>(UnlockAlignerDoorsAction);
  99. AllOnCommand = new DelegateCommand<Object>(AllOnAction);
  100. }
  101. /// <summary>
  102. /// 初始化Keys
  103. /// </summary>
  104. private void InitialKeys()
  105. {
  106. _rtDataKeys.Clear();
  107. _rtDataKeys.Add($"Safety.{SAFETY_DATA}");
  108. _rtDataKeys.Add($"Safety.{IS_INITIALIZED}");
  109. _rtDataKeys.Add($"VPW1.Rotation.{IS_SWITCH_ON}");
  110. _rtDataKeys.Add($"VPW2.Rotation.{IS_SWITCH_ON}");
  111. _rtDataKeys.Add($"SRD1.Rotation.{IS_SWITCH_ON}");
  112. _rtDataKeys.Add($"SRD2.Rotation.{IS_SWITCH_ON}");
  113. _rtDataKeys.Add($"PlatingCell1_2.Vertical.{IS_SWITCH_ON}");
  114. _rtDataKeys.Add($"PlatingCell3_4.Vertical.{IS_SWITCH_ON}");
  115. _rtDataKeys.Add($"PlatingCell1.Rotation.{IS_SWITCH_ON}");
  116. _rtDataKeys.Add($"PlatingCell2.Rotation.{IS_SWITCH_ON}");
  117. _rtDataKeys.Add($"PlatingCell3.Rotation.{IS_SWITCH_ON}");
  118. _rtDataKeys.Add($"PlatingCell4.Rotation.{IS_SWITCH_ON}");
  119. }
  120. /// <summary>
  121. /// 加载数据
  122. /// </summary>
  123. public void LoadData(string systemName)
  124. {
  125. InitialKeys();
  126. if (_timer == null)
  127. {
  128. _timer = new DispatcherTimer();
  129. _timer.Interval = TimeSpan.FromMilliseconds(200);
  130. _timer.Tick += Timer_Tick; ;
  131. }
  132. _timer.Start();
  133. }
  134. /// <summary>
  135. /// 定时器执行
  136. /// </summary>
  137. /// <param name="sender"></param>
  138. /// <param name="e"></param>
  139. /// <exception cref="NotImplementedException"></exception>
  140. private void Timer_Tick(object sender, EventArgs e)
  141. {
  142. if (_rtDataKeys.Count != 0)
  143. {
  144. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  145. if (_rtDataValueDic != null)
  146. {
  147. CommonSafetyData = CommonFunction.GetValue<SafetyData>(_rtDataValueDic, $"Safety.{SAFETY_DATA}");
  148. IsVpw1RotationOn = CommonFunction.GetValue<bool>(_rtDataValueDic, $"VPW1.Rotation.{IS_SWITCH_ON}");
  149. IsVpw2RotationOn = CommonFunction.GetValue<bool>(_rtDataValueDic, $"VPW2.Rotation.{IS_SWITCH_ON}");
  150. IsSRD1RotationOn = CommonFunction.GetValue<bool>(_rtDataValueDic, $"SRD1.Rotation.{IS_SWITCH_ON}");
  151. IsSRD2RotationOn = CommonFunction.GetValue<bool>(_rtDataValueDic, $"SRD2.Rotation.{IS_SWITCH_ON}");
  152. IsPlatingCell1RotationOn = CommonFunction.GetValue<bool>(_rtDataValueDic, $"PlatingCell1.Rotation.{IS_SWITCH_ON}");
  153. IsPlatingCell2RotationOn = CommonFunction.GetValue<bool>(_rtDataValueDic, $"PlatingCell2.Rotation.{IS_SWITCH_ON}");
  154. IsPlatingCell3RotationOn = CommonFunction.GetValue<bool>(_rtDataValueDic, $"PlatingCell3.Rotation.{IS_SWITCH_ON}");
  155. IsPlatingCell4RotationOn = CommonFunction.GetValue<bool>(_rtDataValueDic, $"PlatingCell4.Rotation.{IS_SWITCH_ON}");
  156. IsPlatingCell1_2VerticalOn = CommonFunction.GetValue<bool>(_rtDataValueDic, $"PlatingCell1_2.Vertical.{IS_SWITCH_ON}");
  157. IsPlatingCell3_4VerticalOn = CommonFunction.GetValue<bool>(_rtDataValueDic, $"PlatingCell3_4.Vertical.{IS_SWITCH_ON}");
  158. //判断电机Moving状态
  159. JudgeMoving();
  160. }
  161. }
  162. }
  163. /// <summary>
  164. /// 隐藏
  165. /// </summary>
  166. public void Hide()
  167. {
  168. if (_timer != null)
  169. {
  170. _timer.Stop();
  171. }
  172. }
  173. #region 指令Action
  174. /// <summary>
  175. /// Pause
  176. /// </summary>
  177. /// <param name="param"></param>
  178. private void PauseAction(object param)
  179. {
  180. throw new NotImplementedException();
  181. }
  182. /// <summary>
  183. /// Resume
  184. /// </summary>
  185. /// <param name="param"></param>
  186. private void ResumeAction(object param)
  187. {
  188. throw new NotImplementedException();
  189. }
  190. /// <summary>
  191. /// AllOn
  192. /// </summary>
  193. /// <param name="param"></param>
  194. private void AllOnAction(object param)
  195. {
  196. InvokeClient.Instance.Service.DoOperation("Safety.AllOnOperation");
  197. }
  198. /// <summary>
  199. /// Reset
  200. /// </summary>
  201. /// <param name="param"></param>
  202. private void ResetAction(object param)
  203. {
  204. InvokeClient.Instance.Service.DoOperation("Safety.ResetOperation");
  205. }
  206. private void LockCassetteDoorsAction(object param)
  207. {
  208. InvokeClient.Instance.Service.DoOperation("Safety.LockCasseteDoor");
  209. }
  210. private void UnlockCassetteDoorsAction(object param)
  211. {
  212. InvokeClient.Instance.Service.DoOperation("Safety.UnlockCasseteDoor");
  213. }
  214. private void LockCell12DoorsAction(object param)
  215. {
  216. InvokeClient.Instance.Service.DoOperation("Safety.LockCell12Door");
  217. }
  218. private void UnlockCell12DoorsAction(object param)
  219. {
  220. InvokeClient.Instance.Service.DoOperation("Safety.UnlockCell12Door");
  221. }
  222. private void LockCell34DoorsAction(object param)
  223. {
  224. InvokeClient.Instance.Service.DoOperation("Safety.LockCell34Door");
  225. }
  226. private void UnlockCell34DoorsAction(object param)
  227. {
  228. InvokeClient.Instance.Service.DoOperation("Safety.UnlockCell34Door");
  229. }
  230. private void LockAlignerDoorsAction(object param)
  231. {
  232. InvokeClient.Instance.Service.DoOperation("Safety.LockAlignerDoor");
  233. }
  234. private void UnlockAlignerDoorsAction(object param)
  235. {
  236. InvokeClient.Instance.Service.DoOperation("Safety.UnlockAlignerDoor");
  237. }
  238. /// <summary>
  239. /// 判断各个电机Moving状态
  240. /// </summary>
  241. /// <param name="param"></param>
  242. private void JudgeMoving()
  243. {
  244. }
  245. #endregion
  246. }
  247. }