diff --git a/Modbus.Net/ModBus.Net/ValueHelper.cs b/Modbus.Net/ModBus.Net/ValueHelper.cs index 27e52bb..87e4dbe 100644 --- a/Modbus.Net/ModBus.Net/ValueHelper.cs +++ b/Modbus.Net/ModBus.Net/ValueHelper.cs @@ -291,6 +291,11 @@ namespace ModBus.Net return translateTarget.ToArray(); } + public object[] ByteArrayToObjectArray(byte[] contents, KeyValuePair translateTypeAndCount) + { + return ByteArrayToObjectArray(contents, new List>() {translateTypeAndCount}); + } + public object[] ByteArrayToObjectArray(byte[] contents, IEnumerable> translateTypeAndCount) { diff --git a/Modbus.Net/NA200H.UI.Console/Program.cs b/Modbus.Net/NA200H.UI.Console/Program.cs index eb1154d..d0e70c9 100644 --- a/Modbus.Net/NA200H.UI.Console/Program.cs +++ b/Modbus.Net/NA200H.UI.Console/Program.cs @@ -65,7 +65,7 @@ namespace NA200H.UI.ConsoleApp bool[] array = ValueHelper.Instance.ObjectArrayToDestinationArray( ValueHelper.Instance.ByteArrayToObjectArray(readCoilStatusOutputStruct.DataValue, - new List>() {new KeyValuePair(typeof (bool), 0x0a)})); + new KeyValuePair(typeof (bool), 0x0a))); for (int i = 0; i < array.Length; i++) { Console.WriteLine(array[i]); @@ -79,7 +79,7 @@ namespace NA200H.UI.ConsoleApp ushort[] array2 = ValueHelper.Instance.ObjectArrayToDestinationArray( ValueHelper.Instance.ByteArrayToObjectArray(readHoldRegisterOutputStruct.DataValue, - new List>() {new KeyValuePair(typeof (ushort), 8)})); + new KeyValuePair(typeof (ushort), 8))); for (int i = 0; i < array2.Length; i++) { Console.WriteLine(array2[i]); diff --git a/Modbus.Net/NA200H.UI.WPF/MainWindow.xaml.cs b/Modbus.Net/NA200H.UI.WPF/MainWindow.xaml.cs index 0dbbd47..1aed2da 100644 --- a/Modbus.Net/NA200H.UI.WPF/MainWindow.xaml.cs +++ b/Modbus.Net/NA200H.UI.WPF/MainWindow.xaml.cs @@ -47,8 +47,7 @@ namespace NA200H.UI.WPF Thread.Sleep(100); byte[] getNum = utility.GetDatas(0x02, (byte)ModbusProtocalReadDataFunctionCode.ReadHoldRegister, "10000", 4); object[] getNumObjects = - ValueHelper.Instance.ByteArrayToObjectArray(getNum, - new List>() { { new KeyValuePair(typeof(ushort), 4) } }); + ValueHelper.Instance.ByteArrayToObjectArray(getNum, new KeyValuePair(typeof(ushort), 4)); ushort[] getNumUshorts = ValueHelper.Instance.ObjectArrayToDestinationArray(getNumObjects); SetValue(getNumUshorts); }