请教串口通讯DataReceived事件不触发的问题
VB2005的 一个自发自收的程序,串口2和3短接。运行程序后,第一次连接、打开串口后,收发正常。再发送,能看到BytesToRead随着发送次数增长,但不能触发DataReceived事件。关闭串口再打开,则能再正常收发一次,后续收发不正常,直到重新关闭打开串口。不知道为什么。盼高人指点,下面是源程序,谢谢。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Sp.Write(txtBox1.Text)
End Sub
Public Sub Sp_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SP.DataReceived
Me.Invoke(New EventHandler(AddressOf Sp_Receiving))
End Sub
Private Sub Sp_Receiving(ByVal sender As Object, ByVal e As EventArgs)
Dim strIncoming As String
strIncoming = Sp.ReadLine.ToString 'Sp.ReadExisting.ToString
Sp.DiscardInBuffer()
TexMes.Text = strIncoming
End Sub