版博士V2.0程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

72 wiersze
2.5 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 SmallAxisProp
  17. {
  18. public SmallAxisProp( string comName) {
  19. ComName = comName;
  20. }
  21. [PropertyOrder(1), Browsable(true), Category("设备"), DisplayName("端口号"), Description("端口号"), ReadOnly(true), JsonIgnore]
  22. public string ComName { get;set; }
  23. //
  24. [PropertyOrder(23), Browsable(true), Category("位置"), DisplayName("命令脉冲"), Description("命令脉冲") ]
  25. public int CmdPos { get; set; }
  26. [PropertyOrder(11), Browsable(true), Category("状态"), DisplayName("运动中"), Description("运动中"), ReadOnly(true), JsonIgnore]
  27. public bool Moving { get; set; }
  28. [PropertyOrder(23), Browsable(true), Category("状态"), DisplayName("最大脉冲"), Description("最大脉冲"), ReadOnly(true), JsonIgnore]
  29. public int MaxPPU { get; set; }
  30. [PropertyOrder(24), Browsable(true), Category("状态"), DisplayName("反馈脉冲"), Description("实际/反馈脉冲"), ReadOnly(true), JsonIgnore]
  31. public int ActualPPU { get; set; }
  32. /// <summary>
  33. /// 序列化
  34. /// </summary>
  35. /// <param name="obj"></param>
  36. /// <returns></returns>
  37. public string serialize()
  38. {
  39. return JsonConvert.SerializeObject(this);
  40. }
  41. /// <summary>
  42. /// 反序列化
  43. /// </summary>
  44. /// <param name="json"></param>
  45. /// <returns></returns>
  46. public void deserialize(string json)
  47. {
  48. var o= JsonConvert.DeserializeObject<SmallAxisProp>(json);
  49. Type type = o.GetType();
  50. System.Reflection.PropertyInfo[] properties = type.GetProperties();
  51. foreach (System.Reflection.PropertyInfo property in properties)
  52. {
  53. string name = property.Name;
  54. if (!type.GetProperty(name).IsDefined(typeof(JsonIgnoreAttribute), true))
  55. {
  56. var value = property.GetValue(o);
  57. this.GetType().GetProperty(name).SetValue(this, value);
  58. }
  59. }
  60. }
  61. }
  62. }