T
Tony K
I have a slight problem. When attempting to receive data via my serial port
I sometimes do not get the complete data. For example, I have a scanner
that reads barcodes. When reading barcode after barcode, there might be 2
or 3 barcodes in a row where I do not get the complete barcode. It will be
split up over 2 lines.
Here is my code and an example of the data received is toward the bottom.
Dim WithEvents com1 As New SerialPort
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Try
With com1
.PortName = "Com4"
.BaudRate = 9600
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.One
End With
com1.Open()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub com1_DataReceived(ByVal sender As Object, ByVal e As
System.IO.Ports.SerialDataReceivedEventArgs) Handles com1.DataReceived
Dim returnStr As String
returnStr = com1.ReadExisting 'ReadLine does not work. Any
reason why??
ReceiveSerialData(returnStr)
com1.DiscardInBuffer()
End Sub
Sub ReceiveSerialData(ByVal msg As String)
' Receive strings from a serial port.
CheckForIllegalCrossThreadCalls = False
TextBox1.Text &= msg & vbCrLf
End Sub
I cannot find anything about an EOM (End Of Message) character setting for
the Serial Port. My scanner is set up to send <CR><LF> at the end of each
scan.
Here is an example of the data that I receive. I scanned 2 barcodes over
and over. You can see the barcodes are split up but I'm not sure what is
causing this. Any suggestions would be greatly appreciated.
036600826313
04740
0097742
036600826313
047400097742
036600826313
0474
00097742
036
600826313
047
400097742
036600826313
04740009
7742
Thank you all,
Tony
I sometimes do not get the complete data. For example, I have a scanner
that reads barcodes. When reading barcode after barcode, there might be 2
or 3 barcodes in a row where I do not get the complete barcode. It will be
split up over 2 lines.
Here is my code and an example of the data received is toward the bottom.
Dim WithEvents com1 As New SerialPort
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Try
With com1
.PortName = "Com4"
.BaudRate = 9600
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.One
End With
com1.Open()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub com1_DataReceived(ByVal sender As Object, ByVal e As
System.IO.Ports.SerialDataReceivedEventArgs) Handles com1.DataReceived
Dim returnStr As String
returnStr = com1.ReadExisting 'ReadLine does not work. Any
reason why??
ReceiveSerialData(returnStr)
com1.DiscardInBuffer()
End Sub
Sub ReceiveSerialData(ByVal msg As String)
' Receive strings from a serial port.
CheckForIllegalCrossThreadCalls = False
TextBox1.Text &= msg & vbCrLf
End Sub
I cannot find anything about an EOM (End Of Message) character setting for
the Serial Port. My scanner is set up to send <CR><LF> at the end of each
scan.
Here is an example of the data that I receive. I scanned 2 barcodes over
and over. You can see the barcodes are split up but I'm not sure what is
causing this. Any suggestions would be greatly appreciated.
036600826313
04740
0097742
036600826313
047400097742
036600826313
0474
00097742
036
600826313
047
400097742
036600826313
04740009
7742
Thank you all,
Tony