使用以下代码时:
Private Sub DataReceivedHandler(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)
Dim sp As SerialPort = CType(sender, SerialPort)
Debug.WriteLine("DataReceivedHandler() - Data Received! number of bytes=" & sp.BytesToRead)
Dim indata As String = sp.ReadExisting()
Debug.WriteLine("DataReceivedHandler() - indata=" & TTSHelperFunctions.StringToHex(indata))
End Sub
什么可能导致sp.BytesToRead
表示比在调试输出中显示indata
变量时更少的字节数?
答案 0 :(得分:3)
Debug.WriteLine()非常慢。串行端口在执行时将继续接收字节。因此,事后获得更多字节是一种明显的可能性。