title: Receive data from serialport in realtime VB.net
body: <p>I created this code to receive data from serial port (com)</p>
  
  <pre><code> Private port As New SerialPort("COM1", 9600, Parity.None, 8, StopBits.One)
  
  Function ReceiveSerialData() As String
  
      Dim returnStr As String = ""
  
      Dim com1 As IO.Ports.SerialPort = Nothing
      Try
  
          port.Open()
  
          port.ReadTimeout = 1000
  
          Dim Incoming As String
  
              Incoming = port.ReadLine()
  
          returnStr = Incoming
  
      Catch erreur As IOException
          returnStr = "Check Port"
      Catch ex As TimeoutException
          returnStr = "Error: Serial Port read timed out."
      Finally
          If port IsNot Nothing Then port.Close()
      End Try
  
      Return returnStr
  End Function
  
  
  
  Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
  
      Label2.Content = ReceiveSerialData()
  
  End Sub
  </code></pre>
  
  <p>I want to create an event to re execute this code when the data's changed in real time.</p>
  
  <p>My Form is like this : 
  <a href="https://i.stack.imgur.com/4egAk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4egAk.png" alt="enter image description here"></a></p>
  
  <p>Any suggestion ? </p>