版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

79 lines
3.3 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.Device.ScannerDev;
  13. using static ProductionControl.UI.UIAxisDev;
  14. namespace ProductionControl.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. [PropertyOrder(1), Browsable(true), Category("2 图像"), DisplayName("AI引擎库"), Description("此照片所调用的AI库")]
  27. public AIEngineLibEnum AIEngineLib { get; set; }
  28. //100-9999500
  29. [PropertyOrder(11), Browsable(true), Category("3 参数"), DisplayName("曝光"), Description("曝光时长(us)")]
  30. public float ExposureTime { get; set; }
  31. [PropertyOrder(12), Browsable(true), Category("3 参数"), DisplayName("增益"), Description("增益")]
  32. public float Gain { get; set; }
  33. [PropertyOrder(13), Browsable(true), Category("3 参数"), DisplayName("帧率"), Description("帧率")]
  34. public float ResultingFrameRate { get; set; }
  35. [PropertyOrder(25), Browsable(true), Category("4 控制"), DisplayName("4.1 运行前Sleep(ms)"), Description("休息时间")]
  36. public uint SleepPre { get; set; }
  37. [PropertyOrder(26), Browsable(true), Category("4 控制"), DisplayName("4.2 运行后Sleep(ms)"), Description("休息时间")]
  38. public uint SleepLater { get; set; }
  39. [PropertyOrder(27), Browsable(true), Category("4 控制"), DisplayName("4.4 禁用工序"), Description("禁用本工序(True-是;False-否)")]
  40. public bool Disable { get; set; }
  41. /// <summary>
  42. /// 序列化
  43. /// </summary>
  44. /// <param name="obj"></param>
  45. /// <returns></returns>
  46. public string serialize()
  47. {
  48. return JsonConvert.SerializeObject(this);
  49. }
  50. /// <summary>
  51. /// 反序列化
  52. /// </summary>
  53. /// <param name="json"></param>
  54. /// <returns></returns>
  55. public void deserialize(string json)
  56. {
  57. var o= JsonConvert.DeserializeObject<ScannerDevProp>(json);
  58. Type type = o.GetType();
  59. System.Reflection.PropertyInfo[] properties = type.GetProperties();
  60. foreach (System.Reflection.PropertyInfo property in properties)
  61. {
  62. string name = property.Name;
  63. if (!type.GetProperty(name).IsDefined(typeof(JsonIgnoreAttribute), true))
  64. {
  65. var value = property.GetValue(o);
  66. this.GetType().GetProperty(name).SetValue(this, value);
  67. }
  68. }
  69. }
  70. }
  71. }