Esempio n. 1
0
        public static Memory <byte> TranslateToMemory(S7DataItemWriteResult datagram, Memory <byte> memory)
        {
            var result = memory.IsEmpty ? new Memory <byte>(new byte[1]) : memory;  // check if we could use ArrayBuffer
            var span   = result.Span;

            span[0] = datagram.ReturnCode;

            return(result);
        }
Esempio n. 2
0
        public static Memory <byte> TranslateToMemory(S7DataItemWriteResult datagram, Memory <byte> memory)
        {
            var result = memory.IsEmpty ? new Memory <byte>(new byte[1]) : memory;  // normaly the got the memory, to the allocation should not occure
            var span   = result.Span;

            span[0] = datagram.ReturnCode;

            return(result);
        }
Esempio n. 3
0
        public static S7DataItemWriteResult TranslateFromMemory(Memory <byte> data)
        {
            var span   = data.Span;
            var result = new S7DataItemWriteResult
            {
                ReturnCode = span[0]
            };

            return(result);
        }
Esempio n. 4
0
        public static Memory <byte> TranslateToMemory(S7WriteJobAckDatagram datagram)
        {
            var result = S7AckDataDatagram.TranslateToMemory(datagram.Header);
            var span   = result.Span;
            var offset = datagram.Header.Header.GetHeaderSize();

            span[offset++] = datagram.Function;
            span[offset++] = datagram.ItemCount;


            foreach (var item in datagram.Data)
            {
                S7DataItemWriteResult.TranslateToMemory(item, result.Slice(offset));
                offset += item.GetSpecificationLength();
            }

            return(result);
        }
Esempio n. 5
0
        public static IMemoryOwner <byte> TranslateToMemory(S7WriteJobAckDatagram datagram, out int memoryLength)
        {
            var result = S7AckDataDatagram.TranslateToMemory(datagram.Header, out memoryLength);
            var take   = memoryLength - datagram.Header.GetParameterOffset();
            var mem    = result.Memory.Slice(datagram.Header.GetParameterOffset(), take);
            var span   = mem.Span;
            var offset = 0;

            span[offset++] = datagram.Function;
            span[offset++] = datagram.ItemCount;


            foreach (var item in datagram.Data)
            {
                S7DataItemWriteResult.TranslateToMemory(item, mem.Slice(offset));
                offset += item.GetSpecificationLength();
            }

            return(result);
        }
Esempio n. 6
0
        public static S7WriteJobAckDatagram TranslateFromMemory(Memory <byte> data)
        {
            var span   = data.Span;
            var result = new S7WriteJobAckDatagram
            {
                Header = S7AckDataDatagram.TranslateFromMemory(data),
            };
            var offset = result.Header.GetParameterOffset();

            result.Function  = span[offset++];
            result.ItemCount = span[offset++];

            for (var i = 0; i < result.ItemCount; i++)
            {
                var res = S7DataItemWriteResult.TranslateFromMemory(data.Slice(offset));
                result.Data.Add(res);
                offset += res.GetSpecificationLength();
            }

            return(result);
        }