| | |
| | | /// IO点的值 |
| | | /// </summary> |
| | | [Category("IO配置")] |
| | | [Description("IO数值")] |
| | | public virtual int Value { get; set; } |
| | | [Description("IO状态")] |
| | | [TypeConverter(typeof(EnumDescriptionConverter<IOValue>))] |
| | | public virtual IOValue Value { get; set; } |
| | | |
| | | /// <summary> |
| | | /// IO点是in还是out |
| | |
| | | return false; |
| | | } |
| | | |
| | | public string GetDisplayText() |
| | | public virtual string GetDisplayText() |
| | | { |
| | | return $"{IOType.GetEnumDescription()}-{IONum}-{Value}"; |
| | | return $"{IOType.GetEnumDescription()}-{IONum}-{Value.GetEnumDescription()}"; |
| | | } |
| | | |
| | | public int GetHashCode(object obj) |
| | |
| | | public class IODefinition : IOItem |
| | | { |
| | | [Category("IO配置")] |
| | | [Description("IO预定义")] |
| | | [TypeConverter(typeof(EnumDescriptionConverter<IOPrestatement>))] |
| | | public IOPrestatement IOPreStatement { get; set; } = IOPrestatement.Customized; |
| | | |
| | | [Category("IO配置")] |
| | | [Description("IO用途描述")] |
| | | public string IODesc { get; set; } |
| | | |
| | |
| | | |
| | | [Browsable(false)] |
| | | [JsonIgnore] |
| | | public override int Value { get; set; } |
| | | public override IOValue Value { get; set; } |
| | | |
| | | public new string GetDisplayText() |
| | | public override string GetDisplayText() |
| | | { |
| | | return $"{IODesc} {IOType.GetEnumDescription()} {IONum}"; |
| | | return $"{(IOPreStatement == IOPrestatement.Customized ? IODesc : IOPreStatement.GetEnumDescription())} {IOType.GetEnumDescription()} {IONum}"; |
| | | } |
| | | } |
| | | |
| | |
| | | public IODefinition IOItem { get; set; } = new IODefinition(); |
| | | |
| | | [Category("IO操作配置")] |
| | | [Description("需要操作的IO的数值")] |
| | | public int CheckValue |
| | | [Description("需要操作的IO的状态")] |
| | | public IOValue CheckValue |
| | | { |
| | | get => IOItem.Value; |
| | | set => IOItem.Value = value; |
| | |
| | | |
| | | public string GetDisplayText() |
| | | { |
| | | return IOItem.IODesc + "-" + CheckValue; |
| | | return IOItem.IODesc + "-" + CheckValue.GetEnumDescription(); |
| | | } |
| | | } |
| | | |
| | |
| | | Dictionary<IODefinition, string> itemDict = new Dictionary<IODefinition, string>(); |
| | | public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) |
| | | { |
| | | itemDict.Clear(); |
| | | if (context.Instance is IORefrenceItem item) |
| | | { |
| | | item.IOItemSource.ForEach(i => |
| | | { |
| | | itemDict[i] = i.IODesc + "-" + i.IOType.GetEnumDescription() + "-" + i.IONum; |
| | | IODefinition temp = new IODefinition(); |
| | | temp.DataFrom(i); |
| | | itemDict[temp] = (string.IsNullOrWhiteSpace(i.IODesc) ? i.IOPreStatement.GetEnumDescription() : i.IODesc) + "|" + i.IOType.GetEnumDescription() + "|" + i.IONum; |
| | | }); |
| | | |
| | | return new StandardValuesCollection(itemDict.Keys); |
| | |
| | | /// <returns></returns> |
| | | public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) |
| | | { |
| | | var s = value.ToString().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries); |
| | | var s = value.ToString().Split(new char[] { '|' }); |
| | | |
| | | if (s.Length == 3) |
| | | { |