diff --git a/S7.Net/PlcAsynchronous.cs b/S7.Net/PlcAsynchronous.cs index 387e610..ada92cf 100644 --- a/S7.Net/PlcAsynchronous.cs +++ b/S7.Net/PlcAsynchronous.cs @@ -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]); } diff --git a/S7.Net/Types/Int.cs b/S7.Net/Types/Int.cs index d16d0fd..5489691 100644 --- a/S7.Net/Types/Int.cs +++ b/S7.Net/Types/Int.cs @@ -10,15 +10,15 @@ namespace S7.Net.Types /// /// Converts a S7 Int (2 bytes) to short (Int16) /// - 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)); }