DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2005
    Posts
    3

    Detecting line feed and carriage return

    Hi,

    I have an application in VB.net that reads a stream of GPS NMEA data from a serial port and converts it to string and then sends the string to a parser subroutine.

    The parser subroutine looks for an identifier that signals the start of one NMEA data packet i.e. "$".

    When it finds this, the subroutine than copies the characters following the "$" char one by one into a local buffer until it reaches a carriage return. When it finds a carriage return it then goes on look for a line feed, at which point it then sends the local buffer to another function that processes the particular string.

    My problem is simply this - my subroutine has difficulty in differentiating between a line feed character and a carriage return character.

    This is my code:

    Private Sub ParseText(ByVal NMEA_buff As String, ByVal MAX_PACKET As Integer)
    'MAX_PACKET is 100
    Dim ch As String
    Dim i As Integer
    Static NMEA_localbuff As String
    Static NMEA_state As Integer

    On Error GoTo ErrHandler

    i = 1
    ch = Mid(NMEA_buff, i, 1)
    While (ch <> "")
    If (ch = "$") Then
    NMEA_state = 1
    NMEA_localbuff = ch
    bytecntr = 0
    Else
    Select Case (NMEA_state)
    Case 1
    bytecntr = bytecntr + 1
    'chr(13) is carriage return \r
    If (ch = Chr(13)) Then
    NMEA_state = 2
    Else
    NMEA_localbuff = NMEA_localbuff + ch
    End If
    If (bytecntr >= MAX_PACKET) Then
    NMEA_state = 0
    End If

    Case 2
    ' chr(10) is line feed \n
    If (ch = Chr(10)) Then
    process(NMEA_localbuff)
    NMEA_localbuff = ""
    End If
    NMEA_state = 0
    End Select
    End If
    i = i + 1
    ch = Mid(NMEA_buff, i, 1)
    End While
    ErrHandler:
    MsgBox("Error " & Err.Number & " " & Err.Description)

    End Sub

    It keeps looping around the same Select Case 1 without evenr going into Select Case 2 as it should.

    I've tried using vbLf and vbCr for Chr(10) and Chr(13) respectively, but still no dice.

    Is there another way I can use to detect line feeds and carriage returns?

    Any help will be greatly appreciated...

    Thanks and regards.

    SASHI

  2. #2
    Join Date
    Dec 2003
    Posts
    2,750
    Is there a reason why you can't look for vbCrLf instead of each each individually?
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

Similar Threads

  1. carriage return problem
    By kim in forum Web
    Replies: 2
    Last Post: 09-29-2001, 12:10 PM
  2. Carriage return and newline
    By Charles in forum Database
    Replies: 1
    Last Post: 04-30-2001, 12:09 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links