/// <summary> /// リクエスト送信と応答受信。 /// </summary> /// <param name="request"></param> /// <returns></returns> public ResponsePacket SendAndReceive(RequestPacket request) { int received; byte [] requestBytes; byte [] receiveBuffer; ResponsePacketHeader responsePacketHeader; ResponsePacketBody responsePacketBody; // リクエスト送信。 requestBytes = request.GetBytes(); ReportProgress(0, false); port.Write(requestBytes, 0, requestBytes.Length); ReportProgress(100, false); // 応答ヘッダ部受信。 received = 0; receiveBuffer = new byte [PacketHeader.Length]; ReportProgress(0, true); do { received += port.Read( receiveBuffer, received, receiveBuffer.Length - received); ReportProgress(10 * received / PacketHeader.Length, true); }while(received < PacketHeader.Length); responsePacketHeader = new ResponsePacketHeader(receiveBuffer); // 応答ボディ部受信。 received = 0; receiveBuffer = new byte [responsePacketHeader.length]; do { received += port.Read( receiveBuffer, received, receiveBuffer.Length - received); ReportProgress( 10 + (90 * received) / responsePacketHeader.length, true); }while(received < responsePacketHeader.length); responsePacketBody = new ResponsePacketBody(responsePacketHeader, receiveBuffer); return(new ResponsePacket(responsePacketHeader, responsePacketBody)); }
/// <summary> /// /// </summary> /// <param name="header"></param> /// <param name="body"></param> public ResponsePacket(ResponsePacketHeader header, ResponsePacketBody body) { this.header = header; this.body = body; }