Reply To: GUI does not work properly
› Forums › Graphical User Interface using C#, VB, HTML, ASP.NET Discussions › GUI does not work properly › Reply To: GUI does not work properly
You need to subscribe to the DataReceived event before opening the port, then listen to that event when triggered. You can’t just read data without knowing if data is there.
when there is data in the buffer, the data received event is triggered.
use something like this:
private void OpenSerialPort()
m_serialPort.DataReceived += SerialPortDataReceived;
catch (Exception ex)
System.Diagnostics.Debug.WriteLine(ex.Message + ex.StackTrace);
private void SerialPortDataReceived(object sender, SerialDataReceivedEventArgs e)
var serialPort = (SerialPort)sender;
var data = serialPort.ReadExisting();