diff --git a/S7.Net.UnitTest/S7NetTestsSync.cs b/S7.Net.UnitTest/S7NetTestsSync.cs index 85e22461..7128a6ce 100644 --- a/S7.Net.UnitTest/S7NetTestsSync.cs +++ b/S7.Net.UnitTest/S7NetTestsSync.cs @@ -1015,6 +1015,17 @@ public void T26_ReadWriteDouble() Assert.AreEqual(test_value, result, "Compare Write/Read"); } + [TestMethod] + public void T26_ReadWriteDoubles() + { + double[] test_values = [ 55.66, 89.88 ]; + plc.Write(DataType.DataBlock, 1, 0, test_values); + var result = (double[])plc.Read(DataType.DataBlock, 1, 0, VarType.LReal, 2); + + Assert.AreEqual(test_values[0], result[0], "Compare Write/Read 0"); + Assert.AreEqual(test_values[1], result[1], "Compare Write/Read 1"); + } + [TestMethod] public void T27_ReadWriteBytesMany() { diff --git a/S7.Net/Types/TypeHelper.cs b/S7.Net/Types/TypeHelper.cs index af5441b1..68c93bf2 100644 --- a/S7.Net/Types/TypeHelper.cs +++ b/S7.Net/Types/TypeHelper.cs @@ -11,11 +11,12 @@ internal static class TypeHelper /// public static byte[] ToByteArray(T[] value, Func converter) where T : struct { - var buffer = new byte[Marshal.SizeOf(default(T)) * value.Length]; + var typeSize = Marshal.SizeOf(default(T)); + var buffer = new byte[typeSize * value.Length]; var stream = new MemoryStream(buffer); foreach (var val in value) { - stream.Write(converter(val), 0, 4); + stream.Write(converter(val), 0, typeSize); } return buffer;