Public Class Form1 Dim SerialPort1 As IO.Ports.SerialPort Delegate Sub SetTextCallback(ByVal data As String) Private Delegate Sub UpdateLabelDelegate(theText As String) Private Sub UpdateLabel(theText As String) If Me.InvokeRequired Then Me.Invoke(New UpdateLabelDelegate(AddressOf UpdateLabel), theText) Else TextBox1.Text = theText End If End Sub Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived Dim returnStr As String returnStr = SerialPort1.ReadExisting Me.BeginInvoke(Sub() UpdateLabel(returnStr) End Sub) End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click SerialPort1.Open() End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click SerialPort1.Close() End Sub End Class
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)