1
votes

I got an Arduino hooked up to the PC and would like to read the serial port of it. I read the serial port in Visual Basic with com.Readline, but it won't read everything. It looses around 2-3 lines that were sent over the serial port to the Visual Basic code. They get "lost".

If I go even with higher Baud rates (57600) it loses even more lines...

I use this to read:

Private Sub com9_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles com.DataReceived
        Dim returnStr As String
        returnStr = com.ReadLine
        ReceiveSerialData(returnStr)
End Sub

Is the program too slow to get all data or what is the problem?

1

1 Answers

1
votes

SerialPort.DataReceived Event has an interesting comment which may point you in the right direction:

The DataReceived event is not guaranteed to be raised for every byte received. Use the BytesToRead property to determine how much data is left to be read in the buffer.

Note that the page(s) also mention the fact that the buffering behavior complicates things...