S7NetPlus / s7netplus

S7.NET+ -- A .NET library to connect to Siemens Step7 devices
MIT License
1.3k stars 580 forks source link

DInt.FromByteArray(byte[] bytes) may be got wrong value in Big-Endian PC #465

Closed weiwxg closed 1 year ago

weiwxg commented 1 year ago

As i saw method ReadMultipleVars() read bytes from plc and parse to Int32 use this method:

public static Int32 FromByteArray(byte[] bytes)
{
    if (bytes.Length != 4)
    {
        throw new ArgumentException("Wrong number of bytes. Bytes array must contain 4 bytes.");
    }
    return bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3];
}

it works correct now because of most of pc are Little-Endian device. Is it works for Large-Endian pc?

scamille commented 1 year ago

I am pretty sure the assumption is that S7NetPlus. only works on little endian computers. That might not be true for all platforms that .NET runs on, but it is unlikely that these more esoteric ones will be used for running S7NetPlus.