diff --git a/Modbus.Net/Modbus.Net/BaseMachine.cs b/Modbus.Net/Modbus.Net/BaseMachine.cs index 7cedbb7..022d544 100644 --- a/Modbus.Net/Modbus.Net/BaseMachine.cs +++ b/Modbus.Net/Modbus.Net/BaseMachine.cs @@ -468,18 +468,6 @@ namespace Modbus.Net { return BaseUtility.Disconnect(); } - - /// - /// 将获取的数据转换成可以向设备写入的数据格式 - /// - /// 获取的数据 - /// 写入的数据 - public static Dictionary MapGetValuesToSetValues(Dictionary getValues) - { - if (getValues == null) return null; - return (from getValue in getValues where getValue.Value.PlcValue != null - select new KeyValuePair(getValue.Key, getValue.Value.PlcValue.Value)).ToDictionary(p=>p.Key,p=>p.Value); - } } public class BaseMachineEqualityComparer : IEqualityComparer diff --git a/Modbus.Net/Modbus.Net/BaseMachineExtend.cs b/Modbus.Net/Modbus.Net/BaseMachineExtend.cs new file mode 100644 index 0000000..68c49e9 --- /dev/null +++ b/Modbus.Net/Modbus.Net/BaseMachineExtend.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Modbus.Net +{ + public static class BaseMachineExtend + { + /// + /// 将获取的数据转换成可以向设备写入的数据格式 + /// + /// 获取的数据 + /// 写入的数据 + public static Dictionary MapGetValuesToSetValues(this Dictionary getValues) + { + if (getValues == null) return null; + return (from getValue in getValues + where getValue.Value.PlcValue != null + select new KeyValuePair(getValue.Key, getValue.Value.PlcValue.Value)).ToDictionary(p => p.Key, p => p.Value); + } + } +} diff --git a/Modbus.Net/Modbus.Net/Modbus.Net.csproj b/Modbus.Net/Modbus.Net/Modbus.Net.csproj index 8f976de..fe07a8d 100644 --- a/Modbus.Net/Modbus.Net/Modbus.Net.csproj +++ b/Modbus.Net/Modbus.Net/Modbus.Net.csproj @@ -54,6 +54,7 @@ + diff --git a/Modbus.Net/NA200H.UI.WPF/MainWindow.xaml.cs b/Modbus.Net/NA200H.UI.WPF/MainWindow.xaml.cs index b4e0c9c..c8a6cbd 100644 --- a/Modbus.Net/NA200H.UI.WPF/MainWindow.xaml.cs +++ b/Modbus.Net/NA200H.UI.WPF/MainWindow.xaml.cs @@ -65,8 +65,7 @@ namespace NA200H.UI.WPF machine.AddressCombiner = new AddressCombinerContinus(machine.AddressTranslator); machine.AddressCombinerSet = new AddressCombinerContinus(machine.AddressTranslator); } - var result = machine.GetDatas(MachineGetDataType.CommunicationTag); - var resultFormat = BaseMachine.MapGetValuesToSetValues(result); + var resultFormat = machine.GetDatas(MachineGetDataType.CommunicationTag).MapGetValuesToSetValues(); SetValue(new ushort[4] {(ushort)resultFormat["Add1"], (ushort)resultFormat["Add2"], (ushort)resultFormat["Add3"], (ushort)resultFormat["Ans"]}); }