Shop OBEX P1 Docs P2 Docs Learn Events
Expert coder needed - Page 5 — Parallax Forums

Expert coder needed

1235

Comments

  • computer guycomputer guy Posts: 1,113
    edited 2008-02-13 01:29
    Thank you smile.gif
    All is well.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • computer guycomputer guy Posts: 1,113
    edited 2008-02-13 03:31
    Ok.
    With this reading in of information am I doing it right.

    I am doing the following.

    1. Sending 's' to the prop to get it to call the sendDataSerial function.
    2. Reading in the Number of schedules as a byte.
    3. doing a For Loop to read in the long one byte at a time.
    e.g
    For i = 0 To NumSchedules(0).ToString - 1
                    SerialPort1.Read(Data, 0, 4) 'Read in 4 Bytes of information and save to buffer Data which is a Byte array
    
                    'Display the data in a textbox
                    RichTextBox1.Text += Data(0).ToString
                    RichTextBox1.Text += Data(1).ToString
                    RichTextBox1.Text += Data(2).ToString
                    RichTextBox1.Text += Data(3).ToString
                    RichTextBox1.Text += vbCrLf
                Next
    
    



    4. Display the data as a string.

    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-02-13 03:39
    Yes that is right. I don't know vb so I'm not sure if that's right or not. Should
    For i = 0 To NumSchedules(0).ToString - 1
    


    be
    For i = 0 To NumSchedules(0) - 1
    
  • computer guycomputer guy Posts: 1,113
    edited 2008-02-13 04:02
    I have tried it both ways and it doesn't make any difference.

    Will post the question on a VB forum and see if I get any answers.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-02-13 04:09
    Can you get and display the data if you use the strings we were using with hyperterminal?
  • computer guycomputer guy Posts: 1,113
    edited 2008-02-13 04:10
    I will give it a try.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • computer guycomputer guy Posts: 1,113
    edited 2008-02-13 05:51
    VB can only read in bytes.
    With the original method is all the data sent as bytes representing the numbers.
    How do you change a byte of 1's and 0's into an actual number again.
    All I am doing is getting all four bytes and joining them together and displaying them as text.

    Will ask on the VB forums anyway and see if I get any useful information.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-02-13 06:01
    Try something like this
    For i = 0 To NumSchedules(0).ToString - 1
                    SerialPort1.Read(Data, 0, 1) 'Read in 1 Bytes of information
    
                    'Display the data in a textbox
                    RichTextBox1.Text += Data1.ToString
                    SerialPort1.Read(Data, 0, 1)
                    RichTextBox1.Text += Data.ToString
                    SerialPort1.Read(Data, 0, 1)
                    RichTextBox1.Text += Data.ToString
                    SerialPort1.Read(Data, 0, 1)
                    RichTextBox1.Text += Data.ToString
                    RichTextBox1.Text += vbCrLf
                Next
    
  • computer guycomputer guy Posts: 1,113
    edited 2008-02-13 06:09
    With the above code I get this.

    51525152
    77111110100
    
    



    with this

    Time 22:22, Day Monday, Code 01
    Time 22:22, Day Monday, Code 01
    
    



    It is consistent though.

    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-02-13 06:10
    Can you make it put in a space so that we can see what the individual numbers are? Thanks
  • computer guycomputer guy Posts: 1,113
    edited 2008-02-13 06:24
    ok it is.

    51 52 51 52 
    77 111 110 100 
    
    



    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-02-13 06:32
    Can you set hyperterminal up to show the actual hex values received? If you can do you get the same?
  • computer guycomputer guy Posts: 1,113
    edited 2008-02-13 06:49
    With hyper terminal I get
    3434Monday01
    
    



    Have to go to tafe. Will look forward to your response when I get back at 9:00pm.

    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-02-13 07:03
    That is what I would expect as 34 is the BCD equivalent of 22 so there must be something wrong with the VB code. What do you do at tafe?
  • computer guycomputer guy Posts: 1,113
    edited 2008-02-13 11:33
    I am learning how to arc weld.
    Just started tonight.
    Goes from 6 to 10.

    Longest 4 hours of my life. smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-02-13 11:42
    Have fun, and don't get the stick stuck to the bench, and don't get any slag or splatter on yourself smile.gif

    When I was doing my mech eng adv diploma we did some welding but it was only 2 or 3 hours a week and that was enough
  • computer guycomputer guy Posts: 1,113
    edited 2008-02-13 11:45
    I know 4 hours is a long time to be doing the same thing.

    Thanks for the advice. smile.gif

    Will keep persevering with this code problem.
    I think it is a problem with the conversion from byte to string, could be wrong though. smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-02-13 11:47
    Never used a serial port in any of the programming that I've done on a pc and I've never used vb so I really don't know. Maybe see if someone else here can help smile.gif I think that there are several people here that know vb.
  • Computer Geek 101Computer Geek 101 Posts: 179
    edited 2008-02-13 12:18
    what version of VB.net? I have a dll I wrote in vb.net 2005 that controls the serial port. you setup the port number, speed, etc. and an event fires off anytime data is detected. I'll post it if it would help.
  • computer guycomputer guy Posts: 1,113
    edited 2008-02-13 12:19
    I found this interesting and it may help people with knowledge of VB.

    When I add more entries I get a pattern.

    51 52 51 52 
    77 111 110 100 
    97 121 48 49 
    51 52 51 52 
    77 111 110 100 
    97 121 48 49 
    
    



    is what I get with this.

    
    Time 22:22, Day Monday, Code 01
    Time 22:22, Day Monday, Code 01
    Time 22:22, Day Monday, Code 01
    Time 22:22, Day Monday, Code 01
    Time 22:22, Day Monday, Code 01
    Time 22:22, Day Monday, Code 01
    
    
    



    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • computer guycomputer guy Posts: 1,113
    edited 2008-02-13 12:22
    Computer Geek 101,

    Thank you, however I am currently using the serial component that comes with Visual Basic 2008 and it works fine with sending.
    The only problem is that when receiving the data is getting fragmented and the wrong values are returned.

    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-02-13 16:39
    Hi computer guy, for VB display purposes you can use the DataReceived event of the serial port and capture the characters as they come. First set up a delegate that will actually write to the text box

    Public Delegate Sub capture(ByVal sData As String)

    ·Private Sub Text_Out(ByVal sData As String)
    ······· RichTextBox1.Text = RichTextBox1.Text & Chr(sData) 'this will write the ASCII code as a character
    End Sub

    then invoke the delegate from within the datareceived event

    Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived

    ······· Do
    ············ Dim in_data As String
    ············ Dim capture_delegate As New capture(AddressOf Text_Out)
    ············ in_data = SerialPort1.ReadByte
    ············ RichTextBox1.Invoke(capture_delegate, in_data)
    ········ Loop Until SerialPort1.BytesToRead < 1·····

    End Sub

    you will probably have to drop a LF or CR in there somewhere, it should work with your data.

    Jeff T.
  • computer guycomputer guy Posts: 1,113
    edited 2008-02-13 20:20
    Hi Jeff,

    Your code results in this data.

    444444444444
    
    



    the code on the prop side is

    PUB sendDataSerial|i,time,data
      data := (NumScheduleItems/10)<<4+NumScheduleItems//10
      ser.tx(data)'So that you know how many items there are
      i:=1
      repeat while i<numScheduleItems
        time:=schedule[i]
        ser.tx(time.byte[noparse][[/noparse]0])
        ser.tx((time.byte/10)<<4+time.byte//10)
        ser.tx((time.byte/10)<<4+time.byte//10)
        ser.tx(time.byte)
    
        i++ 
    [/i]
    



    This is the original VB code I had and is the way I would like it done.

            Try
                RichTextBox1.Text = ""
                Dim NumSchedules As Byte() = New Byte(1) {}
                Dim Data As Byte() = New Byte(1) {}
                Dim i As Integer = 0
                SerialPort1.Open()
    
                SerialPort1.Write("s")
                SerialPort1.Read(NumSchedules, 0, 1)
                Label1.Text = NumSchedules(0)
                For i = 0 To (NumSchedules(0) - 1)
                    SerialPort1.Read(Data, 0, 1) 'Read in 1 Bytes of information
    
                    RichTextBox1.Text += Data(0).ToString + " "
                    SerialPort1.Read(Data, 0, 1)
                    RichTextBox1.Text += Data(0).ToString + " "
                    SerialPort1.Read(Data, 0, 1)
                    RichTextBox1.Text += Data(0).ToString + " "
                    SerialPort1.Read(Data, 0, 1)
                    RichTextBox1.Text += Data(0).ToString + " "
                    RichTextBox1.Text += vbCrLf
                Next
                SerialPort1.Close()
            Catch
            End Try
    
    



    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker

    Post Edited (computer guy) : 2/13/2008 8:28:05 PM GMT
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-02-14 01:00
    Hi computer guy, my mistake, I thought you were sending an ASCII·string from the prop when I saw the ASCII codes for Monday 01( 77·111·110·100·97·121·48·49·) .

    So you should be able to display the day with the following modification to the way you want to do it.

    RichTextBox1.Text·+=·Chr(Data(0).ToString)·+·"·"

    That·should give you·part of your data but not all.

    Jeff T.
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-02-14 01:13
    Okay, that makes it simple. Yoy forgot to comment out the case statement in sendDataSerial smile.gif
  • computer guycomputer guy Posts: 1,113
    edited 2008-02-14 05:20
    Jeff,

    The code you provided didn't help.
    It have worked after the modifications I made, however since I don't need that code to get it to work I have left it out.

    @Jeff and Steven

    The solution was this.

    1. Upload the up to date code to the propeller chip.
    This includes changing sendDataSerial back to.
     data := (NumScheduleItems/10)<<4+NumScheduleItems//10
      ser.tx(data)'So that you know how many items there are
      i:=0
      repeat while i<numScheduleItems
        time:=schedule[i]
        ser.tx(time.byte[noparse][[/noparse]0])
        ser.tx(time.byte)
        ser.tx(time.byte)
        ser.tx(time.byte)
    [/i]
    



    2. Add the following just above the code that receives the data from the buffer.
                    Data(0 To 3) = 0
                    System.Threading.Thread.Sleep(100)
    
    


    This blanks out the Byte Array and then pauses to give the prop time to send the new values (this is what was causing the random values).

    3. Change the VB code back to what I had originally.
              For i = 0 To (NumSchedules(0) - 1)
                    Data(0 To 3) = 0
                    System.Threading.Thread.Sleep(100)
                    SerialPort1.Read(Data, 0, 4) 'Read in 1 Bytes of information
    
                    'Display the data in a textbox
                    RichTextBox1.Text += Data(0).ToString + " "
                    RichTextBox1.Text += Data(1).ToString + " "
                    RichTextBox1.Text += Data(2).ToString + " "
                    RichTextBox1.Text += Data(3).ToString + " "
                    RichTextBox1.Text += vbCrLf
                Next
    
    


    Not needed but the code is allot simpler this way. smile.gif

    Like magic... It works. smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker

    Post Edited (computer guy) : 2/14/2008 5:43:04 AM GMT
  • JoMoJoMo Posts: 19
    edited 2008-02-14 05:34
    Just a note:
    It's good practice to close/flush· (check if not null first) sockets or database connections etc. in a Finally block.
    Just declare·them as null·object·above the Try and close·them in the Finally.
    This way, if they don't connect or throw an exception, before the method is exited an attempt will be made to close them.
    Have fun!

    -Joe

    Post Edited (JoMo) : 2/14/2008 5:39:36 AM GMT
  • computer guycomputer guy Posts: 1,113
    edited 2008-02-14 05:40
    Joe,

    Thank you, It is in a "Try Finally" block.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-02-14 06:31
    Glad you finally got it working. Now you just have to do it all over with the MatchPort smile.gif
  • computer guycomputer guy Posts: 1,113
    edited 2008-02-14 06:33
    Yea, The reason I wanted to get it going with VB.net is because working with the Matchport and Java will be allot easier if I have a starting point. smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
Sign In or Register to comment.