コード例 #1
0
        public static S7WriteJobDatagram TranslateFromMemory(Memory <byte> data)
        {
            var span   = data.Span;
            var result = new S7WriteJobDatagram
            {
                Header = S7HeaderDatagram.TranslateFromMemory(data),
            };
            var offset = result.Header.GetHeaderSize();

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

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

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

            return(result);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public static S7AckDataDatagram TranslateFromMemory(Memory <byte> data)
        {
            var result = new S7AckDataDatagram
            {
                Header = S7HeaderDatagram.TranslateFromMemory(data)
            };

            result.Error = S7HeaderErrorCodesDatagram.TranslateFromMemory(data.Slice(result.Header.GetHeaderSize()));

            return(result);
        }
コード例 #4
0
        public static S7UserDataDatagram TranslateFromMemory(Memory <byte> data)
        {
            var span   = data.Span;
            var result = new S7UserDataDatagram
            {
                Header = S7HeaderDatagram.TranslateFromMemory(data),
                Data   = new S7UserData()
            };

            result.Parameter = S7UserDataParameter.TranslateFromMemory(data.Slice(result.Header.GetHeaderSize()));
            var offset = result.Header.GetHeaderSize() + result.Parameter.GetParamSize();

            result.Data.ReturnCode     = span[offset++];
            result.Data.TransportSize  = span[offset++];
            result.Data.UserDataLength = BinaryPrimitives.ReadUInt16BigEndian(span.Slice(offset, 2));
            offset          += 2;
            result.Data.Data = new byte[result.Data.UserDataLength];
            data.Slice(offset, result.Data.UserDataLength).CopyTo(result.Data.Data);
            return(result);
        }