?
Solved

Serial stream string help

Posted on 2006-03-25
2
Medium Priority
?
215 Views
Last Modified: 2010-04-23
Friends,

I am needing help with putting a partial string back together when the serial stream buffer only sends part of it.

Here's the deal.

Let's say that a chunk of data comes from the buffer and looks like this:

"Tx    "

Then you have the rest that looks like

"    9 M3  8:22:39.147192"

I need those to get combined.

Now, thanks to previous help, I have this, but it isn't quite working correctly..

Here is my code:

Dim LeftOvers As String = ""

    Dim Buffer1 As String = "S         8 M3       12.241000" & vbCrLf _
    & "Tx        3 M4  8:22:35.417706" & vbCrLf _
    & "V   1           20.129  [km/h]" & vbCrLf _
    & "Tx  "

    Dim Buffer2 As String = "      9 M3  8:22:39.147192"


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Try

            Dim s As String

            s = LeftOvers & Buffer1.ToString() '& "$"

            LeftOvers = ""
            s = s.Replace(ControlChars.CrLf, "$")     ' remove all the CR and LF to become one line

            'Dim StringBuffer() As String = Split(s, ControlChars.CrLf)    ' split each by CR/LF
            Dim StringBuffer() As String = Split(s, "$")

            Dim TagHeuerPhotoCellValidString As String

            For i As Int64 = 0 To StringBuffer.GetUpperBound(0)
                If StringBuffer(i) <> Nothing Then
                    If ValidLine(StringBuffer(i)) Then

                        TagHeuerPhotoCellValidString = StringBuffer(i)

                    End If
                Else
                    LeftOvers = StringBuffer(i) <----This is never getting hit...Why?
                End If
            Next

 

        Catch ex As Exception

        End Try

    End Sub

    Function ValidLine(ByVal TestData As String) As Boolean

        Dim SplitUpString() As String
        Dim AlphaNum As String
        Dim character As Char

        'Return True

        If TestData.StartsWith("Tx") And (TestData.Length = 30) Then
            Return True
        Else
            Return False
        End If

    End Function

Thanks!

Eric
0
Comment
Question by:indy500fan
2 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 2000 total points
ID: 16289640
Eric

Your code never makes use of what you've put in Buffer2, which I imagine is part of the problem.

And then this code

                If StringBuffer(i) <> Nothing Then
                    If ValidLine(StringBuffer(i)) Then

                        TagHeuerPhotoCellValidString = StringBuffer(i)

                    End If
                Else
                    LeftOvers = StringBuffer(i) <----This is never getting hit...Why?
                End If

will only hit the line you've marked if StringBuffer(i) = Nothing.  What I imagine you really want is

                If StringBuffer(i) <> Nothing Then
                    If ValidLine(StringBuffer(i)) Then

                        TagHeuerPhotoCellValidString = StringBuffer(i)

                    Else
                        LeftOvers = StringBuffer(i)
                    End If
                End If

Roger
0
 

Author Comment

by:indy500fan
ID: 16289828
Yep, you are exactly right.  Geesh, I knew it was something simple.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month16 days, 1 hour left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question