PlatingCellSetupViewModel.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. using MECF.Framework.Common.CommonData.PUF;
  2. using MECF.Framework.Common.DataCenter;
  3. using MECF.Framework.Common.Equipment;
  4. using MECF.Framework.Common.Utilities;
  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 PunkHPX8_MainPages.ViewModels
  13. {
  14. public class PlatingCellSetupViewModel : BindableBase
  15. {
  16. #region 常量
  17. private const string MOTION_DATA = "MotionData";
  18. private const string IS_SWITCH_ON = "IsSwitchOn";
  19. private const string CURRENT_STATION = "CurrentStation";
  20. #endregion
  21. #region 内部变量
  22. #region PlatingCell1_2Vertical
  23. /// <summary>
  24. /// 模块名称
  25. /// </summary>
  26. private string _platingCell1_2VerticalName;
  27. /// <summary>
  28. /// 运动数据
  29. /// </summary>
  30. private CommandMotionData _platingCell1_2VerticalMotionData;
  31. /// <summary>
  32. /// 当前位置
  33. /// </summary>
  34. private string _platingCell1_2VerticalCurrentStation;
  35. #endregion
  36. #region PlatingCell3_4Vertical
  37. /// <summary>
  38. /// 模块名称
  39. /// </summary>
  40. private string _platingCell3_4VerticalName;
  41. /// <summary>
  42. /// 运动数据
  43. /// </summary>
  44. private CommandMotionData _platingCell3_4VerticalMotionData;
  45. /// <summary>
  46. /// 当前位置
  47. /// </summary>
  48. private string _platingCell3_4VerticalCurrentStation;
  49. #endregion
  50. #region PlatingCell1Rotation
  51. /// <summary>
  52. /// 模块名称
  53. /// </summary>
  54. private string _platingCell1RotationName;
  55. /// <summary>
  56. /// 运动数据
  57. /// </summary>
  58. private CommandMotionData _platingCell1RotationMotionData;
  59. /// <summary>
  60. /// 当前位置
  61. /// </summary>
  62. private string _platingCell1RotationCurrentStation;
  63. #endregion
  64. #region PlatingCell2Rotation
  65. /// <summary>
  66. /// 模块名称
  67. /// </summary>
  68. private string _platingCell2RotationName;
  69. /// <summary>
  70. /// 运动数据
  71. /// </summary>
  72. private CommandMotionData _platingCell2RotationMotionData;
  73. /// <summary>
  74. /// 当前位置
  75. /// </summary>
  76. private string _platingCell2RotationCurrentStation;
  77. #endregion
  78. #region PlatingCell3Rotation
  79. /// <summary>
  80. /// 模块名称
  81. /// </summary>
  82. private string _platingCell3RotationName;
  83. /// <summary>
  84. /// 运动数据
  85. /// </summary>
  86. private CommandMotionData _platingCell3RotationMotionData;
  87. /// <summary>
  88. /// 当前位置
  89. /// </summary>
  90. private string _platingCell3RotationCurrentStation;
  91. #endregion
  92. #region PlatingCell4Rotation
  93. /// <summary>
  94. /// 模块名称
  95. /// </summary>
  96. private string _platingCell4RotationName;
  97. /// <summary>
  98. /// 运动数据
  99. /// </summary>
  100. private CommandMotionData _platingCell4RotationMotionData;
  101. /// <summary>
  102. /// 当前位置
  103. /// </summary>
  104. private string _platingCell4RotationCurrentStation;
  105. #endregion
  106. #endregion
  107. #region 系统数据
  108. /// <summary>
  109. /// 定时器
  110. /// </summary>
  111. DispatcherTimer _timer;
  112. /// <summary>
  113. /// 查询后台数据集合
  114. /// </summary>
  115. private List<string> _rtDataKeys = new List<string>();
  116. /// <summary>
  117. /// rt查询key数值字典
  118. /// </summary>
  119. private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
  120. #endregion
  121. #region 属性
  122. #region PlatingCell1_2Vertical
  123. /// <summary>
  124. ///名称
  125. /// </summary>
  126. public string PlatingCell1_2VerticalName
  127. {
  128. get { return _platingCell1_2VerticalName; }
  129. set { SetProperty(ref _platingCell1_2VerticalName, value); }
  130. }
  131. /// <summary>
  132. /// 运动数据
  133. /// </summary>
  134. public CommandMotionData PlatingCell1_2VerticalMotionData
  135. {
  136. get { return _platingCell1_2VerticalMotionData; }
  137. set { SetProperty(ref _platingCell1_2VerticalMotionData, value); }
  138. }
  139. /// <summary>
  140. ///当前位置
  141. /// </summary>
  142. public string PlatingCell1_2VerticalCurrentStation
  143. {
  144. get { return _platingCell1_2VerticalCurrentStation; }
  145. set { SetProperty(ref _platingCell1_2VerticalCurrentStation, value); }
  146. }
  147. #endregion
  148. #region PlatingCell3_4Vertical
  149. /// <summary>
  150. ///名称
  151. /// </summary>
  152. public string PlatingCell3_4VerticalName
  153. {
  154. get { return _platingCell3_4VerticalName; }
  155. set { SetProperty(ref _platingCell3_4VerticalName, value); }
  156. }
  157. /// <summary>
  158. /// 运动数据
  159. /// </summary>
  160. public CommandMotionData PlatingCell3_4VerticalMotionData
  161. {
  162. get { return _platingCell3_4VerticalMotionData; }
  163. set { SetProperty(ref _platingCell3_4VerticalMotionData, value); }
  164. }
  165. /// <summary>
  166. /// 当前位置
  167. /// </summary>
  168. public string PlatingCell3_4VerticalCurrentStation
  169. {
  170. get { return _platingCell3_4VerticalCurrentStation; }
  171. set { SetProperty(ref _platingCell3_4VerticalCurrentStation, value); }
  172. }
  173. #endregion
  174. #region PlatingCell1Rotation
  175. /// <summary>
  176. ///名称
  177. /// </summary>
  178. public string PlatingCell1RotationName
  179. {
  180. get { return _platingCell1RotationName; }
  181. set { SetProperty(ref _platingCell1RotationName, value); }
  182. }
  183. /// <summary>
  184. /// 运动数据
  185. /// </summary>
  186. public CommandMotionData PlatingCell1RotationMotionData
  187. {
  188. get { return _platingCell1RotationMotionData; }
  189. set { SetProperty(ref _platingCell1RotationMotionData, value); }
  190. }
  191. /// <summary>
  192. /// 当前位置
  193. /// </summary>
  194. public string PlatingCell1RotationCurrentStation
  195. {
  196. get { return _platingCell1RotationCurrentStation; }
  197. set { SetProperty(ref _platingCell1RotationCurrentStation, value); }
  198. }
  199. #endregion
  200. #region PlatingCell2Rotation
  201. /// <summary>
  202. ///名称
  203. /// </summary>
  204. public string PlatingCell2RotationName
  205. {
  206. get { return _platingCell2RotationName; }
  207. set { SetProperty(ref _platingCell2RotationName, value); }
  208. }
  209. /// <summary>
  210. /// 运动数据
  211. /// </summary>
  212. public CommandMotionData PlatingCell2RotationMotionData
  213. {
  214. get { return _platingCell2RotationMotionData; }
  215. set { SetProperty(ref _platingCell2RotationMotionData, value); }
  216. }
  217. /// <summary>
  218. /// 当前位置
  219. /// </summary>
  220. public string PlatingCell2RotationCurrentStation
  221. {
  222. get { return _platingCell2RotationCurrentStation; }
  223. set { SetProperty(ref _platingCell2RotationCurrentStation, value); }
  224. }
  225. #endregion
  226. #region PlatingCell3Rotation
  227. /// <summary>
  228. ///名称
  229. /// </summary>
  230. public string PlatingCell3RotationName
  231. {
  232. get { return _platingCell3RotationName; }
  233. set { SetProperty(ref _platingCell3RotationName, value); }
  234. }
  235. /// <summary>
  236. /// 运动数据
  237. /// </summary>
  238. public CommandMotionData PlatingCell3RotationMotionData
  239. {
  240. get { return _platingCell3RotationMotionData; }
  241. set { SetProperty(ref _platingCell3RotationMotionData, value); }
  242. }
  243. /// <summary>
  244. /// 当前位置
  245. /// </summary>
  246. public string PlatingCell3RotationCurrentStation
  247. {
  248. get { return _platingCell3RotationCurrentStation; }
  249. set { SetProperty(ref _platingCell3RotationCurrentStation, value); }
  250. }
  251. #endregion
  252. #region PlatingCell4Rotation
  253. /// <summary>
  254. ///名称
  255. /// </summary>
  256. public string PlatingCell4RotationName
  257. {
  258. get { return _platingCell4RotationName; }
  259. set { SetProperty(ref _platingCell4RotationName, value); }
  260. }
  261. /// <summary>
  262. /// 运动数据
  263. /// </summary>
  264. public CommandMotionData PlatingCell4RotationMotionData
  265. {
  266. get { return _platingCell4RotationMotionData; }
  267. set { SetProperty(ref _platingCell4RotationMotionData, value); }
  268. }
  269. /// <summary>
  270. /// 当前位置
  271. /// </summary>
  272. public string PlatingCell4RotationCurrentStation
  273. {
  274. get { return _platingCell4RotationCurrentStation; }
  275. set { SetProperty(ref _platingCell4RotationCurrentStation, value); }
  276. }
  277. #endregion
  278. #endregion
  279. /// <summary>
  280. /// 构造函数
  281. /// </summary>
  282. public PlatingCellSetupViewModel()
  283. {
  284. }
  285. /// <summary>
  286. /// 加载数据
  287. /// </summary>
  288. public void LoadData(string systemName)
  289. {
  290. PlatingCell1_2VerticalName = $"PlatingCell1_2.Vertical";
  291. PlatingCell3_4VerticalName = $"PlatingCell3_4.Vertical";
  292. PlatingCell1RotationName = $"PlatingCell1.Rotation";
  293. PlatingCell2RotationName = $"PlatingCell2.Rotation";
  294. PlatingCell3RotationName = $"PlatingCell3.Rotation";
  295. PlatingCell4RotationName = $"PlatingCell4.Rotation";
  296. AddDataKeys();
  297. if (_timer == null)
  298. {
  299. _timer = new DispatcherTimer();
  300. _timer.Interval = TimeSpan.FromMilliseconds(200);
  301. _timer.Tick += Timer_Tick;
  302. }
  303. _timer.Start();
  304. }
  305. /// <summary>
  306. /// 定时器执行
  307. /// </summary>
  308. /// <param name="sender"></param>
  309. /// <param name="e"></param>
  310. private void Timer_Tick(object sender, EventArgs e)
  311. {
  312. OnTimer();
  313. }
  314. /// <summary>
  315. /// 隐藏
  316. /// </summary>
  317. public void Hide()
  318. {
  319. if (_timer != null)
  320. {
  321. _timer.Stop();
  322. }
  323. }
  324. /// <summary>
  325. /// 初始化查询数据集合
  326. /// </summary>
  327. private void AddDataKeys()
  328. {
  329. _rtDataKeys.Clear();
  330. _rtDataKeys.Add($"{PlatingCell1_2VerticalName}.{MOTION_DATA}");
  331. _rtDataKeys.Add($"{PlatingCell1_2VerticalName}.{IS_SWITCH_ON}");
  332. _rtDataKeys.Add($"{PlatingCell1_2VerticalName}.{CURRENT_STATION}");
  333. _rtDataKeys.Add($"{PlatingCell3_4VerticalName}.{MOTION_DATA}");
  334. _rtDataKeys.Add($"{PlatingCell3_4VerticalName}.{IS_SWITCH_ON}");
  335. _rtDataKeys.Add($"{PlatingCell3_4VerticalName}.{CURRENT_STATION}");
  336. _rtDataKeys.Add($"{PlatingCell1RotationName}.{MOTION_DATA}");
  337. _rtDataKeys.Add($"{PlatingCell1RotationName}.{IS_SWITCH_ON}");
  338. _rtDataKeys.Add($"{PlatingCell1RotationName}.{CURRENT_STATION}");
  339. _rtDataKeys.Add($"{PlatingCell2RotationName}.{MOTION_DATA}");
  340. _rtDataKeys.Add($"{PlatingCell2RotationName}.{IS_SWITCH_ON}");
  341. _rtDataKeys.Add($"{PlatingCell2RotationName}.{CURRENT_STATION}");
  342. _rtDataKeys.Add($"{PlatingCell3RotationName}.{MOTION_DATA}");
  343. _rtDataKeys.Add($"{PlatingCell3RotationName}.{IS_SWITCH_ON}");
  344. _rtDataKeys.Add($"{PlatingCell3RotationName}.{CURRENT_STATION}");
  345. _rtDataKeys.Add($"{PlatingCell4RotationName}.{MOTION_DATA}");
  346. _rtDataKeys.Add($"{PlatingCell4RotationName}.{IS_SWITCH_ON}");
  347. _rtDataKeys.Add($"{PlatingCell4RotationName}.{CURRENT_STATION}");
  348. }
  349. /// <summary>
  350. /// 定时器
  351. /// </summary>
  352. /// <returns></returns>
  353. private Boolean OnTimer()
  354. {
  355. if (_rtDataKeys.Count != 0)
  356. {
  357. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  358. if (_rtDataValueDic != null)
  359. {
  360. PlatingCell1_2VerticalMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{PlatingCell1_2VerticalName}.{MOTION_DATA}");
  361. PlatingCell1_2VerticalCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{PlatingCell1_2VerticalName}.{CURRENT_STATION}"), PlatingCell1_2VerticalName);
  362. PlatingCell3_4VerticalMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{PlatingCell3_4VerticalName}.{MOTION_DATA}");
  363. PlatingCell3_4VerticalCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{PlatingCell3_4VerticalName}.{CURRENT_STATION}"), PlatingCell3_4VerticalName);
  364. PlatingCell1RotationMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{PlatingCell1RotationName}.{MOTION_DATA}");
  365. PlatingCell1RotationCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{PlatingCell1RotationName}.{CURRENT_STATION}"), PlatingCell1RotationName);
  366. PlatingCell2RotationMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{PlatingCell2RotationName}.{MOTION_DATA}");
  367. PlatingCell2RotationCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{PlatingCell2RotationName}.{CURRENT_STATION}"), PlatingCell2RotationName);
  368. PlatingCell3RotationMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{PlatingCell3RotationName}.{MOTION_DATA}");
  369. PlatingCell3RotationCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{PlatingCell3RotationName}.{CURRENT_STATION}"), PlatingCell3RotationName);
  370. PlatingCell3RotationMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{PlatingCell4RotationName}.{MOTION_DATA}");
  371. PlatingCell3RotationCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{PlatingCell4RotationName}.{CURRENT_STATION}"), PlatingCell4RotationName);
  372. }
  373. }
  374. return true;
  375. }
  376. }
  377. }