Read struct and multiple bytes from a specific start bytes address.

This commit is contained in:
Marcos Pereira
2016-02-23 09:09:12 +00:00
parent 849b94d401
commit 6cff54514f
2 changed files with 26 additions and 6 deletions

View File

@@ -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<byte> resultBytes = ReadMultipleBytes(numBytes, db);
List<byte> resultBytes = ReadMultipleBytes(numBytes, db, startByteAdr);
// and decode it
return Types.Struct.FromBytes(structType, resultBytes.ToArray());
}
@@ -851,9 +856,14 @@ namespace S7.Net
/// <param name="db"></param>
/// <returns></returns>
private List<byte> ReadMultipleBytes(int numBytes, int db)
{
return ReadMultipleBytes(numBytes, db, 0);
}
private List<byte> ReadMultipleBytes(int numBytes, int db, int startByteAdr)
{
List<byte> resultBytes = new List<byte>();
int index = 0;
int index = startByteAdr;
while (numBytes > 0)
{
var maxToRead = (int)Math.Min(numBytes, 200);

View File

@@ -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<byte> resultBytes = ReadMultipleBytes(numBytes, db);
List<byte> resultBytes = ReadMultipleBytes(numBytes, db, startByteAdr);
// and decode it
return Types.Struct.FromBytes(structType, resultBytes.ToArray());
}
@@ -851,9 +856,14 @@ namespace S7.Net
/// <param name="db"></param>
/// <returns></returns>
private List<byte> ReadMultipleBytes(int numBytes, int db)
{
return ReadMultipleBytes(numBytes, db, 0);
}
private List<byte> ReadMultipleBytes(int numBytes, int db, int startByteAdr)
{
List<byte> resultBytes = new List<byte>();
int index = 0;
int index = startByteAdr;
while (numBytes > 0)
{
var maxToRead = (int)Math.Min(numBytes, 200);