private byte[] Request(byte[] data) { Net.Net.Command command = (Net.Net.Command)data[Net.Net.HDR_SZ - 1]; lock (controlSocket) { try { int toSend = data.Length; while (toSend > 0) { toSend -= controlSocket.Send(data, data.Length - toSend, toSend, SocketFlags.None); } } catch (Exception se) { Logger.Error("Failure while sending to socket, destroying: {0}" + se.Message); Destroy(); throw new ScopeIOException("Failure while sending to socket: " + se.Message); } switch (command) { case Net.Net.Command.DATA: case Net.Net.Command.GET: case Net.Net.Command.PIC_FW_VERSION: case Net.Net.Command.SERIAL: case Net.Net.Command.FLASH_FPGA: case Net.Net.Command.DATA_PORT: case Net.Net.Command.ACQUISITION: List <Net.Net.Message> l = Net.Net.ReceiveMessage(controlSocket, msgBuffer, ref msgBufferLength); if (l == null) { Logger.Debug("Message list is null - no message received?"); Destroy(); throw new ScopeIOException("Message list is null - no message received?"); } if (l.Count > 1) { int i = 0; foreach (Net.Net.Message m in l) { Logger.Error("Message {0} : {1:G} [{2} bytes]", i, m.command, m.length); i++; } throw new ScopeIOException("More than 1 message received"); } if (l.Count == 0) { throw new ScopeIOException("No reply message received"); } Net.Net.Message reply = l[0]; if (reply.command != command) { throw new ScopeIOException(string.Format("Reply {0:G} doesn't match request command {1:G}", reply.command, command)); } if (command == Net.Net.Command.GET) { ScopeController c; int a; int b; byte[] response; Net.Net.ParseControllerHeader(reply.data, out c, out a, out b, out response); return(response); } else { return(reply.data); } default: return(null); } } }
private byte[] Request(Net.Net.Command command, byte[] cmdData = null) { return(Request(command.msg(cmdData))); }