S7NetPlus / s7netplus

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

plc.WriteStruct() exception, when using bool #448

Closed uAinring closed 1 year ago

uAinring commented 1 year ago

S7.Net Runtime Version: v4.0.30319 Version 0.14.0.0 ` public struct sDB3 { public byte start; public byte cancel; public byte ok; public byte nok; public bool masterReady;

        public sDB3(byte s, byte c, byte o, byte n, bool mr)
        {
            this.start = s;
            this.cancel = c;
            this.ok = o;
            this.nok = n;
            this.masterReady = mr;
        }
    }

sDB3 db3 = new sDB3((byte)0x10, (byte)0x20, (byte)0x30, (byte)0x40, false);
plc.WriteStruct(db3, 3, 0);

S7.Net throws Exception: array out of bounds. at S7.Net.Types.Struct.ToBytes(Object structValue).

Hint: when I set the bool to type byte everything works fine.

Uwe

uAinring commented 1 year ago

Initial problem was, that GefFields() somehow always returns zero. After recompilation of S7 dll issue disappeared.