版博士V2.0程序
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

76 Zeilen
3.0 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 AssistClient.UI.PropExtend;
  12. using static AssistClient.Device.ScannerDev;
  13. using static AssistClient.UI.UIAxisDev;
  14. namespace AssistClient.UI
  15. {
  16. //[TypeConverter(typeof(PropertySorter))] //此属性使类无法序列化和反序列化
  17. public class ScannerDevProp
  18. {
  19. public ScannerDevProp(ScannerType devType) {
  20. DeviceType=devType;
  21. }
  22. [PropertyOrder(1), Browsable(true), Category("1 设备"), DisplayName("设备类型"), Description("设备类型"), ReadOnly(true)]
  23. public ScannerType DeviceType { get;set; }
  24. [PropertyOrder(1), Browsable(true), Category("2 图像"), DisplayName("图像名称"), Description("图像名称"), ReadOnly(true), JsonIgnore]
  25. public string[] ImageList { get; set; }
  26. //
  27. [PropertyOrder(11), Browsable(true), Category("3 参数"), DisplayName("曝光"), Description("曝光")]
  28. public float ExposureTime { get; set; }
  29. [PropertyOrder(12), Browsable(true), Category("3 参数"), DisplayName("增益"), Description("增益")]
  30. public float Gain { get; set; }
  31. [PropertyOrder(13), Browsable(true), Category("3 参数"), DisplayName("帧率"), Description("帧率")]
  32. public float ResultingFrameRate { 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("禁用本工序")]
  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<ScannerDevProp>(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. }