VpDeviceTimer.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.Util;
  3. using MECF.Framework.Common.Equipment;
  4. using MECF.Framework.Common.ToolLayout;
  5. using PunkHPX8_RT.Devices.AXIS;
  6. using PunkHPX8_RT.Devices.SRD;
  7. using PunkHPX8_RT.Devices.VpwCell;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace PunkHPX8_RT.Devices.VpwMain
  14. {
  15. public class VpDeviceTimer : BaseDevice, IDevice
  16. {
  17. #region 常量
  18. private const string VPW = "Vpw";
  19. #endregion
  20. #region 内部变量
  21. private PeriodicJob _periodicJob;
  22. private VpwMainDevice _vpwMainDevice;
  23. private VpwCellDevice[] _vpwCellDevices;
  24. #endregion
  25. /// <summary>
  26. /// 构造函数
  27. /// </summary>
  28. public VpDeviceTimer() : base(VPW, VPW, VPW, VPW)
  29. {
  30. _periodicJob = new PeriodicJob(20, OnTimer, $"{VPW}.OnTimer", false);
  31. }
  32. /// <summary>
  33. /// 初始化
  34. /// </summary>
  35. /// <returns></returns>
  36. public bool Initialize()
  37. {
  38. if (ModuleHelper.IsInstalled(ModuleName.VPWMain1))
  39. {
  40. _vpwMainDevice=DEVICE.GetDevice<VpwMainDevice>(ModuleName.VPWMain1.ToString());
  41. }
  42. List<string> installedCells = VpwCellItemManager.Instance.InstalledModules;
  43. _vpwCellDevices=new VpwCellDevice[installedCells.Count];
  44. for (int i=0;i<_vpwCellDevices.Length;i++)
  45. {
  46. _vpwCellDevices[i] = DEVICE.GetDevice<VpwCellDevice>(installedCells[i]);
  47. }
  48. _periodicJob.Start();
  49. return true;
  50. }
  51. public void Monitor()
  52. {
  53. }
  54. public void Reset()
  55. {
  56. }
  57. public void Terminate()
  58. {
  59. _periodicJob.Stop();
  60. }
  61. /// <summary>
  62. /// 定时器执行
  63. /// </summary>
  64. /// <returns></returns>
  65. private bool OnTimer()
  66. {
  67. if (_vpwMainDevice != null)
  68. {
  69. _vpwMainDevice.OnTimer();
  70. }
  71. foreach(var item in _vpwCellDevices)
  72. {
  73. item.OnTimer();
  74. }
  75. return true;
  76. }
  77. }
  78. }