版博士V2.0程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

79 rindas
3.2 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 SmallAxisDevProp
  17. {
  18. public SmallAxisDevProp( string comName) {
  19. ComName = comName;
  20. }
  21. [PropertyOrder(1), Browsable(true), Category("1 设备"), DisplayName("端口号"), Description("端口号"), ReadOnly(true), JsonIgnore]
  22. public string ComName { get;set; }
  23. //
  24. [PropertyOrder(23), Browsable(true), Category("2 位置"), DisplayName("命令脉冲"), Description("命令脉冲") ]
  25. //public SmallAxCmdPos CmdPos { get; set; }
  26. public int CmdPos { get; set; }
  27. [PropertyOrder(11), Browsable(true), Category("3 状态"), DisplayName("3.1 运动中"), Description("运动中(True-是;False-否)"), ReadOnly(true), JsonIgnore]
  28. public bool Moving { get; set; }
  29. [PropertyOrder(23), Browsable(true), Category("3 状态"), DisplayName("3.2 最大脉冲"), Description("最大脉冲"), ReadOnly(true), JsonIgnore]
  30. public int MaxPPU { get; set; }
  31. [PropertyOrder(24), Browsable(true), Category("3 状态"), DisplayName("3.3 反馈脉冲"), Description("实际/反馈脉冲"), ReadOnly(true), JsonIgnore]
  32. public int ActualPPU { get; set; }
  33. [PropertyOrder(25), Browsable(true), Category("4 控制"), DisplayName("4.1 运行前Sleep(ms)"), Description("休息时间")]
  34. public uint SleepPre { get; set; }
  35. [PropertyOrder(26), Browsable(true), Category("4 控制"), DisplayName("4.2 运行后Sleep(ms)"), Description("休息时间")]
  36. public uint SleepLater { get; set; }
  37. [PropertyOrder(27), Browsable(true), Category("4 控制"), DisplayName("4.4 禁用工序"), Description("禁用本工序(True-是;False-否)")]
  38. public bool Disable { get; set; }
  39. /// <summary>
  40. /// 序列化
  41. /// </summary>
  42. /// <param name="obj"></param>
  43. /// <returns></returns>
  44. public string serialize()
  45. {
  46. return JsonConvert.SerializeObject(this);
  47. }
  48. /// <summary>
  49. /// 反序列化
  50. /// </summary>
  51. /// <param name="json"></param>
  52. /// <returns></returns>
  53. public void deserialize(string json)
  54. {
  55. var o= JsonConvert.DeserializeObject<SmallAxisDevProp>(json);
  56. Type type = o.GetType();
  57. System.Reflection.PropertyInfo[] properties = type.GetProperties();
  58. foreach (System.Reflection.PropertyInfo property in properties)
  59. {
  60. string name = property.Name;
  61. if (!type.GetProperty(name).IsDefined(typeof(JsonIgnoreAttribute), true))
  62. {
  63. var value = property.GetValue(o);
  64. this.GetType().GetProperty(name).SetValue(this, value);
  65. }
  66. }
  67. }
  68. }
  69. }