I program an App in VB.Net and I want to read received data from a serial port in maximum baudrate. I used SerialPort component in my form and its properties are as follows:
(BuadRate=115200 , DataBits=8 , Parity=None , StopBits=One)
When I use connPort.ReadLine
in DataReceived
event, data congestion caused in buffer and I can't read all received data in realtime, because event fires are slower than received data.
On the other side when I use connPort.ReadExisting
, I can read all received data in realtime without data congestion in buffer, but the received data is look like this:
First received:
-12917
-12958
-13004Second received:
-13055
-13118
-13181
-1324Third received:
6
-13320
-13391
-13463
So I need to parser the received data line by line and on the other side I need to detect some received data errors look like:
...
-1324Third received:
6
...The correct data is: -13246
My code:
Private Sub connPort_DataReceived _
(ByVal sender As System.Object, _
ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) _
Handles connPort.DataReceived
Dim rcData as String
rcData = connPort.ReadLine
dt_Write(rcData)
'rcData = connPort.ReadExisting
'dt_Write(rcData)
End Sub
' Save received data in a created DataTable
Public dt As New DataTable
Private Sub dt_Write(ByVal rcData As String)
dt.Rows.Add(New Object() {Nothing, rcData})
End Sub
I tried Timer component and Tick
event With one millisecond Interval property (One millisecond is not real resolution) to receive data, but the fires are slower too and there are mentioned problems too.
I am looking for a right way and I'm trying to avoid redundant operations. Thank you