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(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(S7AckDataDatagram datagram) { var result = S7HeaderDatagram.TranslateToMemory(datagram.Header); S7HeaderErrorCodesDatagram.TranslateToMemory(datagram.Error, 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 IMemoryOwner <byte> TranslateToMemory(S7AckDataDatagram datagram, out int memoryLength) { var result = S7HeaderDatagram.TranslateToMemory(datagram.Header, datagram.Header.GetHeaderSize() + datagram.Error.GetSize() + datagram.Header.ParamLength + datagram.Header.DataLength, out memoryLength); var take = memoryLength - datagram.Header.GetHeaderSize(); S7HeaderErrorCodesDatagram.TranslateToMemory(datagram.Error, result.Memory.Slice(datagram.Header.GetHeaderSize(), take)); return(result); }
public static IMemoryOwner <byte> TranslateToMemory(S7UserDataDatagram datagram, out int memoryLength) { var offset = datagram.Header.GetHeaderSize() + datagram.Parameter.GetParamSize(); var dataSize = offset + datagram.Data.GetUserDataLength(); var result = S7HeaderDatagram.TranslateToMemory(datagram.Header, dataSize, out memoryLength); var mem = result.Memory.Slice(0, memoryLength); S7UserDataParameter.TranslateToMemory(datagram.Parameter, mem.Slice(datagram.Header.GetHeaderSize())); mem.Span[offset++] = datagram.Data.ReturnCode; mem.Span[offset++] = datagram.Data.TransportSize; BinaryPrimitives.WriteUInt16BigEndian(mem.Slice(offset, 2).Span, datagram.Data.UserDataLength); datagram.Data.Data.CopyTo(mem.Slice(offset + 2, datagram.Data.UserDataLength)); return(result); }
public static Memory <byte> TranslateToMemory(S7ReadJobDatagram datagram) { var result = S7HeaderDatagram.TranslateToMemory(datagram.Header); var span = result.Span; var offset = datagram.Header.GetHeaderSize(); span[offset++] = datagram.Function; span[offset++] = datagram.ItemCount; foreach (var item in datagram.Items) { S7AddressItemSpecificationDatagram.TranslateToMemory(item, result.Slice(offset)); offset += item.GetSpecificationLength(); } return(result); }