mirror of
https://github.com/S7NetPlus/s7netplus.git
synced 2026-02-17 22:38:27 +08:00
Merge pull request #43 from watashimeandeu/master
Read struct and multiple bytes from a specific start bytes address.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user