using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using MaiMuAOI.SysCtrl;
using MaiMuAOI.SysUI.StepUI.PropExtend;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using static ProductionControl.UI.UIAxisDev;
namespace ProductionControl.UI
{
//[TypeConverter(typeof(PropertySorter))] //此属性使类无法序列化和反序列化
public class ScannerDevProp
{
public ScannerDevProp(ScannerType devType = ScannerType.GENTL) {
DeviceType=devType;
AutoFocus = true;
FocusStep = 0.02;
DirStep = 0.04;
WaitTime = 200;
TimeOut = 30000;
}
[PropertyOrder(1), Browsable(true), Category("1 设备"), DisplayName("设备类型"), Description("设备类型"), ReadOnly(true)]
public ScannerType DeviceType { get;set; }
[PropertyOrder(1), Browsable(true), Category("2 图像"), DisplayName("图像名称"), Description("图像名称"), ReadOnly(true), JsonIgnore]
public string[] ImageList { get; set; }
[PropertyOrder(1), Browsable(true), Category("2 图像"), DisplayName("AI引擎库"), Description("此照片所调用的AI库")]
public AIEngineLibEnum AIEngineLib { get; set; }
//100-9999500
[PropertyOrder(11), Browsable(true), Category("3 参数"), DisplayName("曝光"), Description("曝光时长(us)")]
public float ExposureTime { get; set; }
[PropertyOrder(12), Browsable(true), Category("3 参数"), DisplayName("增益"), Description("增益")]
public float Gain { get; set; }
[PropertyOrder(13), Browsable(true), Category("3 参数"), DisplayName("帧率"), Description("帧率")]
public float ResultingFrameRate { get; set; }
//2024-1-24
[PropertyOrder(21), Browsable(true), Category("4 聚焦"), DisplayName("4.1 开启自动聚焦"), Description("是否开启自动聚焦功能(True-是;False-否),开启后后面测试项会开始时自动聚焦一次")]
public bool AutoFocus { get; set; }
[PropertyOrder(22), Browsable(true), Category("4 聚焦"), DisplayName("4.2 聚焦步进(mm)"), Description("每次聚焦的步进长度")]
public double FocusStep { get; set; }
[PropertyOrder(23), Browsable(true), Category("4 聚焦"), DisplayName("4.3 方向步进(mm)"), Description("寻找聚焦方向时的步进长度")]
public double DirStep { get; set; }
[PropertyOrder(24), Browsable(true), Category("4 聚焦"), DisplayName("4.4 等待稳定时间(ms)"), Description("聚焦步进之后等待稳定时间")]
public int WaitTime { get; set; }
[PropertyOrder(25), Browsable(true), Category("4 聚焦"), DisplayName("4.5 聚焦超时(ms)"), Description("自动聚焦超时报警")]
public int TimeOut { get; set; }
[PropertyOrder(35), Browsable(true), Category("5 控制"), DisplayName("5.1 运行前Sleep(ms)"), Description("休息时间")]
public uint SleepPre { get; set; }
[PropertyOrder(36), Browsable(true), Category("5 控制"), DisplayName("5.2 运行后Sleep(ms)"), Description("休息时间")]
public uint SleepLater { get; set; }
[PropertyOrder(37), Browsable(true), Category("5 控制"), DisplayName("5.4 禁用工序"), Description("禁用本工序(True-是;False-否)")]
public bool Disable { get; set; }
///
/// 序列化
///
///
///
public string serialize()
{
return JsonConvert.SerializeObject(this);
}
///
/// 反序列化
///
///
///
public void deserialize(string json)
{
var o= JsonConvert.DeserializeObject(json);
Type type = o.GetType();
System.Reflection.PropertyInfo[] properties = type.GetProperties();
foreach (System.Reflection.PropertyInfo property in properties)
{
string name = property.Name;
if (!type.GetProperty(name).IsDefined(typeof(JsonIgnoreAttribute), true))
{
var value = property.GetValue(o);
this.GetType().GetProperty(name).SetValue(this, value);
}
}
}
}
}