Copy ReadBytes data in one go.

Instead of using a loop, use Array.Copy to
This commit is contained in:
Serge Camille
2020-08-17 22:09:17 +02:00
parent 688d4e2a28
commit 783c456dc9
2 changed files with 4 additions and 9 deletions

View File

@@ -388,8 +388,6 @@ namespace S7.Net
{
var stream = GetStreamIfAvailable();
byte[] bytes = new byte[count];
// first create the header
int packageSize = 31;
var package = new System.IO.MemoryStream(packageSize);
@@ -403,9 +401,8 @@ namespace S7.Net
var s7data = await COTP.TSDU.ReadAsync(stream);
AssertReadResponse(s7data, count);
for (int cnt = 0; cnt < count; cnt++)
bytes[cnt] = s7data[cnt + 18];
var bytes = new byte[count];
Array.Copy(s7data, 18, bytes, 0, count);
return bytes;
}

View File

@@ -344,7 +344,6 @@ namespace S7.Net
private byte[] ReadBytesWithSingleRequest(DataType dataType, int db, int startByteAdr, int count)
{
var stream = GetStreamIfAvailable();
byte[] bytes = new byte[count];
try
{
// first create the header
@@ -360,9 +359,8 @@ namespace S7.Net
var s7data = COTP.TSDU.Read(stream);
AssertReadResponse(s7data, count);
for (int cnt = 0; cnt < count; cnt++)
bytes[cnt] = s7data[cnt + 18];
var bytes = new byte[count];
Array.Copy(s7data, 18, bytes, 0, count);
return bytes;
}
catch (Exception exc)