'vb.net的串口接收数据要用到委托 Delegate Sub SetTextCallback(ByVal InputString As String) '声明一个委派类,并声明符合函数参数有一个,而其型态是字符串 Private Sub ShowString(ByVal comData As String) txt_Re.Text &= comData '将收到的数据入接收文字框中--- txt_Re.Text 是接收用的文本框 txt_Re.SelectionStart = txt_Re.Text.Length txt_Re.ScrollToCaret() End Sub Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived‘自动接收事件 Dim inData As String = SerialPort1.ReadExisting Dim d As New SetTextCallback(AddressOf ShowString) Invoke(d, inData) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '发送指令 SerialPort1.Write("123") End Sub