如何用VB.NET2005的SerialPort控件进行串口接收数据?
用串口调试助手进行调试
1.我先用的DataReceived事件不能自动触发
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort1.Close()
SerialPort1.Open()
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
MsgBox(SerialPort1.ReadLine)
End Sub
串口调试助手发送数据给我,收不到。
2.我加了个Button手动触发,但是还是接收不到,设置断点后就死在里面
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Do
Dim Incoming As String = SerialPort1.ReadLine()
If Incoming Is Nothing Then
Exit Do
Else
TextBox1.Text = Incoming
End If
Loop
MsgBox(Incoming)
Catch ex As Exception
MsgBox(ex)
End Try
End Sub
请教各位帮我解决下吧,谢谢~~