コード例 #1
0
ファイル: S7WriteJobAckDatagram.cs プロジェクト: lulzzz/dacs7
        public static S7WriteJobAckDatagram Build(SiemensPlcProtocolContext context, int id, IEnumerable <WriteResultItem> vars)
        {
            var result = new S7WriteJobAckDatagram();

            result.Header.Header.ProtocolDataUnitReference = (ushort)id;

            if (vars != null)
            {
                result.ItemCount = (byte)vars.Count();
                var numberOfItems = result.ItemCount;
                foreach (var item in vars)
                {
                    numberOfItems--;
                    result.Data.Add(new S7DataItemWriteResult
                    {
                        ReturnCode = (byte)item.ReturnCode
                    });
                }
            }

            result.Header.Header.ParamLength = (ushort)2;
            result.Header.Header.DataLength  = (ushort)result.Data.Count;
            result.ItemCount = (byte)result.Data.Count;
            return(result);
        }
コード例 #2
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);
        }
コード例 #3
0
ファイル: S7WriteJobAckDatagram.cs プロジェクト: lulzzz/dacs7
        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);
        }
コード例 #4
0
ファイル: S7WriteJobAckDatagram.cs プロジェクト: lulzzz/dacs7
        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);
        }