title: How to read Binary Data from Serial Port without any Encoding?
body: <p>I have developed an application to read data from SerialPort in C#. Its working fine. But the data read from SerialPort is different than I expected.</p>
  
  <p>When I read the port using XCTU or Matlab it will gives the data like the following,</p>
  
  <pre><code>00 00 e2 00 40 74 95 07 02 25 14 00 8a 92 00 77 ff
  </code></pre>
  
  <p>But When I am reading the same data from C# application it gives, </p>
  
  <pre><code>8C3F275A483F
  </code></pre>
  
  <p>I am expecting the result data of C# application like the result from Matlab and XCTU. I have tried with SerialPort encodings(ASCIIEncoding, Unicode, Latin). But nothing works. Help me. this is my code,</p>
  
  <pre><code>//DataReceived event handler
  public event EventHandler&lt;SerialDataEventArgs&gt; NewSerialDataRecieved;
  //Serial Port Initialization
  SerialPort _serialPort = new SerialPort("COM3",9600,Parity.None,8,StopBits.One);
  _serialPort.DataReceived += new SerialDataReceivedEventHandler(_serialPort_DataReceived);
  _serialPort.Open();
  
  //DataReceived event
  void _serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
  {
      int dataLength = _serialPort.BytesToRead;
      byte[] data = new byte[dataLength];
      int nbrDataRead = _serialPort.Read(data, 0, dataLength);
      if (nbrDataRead == 0)
          return;
  
      if (NewSerialDataRecieved != null)
          NewSerialDataRecieved(this, new SerialDataEventArgs(data));
  }
  
  //class SerialDataEventArgs
  public class SerialDataEventArgs : EventArgs
  {
      public string Data;
      public SerialDataEventArgs(string dataInByteArray)
      {
          Data = dataInByteArray;
      }
  
  }
  
  //printing the read data
  string str = BitConverter.ToString(e.Data);
  txtData.AppendText(str);//txtData is a TextBox
  </code></pre>