From 6cff54514fe0dc533046a10b3e06097918135015 Mon Sep 17 00:00:00 2001 From: Marcos Pereira Date: Tue, 23 Feb 2016 09:09:12 +0000 Subject: [PATCH] Read struct and multiple bytes from a specific start bytes address. --- S7.Net.Core/PLC.cs | 16 +++++++++++++--- S7.Net/PLC.cs | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/S7.Net.Core/PLC.cs b/S7.Net.Core/PLC.cs index 7936417..f7d32a9 100644 --- a/S7.Net.Core/PLC.cs +++ b/S7.Net.Core/PLC.cs @@ -507,11 +507,16 @@ namespace S7.Net } public object ReadStruct(Type structType, int db) + { + return ReadStruct(structType, db, 0); + } + + public object ReadStruct(Type structType, int db, int startByteAdr) { int numBytes = Types.Struct.GetStructSize(structType); // now read the package - List resultBytes = ReadMultipleBytes(numBytes, db); - + List resultBytes = ReadMultipleBytes(numBytes, db, startByteAdr); + // and decode it return Types.Struct.FromBytes(structType, resultBytes.ToArray()); } @@ -851,9 +856,14 @@ namespace S7.Net /// /// private List ReadMultipleBytes(int numBytes, int db) + { + return ReadMultipleBytes(numBytes, db, 0); + } + + private List ReadMultipleBytes(int numBytes, int db, int startByteAdr) { List resultBytes = new List(); - int index = 0; + int index = startByteAdr; while (numBytes > 0) { var maxToRead = (int)Math.Min(numBytes, 200); diff --git a/S7.Net/PLC.cs b/S7.Net/PLC.cs index 9374fe9..a0b4abf 100644 --- a/S7.Net/PLC.cs +++ b/S7.Net/PLC.cs @@ -507,11 +507,16 @@ namespace S7.Net } public object ReadStruct(Type structType, int db) + { + return ReadStruct(structType, db, 0); + } + + public object ReadStruct(Type structType, int db, int startByteAdr) { int numBytes = Types.Struct.GetStructSize(structType); // now read the package - List resultBytes = ReadMultipleBytes(numBytes, db); - + List resultBytes = ReadMultipleBytes(numBytes, db, startByteAdr); + // and decode it return Types.Struct.FromBytes(structType, resultBytes.ToArray()); } @@ -851,9 +856,14 @@ namespace S7.Net /// /// private List ReadMultipleBytes(int numBytes, int db) + { + return ReadMultipleBytes(numBytes, db, 0); + } + + private List ReadMultipleBytes(int numBytes, int db, int startByteAdr) { List resultBytes = new List(); - int index = 0; + int index = startByteAdr; while (numBytes > 0) { var maxToRead = (int)Math.Min(numBytes, 200);