SRDStationSetupViewModel.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Aitex.Core.Common;
  9. using LiveCharts;
  10. using System.Windows;
  11. using MECF.Framework.Common.CommonData.PUF;
  12. using MECF.Framework.Common.DataCenter;
  13. using MECF.Framework.Common.Equipment;
  14. using Prism.Mvvm;
  15. using System.Timers;
  16. using Aitex.Core.RT.DataCenter;
  17. using MECF.Framework.Common.Utilities;
  18. using MECF.Framework.Common.CommonData.Loader;
  19. using MECF.Framework.Common.OperationCenter;
  20. using Aitex.Core.Utilities;
  21. using System.Windows.Input;
  22. using Aitex.Core.UI.MVVM;
  23. using System.Windows.Threading;
  24. namespace CyberX8_MainPages.ViewModels
  25. {
  26. public class SRDStationSetupViewModel:BindableBase
  27. {
  28. #region 常量
  29. private const string MOTION_DATA = "MotionData";
  30. private const string IS_SWITCH_ON = "IsSwitchOn";
  31. private const string CURRENT_STATION = "CurrentStation";
  32. #endregion
  33. #region 内部变量
  34. #region SRD1Arm
  35. /// <summary>
  36. /// sRD1Arm模块名称
  37. /// </summary>
  38. private string _sRD1ArmModuleName;
  39. /// <summary>
  40. /// sRD1Arm运动数据
  41. /// </summary>
  42. private CommandMotionData _sRD1ArmMotionData;
  43. /// <summary>
  44. /// sRD1Arm当前位置
  45. /// </summary>
  46. private string _sRD1ArmCurrentStation;
  47. #endregion
  48. #region SRD1Rotation
  49. /// <summary>
  50. /// sRD1Rotation模块名称
  51. /// </summary>
  52. private string _sRD1RotationModuleName;
  53. /// <summary>
  54. /// sRD1Rotation运动数据
  55. /// </summary>
  56. private CommandMotionData _sRD1RotationMotionData;
  57. /// <summary>
  58. /// sRD1Rotation当前位置
  59. /// </summary>
  60. private string _sRD1RotationCurrentStation;
  61. #endregion
  62. #region SRD2Arm
  63. /// <summary>
  64. /// sRD2Arm模块名称
  65. /// </summary>
  66. private string _sRD2ArmModuleName;
  67. /// <summary>
  68. /// sRD2Arm运动数据
  69. /// </summary>
  70. private CommandMotionData _sRD2ArmMotionData;
  71. /// <summary>
  72. /// sRD2Arm当前位置
  73. /// </summary>
  74. private string _sRD2ArmCurrentStation;
  75. #endregion
  76. #region SRD2Rotation
  77. /// <summary>
  78. /// sRD2Rotation模块名称
  79. /// </summary>
  80. private string _sRD2RotationModuleName;
  81. /// <summary>
  82. /// sRD2Rotation运动数据
  83. /// </summary>
  84. private CommandMotionData _sRD2RotationMotionData;
  85. /// <summary>
  86. /// sRD2Rotation当前位置
  87. /// </summary>
  88. private string _sRD2RotationCurrentStation;
  89. #endregion
  90. #region 系统数据
  91. /// <summary>
  92. /// 定时器
  93. /// </summary>
  94. DispatcherTimer _timer;
  95. /// <summary>
  96. /// 查询后台数据集合
  97. /// </summary>
  98. private List<string> _rtDataKeys = new List<string>();
  99. /// <summary>
  100. /// rt查询key数值字典
  101. /// </summary>
  102. private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
  103. #endregion
  104. #region AWC
  105. /// <summary>
  106. /// AWC ModuleName
  107. /// </summary>
  108. private ModuleName _awcModuleName;
  109. /// <summary>
  110. /// Is AWC Cycle runnning
  111. /// </summary>
  112. private bool _isAWCCycling;
  113. #endregion
  114. #endregion
  115. #region 属性
  116. #region SRD1Arm
  117. /// <summary>
  118. /// SRD1Arm名称
  119. /// </summary>
  120. public string SRD1ArmModuleName
  121. {
  122. get { return _sRD1ArmModuleName; }
  123. set { SetProperty(ref _sRD1ArmModuleName, value); }
  124. }
  125. /// <summary>
  126. /// SRD1Arm运动数据
  127. /// </summary>
  128. public CommandMotionData SRD1ArmMotionData
  129. {
  130. get { return _sRD1ArmMotionData; }
  131. set { SetProperty(ref _sRD1ArmMotionData, value); }
  132. }
  133. /// <summary>
  134. /// SRD1Arm当前位置
  135. /// </summary>
  136. public string SRD1ArmCurrentStation
  137. {
  138. get { return _sRD1ArmCurrentStation; }
  139. set { SetProperty(ref _sRD1ArmCurrentStation, value); }
  140. }
  141. #endregion
  142. #region SRD1Rotation
  143. /// <summary>
  144. /// SRD1Rotation名称
  145. /// </summary>
  146. public string SRD1RotationModuleName
  147. {
  148. get { return _sRD1RotationModuleName; }
  149. set { SetProperty(ref _sRD1RotationModuleName, value); }
  150. }
  151. /// <summary>
  152. /// SRD1Rotation运动数据
  153. /// </summary>
  154. public CommandMotionData SRD1RotationMotionData
  155. {
  156. get { return _sRD1RotationMotionData; }
  157. set { SetProperty(ref _sRD1RotationMotionData, value); }
  158. }
  159. /// <summary>
  160. /// SRD1Rotation当前位置
  161. /// </summary>
  162. public string SRD1RotationCurrentStation
  163. {
  164. get { return _sRD1RotationCurrentStation; }
  165. set { SetProperty(ref _sRD1RotationCurrentStation, value); }
  166. }
  167. #endregion
  168. #region SRD2Arm
  169. /// <summary>
  170. /// SRD2Arm名称
  171. /// </summary>
  172. public string SRD2ArmModuleName
  173. {
  174. get { return _sRD2ArmModuleName; }
  175. set { SetProperty(ref _sRD2ArmModuleName, value); }
  176. }
  177. /// <summary>
  178. /// SRD2Arm运动数据
  179. /// </summary>
  180. public CommandMotionData SRD2ArmMotionData
  181. {
  182. get { return _sRD2ArmMotionData; }
  183. set { SetProperty(ref _sRD2ArmMotionData, value); }
  184. }
  185. /// <summary>
  186. /// SRD2Arm当前位置
  187. /// </summary>
  188. public string SRD2ArmCurrentStation
  189. {
  190. get { return _sRD2ArmCurrentStation; }
  191. set { SetProperty(ref _sRD2ArmCurrentStation, value); }
  192. }
  193. #endregion
  194. #region SRD2Rotation
  195. /// <summary>
  196. /// SRD2Rotation名称
  197. /// </summary>
  198. public string SRD2RotationModuleName
  199. {
  200. get { return _sRD2RotationModuleName; }
  201. set { SetProperty(ref _sRD2RotationModuleName, value); }
  202. }
  203. /// <summary>
  204. /// SRD1Rotation运动数据
  205. /// </summary>
  206. public CommandMotionData SRD2RotationMotionData
  207. {
  208. get { return _sRD2RotationMotionData; }
  209. set { SetProperty(ref _sRD2RotationMotionData, value); }
  210. }
  211. /// <summary>
  212. /// SRD2Rotation当前位置
  213. /// </summary>
  214. public string SRD2RotationCurrentStation
  215. {
  216. get { return _sRD2RotationCurrentStation; }
  217. set { SetProperty(ref _sRD2RotationCurrentStation, value); }
  218. }
  219. #endregion
  220. #region AWC
  221. /// <summary>
  222. /// AWC ModuleName
  223. /// </summary>
  224. public ModuleName AWCModuleName
  225. {
  226. get { return _awcModuleName; }
  227. set { SetProperty(ref _awcModuleName, value); }
  228. }
  229. /// <summary>
  230. /// Is AWC Cycle runnning
  231. /// </summary>
  232. public bool IsAWCCycling
  233. {
  234. get { return _isAWCCycling; }
  235. set { SetProperty(ref _isAWCCycling, value); }
  236. }
  237. #endregion
  238. #endregion
  239. /// <summary>
  240. /// 构造函数
  241. /// </summary>
  242. public SRDStationSetupViewModel()
  243. {
  244. }
  245. /// <summary>
  246. /// 加载数据
  247. /// </summary>
  248. public void LoadData(string systemName)
  249. {
  250. SRD1ArmModuleName = $"{ModuleName.SRD1}.Arm";
  251. SRD1RotationModuleName = $"{ModuleName.SRD1}.Rotation";
  252. SRD2ArmModuleName = $"{ModuleName.SRD2}.Arm";
  253. SRD2RotationModuleName = $"{ModuleName.SRD2}.Rotation";
  254. AddDataKeys();
  255. if (_timer == null)
  256. {
  257. _timer = new DispatcherTimer();
  258. _timer.Interval = TimeSpan.FromMilliseconds(200);
  259. _timer.Tick += Timer_Tick; ;
  260. }
  261. _timer.Start();
  262. }
  263. /// <summary>
  264. /// 定时器执行
  265. /// </summary>
  266. /// <param name="sender"></param>
  267. /// <param name="e"></param>
  268. private void Timer_Tick(object sender, EventArgs e)
  269. {
  270. OnTimer();
  271. }
  272. /// <summary>
  273. /// 隐藏
  274. /// </summary>
  275. public void Hide()
  276. {
  277. if (_timer != null)
  278. {
  279. _timer.Stop();
  280. }
  281. }
  282. /// <summary>
  283. /// 初始化查询数据集合
  284. /// </summary>
  285. private void AddDataKeys()
  286. {
  287. _rtDataKeys.Clear();
  288. _rtDataKeys.Add($"{SRD1ArmModuleName}.{MOTION_DATA}");
  289. _rtDataKeys.Add($"{SRD1ArmModuleName}.{IS_SWITCH_ON}");
  290. _rtDataKeys.Add($"{SRD1ArmModuleName}.{CURRENT_STATION}");
  291. _rtDataKeys.Add($"{SRD2ArmModuleName}.{MOTION_DATA}");
  292. _rtDataKeys.Add($"{SRD2ArmModuleName}.{IS_SWITCH_ON}");
  293. _rtDataKeys.Add($"{SRD2ArmModuleName}.{CURRENT_STATION}");
  294. _rtDataKeys.Add($"{SRD1RotationModuleName}.{MOTION_DATA}");
  295. _rtDataKeys.Add($"{SRD1RotationModuleName}.{IS_SWITCH_ON}");
  296. _rtDataKeys.Add($"{SRD1RotationModuleName}.{CURRENT_STATION}");
  297. _rtDataKeys.Add($"{SRD2RotationModuleName}.{MOTION_DATA}");
  298. _rtDataKeys.Add($"{SRD2RotationModuleName}.{IS_SWITCH_ON}");
  299. _rtDataKeys.Add($"{SRD2RotationModuleName}.{CURRENT_STATION}");
  300. _rtDataKeys.Add($"{SRD2RotationModuleName}.{CURRENT_STATION}");
  301. _rtDataKeys.Add($"SRD1.IsAWCCycling");
  302. _rtDataKeys.Add($"SRD2.IsAWCCycling");
  303. }
  304. /// <summary>
  305. /// 定时器
  306. /// </summary>
  307. /// <returns></returns>
  308. private Boolean OnTimer()
  309. {
  310. if(_rtDataKeys.Count != 0)
  311. {
  312. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  313. if (_rtDataValueDic != null)
  314. {
  315. SRD1ArmMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{SRD1ArmModuleName}.{MOTION_DATA}");
  316. SRD1ArmCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{SRD1ArmModuleName}.{CURRENT_STATION}"), SRD1ArmModuleName);
  317. SRD2ArmMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{SRD2ArmModuleName}.{MOTION_DATA}");
  318. SRD2ArmCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{SRD2ArmModuleName}.{CURRENT_STATION}"), SRD2ArmModuleName);
  319. SRD1RotationMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{SRD1RotationModuleName}.{MOTION_DATA}");
  320. SRD1RotationCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{SRD1RotationModuleName}.{CURRENT_STATION}"), SRD1RotationModuleName);
  321. SRD2RotationMotionData = CommonFunction.GetValue<CommandMotionData>(_rtDataValueDic, $"{SRD2RotationModuleName}.{MOTION_DATA}");
  322. SRD2RotationCurrentStation = CommonFunction.GetCurrentStationLastContent(CommonFunction.GetValue<string>(_rtDataValueDic, $"{SRD2RotationModuleName}.{CURRENT_STATION}"), SRD2RotationModuleName);
  323. //判断AWC是否在running
  324. if(AWCModuleName == ModuleName.SRD1)
  325. {
  326. IsAWCCycling = CommonFunction.GetValue<bool>(_rtDataValueDic, $"SRD1.IsAWCCycling"); ;
  327. }else if(AWCModuleName == ModuleName.SRD2)
  328. {
  329. IsAWCCycling = CommonFunction.GetValue<bool>(_rtDataValueDic, $"SRD2.IsAWCCycling"); ;
  330. }
  331. else
  332. {
  333. IsAWCCycling = false;
  334. }
  335. }
  336. }
  337. return true;
  338. }
  339. }
  340. }