We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Serial stream string help

indy500fan
indy500fan asked
on
Medium Priority
229 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
Comment
Watch Question

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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Yep, you are exactly right.  Geesh, I knew it was something simple.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.