Serial stream string help

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
indy500fanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SanclerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
indy500fanAuthor Commented:
Yep, you are exactly right.  Geesh, I knew it was something simple.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.