Exemple #1
0
        public static Memory <byte> TranslateToMemory(S7CommSetupDatagram datagram)
        {
            var result = S7HeaderDatagram.TranslateToMemory(datagram.Header);

            S7CommSetupParameterDatagram.TranslateToMemory(datagram.Parameter, result.Slice(datagram.Header.GetHeaderSize()));
            return(result);
        }
        public static IMemoryOwner <byte> TranslateToMemory(S7CommSetupDatagram datagram, out int memoryLength)
        {
            var result = S7HeaderDatagram.TranslateToMemory(datagram.Header, out memoryLength);
            var take   = memoryLength - datagram.Header.GetHeaderSize();

            S7CommSetupParameterDatagram.TranslateToMemory(datagram.Parameter, result.Memory.Slice(datagram.Header.GetHeaderSize(), take));
            return(result);
        }
        public static S7CommSetupDatagram TranslateFromMemory(Memory <byte> data)
        {
            var result = new S7CommSetupDatagram
            {
                Header = S7HeaderDatagram.TranslateFromMemory(data)
            };

            result.Parameter = S7CommSetupParameterDatagram.TranslateFromMemory(data.Slice(result.Header.GetHeaderSize()));
            return(result);
        }
        public static S7CommSetupAckDataDatagram TranslateFromMemory(Memory <byte> data)
        {
            var result = new S7CommSetupAckDataDatagram
            {
                Header = S7AckDataDatagram.TranslateFromMemory(data),
            };

            result.Parameter = S7CommSetupParameterDatagram.TranslateFromMemory(data.Slice(result.Header.GetParameterOffset()));
            return(result);
        }
Exemple #5
0
        public static Memory <byte> TranslateToMemory(S7CommSetupParameterDatagram datagram, Memory <byte> memory)
        {
            var result = memory.IsEmpty ? new Memory <byte>(new byte[2]) : memory;  // check if we could use ArrayBuffer
            var span   = result.Span;

            span[0] = datagram.Function;
            span[1] = datagram.Reserved;
            BinaryPrimitives.WriteUInt16BigEndian(span.Slice(2, 2), datagram.MaxAmQCalling);
            BinaryPrimitives.WriteUInt16BigEndian(span.Slice(4, 2), datagram.MaxAmQCalled);
            BinaryPrimitives.WriteUInt16BigEndian(span.Slice(6, 2), datagram.PduLength);

            return(result);
        }
Exemple #6
0
        public static S7CommSetupParameterDatagram TranslateFromMemory(Memory <byte> data)
        {
            var span   = data.Span;
            var result = new S7CommSetupParameterDatagram
            {
                Function      = span[0],
                Reserved      = span[1],
                MaxAmQCalling = BinaryPrimitives.ReadUInt16BigEndian(span.Slice(2, 2)),
                MaxAmQCalled  = BinaryPrimitives.ReadUInt16BigEndian(span.Slice(4, 2)),
                PduLength     = BinaryPrimitives.ReadUInt16BigEndian(span.Slice(6, 2))
            };

            return(result);
        }