diff --git a/Net461DllTest/LogicControl/PlcLogicControl.cs b/Net461DllTest/LogicControl/PlcLogicControl.cs index 29a98dc..9ed600c 100644 --- a/Net461DllTest/LogicControl/PlcLogicControl.cs +++ b/Net461DllTest/LogicControl/PlcLogicControl.cs @@ -13,6 +13,7 @@ using Serein.Library.NodeFlow.Tool; using Serein.Library.Utils; using Serein.Library.Web; using System; +using System.Collections.Generic; using System.ComponentModel; using System.Reflection; using System.Threading.Tasks; @@ -131,19 +132,20 @@ namespace Net461DllTest.LogicControl } - + // [BindConvertor(typeof(PlcVarEnum), typeof(PlcVarConvertor))] [NodeAction(NodeType.Action, "PLC获取变量")] - public object ReadVar([BindConvertor(typeof(PlcVarEnum), typeof(PlcVarConvertor))] PlcVarInfo varInfo) + public object ReadVar(PlcVarEnum plcVarEnum) { + var varInfo = Convertor(plcVarEnum); var result = MyPlc.Read(varInfo); Console.WriteLine($"获取变量成功:({varInfo})\t result = {result}"); return result; } [NodeAction(NodeType.Action, "PLC写入变量")] - public SiemensPlcDevice WriteVar2(object value, [BindConvertor(typeof(PlcVarEnum), typeof(PlcVarConvertor))] PlcVarInfo varInfo) + public SiemensPlcDevice WriteVar2(object value, PlcVarEnum plcVarEnum) { - + var varInfo = Convertor(plcVarEnum); if (MyPlc.State == PlcState.Runing) { if (varInfo.IsProtected) @@ -164,27 +166,48 @@ namespace Net461DllTest.LogicControl } + private readonly Dictionary VarInfoDict; + public PlcVarInfo Convertor(PlcVarEnum plcVarEnum) + { + if (VarInfoDict.ContainsKey(plcVarEnum)) + { + return VarInfoDict[plcVarEnum]; + } + if (plcVarEnum == PlcVarEnum.None) + { + throw new Exception("非预期枚举值"); + } + var plcValue = EnumHelper.GetBoundValue(plcVarEnum, attr => attr.PlcInfo) + ?? throw new Exception($"获取变量异常:{plcVarEnum},没有标记PlcValueAttribute"); + if (string.IsNullOrEmpty(plcValue.VarAddress)) + { + throw new Exception($"获取变量异常:{plcVarEnum},变量地址为空"); + } + VarInfoDict.Add(plcVarEnum, plcValue); + return plcValue; + } + /// /// 转换器,用于将枚举转为自定义特性中的数据 /// - public class PlcVarConvertor: IEnumConvertor - { - public PlcVarInfo Convertor(PlcVarEnum plcVarValue) - { - if (plcVarValue == PlcVarEnum.None) - { - throw new Exception("非预期枚举值"); - } - var plcValue = EnumHelper.GetBoundValue(plcVarValue, attr => attr.PlcInfo) - ?? throw new Exception($"获取变量异常:{plcVarValue},没有标记PlcValueAttribute"); - if (string.IsNullOrEmpty(plcValue.VarAddress)) - { - throw new Exception($"获取变量异常:{plcVarValue},变量地址为空"); - } - return plcValue; - } + //public class PlcVarConvertor: IEnumConvertor + //{ + // public PlcVarInfo Convertor(PlcVarEnum plcVarValue) + // { + // if (plcVarValue == PlcVarEnum.None) + // { + // throw new Exception("非预期枚举值"); + // } + // var plcValue = EnumHelper.GetBoundValue(plcVarValue, attr => attr.PlcInfo) + // ?? throw new Exception($"获取变量异常:{plcVarValue},没有标记PlcValueAttribute"); + // if (string.IsNullOrEmpty(plcValue.VarAddress)) + // { + // throw new Exception($"获取变量异常:{plcVarValue},变量地址为空"); + // } + // return plcValue; + // } - } + //} #endregion } diff --git a/NodeFlow/FlowEnvironment.cs b/NodeFlow/FlowEnvironment.cs index 986989f..c8887ca 100644 --- a/NodeFlow/FlowEnvironment.cs +++ b/NodeFlow/FlowEnvironment.cs @@ -755,6 +755,7 @@ namespace Serein.NodeFlow /// public bool AddInterruptExpression(string key, string expression) { + if(string.IsNullOrEmpty(expression)) return false; if (dictMonitorObjExpInterrupt.TryGetValue(key, out var condition)) { condition.Clear(); // 暂时 diff --git a/WorkBench/Themes/ObjectViewerControl.xaml.cs b/WorkBench/Themes/ObjectViewerControl.xaml.cs index 5b7570a..65390a2 100644 --- a/WorkBench/Themes/ObjectViewerControl.xaml.cs +++ b/WorkBench/Themes/ObjectViewerControl.xaml.cs @@ -314,8 +314,8 @@ namespace Serein.WorkBench.Themes #region 属性 if (member is PropertyInfo property) { - #region 集合类型 - if (typeof(IEnumerable).IsAssignableFrom(property.PropertyType) && property.GetValue(obj) is IEnumerable collection && collection is not null) + #region 集合类型(非字符串) + if (property.PropertyType != typeof(string) && typeof(IEnumerable).IsAssignableFrom(property.PropertyType) && property.GetValue(obj) is IEnumerable collection && collection is not null) { TreeViewItem memberNode = new TreeViewItem { Header = member.Name }; // 处理集合类型的属性 @@ -377,8 +377,8 @@ namespace Serein.WorkBench.Themes #region 字段 else if (member is FieldInfo field) { - #region 集合类型 - if (typeof(IEnumerable).IsAssignableFrom(field.FieldType) && field.GetValue(obj) is IEnumerable collection && collection is not null) + #region 集合类型(非字符串) + if (field.FieldType != typeof(string) && typeof(IEnumerable).IsAssignableFrom(field.FieldType) && field.GetValue(obj) is IEnumerable collection && collection is not null) { TreeViewItem memberNode = new TreeViewItem { Header = member.Name }; // 处理集合类型的字段