By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,078 Members | 1,846 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,078 IT Pros & Developers. It's quick & easy.

How to read all data across a serial COM

P: n/a
Im trying to raed data over a com port. The data comes over the serial
port as such reading CRLF reading CRLF and so on.

The code below only sees the first reading CRLF and then only added
that into the DSIDXPort arraylist and never adds readings 2 through
16.....

How can I get it to read those?

[code]

serialPort.ReadTimeout = 50
serialPort.DiscardInBuffer()

Dim strData As String = String.Empty

If Not serialPort.IsOpen Then
strData = String.Empty
Else
strData = serialPort.ReadLine
End If


If strData.Length 0 Then

Dim tempArray() As String
strData = strData.Replace(vbCrLf,
vbTab).Replace(Chr(26), "").Replace(Chr(12), "").Replace(Chr(13), "")

'parses out the information gathered from the COM port
to a temp location
tempArray = Split(strData, vbTab)
If serialPort.ReadTimeout = 50 Then
Dim intLoop As Integer
For intLoop = 0 To UBound(tempArray)
If IsNumeric(tempArray(intLoop)) Then
DSIMRPort.Add(tempArray(intLoop))
End If

Next
End If
end if
[\CODE]
Nov 6 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"cmdolcet69" <co************@hotmail.comschrieb
Im trying to raed data over a com port. The data comes over the
serial port as such reading CRLF reading CRLF and so on.
I don't fully understand the meaning of this sentence.
The code below only sees the first reading CRLF and then only added
that into the DSIDXPort arraylist and never adds readings 2 through
16.....

How can I get it to read those?

I only see one "serialPort.ReadLine". When or where do you expect it to read
more?
Armin

Nov 6 '08 #2

P: n/a
I presume you mean that the format of the data stream is variable length
strings separated by CR and LF.

As VB is an event based language, you need to make use of the event that
indicates that some data has been received from the port. There is no event
available that tells you that a CRLF has been received, but the DataReceived
event will tell you when each character is received. You can use processing
in that event to see if the received character was a CR or LF - if it is,
then there is a data sentence in the buffer that can be retrieved. You can
then use Readline to retrieve the data from the buffer.

You should not use readline unless you know there is a line to be read.

"cmdolcet69" <co************@hotmail.comwrote in message
news:82**********************************@k36g2000 pri.googlegroups.com...
Im trying to raed data over a com port. The data comes over the serial
port as such reading CRLF reading CRLF and so on.

The code below only sees the first reading CRLF and then only added
that into the DSIDXPort arraylist and never adds readings 2 through
16.....

How can I get it to read those?

[code]

serialPort.ReadTimeout = 50
serialPort.DiscardInBuffer()

Dim strData As String = String.Empty

If Not serialPort.IsOpen Then
strData = String.Empty
Else
strData = serialPort.ReadLine
End If


If strData.Length 0 Then

Dim tempArray() As String
strData = strData.Replace(vbCrLf,
vbTab).Replace(Chr(26), "").Replace(Chr(12), "").Replace(Chr(13), "")

'parses out the information gathered from the COM port
to a temp location
tempArray = Split(strData, vbTab)
If serialPort.ReadTimeout = 50 Then
Dim intLoop As Integer
For intLoop = 0 To UBound(tempArray)
If IsNumeric(tempArray(intLoop)) Then
DSIMRPort.Add(tempArray(intLoop))
End If

Next
End If
end if
[\CODE]
Nov 7 '08 #3

P: n/a
I'd have to see the actual code. You call ReadLine each time you want to
read a line (seems clear). Do you have a loop for reading data? Are you
calling this in the DataReceived event (if so, the you certainly cannot call
DiscardInBuffer).
--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
Nov 7 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.