版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

77 строки
3.1 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 MaiMuAOI.SysUI.StepUI.PropExtend;
  9. using Newtonsoft.Json;
  10. using Newtonsoft.Json.Serialization;
  11. using static ProductionControl.UI.UIAxisDev;
  12. namespace ProductionControl.UI
  13. {
  14. //[TypeConverter(typeof(PropertySorter))] //此属性使类无法序列化和反序列化
  15. public class TensionDevProp
  16. {
  17. public TensionDevProp(int portNum) {
  18. PortNum = portNum;
  19. }
  20. [PropertyOrder(1), Browsable(true), Category("1 设备"), DisplayName("端口号"), Description("端口号"), ReadOnly(true), JsonIgnore]
  21. public int PortNum { get;private set; }
  22. //
  23. [PropertyOrder(11), Browsable(true), Category("2 数据"), DisplayName("单位"), Description("单位"), ReadOnly(true), JsonIgnore]
  24. public string Unit { get; set; }
  25. [PropertyOrder(12), Browsable(true), Category("2 数据"), DisplayName("张力值"), Description("张力值"), ReadOnly(true), JsonIgnore]
  26. public double TensionValue { get; set; }
  27. [PropertyOrder(91), Browsable(true), Category("3 阀值"), DisplayName("阀值上限"), Description("阀值上限")]
  28. public double LimitThresholdVal { get; set; }
  29. [PropertyOrder(92), Browsable(true), Category("3 阀值"), DisplayName("阀值下限"), Description("阀值下限")]
  30. public double LowerThresholdVal { get; set; }
  31. [PropertyOrder(25), Browsable(true), Category("4 控制"), DisplayName("4.1 运行前Sleep(ms)"), Description("休息时间")]
  32. public uint SleepPre { get; set; }
  33. [PropertyOrder(26), Browsable(true), Category("4 控制"), DisplayName("4.2 运行后Sleep(ms)"), Description("休息时间")]
  34. public uint SleepLater { get; set; }
  35. [PropertyOrder(27), Browsable(true), Category("4 控制"), DisplayName("4.4 禁用工序"), Description("禁用本工序(True-是;False-否)")]
  36. public bool Disable { get; set; }
  37. /// <summary>
  38. /// 序列化
  39. /// </summary>
  40. /// <param name="obj"></param>
  41. /// <returns></returns>
  42. public string serialize()
  43. {
  44. return JsonConvert.SerializeObject(this);
  45. }
  46. /// <summary>
  47. /// 反序列化
  48. /// </summary>
  49. /// <param name="json"></param>
  50. /// <returns></returns>
  51. public void deserialize(string json)
  52. {
  53. var o= JsonConvert.DeserializeObject<TensionDevProp>(json);
  54. Type type = o.GetType();
  55. System.Reflection.PropertyInfo[] properties = type.GetProperties();
  56. foreach (System.Reflection.PropertyInfo property in properties)
  57. {
  58. string name = property.Name;
  59. if (!type.GetProperty(name).IsDefined(typeof(JsonIgnoreAttribute), true))
  60. {
  61. var value = property.GetValue(o);
  62. this.GetType().GetProperty(name).SetValue(this, value);
  63. }
  64. }
  65. }
  66. }
  67. }