Results 1 to 39 of 39

Thread: Substring not Getting the SubString?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Posts
    73

    Substring not Getting the SubString?

    Here's my subroutine that has the problem:

    Code:
     Private Sub GetData()
            Try
                If InvokeRequired Then
                    Me.Invoke(New MethodInvoker(AddressOf GetData))
                Else
    
                    'get voltage data from loadcell, main batt, and ampbatt
                    inputstring = SerialPort1.ReadLine
    
                    loadcell = Val(inputstring.Substring(0, 4))
                    loadcell = ((loadcell / 1024) * 10 - zerovalue) * forcescale
                    ampbatt = Val(inputstring.Substring(4, 4))
                    ampbatt = (ampbatt / 1024) * 10
                    Datachart.Series("DataSeries").Points.AddY(loadcell)
                    Datachart.ChartAreas(0).AxisX.Minimum = Datachart.ChartAreas(0).AxisX.Maximum - 250
                    SerialPort1.Write("1")
                     End If
            Catch ex As Exception
    
            End Try
            
        End Sub
    This program reads a string "inputstring" that is coming from an Arduino board. It has loadcell and battery voltages coming in in an 8 digit string.
    For some reason I am getting a random number for "loadcell", ie it goes from 0.6v to over 1,000v. I added a label to display the string coming in (input string) here is nothing wrong with the incoming data. Notice the last line "SerialPort1.Write("1")", when the arduino board receives this, it flashes an led to indicate the computer program is responding. This led does not flash when the erroneous voltages come in.

    This sub runs when the SerialPort recieves data, it was working at 25/s. I tried 100/s but the anomalies began, so I tried, 50, 40, 30, and finally 25/s but I am still getting the bad voltages. Once again, the incoming data is fine...

    Suggestions? Totally at a standstill here!

    Thanks guys!
    Ryan

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Substring not Getting the SubString?

    There is next to no point in having a Try with an empty Catch. This means that any errors will be ignored leaving you with erroneous data and no idea why. Display the errors (of which I'm almost certain there will be some) and diagnose accordingly. Otherwise we're all just blundering around in the dark.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Posts
    73

    Re: Substring not Getting the SubString?

    Good idea, lol, will do!

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: Substring not Getting the SubString?

    Aside from that, Val is a bit risky. What Val does is starts parsing the string, character by character, until it finds a character that it can't turn into a number. At that point it returns. Therefore, if you have a byte coming in that Val doesn't know what to do with, it will return early. What may be happening is just that the string sections you think will hold the value may be off a bit in some way.

    One way to get at this would be to put a breakpoint in there and see what is happening. However, I expect that what is happening is that you are getting a deluge of data, only parts of which are off. Therefore, what you might consider is adding in some code while testing. For instance, suppose you added in a Dictionary (of String, Double). Every time you took a substring and converted it, add an entry to the Dictionary with the string and the double....except that it won't really work as I just stated, because you can't have duplicate keys. Therefore, you may have to use a List(of String) where you add in the substring & "::" & loadcell

    By doing whichever one of those worked, your routine would be logging what string it was trying to convert, and what the conversion resulted in. You might go further and log the whole line received, as well, so you could see what the code was doing. You would then root through that mass of data looking at what was being recorded. Once you had it figured out, you could remove that logging code.
    My usual boring signature: Nothing

  5. #5
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Substring not Getting the SubString?

    It will be interesting to see what the error is. I agree with Shaggy.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Posts
    73

    Re: Substring not Getting the SubString?

    Shaggy, can you explain your post come more? Sorry, but you lost this newbie

    Thanks

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: Substring not Getting the SubString?

    Which part? I think I covered a couple.

    Val is a dangerous way to convert a string to a number because it will ALWAYS work. You may think that's a benefit, but it isn't as beneficial as you might think. The problem is that Val will always returns some number, but it may not return the RIGHT number. For example:

    Val("123") returns 123
    Val("12a") returns 12
    Val(",12") returns 0
    Val(" 123") returns 0
    Val("1 23") returns 1

    As soon as Val hits a character that it doesn't know what to do with, it will return whatever it has converted to that point, which may be 0 if it fails on the first character. You will always get a number back from Val without exception, but you won't always get back the number you were expecting. You will only get the number you were expecting if the string is what you expected with nothing else added in. Do you know that it always will be? Add one byte of noise and your offsets are wrong, in which case Val will return an incorrect value, but it will still return a value. If you were to use Double.TryParse rather than Val, you would be able to identify those situations where the wrong part of the string was being parsed....maybe. This would be because .TryParse returns a Boolean indicating whether or not the conversion worked. The actual converted value is returned in the second argument to the .TryParse method.

    Of course, that won't solve all problems. If you are plucking four numbers from a string of numbers, and you are just getting the wrong four numbers, then TryParse will be just as wrong as Val, because both will correctly convert an incorrect string, which will result in an incorrect number. That's where the logging comes in.

    Suppose you were to add something like this outside of the method:

    Private valLogger as New List(of String)

    then you changed the method slightly:

    Code:
    inputstring = SerialPort1.ReadLine
    valLogger.Add(inputstring.Substring(0,4) & "::" & inputstring.Substring(4,4) & "::" & inputstring)
    loadcell = Val(inputstring.Substring(0, 4))
    Then ran the thing. You would be adding a string every time you read a line. That would end up being pretty large, so you probably wouldn't want to leave it in the program forever, but for diagnostic purposes it would be pretty useful. Let it run for a bit, and when you see an incorrect value, break the program and look at valLogger (or build something to let you see it in a Listbox, or the like, though it will be HUGE, so a listbox may not work well). What is being added each time is the first string you convert to a number, the second string you convert to a number, and the whole input line, all separated by a pair of colons to make them more distinct. If you get a bad value, then look at valLogger and see that the four bytes you just converted weren't the four bytes you wanted to convert, you will probably be able to see why at the same time. Alternatively, it may show you that the bytes you are converting are exactly the right bytes every time. Either of those results would be very useful information to have. One would show you what the problem IS, while the other would show you what the problem is NOT. Then you would know whether or not you can fix the problem in the code you have, or if the problem lies elsewhere.

    Therefore, it's just a means to gather more information about the problem, rather than a solution to the problem. After all, it isn't clear, yet, whether the code is right but the data is wrong, or vice versa.
    My usual boring signature: Nothing

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Posts
    73

    Re: Substring not Getting the SubString?

    That really helped... the string thats should be coming in seems to lose the first digit, ie...

    strings appearing in list box:

    00630708
    00620707
    0630708
    00640709
    00630707


    since this seems to be the only problem, should I add something like:

    Code:
    if inputstring.length = 8 then
     'continue
    else
     inputstring = "0" + inputstring
    end if
    One issue I see with this is that the highest integers possible would be: 10241024... therefore if it is truncated here and appears as 0241024, then the string I would get would be 024 and 024... help? How else can I get the strings numeric value without Val?

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Posts
    73

    Re: Substring not Getting the SubString?

    I should clarify, the string "inputstring" is losing the first digit. However, the data coming in is correct, ie the Arduino is sending 00630707 but the program reads the SerialPort1.ReadLine as 0630707... So I think the problem itself is somewhere around where it reads the data line coming in the serial port...

  10. #10
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Substring not Getting the SubString?

    Quote Originally Posted by rpmaurer View Post
    I should clarify, the string "inputstring" is losing the first digit. However, the data coming in is correct, ie the Arduino is sending 00630707 but the program reads the SerialPort1.ReadLine as 0630707... So I think the problem itself is somewhere around where it reads the data line coming in the serial port...
    Is it the microcontroller or the ReadLine? A simple way to check that is to write a simple program that does the ReadLine and stores the lines in the logger, and nothing else. Let it run for a while and see. I believe if the Arduino is sending 10 characters (8 data + newline) the serialport is reading it.

    Here is how to convert the values without Val:

    Code:
            Dim inputstring As String = "10241024" 'for testing
            Dim loadcell As Double
            Dim ampbatt As Double
    
            'Double.TryParse documentation
            'http://msdn.microsoft.com/en-us/library/994c0zb1.aspx  
            If Double.TryParse(inputstring.Substring(0, 4), loadcell) Then
                'loadcell has number
            Else
                'error
            End If
    
            If Double.TryParse(inputstring.Substring(4, 4), ampbatt) Then
                'ampbatt has number
            Else
                'error
            End If
    Some rough ideas on how you might approach the problem:

    Code:
    Public Class Form1
        Dim WithEvents tmr As New Windows.Forms.Timer
        Dim WithEvents sp As New IO.Ports.SerialPort
        Dim readBuf As New List(Of String)
        Dim bufLock As New Object
        Dim haveData As New Threading.AutoResetEvent(False)
    
        Public Sub comRead()
            Do While sp.IsOpen
                haveData.WaitOne()
                If sp.IsOpen AndAlso sp.BytesToRead >= 10 Then
                    Dim s As String = sp.ReadLine 'this may block
                    Threading.Monitor.Enter(bufLock)
                    readBuf.Add(s)
                    Threading.Monitor.Exit(bufLock)
                End If
            Loop
        End Sub
    
        Private Sub sp_DataReceived(sender As Object, e As IO.Ports.SerialDataReceivedEventArgs) Handles sp.DataReceived
            If sp.BytesToRead >= 10 Then 'do we have 10 bytes
                haveData.Set()
            End If
        End Sub
    
        Private Sub tmr_Tick(sender As Object, e As EventArgs) Handles tmr.Tick
            If readBuf.Count > 0 Then
                'process lines
                If Threading.Monitor.TryEnter(bufLock) Then
                    For Each s As String In readBuf
                        Debug.WriteLine(s)
                    Next
                    readBuf.Clear()
                    Threading.Monitor.Exit(bufLock)
                End If
            End If
        End Sub
    
        Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
            sp.Close()
            haveData.Set()
            t.Join()
        End Sub
    
        Dim t As Threading.Thread
    
        Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
            openCom()
            t = New Threading.Thread(AddressOf comRead)
            t.IsBackground = True
            t.Start()
    
            tmr.Interval = 10
            tmr.Start()
        End Sub
    
        Public Function openCom() As Boolean
            'setup comport with your parameters
            Try
                With sp
                    .PortName = "COM1"
                    .BaudRate = 9600
                    .DtrEnable = True
                    .RtsEnable = True
                    'etc
                End With
                sp.Open()
            Catch ex As Exception
                'port did not open
                Debug.WriteLine(ex.Message)
            End Try
            Return sp.IsOpen
        End Function
    End Class
    This code is intended to provide direction. It was not tested but it should be close.
    Last edited by dbasnett; Feb 11th, 2013 at 10:02 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  11. #11
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: Substring not Getting the SubString?

    I think the testing that DB has suggested is the way to go. He knows his serial port stuff.

    One thing I will mention is that if you end up wanting to add a 0, take a look at the PadLeft method. It's easier than the If statement, as it allows you to pad out the value to the length you want in a single statement.
    My usual boring signature: Nothing

  12. #12
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Substring not Getting the SubString?

    Quote Originally Posted by Shaggy Hiker View Post
    ...One thing I will mention is that if you end up wanting to add a 0, take a look at the PadLeft method. It's easier than the If statement, as it allows you to pad out the value to the length you want in a single statement.
    I agree with this, but...

    My concern is the disappearance of the data. If you send x bytes you should receive x bytes.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  13. #13
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: Substring not Getting the SubString?

    Tax.
    My usual boring signature: Nothing

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Posts
    73

    Re: Substring not Getting the SubString?

    Checked data leaving Arduino, its fine. Will check to see what the data coming in the serial port is, but the inputstring, which is the string representation of the serial port line, is randomly missing the first digit.... :/

  15. #15
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: Substring not Getting the SubString?

    If it is ALWAYS just the first digit, and if that digit is always the same, then the PadLeft solution may be easier than figuring out when this happens. Not quite as satisfying, though.
    My usual boring signature: Nothing

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Posts
    73

    Re: Substring not Getting the SubString?

    There is a 98% chance it will be a 0, 2% chance it will be a one...

    The integer ranges from 0000 to 1024... So unfortunately, the 2% chance will happen I am sure :/

  17. #17
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Substring not Getting the SubString?

    Quote Originally Posted by rpmaurer View Post
    Checked data leaving Arduino, its fine. Will check to see what the data coming in the serial port is, but the inputstring, which is the string representation of the serial port line, is randomly missing the first digit.... :/
    Add a ErrorReceived event handler for the SerialPort and see if there are any errors. Just losing bits should not happen without there being some indication.

    Are you converting an Arduino integer to a string and then transmitting that? What is the range for an Arduino integer?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  18. #18
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: Substring not Getting the SubString?

    Could it always be the case where the first digit is 1 where it is not being passed?

    In any case, DB is very much right about this. How useful would a serial port be if it routinely dropped a byte here and there? There certainly is an explanation, and once you find it you will understand it, because it will most likely be simple and obvious once you see it.
    My usual boring signature: Nothing

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Posts
    73

    Re: Substring not Getting the SubString?

    Nope, not only happening when it starts with one... grrr...

  20. #20
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Substring not Getting the SubString?

    Quote Originally Posted by rpmaurer View Post
    Nope, not only happening when it starts with one... grrr...
    Did you try the code I posted in post #10?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Posts
    73

    Re: Substring not Getting the SubString?

    Unfortunately there is no error coming in the SerialPort... the ErrorRecieved Handler is not being tripped. What I CAN do is to program the Arduino to not allow numbers greater than 999... there fore if the first digit is dropped it will ALWAYS be 0.

    Any other ideas?

    Ryan

  22. #22
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Substring not Getting the SubString?

    Can you show us the code that sets up and opens the serial port? If this is a USB to serialport adapter have you tried re-installing the driver for it?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  23. #23
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: Substring not Getting the SubString?

    I'm still finding it hard to believe that the first byte is being dropped. ReadLine reads a string from the input, but the input is actually bytes, so there is an interpretation step hidden in there that turns the bytes into a string. I think you should examine the byte stream rather than the string. That may be fairly difficult. ReadLine has some features that makes it fairly easy to work with in a singlethreaded way. Read and ReadByte are both going to be more difficult to work with, and I would think that they would both work better on a different thread (though a solution using such a technique can ultimately be superior, since you are currently converting bytes to a string, then converting some of the string back to bytes).

    What I am thinking is that you are getting the full set of bytes, but one of them is not being turned into a string, so ReadLine is not showing that byte. What it would be is hard to say. At the moment, I can't think of an answer that would suit. I was thinking that perhaps the first character was a negative sign, or something like that, where the string doesn't show it, but is curtailed at the same time.
    My usual boring signature: Nothing

  24. #24
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Substring not Getting the SubString?

    Quote Originally Posted by Shaggy Hiker View Post
    I'm still finding it hard to believe that the first byte is being dropped. ReadLine reads a string from the input, but the input is actually bytes, so there is an interpretation step hidden in there that turns the bytes into a string. I think you should examine the byte stream rather than the string. That may be fairly difficult. ReadLine has some features that makes it fairly easy to work with in a singlethreaded way. Read and ReadByte are both going to be more difficult to work with, and I would think that they would both work better on a different thread (though a solution using such a technique can ultimately be superior, since you are currently converting bytes to a string, then converting some of the string back to bytes).

    What I am thinking is that you are getting the full set of bytes, but one of them is not being turned into a string, so ReadLine is not showing that byte. What it would be is hard to say. At the moment, I can't think of an answer that would suit. I was thinking that perhaps the first character was a negative sign, or something like that, where the string doesn't show it, but is curtailed at the same time.
    Good idea. The first character may not have a glyph based on the encoding, which is one of the reasons I asked for the settings. Actually it might be better if the program on the Arduino was modified to send the actual values instead of converting them to string then sending.

    I have a PIC that sends data to my pc using RS232 and have never had an issue like this, but I use SerialPort.Read. I also have a protocol that includes a sync char, length, and checksum. This makes the messages a little longer, but a lot more reliable. I convert values on the PC as needed.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  25. #25

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Posts
    73

    Re: Substring not Getting the SubString?

    Initilization Code:
    Code:
    'initialize serial communication
    
            Me.SerialPort1.PortName = selectedport
            Me.SerialPort1.Open()
            Me.SerialPort1.WriteLine("1")
    
            'add subroutine on datarecived
            AddHandler SerialPort1.DataReceived, AddressOf GetData
    GetData Sub Routine
    Code:
        Private Sub GetData()
            If InvokeRequired Then
                Me.Invoke(New MethodInvoker(AddressOf GetData))
            Else
                Try
                    'get voltage data from loadcell ONLY
                    inputstring = SerialPort1.ReadLine
                    loadcell = Val(inputstring.Substring(0, 4))
                    loadcell = (loadcell / 1024) * 10
    
                    If inputstring.Length = 9 Then
                    Else
                        inputstring = "0" + inputstring
                    End If
    
    
    
                    'load voltage into appropriate textbox
                    If Button_LogHigh.Enabled = True Then
                        TextBox_HighVoltage.Text = Math.Round(loadcell, 4).ToString
                    Else
                        TextBox_LowVoltage.Text = Math.Round(loadcell, 4).ToString
                    End If
    
                    SerialPort1.Write("1")
    
    
                Catch ex As Exception
    
                    If Label4.Text = "error1" Then
                        Label4.Text = "error2"
                    Else
                        Label4.Text = "error1"
                    End If
    
                End Try
                
    
            End If
    
        End Sub
    Label4 was added to show when a error pops up... none did lol. One thing i have noticed is that when the batteries powering the Arduino get low then the signals become very erratic. This was not the case here however as I am still having the separate error when the batteries and fully charged...

    The Arduino has an Xbee mounted to it, the Xbee sends the signals to another Xbee plugged into the computer... I have checked all three units, their configs are correct, I have checked the data coming into the computer through the Arduino;s programming software, it too is ok.

  26. #26
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: Substring not Getting the SubString?

    That makes me think that this has to do with a string conversion issue, which just reinforces my idea that you need to re-work this to read the bytes rather than ReadLine (which will have already done the conversion to string before you get to see any of it).
    My usual boring signature: Nothing

  27. #27
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Substring not Getting the SubString?

    You should add the handler before you open the port. I agree that doing this with reading bytes rather than lines would help, or as I suggested before just send the raw data without converting it on the Arduino.

    Here is a little test program that will help us understand what is going on. Change the setting as needed.

    Code:
    Public Class Form1
    
        Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
            initSP()
        End Sub
    
        Private Sub initSP() 'initialize serial communication
    
            'add subroutine on datarecived
            AddHandler SerialPort1.DataReceived, AddressOf GetData
            'change the following lines as needed
            Dim selectedport As String = "COM27"
            SerialPort1.DtrEnable = True
            SerialPort1.RtsEnable = True
            SerialPort1.BaudRate = 9600
            SerialPort1.PortName = selectedport
            SerialPort1.Open()
    
            'SerialPort1.WriteLine("1")
    
        End Sub
    
        Private Sub GetData(sender As Object, e As IO.Ports.SerialDataReceivedEventArgs)
            Dim btr As Integer = Me.SerialPort1.BytesToRead
            Dim buf(btr - 1) As Byte
            SerialPort1.Read(buf, 0, btr)
            For Each byt As Byte In buf
                Debug.Write(byt.ToString.PadLeft(3, "0"c) & " ")
                If CInt(byt) = Asc(SerialPort1.NewLine) Then
                    Debug.WriteLine("")
                End If
            Next
        End Sub
    End Class
    Let this run for a short time and then copy and paste the debug output here.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  28. #28

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Posts
    73

    Re: Substring not Getting the SubString?

    Glad you understand this part, lol!

    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.DivideByZeroException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

  29. #29

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Posts
    73

    Re: Substring not Getting the SubString?

    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    A first chance exception of type 'System.ObjectDisposedException' occurred in System.Windows.Forms.dll
    049 050 051 052 053 013 010
    049 050 051 052 053 013 010
    049 050 051 052 053 013 010
    A first chance exception of type 'System.InvalidOperationException' occurred in System.dll
    049 050 051 052 053 013 010
    049 050 051 052 053 013 010
    049 050 051 052 053 013 010
    049 050 051 052 053 013 010
    049 050 051 052 053 013 010
    049 050 051 052 053 013 010
    049 050 051 052 053 013 010
    049 050 051 052 053 013 010
    A first chance exception of type 'System.InvalidOperationException' occurred in System.dll
    049 048 048 054 056 048 056 051 050 013 010
    048 048 054 056 048 056 051 054 013 010
    048 048 054 056 048 056 051 055 013 010
    048 048 054 057 048 056 051 055 013 010
    048 048 054 057 048 056 051 055 013 010
    048 048 054 056 048 056 051 048 048 054 056 048 056 051 010
    048 048 048 056 051 055 013 048 054 056 048 056 051 051 013 010
    048 054 056 048 056 051 055 013 048 048 056 051 055 013 010
    048 048 054 056 055 013 048 048 054 056 056 013 010
    048 054 056 010
    048 048 048 056 051 055 013 010
    048 048 054 056 048 048 054 056 048 056 051 056 013 010
    048 048 056 051 055 013 010
    048 048 054 056 055 013 010
    048 054 056 048 056 051 055 013 010
    048 048 054 056 010
    048 048 054 056 048 056 051 010
    048 054 057 048 056 051 055 013 010
    048 048 048 056 051 056 013 048 048 051 013 010
    048 048 054 057 051 013 010
    048 048 056 051 056 013 010
    048 048 054 057 048 056 051 056 013 048 048 054 057 048 013 010
    048 054 056 048 056 051 051 013 048 048 054 056 048 013 010
    048 048 048 056 051 010
    048 048 054 056 051 013 010
    048 054 056 048 056 051 055 013 010
    048 048 054 056 048 056 051 055 013 010
    048 048 054 057 048 056 051 055 010
    048 054 057 048 056 051 053 013 048 054 056 048 056 051 055 013 010
    048 048 048 056 051 010
    048 048 054 057 048 056 051 051 010
    048 054 056 010
    048 048 054 056 055 013 010
    048 054 056 010
    048 048 048 056 051 055 013 048 048 056 051 051 013 010
    048 048 054 057 055 013 048 048 054 056 048 056 051 055 010
    054 056 048 056 051 051 013 010
    048 010
    048 054 056 048 056 051 056 013 048 048 048 056 051 056 013 010
    048 048 054 057 048 056 051 048 048 054 056 048 056 051 055 013 010

  30. #30

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Posts
    73

    Re: Substring not Getting the SubString?

    048 054 056 048 056 051 056 013 010
    048 048 056 051 055 010
    048 048 054 056 048 056 051 052 010
    048 054 056 048 056 051 051 013 048 054 056 048 056 051 055 013 010
    048 048 048 056 051 010
    048 048 054 056 051 013 010
    048 054 056 010
    048 048 048 056 051 055 013 048 048 056 051 051 013 010
    048 048 048 056 051 010
    048 048 054 056 048 056 051 010
    048 054 057 048 056 051 056 013 048 054 056 048 056 051 055 013 010
    048 048 055 013 010
    048 048 054 056 048 056 051 010
    048 054 056 048 056 051 055 013 010
    048 054 057 048 056 051 055 013 010
    048 048 055 013 010
    048 048 048 056 051 010
    048 048 054 056 048 056 051 051 010
    048 054 056 048 056 051 053 013 048 048 054 056 048 013 010
    048 054 057 048 056 051 052 013 010
    048 048 054 056 048 056 051 055 013 010
    048 054 056 048 056 051 051 013 010
    048 048 054 056 048 056 051 055 013 010
    048 048 056 051 055 013 010
    048 048 054 056 048 056 051 010
    048 054 057 048 056 051 055 013 010
    048 048 048 056 051 010
    048 048 054 057 048 056 051 051 010
    048 054 056 010
    048 048 054 056 048 056 051 010
    048 048 056 051 055 013 010
    048 048 054 056 051 013 048 048 054 056 048 056 051 055 010
    048 048 048 056 051 010
    048 048 054 056 048 056 051 051 010
    048 048 048 056 051 051 010
    048 048 054 056 048 056 051 051 010
    048 054 057 010
    048 048 054 057 055 013 010
    048 054 056 010
    048 048 048 056 051 055 013 048 048 051 013 010
    048 048 054 056 051 013 048 048 054 056 048 013 010
    048 048 048 056 051 010
    048 048 054 056 051 013 010
    048 054 056 010
    048 048 054 056 048 056 051 010
    048 054 057 010
    048 048 048 056 051 053 013 048 048 056 051 051 013 010
    048 048 054 057 048 056 051 010
    048 048 054 057 048 013 010
    048 048 048 056 051 010
    048 048 054 056 048 056 051 051 010
    048 054 056 010
    048 048 054 057 055 013 010
    048 054 056 010
    048 048 048 056 051 055 013 048 054 056 048 056 051 051 013 010
    048 048 054 056 048 056 051 055 013 010
    048 048 056 051 054 013 010
    048 048 048 056 051 010
    048 048 054 057 051 013 010
    048 054 056 010
    048 048 048 056 051 055 013 048 054 057 048 056 051 051 013 010
    048 048 054 056 048 056 051 055 013 010
    048 048 054 056 048 056 051 051 013 010
    048 048 054 056 048 056 051 057 013 010
    048 048 054 056 048 056 051 057 013 048 048 054 056 048 056 051 057 013 010
    048 048 054 057 048 056 052 048 013 010
    048 048 054 057 048 056 052 010
    048 048 048 056 051 057 013 010
    048 054 056 048 056 051 052 013 010
    048 054 056 048 056 052 048 013 010
    048 048 054 056 048 056 051 057 013 010
    048 048 054 056 048 056 051 051 013 010
    048 054 056 048 056 052 048 013 048 054 056 048 056 051 056 013 010
    048 048 054 056 048 010
    048 048 048 056 051 052 013 048 048 056 051 052 013 010
    048 048 054 056 048 056 052 010
    048 054 056 048 056 051 057 013 010
    048 048 048 056 051 010
    048 048 054 056 048 056 051 052 010
    048 054 057 010
    048 048 054 056 048 056 052 010
    048 054 056 048 056 051 057 013 010
    048 054 056 048 056 051 057 013 010
    048 048 057 013 010
    048 048 054 056 052 013 048 048 054 057 048 013 010
    048 048 048 056 051 010
    048 048 054 056 048 056 051 052 010
    048 054 056 010
    048 048 054 056 048 013 010
    048 054 056 010
    048 048 048 056 051 057 013 048 048 056 051 052 013 010
    048 048 054 056 048 056 051 010
    048 054 056 048 056 051 057 013 010
    048 048 048 056 052 010
    048 048 054 056 048 056 051 052 010
    048 054 057 048 056 051 053 013 010
    048 048 048 056 051 051 013 010
    048 048 054 056 010
    048 048 048 056 052 048 013 048 048 056 051 052 013 010
    048 048 054 056 048 056 052 010
    048 048 054 056 048 013 010
    048 048 048 056 051 010
    048 048 054 057 048 056 051 051 010
    048 054 056 010
    048 048 054 056 057 013 010
    048 054 056 010
    048 048 048 056 052 048 013 048 048 056 051 052 013 010
    048 048 054 056 048 056 051 010
    048 048 054 057 013 010
    048 048 048 056 051 010
    048 048 054 056 048 056 051 010
    048 054 056 010
    048 048 054 056 056 013 010
    048 054 056 010
    048 048 048 056 051 057 013 048 048 051 013 010
    048 048 054 056 051 013 048 048 054 056 048 013 010
    048 048 048 056 051 010
    048 048 054 056 048 056 051 052 010
    048 054 056 010
    048 048 054 056 057 013 010
    048 054 056 048 056 051 057 013 010
    048 048 054 056 048 056 051 010
    048 054 057 048 056 051 056 013 010
    048 048 048 056 051 057 010
    048 010
    048 054 056 048 056 051 056 013 048 054 056 048 056 051 055 013 010
    048 048 054 056 010
    048 048 054 056 056 013 010
    048 054 056 010
    048 048 048 056 051 056 013 048 048 056 051 051 013 010
    048 048 054 056 048 056 051 010
    048 054 056 048 056 051 057 013 010
    048 048 048 056 051 010
    048 048 054 056 048 013 010
    048 054 056 010
    048 048 054 056 056 013 010
    048 048 056 051 056 013 010
    048 048 054 056 048 056 051 056 013 048 048 054 056 048 056 051 056 010
    048 054 056 048 056 051 051 013 048 048 056 051 051 013 010
    048 048 054 057 057 013 048 048 054 056 056 013 010
    048 054 057 010
    048 048 054 056 056 013 010
    048 048 056 051 056 013 010
    048 048 054 057 048 056 051 056 013 010
    048 048 054 056 048 056 051 056 013 010
    048 048 054 056 048 056 051 056 013 010
    048 048 054 057 048 056 051 056 013 010
    048 048 054 056 048 056 051 056 013 010
    048 048 054 056 048 056 051 056 013 010
    048 048 054 057 048 056 051 010
    048 048 054 056 056 013 010
    048 048 048 056 051 057 013 010
    048 048 054 057 048 048 054 056 048 056 051 056 010
    048 054 056 048 056 051 050 013 048 048 010
    048 048 054 056 048 056 051 051 013 010
    048 054 057 048 056 051 056 013 010
    048 048 054 056 010
    048 048 054 057 056 013 010
    048 048 056 051 056 013 010
    048 048 054 057 048 056 051 010
    048 048 054 056 048 013 010
    048 048 048 056 051 010
    048 048 054 056 048 056 051 050 010
    048 054 056 010
    048 048 054 056 056 013 010
    048 048 056 013 010
    048 048 054 056 048 056 051 010
    048 054 056 048 056 051 055 013 010
    054 056 048 056 051 055 013 010
    048 048 054 056 055 013 010
    048 048 048 056 051 010
    048 010
    048 054 057 010
    048 048 054 056 048 056 051 056 013 048 048 054 056 048 056 051 056 013 010
    048 048 054 056 048 056 051 056 013 010
    048 048 054 056 048 056 051 055 013 010
    048 048 054 057 048 056 051 056 013 010
    048 048 054 056 048 056 051 056 013 010
    048 048 054 057 048 056 051 055 013 010
    048 048 054 056 048 056 051 054 013 010
    048 048 054 056 048 056 051 055 013 010
    048 048 054 056 048 056 051 055 013 010
    048 048 054 056 048 056 051 056 013 010
    048 048 054 056 048 056 051 056 013 010
    A first chance exception of type 'System.InvalidOperationException' occurred in System.dll
    048 048 054 056 048 056 052 050 013 010
    048 048 054 056 048 056 052 054 013 010
    048 048 054 056 048 056 052 054 013 010
    048 048 054 056 048 056 052 054 013 010
    048 048 054 056 048 056 052 054 013 010
    048 048 054 056 048 056 052 055 013 010
    048 048 054 056 048 056 052 055 013 010
    048 048 054 057 048 056 052 055 013 010
    048 054 056 048 056 052 054 013 010
    048 048 054 057 048 056 052 054 013 010
    048 048 054 057 048 056 052 055 013 010
    048 048 054 056 048 056 052 055 013 010
    048 048 054 056 048 056 052 055 013 010
    048 048 048 056 052 055 013 010
    048 048 054 056 048 056 052 051 013 010
    048 054 056 048 056 052 054 013 010
    048 048 054 056 048 056 052 054 013 048 048 054 056 048 056 052 054 013 010
    048 048 048 056 052 055 013 010
    048 054 056 048 056 052 051 013 010
    048 048 054 056 048 056 052 055 013 010
    048 048 054 056 051 013 010
    048 048 056 052 055 013 010
    048 048 054 056 048 056 052 010
    048 054 056 048 056 052 054 013 010
    048 048 048 056 052 054 010
    048 010
    048 054 056 010
    048 048 054 056 055 013 010
    048 054 056 010
    048 048 054 056 054 013 010
    048 048 056 052 054 013 010
    048 048 054 057 048 056 052 010
    048 054 056 048 056 052 054 013 010
    048 048 048 056 052 010
    048 048 054 057 048 056 052 051 010
    048 054 056 010
    048 048 054 056 054 013 010
    048 054 056 010
    048 048 054 056 054 013 010
    048 048 056 052 054 013 010
    048 048 054 056 048 056 052 010
    048 054 057 048 056 052 054 013 010
    048 048 048 056 052 010
    048 048 054 056 048 056 052 050 010
    048 054 056 010
    048 048 054 057 054 013 010
    048 048 056 052 054 013 010
    048 048 054 056 048 056 052 054 013 048 054 056 048 056 052 054 013 010
    048 048 048 056 052 054 010
    048 010
    048 048 048 056 052 010
    048 048 054 056 048 056 052 050 010
    048 054 056 010
    048 048 054 056 054 013 010
    048 054 057 010
    048 048 048 056 052 053 013 048 048 056 052 051 013 010
    048 048 054 056 048 056 052 010
    048 054 056 048 056 052 054 013 010
    048 048 048 056 052 010
    048 048 054 056 048 056 052 050 010
    048 054 056 010
    048 048 054 056 053 013 010
    048 054 056 010
    048 048 048 056 052 054 013 048 048 056 052 050 013 010
    048 048 054 056 048 056 052 010
    048 054 057 048 056 052 054 013 010
    048 048 048 056 052 010
    048 048 054 056 048 056 052 010

  31. #31

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Posts
    73

    Re: Substring not Getting the SubString?

    Wasnt sure how much of the Debug you wanted, I ran that for only 3 seconds...

    Went back and checked all setups for Arduinos and Xbees, checked the data coming into the Xbee hooked up to the computer, its all good, it is something with this code

  32. #32

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Posts
    73

    Re: Substring not Getting the SubString?

    Also, I am starting to see drop outs of the first 2 digits also

  33. #33

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Posts
    73

    Re: Substring not Getting the SubString?

    AHA, break through (sort of)... I added a list box and added this code:
    Code:
    ListBox1.Items.Add(SerialPort1.ReadLine)
    I do NOT have any problems on that one!

  34. #34
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Substring not Getting the SubString?

    Did you create a new project with just the code I provided? If so I don't understand the errors.

    The data provided (short sample below) shows that your 'lines' are not always 8 characters, and the new line is not consistent.

    Code:
    048 054 056 048 056 051 056 013 010
    048 048 056 051 055 010
    048 048 054 056 048 056 051 052 010
    048 054 056 048 056 051 051 013 048 054 056 048 056 051 055 013 010
    048 = 0, 049 = 1, 050 = 2, 051 = 3, 052 = 4, 053 = 5, 054 = 6, 055 = 7, 056 = 8, 057 = 9
    013 = CR, 10 = LF

    Maybe I have asked before, but what kind of RS232 adapter do you have?

    FYI - I didn't need to see so much data
    Last edited by dbasnett; Feb 17th, 2013 at 10:18 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  35. #35

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Posts
    73

    Re: Substring not Getting the SubString?

    I have an Arduino UNO, hooked up to an Xbee (1mW antenna), which wirelessly transmitts to another Xbee, same type, hooked up to the computer using a sparkfun usb dongle... I am going to try to do this with a usb cable directly from Arduino to Computer to see if i still have the problem...

  36. #36

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Posts
    73

    Re: Substring not Getting the SubString?

    I have an Arduino UNO, hooked up to an Xbee (1mW antenna), which wirelessly transmitts to another Xbee, same type, hooked up to the computer using a sparkfun usb dongle... I am going to try to do this with a usb cable directly from Arduino to Computer to see if i still have the problem...

    Is it possible that the serial data is coming in in packets of bytes and thus tripping the handler when all of the data has not yet been recieved?

  37. #37

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Posts
    73

    Re: Substring not Getting the SubString?

    No errors at ALL when hard wired

  38. #38
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Substring not Getting the SubString?

    Quote Originally Posted by rpmaurer View Post
    No errors at ALL when hard wired
    Is this your config with no errors?

    PC --- SparkFun --- Arduino

    And this did not work?

    PC --- SparkFun --- Xbee (()) Xbee --- Arduino

    "Is it possible that the serial data is coming in in packets of bytes and thus tripping the handler when all of the data has not yet been recieved?" If you are asking if the DataReceivedEvent handler fires with less than the amount of bytes you expect, then yes. The event will fire if there is at least .ReceivedBytesThreshold number of bytes available. Putting a readline in the event handler would be my last choice.

    All the serial port really does is send and receive bytes. It does not care for the most part what those bytes are. When you perform a ReadLine the serial port converts the bytes based on the encoding specified, and looks to see if there is a .NewLine . If there is it returns the string, based on the encoding. If not it blocks.

    If I were doing this I would create a protocol that encapsulated the data, and I would send raw data, not data converted to strings. I would also just accumulate bytes in a buffer and scan the buffer outside of the event handler.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  39. #39

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Posts
    73

    Re: Substring not Getting the SubString?

    That seems to have done it! I also went through and reset both XBees to their original factory settings... seems to be working now *knock on wood* Thanks for helping me narrow down the problem, expect more issues from me in the future...

    Ryan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width