LinmotDeviceTimer.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using Aitex.Core.RT.Device;
  2. using Aitex.Core.Util;
  3. using MECF.Framework.Common.ToolLayout;
  4. using SecsGem.Core.ItemModel;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace CyberX8_RT.Devices.LinMot
  11. {
  12. public class LinmotDeviceTimer : BaseDevice, IDevice
  13. {
  14. #region 常量
  15. private const string LINMOT = "Linmot";
  16. #endregion
  17. #region 内部变量
  18. private PeriodicJob _periodicJob;
  19. private List<LinMotAxis> _linMotAxisList=new List<LinMotAxis>();
  20. #endregion
  21. public LinmotDeviceTimer() : base(LINMOT, LINMOT, LINMOT, LINMOT)
  22. {
  23. _periodicJob = new PeriodicJob(20, OnTimer, $"{LINMOT}.OnTimer", false);
  24. }
  25. /// <summary>
  26. /// 初始化
  27. /// </summary>
  28. /// <returns></returns>
  29. public bool Initialize()
  30. {
  31. foreach (string item in LinmotItemManager.Instance.InstalledModules)
  32. {
  33. LinmotItem linmotItem = LinmotItemManager.Instance.GetLinmotItem(item);
  34. for (int i = 0; i < linmotItem.Count; i++)
  35. {
  36. LinMotAxis linMotAxis = DEVICE.GetDevice<LinMotAxis>($"{item}-{i + 1}");
  37. _linMotAxisList.Add(linMotAxis);
  38. }
  39. }
  40. _periodicJob.Start();
  41. return true;
  42. }
  43. public void Monitor()
  44. {
  45. }
  46. public void Reset()
  47. {
  48. }
  49. /// <summary>
  50. /// 中止
  51. /// </summary>
  52. public void Terminate()
  53. {
  54. _periodicJob.Stop();
  55. }
  56. /// <summary>
  57. /// 定时器执行
  58. /// </summary>
  59. /// <returns></returns>
  60. private bool OnTimer()
  61. {
  62. foreach (LinMotAxis item in _linMotAxisList)
  63. {
  64. item.OnTimer();
  65. }
  66. return true;
  67. }
  68. }
  69. }