title: c# Serial-port: Receiving some echo
body: <p>I have made a tiny program, witch can send and receive over a serial port. 
  My problem is that when I send commands ex: "netcfg" I get this echo: </p>
  
  <p><img src="https://i.stack.imgur.com/VLyA6.png" alt="http://i44.tinypic.com/izx92p.png"></p>
  
  <p>At the spaces it displays the UTF8-code 08. If you convert to java script it displays: \b
  But the output just have to be: netcfg, not: n ne net netc netcf netcfg </p>
  
  <p>so the output i want loks like this:
  "sds://>netcfg" and then newline.</p>
  
  <p>I can see that the device understands my command, but this doesn't look nice, so please help me.</p>
  
  <p>My code is messy right now but here it is anyway: </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.IO.Ports;
  using System.Text;
  using System.Windows.Forms;
  
  namespace WindowsFormsApplication2
  {
      public partial class Form1 : Form
      {
          private string _TerminalString;
  
          public Form1()
          {
              InitializeComponent();
              if (!mySerialPort.IsOpen)
              {
                  mySerialPort.Open();
                  txtTerminal.Text = "The port is now open";
              }
              else
              {
                  txtTerminal.Text = "The port is in use";
              }
          }
  
          private void mySerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
          {
              _TerminalString = mySerialPort.ReadExisting();
  
              Invoke(new EventHandler(displayText));
          }
  
          private void displayText(object o, EventArgs e)
          {
              byte[] str2 = Encoding.ASCII.GetBytes(txtSend.Text);
              var testList = new List&lt;byte&gt;(str2);
              testList.Add(0x0D);
              byte[] str3 = testList.ToArray();
              mySerialPort.Write(str3, 0, str3.Length);
              txtTerminal.AppendText(_TerminalString);
          }
  
          private void bSend_Click(object sender, EventArgs e)
          {
              byte[] str2 = Encoding.ASCII.GetBytes(txtSend.Text);
              var testList = new List&lt;byte&gt;(str2);
              testList.Add(0x0D);
              byte[] str3 = testList.ToArray();
              mySerialPort.Write(str3, 0, str3.Length);
          }
  
          private void bClear_Click(object sender, EventArgs e)
          {
              txtTerminal.Clear();
              txtSend.Clear();
          }
  
          private void Form1_FormClosed(object sender, FormClosedEventArgs e)
          {
              mySerialPort.Close();
          }
  
  
          private void btnSearchForComPorts_Click(object sender, EventArgs e)
          {
              string[] ports = SerialPort.GetPortNames();
              foreach (string port in ports)
              {
                  cbmComPorts.Items.Add(port);
              }
          }
  
          private void btnSelectComPort_Click(object sender, EventArgs e)
          {
              if (mySerialPort.IsOpen)
              {
                  mySerialPort.Close();
              }
  
              mySerialPort.PortName = cbmComPorts.Text;
              txtTerminal.AppendText(cbmComPorts.Text);
              mySerialPort.Open();
          }
  
          private void btnNetcfg_Click(object sender, EventArgs e)
          {
              // netcfg + enter
              byte[] str = {0x6E, 0x65, 0x74, 0x63, 0x66, 0x67, 0x0D, 0x0A};
  
              mySerialPort.Write(str, 0, str.Length);
          }
      }
  }
  </code></pre>