Revert MaxPDUSize parse change.

This commit is contained in:
Serge Camille
2020-09-16 22:28:42 +02:00
parent 80ad95372b
commit 4a72c3596b
2 changed files with 5 additions and 9 deletions

View File

@@ -79,11 +79,7 @@ namespace S7.Net
throw new WrongNumberOfBytesException("Not enough data received in response to Communication Setup");
// TODO: check if this should not rather be UInt16.
MaxPDUSize = Types.Int.FromByteArray(s7data, 18);
if (MaxPDUSize <= 0 )
{
throw new PlcException(ErrorCode.ConnectionError, "Communication Setup resulted in non-positive PDU size.");
}
MaxPDUSize = (short)(s7data[18] * 256 + s7data[19]);
}

View File

@@ -10,15 +10,15 @@ namespace S7.Net.Types
/// <summary>
/// Converts a S7 Int (2 bytes) to short (Int16)
/// </summary>
public static short FromByteArray(byte[] bytes, int offset = 0)
public static short FromByteArray(byte[] bytes)
{
if (bytes.Length < offset + 2)
if (bytes.Length != 2)
{
throw new ArgumentException($"Wrong number of bytes. Bytes array must contain at least {offset+2} bytes.");
throw new ArgumentException("Wrong number of bytes. Bytes array must contain 2 bytes.");
}
// bytes[0] -> HighByte
// bytes[1] -> LowByte
return (short)(bytes[offset + 1] | (bytes[offset + 0] << 8));
return (short)((int)(bytes[1]) | ((int)(bytes[0]) << 8));
}