版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

119 rivejä
6.8 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Xml.Linq;
  8. using Advantech.Motion;
  9. using Newtonsoft.Json;
  10. using Newtonsoft.Json.Serialization;
  11. using ProductionControl.UI.PropExtend;
  12. using static ProductionControl.UI.UIAxisDev;
  13. namespace ProductionControl.UI
  14. {
  15. //[TypeConverter(typeof(PropertySorter))] //此属性使类无法序列化和反序列化
  16. public class AxisDevProp
  17. {
  18. [PropertyOrder(1), Browsable(true), Category("1 设备"), DisplayName("1.0 轴索引"), Description("Axis0-X0轴; Axis1-X1轴; Axis2-Y轴; Axis3-Z轴")]
  19. public AxisName AxisIndex { get; set; }
  20. [PropertyOrder(1), Browsable(true), Category("1 设备"), DisplayName("1.1 保存此轴设置"), Description("保存此轴设置供流程使用(True-是;False-否)")]//JsonIgnore 不好加,切换时不好判断
  21. public bool Enable { get; set; }//后加,有可能为空
  22. //[PropertyOrder(2), Browsable(true), Category("设备"), DisplayName("类型"), Description("类型")]
  23. //public AxisType DeviceType { get; set; }
  24. //[PropertyOrder(2), Browsable(true), Category("设备"), DisplayName("回原点模式"), Description("回原点模式"), ReadOnly(true), JsonIgnore]
  25. //public AxitHomeMode HomeMode { get; set; }
  26. //
  27. [PropertyOrder(11), Browsable(true), Category("2 速度"), DisplayName("2.1 起始速度(mm/s)"), Description("起始速度")]
  28. public double VelLow { get; set; }
  29. [PropertyOrder(12), Browsable(true), Category("2 速度"), DisplayName("2.2 运行速度(mm/s)"), Description("运行速度")]
  30. public double VelHigh { get; set; }
  31. [PropertyOrder(13), Browsable(true), Category("2 速度"), DisplayName("2.3 加速度(mm/s)"), Description("加速度")]
  32. public double Acc { get; set; }
  33. [PropertyOrder(14), Browsable(true), Category("2 速度"), DisplayName("2.4 减速度(mm/s)"), Description("减速度")]
  34. public double Dec { get; set; }
  35. //----
  36. [PropertyOrder(21), Browsable(true), Category("3 位置"), DisplayName("3.1 运动模式"), Description("运动模式")]
  37. public AxMoveMode MoveMode { get; set; } = AxMoveMode.相对位置;
  38. [PropertyOrder(22), Browsable(true), Category("3 位置"), DisplayName("3.2 运动距离(mm)"), Description("移动量")]
  39. public double Value { get; set; }
  40. [PropertyOrder(23), Browsable(true), Category("3 位置"), DisplayName("3.3 命令位置(mm)"), Description("命令位置"), ReadOnly(true), JsonIgnore]
  41. public double CmdPos { get; set; }
  42. [PropertyOrder(24), Browsable(true), Category("3 位置"), DisplayName("3.4 反馈位置(mm)"), Description("实际/反馈位置"), ReadOnly(true), JsonIgnore]
  43. public double ActualPos { get; set; }
  44. [PropertyOrder(25), Browsable(true), Category("4 控制"), DisplayName("4.1 运行前Sleep(ms)"), Description("休息时间")]
  45. public uint SleepPre { get; set; }
  46. [PropertyOrder(26), Browsable(true), Category("4 控制"), DisplayName("4.2 运行后Sleep(ms)"), Description("休息时间")]
  47. public uint SleepLater { get; set; }
  48. //轴组内多轴自动异步,轴组如果强制等待完成
  49. //[PropertyOrder(27), Browsable(true), Category("4 控制"), DisplayName("4.3 异步运行"), Description("非阻塞后续流程运行")]
  50. //public bool AsynRun { get; set; }
  51. [PropertyOrder(28), Browsable(true), Category("4 控制"), DisplayName("4.4 禁用工序"), Description("禁用本工序(True-是;False-否)")]
  52. public bool Disable { get; set; }
  53. //[PropertyOrder(27), Browsable(true), Category("模式"), DisplayName("脉冲输出模式"), Description("脉冲输出模式")]
  54. //public AxisPulseOutMode PulseOutMode { get; set; } = AxisPulseOutMode.O_CW_CCW;
  55. //
  56. [PropertyOrder(31), Browsable(true), Category("5 状态"), DisplayName("5.1 轴状态"), Description("轴状态"), ReadOnly(true), JsonIgnore]
  57. public AxisState AxState { get; set; }
  58. [PropertyOrder(32), Browsable(false), Category("5 状态"), DisplayName("5.2 轴IO状态"), Description("轴IO状态"), ReadOnly(true), JsonIgnore]
  59. public uint AxIOStatus { get; set; }
  60. [PropertyOrder(33), Browsable(true), Category("5 状态"), DisplayName("5.2 轴运动状态"), Description("轴运动状态"), ReadOnly(true), JsonIgnore]
  61. public uint AxMotionState { get; set; }
  62. [PropertyOrder(35), Browsable(true), Category("5 状态"), DisplayName("5.3 ALM"), Description("轴IO状态"), ReadOnly(true), JsonIgnore]
  63. public bool ALM { get; set; }
  64. [PropertyOrder(35), Browsable(true), Category("5 状态"), DisplayName("5.4 EMG"), Description("轴IO状态"), ReadOnly(true), JsonIgnore]
  65. public bool EMG { get; set; }
  66. [PropertyOrder(36), Browsable(true), Category("5 状态"), DisplayName("5.5 LMT+"), Description("轴IO状态"), ReadOnly(true), JsonIgnore]
  67. public bool LMTP { get; set; }
  68. [PropertyOrder(37), Browsable(true), Category("5 状态"), DisplayName("5.6 LMT-"), Description("轴IO状态"), ReadOnly(true), JsonIgnore]
  69. public bool LMTN { get; set; }
  70. [PropertyOrder(38), Browsable(true), Category("5 状态"), DisplayName("5.7 ORG"), Description("轴IO状态"), ReadOnly(true), JsonIgnore]
  71. public bool ORG { get; set; }
  72. [PropertyOrder(38), Browsable(true), Category("5 状态"), DisplayName("5.8 EZ"), Description("轴EZ状态"), ReadOnly(true), JsonIgnore]
  73. public bool EZ { get; set; }
  74. [PropertyOrder(39), Browsable(true), Category("5 状态"), DisplayName("5.9 SVON"), Description("轴IO状态"), ReadOnly(true), JsonIgnore]
  75. public bool SVON { get; set; }
  76. /// <summary>
  77. /// 序列化
  78. /// </summary>
  79. /// <param name="obj"></param>
  80. /// <returns></returns>
  81. public string serialize()
  82. {
  83. return JsonConvert.SerializeObject(this);
  84. }
  85. /// <summary>
  86. /// 反序列化
  87. /// </summary>
  88. /// <param name="json"></param>
  89. /// <returns></returns>
  90. public void deserialize(string json)
  91. {
  92. var o = JsonConvert.DeserializeObject<AxisDevProp>(json);
  93. Type type = o.GetType();
  94. System.Reflection.PropertyInfo[] properties = type.GetProperties();
  95. foreach (System.Reflection.PropertyInfo property in properties)
  96. {
  97. string name = property.Name;
  98. if (!type.GetProperty(name).IsDefined(typeof(JsonIgnoreAttribute), true))
  99. {
  100. var value = property.GetValue(o);
  101. this.GetType().GetProperty(name).SetValue(this, value);
  102. }
  103. }
  104. }
  105. }
  106. }