VpwDeviceTimer.cs 2.2 KB

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