S7NetPlus / s7netplus

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

Missing Types at Serialization #476

Open TobyStoe opened 1 year ago

TobyStoe commented 1 year ago

I tried to use the .Write Method with different Datatypes. It seems like there are missing some Datatypes for the Serialization.

S7.Net.Protocol.Serialization.SerializeValue

Missing Types are: [S7]/[C#]

mycroes commented 1 year ago

Yes, these are indeed missing. I'm quite time constrained so I won't make any promises about adding them, shouldn't be too hard to add them similar to the current implementations though.

paviano commented 1 year ago

Either a System.Boolean[]/BitArray is not supported yet. Especially to write an entire array it could be very useful. [From Stackoverflow]

internal static byte[] BoolsToByteArray(bool[] bools)
    {
        int len = bools.Length;
        int bytes = len >> 3;

        if ((len & 0x07) != 0) 
            ++bytes;

        byte[] arr2 = new byte[bytes];

        for (int i = 0; i < bools.Length; i++)
        {
            if (bools[i])
                arr2[i >> 3] |= (byte)(1 << (i & 0x07));
        }

        return arr2;
    }