mirror of
https://github.com/S7NetPlus/s7netplus.git
synced 2026-02-17 22:38:27 +08:00
Revert MaxPDUSize parse change.
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user