banboshi_V1/halftoneproject-master/Code/UI/TensionDevProp.cs
2023-10-31 13:19:29 +08:00

78 lines
3.1 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using Advantech.Motion;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using ProductionControl.UI.PropExtend;
using static ProductionControl.UI.UIAxisDev;
namespace ProductionControl.UI
{
//[TypeConverter(typeof(PropertySorter))] //此属性使类无法序列化和反序列化
public class TensionDevProp
{
public TensionDevProp(int portNum) {
PortNum = portNum;
}
[PropertyOrder(1), Browsable(true), Category("1 设备"), DisplayName("端口号"), Description("端口号"), ReadOnly(true), JsonIgnore]
public int PortNum { get;private set; }
//
[PropertyOrder(11), Browsable(true), Category("2 数据"), DisplayName("单位"), Description("单位"), ReadOnly(true), JsonIgnore]
public string Unit { get; set; }
[PropertyOrder(12), Browsable(true), Category("2 数据"), DisplayName("张力值"), Description("张力值"), ReadOnly(true), JsonIgnore]
public double TensionValue { get; set; }
[PropertyOrder(91), Browsable(true), Category("3 阀值"), DisplayName("阀值上限"), Description("阀值上限")]
public double LimitThresholdVal { get; set; }
[PropertyOrder(92), Browsable(true), Category("3 阀值"), DisplayName("阀值下限"), Description("阀值下限")]
public double LowerThresholdVal { get; set; }
[PropertyOrder(25), Browsable(true), Category("4 控制"), DisplayName("4.1 运行前Sleep(ms)"), Description("休息时间")]
public uint SleepPre { get; set; }
[PropertyOrder(26), Browsable(true), Category("4 控制"), DisplayName("4.2 运行后Sleep(ms)"), Description("休息时间")]
public uint SleepLater { get; set; }
[PropertyOrder(27), Browsable(true), Category("4 控制"), DisplayName("4.4 禁用工序"), Description("禁用本工序(True-是False-否)")]
public bool Disable { get; set; }
/// <summary>
/// 序列化
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public string serialize()
{
return JsonConvert.SerializeObject(this);
}
/// <summary>
/// 反序列化
/// </summary>
/// <param name="json"></param>
/// <returns></returns>
public void deserialize(string json)
{
var o= JsonConvert.DeserializeObject<TensionDevProp>(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);
}
}
}
}
}