VB.NET做上位机 serialport控件问题
发布网友
发布时间:2022-11-28 16:07
我来回答
共1个回答
热心网友
时间:2023-10-23 15:14
要用委托的形式(界面上拖一个txt_Rect文本框)
Delegate Sub SetTextCallback(ByVal InputString As String)
Private Sub ShowString(ByVal comData As String)
txt_Rect.Text += comData '将收到的数据入接收文字框中
txt_Rect.SelectionStart = txt_Rect.Text.Length
txt_Rect.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)
BeginInvoke(d, inData)
End Sub
追问没明白什么意思,我自己弄好了,在datareceived加一个挂起线程,Thread.Sleep(100)就行了,谢了!分还是给你!