title: How do I use dataReceived event of the SerialPort in C#
body: <p>I had an application that retrieves data from an EXA brand scale, from the serial port c #.
  I would like to do the same thing, but this time by another brand, KERN PFB, the problem is that the SerialDataReceivedEventHandler event never executes. I do not know what I missing here .</p>
  
  <p>I tried with this : <a href="https://stackoverflow.com/questions/466474/how-do-i-use-datareceived-event-of-the-serialport-port-object-in-c">How do I use dataReceived event of the SerialPort Port Object in C#?</a></p>
  
  <pre><code>    public static  SerialPort mySerialPort = new SerialPort("COM1");
      public static string indata = string.Empty;
  
      public static void SetSetting()
      {
          mySerialPort.BaudRate = 9600;
          mySerialPort.Parity = Parity.None;
          mySerialPort.StopBits = StopBits.One;
          mySerialPort.DataBits = 8;
          mySerialPort.Handshake = Handshake.None;
          mySerialPort.RtsEnable = true;
  
          mySerialPort.DataReceived += MySerialPort_DataReceived;
      }
  
      public static void MySerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
      {
          SerialPort sp = (SerialPort)sender;
          indata += sp.ReadExisting();
      }
  
      public static float GetPesage()
      {
          indata = string.Empty;
          mySerialPort.Open();
          Thread.Sleep(1000);
  
          string[] dataSplited = indata.Trim().Split(' ');            
          float poids = 0;
          //
          ...
          //
  
          mySerialPort.Close();
          return poids;
      }
  </code></pre>
  
  <p>I expect data is received but isn't.</p>
  
  <p>Thank you.</p>