1

使用以下代码时:

    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在调试输出中显示变量时少?

4

1 回答 1

3

Debug.WriteLine() 非常慢。串行端口在执行时将继续接收字节。因此,之后获得更多字节是一种明显的可能性。

于 2013-03-05T18:18:42.963 回答