版博士V2.0程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

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