16,555
社区成员
发帖
与我相关
我的任务
分享
Public Delegate Sub SetTextCallback([text] As String) '定义委托
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Dim DATA2Send As String
Dim temp As String
ISrouting = True
temp = SerialPort1.ReadLine()'如果你的下位机是有换行符 或 回车符作为一行的结尾的话
'处理temp (包括 用strings.left取左边4个字节,right取右边;然后转成十进制等)赋值到DATA2Send
SetText(DATA2Send)
End sub
Sub SetText(ByVal [txt] As String)
If Me.TextBox1.InvokeRequired Then
Dim dsettext As New SetTextCallback(AddressOf SetText)
Me.Invoke(dsettext, [txt].ToString)
Else
TextBox1.Text = [txt]
End If
End Sub