private void SerialPortService_DataReceived(object sender, EventArgs e) { var buffer = new byte[SerialPortService.BytesToRead]; SerialPortService.Read(buffer, 0, buffer.Length); switch (ConsoleOutput.OutputFormat) { case Format.Text: string text = Encoding.GetString(buffer, 0, buffer.Length); ConsoleService.Write(text); break; case Format.BytesDecimal: foreach (byte b in buffer) { ConsoleService.Write("{0} ", b); } break; case Format.BytesHex: string str = BitConverter.ToString(buffer).Replace("-", " "); ConsoleService.Write("{0} ", str); break; } }