public static HashSet <ReadOperandsRequest> CreateMultiple(UnitronicsPLC plc, Dictionary <OperandType, HashSet <ushort> > operandAddresses) { HashSet <ReadOperandsRequest> requests = new HashSet <ReadOperandsRequest>(); ushort maximumBufferSize = (ushort)(plc.BufferSize - Response.HeaderLength - Response.FooterLength); ReadOperandsRequest request = null; foreach (OperandType operand in operandAddresses.Keys.OrderBy(type => (ushort)type)) { foreach (ushort address in operandAddresses[operand].OrderBy(address => address)) { if (request == null) { request = new ReadOperandsRequest(plc.UnitID); } else if (request.newOperandAddressFitsBuffer(operand, address, maximumBufferSize) == false) { requests.Add(request); request = new ReadOperandsRequest(plc.UnitID); } request.addOperandAddress(plc, operand, address); } } if (request != null && request.OperandRequests.Count > 0 && request.OperandRequests.Values.Any(request => request.Count > 0)) { requests.Add(request); } return(requests); }
public static ReadOperandsResponse UnpackResponseMessage(ReadOperandsRequest request, Memory <byte> responseMessage, bool disableChecksum = false) { return(new ReadOperandsResponse(request, responseMessage, disableChecksum)); }