title: c# serial port read byte array from serial port
body: <p>Im trying to read data from serial port and to compare it, but i cant get it working, data that i read isnt that i need to get and sometimes its incomplete
  basicly what i want when data from serial port comes and if data data is equal to an array to write some data to serial port</p>
  
  <pre><code>    private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
      {
          var Serial1 = (SerialPort)sender;
          Serial1.DtrEnable = true;
          Serial1.RtsEnable = true;
          int bytes = Serial1.BytesToRead;
          byte[] buffer = new byte[bytes];
          Serial1.Read(buffer, 0, bytes);
          string buffer1 = System.Text.Encoding.UTF8.GetString(buffer);
          newform(buffer1);
          showinwindow(buffer);
  
      }
  
      private void showinwindow(byte[] buffer)
      {
          byte[] array1 = { 0x03, 0x2F, 0x2C };
          bool a = array1.SequenceEqual(buffer);
          if (a == true)
          {
              byte[] upisipodatak = { 0x03, 0x20, 0x23 };
              serialPort1.Write(upisipodatak, 0, upisipodatak.Length);
          }
      }
  
      private void newform(string buffer1)
      {
          BeginInvoke(new EventHandler(delegate
          {
                  textBox1.AppendText(buffer1);
          }));
      }
  </code></pre>