public static HashSet <ReadOperandsRequest> CreateMultiple(UnitronicsPLC plc, Dictionary <OperandType, HashSet <ushort> > operandAddresses) { HashSet <ReadOperandsRequest> requests = new HashSet <ReadOperandsRequest>(); foreach (OperandType operand in operandAddresses.Keys) { byte operandLength = calculateOperandMessageLength(operand); int maximumReceiveLength = plc.BufferSize - Response.STX.Length - Response.UnitIDLength - Response.CommandLength - Response.CRCLength - Response.ETXLength; ReadOperandsRequest request = null; foreach (ushort address in operandAddresses[operand].OrderBy(address => address)) { if (request != null) { int newLength = address - request.StartAddress + 1; if (newLength * operandLength > maximumReceiveLength || newLength > MaximumOperandsLength) { requests.Add(request); request = CreateNew(plc, operand, address, 1); } else { request.Length = (byte)newLength; } } else { request = CreateNew(plc, operand, address, 1); } } if (request != null && request.Length > 0) { requests.Add(request); } } return(requests); }
public static ReadOperandsResponse UnpackResponseMessage(ReadOperandsRequest request, Memory <byte> responseMessage) { return(new ReadOperandsResponse(request, responseMessage)); }