public static IMemoryOwner <byte> TranslateToMemory(S7WriteJobDatagram datagram, out int memoryLength) { var result = S7HeaderDatagram.TranslateToMemory(datagram.Header, out memoryLength); var mem = result.Memory.Slice(0, memoryLength); var span = mem.Span; var offset = datagram.Header.GetHeaderSize(); span[offset++] = datagram.Function; span[offset++] = datagram.ItemCount; foreach (var item in datagram.Items) { S7AddressItemSpecificationDatagram.TranslateToMemory(item, mem.Slice(offset)); offset += item.GetSpecificationLength(); } foreach (var item in datagram.Data) { S7DataItemSpecification.TranslateToMemory(item, mem.Slice(offset)); offset += item.GetSpecificationLength(); if (offset % 2 != 0) { offset++; } } return(result); }
public static Memory <byte> TranslateToMemory(S7ReadJobAckDatagram 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) { S7DataItemSpecification.TranslateToMemory(item, result.Slice(offset)); offset += item.GetSpecificationLength(); } return(result); }
public static IMemoryOwner <byte> TranslateToMemory(S7ReadJobAckDatagram 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) { S7DataItemSpecification.TranslateToMemory(item, mem.Slice(offset)); offset += item.GetSpecificationLength(); if (offset % 2 != 0) { offset++; } } return(result); }