AxisManager.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Core.Util;
  3. using CyberX8_RT.Devices.AXIS.CANOpen;
  4. using CyberX8_RT.Devices.AXIS.Yaskawa;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using static Mono.Security.X509.X520;
  12. namespace CyberX8_RT.Devices.AXIS
  13. {
  14. public class AxisManager : Singleton<AxisManager>
  15. {
  16. /// <summary>
  17. /// 模块电机字典
  18. /// </summary>
  19. private Dictionary<string, List<JetAxisBase>> _moduleAxisDictionary = new Dictionary<string, List<JetAxisBase>>();
  20. /// <summary>
  21. /// 获取Axis对象
  22. /// </summary>
  23. /// <param name="type"></param>
  24. /// <param name="module"></param>
  25. /// <param name="name"></param>
  26. /// <returns></returns>
  27. public JetAxisBase GetAxisInstance(string type,string module,string name)
  28. {
  29. switch(type)
  30. {
  31. case "Copley":
  32. return new CanOpenAxis(module, name);
  33. case "Yaskawa":
  34. return new YaskawaAxis(module, name);
  35. case "Maxon":
  36. return new MaxonAxis(module, name);
  37. default:
  38. return null;
  39. }
  40. }
  41. /// <summary>
  42. /// 将Axis增加至模块字典
  43. /// </summary>
  44. /// <param name="moduleName"></param>
  45. /// <param name="axis"></param>
  46. public void AddModuleAxis(string moduleName, JetAxisBase axis)
  47. {
  48. if (_moduleAxisDictionary.ContainsKey(moduleName))
  49. {
  50. List<JetAxisBase> lst=_moduleAxisDictionary[moduleName];
  51. if(lst.FindIndex(O=>O.Name==axis.Name&&O.Module==moduleName)==-1)
  52. {
  53. lst.Add(axis);
  54. }
  55. }
  56. else
  57. {
  58. List<JetAxisBase> lst = new List<JetAxisBase>();
  59. lst.Add(axis);
  60. _moduleAxisDictionary[moduleName] = lst;
  61. }
  62. }
  63. /// <summary>
  64. /// 获取模块电机集合
  65. /// </summary>
  66. /// <returns></returns>
  67. public List<JetAxisBase> GetModuleAxisList(string moduleName)
  68. {
  69. return _moduleAxisDictionary.ContainsKey(moduleName) ? _moduleAxisDictionary[moduleName]:null;
  70. }
  71. /// <summary>
  72. /// 检验模块电机是否均上电
  73. /// </summary>
  74. /// <returns></returns>
  75. public bool CheckModuleAxisSwitchOn(string module,string name)
  76. {
  77. List<JetAxisBase> axises = AxisManager.Instance.GetModuleAxisList(module);
  78. if (axises != null)
  79. {
  80. foreach (JetAxisBase axis in axises)
  81. {
  82. if (!axis.IsSwitchOn)
  83. {
  84. LOG.WriteLog(eEvent.ERROR_PUF_NOT_SWITCHON, $"{module}.{name}", $"{axis.Name} is switch off");
  85. return false;
  86. }
  87. }
  88. }
  89. return true;
  90. }
  91. }
  92. }