版博士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.
 
 
 
 

101 line
4.9 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.UIAxis;
  13. namespace ProductionControl.UI
  14. {
  15. //[TypeConverter(typeof(PropertySorter))] //此属性使类无法序列化和反序列化
  16. public class AxisProp
  17. {
  18. [PropertyOrder(1), Browsable(true), Category("设备"), DisplayName("轴索引"), Description("轴索引")]
  19. public AxisName AxisIndex { get; set; }
  20. [PropertyOrder(2), Browsable(true), Category("设备"), DisplayName("类型"), Description("类型")]
  21. public AxisType DeviceType { get; set; }
  22. //
  23. [PropertyOrder(11), Browsable(true), Category("速度"), DisplayName("起始速度"), Description("起始速度")]
  24. public double VelLow { get; set; }
  25. [PropertyOrder(12), Browsable(true), Category("速度"), DisplayName("运行速度"), Description("运行速度")]
  26. public double VelHigh { get; set; }
  27. [PropertyOrder(13), Browsable(true), Category("速度"), DisplayName("加速度"), Description("加速度")]
  28. public double Acc { get; set; }
  29. [PropertyOrder(14), Browsable(true), Category("速度"), DisplayName("减速度"), Description("减速度")]
  30. public double Dec { get; set; }
  31. //
  32. [PropertyOrder(21), Browsable(true), Category("位置"), DisplayName("绝对位置"), Description("绝对:true 相对:false")]
  33. public bool IsAbsPos { get; set; }
  34. [PropertyOrder(22), Browsable(true), Category("位置"), DisplayName("运动距离PPU"), Description("移动量")]
  35. public int Value { get; set; }
  36. [PropertyOrder(23), Browsable(true), Category("位置"), DisplayName("命令位置"), Description("命令位置"), ReadOnly(true), JsonIgnore]
  37. public double CmdPos { get; set; }
  38. [PropertyOrder(24), Browsable(true), Category("位置"), DisplayName("反馈位置"), Description("实际/反馈位置"), ReadOnly(true), JsonIgnore]
  39. public double ActualPos { get; set; }
  40. //
  41. [PropertyOrder(31), Browsable(true), Category("状态"), DisplayName("轴状态"), Description("轴状态"), ReadOnly(true), JsonIgnore]
  42. public AxisState AxState { get; set; }
  43. [PropertyOrder(32), Browsable(false), Category("状态"), DisplayName("轴IO状态"), Description("轴IO状态"), ReadOnly(true), JsonIgnore]
  44. public uint AxIOStatus { get; set; }
  45. [PropertyOrder(33), Browsable(true), Category("状态"), DisplayName("轴运动状态"), Description("轴运动状态"), ReadOnly(true), JsonIgnore]
  46. public uint AxMotionState { get; set; }
  47. [PropertyOrder(35), Browsable(true), Category("状态"), DisplayName("ALM"), Description("轴IO状态"), ReadOnly(true), JsonIgnore]
  48. public bool ALM { get; set; }
  49. [PropertyOrder(35), Browsable(true), Category("状态"), DisplayName("EMG"), Description("轴IO状态"), ReadOnly(true), JsonIgnore]
  50. public bool EMG { get; set; }
  51. [PropertyOrder(36), Browsable(true), Category("状态"), DisplayName("LMT+"), Description("轴IO状态"), ReadOnly(true), JsonIgnore]
  52. public bool LMTP { get; set; }
  53. [PropertyOrder(37), Browsable(true), Category("状态"), DisplayName("LMT-"), Description("轴IO状态"), ReadOnly(true), JsonIgnore]
  54. public bool LMTN { get; set; }
  55. [PropertyOrder(38), Browsable(true), Category("状态"), DisplayName("ORG"), Description("轴IO状态"), ReadOnly(true), JsonIgnore]
  56. public bool ORG { get; set; }
  57. [PropertyOrder(39), Browsable(true), Category("状态"), DisplayName("SVON"), Description("轴IO状态"), ReadOnly(true), JsonIgnore]
  58. public bool SVON { get; set; }
  59. /// <summary>
  60. /// 序列化
  61. /// </summary>
  62. /// <param name="obj"></param>
  63. /// <returns></returns>
  64. public string serialize()
  65. {
  66. return JsonConvert.SerializeObject(this);
  67. }
  68. /// <summary>
  69. /// 反序列化
  70. /// </summary>
  71. /// <param name="json"></param>
  72. /// <returns></returns>
  73. public void deserialize(string json)
  74. {
  75. var o = JsonConvert.DeserializeObject<IOCardProp>(json);
  76. Type type = o.GetType();
  77. System.Reflection.PropertyInfo[] properties = type.GetProperties();
  78. foreach (System.Reflection.PropertyInfo property in properties)
  79. {
  80. string name = property.Name;
  81. if (!type.GetProperty(name).IsDefined(typeof(JsonIgnoreAttribute), true))
  82. {
  83. var value = property.GetValue(o);
  84. this.GetType().GetProperty(name).SetValue(this, value);
  85. }
  86. }
  87. }
  88. }
  89. }